Search in sources :

Example 1 with InvalidChangeRequestException

use of net.geoprism.registry.action.InvalidChangeRequestException in project geoprism-registry by terraframe.

the class UpdateChangeOverTimeAttributeView method validateValuesOverTime.

public void validateValuesOverTime(ValueOverTimeCollection votc) {
    for (ValueOverTime vot : votc) {
        if (vot.getStartDate() == null) {
            throw new InvalidChangeRequestException();
        }
        if (vot.getEndDate() == null) {
            vot.setEndDate(ValueOverTime.INFINITY_END_DATE);
        }
        if (vot.getStartDate().after(vot.getEndDate())) {
            throw new InvalidChangeRequestException();
        }
    }
    for (ValueOverTime vot : votc) {
        Date s1 = vot.getStartDate();
        Date e1 = vot.getEndDate();
        for (ValueOverTime vot2 : votc) {
            if (vot != vot2) {
                Date s2 = vot2.getStartDate();
                Date e2 = vot2.getEndDate();
                if (this.dateRangeOverlaps(s1.getTime(), e1.getTime(), s2.getTime(), e2.getTime())) {
                    throw new InvalidChangeRequestException();
                }
            }
        }
    }
}
Also used : ValueOverTime(com.runwaysdk.dataaccess.graph.attributes.ValueOverTime) InvalidChangeRequestException(net.geoprism.registry.action.InvalidChangeRequestException) Date(java.util.Date)

Example 2 with InvalidChangeRequestException

use of net.geoprism.registry.action.InvalidChangeRequestException 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)

Example 3 with InvalidChangeRequestException

use of net.geoprism.registry.action.InvalidChangeRequestException in project geoprism-registry by terraframe.

the class UpdateParentView method validateValuesOverTime.

public void validateValuesOverTime(SortedSet<EdgeObject> votc) {
    for (EdgeObject edge : votc) {
        Date startDate = edge.getObjectValue(GeoVertex.START_DATE);
        Date endDate = edge.getObjectValue(GeoVertex.END_DATE);
        if (startDate == null) {
            throw new InvalidChangeRequestException();
        }
        if (endDate == null) {
            edge.setValue(GeoVertex.END_DATE, ValueOverTime.INFINITY_END_DATE);
        }
        if (startDate.after(endDate)) {
            throw new InvalidChangeRequestException();
        }
    }
    for (EdgeObject edge : votc) {
        Date s1 = edge.getObjectValue(GeoVertex.START_DATE);
        Date e1 = edge.getObjectValue(GeoVertex.END_DATE);
        for (EdgeObject edge2 : votc) {
            if (edge != edge2) {
                Date s2 = edge2.getObjectValue(GeoVertex.START_DATE);
                Date e2 = edge2.getObjectValue(GeoVertex.END_DATE);
                if (this.dateRangeOverlaps(s1.getTime(), e1.getTime(), s2.getTime(), e2.getTime())) {
                    throw new InvalidChangeRequestException();
                }
            }
        }
    }
}
Also used : InvalidChangeRequestException(net.geoprism.registry.action.InvalidChangeRequestException) EdgeObject(com.runwaysdk.business.graph.EdgeObject) Date(java.util.Date)

Example 4 with InvalidChangeRequestException

use of net.geoprism.registry.action.InvalidChangeRequestException in project geoprism-registry by terraframe.

the class UpdateValueOverTimeView method execute.

/*
   * You should NOT be directly setting values on the VOTC contained within the
   * GeoObject here. Use the looseVotc instead. For reasons why, {{@see
   * UpdateChangeOverTimeAttributeView.execute}}
   */
public void execute(UpdateChangeOverTimeAttributeView cotView, VertexServerGeoObject go, List<ValueOverTime> looseVotc) {
    if (this.action.equals(UpdateActionType.DELETE)) {
        ValueOverTime vot = this.getValueByOid(looseVotc, this.getOid());
        if (vot == null) {
            ExecuteOutOfDateChangeRequestException ex = new ExecuteOutOfDateChangeRequestException();
            throw ex;
        }
        looseVotc.remove(vot);
    } else if (this.action.equals(UpdateActionType.UPDATE)) {
        ValueOverTime vot = this.getValueByOid(looseVotc, this.getOid());
        if (vot == null) {
            ExecuteOutOfDateChangeRequestException ex = new ExecuteOutOfDateChangeRequestException();
            throw ex;
        }
        if (this.newValue == null && this.newStartDate == null && this.newEndDate == null) {
            throw new InvalidChangeRequestException();
        }
        if (newStartDate != null) {
            vot.setStartDate(newStartDate);
        }
        if (newEndDate != null) {
            vot.setEndDate(newEndDate);
        }
        this.persistValue(vot, cotView, go, looseVotc);
    } else if (this.action.equals(UpdateActionType.CREATE)) {
        ValueOverTime vot = this.getValueByDate(looseVotc, this.newStartDate, this.newEndDate);
        if (vot != null) {
            ExecuteOutOfDateChangeRequestException ex = new ExecuteOutOfDateChangeRequestException();
            throw ex;
        }
        if (this.newValue == null || this.newStartDate == null || this.newEndDate == null) {
            throw new InvalidChangeRequestException();
        }
        this.persistValue(null, cotView, go, looseVotc);
    } else {
        throw new UnsupportedOperationException("Unsupported action type [" + this.action + "].");
    }
}
Also used : ValueOverTime(com.runwaysdk.dataaccess.graph.attributes.ValueOverTime) InvalidChangeRequestException(net.geoprism.registry.action.InvalidChangeRequestException) ExecuteOutOfDateChangeRequestException(net.geoprism.registry.action.ExecuteOutOfDateChangeRequestException)

Aggregations

InvalidChangeRequestException (net.geoprism.registry.action.InvalidChangeRequestException)4 Date (java.util.Date)3 EdgeObject (com.runwaysdk.business.graph.EdgeObject)2 ValueOverTime (com.runwaysdk.dataaccess.graph.attributes.ValueOverTime)2 ExecuteOutOfDateChangeRequestException (net.geoprism.registry.action.ExecuteOutOfDateChangeRequestException)2 ServerHierarchyType (net.geoprism.registry.model.ServerHierarchyType)1 VertexComponent (net.geoprism.registry.model.graph.VertexComponent)1 VertexServerGeoObject (net.geoprism.registry.model.graph.VertexServerGeoObject)1