Search in sources :

Example 21 with Classifier

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

the class ServerGeoObjectType method deleteInTransaction.

@Transaction
private void deleteInTransaction() {
    List<ServerHierarchyType> hierarchies = this.getHierarchies(true);
    if (hierarchies.size() > 0) {
        StringBuilder codes = hierarchies.stream().collect(StringBuilder::new, (x, y) -> x.append(y.getCode()), (a, b) -> a.append(",").append(b));
        throw new TypeInUseException("Cannot delete a GeoObjectType used in the hierarchies: " + codes);
    }
    // for (String hierarchy : hierarchies)
    // {
    // OIterator<com.runwaysdk.business.ontology.Term> it =
    // this.universal.getDirectDescendants(hierarchy);
    // 
    // try
    // {
    // if (it.hasNext())
    // {
    // }
    // }
    // finally
    // {
    // it.close();
    // }
    // }
    /*
     * Delete all subtypes
     */
    List<ServerGeoObjectType> subtypes = this.getSubtypes();
    for (ServerGeoObjectType subtype : subtypes) {
        subtype.deleteInTransaction();
    }
    /*
     * Delete all inherited hierarchies
     */
    List<? extends InheritedHierarchyAnnotation> annotations = InheritedHierarchyAnnotation.getByUniversal(getUniversal());
    for (InheritedHierarchyAnnotation annotation : annotations) {
        annotation.delete();
    }
    GeoVertexType.remove(this.universal.getUniversalId());
    /*
     * Delete all Attribute references
     */
    // AttributeHierarchy.deleteByUniversal(this.universal);
    this.getMetadata().delete();
    // This deletes the {@link MdBusiness} as well
    this.universal.delete(false);
    // Delete the term root
    Classifier classRootTerm = TermConverter.buildIfNotExistdMdBusinessClassifier(this.mdBusiness);
    classRootTerm.delete();
    // roles specified on the super type.
    if (this.getSuperType() == null) {
        Actor ownerActor = this.universal.getOwner();
        if (ownerActor instanceof Roles) {
            Roles ownerRole = (Roles) ownerActor;
            String roleName = ownerRole.getRoleName();
            if (RegistryRole.Type.isOrgRole(roleName)) {
                String organizationCode = RegistryRole.Type.parseOrgCode(roleName);
                String geoObjectTypeCode = this.type.getCode();
                String rmRoleName = RegistryRole.Type.getRM_RoleName(organizationCode, geoObjectTypeCode);
                Roles role = Roles.findRoleByName(rmRoleName);
                role.delete();
                String rcRoleName = RegistryRole.Type.getRC_RoleName(organizationCode, geoObjectTypeCode);
                role = Roles.findRoleByName(rcRoleName);
                role.delete();
                String acRoleName = RegistryRole.Type.getAC_RoleName(organizationCode, geoObjectTypeCode);
                role = Roles.findRoleByName(acRoleName);
                role.delete();
            }
        }
    }
    ListType.markAllAsInvalid(null, this);
    new SearchService().clear(this.getCode());
    new ChangeRequestService().markAllAsInvalid(this);
    // Delete the transition and transition events
    TransitionEvent.removeAll(this);
    Transition.removeAll(this);
}
Also used : InheritedHierarchyAnnotation(net.geoprism.registry.InheritedHierarchyAnnotation) Roles(com.runwaysdk.system.Roles) Classifier(net.geoprism.ontology.Classifier) TypeInUseException(net.geoprism.registry.TypeInUseException) ChangeRequestService(net.geoprism.registry.service.ChangeRequestService) Actor(com.runwaysdk.system.Actor) SearchService(net.geoprism.registry.service.SearchService) Transaction(com.runwaysdk.dataaccess.transaction.Transaction)

Example 22 with Classifier

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

the class VertexServerGeoObject method toGeoObjectOverTime.

