Search in sources :

Example 1 with UpdateAttributeAction

use of net.geoprism.registry.action.geoobject.UpdateAttributeAction 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 2 with UpdateAttributeAction

use of net.geoprism.registry.action.geoobject.UpdateAttributeAction 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 3 with UpdateAttributeAction

use of net.geoprism.registry.action.geoobject.UpdateAttributeAction in project geoprism-registry by terraframe.

the class ChangeRequestServiceTest method testComplexUpdateGeoObjectCR_Verify.

@Request
private void testComplexUpdateGeoObjectCR_Verify(String[] data) throws Exception {
    final String oldOid = data[1];
    final SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
    sdf.setTimeZone(GeoRegistryUtil.SYSTEM_TIMEZONE);
    final Date newStartDate = sdf.parse(NEW_START_DATE);
    final Date newEndDate = sdf.parse(NEW_END_DATE);
    final Date oldStartDate = sdf.parse(OLD_START_DATE);
    final Date oldEndDate = sdf.parse(OLD_END_DATE);
    ChangeRequestQuery crq = new ChangeRequestQuery(new QueryFactory());
    Assert.assertEquals(1, crq.getCount());
    ChangeRequest cr = crq.getIterator().next();
    Assert.assertEquals(AllGovernanceStatus.ACCEPTED.name(), cr.getGovernanceStatus().name());
    AbstractAction action = cr.getAllAction().next();
    Assert.assertTrue(action instanceof UpdateAttributeAction);
    Assert.assertEquals(FastTestDataset.CAMBODIA.getCode(), cr.getGeoObjectCode());
    Assert.assertEquals(FastTestDataset.CAMBODIA.getGeoObjectType().getCode(), cr.getGeoObjectTypeCode());
    Assert.assertEquals(FastTestDataset.ORG_CGOV.getCode(), cr.getOrganizationCode());
    ServerGeoObjectIF cambodia = FastTestDataset.CAMBODIA.getServerObject();
    ValueOverTimeCollection votc = cambodia.getValuesOverTime(FastTestDataset.AT_National_Anthem.getAttributeName());
    Assert.assertEquals(2, votc.size());
    ValueOverTime vot1 = votc.get(0);
    Assert.assertNotNull(vot1.getOid());
    Assert.assertTrue(!(vot1.getOid().equals(oldOid)));
    Assert.assertEquals(NEW_ANTHEM, vot1.getValue());
    Assert.assertEquals(oldStartDate, vot1.getStartDate());
    Assert.assertEquals(oldEndDate, vot1.getEndDate());
    ValueOverTime vot2 = votc.get(1);
    Assert.assertNotNull(vot2.getOid());
    Assert.assertTrue(!(vot2.getOid().equals(oldOid)));
    Assert.assertEquals(NEW_ANTHEM, vot2.getValue());
    Assert.assertEquals(newStartDate, vot2.getStartDate());
    Assert.assertEquals(newEndDate, vot2.getEndDate());
}
Also used : ValueOverTime(com.runwaysdk.dataaccess.graph.attributes.ValueOverTime) QueryFactory(com.runwaysdk.query.QueryFactory) ServerGeoObjectIF(net.geoprism.registry.model.ServerGeoObjectIF) ChangeRequestQuery(net.geoprism.registry.action.ChangeRequestQuery) ValueOverTimeCollection(com.runwaysdk.dataaccess.graph.attributes.ValueOverTimeCollection) ChangeRequest(net.geoprism.registry.action.ChangeRequest) SimpleDateFormat(java.text.SimpleDateFormat) AbstractAction(net.geoprism.registry.action.AbstractAction) UpdateAttributeAction(net.geoprism.registry.action.geoobject.UpdateAttributeAction) Date(java.util.Date) Request(com.runwaysdk.session.Request) ChangeRequest(net.geoprism.registry.action.ChangeRequest)

Example 4 with UpdateAttributeAction

