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 };
}
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);
}
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() };
}
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()));
}
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());
}
Aggregations