Search in sources :

Example 26 with ValueOverTime

use of com.runwaysdk.dataaccess.graph.attributes.ValueOverTime in project geoprism-registry by terraframe.

the class UpdateValueOverTimeView method execute.

/*
   * You should NOT be directly setting values on the VOTC contained within the
   * GeoObject here. Use the looseVotc instead. For reasons why, {{@see
   * UpdateChangeOverTimeAttributeView.execute}}
   */
public void execute(UpdateChangeOverTimeAttributeView cotView, VertexServerGeoObject go, List<ValueOverTime> looseVotc) {
    if (this.action.equals(UpdateActionType.DELETE)) {
        ValueOverTime vot = this.getValueByOid(looseVotc, this.getOid());
        if (vot == null) {
            ExecuteOutOfDateChangeRequestException ex = new ExecuteOutOfDateChangeRequestException();
            throw ex;
        }
        looseVotc.remove(vot);
    } else if (this.action.equals(UpdateActionType.UPDATE)) {
        ValueOverTime vot = this.getValueByOid(looseVotc, this.getOid());
        if (vot == null) {
            ExecuteOutOfDateChangeRequestException ex = new ExecuteOutOfDateChangeRequestException();
            throw ex;
        }
        if (this.newValue == null && this.newStartDate == null && this.newEndDate == null) {
            throw new InvalidChangeRequestException();
        }
        if (newStartDate != null) {
            vot.setStartDate(newStartDate);
        }
        if (newEndDate != null) {
            vot.setEndDate(newEndDate);
        }
        this.persistValue(vot, cotView, go, looseVotc);
    } else if (this.action.equals(UpdateActionType.CREATE)) {
        ValueOverTime vot = this.getValueByDate(looseVotc, this.newStartDate, this.newEndDate);
        if (vot != null) {
            ExecuteOutOfDateChangeRequestException ex = new ExecuteOutOfDateChangeRequestException();
            throw ex;
        }
        if (this.newValue == null || this.newStartDate == null || this.newEndDate == null) {
            throw new InvalidChangeRequestException();
        }
        this.persistValue(null, cotView, go, looseVotc);
    } else {
        throw new UnsupportedOperationException("Unsupported action type [" + this.action + "].");
    }
}
Also used : ValueOverTime(com.runwaysdk.dataaccess.graph.attributes.ValueOverTime) InvalidChangeRequestException(net.geoprism.registry.action.InvalidChangeRequestException) ExecuteOutOfDateChangeRequestException(net.geoprism.registry.action.ExecuteOutOfDateChangeRequestException)

Example 27 with ValueOverTime

use of com.runwaysdk.dataaccess.graph.attributes.ValueOverTime in project geoprism-registry by terraframe.

the class ChangeRequestServiceTest method testUpdateGeoObjectLocalizedValueCR_applyCR.

@Request
private String[] testUpdateGeoObjectLocalizedValueCR_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(DefaultAttribute.DISPLAY_LABEL.getName());
    JsonObject diff = new JsonObject();
    VertexServerGeoObject cambodia = (VertexServerGeoObject) FastTestDataset.CAMBODIA.getServerObject();
    ValueOverTime vot = cambodia.getValuesOverTime(DefaultAttribute.DISPLAY_LABEL.getName()).getValueOverTime(FastTestDataset.DEFAULT_OVER_TIME_DATE, TestDataSet.DEFAULT_END_TIME_DATE);
    JsonArray valuesOverTime = JsonParser.parseString("[" + "{" + "  \"oid\": \"" + vot.getOid() + "\"," + "  \"action\": \"UPDATE\"," + "  \"oldEndDate\": \"" + OLD_END_DATE + "\"," + "  \"oldStartDate\": \"" + OLD_START_DATE + "\"," + "  \"oldValue\": \"\"," + "  \"newValue\": \"\"," + "  \"newStartDate\": \"" + NEW_START_DATE + "\"," + "  \"newEndDate\": \"" + NEW_END_DATE + "\"" + "}" + "]").getAsJsonArray();
    valuesOverTime.get(0).getAsJsonObject().add("oldValue", cambodia.getDisplayLabel(FastTestDataset.DEFAULT_OVER_TIME_DATE).toJSON());
    LocalizedValue newValue = new LocalizedValue("localizeTest");
    valuesOverTime.get(0).getAsJsonObject().add("newValue", newValue.toJSON());
    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, vot.getOid() };
}
Also used : JsonArray(com.google.gson.JsonArray) ValueOverTime(com.runwaysdk.dataaccess.graph.attributes.ValueOverTime) LocalizedValue(org.commongeoregistry.adapter.dataaccess.LocalizedValue) UpdateAttributeActionBase(net.geoprism.registry.action.geoobject.UpdateAttributeActionBase) JsonObject(com.google.gson.JsonObject) VertexServerGeoObject(net.geoprism.registry.model.graph.VertexServerGeoObject) 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)