use of net.geoprism.registry.action.geoobject.UpdateAttributeAction in project geoprism-registry by terraframe.

the class ChangeRequestServiceTest method testUpdateGeoObjectLocalizedValueCR_Verify.

@Request
private void testUpdateGeoObjectLocalizedValueCR_Verify(String[] data) throws Exception {
    final String oldOid = data[1];
    final SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
    sdf.setTimeZone(GeoRegistryUtil.SYSTEM_TIMEZONE);
    final Date newStartDate = sdf.parse(NEW_START_DATE);
    final Date newEndDate = sdf.parse(NEW_END_DATE);
    ChangeRequestQuery crq = new ChangeRequestQuery(new QueryFactory());
    Assert.assertEquals(1, crq.getCount());
    ChangeRequest cr = crq.getIterator().next();
    Assert.assertEquals(AllGovernanceStatus.ACCEPTED.name(), cr.getGovernanceStatus().name());
    AbstractAction action = cr.getAllAction().next();
    Assert.assertTrue(action instanceof UpdateAttributeAction);
    Assert.assertEquals(FastTestDataset.CAMBODIA.getCode(), cr.getGeoObjectCode());
    Assert.assertEquals(FastTestDataset.CAMBODIA.getGeoObjectType().getCode(), cr.getGeoObjectTypeCode());
    Assert.assertEquals(FastTestDataset.ORG_CGOV.getCode(), cr.getOrganizationCode());
    VertexServerGeoObject cambodia = (VertexServerGeoObject) FastTestDataset.CAMBODIA.getServerObject();
    ValueOverTimeCollection votc = cambodia.getValuesOverTime(DefaultAttribute.DISPLAY_LABEL.getName());
    Assert.assertEquals(1, votc.size());
    ValueOverTime vot1 = votc.get(0);
    Assert.assertNotNull(vot1.getOid());
    Assert.assertEquals(oldOid, vot1.getOid());
    Assert.assertEquals(newStartDate, vot1.getStartDate());
    Assert.assertEquals(newEndDate, vot1.getEndDate());
    Assert.assertEquals("localizeTest", cambodia.getDisplayLabel(newStartDate).getValue());
}
Also used : ValueOverTime(com.runwaysdk.dataaccess.graph.attributes.ValueOverTime) QueryFactory(com.runwaysdk.query.QueryFactory) ChangeRequestQuery(net.geoprism.registry.action.ChangeRequestQuery) ValueOverTimeCollection(com.runwaysdk.dataaccess.graph.attributes.ValueOverTimeCollection) VertexServerGeoObject(net.geoprism.registry.model.graph.VertexServerGeoObject) ChangeRequest(net.geoprism.registry.action.ChangeRequest) SimpleDateFormat(java.text.SimpleDateFormat) AbstractAction(net.geoprism.registry.action.AbstractAction) UpdateAttributeAction(net.geoprism.registry.action.geoobject.UpdateAttributeAction) Date(java.util.Date) Request(com.runwaysdk.session.Request) ChangeRequest(net.geoprism.registry.action.ChangeRequest)

Example 5 with UpdateAttributeAction

use of net.geoprism.registry.action.geoobject.UpdateAttributeAction in project geoprism-registry by terraframe.

the class ChangeRequestServiceTest method testComplexUpdateGeoObjectCR_applyCR.

