Search in sources :

Example 16 with Classifier

use of net.geoprism.ontology.Classifier in project geoprism-registry by terraframe.

the class ChangeRequestServiceTest method testUpdateGeoObjectTermCR_Verify.

@Request
private void testUpdateGeoObjectTermCR_Verify(String[] data) throws Exception {
    final String attrName = FastTestDataset.AT_RELIGION.getAttributeName();
    final String oldOid = data[1];
    final SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
    sdf.setTimeZone(GeoRegistryUtil.SYSTEM_TIMEZONE);
    final Date newStartDate = sdf.parse(NEW_START_DATE);
    final Date newEndDate = sdf.parse(NEW_END_DATE);
    ChangeRequestQuery crq = new ChangeRequestQuery(new QueryFactory());
    Assert.assertEquals(1, crq.getCount());
    ChangeRequest cr = crq.getIterator().next();
    Assert.assertEquals(AllGovernanceStatus.ACCEPTED.name(), cr.getGovernanceStatus().name());
    AbstractAction action = cr.getAllAction().next();
    Assert.assertTrue(action instanceof UpdateAttributeAction);
    Assert.assertEquals(FastTestDataset.CAMBODIA.getCode(), cr.getGeoObjectCode());
    Assert.assertEquals(FastTestDataset.CAMBODIA.getGeoObjectType().getCode(), cr.getGeoObjectTypeCode());
    Assert.assertEquals(FastTestDataset.ORG_CGOV.getCode(), cr.getOrganizationCode());
    VertexServerGeoObject cambodia = (VertexServerGeoObject) FastTestDataset.CAMBODIA.getServerObject();
    ValueOverTimeCollection votc = cambodia.getValuesOverTime(attrName);
    Assert.assertEquals(1, votc.size());
    ValueOverTime vot1 = votc.get(0);
    Assert.assertNotNull(vot1.getOid());
    Assert.assertEquals(oldOid, vot1.getOid());
    Assert.assertEquals(newStartDate, vot1.getStartDate());
    Assert.assertEquals(newEndDate, vot1.getEndDate());
    String classyId = ((Classifier) cambodia.getValue(attrName, newStartDate)).getOid();
    Assert.assertEquals(FastTestDataset.T_Islam.fetchClassifier().getOid(), classyId);
    Assert.assertEquals(classyId, vot1.getValue());
}
Also used : ValueOverTime(com.runwaysdk.dataaccess.graph.attributes.ValueOverTime) QueryFactory(com.runwaysdk.query.QueryFactory) ChangeRequestQuery(net.geoprism.registry.action.ChangeRequestQuery) ValueOverTimeCollection(com.runwaysdk.dataaccess.graph.attributes.ValueOverTimeCollection) VertexServerGeoObject(net.geoprism.registry.model.graph.VertexServerGeoObject) Classifier(net.geoprism.ontology.Classifier) ChangeRequest(net.geoprism.registry.action.ChangeRequest) SimpleDateFormat(java.text.SimpleDateFormat) AbstractAction(net.geoprism.registry.action.AbstractAction) UpdateAttributeAction(net.geoprism.registry.action.geoobject.UpdateAttributeAction) Date(java.util.Date) Request(com.runwaysdk.session.Request) ChangeRequest(net.geoprism.registry.action.ChangeRequest)

Example 17 with Classifier

use of net.geoprism.ontology.Classifier 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 18 with Classifier

use of net.geoprism.ontology.Classifier in project geoprism-registry by terraframe.

the class PatchTerms method doIt.

@Transaction
private void doIt() {
    ClassifierQuery gQuery = new ClassifierQuery(new QueryFactory());
    Classifier clazz = this.getByClassifierId("CLASS");
    BusinessDAO clazzDAO = BusinessDAO.get(clazz.getOid()).getBusinessDAO();
    clazzDAO.setValue(Classifier.CLASSIFIERPACKAGE, RegistryConstants.REGISTRY_PACKAGE);
    clazzDAO.setValue(Classifier.KEYNAME, "CLASS");
    clazzDAO.apply();
    Classifier root = this.getByClassifierId("ROOT");
    BusinessDAO rootDAO = BusinessDAO.get(root.getOid()).getBusinessDAO();
    rootDAO.setValue(Classifier.CLASSIFIERPACKAGE, "ROOT");
    rootDAO.setValue(Classifier.KEYNAME, "ROOT");
    rootDAO.apply();
    try (OIterator<? extends Classifier> it = gQuery.getIterator()) {
        while (it.hasNext()) {
            Classifier classifier = it.next();
            LinkedList<Term> parents = new LinkedList<>(GeoEntityUtil.getOrderedAncestors(root, classifier, ClassifierIsARelationship.CLASS));
            Collections.reverse(parents);
            // Root -> Class Root -> Class -> Attribute -> Option
            if (parents.size() == 4) {
                Iterator<Term> pit = parents.iterator();
                // while (pit.hasNext())
                // {
                // Classifier p = (Classifier) pit.next();
                // 
                // // logger.error("[" + p.getClassifierId() + "]: ");
                // System.out.println(" Parent [" + p.getClassifierId() + "]: ");
                // }
                pit = parents.iterator();
                pit.next();
                Classifier parent = (Classifier) pit.next();
                classifier.appLock();
                classifier.setClassifierPackage(parent.getKey());
                classifier.setKeyName(Classifier.buildKey(parent.getKey(), classifier.getClassifierId()));
                classifier.apply();
            } else if (!(classifier.getOid().equals(clazz.getOid()) || classifier.getOid().equals(root.getOid()))) {
                classifier.appLock();
                classifier.setClassifierPackage(RegistryConstants.REGISTRY_PACKAGE);
                classifier.setKeyName(Classifier.buildKey(RegistryConstants.REGISTRY_PACKAGE, classifier.getClassifierId()));
                classifier.apply();
            }
        }
    }
}
Also used : ClassifierQuery(net.geoprism.ontology.ClassifierQuery) QueryFactory(com.runwaysdk.query.QueryFactory) BusinessDAO(com.runwaysdk.dataaccess.BusinessDAO) Classifier(net.geoprism.ontology.Classifier) Term(com.runwaysdk.business.ontology.Term) LinkedList(java.util.LinkedList) Transaction(com.runwaysdk.dataaccess.transaction.Transaction)

