use of net.geoprism.registry.model.graph.VertexComponent 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 + "].");
}
}
Aggregations