Search in sources :

Example 1 with CreateGeoObjectAction

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;
}
Also used : CreateGeoObjectAction(net.geoprism.registry.action.geoobject.CreateGeoObjectAction) ServerGeoObjectService(net.geoprism.registry.geoobject.ServerGeoObjectService) UpdateGeoObjectAction(net.geoprism.registry.action.geoobject.UpdateGeoObjectAction) ServerGeoObjectIF(net.geoprism.registry.model.ServerGeoObjectIF) Instant(java.time.Instant) ParentTreeNode(org.commongeoregistry.adapter.dataaccess.ParentTreeNode) GeoObject(org.commongeoregistry.adapter.dataaccess.GeoObject) ChangeRequest(net.geoprism.registry.action.ChangeRequest) Date(java.util.Date) Endpoint(com.runwaysdk.mvc.Endpoint) Transaction(com.runwaysdk.dataaccess.transaction.Transaction)

Example 2 with CreateGeoObjectAction

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;
}
Also used : CreateGeoObjectAction(net.geoprism.registry.action.geoobject.CreateGeoObjectAction) Instant(java.time.Instant) JsonObject(com.google.gson.JsonObject) AbstractAction(net.geoprism.registry.action.AbstractAction) UpdateAttributeAction(net.geoprism.registry.action.geoobject.UpdateAttributeAction) Transaction(com.runwaysdk.dataaccess.transaction.Transaction)

Example 3 with CreateGeoObjectAction

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();
    }
}
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 4 with CreateGeoObjectAction

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();
}
Also used : CreateGeoObjectAction(net.geoprism.registry.action.geoobject.CreateGeoObjectAction) CreateGeoObjectActionBase(net.geoprism.registry.action.geoobject.CreateGeoObjectActionBase) UpdateAttributeActionBase(net.geoprism.registry.action.geoobject.UpdateAttributeActionBase) ChangeRequest(net.geoprism.registry.action.ChangeRequest) AbstractAction(net.geoprism.registry.action.AbstractAction) UpdateAttributeAction(net.geoprism.registry.action.geoobject.UpdateAttributeAction) Date(java.util.Date) Transaction(com.runwaysdk.dataaccess.transaction.Transaction)

Example 5 with CreateGeoObjectAction

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();
        }
    }
}
Also used : CreateGeoObjectAction(net.geoprism.registry.action.geoobject.CreateGeoObjectAction) TreeSet(java.util.TreeSet) GeoprismUser(net.geoprism.GeoprismUser) UpdateAttributeAction(net.geoprism.registry.action.geoobject.UpdateAttributeAction) SingleActor(com.runwaysdk.system.SingleActor) Transaction(com.runwaysdk.dataaccess.transaction.Transaction)

Aggregations

CreateGeoObjectAction (net.geoprism.registry.action.geoobject.CreateGeoObjectAction)9 Transaction (com.runwaysdk.dataaccess.transaction.Transaction)7 ChangeRequest (net.geoprism.registry.action.ChangeRequest)7 Date (java.util.Date)4 AbstractAction (net.geoprism.registry.action.AbstractAction)4 UpdateAttributeAction (net.geoprism.registry.action.geoobject.UpdateAttributeAction)4 Instant (java.time.Instant)3 JsonObject (com.google.gson.JsonObject)2 QueryFactory (com.runwaysdk.query.QueryFactory)2 ChangeRequestQuery (net.geoprism.registry.action.ChangeRequestQuery)2 UpdateGeoObjectAction (net.geoprism.registry.action.geoobject.UpdateGeoObjectAction)2 ServerGeoObjectIF (net.geoprism.registry.model.ServerGeoObjectIF)2 Endpoint (com.runwaysdk.mvc.Endpoint)1 OIterator (com.runwaysdk.query.OIterator)1 Request (com.runwaysdk.session.Request)1 SingleActor (com.runwaysdk.system.SingleActor)1 TreeSet (java.util.TreeSet)1 GeoprismUser (net.geoprism.GeoprismUser)1 CGRPermissionException (net.geoprism.registry.CGRPermissionException)1 CreateGeoObjectActionBase (net.geoprism.registry.action.geoobject.CreateGeoObjectActionBase)1