Search in sources :

Example 11 with EdgeObject

use of com.runwaysdk.business.graph.EdgeObject in project geoprism-registry by terraframe.

the class VertexServerGeoObject method addParent.

@Override
public ServerParentTreeNode addParent(ServerGeoObjectIF parent, ServerHierarchyType hierarchyType) {
    if (!hierarchyType.getUniversalType().equals(AllowedIn.CLASS)) {
        hierarchyType.validateUniversalRelationship(this.getType(), parent.getType());
    }
    String edgeOid = null;
    if (this.getVertex().isNew() || !this.exists(parent, hierarchyType, null, null)) {
        EdgeObject edge = this.getVertex().addParent(((VertexComponent) parent).getVertex(), hierarchyType.getMdEdge());
        edge.apply();
        edgeOid = edge.getOid();
    }
    ServerParentTreeNode node = new ServerParentTreeNode(this, hierarchyType, this.date, null, null);
    node.addParent(new ServerParentTreeNode(parent, hierarchyType, this.date, null, edgeOid));
    return node;
}
Also used : ServerParentTreeNode(net.geoprism.registry.model.ServerParentTreeNode) EdgeObject(com.runwaysdk.business.graph.EdgeObject) MultiLineString(com.vividsolutions.jts.geom.MultiLineString) LineString(com.vividsolutions.jts.geom.LineString)

Example 12 with EdgeObject

use of com.runwaysdk.business.graph.EdgeObject in project geoprism-registry by terraframe.

the class VertexServerGeoObject method getExternalIdEdge.

private EdgeObject getExternalIdEdge(ExternalSystem system) {
    MdEdgeDAOIF mdEdge = MdEdgeDAO.getMdEdgeDAO(GeoVertex.EXTERNAL_ID);
    String statement = "SELECT expand(inE('" + mdEdge.getDBClassName() + "')[out = :parent])";
    statement += " FROM :child";
    GraphQuery<EdgeObject> query = new GraphQuery<EdgeObject>(statement);
    query.setParameter("parent", system.getRID());
    query.setParameter("child", this.getVertex().getRID());
    return query.getSingleResult();
}
Also used : MdEdgeDAOIF(com.runwaysdk.dataaccess.MdEdgeDAOIF) EdgeObject(com.runwaysdk.business.graph.EdgeObject) MultiLineString(com.vividsolutions.jts.geom.MultiLineString) LineString(com.vividsolutions.jts.geom.LineString) GraphQuery(com.runwaysdk.business.graph.GraphQuery)

Example 13 with EdgeObject

use of com.runwaysdk.business.graph.EdgeObject in project geoprism-registry by terraframe.

the class VertexServerGeoObject method setParents.

@Override
public void setParents(ServerParentTreeNodeOverTime parentsOverTime) {
    parentsOverTime.enforceUserHasPermissionSetParents(this.getType().getCode(), false);
    final Collection<ServerHierarchyType> hierarchyTypes = parentsOverTime.getHierarchies();
    for (ServerHierarchyType hierarchyType : hierarchyTypes) {
        final List<ServerParentTreeNode> entries = parentsOverTime.getEntries(hierarchyType);
        this.removeAllEdges(hierarchyType);
        final TreeSet<EdgeObject> edges = new TreeSet<EdgeObject>(new EdgeComparator());
        for (ServerParentTreeNode entry : entries) {
            final ServerGeoObjectIF parent = entry.getGeoObject();
            EdgeObject newEdge = this.getVertex().addParent(((VertexComponent) parent).getVertex(), hierarchyType.getMdEdge());
            newEdge.setValue(GeoVertex.START_DATE, entry.getStartDate());
            newEdge.setValue(GeoVertex.END_DATE, entry.getEndDate());
            edges.add(newEdge);
        }
        for (EdgeObject e : edges) {
            e.apply();
        }
    }
}
Also used : ServerHierarchyType(net.geoprism.registry.model.ServerHierarchyType) ServerParentTreeNode(net.geoprism.registry.model.ServerParentTreeNode) ServerGeoObjectIF(net.geoprism.registry.model.ServerGeoObjectIF) EdgeObject(com.runwaysdk.business.graph.EdgeObject) TreeSet(java.util.TreeSet)

Example 14 with EdgeObject

use of com.runwaysdk.business.graph.EdgeObject in project geoprism-registry by terraframe.

the class VertexServerGeoObject method internalGetParentOverTime.

