Search in sources :

Example 51 with AttributeType

use of org.commongeoregistry.adapter.metadata.AttributeType in project geoprism-registry by terraframe.

the class DHIS2ServiceTest method exportCustomAttribute.

private void exportCustomAttribute(TestGeoObjectTypeInfo got, TestGeoObjectInfo go, TestAttributeTypeInfo attr) throws InterruptedException {
    DHIS2SyncLevel level2 = new DHIS2SyncLevel();
    level2.setGeoObjectType(got.getServerObject().getCode());
    level2.setSyncType(DHIS2SyncLevel.Type.ALL);
    level2.setLevel(1);
    Collection<DHIS2AttributeMapping> mappings = getDefaultMappings();
    DHIS2AttributeMapping mapping;
    if (attr.getType().equals(AttributeTermType.TYPE)) {
        mapping = new DHIS2TermAttributeMapping();
        mapping.setAttributeMappingStrategy(DHIS2TermAttributeMapping.class.getName());
        Map<String, String> terms = new HashMap<String, String>();
        terms.put(AllAttributesDataset.AT_GO_TERM.fetchRootAsClassifier().getClassifierId(), "TEST_EXTERNAL_ID");
        terms.put(AllAttributesDataset.TERM_TERM_VAL1.fetchClassifier().getClassifierId(), "TEST_EXTERNAL_ID");
        terms.put(AllAttributesDataset.TERM_TERM_VAL2.fetchClassifier().getClassifierId(), "TEST_EXTERNAL_ID");
        ((DHIS2TermAttributeMapping) mapping).setTerms(terms);
    } else {
        mapping = new DHIS2AttributeMapping();
        mapping.setAttributeMappingStrategy(DHIS2AttributeMapping.class.getName());
    }
    mapping.setCgrAttrName(attr.getAttributeName());
    mapping.setDhis2AttrName(attr.getAttributeName());
    mapping.setExternalId("TEST_EXTERNAL_ID");
    mappings.add(mapping);
    level2.setMappings(mappings);
    SynchronizationConfig config = createSyncConfig(this.system, level2);
    JsonObject jo = syncService.run(testData.clientSession.getSessionId(), config.getOid());
    ExportHistory hist = ExportHistory.get(jo.get("historyId").getAsString());
    SchedulerTestUtils.waitUntilStatus(hist.getOid(), AllJobStatus.SUCCESS);
    LinkedList<Dhis2Payload> payloads = this.dhis2.getPayloads();
    Assert.assertEquals(2, payloads.size());
    for (int level = 0; level < payloads.size(); ++level) {
        Dhis2Payload payload = payloads.get(level);
        JsonObject joPayload = JsonParser.parseString(payload.getData()).getAsJsonObject();
        JsonArray orgUnits = joPayload.get("organisationUnits").getAsJsonArray();
        Assert.assertEquals(1, orgUnits.size());
        JsonObject orgUnit = orgUnits.get(0).getAsJsonObject();
        Assert.assertEquals(level, orgUnit.get("level").getAsInt());
        Assert.assertEquals("MULTI_POLYGON", orgUnit.get("featureType").getAsString());
        if (level == 0) {
            Assert.assertEquals(AllAttributesDataset.GO_ALL.getCode(), orgUnit.get("code").getAsString());
        } else {
            Assert.assertEquals(go.getCode(), orgUnit.get("code").getAsString());
            Assert.assertTrue(orgUnit.has("attributeValues"));
            JsonArray attributeValues = orgUnit.get("attributeValues").getAsJsonArray();
            Assert.assertEquals(1, attributeValues.size());
            JsonObject attributeValue = attributeValues.get(0).getAsJsonObject();
            Assert.assertNotNull(attributeValue.get("lastUpdated").getAsString());
            Assert.assertNotNull(attributeValue.get("created").getAsString());
            AttributeType attrDto = attr.fetchDTO();
            if (attrDto instanceof AttributeIntegerType) {
                Assert.assertEquals(go.getServerObject().getValue(attr.getAttributeName()), attributeValue.get("value").getAsLong());
            } else if (attrDto instanceof AttributeFloatType) {
                Assert.assertEquals(go.getServerObject().getValue(attr.getAttributeName()), attributeValue.get("value").getAsDouble());
            } else if (attrDto instanceof AttributeDateType) {
                // TODO : If we fetch the object from the database in this manner the
                // miliseconds aren't included on the date. But if we fetch the object
                // via a query (as in DataExportJob) then the miliseconds ARE
                // included...
                // String expected =
                // DHIS2GeoObjectJsonAdapters.DHIS2Serializer.formatDate((Date)
                // go.getServerObject().getValue(attr.getAttributeName()));
                String expected = DHIS2GeoObjectJsonAdapters.DHIS2Serializer.formatDate(AllAttributesDataset.GO_DATE_VALUE);
                String actual = attributeValue.get("value").getAsString();
                Assert.assertEquals(expected, actual);
            } else if (attrDto instanceof AttributeBooleanType) {
                Assert.assertEquals(go.getServerObject().getValue(attr.getAttributeName()), attributeValue.get("value").getAsBoolean());
            } else if (attrDto instanceof AttributeTermType) {
                String dhis2Id = attributeValue.get("value").getAsString();
                // Term term = (Term)
                // go.getServerObject().getValue(attr.getAttributeName());
                Assert.assertEquals("TEST_EXTERNAL_ID", dhis2Id);
            } else {
                Assert.assertEquals(go.getServerObject().getValue(attr.getAttributeName()), attributeValue.get("value").getAsString());
            }
            Assert.assertEquals("TEST_EXTERNAL_ID", attributeValue.get("attribute").getAsJsonObject().get("id").getAsString());
        }
    }
}
Also used : AttributeIntegerType(org.commongeoregistry.adapter.metadata.AttributeIntegerType) HashMap(java.util.HashMap) JsonObject(com.google.gson.JsonObject) Dhis2Payload(net.geoprism.registry.etl.DHIS2TestService.Dhis2Payload) AttributeFloatType(org.commongeoregistry.adapter.metadata.AttributeFloatType) AttributeDateType(org.commongeoregistry.adapter.metadata.AttributeDateType) JsonArray(com.google.gson.JsonArray) ExportHistory(net.geoprism.registry.etl.export.ExportHistory) AttributeType(org.commongeoregistry.adapter.metadata.AttributeType) SynchronizationConfig(net.geoprism.registry.SynchronizationConfig) AttributeBooleanType(org.commongeoregistry.adapter.metadata.AttributeBooleanType) AttributeTermType(org.commongeoregistry.adapter.metadata.AttributeTermType)

