Search in sources :

Example 1 with CGRPermissionException

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();
    }
}
Also used : RolePermissionService(net.geoprism.registry.permission.RolePermissionService) CGRPermissionException(net.geoprism.registry.CGRPermissionException) CreateGeoObjectAction(net.geoprism.registry.action.geoobject.CreateGeoObjectAction) ServerGeoObjectIF(net.geoprism.registry.model.ServerGeoObjectIF) ServerGeoObjectType(net.geoprism.registry.model.ServerGeoObjectType) Instant(java.time.Instant) JsonObject(com.google.gson.JsonObject) GeoObjectOverTime(org.commongeoregistry.adapter.dataaccess.GeoObjectOverTime) ServerParentTreeNodeOverTime(net.geoprism.registry.view.ServerParentTreeNodeOverTime) ChangeRequest(net.geoprism.registry.action.ChangeRequest) Transaction(com.runwaysdk.dataaccess.transaction.Transaction)

Example 2 with 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();
}
Also used : CGRPermissionException(net.geoprism.registry.CGRPermissionException) VaultFile(com.runwaysdk.system.VaultFile) JsonObject(com.google.gson.JsonObject) ChangeRequest(net.geoprism.registry.action.ChangeRequest) Transaction(com.runwaysdk.dataaccess.transaction.Transaction)

Example 3 with CGRPermissionException

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;
}
Also used : CGRPermissionException(net.geoprism.registry.CGRPermissionException) ChangeRequest(net.geoprism.registry.action.ChangeRequest) Request(com.runwaysdk.session.Request) ChangeRequest(net.geoprism.registry.action.ChangeRequest)

Example 4 with CGRPermissionException

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();
}
Also used : CGRPermissionException(net.geoprism.registry.CGRPermissionException) AbstractAction(net.geoprism.registry.action.AbstractAction) Request(com.runwaysdk.session.Request) ChangeRequest(net.geoprism.registry.action.ChangeRequest)

Example 5 with CGRPermissionException

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();
}
Also used : JsonArray(com.google.gson.JsonArray) CGRPermissionException(net.geoprism.registry.CGRPermissionException) VaultFile(com.runwaysdk.system.VaultFile) JsonObject(com.google.gson.JsonObject) ChangeRequest(net.geoprism.registry.action.ChangeRequest)

Aggregations

CGRPermissionException (net.geoprism.registry.CGRPermissionException)10 ChangeRequest (net.geoprism.registry.action.ChangeRequest)10 JsonObject (com.google.gson.JsonObject)4 Transaction (com.runwaysdk.dataaccess.transaction.Transaction)4 Request (com.runwaysdk.session.Request)4 VaultFile (com.runwaysdk.system.VaultFile)4 JsonArray (com.google.gson.JsonArray)2 ServerGeoObjectType (net.geoprism.registry.model.ServerGeoObjectType)2 RolePermissionService (net.geoprism.registry.permission.RolePermissionService)2 Instant (java.time.Instant)1 AbstractAction (net.geoprism.registry.action.AbstractAction)1 CreateGeoObjectAction (net.geoprism.registry.action.geoobject.CreateGeoObjectAction)1 ServerGeoObjectIF (net.geoprism.registry.model.ServerGeoObjectIF)1 VertexServerGeoObject (net.geoprism.registry.model.graph.VertexServerGeoObject)1 ServerParentTreeNodeOverTime (net.geoprism.registry.view.ServerParentTreeNodeOverTime)1 GeoObjectOverTime (org.commongeoregistry.adapter.dataaccess.GeoObjectOverTime)1