public GeoObjectOverTime toGeoObjectOverTime(boolean generateUid) {
    Map<String, ValueOverTimeCollectionDTO> votAttributeMap = GeoObjectOverTime.buildVotAttributeMap(type.getType());
    Map<String, Attribute> attributeMap = GeoObjectOverTime.buildAttributeMap(type.getType());
    GeoObjectOverTime geoObj = new GeoObjectOverTime(type.getType(), votAttributeMap, attributeMap);
    Map<String, AttributeType> attributes = type.getAttributeMap();
    attributes.forEach((attributeName, attribute) -> {
        if (attributeName.equals(DefaultAttribute.DISPLAY_LABEL.getName())) {
            ValueOverTimeCollection votc = this.getValuesOverTime(attributeName);
            ValueOverTimeCollectionDTO votcDTO = new ValueOverTimeCollectionDTO(attribute);
            for (ValueOverTime vot : votc) {
                Object value = this.getDisplayLabel(vot.getStartDate());
                ValueOverTimeDTO votDTO = new ValueOverTimeDTO(vot.getOid(), vot.getStartDate(), vot.getEndDate(), votcDTO);
                votDTO.setValue(value);
                votcDTO.add(votDTO);
            }
            geoObj.setValueCollection(attributeName, votcDTO);
        } else // }
        if (vertex.hasAttribute(attributeName)) {
            if (attribute.isChangeOverTime()) {
                ValueOverTimeCollection votc = this.getValuesOverTime(attributeName);
                ValueOverTimeCollectionDTO votcDTO = new ValueOverTimeCollectionDTO(attribute);
                for (ValueOverTime vot : votc) {
                    // if (attributeName.equals(DefaultAttribute.STATUS.getName()))
                    // {
                    // Term statusTerm =
                    // ServiceFactory.getConversionService().geoObjectStatusToTerm(this.getStatus(vot.getStartDate()));
                    // 
                    // ValueOverTimeDTO votDTO = new ValueOverTimeDTO(vot.getOid(),
                    // vot.getStartDate(), vot.getEndDate(), votcDTO);
                    // votDTO.setValue(statusTerm.getCode());
                    // votcDTO.add(votDTO);
                    // }
                    // else
                    // {
                    Object value = vot.getValue();
                    if (value != null) {
                        if (attribute instanceof AttributeTermType) {
                            Classifier classifier = Classifier.get((String) value);
                            try {
                                ValueOverTimeDTO votDTO = new ValueOverTimeDTO(vot.getOid(), vot.getStartDate(), vot.getEndDate(), votcDTO);
                                votDTO.setValue(classifier.getClassifierId());
                                votcDTO.add(votDTO);
                            } catch (UnknownTermException e) {
                                TermValueException ex = new TermValueException();
                                ex.setAttributeLabel(e.getAttribute().getLabel().getValue());
                                ex.setCode(e.getCode());
                                throw e;
                            }
                        } else if (attribute instanceof AttributeClassificationType) {
                            String classificationTypeCode = ((AttributeClassificationType) attribute).getClassificationType();
                            ClassificationType classificationType = ClassificationType.getByCode(classificationTypeCode);
                            Classification classification = Classification.getByOid(classificationType, (String) value);
                            try {
                                ValueOverTimeDTO votDTO = new ValueOverTimeDTO(vot.getOid(), vot.getStartDate(), vot.getEndDate(), votcDTO);
                                votDTO.setValue(classification.toTerm());
                                votcDTO.add(votDTO);
                            } catch (UnknownTermException e) {
                                TermValueException ex = new TermValueException();
                                ex.setAttributeLabel(e.getAttribute().getLabel().getValue());
                                ex.setCode(e.getCode());
                                throw e;
                            }
                        } else {
                            ValueOverTimeDTO votDTO = new ValueOverTimeDTO(vot.getOid(), vot.getStartDate(), vot.getEndDate(), votcDTO);
                            votDTO.setValue(value);
                            votcDTO.add(votDTO);
                        }
                    }
                // }
                }
                geoObj.setValueCollection(attributeName, votcDTO);
            } else {
                Object value = this.getValue(attributeName);
                if (value != null) {
                    if (attribute instanceof AttributeTermType) {
                        Classifier classifier = Classifier.get((String) value);
                        try {
                            geoObj.setValue(attributeName, classifier.getClassifierId());
                        } catch (UnknownTermException e) {
                            TermValueException ex = new TermValueException();
                            ex.setAttributeLabel(e.getAttribute().getLabel().getValue());
                            ex.setCode(e.getCode());
                            throw e;
                        }
                    } else if (attribute instanceof AttributeClassificationType) {
                        String classificationType = ((AttributeClassificationType) attribute).getClassificationType();
                        MdClassificationDAOIF mdClassificationDAO = MdClassificationDAO.getMdClassificationDAO(classificationType);
                        MdVertexDAOIF mdVertexDAO = mdClassificationDAO.getReferenceMdVertexDAO();
                        VertexObject classification = VertexObject.get(mdVertexDAO, (String) value);
                        try {
                            geoObj.setValue(attributeName, classification.getObjectValue(AbstractClassification.CODE));
                        } catch (UnknownTermException e) {
                            TermValueException ex = new TermValueException();
                            ex.setAttributeLabel(e.getAttribute().getLabel().getValue());
                            ex.setCode(e.getCode());
                            throw e;
                        }
                    } else {
                        geoObj.setValue(attributeName, value);
                    }
                }
            }
        }
    });
    if (// && !vertex.isAppliedToDB())
    generateUid && vertex.isNew()) {
        geoObj.setUid(RegistryIdService.getInstance().next());
    // geoObj.setStatus(ServiceFactory.getAdapter().getMetadataCache().getTerm(DefaultTerms.GeoObjectStatusTerm.NEW.code).get(),
    // this.date, this.date);
    } else {
        geoObj.setUid(vertex.getObjectValue(RegistryConstants.UUID));
    }
    ValueOverTimeCollection votc = this.getValuesOverTime(this.getGeometryAttributeName());
    ValueOverTimeCollectionDTO votcDTO = new ValueOverTimeCollectionDTO(geoObj.getGeometryAttributeType());
    for (ValueOverTime vot : votc) {
        Object value = vot.getValue();
        ValueOverTimeDTO votDTO = new ValueOverTimeDTO(vot.getOid(), vot.getStartDate(), vot.getEndDate(), votcDTO);
        votDTO.setValue(value);
        votcDTO.add(votDTO);
    }
    geoObj.setValueCollection(DefaultAttribute.GEOMETRY.getName(), votcDTO);
    geoObj.setCode(vertex.getObjectValue(DefaultAttribute.CODE.getName()));
    return geoObj;
}
Also used : MdVertexDAOIF(com.runwaysdk.dataaccess.MdVertexDAOIF) ValueOverTimeCollectionDTO(org.commongeoregistry.adapter.dataaccess.ValueOverTimeCollectionDTO) Attribute(org.commongeoregistry.adapter.dataaccess.Attribute) DefaultAttribute(org.commongeoregistry.adapter.constants.DefaultAttribute) VertexObject(com.runwaysdk.business.graph.VertexObject) GeoObjectOverTime(org.commongeoregistry.adapter.dataaccess.GeoObjectOverTime) ValueOverTimeDTO(org.commongeoregistry.adapter.dataaccess.ValueOverTimeDTO) MultiLineString(com.vividsolutions.jts.geom.MultiLineString) LineString(com.vividsolutions.jts.geom.LineString) Classifier(net.geoprism.ontology.Classifier) AttributeClassificationType(org.commongeoregistry.adapter.metadata.AttributeClassificationType) ClassificationType(net.geoprism.registry.model.ClassificationType) AttributeClassificationType(org.commongeoregistry.adapter.metadata.AttributeClassificationType) MdClassificationDAOIF(com.runwaysdk.dataaccess.MdClassificationDAOIF) ValueOverTime(com.runwaysdk.dataaccess.graph.attributes.ValueOverTime) TermValueException(net.geoprism.registry.io.TermValueException) AttributeType(org.commongeoregistry.adapter.metadata.AttributeType) Classification(net.geoprism.registry.model.Classification) AbstractClassification(com.runwaysdk.system.AbstractClassification) ValueOverTimeCollection(com.runwaysdk.dataaccess.graph.attributes.ValueOverTimeCollection) 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) AttributeTermType(org.commongeoregistry.adapter.metadata.AttributeTermType) UnknownTermException(org.commongeoregistry.adapter.dataaccess.UnknownTermException)