Example 52 with AttributeType

use of org.commongeoregistry.adapter.metadata.AttributeType in project geoprism-registry by terraframe.

the class AttributeTypeServiceTest method testCreateGeoObjectTypeDate.

@Test
public void testCreateGeoObjectTypeDate() {
    String organizationCode = FastTestDataset.ORG_CGOV.getCode();
    GeoObjectType province = MetadataFactory.newGeoObjectType(TEST_GOT.getCode(), GeometryType.POLYGON, new LocalizedValue("Province"), new LocalizedValue(""), true, organizationCode, testData.adapter);
    String gtJSON = province.toJSON().toString();
    AttributeType testDate = AttributeType.factory("testDate", new LocalizedValue("testDateLocalName"), new LocalizedValue("testDateLocalDescrip"), AttributeDateType.TYPE, false, false, false);
    testData.adapter.createGeoObjectType(gtJSON);
    String geoObjectTypeCode = province.getCode();
    String attributeTypeJSON = testDate.toJSON().toString();
    testDate = testData.adapter.createAttributeType(geoObjectTypeCode, attributeTypeJSON);
    MdAttributeDAOIF mdAttributeConcreteDAOIF = checkAttribute(TEST_GOT.getCode(), testDate.getName());
    Assert.assertNotNull("A GeoObjectType did not define the attribute: " + testDate.getName(), mdAttributeConcreteDAOIF);
    Assert.assertTrue("A GeoObjectType did not define the attribute of the correct type: " + mdAttributeConcreteDAOIF.getType(), mdAttributeConcreteDAOIF instanceof MdAttributeMomentDAOIF);
}
Also used : LocalizedValue(org.commongeoregistry.adapter.dataaccess.LocalizedValue) ServerGeoObjectType(net.geoprism.registry.model.ServerGeoObjectType) GeoObjectType(org.commongeoregistry.adapter.metadata.GeoObjectType) MdAttributeDAOIF(com.runwaysdk.dataaccess.MdAttributeDAOIF) AttributeType(org.commongeoregistry.adapter.metadata.AttributeType) MdAttributeMomentDAOIF(com.runwaysdk.dataaccess.MdAttributeMomentDAOIF) Test(org.junit.Test) ClassificationTypeTest(net.geoprism.registry.classification.ClassificationTypeTest)

