Search in sources :

Example 31 with ValueOverTime

use of com.runwaysdk.dataaccess.graph.attributes.ValueOverTime in project geoprism-registry by terraframe.

the class ChangeRequestServiceTest method testUpdateGeoObjectDateCR_applyCR.

@Request
private Object[] testUpdateGeoObjectDateCR_applyCR() throws Exception {
    final Long newValue = new Date().getTime();
    final String attrName = FastTestDataset.AT_DATE_OF_FORMATION.getAttributeName();
    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(attrName);
    JsonObject diff = new JsonObject();
    VertexServerGeoObject cambodia = (VertexServerGeoObject) FastTestDataset.CAMBODIA.getServerObject();
    ValueOverTime vot = cambodia.getValuesOverTime(attrName).getValueOverTime(FastTestDataset.DEFAULT_OVER_TIME_DATE, TestDataSet.DEFAULT_END_TIME_DATE);
    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().addProperty("oldValue", ((Date) FastTestDataset.CAMBODIA.getDefaultValue(attrName)).getTime());
    valuesOverTime.get(0).getAsJsonObject().addProperty("newValue", newValue);
    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 Object[] { serializedCR, vot.getOid(), newValue };
}
Also used : JsonArray(com.google.gson.JsonArray) ValueOverTime(com.runwaysdk.dataaccess.graph.attributes.ValueOverTime) UpdateAttributeActionBase(net.geoprism.registry.action.geoobject.UpdateAttributeActionBase) JsonObject(com.google.gson.JsonObject) VertexServerGeoObject(net.geoprism.registry.model.graph.VertexServerGeoObject) JsonObject(com.google.gson.JsonObject) VertexServerGeoObject(net.geoprism.registry.model.graph.VertexServerGeoObject) ChangeRequest(net.geoprism.registry.action.ChangeRequest) UpdateAttributeAction(net.geoprism.registry.action.geoobject.UpdateAttributeAction) Date(java.util.Date) Request(com.runwaysdk.session.Request) ChangeRequest(net.geoprism.registry.action.ChangeRequest)

Example 32 with ValueOverTime

use of com.runwaysdk.dataaccess.graph.attributes.ValueOverTime in project geoprism-registry by terraframe.

the class ChangeRequestServiceTest method testUpdateGeoObjectGeometryCR_Verify.

@Request
private void testUpdateGeoObjectGeometryCR_Verify(String[] data) throws Exception {
    final String oldOid = data[1];
    final SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
    sdf.setTimeZone(GeoRegistryUtil.SYSTEM_TIMEZONE);
    final Date newStartDate = sdf.parse(NEW_START_DATE);
    final Date newEndDate = sdf.parse(NEW_END_DATE);
    ChangeRequestQuery crq = new ChangeRequestQuery(new QueryFactory());
    Assert.assertEquals(1, crq.getCount());
    ChangeRequest cr = crq.getIterator().next();
    Assert.assertEquals(AllGovernanceStatus.ACCEPTED.name(), cr.getGovernanceStatus().name());
    AbstractAction action = cr.getAllAction().next();
    Assert.assertTrue(action instanceof UpdateAttributeAction);
    Assert.assertEquals(FastTestDataset.CAMBODIA.getCode(), cr.getGeoObjectCode());
    Assert.assertEquals(FastTestDataset.CAMBODIA.getGeoObjectType().getCode(), cr.getGeoObjectTypeCode());
    Assert.assertEquals(FastTestDataset.ORG_CGOV.getCode(), cr.getOrganizationCode());
    VertexServerGeoObject cambodia = (VertexServerGeoObject) FastTestDataset.CAMBODIA.getServerObject();
    ValueOverTimeCollection votc = cambodia.getValuesOverTime(cambodia.getGeometryAttributeName());
    Assert.assertEquals(1, votc.size());
    ValueOverTime vot1 = votc.get(0);
    Assert.assertNotNull(vot1.getOid());
    Assert.assertEquals(oldOid, vot1.getOid());
    Assert.assertEquals(newStartDate, vot1.getStartDate());
    Assert.assertEquals(newEndDate, vot1.getEndDate());
    Assert.assertTrue(vot1.getValue() instanceof Geometry);
}
Also used : Geometry(com.vividsolutions.jts.geom.Geometry) ValueOverTime(com.runwaysdk.dataaccess.graph.attributes.ValueOverTime) QueryFactory(com.runwaysdk.query.QueryFactory) ChangeRequestQuery(net.geoprism.registry.action.ChangeRequestQuery) ValueOverTimeCollection(com.runwaysdk.dataaccess.graph.attributes.ValueOverTimeCollection) VertexServerGeoObject(net.geoprism.registry.model.graph.VertexServerGeoObject) ChangeRequest(net.geoprism.registry.action.ChangeRequest) SimpleDateFormat(java.text.SimpleDateFormat) AbstractAction(net.geoprism.registry.action.AbstractAction) UpdateAttributeAction(net.geoprism.registry.action.geoobject.UpdateAttributeAction) Date(java.util.Date) Request(com.runwaysdk.session.Request) ChangeRequest(net.geoprism.registry.action.ChangeRequest)

Example 33 with ValueOverTime