Example 23 with Classifier

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

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

the class VertexServerGeoObject method toGeoObject.

@Override
public GeoObject toGeoObject(Date date) {
    Map<String, Attribute> attributeMap = GeoObject.buildAttributeMap(type.getType());
    GeoObject geoObj = new GeoObject(type.getType(), type.getGeometryType(), attributeMap);
    Map<String, AttributeType> attributes = type.getAttributeMap();
    attributes.forEach((attributeName, attribute) -> {
        if (attributeName.equals(DefaultAttribute.TYPE.getName())) {
        // Ignore
        } else if (vertex.hasAttribute(attributeName)) {
            Object value = vertex.getObjectValue(attributeName, date);
            if (value != null) {
                if (attribute instanceof AttributeTermType) {
                    Classifier classifier = Classifier.get((String) value);
                    try {
                        geoObj.setValue(attributeName, classifier.getClassifierId());
                    } catch (UnknownTermException e) {
                        TermValueException ex = new TermValueException();
                        ex.setAttributeLabel(e.getAttribute().getLabel().getValue());
                        ex.setCode(e.getCode());
                        throw e;
                    }
                } else if (attribute instanceof AttributeClassificationType) {
                    String classificationTypeCode = ((AttributeClassificationType) attribute).getClassificationType();
                    ClassificationType classificationType = ClassificationType.getByCode(classificationTypeCode);
                    Classification classification = Classification.getByOid(classificationType, (String) value);
                    try {
                        geoObj.setValue(attributeName, classification.toTerm());
                    } catch (UnknownTermException e) {
                        TermValueException ex = new TermValueException();
                        ex.setAttributeLabel(e.getAttribute().getLabel().getValue());
                        ex.setCode(e.getCode());
                        throw e;
                    }
                } else {
                    geoObj.setValue(attributeName, value);
                }
            }
        }
    });
    geoObj.setUid(vertex.getObjectValue(RegistryConstants.UUID));
    geoObj.setCode(vertex.getObjectValue(DefaultAttribute.CODE.getName()));
    geoObj.setGeometry(this.getGeometry());
    geoObj.setDisplayLabel(this.getDisplayLabel());
    geoObj.setExists(this.getExists(date));
    geoObj.setInvalid(this.getInvalid());
    if (// && !vertex.isAppliedToDB())
    vertex.isNew()) {
        geoObj.setUid(RegistryIdService.getInstance().next());
    }
    return geoObj;
}
Also used : Attribute(org.commongeoregistry.adapter.dataaccess.Attribute) DefaultAttribute(org.commongeoregistry.adapter.constants.DefaultAttribute) MultiLineString(com.vividsolutions.jts.geom.MultiLineString) LineString(com.vividsolutions.jts.geom.LineString) Classifier(net.geoprism.ontology.Classifier) AttributeClassificationType(org.commongeoregistry.adapter.metadata.AttributeClassificationType) ClassificationType(net.geoprism.registry.model.ClassificationType) AttributeClassificationType(org.commongeoregistry.adapter.metadata.AttributeClassificationType) TermValueException(net.geoprism.registry.io.TermValueException) AttributeType(org.commongeoregistry.adapter.metadata.AttributeType) Classification(net.geoprism.registry.model.Classification) AbstractClassification(com.runwaysdk.system.AbstractClassification) GeoObject(org.commongeoregistry.adapter.dataaccess.GeoObject) AbstractServerGeoObject(net.geoprism.registry.model.AbstractServerGeoObject) 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) AttributeTermType(org.commongeoregistry.adapter.metadata.AttributeTermType) UnknownTermException(org.commongeoregistry.adapter.dataaccess.UnknownTermException)