protected static ServerParentTreeNodeOverTime internalGetParentOverTime(VertexServerGeoObject child, String[] parentTypes, boolean recursive) {
    final ServerGeoObjectType cType = child.getType();
    final List<ServerHierarchyType> hierarchies = cType.getHierarchies();
    ServerParentTreeNodeOverTime response = new ServerParentTreeNodeOverTime(cType);
    for (ServerHierarchyType ht : hierarchies) {
        response.add(ht);
    }
    Map<String, Object> parameters = new HashedMap<String, Object>();
    parameters.put("rid", child.getVertex().getRID());
    StringBuilder statement = new StringBuilder();
    statement.append("SELECT EXPAND(inE()");
    if (parentTypes != null && parentTypes.length > 0) {
        statement.append("[");
        for (int i = 0; i < parentTypes.length; i++) {
            ServerGeoObjectType type = ServerGeoObjectType.get(parentTypes[i]);
            if (i > 0) {
                statement.append(" OR ");
            }
            statement.append("out.@class = :a" + i);
            parameters.put("a" + Integer.toString(i), type.getMdVertex().getDBClassName());
        }
        statement.append("]");
    }
    statement.append(") FROM :rid");
    statement.append(" ORDER BY startDate ASC");
    GraphQuery<EdgeObject> query = new GraphQuery<EdgeObject>(statement.toString(), parameters);
    List<EdgeObject> edges = query.getResults();
    for (EdgeObject edge : edges) {
        MdEdgeDAOIF mdEdge = (MdEdgeDAOIF) edge.getMdClass();
        if (HierarchicalRelationshipType.isEdgeAHierarchyType(mdEdge)) {
            ServerHierarchyType ht = ServerHierarchyType.get(mdEdge);
            VertexObject parentVertex = edge.getParent();
            MdVertexDAOIF mdVertex = (MdVertexDAOIF) parentVertex.getMdClass();
            ServerGeoObjectType parentType = ServerGeoObjectType.get(mdVertex);
            Date date = edge.getObjectValue(GeoVertex.START_DATE);
            Date endDate = edge.getObjectValue(GeoVertex.END_DATE);
            String oid = edge.getObjectValue(GeoVertex.OID);
            ServerParentTreeNode tnRoot = new ServerParentTreeNode(child, null, date, null, oid);
            tnRoot.setEndDate(endDate);
            tnRoot.setOid(oid);
            VertexServerGeoObject parent = new VertexServerGeoObject(parentType, parentVertex, date);
            ServerParentTreeNode tnParent;
            if (recursive) {
                tnParent = internalGetParentGeoObjects(parent, parentTypes, recursive, ht, date);
            } else {
                tnParent = new ServerParentTreeNode(parent, ht, date, null, oid);
            }
            tnRoot.addParent(tnParent);
            response.add(ht, tnRoot);
        }
    }
    return response;
}
Also used : MdVertexDAOIF(com.runwaysdk.dataaccess.MdVertexDAOIF) ServerHierarchyType(net.geoprism.registry.model.ServerHierarchyType) MdEdgeDAOIF(com.runwaysdk.dataaccess.MdEdgeDAOIF) VertexObject(com.runwaysdk.business.graph.VertexObject) ServerParentTreeNode(net.geoprism.registry.model.ServerParentTreeNode) ServerGeoObjectType(net.geoprism.registry.model.ServerGeoObjectType) EdgeObject(com.runwaysdk.business.graph.EdgeObject) MultiLineString(com.vividsolutions.jts.geom.MultiLineString) LineString(com.vividsolutions.jts.geom.LineString) MultiPoint(com.vividsolutions.jts.geom.MultiPoint) Point(com.vividsolutions.jts.geom.Point) Date(java.util.Date) LocalDate(java.time.LocalDate) 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) ServerParentTreeNodeOverTime(net.geoprism.registry.view.ServerParentTreeNodeOverTime) HashedMap(org.apache.commons.collections4.map.HashedMap) GraphQuery(com.runwaysdk.business.graph.GraphQuery)

Example 15 with EdgeObject

use of com.runwaysdk.business.graph.EdgeObject in project geoprism-registry by terraframe.

the class UpdateParentValueOverTimeView method executeParent.

