use of net.geoprism.registry.action.AbstractAction in project geoprism-registry by terraframe.
the class ChangeRequestTestDataGenerator method submitChangeRequest.
private static void submitChangeRequest(String sJson) {
ChangeRequest cr = new ChangeRequest();
cr.addApprovalStatus(AllGovernanceStatus.PENDING);
cr.apply();
List<AbstractActionDTO> actionDTOs = AbstractActionDTO.parseActions(sJson);
for (AbstractActionDTO actionDTO : actionDTOs) {
AbstractAction ra = AbstractAction.dtoToRegistry(actionDTO);
ra.addApprovalStatus(AllGovernanceStatus.PENDING);
ra.apply();
cr.addAction(ra).apply();
}
}
use of net.geoprism.registry.action.AbstractAction 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.AbstractAction in project geoprism-registry by terraframe.
the class ChangeRequestService method setActionStatus.
@Request(RequestType.SESSION)
public void setActionStatus(String sessionId, String actionOid, String status) {
AbstractAction action = AbstractAction.get(actionOid);
if (!this.permService.getPermissions(action.getAllRequest().next()).containsAll(Arrays.asList(ChangeRequestPermissionAction.WRITE_APPROVAL_STATUS))) {
throw new CGRPermissionException();
}
action.appLock();
action.clearApprovalStatus();
action.addApprovalStatus(AllGovernanceStatus.valueOf(status));
action.apply();
}
use of net.geoprism.registry.action.AbstractAction in project geoprism-registry by terraframe.
the class ChangeRequestServiceTest method testImplementParentDecisionsVerify.
@Request
private void testImplementParentDecisionsVerify(String crOid) throws Exception {
ChangeRequest cr = ChangeRequest.get(crOid);
Assert.assertEquals(AllGovernanceStatus.ACCEPTED.name(), cr.getApprovalStatus().get(0).name());
AbstractAction action = cr.getAllAction().next();
Assert.assertEquals(AllGovernanceStatus.ACCEPTED.name(), action.getApprovalStatus().get(0).name());
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
sdf.setTimeZone(GeoRegistryUtil.SYSTEM_TIMEZONE);
Date newStartDate = sdf.parse(NEW_START_DATE);
Date newEndDate = sdf.parse(NEW_END_DATE);
ServerGeoObjectIF serverGo = FastTestDataset.PROV_CENTRAL.getServerObject();
List<ServerParentTreeNode> ptns = serverGo.getParentsOverTime(new String[] { FastTestDataset.COUNTRY.getCode() }, false).getEntries(FastTestDataset.HIER_ADMIN.getServerObject());
Assert.assertEquals(1, ptns.size());
ServerParentTreeNode ptn = ptns.get(0);
List<ServerParentTreeNode> parents = ptn.getParents();
Assert.assertEquals(1, parents.size());
ServerParentTreeNode parent = parents.get(0);
Assert.assertEquals(newStartDate, ptn.getStartDate());
Assert.assertEquals(newEndDate, ptn.getEndDate());
Assert.assertEquals(BELIZE.getCode(), parent.getGeoObject().getCode());
}
use of net.geoprism.registry.action.AbstractAction 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();
}
Aggregations