Search in sources :

Example 6 with MdClassificationDAOIF

use of com.runwaysdk.dataaccess.MdClassificationDAOIF 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)

Aggregations

MdClassificationDAOIF (com.runwaysdk.dataaccess.MdClassificationDAOIF)6 AttributeClassificationType (org.commongeoregistry.adapter.metadata.AttributeClassificationType)4 AttributeTermType (org.commongeoregistry.adapter.metadata.AttributeTermType)4 Classifier (net.geoprism.ontology.Classifier)3 Classification (net.geoprism.registry.model.Classification)3 ClassificationType (net.geoprism.registry.model.ClassificationType)3 Term (org.commongeoregistry.adapter.Term)3 AttributeType (org.commongeoregistry.adapter.metadata.AttributeType)3 JsonObject (com.google.gson.JsonObject)2 VertexObject (com.runwaysdk.business.graph.VertexObject)2 MdAttributeClassificationDAOIF (com.runwaysdk.dataaccess.MdAttributeClassificationDAOIF)2 MdEdgeDAOIF (com.runwaysdk.dataaccess.MdEdgeDAOIF)2 MdVertexDAOIF (com.runwaysdk.dataaccess.MdVertexDAOIF)2 List (java.util.List)2 Locale (java.util.Locale)2 DefaultAttribute (org.commongeoregistry.adapter.constants.DefaultAttribute)2 JsonArray (com.google.gson.JsonArray)1 EdgeObject (com.runwaysdk.business.graph.EdgeObject)1 GraphObject (com.runwaysdk.business.graph.GraphObject)1 BusinessDAO (com.runwaysdk.dataaccess.BusinessDAO)1