use of com.runwaysdk.business.graph.EdgeObject in project geoprism-registry by terraframe.
the class VertexServerGeoObject method internalGetParentGeoObjects.
protected static ServerParentTreeNode internalGetParentGeoObjects(VertexServerGeoObject child, String[] parentTypes, boolean recursive, ServerHierarchyType htIn, Date date) {
ServerParentTreeNode tnRoot = new ServerParentTreeNode(child, htIn, date, null, null);
Map<String, Object> parameters = new HashedMap<String, Object>();
parameters.put("rid", child.getVertex().getRID());
StringBuilder statement = new StringBuilder();
statement.append("SELECT EXPAND( inE(");
if (htIn != null) {
statement.append("'" + htIn.getMdEdge().getDBClassName() + "'");
}
statement.append(")");
if (date != null || (parentTypes != null && parentTypes.length > 0)) {
statement.append("[");
if (date != null) {
statement.append(" :date BETWEEN startDate AND endDate");
parameters.put("date", date);
}
if (parentTypes != null && parentTypes.length > 0) {
if (date != null) {
statement.append(" AND");
}
statement.append("(");
for (int i = 0; i < parentTypes.length; i++) {
ServerGeoObjectType type = ServerGeoObjectType.get(parentTypes[i]);
final String paramName = "p" + Integer.toString(i);
if (i > 0) {
statement.append(" OR ");
}
statement.append("out.@class = :" + paramName);
parameters.put(paramName, type.getMdVertex().getDBClassName());
}
statement.append(")");
}
statement.append("]");
}
statement.append(") FROM :rid");
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)) {
final VertexObject parentVertex = edge.getParent();
MdVertexDAOIF mdVertex = (MdVertexDAOIF) parentVertex.getMdClass();
ServerHierarchyType ht = ServerHierarchyType.get(mdEdge);
ServerGeoObjectType parentType = ServerGeoObjectType.get(mdVertex);
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, edge.getOid());
}
tnRoot.addParent(tnParent);
}
}
return tnRoot;
}
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, 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;
}
use of com.runwaysdk.business.graph.EdgeObject 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;
}
use of com.runwaysdk.business.graph.EdgeObject in project geoprism-registry by terraframe.
the class UpdateParentValueOverTimeView method getEdgeByDate.
protected EdgeObject getEdgeByDate(SortedSet<EdgeObject> looseVotc, Date startDate, Date endDate) {
for (EdgeObject edge : looseVotc) {
Date edgeStartDate = edge.getObjectValue(GeoVertex.START_DATE);
Date edgeEndDate = edge.getObjectValue(GeoVertex.END_DATE);
if (edgeStartDate.equals(startDate) && edgeEndDate.equals(endDate)) {
return edge;
}
}
return null;
}
use of com.runwaysdk.business.graph.EdgeObject in project geoprism-registry by terraframe.
the class UpdateParentView method execute.
@Override
public void execute(VertexServerGeoObject go) {
final ServerHierarchyType hierarchyType = ServerHierarchyType.get(this.getHierarchyCode());
SortedSet<EdgeObject> looseVotc = go.getEdges(hierarchyType);
for (UpdateValueOverTimeView vot : this.valuesOverTime) {
((UpdateParentValueOverTimeView) vot).executeParent(this, go, looseVotc);
}
// The edge work has already been applied at this point. We just need to validate what's in the DB
this.validateValuesOverTime(looseVotc);
}
Aggregations