Search in sources :

Example 21 with ValueOverTime

use of com.runwaysdk.dataaccess.graph.attributes.ValueOverTime in project geoprism-registry by terraframe.

the class UndirectedGraphStrategy method addParent.

@SuppressWarnings("unchecked")
@Override
public <T extends ServerGraphNode> T addParent(VertexServerGeoObject geoObject, VertexServerGeoObject parent, Date startDate, Date endDate) {
    if (this.isCycle(geoObject, parent, startDate, endDate)) {
        throw new UnsupportedOperationException("Cyclic graph is not supported");
    }
    if (this.getEdges(geoObject, parent, startDate, endDate).size() > 0) {
        throw new UnsupportedOperationException("Duplicate edge");
    }
    Set<ValueOverTime> votc = this.getParentCollection(geoObject);
    votc.add(new ValueOverTime(startDate, endDate, parent));
    SortedSet<EdgeObject> newEdges = this.setParentCollection(geoObject, votc);
    ServerParentGraphNode node = new ServerParentGraphNode(geoObject, this.type, startDate, endDate, null);
    node.addParent(new ServerParentGraphNode(parent, this.type, startDate, endDate, newEdges.first().getOid()));
    return (T) node;
}
Also used : ValueOverTime(com.runwaysdk.dataaccess.graph.attributes.ValueOverTime) EdgeObject(com.runwaysdk.business.graph.EdgeObject) ServerParentGraphNode(net.geoprism.registry.model.ServerParentGraphNode)

Example 22 with ValueOverTime

use of com.runwaysdk.dataaccess.graph.attributes.ValueOverTime in project geoprism-registry by terraframe.

the class VertexServerGeoObject method addParent.

@Override
public ServerParentTreeNode addParent(ServerGeoObjectIF parent, ServerHierarchyType hierarchyType, Date startDate, Date endDate) {
    if (!hierarchyType.getUniversalType().equals(AllowedIn.CLASS)) {
        hierarchyType.validateUniversalRelationship(this.getType(), parent.getType());
    }
    ValueOverTimeCollection votc = this.getParentCollection(hierarchyType);
    votc.add(new ValueOverTime(startDate, endDate, parent));
    SortedSet<EdgeObject> newEdges = this.setParentCollection(hierarchyType, votc);
    ServerParentTreeNode node = new ServerParentTreeNode(this, hierarchyType, startDate, null, null);
    node.addParent(new ServerParentTreeNode(parent, hierarchyType, startDate, null, newEdges.first().getOid()));
    return node;
}
Also used : ValueOverTime(com.runwaysdk.dataaccess.graph.attributes.ValueOverTime) ServerParentTreeNode(net.geoprism.registry.model.ServerParentTreeNode) EdgeObject(com.runwaysdk.business.graph.EdgeObject) ValueOverTimeCollection(com.runwaysdk.dataaccess.graph.attributes.ValueOverTimeCollection)

Example 23 with ValueOverTime

use of com.runwaysdk.dataaccess.graph.attributes.ValueOverTime 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 24 with ValueOverTime

use of com.runwaysdk.dataaccess.graph.attributes.ValueOverTime in project geoprism-registry by terraframe.

the class VertexServerGeoObject method setParentCollection.

