Example #1
0
        private static void BuildParentQueryConstraint(CollectionMatchingResultWrapper matchingResultWrapper,
                                                       AttributeHolder[] attributeHolders, EntityAssociationAttribute lookupAttribute,
                                                       SearchRequestDto searchRequestDto)
        {
            var searchValues  = new List <string>();
            var enumerable    = attributeHolders as AttributeHolder[] ?? attributeHolders.ToArray();
            var hasMainEntity = enumerable.Any();

            foreach (var entity in attributeHolders)
            {
                var key         = matchingResultWrapper.FetchKey(entity);
                var searchValue = SearchUtils.GetSearchValue(lookupAttribute, entity);
                if (!String.IsNullOrWhiteSpace(searchValue) && lookupAttribute.To != null)
                {
                    searchValues.Add(searchValue);
                    key.AppendEntry(lookupAttribute.To, searchValue);
                }
            }
            if (searchValues.Any())
            {
                searchRequestDto.AppendSearchEntry(lookupAttribute.To, searchValues);
            }
            else if (hasMainEntity && lookupAttribute.Primary)
            {
                //if nothing was provided, it should return nothing, instead of all the values -->
                //if the main entity had a null on a primary element of the composition, nothing should be seen
                searchRequestDto.AppendSearchEntry(lookupAttribute.To, new[] { "-1231231312" });
            }
        }
        public void TestRelationshipQuery()
        {
            var dto = new SearchRequestDto();

            dto.AppendProjectionField(ProjectionField.Default("description"));
            dto.AppendSearchEntry("status", "('120 Active','OPERATING')");
            dto.AppendSearchEntry("usercustodianuser_.personid", "xxx");
            var result = QueryFromBuilder.Build(MetadataProvider.Entity("asset"), dto);

            Assert.AreEqual("from asset as asset left join AssetUserCust as usercustodianuser_ on (asset.assetnum = usercustodianuser_.assetnum and asset.siteid = usercustodianuser_.siteid and usercustodianuser_.isuser = 1)", result);
        }
        internal static SearchRequestDto BuildDTO()
        {
            var dto = new SearchRequestDto {
                SearchSort      = "computername",
                SearchAscending = true,
                QueryAlias      = "rI102"
            };

            dto.AppendWhereClause("upper(ASSET.STATUS) = '{0}'".Fmt(AssetConstants.Active.ToUpper()));
            dto.AppendSearchEntry("upper_computername", "P%");


            var configFilePath = MetadataProvider.GlobalProperty("RI102Path");

            if (!File.Exists(configFilePath))
            {
                return(dto);
            }
            var fileLines = File.ReadAllLines(configFilePath);

            var sb = ClassStructureConfigFileReader.DoBuildQuery(fileLines);

            dto.AppendWhereClause(sb);
            return(dto);
        }
        public void TestRelationshipQuery3Levels()
        {
            var dto = new SearchRequestDto();

            dto.AppendSearchEntry("asset_aucisowner_person_.hlagdisplayname", "xxx");
            var result = QueryFromBuilder.Build(MetadataProvider.Entity("imac"), dto);

            Assert.AreEqual("from SR as imac left join asset as asset_ on (imac.assetnum = asset_.assetnum and imac.siteid = asset_.siteid)left join AssetUserCust as asset_aucisowner_ on (asset_.assetnum = asset_aucisowner_.assetnum and asset_aucisowner_.itdassetrole = 'Owner' and asset_aucisowner_.isuser = 1)left join person as asset_aucisowner_person_ on (asset_aucisowner_.personid = asset_aucisowner_person_.personid)", result);
        }
        public void TestRelationshipQueryField()
        {
            var dto = new SearchRequestDto();

            dto.AppendSearchEntry("aucisnotowner_.personid", "xxx");
            var result = QueryFromBuilder.Build(MetadataProvider.Entity("asset"), dto);

            Assert.AreEqual("from asset as asset left join AssetUserCust as aucisnotowner_ on (asset.assetnum = aucisnotowner_.assetnum and (aucisnotowner_.itdassetrole is null or aucisnotowner_.itdassetrole !='Owner') and aucisnotowner_.isuser = 1)", result);
        }
