Search in sources :

Example 21 with Term

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

the class ServerGeoObjectType method updateMdAttributeFromAttributeType.

/**
 * Creates an {@link MdAttributeConcrete} for the given {@link MdBusiness}
 * from the given {@link AttributeType}
 *
 * @pre assumes no attribute has been defined on the type with the given name.
 *
 * @param mdBusiness
 *          Type to receive attribute definition
 * @param attributeType
 *          newly defined attribute
 *
 * @return {@link AttributeType}
 */
@Transaction
public static MdAttributeConcrete updateMdAttributeFromAttributeType(MdClass mdClass, AttributeType attributeType) {
    MdAttributeConcreteDAOIF mdAttributeConcreteDAOIF = getMdAttribute(mdClass, attributeType.getName());
    if (mdAttributeConcreteDAOIF != null) {
        // Get the type safe version
        MdAttributeConcrete mdAttribute = (MdAttributeConcrete) BusinessFacade.get(mdAttributeConcreteDAOIF);
        mdAttribute.lock();
        try {
            // The name cannot be updated
            // mdAttribute.setAttributeName(attributeType.getName());
            LocalizedValueConverter.populate(mdAttribute.getDisplayLabel(), attributeType.getLabel());
            LocalizedValueConverter.populate(mdAttribute.getDescription(), attributeType.getDescription());
            if (attributeType instanceof AttributeFloatType) {
                // Refresh the terms
                AttributeFloatType attributeFloatType = (AttributeFloatType) attributeType;
                mdAttribute.setValue(MdAttributeDoubleInfo.LENGTH, Integer.toString(attributeFloatType.getPrecision()));
                mdAttribute.setValue(MdAttributeDoubleInfo.DECIMAL, Integer.toString(attributeFloatType.getScale()));
            } else if (attributeType instanceof AttributeClassificationType) {
                MdAttributeClassification mdAttributeTerm = (MdAttributeClassification) mdAttribute;
                AttributeClassificationType attributeClassificationType = (AttributeClassificationType) attributeType;
                String classificationTypeCode = attributeClassificationType.getClassificationType();
                ClassificationType classificationType = ClassificationType.getByCode(classificationTypeCode);
                Term root = attributeClassificationType.getRootTerm();
                if (root != null) {
                    Classification classification = Classification.get(classificationType, root.getCode());
                    mdAttributeTerm.setValue(MdAttributeClassification.ROOT, classification.getOid());
                }
            }
            mdAttribute.apply();
        } finally {
            mdAttribute.unlock();
        }
        if (attributeType instanceof AttributeTermType) {
            // Refresh the terms
            AttributeTermType attributeTermType = (AttributeTermType) attributeType;
            org.commongeoregistry.adapter.Term getRootTerm = attributeTermType.getRootTerm();
            String classifierKey = TermConverter.buildClassifierKeyFromTermCode(getRootTerm.getCode());
            TermConverter termBuilder = new TermConverter(classifierKey);
            attributeTermType.setRootTerm(termBuilder.build());
        }
        return mdAttribute;
    }
    return null;
}
Also used : MdAttributeClassification(com.runwaysdk.system.metadata.MdAttributeClassification) Term(org.commongeoregistry.adapter.Term) MdAttributeTerm(com.runwaysdk.system.metadata.MdAttributeTerm) Term(org.commongeoregistry.adapter.Term) AttributeClassificationType(org.commongeoregistry.adapter.metadata.AttributeClassificationType) AttributeClassificationType(org.commongeoregistry.adapter.metadata.AttributeClassificationType) AttributeFloatType(org.commongeoregistry.adapter.metadata.AttributeFloatType) MdAttributeClassification(com.runwaysdk.system.metadata.MdAttributeClassification) MdAttributeConcrete(com.runwaysdk.system.metadata.MdAttributeConcrete) AttributeTermType(org.commongeoregistry.adapter.metadata.AttributeTermType) TermConverter(net.geoprism.registry.conversion.TermConverter) MdAttributeConcreteDAOIF(com.runwaysdk.dataaccess.MdAttributeConcreteDAOIF) Transaction(com.runwaysdk.dataaccess.transaction.Transaction)

Example 22 with Term

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

the class VertexServerGeoObject method populate.

