use of net.geoprism.registry.action.geoobject.UpdateAttributeAction in project geoprism-registry by terraframe.
the class ServerGeoObjectService method updateChangeRequest.
@Transaction
public ChangeRequest updateChangeRequest(ChangeRequest request, String notes, final JsonArray jaActions) {
Instant base = Instant.now();
int sequence = 0;
// Delete all existing actions
try (OIterator<? extends AbstractAction> actions = request.getAllAction()) {
while (actions.hasNext()) {
AbstractAction action = actions.next();
action.delete();
}
}
// Create the new actions
for (int i = 0; i < jaActions.size(); ++i) {
JsonObject joAction = jaActions.get(i).getAsJsonObject();
String actionType = joAction.get("actionType").getAsString();
if (actionType.equals(CreateGeoObjectAction.class.getSimpleName())) {
CreateGeoObjectAction action = new CreateGeoObjectAction();
action.addApprovalStatus(AllGovernanceStatus.PENDING);
action.setCreateActionDate(Date.from(base.plus(sequence++, ChronoUnit.MINUTES)));
action.setApiVersion(CGRAdapterProperties.getApiVersion());
action.setContributorNotes(notes);
if (joAction.has(CreateGeoObjectAction.GEOOBJECTJSON) && !joAction.get(CreateGeoObjectAction.GEOOBJECTJSON).isJsonNull()) {
action.setGeoObjectJson(joAction.get(CreateGeoObjectAction.GEOOBJECTJSON).getAsJsonObject().toString());
}
if (joAction.has(CreateGeoObjectAction.PARENTJSON) && !joAction.get(CreateGeoObjectAction.PARENTJSON).isJsonNull()) {
action.setParentJson(joAction.get(CreateGeoObjectAction.PARENTJSON).getAsJsonArray().toString());
}
action.apply();
request.addAction(action).apply();
} else {
String attributeName = joAction.get("attributeName").getAsString();
JsonObject attributeDiff = joAction.get("attributeDiff").getAsJsonObject();
UpdateAttributeAction action = new UpdateAttributeAction();
action.addApprovalStatus(AllGovernanceStatus.PENDING);
action.setCreateActionDate(Date.from(base.plus(sequence++, ChronoUnit.MINUTES)));
action.setAttributeName(attributeName);
action.setJson(attributeDiff.toString());
action.setApiVersion(CGRAdapterProperties.getApiVersion());
action.setContributorNotes(notes);
action.apply();
request.addAction(action).apply();
}
}
request.appLock();
request.setContributorNotes(notes);
request.apply();
return request;
}
use of net.geoprism.registry.action.geoobject.UpdateAttributeAction in project geoprism-registry by terraframe.
the class ChangeRequestServiceTest method createCRTrans.
@Transaction
private String createCRTrans(String actionType) {
ChangeRequest cr = new ChangeRequest();
cr.addApprovalStatus(AllGovernanceStatus.PENDING);
cr.setOrganizationCode(FastTestDataset.ORG_CGOV.getCode());
if (actionType.equals(UpdateAttributeViewJsonAdapters.PARENT_ATTR_NAME)) {
cr.setGeoObjectCode(FastTestDataset.PROV_CENTRAL.getCode());
cr.setGeoObjectTypeCode(FastTestDataset.PROV_CENTRAL.getGeoObjectType().getCode());
} else {
cr.setGeoObjectCode(FastTestDataset.CAMBODIA.getCode());
cr.setGeoObjectTypeCode(FastTestDataset.CAMBODIA.getGeoObjectType().getCode());
}
cr.apply();
AbstractAction action = null;
if (actionType.equals(CreateGeoObjectAction.CLASS)) {
action = new CreateGeoObjectAction();
action.setApiVersion("1.0");
((CreateGeoObjectActionBase) action).setGeoObjectJson(FastTestDataset.CAMBODIA.fetchGeoObjectOverTime().toJSON().toString());
action.addApprovalStatus(AllGovernanceStatus.PENDING);
action.setCreateActionDate(new Date());
action.apply();
} else if (actionType.equals(UpdateAttributeAction.CLASS)) {
action = new UpdateAttributeAction();
action.setApiVersion("1.0");
((UpdateAttributeActionBase) action).setAttributeName(FastTestDataset.AT_National_Anthem.getAttributeName());
((UpdateAttributeActionBase) action).setJson(UPDATE_ATTR_JSON);
action.addApprovalStatus(AllGovernanceStatus.PENDING);
action.setCreateActionDate(new Date());
action.apply();
} else if (actionType.equals(UpdateAttributeViewJsonAdapters.PARENT_ATTR_NAME)) {
action = new UpdateAttributeAction();
action.setApiVersion("1.0");
((UpdateAttributeActionBase) action).setAttributeName(UpdateAttributeViewJsonAdapters.PARENT_ATTR_NAME);
((UpdateAttributeActionBase) action).setJson(UPDATE_PARENT_ATTR_JSON);
action.addApprovalStatus(AllGovernanceStatus.PENDING);
action.setCreateActionDate(new Date());
action.apply();
} else {
throw new UnsupportedOperationException();
}
cr.addAction(action).apply();
return cr.toJSON().toString();
}
use of net.geoprism.registry.action.geoobject.UpdateAttributeAction in project geoprism-registry by terraframe.
the class ChangeRequestServiceTest method testComplexUpdateGeoObjectCR_Verify.
@Request
private void testComplexUpdateGeoObjectCR_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);
final Date oldStartDate = sdf.parse(OLD_START_DATE);
final Date oldEndDate = sdf.parse(OLD_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());
ServerGeoObjectIF cambodia = FastTestDataset.CAMBODIA.getServerObject();
ValueOverTimeCollection votc = cambodia.getValuesOverTime(FastTestDataset.AT_National_Anthem.getAttributeName());
Assert.assertEquals(2, votc.size());
ValueOverTime vot1 = votc.get(0);
Assert.assertNotNull(vot1.getOid());
Assert.assertTrue(!(vot1.getOid().equals(oldOid)));
Assert.assertEquals(NEW_ANTHEM, vot1.getValue());
Assert.assertEquals(oldStartDate, vot1.getStartDate());
Assert.assertEquals(oldEndDate, vot1.getEndDate());
ValueOverTime vot2 = votc.get(1);
Assert.assertNotNull(vot2.getOid());
Assert.assertTrue(!(vot2.getOid().equals(oldOid)));
Assert.assertEquals(NEW_ANTHEM, vot2.getValue());
Assert.assertEquals(newStartDate, vot2.getStartDate());
Assert.assertEquals(newEndDate, vot2.getEndDate());
}
use of net.geoprism.registry.action.geoobject.UpdateAttributeAction in project geoprism-registry by terraframe.
the class ChangeRequestServiceTest method testUpdateGeoObjectLocalizedValueCR_Verify.
@Request
private void testUpdateGeoObjectLocalizedValueCR_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(DefaultAttribute.DISPLAY_LABEL.getName());
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.assertEquals("localizeTest", cambodia.getDisplayLabel(newStartDate).getValue());
}
use of net.geoprism.registry.action.geoobject.UpdateAttributeAction in project geoprism-registry by terraframe.
the class ChangeRequestServiceTest method testComplexUpdateGeoObjectCR_applyCR.
@Request
private String[] testComplexUpdateGeoObjectCR_applyCR() throws Exception {
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(FastTestDataset.AT_National_Anthem.getAttributeName());
JsonObject diff = new JsonObject();
ServerGeoObjectIF cambodia = FastTestDataset.CAMBODIA.getServerObject();
String votOid = cambodia.getValuesOverTime(FastTestDataset.AT_National_Anthem.getAttributeName()).getValueOverTime(FastTestDataset.DEFAULT_OVER_TIME_DATE, TestDataSet.DEFAULT_END_TIME_DATE).getOid();
JsonArray valuesOverTime = JsonParser.parseString("[" + "{" + " \"oid\": \"" + votOid + "\"," + " \"action\": \"DELETE\"" + "}," + "{" + " \"action\": \"CREATE\"," + " \"newValue\": \"" + NEW_ANTHEM + "\"," + " \"newStartDate\": \"" + NEW_START_DATE + "\"," + " \"newEndDate\": \"" + NEW_END_DATE + "\"" + "}," + "{" + " \"action\": \"CREATE\"," + " \"newValue\": \"" + NEW_ANTHEM + "\"," + " \"newStartDate\": \"" + OLD_START_DATE + "\"," + " \"newEndDate\": \"" + OLD_END_DATE + "\"" + "}" + "]").getAsJsonArray();
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, votOid };
}
Aggregations