Example 53 with AttributeType

use of org.commongeoregistry.adapter.metadata.AttributeType in project geoprism-registry by terraframe.

the class ConversionTest method testAttributeTypeIntegerTree.

// Heads up: clean up
// @Test
// public void testAttributeTypeFloatLeaf()
// {
// String sessionId = testData.adminClientRequest.getSessionId();
// 
// // Add a new custom attribute
// AttributeType testFloat = AttributeType.factory("testFloat", new LocalizedValue("testFloatLocalName"), new LocalizedValue("testFloatLocalDescrip"), AttributeFloatType.TYPE, false, false, false);
// testFloat = ServiceFactory.getRegistryService().createAttributeType(sessionId, USATestData.DISTRICT.getCode(), testFloat.toJSON().toString());
// 
// // Create a new GeoObject with the custom attribute
// GeoObject geoObj = ServiceFactory.getRegistryService().newGeoObjectInstance(sessionId, USATestData.DISTRICT.getCode());
// geoObj.setCode(testGo.getCode());
// geoObj.setDisplayLabel(LocalizedValue.DEFAULT_LOCALE, "Test Label");
// geoObj.setUid(ServiceFactory.getRegistryService().getUIDS(sessionId, 1)[0]);
// geoObj.setValue(testFloat.getName(), new Double(234.2));
// 
// ServiceFactory.getRegistryService().createGeoObject(sessionId, geoObj.toJSON().toString());
// 
// // Get the object with the custom attribute
// GeoObject result = ServiceFactory.getRegistryService().getGeoObjectByCode(sessionId, testGo.getCode(), USATestData.DISTRICT.getCode());
// 
// Assert.assertNotNull(result);
// Assert.assertEquals(geoObj.getValue(testFloat.getName()), result.getValue(testFloat.getName()));
// }
@Test
public void testAttributeTypeIntegerTree() {
    String sessionId = testData.clientRequest.getSessionId();
    // Add a new custom attribute
    AttributeType testInteger = AttributeType.factory("testInteger", new LocalizedValue("testIntegerLocalName"), new LocalizedValue("testIntegerLocalDescrip"), AttributeIntegerType.TYPE, false, false, false);
    testInteger = ServiceFactory.getRegistryService().createAttributeType(sessionId, USATestData.STATE.getCode(), testInteger.toJSON().toString());
    // Create a new GeoObject with the custom attribute
    GeoObject geoObj = ServiceFactory.getRegistryService().newGeoObjectInstance(sessionId, USATestData.STATE.getCode());
    geoObj.setCode(testGo.getCode());
    geoObj.setDisplayLabel(LocalizedValue.DEFAULT_LOCALE, "Test Label");
    geoObj.setUid(ServiceFactory.getRegistryService().getUIDS(sessionId, 1)[0]);
    geoObj.setValue(testInteger.getName(), new Long(123));
    ServiceFactory.getRegistryService().createGeoObject(sessionId, geoObj.toJSON().toString(), TestDataSet.DEFAULT_OVER_TIME_DATE, TestDataSet.DEFAULT_END_TIME_DATE);
    // Get the object with the custom attribute
    GeoObject result = ServiceFactory.getRegistryService().getGeoObjectByCode(sessionId, testGo.getCode(), USATestData.STATE.getCode(), TestDataSet.DEFAULT_OVER_TIME_DATE);
    Assert.assertNotNull(result);
    Assert.assertEquals(geoObj.getValue(testInteger.getName()), result.getValue(testInteger.getName()));
}
Also used : LocalizedValue(org.commongeoregistry.adapter.dataaccess.LocalizedValue) AttributeType(org.commongeoregistry.adapter.metadata.AttributeType) GeoObject(org.commongeoregistry.adapter.dataaccess.GeoObject) Test(org.junit.Test)