public void executeParent(UpdateChangeOverTimeAttributeView cotView, VertexServerGeoObject go, SortedSet<EdgeObject> looseVotc) {
    UpdateParentView parentView = (UpdateParentView) cotView;
    final ServerHierarchyType hierarchyType = ServerHierarchyType.get(parentView.getHierarchyCode());
    if (this.action.equals(UpdateActionType.DELETE)) {
        EdgeObject edge = this.getEdgeByOid(looseVotc, this.oid);
        if (edge == null) {
            ExecuteOutOfDateChangeRequestException ex = new ExecuteOutOfDateChangeRequestException();
            throw ex;
        }
        edge.delete();
        looseVotc.remove(edge);
    } else if (this.action.equals(UpdateActionType.UPDATE)) {
        EdgeObject edge = this.getEdgeByOid(looseVotc, this.oid);
        if (edge == null) {
            ExecuteOutOfDateChangeRequestException ex = new ExecuteOutOfDateChangeRequestException();
            throw ex;
        }
        final VertexServerGeoObject newParent = this.getNewValueAsGO();
        final String parentCode = newParent == null ? null : newParent.getCode();
        String currentCode = edge.getParent().getObjectValue(DefaultAttribute.CODE.getName());
        // Parent values can only be changed by deleting the current edge and creating a new one unfortunately
        if (this.newValue != null && (currentCode != parentCode)) {
            Date _newStartDate = this.newStartDate;
            Date _newEndDate = this.newEndDate;
            if (_newStartDate == null) {
                _newStartDate = edge.getObjectValue(GeoVertex.START_DATE);
            }
            if (_newEndDate == null) {
                _newEndDate = edge.getObjectValue(GeoVertex.END_DATE);
            }
            edge.delete();
            looseVotc.remove(edge);
            if (newParent != null) {
                // We unfortunately can't use this method because we have to bypass the votc reordering and validation
                // go.addParent(newParent, hierarchyType, _newStartDate, _newEndDate);
                EdgeObject newEdge = go.getVertex().addParent(((VertexComponent) newParent).getVertex(), hierarchyType.getMdEdge());
                newEdge.setValue(GeoVertex.START_DATE, _newStartDate);
                newEdge.setValue(GeoVertex.END_DATE, _newEndDate);
                newEdge.apply();
                looseVotc.add(newEdge);
            }
            return;
        }
        if (newStartDate != null) {
            edge.setValue(GeoVertex.START_DATE, newStartDate);
        }
        if (newEndDate != null) {
            edge.setValue(GeoVertex.END_DATE, newEndDate);
        }
        edge.apply();
    } else if (this.action.equals(UpdateActionType.CREATE)) {
        final VertexServerGeoObject newParent = this.getNewValueAsGO();
        if (newParent == null || this.newStartDate == null || this.newEndDate == null) {
            throw new InvalidChangeRequestException();
        }
        EdgeObject edge = go.getEdge(newParent, hierarchyType, this.newStartDate, this.newEndDate);
        if (edge != null) {
            ExecuteOutOfDateChangeRequestException ex = new ExecuteOutOfDateChangeRequestException();
            throw ex;
        }
        // We unfortunately can't use this method because we have to bypass the votc reordering and validation
        // go.addParent(newParent, hierarchyType, this.newStartDate, this.newEndDate);
        EdgeObject newEdge = go.getVertex().addParent(((VertexComponent) newParent).getVertex(), hierarchyType.getMdEdge());
        newEdge.setValue(GeoVertex.START_DATE, this.newStartDate);
        newEdge.setValue(GeoVertex.END_DATE, this.newEndDate);
        newEdge.apply();
        looseVotc.add(newEdge);
    } else {
        throw new UnsupportedOperationException("Unsupported action type [" + this.action + "].");
    }
}
Also used : ServerHierarchyType(net.geoprism.registry.model.ServerHierarchyType) InvalidChangeRequestException(net.geoprism.registry.action.InvalidChangeRequestException) EdgeObject(com.runwaysdk.business.graph.EdgeObject) VertexServerGeoObject(net.geoprism.registry.model.graph.VertexServerGeoObject) Date(java.util.Date) ExecuteOutOfDateChangeRequestException(net.geoprism.registry.action.ExecuteOutOfDateChangeRequestException) VertexComponent(net.geoprism.registry.model.graph.VertexComponent)

Aggregations

EdgeObject (com.runwaysdk.business.graph.EdgeObject)31 VertexObject (com.runwaysdk.business.graph.VertexObject)15 MdVertexDAOIF (com.runwaysdk.dataaccess.MdVertexDAOIF)15 ServerGeoObjectType (net.geoprism.registry.model.ServerGeoObjectType)15 GraphQuery (com.runwaysdk.business.graph.GraphQuery)11 Date (java.util.Date)10 ValueOverTime (com.runwaysdk.dataaccess.graph.attributes.ValueOverTime)9 LineString (com.vividsolutions.jts.geom.LineString)7 MultiLineString (com.vividsolutions.jts.geom.MultiLineString)7 TreeSet (java.util.TreeSet)7 HashedMap (org.apache.commons.collections4.map.HashedMap)7 ServerHierarchyType (net.geoprism.registry.model.ServerHierarchyType)6 MdEdgeDAOIF (com.runwaysdk.dataaccess.MdEdgeDAOIF)5 ServerParentGraphNode (net.geoprism.registry.model.ServerParentGraphNode)5 ServerParentTreeNode (net.geoprism.registry.model.ServerParentTreeNode)5 GraphObject (com.runwaysdk.business.graph.GraphObject)3 MultiPoint (com.vividsolutions.jts.geom.MultiPoint)3 Point (com.vividsolutions.jts.geom.Point)3 LocalDate (java.time.LocalDate)3 AbstractServerGeoObject (net.geoprism.registry.model.AbstractServerGeoObject)3