Example 19 with Classifier

use of net.geoprism.ontology.Classifier in project geoprism-registry by terraframe.

the class TermConverter method updateClassifier.

@Transaction
public static Classifier updateClassifier(String parentTermCode, String termCode, LocalizedValue value) {
    String parentClassifierKey = buildClassifierKeyFromTermCode(parentTermCode);
    Classifier parent = Classifier.getByKey(parentClassifierKey);
    enforceTermPermissions(parent, CGRPermissionAction.WRITE);
    String classifierKey = Classifier.buildKey(parent.getKey(), termCode);
    Classifier classifier = Classifier.getByKey(classifierKey);
    classifier.lock();
    classifier.setClassifierId(termCode);
    LocalizedValueConverter.populate(classifier.getDisplayLabel(), value);
    classifier.apply();
    return classifier;
}
Also used : Classifier(net.geoprism.ontology.Classifier) Transaction(com.runwaysdk.dataaccess.transaction.Transaction)

Example 20 with Classifier

use of net.geoprism.ontology.Classifier in project geoprism-registry by terraframe.

the class GeoObjectUtil method convertToTermString.

@SuppressWarnings("unchecked")
public static String convertToTermString(AttributeTermType attributeType, Object value) {
    StringBuilder builder = new StringBuilder();
    boolean first = true;
    if (value instanceof Classifier) {
        if (!first) {
            builder.append(",");
        }
        builder.append(((Classifier) value).getDisplayLabel().getValue());
        first = false;
    } else {
        Iterator<String> codes = (Iterator<String>) value;
        if (codes != null) {
            while (codes.hasNext()) {
                String code = codes.next();
                Term term = attributeType.getTermByCode(code).get();
                if (!first) {
                    builder.append(",");
                }
                builder.append(term.getLabel());
                first = false;
            }
            return builder.toString();
        }
    }
    return null;
}
Also used : Iterator(java.util.Iterator) Classifier(net.geoprism.ontology.Classifier) Term(org.commongeoregistry.adapter.Term)

Aggregations

Classifier (net.geoprism.ontology.Classifier)28 Term (org.commongeoregistry.adapter.Term)14 AttributeTermType (org.commongeoregistry.adapter.metadata.AttributeTermType)11 AttributeClassificationType (org.commongeoregistry.adapter.metadata.AttributeClassificationType)9 AttributeType (org.commongeoregistry.adapter.metadata.AttributeType)9 LocalizedValue (org.commongeoregistry.adapter.dataaccess.LocalizedValue)8 Transaction (com.runwaysdk.dataaccess.transaction.Transaction)7 Classification (net.geoprism.registry.model.Classification)7 JsonObject (com.google.gson.JsonObject)6 VertexObject (com.runwaysdk.business.graph.VertexObject)5 DataNotFoundException (com.runwaysdk.dataaccess.cache.DataNotFoundException)5 MdAttributeTermDAOIF (com.runwaysdk.dataaccess.MdAttributeTermDAOIF)4 Request (com.runwaysdk.session.Request)4 MdAttributeConcrete (com.runwaysdk.system.metadata.MdAttributeConcrete)4 MdAttributeTerm (com.runwaysdk.system.metadata.MdAttributeTerm)4 TermValueException (net.geoprism.registry.io.TermValueException)4 ServerGeoObjectType (net.geoprism.registry.model.ServerGeoObjectType)4 VertexServerGeoObject (net.geoprism.registry.model.graph.VertexServerGeoObject)4 UnknownTermException (org.commongeoregistry.adapter.dataaccess.UnknownTermException)4 EdgeObject (com.runwaysdk.business.graph.EdgeObject)3