Example 54 with AttributeType

use of org.commongeoregistry.adapter.metadata.AttributeType in project geoprism-registry by terraframe.

the class GeoObjectAtTimeShapefileExporterTest method testCreateFeatures.

@Test
@Request
public void testCreateFeatures() {
    ServerGeoObjectType type = FastTestDataset.PROVINCE.getServerObject();
    GeoObjectAtTimeShapefileExporter exporter = new GeoObjectAtTimeShapefileExporter(type, FastTestDataset.DEFAULT_OVER_TIME_DATE);
    SimpleFeatureType featureType = exporter.createFeatureType();
    FeatureCollection<SimpleFeatureType, SimpleFeature> features = exporter.features(featureType);
    Assert.assertTrue(features.size() > 0);
    final FeatureIterator<SimpleFeature> it = features.features();
    boolean hasCentralProvince = false;
    while (it.hasNext()) {
        SimpleFeature feature = it.next();
        if (feature.getID().equals(FastTestDataset.PROV_CENTRAL.getCode())) {
            hasCentralProvince = true;
            final ServerGeoObjectIF object = FastTestDataset.PROV_CENTRAL.getServerObject();
            Object geometry = feature.getDefaultGeometry();
            Assert.assertNotNull(geometry);
            Collection<AttributeType> attributes = new ImportAttributeSerializer(Session.getCurrentLocale(), false, false, LocalizationFacade.getInstalledLocales()).attributes(type.getType());
            for (AttributeType attribute : attributes) {
                String attributeName = attribute.getName();
                Object oValue = object.getValue(attributeName);
                Object fValue = feature.getAttribute(exporter.getColumnName(attributeName));
                if (attribute instanceof AttributeTermType) {
                    Assert.assertEquals("Attributes not equal [" + attributeName + "]", GeoObjectUtil.convertToTermString((AttributeTermType) attribute, oValue), fValue);
                } else if (attribute instanceof AttributeLocalType) {
                    Assert.assertEquals("Attributes not equal [" + attributeName + "]", ((LocalizedValue) oValue).getValue(), fValue);
                } else {
                    Assert.assertEquals("Attributes not equal [" + attributeName + "]", oValue, fValue);
                }
            }
        }
    }
    Assert.assertTrue("Unable to find the central province feature", hasCentralProvince);
}
Also used : ServerGeoObjectIF(net.geoprism.registry.model.ServerGeoObjectIF) ServerGeoObjectType(net.geoprism.registry.model.ServerGeoObjectType) GeoObjectAtTimeShapefileExporter(net.geoprism.registry.shapefile.GeoObjectAtTimeShapefileExporter) SimpleFeature(org.opengis.feature.simple.SimpleFeature) AttributeLocalType(org.commongeoregistry.adapter.metadata.AttributeLocalType) SimpleFeatureType(org.opengis.feature.simple.SimpleFeatureType) LocalizedValue(org.commongeoregistry.adapter.dataaccess.LocalizedValue) AttributeType(org.commongeoregistry.adapter.metadata.AttributeType) AttributeTermType(org.commongeoregistry.adapter.metadata.AttributeTermType) Test(org.junit.Test) Request(com.runwaysdk.session.Request)

Example 55 with AttributeType

use of org.commongeoregistry.adapter.metadata.AttributeType in project geoprism-registry by terraframe.

the class XMLImporterTest method testImport.