@SuppressWarnings("unchecked")
@Override
public void populate(GeoObject geoObject, Date startDate, Date endDate) {
    Map<String, AttributeType> attributes = geoObject.getType().getAttributeMap();
    attributes.forEach((attributeName, attribute) -> {
        if (attributeName.equals(DefaultAttribute.INVALID.getName()) || attributeName.equals(DefaultAttribute.EXISTS.getName()) || attributeName.equals(DefaultAttribute.DISPLAY_LABEL.getName()) || attributeName.equals(DefaultAttribute.CODE.getName()) || attributeName.equals(DefaultAttribute.UID.getName()) || attributeName.equals(GeoVertex.LASTUPDATEDATE) || attributeName.equals(GeoVertex.CREATEDATE)) {
        // Ignore the attributes
        } else if (this.vertex.hasAttribute(attributeName) && !this.vertex.getMdAttributeDAO(attributeName).isSystem()) {
            if (attribute instanceof AttributeTermType) {
                Iterator<String> it = (Iterator<String>) geoObject.getValue(attributeName);
                if (it.hasNext()) {
                    String code = it.next();
                    Term root = ((AttributeTermType) attribute).getRootTerm();
                    String parent = TermConverter.buildClassifierKeyFromTermCode(root.getCode());
                    String classifierKey = Classifier.buildKey(parent, code);
                    Classifier classifier = Classifier.getByKey(classifierKey);
                    this.vertex.setValue(attributeName, classifier.getOid(), startDate, endDate);
                } else {
                    this.vertex.setValue(attributeName, (String) null, startDate, endDate);
                }
            } else if (attribute instanceof AttributeClassificationType) {
                String value = (String) geoObject.getValue(attributeName);
                if (value != null) {
                    Classification classification = Classification.get((AttributeClassificationType) attribute, value);
                    this.vertex.setValue(attributeName, classification.getVertex(), startDate, endDate);
                } else {
                    this.vertex.setValue(attributeName, (String) null, startDate, endDate);
                }
            } else {
                Object value = geoObject.getValue(attributeName);
                if (value != null) {
                    this.vertex.setValue(attributeName, value, startDate, endDate);
                } else {
                    this.vertex.setValue(attributeName, (String) null, startDate, endDate);
                }
            }
        }
    });
    this.setInvalid(geoObject.getInvalid());
    this.setUid(geoObject.getUid());
    this.setCode(geoObject.getCode());
    this.setExists(geoObject.getExists(), startDate, endDate);
    this.setDisplayLabel(geoObject.getDisplayLabel(), startDate, endDate);
    this.setGeometry(geoObject.getGeometry(), startDate, endDate);
}
Also used : AttributeType(org.commongeoregistry.adapter.metadata.AttributeType) Classification(net.geoprism.registry.model.Classification) AbstractClassification(com.runwaysdk.system.AbstractClassification) Iterator(java.util.Iterator) GeoObject(org.commongeoregistry.adapter.dataaccess.GeoObject) VertexObject(com.runwaysdk.business.graph.VertexObject) EdgeObject(com.runwaysdk.business.graph.EdgeObject) AbstractServerGeoObject(net.geoprism.registry.model.AbstractServerGeoObject) GraphObject(com.runwaysdk.business.graph.GraphObject) MultiLineString(com.vividsolutions.jts.geom.MultiLineString) LineString(com.vividsolutions.jts.geom.LineString) Term(org.commongeoregistry.adapter.Term) Classifier(net.geoprism.ontology.Classifier) AttributeTermType(org.commongeoregistry.adapter.metadata.AttributeTermType) AttributeClassificationType(org.commongeoregistry.adapter.metadata.AttributeClassificationType)

Example 23 with Term

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

the class RegistryService method createTerm.

/**
 * Creates a new {@link Term} object and makes it a child of the term with the
 * given code.
 *
 * @param sessionId
 * @param parentTemCode
 *          The code of the parent [@link Term}.
 * @param termJSON
 *          JSON of the term object.
 *
 * @return Newly created {@link Term} object.
 */
