Search in sources :

Example 6 with ServerElement

use of net.geoprism.registry.model.ServerElement in project geoprism-registry by terraframe.

the class XMLImporter method createHierarchies.

private List<ServerElement> createHierarchies(Organization organization, Document doc) {
    LinkedList<ServerElement> list = new LinkedList<ServerElement>();
    NodeList nList = doc.getElementsByTagName("hierarchy");
    for (int i = 0; i < nList.getLength(); i++) {
        Node nNode = nList.item(i);
        if (nNode.getNodeType() == Node.ELEMENT_NODE) {
            Element elem = (Element) nNode;
            ServerHierarchyType type = createServerHierarchyType(organization, elem);
            list.add(type);
            this.cache.put(type.getCode(), type);
            this.addChildren(type, RootGeoObjectType.INSTANCE, elem);
        }
    }
    return list;
}
Also used : ServerHierarchyType(net.geoprism.registry.model.ServerHierarchyType) NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) ServerElement(net.geoprism.registry.model.ServerElement) Element(org.w3c.dom.Element) ServerElement(net.geoprism.registry.model.ServerElement) LinkedList(java.util.LinkedList)

Example 7 with ServerElement

use of net.geoprism.registry.model.ServerElement 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

ServerElement (net.geoprism.registry.model.ServerElement)7 LinkedList (java.util.LinkedList)6 Element (org.w3c.dom.Element)5 Node (org.w3c.dom.Node)5 NodeList (org.w3c.dom.NodeList)5 ServerGeoObjectType (net.geoprism.registry.model.ServerGeoObjectType)3 ServerHierarchyType (net.geoprism.registry.model.ServerHierarchyType)2 ProgrammingErrorException (com.runwaysdk.dataaccess.ProgrammingErrorException)1 Transaction (com.runwaysdk.dataaccess.transaction.Transaction)1 TransactionState (com.runwaysdk.dataaccess.transaction.TransactionState)1 Request (com.runwaysdk.session.Request)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 DocumentBuilder (javax.xml.parsers.DocumentBuilder)1 DocumentBuilderFactory (javax.xml.parsers.DocumentBuilderFactory)1 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)1 Organization (net.geoprism.registry.Organization)1 ClassificationTypeTest (net.geoprism.registry.classification.ClassificationTypeTest)1 ServerGeoObjectTypeConverter (net.geoprism.registry.conversion.ServerGeoObjectTypeConverter)1 RootGeoObjectType (net.geoprism.registry.model.RootGeoObjectType)1