@Request
private String[] testComplexUpdateGeoObjectCR_applyCR() throws Exception {
    ChangeRequest cr = new ChangeRequest();
    cr.addApprovalStatus(AllGovernanceStatus.PENDING);
    cr.setOrganizationCode(FastTestDataset.ORG_CGOV.getCode());
    cr.setGeoObjectCode(FastTestDataset.CAMBODIA.getCode());
    cr.setGeoObjectTypeCode(FastTestDataset.CAMBODIA.getGeoObjectType().getCode());
    cr.apply();
    UpdateAttributeAction action = new UpdateAttributeAction();
    action.setApiVersion("1.0");
    ((UpdateAttributeActionBase) action).setAttributeName(FastTestDataset.AT_National_Anthem.getAttributeName());
    JsonObject diff = new JsonObject();
    ServerGeoObjectIF cambodia = FastTestDataset.CAMBODIA.getServerObject();
    String votOid = cambodia.getValuesOverTime(FastTestDataset.AT_National_Anthem.getAttributeName()).getValueOverTime(FastTestDataset.DEFAULT_OVER_TIME_DATE, TestDataSet.DEFAULT_END_TIME_DATE).getOid();
    JsonArray valuesOverTime = JsonParser.parseString("[" + "{" + "  \"oid\": \"" + votOid + "\"," + "  \"action\": \"DELETE\"" + "}," + "{" + "  \"action\": \"CREATE\"," + "  \"newValue\": \"" + NEW_ANTHEM + "\"," + "  \"newStartDate\": \"" + NEW_START_DATE + "\"," + "  \"newEndDate\": \"" + NEW_END_DATE + "\"" + "}," + "{" + "  \"action\": \"CREATE\"," + "  \"newValue\": \"" + NEW_ANTHEM + "\"," + "  \"newStartDate\": \"" + OLD_START_DATE + "\"," + "  \"newEndDate\": \"" + OLD_END_DATE + "\"" + "}" + "]").getAsJsonArray();
    diff.add("valuesOverTime", valuesOverTime);
    ((UpdateAttributeActionBase) action).setJson(diff.toString());
    action.addApprovalStatus(AllGovernanceStatus.ACCEPTED);
    action.setCreateActionDate(new Date());
    action.apply();
    cr.addAction(action).apply();
    String serializedCR = cr.toJSON().toString();
    return new String[] { serializedCR, votOid };
}
Also used : JsonArray(com.google.gson.JsonArray) ServerGeoObjectIF(net.geoprism.registry.model.ServerGeoObjectIF) UpdateAttributeActionBase(net.geoprism.registry.action.geoobject.UpdateAttributeActionBase) JsonObject(com.google.gson.JsonObject) ChangeRequest(net.geoprism.registry.action.ChangeRequest) UpdateAttributeAction(net.geoprism.registry.action.geoobject.UpdateAttributeAction) Date(java.util.Date) Request(com.runwaysdk.session.Request) ChangeRequest(net.geoprism.registry.action.ChangeRequest)

Aggregations

UpdateAttributeAction (net.geoprism.registry.action.geoobject.UpdateAttributeAction)16 ChangeRequest (net.geoprism.registry.action.ChangeRequest)14 Request (com.runwaysdk.session.Request)11 Date (java.util.Date)11 ValueOverTime (com.runwaysdk.dataaccess.graph.attributes.ValueOverTime)9 AbstractAction (net.geoprism.registry.action.AbstractAction)9 VertexServerGeoObject (net.geoprism.registry.model.graph.VertexServerGeoObject)8 JsonObject (com.google.gson.JsonObject)7 QueryFactory (com.runwaysdk.query.QueryFactory)7 ChangeRequestQuery (net.geoprism.registry.action.ChangeRequestQuery)7 UpdateAttributeActionBase (net.geoprism.registry.action.geoobject.UpdateAttributeActionBase)6 JsonArray (com.google.gson.JsonArray)5 ValueOverTimeCollection (com.runwaysdk.dataaccess.graph.attributes.ValueOverTimeCollection)5 SimpleDateFormat (java.text.SimpleDateFormat)5 CreateGeoObjectAction (net.geoprism.registry.action.geoobject.CreateGeoObjectAction)4 Transaction (com.runwaysdk.dataaccess.transaction.Transaction)3 Instant (java.time.Instant)2 ServerGeoObjectIF (net.geoprism.registry.model.ServerGeoObjectIF)2 OIterator (com.runwaysdk.query.OIterator)1 SingleActor (com.runwaysdk.system.SingleActor)1