Search in sources :

Example 1 with AbstractAction

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();
    }
}
Also used : AbstractActionDTO(org.commongeoregistry.adapter.action.AbstractActionDTO) ChangeRequest(net.geoprism.registry.action.ChangeRequest) AbstractAction(net.geoprism.registry.action.AbstractAction)

Example 2 with AbstractAction

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;
}
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 AbstractAction

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

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());
}
Also used : ServerGeoObjectIF(net.geoprism.registry.model.ServerGeoObjectIF) ServerParentTreeNode(net.geoprism.registry.model.ServerParentTreeNode) ChangeRequest(net.geoprism.registry.action.ChangeRequest) AbstractAction(net.geoprism.registry.action.AbstractAction) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date) Request(com.runwaysdk.session.Request) ChangeRequest(net.geoprism.registry.action.ChangeRequest)

Example 5 with AbstractAction

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

Aggregations

AbstractAction (net.geoprism.registry.action.AbstractAction)15 ChangeRequest (net.geoprism.registry.action.ChangeRequest)14 Request (com.runwaysdk.session.Request)11 UpdateAttributeAction (net.geoprism.registry.action.geoobject.UpdateAttributeAction)9 QueryFactory (com.runwaysdk.query.QueryFactory)8 Date (java.util.Date)8 ChangeRequestQuery (net.geoprism.registry.action.ChangeRequestQuery)8 SimpleDateFormat (java.text.SimpleDateFormat)7 ValueOverTime (com.runwaysdk.dataaccess.graph.attributes.ValueOverTime)6 ValueOverTimeCollection (com.runwaysdk.dataaccess.graph.attributes.ValueOverTimeCollection)6 CreateGeoObjectAction (net.geoprism.registry.action.geoobject.CreateGeoObjectAction)4 VertexServerGeoObject (net.geoprism.registry.model.graph.VertexServerGeoObject)4 ServerGeoObjectIF (net.geoprism.registry.model.ServerGeoObjectIF)3 Transaction (com.runwaysdk.dataaccess.transaction.Transaction)2 JsonObject (com.google.gson.JsonObject)1 OIterator (com.runwaysdk.query.OIterator)1 Geometry (com.vividsolutions.jts.geom.Geometry)1 Instant (java.time.Instant)1 Calendar (java.util.Calendar)1 Classifier (net.geoprism.ontology.Classifier)1