use of net.geoprism.registry.CGRPermissionException 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.CGRPermissionException in project geoprism-registry by terraframe.
the class ChangeRequestService method uploadFileInTransactionCR.
@Transaction
String uploadFileInTransactionCR(String requestId, String fileName, InputStream fileStream) {
ChangeRequest request = ChangeRequest.get(requestId);
if (!this.permService.getPermissions(request).contains(ChangeRequestPermissionAction.WRITE_DOCUMENTS)) {
throw new CGRPermissionException();
}
VaultFile vf = VaultFile.createAndApply(fileName, fileStream);
request.addDocument(vf).apply();
JsonObject jo = new JsonObject();
jo.addProperty("fileName", vf.getName());
jo.addProperty("oid", vf.getOid());
jo.addProperty("requestId", requestId);
return jo.toString();
}
use of net.geoprism.registry.CGRPermissionException in project geoprism-registry by terraframe.
the class ChangeRequestService method deleteChangeRequest.
@Request(RequestType.SESSION)
public String deleteChangeRequest(String sessionId, String requestId) {
ChangeRequest request = ChangeRequest.get(requestId);
if (!this.permService.getPermissions(request).containsAll(Arrays.asList(ChangeRequestPermissionAction.DELETE))) {
throw new CGRPermissionException();
}
request.delete();
return requestId;
}
use of net.geoprism.registry.CGRPermissionException 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.CGRPermissionException in project geoprism-registry by terraframe.
the class ChangeRequestService method listDocumentsCR.
String listDocumentsCR(String requestId) {
JsonArray ja = new JsonArray();
ChangeRequest request = ChangeRequest.get(requestId);
if (!this.permService.getPermissions(request).contains(ChangeRequestPermissionAction.READ_DOCUMENTS)) {
throw new CGRPermissionException();
}
OIterator<? extends VaultFile> it = request.getAllDocument();
try {
for (VaultFile vf : it) {
JsonObject jo = new JsonObject();
jo.addProperty("fileName", vf.getName());
jo.addProperty("oid", vf.getOid());
jo.addProperty("requestId", requestId);
ja.add(jo);
}
} finally {
it.close();
}
return ja.toString();
}
Aggregations