예제 #1
0
        public IEnumerable <IAssociationOption> FindDefaultITCsOfLocation(string subcustomer)
        {
            var dto = new SearchRequestDto();

            dto.AppendProjectionField(ProjectionField.Default("personid"));
            dto.AppendProjectionField(ProjectionField.Default("hlagdisplayname"));
            var groupNameToQuery = HapagPersonGroupConstants.BaseHapagLocationPrefix + subcustomer + "%";

            dto.AppendWhereClauseFormat("personid in (select personid from persongroupview where persongroup like '{0}' and groupdefault=1)", groupNameToQuery);

            var persons = _repository.Get(_personEntity, dto);


            var result = new HashSet <ItcUser>();

            foreach (var user in persons)
            {
                var personId    = user.GetAttribute("personid") as string;
                var displayname = user.GetAttribute("hlagdisplayname") as string;
                result.Add(new ItcUser {
                    Label = displayname,
                    Value = personId
                });
            }
            return(result);
        }
예제 #2
0
        public void TestMethod1()
        {
            var dto = new SearchRequestDto();

            dto.AppendProjectionField(new ProjectionField("primaryuser_.personid,", "primaryuser_.personid"));
            dto.AppendProjectionField(new ProjectionField("primaryuser_person_.displayname", "primaryuser_person_.displayname"));
            var result = QueryFromBuilder.Build(MetadataProvider.Entity("asset"), dto);

            Assert.IsTrue(result.Contains("left join person as primaryuser_person_ on (primaryuser_.personid = primaryuser_person_.personid)"));
        }
예제 #3
0
        public void TestMethod1()
        {
            var dto = new SearchRequestDto();

            dto.AppendProjectionField(new ProjectionField("primaryuser_.personid", "primaryuser_.personid"));
            dto.AppendProjectionField(new ProjectionField("primaryuser_person_.displayname", "primaryuser_person_.displayname"));
            var result = QuerySelectBuilder.BuildSelectAttributesClause(MetadataProvider.Entity("asset"), QueryCacheKey.QueryMode.Detail, dto);

            Assert.IsTrue(result.Contains("primaryuser_.personid as primaryuser_personid, primaryuser_person_.displayname as primaryuser_person_displayname"));
        }
예제 #4
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);
        }
예제 #5
0
        public void TestReplace_Nulls()
        {
            var dto = new SearchRequestDto();

            dto.AppendProjectionField(ProjectionField.Default("#null1"));
            dto.AppendProjectionField(ProjectionField.Default("#null2"));
            //unmappped
            dto.AppendProjectionField(ProjectionField.Default("#attr"));
            dto.AppendProjectionField(ProjectionField.Default("description"));
            var result = QuerySelectBuilder.BuildSelectAttributesClause(MetadataProvider.Entity("sr"), QueryCacheKey.QueryMode.List, dto);

            Assert.AreEqual(("select null, null, SR.description as description "), result);
        }
예제 #6
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);
            }));
        }
예제 #7
0
        public void IncidentHardwareReport()
        {
            var dto = new SearchRequestDto();

            dto.AppendProjectionField(ProjectionField.Default("asset_assetloccomm_commoditiesownedby_.description"));
            dto.AppendProjectionField(ProjectionField.Default("asset_assetloccomm_.commodity"));

            var completeOne = MetadataProvider.Application("incident");
            var metadata    = completeOne.ApplyPolicies(new ApplicationMetadataSchemaKey("hardwarerepair"), InMemoryUser.TestInstance(),
                                                        ClientPlatform.Web);
            ApplicationSchemaDefinition schema;
            var sliced = SlicedEntityMetadataBuilder.GetInstance(MetadataProvider.Entity("incident"), metadata.Schema);
            var result = QueryFromBuilder.Build(sliced, dto);

            Assert.AreEqual("from incident as incident left join asset as asset_ on (incident.assetnum = asset_.assetnum and incident.siteid = asset_.siteid)left join assetloccomm as asset_assetloccomm_ on (asset_.assetnum = asset_assetloccomm_.assetnum and asset_.siteid = asset_assetloccomm_.siteid)left join commodities as asset_assetloccomm_commoditiesownedby_ on (asset_assetloccomm_.commodity = asset_assetloccomm_commoditiesownedby_.commodity and asset_assetloccomm_.itemsetid = asset_assetloccomm_commoditiesownedby_.itemsetid and (asset_assetloccomm_commoditiesownedby_.description like 'Asset owened by%'))", result);
        }
