Search in sources :

Example 11 with Classification

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

the class ClassificationTest method testGetAncestorTree.

@Test
@Request
public void testGetAncestorTree() {
    Classification parent = Classification.newInstance(type);
    parent.setCode(PARENT_CODE);
    parent.apply(null);
    try {
        Classification child = Classification.newInstance(type);
        child.setCode(CHILD_CODE);
        child.apply(parent);
        try {
            ClassificationNode tree = child.getAncestorTree(null, 200);
            Assert.assertEquals(parent.getOid(), tree.getClassification().getOid());
        } finally {
            child.delete();
        }
    } finally {
        parent.delete();
    }
}
Also used : ClassificationNode(net.geoprism.registry.model.ClassificationNode) Classification(net.geoprism.registry.model.Classification) Test(org.junit.Test) Request(com.runwaysdk.session.Request)

Example 12 with Classification

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

the class ClassificationTest method testAddGetChild.

@Test
@Request
public void testAddGetChild() {
    Classification parent = Classification.newInstance(type);
    parent.setCode(PARENT_CODE);
    parent.apply(null);
    try {
        Classification child = Classification.newInstance(type);
        child.setCode(CHILD_CODE);
        child.apply(null);
        try {
            parent.addChild(child);
            Page<Classification> children = parent.getChildren(20, 1);
            Assert.assertEquals(Long.valueOf(1), children.getCount());
            Classification result = children.getResults().get(0);
            Assert.assertEquals(child.getOid(), result.getOid());
        } finally {
            child.delete();
        }
    } finally {
        parent.delete();
    }
}
Also used : Classification(net.geoprism.registry.model.Classification) Test(org.junit.Test) Request(com.runwaysdk.session.Request)

Example 13 with Classification

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

the class AttributeClassificationTest method setUpInReq.

@Request
private static void setUpInReq() {
    type = ClassificationType.apply(ClassificationTypeTest.createMock());
    TEST_GOT.apply();
    Classification root = Classification.newInstance(type);
    root.setCode(CODE);
    root.setDisplayLabel(new LocalizedValue("Test Classification"));
    root.apply(null);
    testClassification = (AttributeClassificationType) AttributeType.factory("testClassification", new LocalizedValue("testClassificationLocalName"), new LocalizedValue("testClassificationLocalDescrip"), AttributeClassificationType.TYPE, false, false, false);
    testClassification.setClassificationType(type.getCode());
    testClassification.setRootTerm(root.toTerm());
    ServerGeoObjectType got = ServerGeoObjectType.get(TEST_GOT.getCode());
    testClassification = (AttributeClassificationType) got.createAttributeType(testClassification.toJSON().toString());
}
Also used : LocalizedValue(org.commongeoregistry.adapter.dataaccess.LocalizedValue) ServerGeoObjectType(net.geoprism.registry.model.ServerGeoObjectType) Classification(net.geoprism.registry.model.Classification) Request(com.runwaysdk.session.Request)

Example 14 with Classification

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

the class ListType method getRestriction.