public SortedSet<EdgeObject> setParentCollection(ServerHierarchyType hierarchyType, ValueOverTimeCollection votc) {
    SortedSet<EdgeObject> newEdges = new TreeSet<EdgeObject>(new EdgeComparator());
    SortedSet<EdgeObject> edges = this.getEdges(hierarchyType);
    for (EdgeObject edge : edges) {
        final Date startDate = edge.getObjectValue(GeoVertex.START_DATE);
        final Date endDate = edge.getObjectValue(GeoVertex.END_DATE);
        VertexObject parentVertex = edge.getParent();
        MdVertexDAOIF mdVertex = (MdVertexDAOIF) parentVertex.getMdClass();
        ServerGeoObjectType parentType = ServerGeoObjectType.get(mdVertex);
        final VertexServerGeoObject edgeGo = new VertexServerGeoObject(parentType, parentVertex, startDate);
        ValueOverTime inVot = null;
        for (ValueOverTime vot : votc) {
            if (vot.getOid() == edge.getOid()) {
                inVot = vot;
                break;
            }
        }
        if (inVot == null) {
            edge.delete();
        } else {
            VertexServerGeoObject inGo = (VertexServerGeoObject) inVot.getValue();
            boolean hasValueChange = false;
            if ((inGo == null && edgeGo != null) || (inGo != null && edgeGo == null)) {
                hasValueChange = true;
            } else if ((inGo != null && edgeGo != null) && !inGo.equals(edgeGo)) {
                hasValueChange = true;
            }
            if (hasValueChange) {
                edge.delete();
                EdgeObject newEdge = this.getVertex().addParent(inGo.getVertex(), hierarchyType.getMdEdge());
                newEdge.setValue(GeoVertex.START_DATE, startDate);
                newEdge.setValue(GeoVertex.END_DATE, endDate);
                newEdge.apply();
                newEdges.add(newEdge);
            } else {
                boolean hasChanges = false;
                if (startDate != inVot.getStartDate()) {
                    hasChanges = true;
                    edge.setValue(GeoVertex.START_DATE, startDate);
                }
                if (endDate != inVot.getEndDate()) {
                    hasChanges = true;
                    edge.setValue(GeoVertex.END_DATE, endDate);
                }
                if (hasChanges) {
                    edge.apply();
                }
            }
        }
    }
    for (ValueOverTime vot : votc) {
        boolean isNew = true;
        for (EdgeObject edge : edges) {
            if (vot.getOid() == edge.getOid()) {
                isNew = false;
            }
        }
        if (isNew) {
            EdgeObject newEdge = this.getVertex().addParent(((VertexServerGeoObject) vot.getValue()).getVertex(), hierarchyType.getMdEdge());
            newEdge.setValue(GeoVertex.START_DATE, vot.getStartDate());
            newEdge.setValue(GeoVertex.END_DATE, vot.getEndDate());
            newEdge.apply();
            newEdges.add(newEdge);
        }
    }
    return newEdges;
}
Also used : MdVertexDAOIF(com.runwaysdk.dataaccess.MdVertexDAOIF) ValueOverTime(com.runwaysdk.dataaccess.graph.attributes.ValueOverTime) VertexObject(com.runwaysdk.business.graph.VertexObject) EdgeObject(com.runwaysdk.business.graph.EdgeObject) TreeSet(java.util.TreeSet) ServerGeoObjectType(net.geoprism.registry.model.ServerGeoObjectType) Date(java.util.Date) LocalDate(java.time.LocalDate)

Example 25 with ValueOverTime

use of com.runwaysdk.dataaccess.graph.attributes.ValueOverTime in project geoprism-registry by terraframe.

the class UpdateChangeOverTimeAttributeView method execute.

@Override
public void execute(VertexServerGeoObject go) {
    String attributeName = this.getAttributeNameGeomAccounting(go);
    // This list is intentionally NOT a ValueOverTimeCollection. The reason for this is because we
    // DON'T want any of the reordering or splitting logic to happen until AFTER we have applied
    // all of the actions. The logic we want to avoid is ValueOverTimeCollection.calculateStartDates
    List<ValueOverTime> looseVotc = new ArrayList<ValueOverTime>(go.getValuesOverTime(attributeName));
    for (UpdateValueOverTimeView vot : this.valuesOverTime) {
        vot.execute(this, go, looseVotc);
    }
    ValueOverTimeCollection newVotc = new ValueOverTimeCollection();
    newVotc.addAll(looseVotc);
    this.validateValuesOverTime(newVotc);
    go.getVertex().getGraphObjectDAO().getAttribute(attributeName).setValuesOverTime(newVotc);
}
Also used : ValueOverTime(com.runwaysdk.dataaccess.graph.attributes.ValueOverTime) ArrayList(java.util.ArrayList) ValueOverTimeCollection(com.runwaysdk.dataaccess.graph.attributes.ValueOverTimeCollection)

Aggregations

ValueOverTime (com.runwaysdk.dataaccess.graph.attributes.ValueOverTime)44 ValueOverTimeCollection (com.runwaysdk.dataaccess.graph.attributes.ValueOverTimeCollection)29 Request (com.runwaysdk.session.Request)26 Date (java.util.Date)22 ServerGeoObjectIF (net.geoprism.registry.model.ServerGeoObjectIF)18 Test (org.junit.Test)16 EdgeObject (com.runwaysdk.business.graph.EdgeObject)10 ChangeRequest (net.geoprism.registry.action.ChangeRequest)10 VertexServerGeoObject (net.geoprism.registry.model.graph.VertexServerGeoObject)10 VertexObject (com.runwaysdk.business.graph.VertexObject)9 UpdateAttributeAction (net.geoprism.registry.action.geoobject.UpdateAttributeAction)9 MdVertexDAOIF (com.runwaysdk.dataaccess.MdVertexDAOIF)8 ServerGeoObjectType (net.geoprism.registry.model.ServerGeoObjectType)8 SimpleDateFormat (java.text.SimpleDateFormat)6 AbstractAction (net.geoprism.registry.action.AbstractAction)6 JsonArray (com.google.gson.JsonArray)5 JsonObject (com.google.gson.JsonObject)5 QueryFactory (com.runwaysdk.query.QueryFactory)5 TreeSet (java.util.TreeSet)5 ChangeRequestQuery (net.geoprism.registry.action.ChangeRequestQuery)5