Example #6
0
        private static SearchRequestDto GetPersonGroupSearchDTO()
        {
            var dto = new SearchRequestDto();

            dto.AppendSearchEntry(PersonGroupColumn, HapagPersonGroupConstants.BaseHapagPrefix);
            dto.AppendProjectionField(ProjectionField.Default(PersonGroupColumn));
            dto.AppendProjectionField(ProjectionField.Default(PersonIdColumn));
            dto.AppendProjectionField(ProjectionField.Default("rowstamp"));
            dto.AppendProjectionField(ProjectionField.Default("rowstamp1"));
            return(dto);
        }
Example #7
0
        private IEnumerable <IAssociationOption> GetRoom(string location, string building, string floor)
        {
            var dto = new SearchRequestDto();

            dto.AppendSearchEntry("LOCATION", building + "/FL:" + floor + "/RO:%");
            return(BuildingFloorRoomManager.DoGetLocation(location, dto, dict => {
                var rawValue = (String)dict["location"];
                //TODO: fix label
                return new AssociationOption(rawValue, rawValue.Split(new[] { "RO:" }, StringSplitOptions.None)[1]);
            }));
        }
        public static IEnumerable <IAssociationOption> DoGetLocation(string location, SearchRequestDto dto, LocationFieldDelegate delegateToUse)
        {
            var locationApp    = MetadataProvider.Application("location");
            var entityMetadata = MetadataProvider.SlicedEntityMetadata(locationApp.ApplyPolicies(new ApplicationMetadataSchemaKey("list"), SecurityFacade.CurrentUser(), ClientPlatform.Web));

//            dto.PageSize = 10000;
            dto.AppendSearchEntry("pluspcustomer", "%" + location);
            dto.AppendSearchEntry("status", "!=DECOMMISSIONED");
            dto.AppendSearchEntry("TYPE", "OPERATING");
            dto.SearchSort        = "location";
            dto.SearchAscending   = true;
            dto.IgnoreWhereClause = true;
            var result  = EntityRepository.GetAsRawDictionary(entityMetadata, dto);
            var options = new HashSet <IAssociationOption>();

            foreach (var attributeHolder in result.ResultList)
            {
                options.Add(delegateToUse.Invoke(attributeHolder));
            }
            return(options);
        }
Example #9
0
        public IEnumerable <FaqData> GetList()
        {
            var dto = new SearchRequestDto();

            dto.AppendSearchEntry("pluspinsertcustomer", "HLC-%");
            dto.AppendSearchEntry("status", "ACTIVE");
            dto.AppendProjectionField(ProjectionField.Default("solutionid"));
            dto.AppendProjectionField(ProjectionField.Default("description"));
            var result           = EntityRepository.GetAsRawDictionary(MetadataProvider.Entity("solution"), dto);
            var attributeHolders = result.ResultList;

            Log.DebugFormat("db size {0}", attributeHolders.Count());
            var treeDataList = new List <FaqData>();

            foreach (var attributeHolder in attributeHolders)
            {
                var solutionId  = (int)attributeHolder["solutionid"];
                var description = (string)attributeHolder["description"];
                treeDataList.Add(new FaqData(solutionId, description));
            }
            Log.DebugFormat("returned list size {0}", treeDataList.Count());
            return(treeDataList);
        }
Example #10
0
        private IEnumerable <IAssociationOption> GetFloor(string location, string building)
        {
            var dto = new SearchRequestDto();

            dto.AppendSearchEntry("LOCATION", building + "/FL:%");
            dto.AppendProjectionField(new ProjectionField("location", String.Format("DISTINCT SUBSTR(REPLACE(location.Location,'{0}',''),1,LOCATE('/',REPLACE(location.Location,'{0}',''))-1)", building + "/FL:")));
            dto.SearchSort      = "location";
            dto.ExpressionSort  = true;
            dto.SearchAscending = true;
            return(BuildingFloorRoomManager.DoGetLocation(location, dto, dict => {
                var rawValue = (String)dict["location"];
                return new AssociationOption(rawValue, rawValue);
            }));
        }