public BasicVertexRestriction getRestriction(ServerGeoObjectType type, Date forDate) {
    String filterJson = this.getFilterJson();
    if (filterJson != null && filterJson.length() > 0) {
        JsonArray filters = JsonParser.parseString(filterJson).getAsJsonArray();
        CompositeRestriction restriction = new CompositeRestriction();
        for (int i = 0; i < filters.size(); i++) {
            JsonObject filter = filters.get(i).getAsJsonObject();
            String attributeName = filter.get("attribute").getAsString();
            String operation = filter.get("operation").getAsString();
            AttributeType attributeType = type.getAttribute(attributeName).get();
            MdAttributeDAOIF mdAttribute = type.getMdVertex().definesAttribute(attributeName);
            if (attributeType instanceof AttributeDateType) {
                String value = filter.get("value").getAsString();
                Date date = GeoRegistryUtil.parseDate(value, false);
                restriction.add(new AttributeValueRestriction(mdAttribute, operation, date, forDate));
            } else if (attributeType instanceof AttributeBooleanType) {
                String value = filter.get("value").getAsString();
                Boolean bVal = Boolean.valueOf(value);
                restriction.add(new AttributeValueRestriction(mdAttribute, operation, bVal, forDate));
            } else if (attributeType instanceof AttributeTermType) {
                String code = filter.get("value").getAsString();
                Term root = ((AttributeTermType) attributeType).getRootTerm();
                String parent = TermConverter.buildClassifierKeyFromTermCode(root.getCode());
                String classifierKey = Classifier.buildKey(parent, code);
                Classifier classifier = Classifier.getByKey(classifierKey);
                restriction.add(new AttributeValueRestriction(mdAttribute, operation, classifier.getOid(), forDate));
            } else if (attributeType instanceof AttributeClassificationType) {
                JsonObject object = filter.get("value").getAsJsonObject();
                Term term = Term.fromJSON(object);
                MdClassificationDAOIF mdClassification = ((MdAttributeClassificationDAOIF) mdAttribute).getMdClassificationDAOIF();
                MdEdgeDAOIF mdEdge = mdClassification.getReferenceMdEdgeDAO();
                ClassificationType classificationType = new ClassificationType(mdClassification);
                Classification classification = Classification.get(classificationType, term.getCode());
                restriction.add(new AttributeValueRestriction(mdAttribute, operation, classification.getVertex().getRID(), forDate));
            } else {
                String value = filter.get("value").getAsString();
                restriction.add(new AttributeValueRestriction(mdAttribute, operation, value, forDate));
            }
        }
        if (restriction.getRestrictions().size() > 0) {
            return restriction;
        }
    }
    return null;
}
Also used : CompositeRestriction(net.geoprism.registry.query.graph.CompositeRestriction) MdEdgeDAOIF(com.runwaysdk.dataaccess.MdEdgeDAOIF) JsonObject(com.google.gson.JsonObject) Term(org.commongeoregistry.adapter.Term) Classifier(net.geoprism.ontology.Classifier) AttributeClassificationType(org.commongeoregistry.adapter.metadata.AttributeClassificationType) ClassificationType(net.geoprism.registry.model.ClassificationType) AttributeClassificationType(org.commongeoregistry.adapter.metadata.AttributeClassificationType) Date(java.util.Date) AttributeDateType(org.commongeoregistry.adapter.metadata.AttributeDateType) AttributeValueRestriction(net.geoprism.registry.query.graph.AttributeValueRestriction) JsonArray(com.google.gson.JsonArray) MdClassificationDAOIF(com.runwaysdk.dataaccess.MdClassificationDAOIF) MdAttributeDAOIF(com.runwaysdk.dataaccess.MdAttributeDAOIF) AttributeType(org.commongeoregistry.adapter.metadata.AttributeType) Classification(net.geoprism.registry.model.Classification) AttributeBooleanType(org.commongeoregistry.adapter.metadata.AttributeBooleanType) AttributeTermType(org.commongeoregistry.adapter.metadata.AttributeTermType)

Example 15 with Classification

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

the class AttributeTypeConverter method build.

