use of net.geoprism.registry.action.geoobject.CreateGeoObjectAction in project geoprism-registry by terraframe.
the class GeoObjectEditorControllerNoOverTime method applyInTransaction.
@Transaction
private GeoObject applyInTransaction(String sessionId, String sPtn, String sGo, Boolean isNew, String masterListId) {
final Date startDate = new Date();
final Date endDate = ValueOverTime.INFINITY_END_DATE;
GeoObject go;
Map<String, String> roles = Session.getCurrentSession().getUserRoles();
if (roles.keySet().contains(RegistryConstants.REGISTRY_CONTRIBUTOR_ROLE)) {
Instant base = Instant.now();
int sequence = 0;
ChangeRequest request = new ChangeRequest();
request.addApprovalStatus(AllGovernanceStatus.PENDING);
request.apply();
if (!isNew) {
UpdateGeoObjectAction action = new UpdateGeoObjectAction();
action.addApprovalStatus(AllGovernanceStatus.PENDING);
action.setCreateActionDate(Date.from(base.plus(sequence++, ChronoUnit.MINUTES)));
action.setGeoObjectJson(sGo);
action.setApiVersion(CGRAdapterProperties.getApiVersion());
action.apply();
request.addAction(action).apply();
} else {
CreateGeoObjectAction action = new CreateGeoObjectAction();
action.addApprovalStatus(AllGovernanceStatus.PENDING);
action.setCreateActionDate(Date.from(base.plus(sequence++, ChronoUnit.MINUTES)));
action.setGeoObjectJson(sGo);
action.setApiVersion(CGRAdapterProperties.getApiVersion());
action.apply();
request.addAction(action).apply();
}
ParentTreeNode ptn = ParentTreeNode.fromJSON(sPtn.toString(), ServiceFactory.getAdapter());
applyChangeRequest(sessionId, request, ptn, isNew, base, sequence, startDate, endDate);
} else {
if (!isNew) {
go = RegistryService.getInstance().updateGeoObject(sessionId, sGo.toString(), startDate, endDate);
} else {
go = RegistryService.getInstance().createGeoObject(sessionId, sGo.toString(), startDate, endDate);
}
ParentTreeNode ptn = ParentTreeNode.fromJSON(sPtn.toString(), ServiceFactory.getAdapter());
applyPtn(sessionId, ptn, startDate, endDate);
// Update the master list record
if (masterListId != null) {
ServerGeoObjectService service = new ServerGeoObjectService();
ServerGeoObjectIF geoObject = service.getGeoObject(go);
if (!isNew) {
ListTypeVersion.get(masterListId).updateRecord(geoObject);
} else {
ListTypeVersion.get(masterListId).publishRecord(geoObject);
}
}
return go;
}
return null;
}
use of net.geoprism.registry.action.geoobject.CreateGeoObjectAction 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.CreateGeoObjectAction in project geoprism-registry by terraframe.
the class ServerGeoObjectService method createGeoObjectInTrans.
@Transaction
public JsonObject createGeoObjectInTrans(String sPtn, String sTimeGo, String masterListId, String notes) {
GeoObjectOverTime timeGO = GeoObjectOverTime.fromJSON(ServiceFactory.getAdapter(), sTimeGo);
ServerGeoObjectType serverGOT = ServerGeoObjectType.get(timeGO.getType());
RolePermissionService perms = ServiceFactory.getRolePermissionService();
final String orgCode = serverGOT.getOrganization().getCode();
if (perms.isSRA() || perms.isRA(orgCode) || perms.isRM(orgCode, serverGOT)) {
ServerGeoObjectService service = new ServerGeoObjectService();
ServerGeoObjectIF serverGO = service.apply(timeGO, true, false);
final ServerGeoObjectType type = serverGO.getType();
if (sPtn != null) {
ServerParentTreeNodeOverTime ptnOt = ServerParentTreeNodeOverTime.fromJSON(type, sPtn);
serverGO.setParents(ptnOt);
}
// Update the master list record
if (masterListId != null) {
ListTypeVersion.get(masterListId).publishRecord(serverGO);
}
JsonObject resp = new JsonObject();
resp.addProperty("isChangeRequest", false);
resp.add("geoObject", serverGO.toGeoObjectOverTime().toJSON(ServiceFactory.getRegistryService().serializer(Session.getCurrentSession().getOid())));
return resp;
} else if (ServiceFactory.getRolePermissionService().isRC(orgCode, serverGOT)) {
Instant base = Instant.now();
int sequence = 0;
ChangeRequest request = new ChangeRequest();
request.addApprovalStatus(AllGovernanceStatus.PENDING);
request.setContributorNotes(notes);
request.setGeoObjectCode(timeGO.getCode());
request.setGeoObjectTypeCode(timeGO.getType().getCode());
request.setOrganizationCode(orgCode);
request.apply();
CreateGeoObjectAction action = new CreateGeoObjectAction();
action.addApprovalStatus(AllGovernanceStatus.PENDING);
action.setCreateActionDate(Date.from(base.plus(sequence++, ChronoUnit.MINUTES)));
action.setGeoObjectJson(sTimeGo);
action.setParentJson(sPtn);
action.setApiVersion(CGRAdapterProperties.getApiVersion());
action.setContributorNotes(notes);
action.apply();
request.addAction(action).apply();
JsonObject resp = new JsonObject();
resp.addProperty("isChangeRequest", true);
resp.addProperty("changeRequestId", request.getOid());
return resp;
} else {
throw new CGRPermissionException();
}
}
use of net.geoprism.registry.action.geoobject.CreateGeoObjectAction 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.CreateGeoObjectAction in project geoprism-registry by terraframe.
the class ChangeRequest method execute.
@Transaction
public void execute(String maintainerNotes, String additionalNotes) {
if (this.getApprovalStatus().contains(AllGovernanceStatus.PENDING)) {
List<AbstractAction> actions = this.getOrderedActions();
Set<AllGovernanceStatus> statuses = new TreeSet<AllGovernanceStatus>();
for (AbstractAction action : actions) {
if (action instanceof UpdateAttributeAction && action.getApprovalStatus().contains(AllGovernanceStatus.PENDING)) {
throw new ActionExecuteException("Unable to execute an action with the pending status");
} else if (action instanceof CreateGeoObjectAction && action.getApprovalStatus().contains(AllGovernanceStatus.PENDING)) {
action.appLock();
action.clearApprovalStatus();
action.addApprovalStatus(AllGovernanceStatus.ACCEPTED);
action.apply();
action.execute();
statuses.add(AllGovernanceStatus.ACCEPTED);
} else if (action.getApprovalStatus().contains(AllGovernanceStatus.ACCEPTED)) {
action.execute();
statuses.add(AllGovernanceStatus.ACCEPTED);
} else if (action.getApprovalStatus().contains(AllGovernanceStatus.REJECTED) || action.getApprovalStatus().contains(AllGovernanceStatus.INVALID)) {
statuses.add(AllGovernanceStatus.REJECTED);
}
}
AllGovernanceStatus status = AllGovernanceStatus.REJECTED;
if (statuses.size() > 0) {
status = statuses.size() == 1 ? statuses.iterator().next() : AllGovernanceStatus.PARTIAL;
}
this.appLock();
this.setMaintainerNotes(maintainerNotes);
this.setAdditionalNotes(additionalNotes);
this.clearApprovalStatus();
this.addApprovalStatus(status);
this.apply();
// Email the contributor
try {
SingleActor actor = this.getCreatedBy();
if (actor instanceof GeoprismUser) {
String email = ((GeoprismUser) actor).getEmail();
if (email != null && email.length() > 0 && !email.contains("@noreply")) {
final String statusLabel = status.getDisplayLabel().toLowerCase(Session.getCurrentLocale());
String subject = LocalizationFacade.getFromBundles("change.request.email.implement.subject");
subject = subject.replaceAll("\\{status\\}", StringUtils.capitalize(statusLabel));
String body = LocalizationFacade.getFromBundles("change.request.email.implement.body");
body = body.replaceAll("\\\\n", "\n");
body = body.replaceAll("\\{status\\}", statusLabel);
body = body.replaceAll("\\{geoobject\\}", this.getGeoObject().getDisplayLabel().getValue());
String link = GeoregistryProperties.getRemoteServerUrl() + "cgr/manage#/registry/change-requests/" + this.getOid();
body = body.replaceAll("\\{link\\}", link);
EmailSetting.sendEmail(subject, body, new String[] { email });
}
}
} catch (Throwable t) {
t.printStackTrace();
}
}
}
Aggregations