@Request
@Test
public void testImport() throws IOException {
    Organization organization = new Organization();
    organization.setCode("TEST_ORG");
    organization.getDisplayLabel().setValue("Test Org");
    organization.apply();
    try (InputStream istream = this.getClass().getResourceAsStream("/xml/test-domain.xml")) {
        XMLImporter xmlImporter = new XMLImporter();
        List<ServerElement> results = xmlImporter.importXMLDefinitions(organization, istream);
        try {
            RegistryService.getInstance().refreshMetadataCache();
            Assert.assertEquals(4, results.size());
            ServerGeoObjectType type = ServerGeoObjectType.get(results.get(0).getCode());
            Assert.assertEquals("TEST_VILLAGE", type.getCode());
            Assert.assertEquals("Test Village", type.getLabel().getValue(LocalizedValue.DEFAULT_LOCALE));
            Assert.assertEquals(GeometryType.MULTIPOINT, type.getGeometryType());
            Assert.assertFalse(type.getIsPrivate());
            Assert.assertFalse(type.isGeometryEditable());
            Assert.assertTrue(type.getIsAbstract());
            Optional<AttributeType> oattribute = type.getAttribute("TEST_TEXT");
            Assert.assertTrue(oattribute.isPresent());
            AttributeType attributeType = oattribute.get();
            Assert.assertEquals("Test Text", attributeType.getLabel().getValue(LocalizedValue.DEFAULT_LOCALE));
            Assert.assertEquals("Test Text Description", attributeType.getDescription().getValue(LocalizedValue.DEFAULT_LOCALE));
            oattribute = type.getAttribute("TEST_BOOLEAN");
            Assert.assertTrue(oattribute.isPresent());
            attributeType = oattribute.get();
            Assert.assertEquals("Test Boolean", attributeType.getLabel().getValue(LocalizedValue.DEFAULT_LOCALE));
            Assert.assertEquals("Test Boolean Description", attributeType.getDescription().getValue(LocalizedValue.DEFAULT_LOCALE));
            oattribute = type.getAttribute("TEST_INTEGER");
            Assert.assertTrue(oattribute.isPresent());
            attributeType = oattribute.get();
            Assert.assertEquals("Test Integer", attributeType.getLabel().getValue(LocalizedValue.DEFAULT_LOCALE));
            Assert.assertEquals("Test Integer Description", attributeType.getDescription().getValue(LocalizedValue.DEFAULT_LOCALE));
            oattribute = type.getAttribute("TEST_DATE");
            Assert.assertTrue(oattribute.isPresent());
            attributeType = oattribute.get();
            Assert.assertEquals("Test Date", attributeType.getLabel().getValue(LocalizedValue.DEFAULT_LOCALE));
            Assert.assertEquals("Test Date Description", attributeType.getDescription().getValue(LocalizedValue.DEFAULT_LOCALE));
            oattribute = type.getAttribute("TEST_DECIMAL");
            Assert.assertTrue(oattribute.isPresent());
            attributeType = oattribute.get();
            Assert.assertEquals("Test Decimal", attributeType.getLabel().getValue(LocalizedValue.DEFAULT_LOCALE));
            Assert.assertEquals("Test Decimal Description", attributeType.getDescription().getValue(LocalizedValue.DEFAULT_LOCALE));
            oattribute = type.getAttribute("TEST_TERM");
            Assert.assertTrue(oattribute.isPresent());
            attributeType = oattribute.get();
            Assert.assertEquals("Test Term", attributeType.getLabel().getValue(LocalizedValue.DEFAULT_LOCALE));
            Assert.assertEquals("Test Term Description", attributeType.getDescription().getValue(LocalizedValue.DEFAULT_LOCALE));
            List<Term> terms = ((AttributeTermType) attributeType).getTerms();
            Assert.assertEquals(3, terms.size());
            oattribute = type.getAttribute("TEST_CLASSIFICATION");
            Assert.assertTrue(oattribute.isPresent());
            attributeType = oattribute.get();
            Assert.assertEquals("Test Classification", attributeType.getLabel().getValue(LocalizedValue.DEFAULT_LOCALE));
            Assert.assertEquals("Test Text Classification", attributeType.getDescription().getValue(LocalizedValue.DEFAULT_LOCALE));
            Assert.assertEquals("TEST_PROG", ((AttributeClassificationType) attributeType).getClassificationType());
            Assert.assertEquals(ROOT_CODE, ((AttributeClassificationType) attributeType).getRootTerm().getCode());
            type = ServerGeoObjectType.get(results.get(1).getCode());
            Assert.assertEquals("TEST_GI", type.getCode());
            Assert.assertEquals("Test GI", type.getLabel().getValue(LocalizedValue.DEFAULT_LOCALE));
            Assert.assertEquals(GeometryType.MULTIPOINT, type.getGeometryType());
            Assert.assertFalse(type.getIsPrivate());
            Assert.assertFalse(type.isGeometryEditable());
            Assert.assertFalse(type.getIsAbstract());
            Assert.assertEquals("TEST_VILLAGE", type.getSuperType().getCode());
            ServerHierarchyType hierarchy = ServerHierarchyType.get(results.get(3).getCode());
            Assert.assertEquals("TEST_HIERARCHY", hierarchy.getCode());
            Assert.assertEquals("Test Hierarchy", hierarchy.getDisplayLabel().getValue(LocalizedValue.DEFAULT_LOCALE));
            Assert.assertEquals("Test Hierarchy Description", hierarchy.getDescription().getValue(LocalizedValue.DEFAULT_LOCALE));
            Assert.assertEquals("Test Progress", hierarchy.getProgress());
            Assert.assertEquals("Test Disclaimer", hierarchy.getDisclaimer());
            Assert.assertEquals("Test Access Constraints", hierarchy.getAccessConstraints());
            Assert.assertEquals("Test Use Constraints", hierarchy.getUseConstraints());
            Assert.assertEquals("Test Acknowledgement", hierarchy.getAcknowledgement());
            List<HierarchyNode> nodes = hierarchy.getRootGeoObjectTypes();
            Assert.assertEquals(1, nodes.size());
            HierarchyNode node = nodes.get(0);
            Assert.assertEquals("TEST_DISTRICT", node.getGeoObjectType().getCode());
            nodes = node.getChildren();
            Assert.assertEquals(1, nodes.size());
            node = nodes.get(0);
            Assert.assertEquals("TEST_VILLAGE", node.getGeoObjectType().getCode());
        } finally {
            Collections.reverse(results);
            for (ServerElement result : results) {
                result.delete();
            }
        }
    } finally {
        organization.delete();
    }
}
Also used : ServerHierarchyType(net.geoprism.registry.model.ServerHierarchyType) Organization(net.geoprism.registry.Organization) InputStream(java.io.InputStream) ServerGeoObjectType(net.geoprism.registry.model.ServerGeoObjectType) Term(org.commongeoregistry.adapter.Term) AttributeClassificationType(org.commongeoregistry.adapter.metadata.AttributeClassificationType) AttributeType(org.commongeoregistry.adapter.metadata.AttributeType) AttributeTermType(org.commongeoregistry.adapter.metadata.AttributeTermType) ServerElement(net.geoprism.registry.model.ServerElement) HierarchyNode(org.commongeoregistry.adapter.metadata.HierarchyNode) Test(org.junit.Test) ClassificationTypeTest(net.geoprism.registry.classification.ClassificationTypeTest) Request(com.runwaysdk.session.Request)