Example 25 with Classifier

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

the class RegistryService method findRootClassifier.

private List<MdAttributeConcrete> findRootClassifier(Classifier classifier, List<MdAttributeConcrete> mdAttributeList) {
    // Is this a root term for an {@link MdAttributeTerm}
    OIterator<? extends MdAttributeTerm> attrTerm = classifier.getAllClassifierTermAttributeRoots();
    for (MdAttributeTerm mdAttributeTerm : attrTerm) {
        mdAttributeList.add(mdAttributeTerm);
    }
    OIterator<? extends MdAttributeMultiTerm> attrMultiTerm = classifier.getAllClassifierMultiTermAttributeRoots();
    for (MdAttributeMultiTerm mdAttributeMultiTerm : attrMultiTerm) {
        mdAttributeList.add(mdAttributeMultiTerm);
    }
    // Traverse up the tree
    OIterator<? extends Classifier> parentTerms = classifier.getAllIsAParent();
    for (Classifier parent : parentTerms) {
        return this.findRootClassifier(parent, mdAttributeList);
    }
    return mdAttributeList;
}
Also used : MdAttributeTerm(com.runwaysdk.system.metadata.MdAttributeTerm) MdAttributeMultiTerm(com.runwaysdk.system.metadata.MdAttributeMultiTerm) Classifier(net.geoprism.ontology.Classifier)

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