예제 #8
0
        public static SearchRequestDto BuildStdParentDTO()
        {
            var dto = new SearchRequestDto();

            dto.AppendProjectionField(ProjectionField.Default(ClassStructureIdColumn));
            dto.AppendWhereClause(StdClassificationPathParent);
            return(dto);
        }
예제 #9
0
        public void TestReplaceInner()
        {
            var dto = new SearchRequestDto();

            dto.AppendProjectionField(ProjectionField.Default("primaryuser_.person_.hlagdisplayname"));
            var result = QuerySelectBuilder.BuildSelectAttributesClause(MetadataProvider.Entity("asset"), QueryCacheKey.QueryMode.Detail, dto);

            Assert.AreEqual(("select CASE WHEN LOCATE('@',primaryuser_person_.PERSONID) > 0 THEN '(' || SUBSTR(primaryuser_person_.PERSONID,1,LOCATE('@',primaryuser_person_.PERSONID)-1) || ') ' || COALESCE(primaryuser_person_.DISPLAYNAME,'-- Name Not Set --') ELSE '(' || primaryuser_person_.PERSONID || ') ' || COALESCE(primaryuser_person_.DISPLAYNAME,'-- Name Not Set --') END as primaryuser_person_hlagdisplayname "), result);
        }
예제 #10
0
        public void TestReplace()
        {
            var dto = new SearchRequestDto();

            dto.AppendProjectionField(new ProjectionField("hlagdescription", "hlagdescription"));
            var result = QuerySelectBuilder.BuildSelectAttributesClause(MetadataProvider.Entity("asset"), QueryCacheKey.QueryMode.Detail, dto);

            Assert.IsTrue(result.Contains("CASE WHEN LOCATE('//',asset.Description) > 0 THEN LTRIM(RTRIM(SUBSTR(asset.Description, LOCATE('//', asset.Description)+3))) ELSE LTRIM(RTRIM(asset.Description)) END as hlagdescription"));
        }
예제 #11
0
        public void TestMethod2()
        {
            var dto = new SearchRequestDto();

            dto.AppendProjectionField(new ProjectionField("value", "assetnum"));
            var result = QuerySelectBuilder.BuildSelectAttributesClause(MetadataProvider.Entity("asset"), QueryCacheKey.QueryMode.Detail, dto);

            Assert.IsTrue(result.Contains("asset.assetnum as value"));
        }
예제 #12
0
        public void TestProjectionFieldWithQuery()
        {
            var dto = new SearchRequestDto();

            dto.AppendProjectionField(new ProjectionField("location", "DISTINCT SUBSTR(REPLACE(location.Location,'test',''),1,LOCATE('/',REPLACE(location.Location,'test',''))-1)"));
            var result = QuerySelectBuilder.BuildSelectAttributesClause(MetadataProvider.Entity("location"), QueryCacheKey.QueryMode.Detail, dto);

            Assert.AreEqual(("select DISTINCT SUBSTR(REPLACE(location.Location,'test',''),1,LOCATE('/',REPLACE(location.Location,'test',''))-1) as location "), result);
        }
예제 #13
0
        private static ProjectionResult BuildProjections(SearchRequestDto searchRequestDto, ApplicationAssociationDefinition association)
        {
            var valueField = association.EntityAssociation.PrimaryAttribute().To;

            // See if association has a schema defined
            var associationMetadata = GetAssociationApplicationMetadata(association);
            var valueKey            = ValueKeyConst;
            var fields = association.LabelFields;

            if (associationMetadata != null)
            {
                //if we have a schema then the projections should be all the fields out of it, except collections, instead of default labelfields
                var entityMetatada = MetadataProvider.SlicedEntityMetadata(associationMetadata);
                fields = entityMetatada.Attributes(EntityMetadata.AttributesMode.NoCollections).Select(a => a.Name).ToList();
            }

            foreach (var field in fields)
            {
                searchRequestDto.AppendProjectionField(new ProjectionField {
                    Alias = field, Name = field
                });
                if (field == valueField)
                {
                    valueKey = field;
                }
            }

            if (valueKey == ValueKeyConst)
            {
                searchRequestDto.AppendProjectionField(new ProjectionField {
                    Alias = ValueKeyConst, Name = valueField
                });
            }

            foreach (var extraField in association.ExtraProjectionFields)
            {
                searchRequestDto.AppendProjectionField(new ProjectionField {
                    Alias = extraField, Name = extraField
                });
            }
            return(new ProjectionResult(valueKey));
        }
