Search in sources :

Example 1 with AttributeGeometryType

use of org.commongeoregistry.adapter.metadata.AttributeGeometryType in project geoprism-registry by terraframe.

the class ChangeRequestServiceTest method testUpdateGeoObjectGeometryCR_applyCR.

@Request
private String[] testUpdateGeoObjectGeometryCR_applyCR() throws Exception {
    AttributeGeometryType geomType = FastTestDataset.CAMBODIA.fetchGeoObjectOverTime().getGeometryAttributeType();
    ChangeRequest cr = new ChangeRequest();
    cr.addApprovalStatus(AllGovernanceStatus.PENDING);
    cr.setOrganizationCode(FastTestDataset.ORG_CGOV.getCode());
    cr.setGeoObjectCode(FastTestDataset.CAMBODIA.getCode());
    cr.setGeoObjectTypeCode(FastTestDataset.CAMBODIA.getGeoObjectType().getCode());
    cr.apply();
    UpdateAttributeAction action = new UpdateAttributeAction();
    action.setApiVersion("1.0");
    ((UpdateAttributeActionBase) action).setAttributeName(geomType.getName());
    JsonObject diff = new JsonObject();
    VertexServerGeoObject cambodia = (VertexServerGeoObject) FastTestDataset.CAMBODIA.getServerObject();
    ValueOverTime vot = cambodia.getValuesOverTime(cambodia.getGeometryAttributeName()).getValueOverTime(FastTestDataset.DEFAULT_OVER_TIME_DATE, TestDataSet.DEFAULT_END_TIME_DATE);
    GeoJSONWriter gw = new GeoJSONWriter();
    org.wololo.geojson.Geometry gJSON = gw.write((Geometry) vot.getValue());
    JsonObject geojson = JsonParser.parseString(gJSON.toString()).getAsJsonObject();
    JsonArray valuesOverTime = JsonParser.parseString("[" + "{" + "  \"oid\": \"" + vot.getOid() + "\"," + "  \"action\": \"UPDATE\"," + "  \"oldEndDate\": \"" + OLD_END_DATE + "\"," + "  \"oldStartDate\": \"" + OLD_START_DATE + "\"," + "  \"oldValue\": \"\"," + "  \"newValue\": \"\"," + "  \"newStartDate\": \"" + NEW_START_DATE + "\"," + "  \"newEndDate\": \"" + NEW_END_DATE + "\"" + "}" + "]").getAsJsonArray();
    valuesOverTime.get(0).getAsJsonObject().add("oldValue", geojson);
    valuesOverTime.get(0).getAsJsonObject().add("newValue", geojson);
    diff.add("valuesOverTime", valuesOverTime);
    ((UpdateAttributeActionBase) action).setJson(diff.toString());
    action.addApprovalStatus(AllGovernanceStatus.ACCEPTED);
    action.setCreateActionDate(new Date());
    action.apply();
    cr.addAction(action).apply();
    String serializedCR = cr.toJSON().toString();
    return new String[] { serializedCR, vot.getOid() };
}
Also used : AttributeGeometryType(org.commongeoregistry.adapter.metadata.AttributeGeometryType) JsonObject(com.google.gson.JsonObject) ChangeRequest(net.geoprism.registry.action.ChangeRequest) UpdateAttributeAction(net.geoprism.registry.action.geoobject.UpdateAttributeAction) Date(java.util.Date) JsonArray(com.google.gson.JsonArray) ValueOverTime(com.runwaysdk.dataaccess.graph.attributes.ValueOverTime) UpdateAttributeActionBase(net.geoprism.registry.action.geoobject.UpdateAttributeActionBase) VertexServerGeoObject(net.geoprism.registry.model.graph.VertexServerGeoObject) GeoJSONWriter(org.wololo.jts2geojson.GeoJSONWriter) Request(com.runwaysdk.session.Request) ChangeRequest(net.geoprism.registry.action.ChangeRequest)

Aggregations

JsonArray (com.google.gson.JsonArray)1 JsonObject (com.google.gson.JsonObject)1 ValueOverTime (com.runwaysdk.dataaccess.graph.attributes.ValueOverTime)1 Request (com.runwaysdk.session.Request)1 Date (java.util.Date)1 ChangeRequest (net.geoprism.registry.action.ChangeRequest)1 UpdateAttributeAction (net.geoprism.registry.action.geoobject.UpdateAttributeAction)1 UpdateAttributeActionBase (net.geoprism.registry.action.geoobject.UpdateAttributeActionBase)1 VertexServerGeoObject (net.geoprism.registry.model.graph.VertexServerGeoObject)1 AttributeGeometryType (org.commongeoregistry.adapter.metadata.AttributeGeometryType)1 GeoJSONWriter (org.wololo.jts2geojson.GeoJSONWriter)1