use of com.runwaysdk.dataaccess.graph.attributes.ValueOverTime 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)

Example 34 with ValueOverTime

use of com.runwaysdk.dataaccess.graph.attributes.ValueOverTime in project geoprism-registry by terraframe.

the class ValueOverTimeParentTest method testFullConsumeDifferentValue.

/**
 * Imported data completely consumes existing data, and the values are different.
 */
@Test
@Request
public void testFullConsumeDifferentValue() {
    ServerGeoObjectIF go = TEST_GO.getServerObject();
    go.addParent(BELIZE.getServerObject(), FastTestDataset.HIER_ADMIN.getServerObject(), addDay(TestDataSet.DEFAULT_OVER_TIME_DATE, -5), addDay(TestDataSet.DEFAULT_END_TIME_DATE, 5));
    go.apply(false);
    go = TEST_GO.getServerObject();
    ValueOverTimeCollection votc = go.getParentCollection(FastTestDataset.HIER_ADMIN.getServerObject());
    Assert.assertEquals(1, votc.size());
    ValueOverTime vot = votc.get(0);
    Assert.assertEquals(BELIZE.getCode(), ((ServerGeoObjectIF) vot.getValue()).getCode());
    Assert.assertEquals(addDay(TestDataSet.DEFAULT_OVER_TIME_DATE, -5), vot.getStartDate());
    Assert.assertEquals(addDay(TestDataSet.DEFAULT_END_TIME_DATE, 5), vot.getEndDate());
}
Also used : ValueOverTime(com.runwaysdk.dataaccess.graph.attributes.ValueOverTime) ServerGeoObjectIF(net.geoprism.registry.model.ServerGeoObjectIF) ValueOverTimeCollection(com.runwaysdk.dataaccess.graph.attributes.ValueOverTimeCollection) Test(org.junit.Test) Request(com.runwaysdk.session.Request)

Example 35 with ValueOverTime

use of com.runwaysdk.dataaccess.graph.attributes.ValueOverTime in project geoprism-registry by terraframe.

the class ValueOverTimeParentTest method testFullConsumeSameValue.

/**
 * Imported data completely consumes existing data, and the values are the same.
 */
@Test
@Request
public void testFullConsumeSameValue() {
    ServerGeoObjectIF go = TEST_GO.getServerObject();
    go.addParent(FastTestDataset.CAMBODIA.getServerObject(), FastTestDataset.HIER_ADMIN.getServerObject(), addDay(TestDataSet.DEFAULT_OVER_TIME_DATE, -5), addDay(TestDataSet.DEFAULT_END_TIME_DATE, 5));
    go.apply(false);
    go = TEST_GO.getServerObject();
    ValueOverTimeCollection votc = go.getParentCollection(FastTestDataset.HIER_ADMIN.getServerObject());
    Assert.assertEquals(1, votc.size());
    ValueOverTime vot = votc.get(0);
    Assert.assertEquals(FastTestDataset.CAMBODIA.getCode(), ((ServerGeoObjectIF) vot.getValue()).getCode());
    Assert.assertEquals(addDay(TestDataSet.DEFAULT_OVER_TIME_DATE, -5), vot.getStartDate());
    Assert.assertEquals(addDay(TestDataSet.DEFAULT_END_TIME_DATE, 5), vot.getEndDate());
}
Also used : ValueOverTime(com.runwaysdk.dataaccess.graph.attributes.ValueOverTime) ServerGeoObjectIF(net.geoprism.registry.model.ServerGeoObjectIF) ValueOverTimeCollection(com.runwaysdk.dataaccess.graph.attributes.ValueOverTimeCollection) Test(org.junit.Test) Request(com.runwaysdk.session.Request)

Aggregations

ValueOverTime (com.runwaysdk.dataaccess.graph.attributes.ValueOverTime)44 ValueOverTimeCollection (com.runwaysdk.dataaccess.graph.attributes.ValueOverTimeCollection)29 Request (com.runwaysdk.session.Request)26 Date (java.util.Date)22 ServerGeoObjectIF (net.geoprism.registry.model.ServerGeoObjectIF)18 Test (org.junit.Test)16 EdgeObject (com.runwaysdk.business.graph.EdgeObject)10 ChangeRequest (net.geoprism.registry.action.ChangeRequest)10 VertexServerGeoObject (net.geoprism.registry.model.graph.VertexServerGeoObject)10 VertexObject (com.runwaysdk.business.graph.VertexObject)9 UpdateAttributeAction (net.geoprism.registry.action.geoobject.UpdateAttributeAction)9 MdVertexDAOIF (com.runwaysdk.dataaccess.MdVertexDAOIF)8 ServerGeoObjectType (net.geoprism.registry.model.ServerGeoObjectType)8 SimpleDateFormat (java.text.SimpleDateFormat)6 AbstractAction (net.geoprism.registry.action.AbstractAction)6 JsonArray (com.google.gson.JsonArray)5 JsonObject (com.google.gson.JsonObject)5 QueryFactory (com.runwaysdk.query.QueryFactory)5 TreeSet (java.util.TreeSet)5 ChangeRequestQuery (net.geoprism.registry.action.ChangeRequestQuery)5