예제 #14
0
        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);
        }
예제 #15
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);
        }
예제 #16
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);
            }));
        }
예제 #17
0
        public void TestInverseRelationship()
        {
//            var dto = new SearchRequestDto();
//            var completeOne = MetadataProvider.Application("change");
//            var metadata = completeOne.ApplyPolicies(new ApplicationMetadataSchemaKey("list"), InMemoryUser.TestInstance(),
//                ClientPlatform.Web);
//            ApplicationSchemaDefinition schema;
//            var sliced = SlicedEntityMetadataBuilder.GetInstance(MetadataProvider.Entity("change"), metadata.Schema);
//            var result = QueryFromBuilder.Build(MetadataProvider.Entity("wochange"), dto);

            var dto = new SearchRequestDto();

            dto.AppendProjectionField(ProjectionField.Default("sr_.description"));
            var result = QueryFromBuilder.Build(MetadataProvider.Entity("wochange"), dto);

            Assert.AreEqual("from wochange as wochange left join SR as sr_ on (wochange.origrecordid = sr_.ticketid and wochange.origrecordclass = 'SR' and wochange.woclass = 'CHANGE')", result);
        }
예제 #18
0
        public IEnumerable <IAssociationOption> FindCostCentersOfITC(string subCustomer, string personId = null)
        {
            string       costCentersToUse = "";
            InMemoryUser inMemoryUser     = null;

            if (personId == null)
            {
                personId     = SecurityFacade.CurrentUser().MaximoPersonId;
                inMemoryUser = SecurityFacade.CurrentUser();
            }

            costCentersToUse = BuildCostCentersFromMaximo(subCustomer, personId);

            if (costCentersToUse.Equals("1!=1"))
            {
                if (inMemoryUser == null)
                {
                    var user = _dao.FindSingleByQuery <User>(User.UserByMaximoPersonId, personId);
                    inMemoryUser = new InMemoryUser(user, new List <UserProfile>(), null);
                }
                //we´re interested in the current user, so we can assume its groups are synced fine.
                //pick the groups from SWDB
                var result  = FillUserLocations(inMemoryUser);
                var context = _contextLookuper.LookupContext();
                //if the user is not on XITC context, then we should pick just the costcenters directly bound to him (HAP-799)
                var locationsToUse = context.IsInModule(FunctionalRole.XItc)
                    ? result.GroupedLocations
                    : result.DirectGroupedLocations;
                var groupedLocation = locationsToUse.FirstOrDefault(f => f.SubCustomerSuffix == subCustomer);
                if (groupedLocation == null)
                {
                    return(null);
                }
                costCentersToUse = groupedLocation.CostCentersForQuery("glaccount");
            }

            var dto = new SearchRequestDto();

            dto.AppendProjectionField(new ProjectionField("accountname", "accountname"));
            dto.AppendProjectionField(new ProjectionField("glaccount", "glaccount"));
            dto.AppendProjectionField(new ProjectionField("displaycostcenter", "displaycostcenter"));

            dto.AppendWhereClause(costCentersToUse);

            var queryResult = _repository.Get(MetadataProvider.Entity("chartofaccounts"), dto);
            var options     = new HashSet <GenericAssociationOption>();

            foreach (var attributeHolder in queryResult)
            {
                var value = (String)attributeHolder.GetAttribute("glaccount");
                var label = (String)attributeHolder.GetAttribute("displaycostcenter");
                options.Add(new GenericAssociationOption(value, label));
            }

            //            if (options.Count == 0 && ApplicationConfiguration.IsDebug()) {
            //                options.Add(new GenericAssociationOption("6700-238-350", "6700/238/350//RMA+Prod+Contract Labor"));
            //                options.Add(new GenericAssociationOption("6690-810-300", "6690/810/300Inv//Shrinkage+Transit+Labor"));
            //                options.Add(new GenericAssociationOption("6700-300-300", "6700/300/300//Maint+Prod+Labor"));
            //            }

            return(options);
        }