Aggregations

AttributeType (org.commongeoregistry.adapter.metadata.AttributeType)55 ServerGeoObjectType (net.geoprism.registry.model.ServerGeoObjectType)27 JsonObject (com.google.gson.JsonObject)18 Locale (java.util.Locale)17 LocalizedValue (org.commongeoregistry.adapter.dataaccess.LocalizedValue)17 AttributeTermType (org.commongeoregistry.adapter.metadata.AttributeTermType)16 GeoObject (org.commongeoregistry.adapter.dataaccess.GeoObject)15 Transaction (com.runwaysdk.dataaccess.transaction.Transaction)12 ServerHierarchyType (net.geoprism.registry.model.ServerHierarchyType)11 AttributeClassificationType (org.commongeoregistry.adapter.metadata.AttributeClassificationType)11 LinkedList (java.util.LinkedList)10 Classifier (net.geoprism.ontology.Classifier)10 ServerGeoObjectIF (net.geoprism.registry.model.ServerGeoObjectIF)10 VertexObject (com.runwaysdk.business.graph.VertexObject)9 MdBusinessDAO (com.runwaysdk.dataaccess.metadata.MdBusinessDAO)9 Request (com.runwaysdk.session.Request)9 List (java.util.List)9 Test (org.junit.Test)9 JsonArray (com.google.gson.JsonArray)8 MdBusiness (com.runwaysdk.system.metadata.MdBusiness)8