Example #11
0
        private IEnumerable <IAssociationOption> GetBuilding(string location)
        {
            var dto = new SearchRequestDto();

            dto.AppendSearchEntry("CLASSSTRUCTUREID", "BUILDING");
            dto.AppendProjectionField(ProjectionField.Default("description"));
            dto.AppendProjectionField(ProjectionField.Default("location"));
            return(BuildingFloorRoomManager.DoGetLocation(location, dto, dict => {
                var rawLabel = (String)dict["description"];
                var rawValue = (String)dict["location"];
                //TODO: fix label
                return new AssociationOption(rawValue.Split('/')[0], rawLabel);
            }));
        }
        protected SearchRequestDto AssetByLocationCondition(SearchRequestDto searchDTO, string fromLocation, ApplicationMetadata metadata)
        {
            if (String.IsNullOrWhiteSpace(fromLocation))
            {
                throw ExceptionUtil.InvalidOperation("from location parameter should not be null");
            }
            searchDTO.IgnoreWhereClause = true;
            var locations = LocationManager.FindAllLocationsOfCurrentUser(metadata);
            var location  = locations.FirstOrDefault(l => l.SubCustomer.Contains(fromLocation));

            if (location == null)
            {
                throw ExceptionUtil.InvalidOperation("current user can not access location {0}", fromLocation);
            }

            searchDTO.AppendSearchEntry(ISMConstants.PluspCustomerColumn, "%" + fromLocation);
            searchDTO.AppendWhereClause(location.CostCentersForQuery("asset.glaccount"));
            return(searchDTO);
        }