Example 28 with ValueOverTime

use of com.runwaysdk.dataaccess.graph.attributes.ValueOverTime in project geoprism-registry by terraframe.

the class ChangeRequestServiceTest method testUpdateGeoObjectTermCR_applyCR.

@Request
private String[] testUpdateGeoObjectTermCR_applyCR() throws Exception {
    final String attrName = FastTestDataset.AT_RELIGION.getAttributeName();
    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(attrName);
    JsonObject diff = new JsonObject();
    VertexServerGeoObject cambodia = (VertexServerGeoObject) FastTestDataset.CAMBODIA.getServerObject();
    ValueOverTime vot = cambodia.getValuesOverTime(attrName).getValueOverTime(FastTestDataset.DEFAULT_OVER_TIME_DATE, TestDataSet.DEFAULT_END_TIME_DATE);
    JsonArray valuesOverTime = JsonParser.parseString("[" + "{" + "  \"oid\": \"" + vot.getOid() + "\"," + "  \"action\": \"UPDATE\"," + "  \"oldEndDate\": \"" + OLD_END_DATE + "\"," + "  \"oldStartDate\": \"" + OLD_START_DATE + "\"," + "  \"oldValue\": [\"" + ((Term) FastTestDataset.CAMBODIA.getDefaultValue(attrName)).getCode() + "\"]," + "  \"newValue\": [\"" + FastTestDataset.T_Islam.getCode() + "\"]," + "  \"newStartDate\": \"" + NEW_START_DATE + "\"," + "  \"newEndDate\": \"" + NEW_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, vot.getOid() };
}
Also used : JsonArray(com.google.gson.JsonArray) ValueOverTime(com.runwaysdk.dataaccess.graph.attributes.ValueOverTime) UpdateAttributeActionBase(net.geoprism.registry.action.geoobject.UpdateAttributeActionBase) JsonObject(com.google.gson.JsonObject) VertexServerGeoObject(net.geoprism.registry.model.graph.VertexServerGeoObject) 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)

Example 29 with ValueOverTime

use of com.runwaysdk.dataaccess.graph.attributes.ValueOverTime in project geoprism-registry by terraframe.

the class ChangeRequestServiceTest method testUpdateGeoObjectDateCR_Verify.

