public void TestSelect2()
        {
            var sliced = SlicedEntityMetadataBuilder.GetInstance(MetadataProvider.Entity("asset"), _schema);
            var select = QuerySelectBuilder.BuildSelectAttributesClause(sliced, QueryCacheKey.QueryMode.List);

            Debug.Write(select);
            Assert.IsTrue(select.Contains("location_shipto_.address1 as \"location_shipto_.address1\""));
            Assert.IsTrue(select.Contains("location_billto_.address1 as \"location_billto_.address1\""));
            Assert.IsTrue(select.Contains("location_serv_.address1 as \"location_serv_.address1\""));
        }
        public void TestAssetListReportBug()
        {
            var schemas = MetadataProvider.Application("asset").Schemas();
            var schema  = schemas[new ApplicationMetadataSchemaKey("assetlistreport", null, "web")];
            var sliced  = SlicedEntityMetadataBuilder.GetInstance(MetadataProvider.Entity("asset"), schema);
            var select  = QuerySelectBuilder.BuildSelectAttributesClause(sliced, QueryCacheKey.QueryMode.List);

            Debug.Write(select);
            Assert.IsTrue(select.Contains("CASE WHEN LOCATE('@',aucisowner_.PERSONID) > 0 THEN SUBSTR(aucisowner_.PERSONID,1,LOCATE('@',aucisowner_.PERSONID)-1) ELSE aucisowner_.PERSONID END as \"aucisowner_.hlagdisplayname\""));
        }
        public void TestSelect3()
        {
            var schemas = MetadataProvider.Application("change").Schemas();
            var schema  = schemas[new ApplicationMetadataSchemaKey("detail", null, "web")];
            var sliced  = SlicedEntityMetadataBuilder.GetInstance(MetadataProvider.Entity("wochange"), schema);
            var select  = QuerySelectBuilder.BuildSelectAttributesClause(sliced, QueryCacheKey.QueryMode.Detail);

            Debug.Write(select);
            Assert.IsFalse(select.Contains("sr_asset_.installdate"));
            Assert.IsTrue(select.Contains("sr_asset_.serialnum"));
        }
        public void ChangeSRUnionSearch()
        {
            var dto         = new SearchRequestDto();
            var completeOne = MetadataProvider.Application("srforchange");
            var metadata    = completeOne.ApplyPolicies(new ApplicationMetadataSchemaKey("changeunionschema"), InMemoryUser.TestInstance(),
                                                        ClientPlatform.Web);
            ApplicationSchemaDefinition schema;
            var sliced = SlicedEntityMetadataBuilder.GetInstance(MetadataProvider.Entity("srforchange"), metadata.Schema);
            var result = QueryFromBuilder.Build(sliced, dto);

            Assert.AreEqual("from SR as srforchange left join asset as asset_ on (srforchange.assetnum = asset_.assetnum and srforchange.siteid = asset_.siteid)", result);
        }
        public void TestSelectNullAttributes()
        {
            var schemas = MetadataProvider.Application("srforchange").Schemas();
            var schema  = schemas[new ApplicationMetadataSchemaKey("changeunionschema", null, "web")];
            var sliced  = SlicedEntityMetadataBuilder.GetInstance(MetadataProvider.Entity("srforchange"), schema, 300, true);

            Assert.AreEqual(15, sliced.Attributes(EntityMetadata.AttributesMode.NoCollections).Count());
            var select = QuerySelectBuilder.BuildSelectAttributesClause(sliced, QueryCacheKey.QueryMode.List);

            Debug.Write(select);
            Assert.IsTrue(select.Contains("null"));
        }
        public void ChangeSRUnionSearch()
        {
            var dto = new SearchRequestDto();

            dto.BuildUnionDTO(dto, MetadataProvider.FindSchemaDefinition("change.list"));

            var completeOne = MetadataProvider.Application("change");
            var metadata    = completeOne.ApplyPolicies(new ApplicationMetadataSchemaKey("list"), InMemoryUser.TestInstance(),
                                                        ClientPlatform.Web);
            ApplicationSchemaDefinition schema;
            var sliced = SlicedEntityMetadataBuilder.GetInstance(MetadataProvider.Entity("wochange"), metadata.Schema, 300);
            var result = QuerySelectBuilder.BuildSelectAttributesClause(sliced.UnionSchema, QueryCacheKey.QueryMode.Union, dto.unionDTO);

            Assert.AreEqual("select null, null, null, null, '-666' as zeroedattr, srforchange.description as hlagchangesummary, srforchange.ticketid as ticketid, asset_.description as asset_description, null, null, CASE WHEN srforchange.PLUSPCUSTOMER IS NOT NULL AND srforchange.PLUSPCUSTOMER = 'HLC-00' then 'HLAG'  WHEN srforchange.PLUSPCUSTOMER IS NOT NULL AND LENGTH(srforchange.PLUSPCUSTOMER) >= 3 THEN SUBSTR(srforchange.PLUSPCUSTOMER, LENGTH(srforchange.PLUSPCUSTOMER) - 2, 3) ELSE '' END as hlagpluspcustomer, CASE WHEN LOCATE('@',srforchange.REPORTEDBY) > 0 THEN SUBSTR(srforchange.REPORTEDBY,1,LOCATE('@',srforchange.REPORTEDBY)-1) ELSE srforchange.REPORTEDBY END as hlagreportedby, srforchange.status as status ", result);
        }
        public void TestFrom()
        {
            var sliced = SlicedEntityMetadataBuilder.GetInstance(MetadataProvider.Entity("asset"), _schema);

            Assert.AreEqual(5, sliced.InnerMetadatas.Count);
            var from = QueryFromBuilder.Build(sliced);

            Debug.Write(from);
            Assert.IsTrue(from.Contains("address as location_shipto_"));
            Assert.IsTrue(from.Contains("address as location_billto_"));
            Assert.IsTrue(from.Contains("address as location_serv_"));
            Assert.IsTrue(from.Contains("on (location_.billtoaddresscode"));
            Assert.IsTrue(from.Contains("on (location_.shiptoaddresscode"));
            Assert.IsTrue(from.Contains("on (location_.serviceaddresscode"));
        }
        public void TestSelect4()
        {
            var schemas = MetadataProvider.Application("imac").Schemas();
            var schema  = schemas[new ApplicationMetadataSchemaKey("detail", "output", "web")];
            var sliced  = SlicedEntityMetadataBuilder.GetInstance(MetadataProvider.Entity("imac"), schema);
            var select  = QuerySelectBuilder.BuildSelectAttributesClause(sliced, QueryCacheKey.QueryMode.Detail);

            Debug.Write(select);
            Assert.IsFalse(select.Contains("case when imac.serialnum"));
            Assert.IsTrue(select.Contains("case when asset_.serialnum"));
            var from = QueryFromBuilder.Build(sliced, null);

//            Debug.Write(from);
            Assert.IsTrue(from.Contains("left join person as asset_aucisowner_person_ on (asset_aucisowner_.personid = asset_aucisowner_person_.personid)"));
        }
        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);
        }
Example #10
0
 private static void BuildSlicedMetadataCache()
 {
     SlicedEntityMetadataCache.Clear();
     foreach (var app in _applicationMetadata)
     {
         var entityName     = app.Entity;
         var entityMetadata = Entity(entityName);
         if (app.IsMobileSupported())
         {
             app.Schemas().Add(ApplicationMetadataSchemaKey.GetSyncInstance(),
                               ApplicationSchemaFactory.GetSyncInstance(app.ApplicationName, app.IdFieldName));
         }
         foreach (var webSchema in app.Schemas())
         {
             var schema = webSchema.Value;
             schema.DepandantFields(DependencyBuilder.BuildDependantFields(schema.Fields, schema.DependableFields));
             schema._fieldWhichHaveDeps = schema.DependantFields.Keys;
             var instance = SlicedEntityMetadataBuilder.GetInstance(entityMetadata, schema, app.FetchLimit);
             SlicedEntityMetadataCache[new SlicedEntityMetadataKey(webSchema.Key, entityName)] = instance;
         }
     }
 }