Example #13
0
        private void AppendLocationCondition(SearchRequestDto searchDTO, string fromLocation, string schema, bool childAsset, bool isNew, ApplicationMetadata applicationMetadata)
        {
            if (String.IsNullOrWhiteSpace(fromLocation))
            {
                throw ExceptionUtil.InvalidOperation("from location parameter should not be null");
            }
            //here we should indeed ignore the whereclauses, since the user can select assets which are not currently under his domain
            var locations = LocationManager.FindAllLocationsOfCurrentUser(applicationMetadata);
            var location  = locations.FirstOrDefault(l => l.SubCustomer.Contains(fromLocation));

            if (location == null)
            {
                throw ExceptionUtil.InvalidOperation("current user can not access location {0}", fromLocation);
            }
            searchDTO.AppendSearchEntry(ISMConstants.PluspCustomerColumn, "%" + fromLocation);

            if (childAsset && (schema.StartsWith(ImacConstants.Remove) || (schema.EqualsAny(ImacConstants.Replace) && !isNew)))
            {
                //HAP-827 impl --> child assets of remove, or "old child assets" of replace should ignore R0017
                searchDTO.IgnoreWhereClause = true;
            }
        }
        public void Sync()
        {
            var rowstamp = ConfigFacade.Lookup <long>(ConfigurationConstants.PersonGroupRowstampKey);
            var dto      = new SearchRequestDto();

            //let´s search just for persongroups that begin with the prefix
            dto.AppendSearchEntry(PersonGroupColumn, HapagPersonGroupConstants.BaseHapagPrefix);
            //ignoring rowstamp cache due to the fact that Maximo rowstamps got wrong
            //fetch all
            var personGroup      = FetchNew(0L, EntityName, dto);
            var attributeHolders = personGroup as AttributeHolder[] ?? personGroup.ToArray();

            if (!attributeHolders.Any())
            {
                //nothing to update
                return;
            }
            var personGroupToSave = ConvertMaximoPersonGroupToPersonGroupEntity(attributeHolders);
            var resultList        = _hlagLocationManager.UpdateCacheOnSync(personGroupToSave);

            _hlagLocationManager.UpdateCache(resultList);
            SetRowstampIfBigger(ConfigurationConstants.PersonGroupRowstampKey, GetLastRowstamp(attributeHolders), rowstamp);
        }
        //TODO: add locale,and format options
        public IDictionary <string, BaseAssociationUpdateResult> BuildAssociationOptions(AttributeHolder dataMap, ApplicationMetadata application, IAssociationPrefetcherRequest request)
        {
            var associationsToFetch = AssociationHelper.BuildAssociationsToPrefetch(request, application.Schema);

            if (associationsToFetch.IsNone)
            {
                return(new Dictionary <string, BaseAssociationUpdateResult>());
            }


            IDictionary <string, BaseAssociationUpdateResult> associationOptionsDictionary = new ConcurrentDictionary <string, BaseAssociationUpdateResult>();
            var before = LoggingUtil.StartMeasuring(Log, "starting association options fetching for application {0} schema {1}", application.Name, application.Schema.Name);

            var associations = application.Schema.Associations;
            var tasks        = new List <Task>();
            var ctx          = ContextLookuper.LookupContext();

            #region associations

            foreach (var applicationAssociation in associations)
            {
                if (!associationsToFetch.ShouldResolve(applicationAssociation.AssociationKey))
                {
                    Log.Debug("ignoring association fetching: {0}".Fmt(applicationAssociation.AssociationKey));
                    continue;
                }

                //only resolve the association options for non lazy associations or lazy loaded with value set.
                SearchRequestDto search;
                if (!applicationAssociation.IsLazyLoaded())
                {
                    search = new SearchRequestDto();
                }
                else if (dataMap != null && dataMap.GetAttribute(applicationAssociation.Target) != null)
                {
                    //if the field has a value, fetch only this single element, for showing eventual extra label fields... ==> lookup with a selected value
                    search = new SearchRequestDto();
                    var toAttribute    = applicationAssociation.EntityAssociation.PrimaryAttribute().To;
                    var prefilledValue = dataMap.GetAttribute(applicationAssociation.Target).ToString();
                    search.AppendSearchEntry(toAttribute, prefilledValue);
                }
                else
                {
                    //lazy association with no default value
                    continue;
                }
                var association = applicationAssociation;

                tasks.Add(Task.Factory.NewThread(c => {
                    //this will avoid that one thread impacts any other, for ex: changing metadataid of the query
                    var perThreadContext = ctx.ShallowCopy();
                    Quartz.Util.LogicalThreadContext.SetData("context", perThreadContext);
                    var associationOptions = _associationOptionResolver.ResolveOptions(application, dataMap, association, search);
                    associationOptionsDictionary.Add(association.AssociationKey, new BaseAssociationUpdateResult(associationOptions));
                }, ctx));
            }
            #endregion

            #region optionfields
            foreach (var optionField in application.Schema.OptionFields)
            {
                if (!associationsToFetch.ShouldResolve(optionField.AssociationKey))
                {
                    Log.Debug("ignoring association fetching: {0}".Fmt(optionField.AssociationKey));
                    continue;
                }

                if (optionField.ProviderAttribute == null)
                {
                    //if there´s no provider, there´s nothing to do --> static list
                    continue;
                }
                var field = optionField;
                tasks.Add(Task.Factory.NewThread(c => {
                    Quartz.Util.LogicalThreadContext.SetData("context", c);
                    var associationOptions = _dynamicOptionFieldResolver.ResolveOptions(application, field, dataMap);
                    if (associationOptionsDictionary.ContainsKey(field.AssociationKey))
                    {
                        associationOptionsDictionary.Remove(field.AssociationKey);
                    }
                    associationOptionsDictionary.Add(field.AssociationKey, new BaseAssociationUpdateResult(associationOptions));
                }, ctx));
            }
            #endregion

            Task.WaitAll(tasks.ToArray());
            if (Log.IsDebugEnabled)
            {
                var keys = String.Join(",", associationOptionsDictionary.Keys.Where(k => associationOptionsDictionary[k].AssociationData != null));
                Log.Debug(LoggingUtil.BaseDurationMessageFormat(before, "Finished execution of options fetching. Resolved collections: {0}", keys));
            }


            return(associationOptionsDictionary);
        }