public AttributeType build(MdAttributeConcreteDAOIF mdAttribute) {
    Locale locale = Session.getCurrentLocale();
    String attributeName = mdAttribute.definesAttribute();
    LocalizedValue displayLabel = AttributeTypeConverter.convert(mdAttribute.getDisplayLabel(locale), mdAttribute.getDisplayLabels());
    LocalizedValue description = AttributeTypeConverter.convert(mdAttribute.getDescription(locale), mdAttribute.getDescriptions());
    boolean required = mdAttribute.isRequired();
    boolean unique = mdAttribute.isUnique();
    boolean isChangeOverTime = true;
    DefaultAttribute defaultAttr = DefaultAttribute.getByAttributeName(attributeName);
    if (defaultAttr != null) {
        isChangeOverTime = defaultAttr.isChangeOverTime();
    }
    if (mdAttribute instanceof MdAttributeBooleanDAOIF) {
        return AttributeType.factory(attributeName, displayLabel, description, AttributeBooleanType.TYPE, required, unique, isChangeOverTime);
    } else if (mdAttribute instanceof MdAttributeLocalDAOIF) {
        return AttributeType.factory(attributeName, displayLabel, description, AttributeLocalType.TYPE, required, unique, isChangeOverTime);
    } else if (mdAttribute instanceof MdAttributeCharacterDAOIF) {
        return AttributeType.factory(attributeName, displayLabel, description, AttributeCharacterType.TYPE, required, unique, isChangeOverTime);
    } else if (mdAttribute instanceof MdAttributeDateDAOIF || mdAttribute instanceof MdAttributeDateTimeDAOIF) {
        return AttributeType.factory(attributeName, displayLabel, description, AttributeDateType.TYPE, required, unique, isChangeOverTime);
    } else if (mdAttribute instanceof MdAttributeDecDAOIF) {
        MdAttributeDecDAOIF mdAttributeDec = (MdAttributeDecDAOIF) mdAttribute;
        AttributeFloatType attributeType = (AttributeFloatType) AttributeType.factory(attributeName, displayLabel, description, AttributeFloatType.TYPE, required, unique, isChangeOverTime);
        attributeType.setPrecision(Integer.parseInt(mdAttributeDec.getLength()));
        attributeType.setScale(Integer.parseInt(mdAttributeDec.getDecimal()));
        return attributeType;
    } else if (mdAttribute instanceof MdAttributeIntegerDAOIF || mdAttribute instanceof MdAttributeLongDAOIF) {
        return AttributeType.factory(attributeName, displayLabel, description, AttributeIntegerType.TYPE, required, unique, isChangeOverTime);
    } else if (mdAttribute instanceof MdAttributeClassificationDAOIF) {
        MdClassificationDAOIF mdClassification = ((MdAttributeClassificationDAOIF) mdAttribute).getMdClassificationDAOIF();
        AttributeClassificationType attributeType = (AttributeClassificationType) AttributeType.factory(attributeName, displayLabel, description, AttributeClassificationType.TYPE, required, unique, isChangeOverTime);
        attributeType.setClassificationType(mdClassification.getValue(MdClassificationInfo.TYPE_NAME));
        String rootOid = ((MdAttributeClassificationDAOIF) mdAttribute).getValue(MdAttributeClassificationInfo.ROOT);
        if (rootOid != null && rootOid.length() > 0) {
            ClassificationType type = new ClassificationType(mdClassification);
            Classification classification = Classification.getByOid(type, rootOid);
            attributeType.setRootTerm(classification.toTerm());
        }
        return attributeType;
    } else if (mdAttribute instanceof MdAttributeEnumerationDAOIF || mdAttribute instanceof MdAttributeTermDAOIF) {
        AttributeTermType attributeType = (AttributeTermType) AttributeType.factory(attributeName, displayLabel, description, AttributeTermType.TYPE, required, unique, isChangeOverTime);
        if (mdAttribute instanceof MdAttributeTermDAOIF) {
            List<RelationshipDAOIF> rels = ((MdAttributeTermDAOIF) mdAttribute).getAllAttributeRoots();
            if (rels.size() > 0) {
                RelationshipDAOIF rel = rels.get(0);
                BusinessDAO classy = (BusinessDAO) rel.getChild();
                TermConverter termBuilder = new TermConverter(classy.getKey());
                Term adapterTerm = termBuilder.build();
                attributeType.setRootTerm(adapterTerm);
            } else {
                throw new ProgrammingErrorException("Expected an attribute root on MdAttribute [" + mdAttribute.getKey() + "].");
            }
        } else {
            throw new ProgrammingErrorException("Enum attributes are not supported at this time.");
        }
        return attributeType;
    }
    throw new UnsupportedOperationException("Unsupported attribute type [" + mdAttribute.getClass().getSimpleName() + "]");
}
Also used : Locale(java.util.Locale) AttributeFloatType(org.commongeoregistry.adapter.metadata.AttributeFloatType) MdClassificationDAOIF(com.runwaysdk.dataaccess.MdClassificationDAOIF) RelationshipDAOIF(com.runwaysdk.dataaccess.RelationshipDAOIF) LocalizedValue(org.commongeoregistry.adapter.dataaccess.LocalizedValue) MdAttributeEnumerationDAOIF(com.runwaysdk.dataaccess.MdAttributeEnumerationDAOIF) MdAttributeLongDAOIF(com.runwaysdk.dataaccess.MdAttributeLongDAOIF) MdAttributeIntegerDAOIF(com.runwaysdk.dataaccess.MdAttributeIntegerDAOIF) Classification(net.geoprism.registry.model.Classification) MdAttributeTermDAOIF(com.runwaysdk.dataaccess.MdAttributeTermDAOIF) List(java.util.List) MdAttributeBooleanDAOIF(com.runwaysdk.dataaccess.MdAttributeBooleanDAOIF) BusinessDAO(com.runwaysdk.dataaccess.BusinessDAO) MdAttributeDateTimeDAOIF(com.runwaysdk.dataaccess.MdAttributeDateTimeDAOIF) Term(org.commongeoregistry.adapter.Term) AttributeClassificationType(org.commongeoregistry.adapter.metadata.AttributeClassificationType) AttributeClassificationType(org.commongeoregistry.adapter.metadata.AttributeClassificationType) ClassificationType(net.geoprism.registry.model.ClassificationType) ProgrammingErrorException(com.runwaysdk.dataaccess.ProgrammingErrorException) MdAttributeLocalDAOIF(com.runwaysdk.dataaccess.MdAttributeLocalDAOIF) MdAttributeDecDAOIF(com.runwaysdk.dataaccess.MdAttributeDecDAOIF) DefaultAttribute(org.commongeoregistry.adapter.constants.DefaultAttribute) MdAttributeClassificationDAOIF(com.runwaysdk.dataaccess.MdAttributeClassificationDAOIF) MdAttributeDateDAOIF(com.runwaysdk.dataaccess.MdAttributeDateDAOIF) AttributeTermType(org.commongeoregistry.adapter.metadata.AttributeTermType) MdAttributeCharacterDAOIF(com.runwaysdk.dataaccess.MdAttributeCharacterDAOIF)