@Request(RequestType.SESSION)
public Term createTerm(String sessionId, String parentTermCode, String termJSON) {
    JsonObject termJSONobj = JsonParser.parseString(termJSON).getAsJsonObject();
    LocalizedValue label = LocalizedValue.fromJSON(termJSONobj.get(Term.JSON_LOCALIZED_LABEL).getAsJsonObject());
    Term term = new Term(termJSONobj.get(Term.JSON_CODE).getAsString(), label, new LocalizedValue(""));
    Classifier classifier = TermConverter.createClassifierFromTerm(parentTermCode, term);
    TermConverter termBuilder = new TermConverter(classifier.getKeyName());
    Term returnTerm = termBuilder.build();
    List<MdAttributeConcrete> mdAttrList = this.findRootClassifier(classifier);
    this.refreshAttributeTermTypeInCache(mdAttrList);
    return returnTerm;
}
Also used : LocalizedValue(org.commongeoregistry.adapter.dataaccess.LocalizedValue) JsonObject(com.google.gson.JsonObject) MdAttributeMultiTerm(com.runwaysdk.system.metadata.MdAttributeMultiTerm) MdAttributeTerm(com.runwaysdk.system.metadata.MdAttributeTerm) Term(org.commongeoregistry.adapter.Term) Classifier(net.geoprism.ontology.Classifier) MdAttributeConcrete(com.runwaysdk.system.metadata.MdAttributeConcrete) TermConverter(net.geoprism.registry.conversion.TermConverter) Request(com.runwaysdk.session.Request) OAuthClientRequest(org.apache.oltu.oauth2.client.request.OAuthClientRequest)

Example 24 with Term

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

the class XMLImporter method createTermOptions.

private void createTermOptions(Element attributeNode, Term root) {
    NodeList attributeList = attributeNode.getElementsByTagName("option");
    for (int i = 0; i < attributeList.getLength(); i++) {
        Node nNode = attributeList.item(i);
        if (nNode.getNodeType() == Node.ELEMENT_NODE) {
            Element elem = (Element) nNode;
            String code = elem.getAttribute("code");
            LocalizedValue label = this.getLabel(elem);
            LocalizedValue description = this.getDescription(elem);
            Term term = new Term(code, label, description);
            Classifier classifier = TermConverter.createClassifierFromTerm(root.getCode(), term);
            TermConverter termBuilder = new TermConverter(classifier.getKeyName());
            termBuilder.build();
        }
    }
}
Also used : LocalizedValue(org.commongeoregistry.adapter.dataaccess.LocalizedValue) NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) ServerElement(net.geoprism.registry.model.ServerElement) Element(org.w3c.dom.Element) Term(org.commongeoregistry.adapter.Term) Classifier(net.geoprism.ontology.Classifier) TermConverter(net.geoprism.registry.conversion.TermConverter)

Example 25 with Term

use of org.commongeoregistry.adapter.Term 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

Term (org.commongeoregistry.adapter.Term)25 AttributeTermType (org.commongeoregistry.adapter.metadata.AttributeTermType)16 Classifier (net.geoprism.ontology.Classifier)14 LocalizedValue (org.commongeoregistry.adapter.dataaccess.LocalizedValue)14 AttributeClassificationType (org.commongeoregistry.adapter.metadata.AttributeClassificationType)11 JsonObject (com.google.gson.JsonObject)8 AttributeType (org.commongeoregistry.adapter.metadata.AttributeType)8 MdAttributeTerm (com.runwaysdk.system.metadata.MdAttributeTerm)7 ServerGeoObjectType (net.geoprism.registry.model.ServerGeoObjectType)7 Classification (net.geoprism.registry.model.Classification)6 AttributeFloatType (org.commongeoregistry.adapter.metadata.AttributeFloatType)6 MdAttributeTermDAOIF (com.runwaysdk.dataaccess.MdAttributeTermDAOIF)4 MdAttributeConcrete (com.runwaysdk.system.metadata.MdAttributeConcrete)4 Iterator (java.util.Iterator)4 AttributeBooleanType (org.commongeoregistry.adapter.metadata.AttributeBooleanType)4 AttributeDateType (org.commongeoregistry.adapter.metadata.AttributeDateType)4 VertexObject (com.runwaysdk.business.graph.VertexObject)3 Request (com.runwaysdk.session.Request)3 Geometry (com.vividsolutions.jts.geom.Geometry)3 LinkedList (java.util.LinkedList)3