@Request
private void testUpdateGeoObjectDateCR_Verify(Object[] data) throws Exception {
    final String attrName = FastTestDataset.AT_DATE_OF_FORMATION.getAttributeName();
    final String oldOid = (String) 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(attrName);
    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());
    Calendar expected = Calendar.getInstance();
    expected.setTime(new Date((Long) data[2]));
    // It's surprising how imprecise Runway's dates are...
    expected.set(Calendar.SECOND, 0);
    expected.set(Calendar.MILLISECOND, 0);
    Calendar actual = Calendar.getInstance();
    actual.setTime((Date) cambodia.getValue(attrName));
    actual.set(Calendar.SECOND, 0);
    actual.set(Calendar.MILLISECOND, 0);
    Assert.assertEquals(expected.getTime(), actual.getTime());
}
Also used : QueryFactory(com.runwaysdk.query.QueryFactory) Calendar(java.util.Calendar) ChangeRequest(net.geoprism.registry.action.ChangeRequest) UpdateAttributeAction(net.geoprism.registry.action.geoobject.UpdateAttributeAction) Date(java.util.Date) ValueOverTime(com.runwaysdk.dataaccess.graph.attributes.ValueOverTime) ChangeRequestQuery(net.geoprism.registry.action.ChangeRequestQuery) ValueOverTimeCollection(com.runwaysdk.dataaccess.graph.attributes.ValueOverTimeCollection) VertexServerGeoObject(net.geoprism.registry.model.graph.VertexServerGeoObject) SimpleDateFormat(java.text.SimpleDateFormat) AbstractAction(net.geoprism.registry.action.AbstractAction) Request(com.runwaysdk.session.Request) ChangeRequest(net.geoprism.registry.action.ChangeRequest)

Example 30 with ValueOverTime

use of com.runwaysdk.dataaccess.graph.attributes.ValueOverTime in project geoprism-registry by terraframe.

the class ChangeRequestServiceTest method testImplementDecisionsVerify.

@Request
private void testImplementDecisionsVerify(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.CAMBODIA.getServerObject();
    ValueOverTimeCollection votc = serverGo.getValuesOverTime(FastTestDataset.AT_National_Anthem.getAttributeName());
    Assert.assertEquals(1, votc.size());
    ValueOverTime vot = votc.get(0);
    Assert.assertEquals(newStartDate, vot.getStartDate());
    Assert.assertEquals(newEndDate, vot.getEndDate());
    Assert.assertEquals(NEW_ANTHEM, vot.getValue());
    Assert.assertEquals(NEW_ANTHEM, serverGo.getValue(FastTestDataset.AT_National_Anthem.getAttributeName(), newStartDate));
}
Also used : ValueOverTime(com.runwaysdk.dataaccess.graph.attributes.ValueOverTime) ServerGeoObjectIF(net.geoprism.registry.model.ServerGeoObjectIF) ValueOverTimeCollection(com.runwaysdk.dataaccess.graph.attributes.ValueOverTimeCollection) 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)

Aggregations

ValueOverTime (com.runwaysdk.dataaccess.graph.attributes.ValueOverTime)44 ValueOverTimeCollection (com.runwaysdk.dataaccess.graph.attributes.ValueOverTimeCollection)29 Request (com.runwaysdk.session.Request)26 Date (java.util.Date)22 ServerGeoObjectIF (net.geoprism.registry.model.ServerGeoObjectIF)18 Test (org.junit.Test)16 EdgeObject (com.runwaysdk.business.graph.EdgeObject)10 ChangeRequest (net.geoprism.registry.action.ChangeRequest)10 VertexServerGeoObject (net.geoprism.registry.model.graph.VertexServerGeoObject)10 VertexObject (com.runwaysdk.business.graph.VertexObject)9 UpdateAttributeAction (net.geoprism.registry.action.geoobject.UpdateAttributeAction)9 MdVertexDAOIF (com.runwaysdk.dataaccess.MdVertexDAOIF)8 ServerGeoObjectType (net.geoprism.registry.model.ServerGeoObjectType)8 SimpleDateFormat (java.text.SimpleDateFormat)6 AbstractAction (net.geoprism.registry.action.AbstractAction)6 JsonArray (com.google.gson.JsonArray)5 JsonObject (com.google.gson.JsonObject)5 QueryFactory (com.runwaysdk.query.QueryFactory)5 TreeSet (java.util.TreeSet)5 ChangeRequestQuery (net.geoprism.registry.action.ChangeRequestQuery)5