Aggregations

Classification (net.geoprism.registry.model.Classification)27 Request (com.runwaysdk.session.Request)19 ClassificationType (net.geoprism.registry.model.ClassificationType)14 LocalizedValue (org.commongeoregistry.adapter.dataaccess.LocalizedValue)9 AttributeClassificationType (org.commongeoregistry.adapter.metadata.AttributeClassificationType)8 AttributeTermType (org.commongeoregistry.adapter.metadata.AttributeTermType)8 Classifier (net.geoprism.ontology.Classifier)7 AttributeType (org.commongeoregistry.adapter.metadata.AttributeType)7 Term (org.commongeoregistry.adapter.Term)6 AbstractClassification (com.runwaysdk.system.AbstractClassification)5 ServerGeoObjectType (net.geoprism.registry.model.ServerGeoObjectType)5 JsonObject (com.google.gson.JsonObject)4 EdgeObject (com.runwaysdk.business.graph.EdgeObject)4 GraphObject (com.runwaysdk.business.graph.GraphObject)4 VertexObject (com.runwaysdk.business.graph.VertexObject)4 LineString (com.vividsolutions.jts.geom.LineString)4 MultiLineString (com.vividsolutions.jts.geom.MultiLineString)4 Test (org.junit.Test)4 JsonArray (com.google.gson.JsonArray)3 MdClassificationDAOIF (com.runwaysdk.dataaccess.MdClassificationDAOIF)3