public void AssetSearch() { var searchRequestDto = new PaginatedSearchRequestDto(100, PaginatedSearchRequestDto.DefaultPaginationOptions); searchRequestDto.SetFromSearchString(_assetSchema, "hlagdescription,serialnum".Split(','), "test%"); Assert.AreEqual("( UPPER(COALESCE(CASE WHEN LOCATE('//',asset.Description) > 0 THEN LTRIM(RTRIM(SUBSTR(asset.Description, LOCATE('//', asset.Description)+3))) ELSE LTRIM(RTRIM(asset.Description)) END,'')) like :hlagdescription ) OR ( UPPER(COALESCE(asset.serialnum,'')) like :serialnum )", SearchUtils.GetWhere(searchRequestDto, "asset")); }
public IApplicationResponse Search(string application, string searchFields, string searchText, string schema = "list") { var user = SecurityFacade.CurrentUser(); var app = MetadataProvider.Application(application); var schemas = app.Schemas(); var key = new ApplicationMetadataSchemaKey(schema, SchemaMode.input, ClientPlatform.Web); ApplicationSchemaDefinition appSchema; if (!schemas.TryGetValue(key, out appSchema)) { throw new InvalidOperationException("schema not found"); } var searchRequestDto = PaginatedSearchRequestDto.DefaultInstance(appSchema); searchRequestDto.SetFromSearchString(appSchema, searchFields.Split(','), searchText); var dataResponse = Get(application, new DataRequestAdapter() { Key = key, SearchDTO = searchRequestDto }); //fixing the filter parameters used so that it is applied on next queries ((ApplicationListResult)dataResponse).PageResultDto.BuildFixedWhereClause(searchRequestDto, app.Entity); dataResponse.Title = appSchema.Title; dataResponse.Mode = SchemaMode.input.ToString().ToLower(); return(dataResponse); // return View("Index", new ApplicationModel(application, "list", SchemaMode.input.ToString().ToLower(), appSchema.Title, dataResponse)); }
public LookupAssociationUpdateResult(IEnumerable <IAssociationOption> associationData, int defaultPageSize, List <int> paginationOptions) : base(associationData) { _pageResultDto = new PaginatedSearchRequestDto(defaultPageSize, paginationOptions) { TotalCount = associationData == null ? 0 : associationData.Count() }; }
public void SearchWithQueryParameter() { var searchRequestDto = new PaginatedSearchRequestDto(100, PaginatedSearchRequestDto.DefaultPaginationOptions); searchRequestDto.SetFromSearchString(_assetSchema, "computername".Split(','), "test%"); var actual = SearchUtils.GetWhere(searchRequestDto, "asset"); Assert.AreEqual("( UPPER(COALESCE(CASE WHEN LOCATE('//',asset.Description) > 0 THEN LTRIM(RTRIM(SUBSTR(asset.Description,1,LOCATE('//',asset.Description)-1))) ELSE LTRIM(RTRIM(asset.Description)) END,'')) like :computername )", actual); }
private bool ShouldPaginate(ApplicationCompositionSchema compositionSchema, PaginatedSearchRequestDto paginatedSearch) { var listSchema = compositionSchema.Schemas.List; var paginationDisabled = listSchema.GetProperty("pagination.disabled"); // did not disable via metadata and requested paginated content //hapag asked to disable whole pagination return(false); }
public ApplicationListResult(int totalCount, PaginatedSearchRequestDto searchDTO, IEnumerable <AttributeHolder> dataMap, ApplicationSchemaDefinition schema) : base(dataMap, null) { Schema = schema; PageResultDto = new PaginatedSearchRequestDto(totalCount, searchDTO.PageNumber, searchDTO.PageSize, searchDTO.SearchValues, searchDTO.PaginationOptions); PageResultDto.SearchParams = searchDTO.SearchParams; PageResultDto.FilterFixedWhereClause = searchDTO.FilterFixedWhereClause; PageResultDto.UnionFilterFixedWhereClause = searchDTO.UnionFilterFixedWhereClause; }
public void SearchWithFixedParam_Hapag_SEARCH_TEST() { var searchRequestDto = new PaginatedSearchRequestDto(100, PaginatedSearchRequestDto.DefaultPaginationOptions); searchRequestDto.SetFromSearchString(_schema, "ticketid,description".Split(','), "%teste%"); searchRequestDto.BuildFixedWhereClause(searchRequestDto, "SR"); var filterFixedWhereClause = searchRequestDto.FilterFixedWhereClause; Assert.AreEqual("( UPPER(COALESCE(SR.ticketid,'')) like '%TESTE%' ) OR ( UPPER(COALESCE(SR.description,'')) like '%TESTE%' )", filterFixedWhereClause); }
public void SearchWithFixedParam_Hapag_SEARCH_TEST_NOTEQ() { var searchRequestDto = new PaginatedSearchRequestDto(100, PaginatedSearchRequestDto.DefaultPaginationOptions); searchRequestDto.SetFromSearchString(_schema, "ticketid".Split(','), "!=teste"); searchRequestDto.BuildFixedWhereClause(searchRequestDto, "SR"); var filterFixedWhereClause = searchRequestDto.FilterFixedWhereClause; Assert.AreEqual("( UPPER(COALESCE(SR.ticketid,'')) != 'TESTE' OR UPPER(COALESCE(SR.ticketid,'')) IS NULL )", filterFixedWhereClause); }
public LookupAssociationUpdateResult(int totalCount, int pageNumber, int pageSize, IEnumerable <IAssociationOption> associationData, ApplicationMetadata associationMetadata, List <int> paginationOptions) : base(associationData) { _pageResultDto = new PaginatedSearchRequestDto(totalCount, pageNumber, pageSize, null, paginationOptions); if (associationMetadata != null) { _associationSchemaDefinition = associationMetadata.Schema; } }
public void DateTimeSearchDtoLteTest() { var searchRequestDto = new PaginatedSearchRequestDto(100, PaginatedSearchRequestDto.DefaultPaginationOptions); searchRequestDto.SetFromSearchString(_schema, "reportdate".Split(','), "<=2013-01-01 15:45"); Assert.IsTrue(SearchUtils.GetWhere(searchRequestDto, "SR").Equals("( SR.reportdate <= :reportdate_end )")); var parametersMap = SearchUtils.GetParameters(searchRequestDto); Assert.IsTrue(parametersMap.Count == 1); Assert.AreEqual(DateTime.Parse("2013-01-01 15:45:59.999"), parametersMap["reportdate_end"]); }
public void NumberSearchDtoGteTest() { var searchRequestDto = new PaginatedSearchRequestDto(100, PaginatedSearchRequestDto.DefaultPaginationOptions); searchRequestDto.SetFromSearchString(_schema, "curbal".Split(','), ">=20"); Assert.AreEqual("( invbalances.curbal >= :curbal )", SearchUtils.GetWhere(searchRequestDto, "invbalances")); var parametersMap = SearchUtils.GetParameters(searchRequestDto); Assert.IsTrue(parametersMap.Count == 1); Assert.IsTrue(parametersMap["curbal"].Equals(20)); }
public void DateSearchDtoGteTest() { var searchRequestDto = new PaginatedSearchRequestDto(100, PaginatedSearchRequestDto.DefaultPaginationOptions); searchRequestDto.SetFromSearchString(_schema, "ticketid,description,asset_.description,siteid,affectedperson,status,reportdate".Split(','), ">=2013-01-01"); Assert.IsTrue(SearchUtils.GetWhere(searchRequestDto, "SR").Equals("( SR.reportdate >= :reportdate_begin )")); var parametersMap = SearchUtils.GetParameters(searchRequestDto); Assert.IsTrue(parametersMap.Count == 1); Assert.IsTrue(parametersMap["reportdate_begin"].Equals(DateUtil.BeginOfDay(DateTime.Parse("2013-01-01")))); }
public void DateSearchDtoGtTest() { var searchRequestDto = new PaginatedSearchRequestDto(100, PaginatedSearchRequestDto.DefaultPaginationOptions); searchRequestDto.SetFromSearchString(_schema, "reportdate".Split(','), ">2013-01-03"); Assert.IsTrue(SearchUtils.GetWhere(searchRequestDto, "SR").Equals("( SR.reportdate > :reportdate_begin )")); var parametersMap = SearchUtils.GetParameters(searchRequestDto); Assert.IsTrue(parametersMap.Count == 1); Assert.IsTrue(parametersMap["reportdate_begin"].Equals(DateUtil.BeginOfDay(DateTime.Parse("2013-01-04")))); }
public void MultipleFieldsSearchDtoTest() { var searchRequestDto = new PaginatedSearchRequestDto(100, PaginatedSearchRequestDto.DefaultPaginationOptions); searchRequestDto.SetFromSearchString(_schema, "ticketid,description,asset_.description,siteid,affectedperson,status,reportdate".Split(','), "teste"); Assert.IsNotNull(searchRequestDto); Assert.AreEqual("ticketid||,description||,asset_.description||,status", searchRequestDto.SearchParams); Assert.AreEqual("teste,,,teste,,,teste,,,teste", searchRequestDto.SearchValues); String whereClause = SearchUtils.GetWhere(searchRequestDto, "SR"); Assert.AreEqual("( SR.ticketid = :ticketid ) OR ( SR.description = :description ) OR ( asset_.description = :asset_.description ) OR ( SR.status = :status )", whereClause); }
public void DateTimeSearchDtoNeqTest() { var searchRequestDto = new PaginatedSearchRequestDto(100, PaginatedSearchRequestDto.DefaultPaginationOptions); searchRequestDto.SetFromSearchString(_schema, "reportdate".Split(','), "!=2013-01-04"); var @where = SearchUtils.GetWhere(searchRequestDto, "SR"); Assert.AreEqual("( SR.reportdate NOT BETWEEN :reportdate_begin AND :reportdate_end OR SR.reportdate IS NULL )", @where); var parametersMap = SearchUtils.GetParameters(searchRequestDto); Assert.IsTrue(parametersMap.Count == 2); Assert.AreEqual(DateUtil.BeginOfDay(DateTime.Parse("2013-01-04")), parametersMap["reportdate_begin"]); Assert.AreEqual(DateUtil.EndOfDay(DateTime.Parse("2013-01-04")), parametersMap["reportdate_end"]); }
public void BasicSearchDtoTest() { var searchRequestDto = new PaginatedSearchRequestDto(100, PaginatedSearchRequestDto.DefaultPaginationOptions); searchRequestDto.SetFromSearchString(_schema, "ticketid".Split(','), "teste"); Assert.IsNotNull(searchRequestDto); Assert.IsTrue(searchRequestDto.SearchParams.Equals("ticketid")); Assert.IsTrue(searchRequestDto.SearchValues.Equals("teste")); var whereClause = SearchUtils.GetWhere(searchRequestDto, "SR"); Assert.AreEqual("( SR.ticketid = :ticketid )", whereClause); }
public void TestUnionOfCalls() { var wlMetadata = MetadataProvider.Entity("fakeentity"); var dto = new PaginatedSearchRequestDto(); dto.WhereClause = "3=3"; dto.UnionWhereClauses = new List <string> { "1=1", "2=2" }; var result = _builder.AllRows(wlMetadata, dto); var resultST = "select fakeentity.fakeid as \"fakeid\", fakeentity.rowstamp as \"rowstamp\" from fakeentity as fakeentity where (3=3) union all select fakeentity.fakeid as \"fakeid\", fakeentity.rowstamp as \"rowstamp\" from fakeentity as fakeentity where (1=1) union all select fakeentity.fakeid as \"fakeid\", fakeentity.rowstamp as \"rowstamp\" from fakeentity as fakeentity where (2=2) order by 1 desc"; Assert.AreEqual(resultST, result.Sql); }
private static PaginatedSearchRequestDto BuildSearchDTO(AssociationUpdateRequest request, ApplicationAssociationDefinition association, AttributeHolder cruddata) { var searchRequest = new PaginatedSearchRequestDto(100, PaginatedSearchRequestDto.DefaultPaginationOptions); if (request.SearchDTO == null) { request.SearchDTO = PaginatedSearchRequestDto.DefaultInstance(null); } searchRequest.PageNumber = request.SearchDTO.PageNumber; searchRequest.PageSize = request.SearchDTO.PageSize; //avoids pagination unless the association renderer defines so (lookup) searchRequest.ShouldPaginate = association.IsPaginated(); searchRequest.NeedsCountUpdate = association.IsPaginated(); var valueSearchString = request.ValueSearchString; if (association.IsLazyLoaded() && !request.HasClientSearch()) { if ((cruddata == null || cruddata.GetAttribute(association.Target) == null)) { //we should not update lazy dependant associations except in one case: //there´s a default value in place already for the dependent association // in that case, we would need to return a 1-value list to show on screen return(null); } //this will force that the search would be made only on that specific value //ex: autocomplete server, lookups that depend upon another association valueSearchString = cruddata.GetAttribute(association.Target) as string; } if (request.AssociationKey != null) { // If association has a schema key defined, the searchDTO will be filled on client, so just copy it from request searchRequest.SearchParams = request.SearchDTO.SearchParams; searchRequest.SearchValues = request.SearchDTO.SearchValues; } else { if (!String.IsNullOrWhiteSpace(valueSearchString)) { searchRequest.AppendSearchParam(association.EntityAssociation.PrimaryAttribute().To); searchRequest.AppendSearchValue("%" + valueSearchString + "%"); } if (!String.IsNullOrWhiteSpace(request.LabelSearchString)) { AppendSearchLabelString(request, association, searchRequest); } } return(searchRequest); }
public override void ExecuteJob() { var lowerRowstamp = ConfigFacade.Lookup <long>(ConfigurationConstants.R0042Rowstamp); var now = DateTime.Now; now = new DateTime(now.Year, now.Month, 1); var lastMonth = DateUtil.BeginOfDay(now.AddMonths(-1)); var beginOfMonth = DateUtil.BeginOfDay(now); var compMetadata = MetadataProvider.Application("asset"); var schema = compMetadata.Schemas()[new ApplicationMetadataSchemaKey("R0042Export")]; var slicedMetadata = MetadataProvider.SlicedEntityMetadata(schema.GetSchemaKey(), "asset"); var dto = new PaginatedSearchRequestDto { PageSize = PageSize }; var needsMore = true; var initOfBatch = true; var i = 1; while (needsMore) { Log.InfoFormat("R0042: fetching first {0} items restricted to rowstamp {1}".Fmt(i * PageSize, lowerRowstamp)); var searchEntityResult = FetchMore(dto, lastMonth, slicedMetadata, lowerRowstamp, initOfBatch); IList <R0042AssetHistory> items = ConvertItems(searchEntityResult.ResultList, beginOfMonth); if (!items.Any()) { break; } DAO.BulkSave(items); var greatestRowstamp = items[items.Count - 1].Rowstamp; //there´s at least one extra item, but could be thousands needsMore = items.Count == PageSize; i++; if (greatestRowstamp.HasValue) { ConfigFacade.SetValue(ConfigurationConstants.R0042Rowstamp, greatestRowstamp); Log.InfoFormat("R0042: updating rowstamp to {0}".Fmt(greatestRowstamp.Value)); lowerRowstamp = greatestRowstamp.Value; } initOfBatch = false; } }
public void DateSearchDtoTest() { var searchRequestDto = new PaginatedSearchRequestDto(100, PaginatedSearchRequestDto.DefaultPaginationOptions); searchRequestDto.SetFromSearchString(_schema, "ticketid,description,asset_.description,siteid,affectedperson,status,reportdate".Split(','), "2013-01-01"); Assert.IsNotNull(searchRequestDto); Assert.IsTrue(searchRequestDto.SearchParams.Equals("reportdate")); Assert.IsTrue(searchRequestDto.SearchValues.Equals("2013-01-01")); String whereClause = SearchUtils.GetWhere(searchRequestDto, "SR"); Assert.IsTrue(whereClause.Equals("( SR.reportdate BETWEEN :reportdate_begin AND :reportdate_end )")); IDictionary <String, Object> parametersMap = SearchUtils.GetParameters(searchRequestDto); Assert.IsTrue(parametersMap.Count == 2); Assert.IsTrue(parametersMap["reportdate_begin"].Equals(DateUtil.BeginOfDay(DateTime.Parse("2013-01-01")))); Assert.IsTrue(parametersMap["reportdate_end"].Equals(DateUtil.EndOfDay(DateTime.Parse("2013-01-01")))); }
private EntityRepository.SearchEntityResult FetchMore(PaginatedSearchRequestDto dto, DateTime lastMonth, SlicedEntityMetadata slicedMetadata, long?lowerRowstamp, Boolean initofBatch) { dto.AppendSearchEntry("status", "!=DECOMMISSIONED"); dto.AppendSearchEntry("changedate", ">=" + lastMonth.ToShortDateString()); if (initofBatch) { dto.AppendSearchEntry("rowstamp", ">" + lowerRowstamp); } else { dto.AppendSearchEntry("rowstamp", ">=" + lowerRowstamp); } dto.SearchSort = "rowstamp asc"; dto.QueryAlias = "R0042"; var searchEntityResult = _entityRepository.GetAsRawDictionary(slicedMetadata, dto, false); return(searchEntityResult); }
public IApplicationResponse RedirectToNextSchema(ApplicationMetadata applicationMetadata, string operation, string id, ClientPlatform platform, ApplicationMetadataSchemaKey currentschemaKey, ApplicationMetadataSchemaKey nextSchemaKey, bool maximoMocked = false) { var applicationName = applicationMetadata.Name; if (nextSchemaKey == null) { if (HasActionRedirectionDefinedByProperties(applicationMetadata.Schema, operation)) { return(ActionRedirection(applicationMetadata.Schema, operation)); } nextSchemaKey = ResolveNextSchemaKey(operation, currentschemaKey, platform, applicationMetadata); } // var applicationName = currentMetadata.Name; var metadata = MetadataProvider.Application(applicationName); var resultSchema = metadata.Schema(nextSchemaKey, true); var user = SecurityFacade.CurrentUser(); var nextMetadata = metadata.ApplyPolicies(nextSchemaKey, user, ClientPlatform.Web); var dataSet = _dataSetProvider.LookupAsBaseDataSet(applicationName); if (resultSchema.Stereotype == SchemaStereotype.Detail) { if (maximoMocked && id == null) { return(mockUtils.GetMockedDataMap(applicationName, resultSchema, nextMetadata)); } var detailRequest = new DetailRequest(nextSchemaKey, null) { Id = id }; detailRequest.CompositionsToFetch = operation != OperationConstants.CRUD_CREATE ? "#all" : null; var response = dataSet.Get(nextMetadata, SecurityFacade.CurrentUser(), detailRequest); return(response); } if (resultSchema.Stereotype == SchemaStereotype.List) { var paginatedSearchRequestDto = PaginatedSearchRequestDto.DefaultInstance(resultSchema); return(dataSet.Get(nextMetadata, user, new DataRequestAdapter(paginatedSearchRequestDto))); } throw new NotImplementedException("missing implementation for this kind of schema redirection"); }
private ApplicationListResult R0042Export(ApplicationMetadata application, PaginatedSearchRequestDto dto) { var refDate = dto.SearchValues; var dates = refDate.Split('/'); // comes as 04/2018 var newDto = new PaginatedSearchRequestDto { NeedsCountUpdate = false }; var year = int.Parse(dates[1]); var month = int.Parse(dates[0]); var extractionDate = new DateTime(year, month, 1); newDto.AppendWhereClauseFormat("month(asset.changedate) = {0} and year(asset.changedate) = {1}", month, year); newDto.AppendSearchEntry("status", "!=DECOMMISSIONED"); var dbList = base.GetList(application, newDto); if (!dbList.ResultObject.Any()) { return(dbList); } var map = R0042QueryHelper.BuildIdMap(dbList); var assetIds = map.Keys.Select(s => s.AssetId).ToList(); var assetNums = map.Keys.Select(s => s.AssetNum).ToList(); var historicData = GetDAO().FindByNativeQuery( "select * from HIST_ASSETR0042 m inner join (select assetid,max(extractiondate) as max_date from HIST_ASSETR0042 where assetid in (:p0) and ExtractionDate <= :p1 group by assetid)i on (m.assetid = i.assetid and m.extractiondate = i.max_date) where m.assetid in (:p0) and m.extractiondate <= :p1", assetIds, extractionDate); var imacDataSet = GetImacDataSet(); var imacs = imacDataSet.GetClosedImacIdsForR0042(assetNums, month, year); R0042QueryHelper.MergeImacData(map, imacs); R0042QueryHelper.MergeData(map, historicData); return(dbList); }
//for each assetnum/site tuple the public IDictionary <R0042AssetKey, ISet <string> > GetClosedImacIdsForR0042(List <string> assetIds, int month, int year) { var result = new Dictionary <R0042AssetKey, ISet <string> >(); var compAppMetadata = MetadataProvider.Application(ApplicationName()); var dto = new PaginatedSearchRequestDto { NeedsCountUpdate = false }; dto.ProjectionFields.Add(ProjectionField.Default("ticketid")); dto.ProjectionFields.Add(ProjectionField.Default("ticketuid")); dto.ProjectionFields.Add(ProjectionField.Default("assetnum")); dto.ProjectionFields.Add(ProjectionField.Default("siteid")); dto.ProjectionFields.Add(ProjectionField.Default("woactivity_.OWNERGROUP")); dto.AppendWhereClauseFormat("woactivity_.OWNERGROUP = 'I-EUS-DE-CSC-SDK-ASSET' and month(woactivity_.ACTFINISH) = {0} and year(woactivity_.ACTFINISH) = {1} and imac.assetnum in ({2})", month, year, BaseQueryUtil.GenerateInString(assetIds)); var entityMetadata = MetadataProvider.SlicedEntityMetadata(new ApplicationMetadataSchemaKey("detail"), "imac"); var searchEntityResult = EntityRepository.GetAsRawDictionary(entityMetadata, dto); foreach (var imac in searchEntityResult.ResultList) { var key = new R0042AssetKey { AssetNum = imac["assetnum"].ToString(), SiteId = imac["siteid"].ToString() }; if (result.ContainsKey(key)) { result[key].Add(imac["ticketid"].ToString()); } else { result[key] = new HashSet <string> { imac["ticketid"].ToString() }; } } return(result); }
public IApplicationResponse Get(ApplicationMetadata application, InMemoryUser user, IDataRequest request) { var adapter = request as DataRequestAdapter; if (adapter != null) { if (adapter.SearchDTO != null) { request = adapter.SearchDTO; } else if (adapter.Id != null) { request = DetailRequest.GetInstance(application, adapter); } } if (request is PaginatedSearchRequestDto) { return(GetList(application, (PaginatedSearchRequestDto)request)); } if (request is DetailRequest) { try { return(GetApplicationDetail(application, user, (DetailRequest)request)); } catch (InvalidOperationException e) { return(new ApplicationDetailResult(null, null, application.Schema, null, ((DetailRequest)request).Id)); } } if (application.Schema.Stereotype == SchemaStereotype.List) { return(GetList(application, PaginatedSearchRequestDto.DefaultInstance(application.Schema))); } if (application.Schema.Stereotype == SchemaStereotype.Detail || request.Key.Mode == SchemaMode.input) { //case of detail of new items return(GetApplicationDetail(application, user, DetailRequest.GetInstance(application, adapter))); } throw new InvalidOperationException("could not determine which operation to take upon request"); }
public IEnumerable <IAssociationOption> GetAssetCommodities(OptionFieldProviderParameters parameters) { var assetnum = parameters.OriginalEntity.GetAttribute("asset") as String; var user = SecurityFacade.CurrentUser(); //TODO: Improve this query var applicationMetadata = MetadataProvider .Application("commodities") .ApplyPolicies(new ApplicationMetadataSchemaKey("detail"), user, ClientPlatform.Web); var entityMetadata = MetadataProvider.SlicedEntityMetadata(applicationMetadata); var searchDto = new PaginatedSearchRequestDto(100, PaginatedSearchRequestDto.DefaultPaginationOptions); searchDto.AppendSearchEntry("commodity", new[] { "HLC-0003", "HLC-0005", "HLC-0006", "HLC-0007", "HLC-0008", "HLC-0786" }); // This value is added due to a inserted parameter in a relatioship clause (from 'commodities' to 'assetloccomm') searchDto.ValuesDictionary["commodityassetnum"] = new SearchParameter(assetnum); var entities = _maximoConnectorEngine.Find(entityMetadata, searchDto); var options = new HashSet <IAssociationOption>(); foreach (var commodity in entities) { var desc = commodity.GetAttribute("description") as String; var isSelected = commodity.GetAttribute("selectedcommodities_.assetnum") != null; if (!String.IsNullOrWhiteSpace(desc)) { options.Add(new MultiValueAssociationOption(desc, desc, new Dictionary <string, object> { { "isSelected", isSelected } })); } } return(options); }
public FileContentResult Export(string application, [FromUri] ApplicationMetadataSchemaKey key, [FromUri] PaginatedSearchRequestDto searchDTO, string module) { searchDTO.PageSize = searchDTO.TotalCount + 1; if (module != null) { _contextLookuper.LookupContext().Module = module; } var before = Stopwatch.StartNew(); var before2 = Stopwatch.StartNew(); var user = SecurityFacade.CurrentUser(); var applicationMetadata = MetadataProvider .Application(application) .ApplyPolicies(key, user, ClientPlatform.Web); var dataResponse = _dataController.Get(application, new DataRequestAdapter { Key = key, SearchDTO = searchDTO }); Log.Debug(LoggingUtil.BaseDurationMessageFormat(before, "finished gathering export excel data")); var excelBytes = _excelUtil.ConvertGridToExcel(user, applicationMetadata.Schema, ((ApplicationListResult)dataResponse).ResultObject); Log.Info(LoggingUtil.BaseDurationMessageFormat(before2, "finished export excel data")); var fileName = GetFileName(application, key.SchemaId) + ".xls"; var result = new FileContentResult(excelBytes, System.Net.Mime.MediaTypeNames.Application.Octet) { FileDownloadName = (string)StringUtil.FirstLetterToUpper(fileName) }; return(result); }
public Dictionary <string, EntityRepository.SearchEntityResult> ResolveCollections(SlicedEntityMetadata entityMetadata, IDictionary <string, ApplicationCompositionSchema> compositionSchemas, AttributeHolder mainEntity, PaginatedSearchRequestDto paginatedSearch = null) { return(ResolveCollections(entityMetadata, compositionSchemas, new List <AttributeHolder> { mainEntity }, paginatedSearch)); }
public Dictionary <string, EntityRepository.SearchEntityResult> ResolveCollections(SlicedEntityMetadata entityMetadata, IDictionary <string, ApplicationCompositionSchema> compositionSchemas, IReadOnlyList <AttributeHolder> entitiesList, PaginatedSearchRequestDto paginatedSearch = null) { if (!compositionSchemas.Any()) { return(new Dictionary <string, EntityRepository.SearchEntityResult>()); } var before = Stopwatch.StartNew(); _log.DebugFormat("Init Collection Resolving for {0} Collections", String.Join(",", compositionSchemas.Keys)); var collectionAssociations = new List <EntityAssociation>(); foreach (var entityListAssociation in entityMetadata.ListAssociations()) { if (compositionSchemas.Keys.Contains(entityListAssociation.Qualifier)) { collectionAssociations.Add(entityListAssociation); } } var results = new Dictionary <string, EntityRepository.SearchEntityResult>(); var tasks = new Task[collectionAssociations.Count]; var i = 0; var ctx = ContextLookuper.LookupContext(); foreach (var collectionAssociation in collectionAssociations) { var association = collectionAssociation; var shouldPaginate = ShouldPaginate(compositionSchemas[association.Qualifier], paginatedSearch) && paginatedSearch != null; var perThreadPaginatedSearch = shouldPaginate ? (PaginatedSearchRequestDto)paginatedSearch.ShallowCopy() : null; //this will avoid that one thread impacts any other var perThreadContext = ctx.ShallowCopy(); tasks[i++] = Task.Factory.NewThread(() => FetchAsync(entityMetadata, association, compositionSchemas, entitiesList, perThreadContext, results, perThreadPaginatedSearch)); } Task.WaitAll(tasks); _log.Debug(LoggingUtil.BaseDurationMessageFormat(before, "Finish Collection Resolving for {0} Collections", String.Join(",", compositionSchemas.Keys))); return(results); }
private SearchRequestDto BuildSearchRequestDto(ApplicationCompositionCollectionSchema applicationCompositionSchema, IEnumerable <EntityAssociationAttribute> lookupattributes, CollectionMatchingResultWrapper matchingResultWrapper, AttributeHolder[] attributeHolders, EntityMetadata collectionEntityMetadata, PaginatedSearchRequestDto paginatedSearch) { var searchRequestDto = (paginatedSearch == null || paginatedSearch.PageSize <= 0) ? new SearchRequestDto() : new PaginatedSearchRequestDto(); searchRequestDto.BuildProjection(applicationCompositionSchema, ContextLookuper.LookupContext().PrintMode); foreach (var lookupAttribute in lookupattributes) { if (lookupAttribute.From != null) { matchingResultWrapper.AddKey(lookupAttribute.To); BuildParentQueryConstraint(matchingResultWrapper, attributeHolders, lookupAttribute, searchRequestDto); } else if (lookupAttribute.Literal != null) { //if the from is a literal, don´t bother with the entities values searchRequestDto.AppendSearchEntry(lookupAttribute.To, lookupAttribute.Literal); } else if (lookupAttribute.Query != null) { searchRequestDto.AppendWhereClause(lookupAttribute.GetQueryReplacingMarkers(collectionEntityMetadata.Name)); } } var orderByField = applicationCompositionSchema.CollectionProperties.OrderByField; if (orderByField != null) { searchRequestDto.SearchSort = orderByField; searchRequestDto.SearchAscending = !orderByField.EndsWith("desc"); } // no pagination intended: return simple search var paginatedDTO = searchRequestDto as PaginatedSearchRequestDto; if (paginatedDTO == null || paginatedSearch == null) { return(searchRequestDto); } // pagination: merging the search dto's paginatedDTO.PageNumber = paginatedSearch.PageNumber; paginatedDTO.PageSize = paginatedSearch.PageSize; paginatedDTO.TotalCount = paginatedSearch.TotalCount; return(searchRequestDto); }