Search in sources :

Example 46 with VertexServerGeoObject

use of net.geoprism.registry.model.graph.VertexServerGeoObject 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 47 with VertexServerGeoObject

use of net.geoprism.registry.model.graph.VertexServerGeoObject 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 48 with VertexServerGeoObject

use of net.geoprism.registry.model.graph.VertexServerGeoObject 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 49 with VertexServerGeoObject

use of net.geoprism.registry.model.graph.VertexServerGeoObject in project geoprism-registry by terraframe.

the class RegistryVersionTest method genericDuplicateDatatypeTest.

private void genericDuplicateDatatypeTest(String attributeName, Object value) throws ParseException {
    final SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
    dateFormat.setTimeZone(GeoRegistryUtil.SYSTEM_TIMEZONE);
    // Initial Setup : Create a VOT with a large date range
    VertexServerGeoObject serverObj = (VertexServerGeoObject) FastTestDataset.PROV_CENTRAL.getServerObject();
    serverObj.getValuesOverTime(attributeName).clear();
    serverObj.setValue(attributeName, value, dateFormat.parse("1990-01-01"), dateFormat.parse("1990-02-01"));
    serverObj.apply(false);
    Assert.assertEquals(1, FastTestDataset.PROV_CENTRAL.getServerObject().getValuesOverTime(attributeName).size());
    // Set a value inside that date range with the same value
    VertexServerGeoObject serverObj2 = (VertexServerGeoObject) FastTestDataset.PROV_CENTRAL.getServerObject();
    serverObj2.setValue(attributeName, value, dateFormat.parse("1990-01-05"), dateFormat.parse("1990-01-10"));
    serverObj2.apply(false);
    // Fetch the object and assert values on it
    Assert.assertEquals(1, FastTestDataset.PROV_CENTRAL.getServerObject().getValuesOverTime(attributeName).size());
    GeoObjectOverTime goTime = testData.adapter.getGeoObjectOverTimeByCode(FastTestDataset.PROV_CENTRAL.getCode(), FastTestDataset.PROV_CENTRAL.getGeoObjectType().getCode());
    Assert.assertEquals(1, goTime.getAllValues(attributeName).size());
    ValueOverTimeCollectionDTO all = goTime.getAllValues(attributeName);
    Assert.assertEquals("1990-01-01", dateFormat.format(all.get(0).getStartDate()));
    Assert.assertEquals("1990-02-01", dateFormat.format(all.get(0).getEndDate()));
    Assert.assertTrue(value.equals(all.get(0).getValue()));
}
Also used : ValueOverTimeCollectionDTO(org.commongeoregistry.adapter.dataaccess.ValueOverTimeCollectionDTO) VertexServerGeoObject(net.geoprism.registry.model.graph.VertexServerGeoObject) GeoObjectOverTime(org.commongeoregistry.adapter.dataaccess.GeoObjectOverTime) SimpleDateFormat(java.text.SimpleDateFormat)

Example 50 with VertexServerGeoObject

use of net.geoprism.registry.model.graph.VertexServerGeoObject in project geoprism-registry by terraframe.

the class TransitionEventTest method testAddTransitionSameType.

@Test
@Request
public void testAddTransitionSameType() {
    long beforeCount = new TaskQuery(new QueryFactory()).getCount();
    TransitionEvent event = new TransitionEvent();
    try {
        LocalizedValueConverter.populate(event, TransitionEvent.DESCRIPTION, new LocalizedValue("Test"));
        event.setEventDate(FastTestDataset.DEFAULT_OVER_TIME_DATE);
        event.setBeforeTypeCode(FastTestDataset.PROVINCE.getCode());
        event.setBeforeTypeOrgCode(FastTestDataset.PROVINCE.getOrganization().getCode());
        event.setAfterTypeCode(FastTestDataset.PROVINCE.getCode());
        event.setAfterTypeOrgCode(FastTestDataset.PROVINCE.getOrganization().getCode());
        event.apply();
        Transition transition = event.addTransition(FastTestDataset.PROV_WESTERN.getServerObject(), FastTestDataset.PROV_CENTRAL.getServerObject(), TransitionType.REASSIGN, TransitionImpact.FULL);
        Assert.assertEquals(3, Task.getTasks(transition.getOid()).size());
        List<Transition> transitions = event.getTransitions();
        Assert.assertEquals(1, transitions.size());
        transition = transitions.get(0);
        VertexServerGeoObject source = transition.getSourceVertex();
        VertexServerGeoObject target = transition.getTargetVertex();
        Assert.assertEquals(FastTestDataset.PROV_WESTERN.getCode(), source.getCode());
        Assert.assertEquals(FastTestDataset.PROV_CENTRAL.getCode(), target.getCode());
    } finally {
        event.delete();
    }
    // Ensure that the unresolved tasks are deleted on event delete
    Assert.assertEquals(beforeCount, new TaskQuery(new QueryFactory()).getCount());
}
Also used : QueryFactory(com.runwaysdk.query.QueryFactory) LocalizedValue(org.commongeoregistry.adapter.dataaccess.LocalizedValue) TaskQuery(net.geoprism.registry.task.TaskQuery) TransitionEvent(net.geoprism.registry.graph.transition.TransitionEvent) Transition(net.geoprism.registry.graph.transition.Transition) VertexServerGeoObject(net.geoprism.registry.model.graph.VertexServerGeoObject) Test(org.junit.Test) Request(com.runwaysdk.session.Request)

Aggregations

VertexServerGeoObject (net.geoprism.registry.model.graph.VertexServerGeoObject)51 VertexObject (com.runwaysdk.business.graph.VertexObject)20 ServerGeoObjectType (net.geoprism.registry.model.ServerGeoObjectType)19 JsonObject (com.google.gson.JsonObject)18 Request (com.runwaysdk.session.Request)13 Date (java.util.Date)12 LinkedList (java.util.LinkedList)11 ChangeRequest (net.geoprism.registry.action.ChangeRequest)11 JsonArray (com.google.gson.JsonArray)10 ValueOverTime (com.runwaysdk.dataaccess.graph.attributes.ValueOverTime)10 LocalizedValue (org.commongeoregistry.adapter.dataaccess.LocalizedValue)10 MdVertexDAOIF (com.runwaysdk.dataaccess.MdVertexDAOIF)9 GraphQuery (com.runwaysdk.business.graph.GraphQuery)8 UpdateAttributeAction (net.geoprism.registry.action.geoobject.UpdateAttributeAction)8 AttributeType (org.commongeoregistry.adapter.metadata.AttributeType)8 QueryFactory (com.runwaysdk.query.QueryFactory)6 SimpleDateFormat (java.text.SimpleDateFormat)6 ServerGeoObjectIF (net.geoprism.registry.model.ServerGeoObjectIF)6 ServerHierarchyType (net.geoprism.registry.model.ServerHierarchyType)6 MdAttributeDAOIF (com.runwaysdk.dataaccess.MdAttributeDAOIF)5