Search in sources :

Example 6 with AbstractAction

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

use of net.geoprism.registry.action.AbstractAction 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 8 with AbstractAction

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

the class ChangeRequestServiceTest method testUpdateGeoObjectTermCR_Verify.

@Request
private void testUpdateGeoObjectTermCR_Verify(String[] data) throws Exception {
    final String attrName = FastTestDataset.AT_RELIGION.getAttributeName();
    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(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());
    String classyId = ((Classifier) cambodia.getValue(attrName, newStartDate)).getOid();
    Assert.assertEquals(FastTestDataset.T_Islam.fetchClassifier().getOid(), classyId);
    Assert.assertEquals(classyId, vot1.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) Classifier(net.geoprism.ontology.Classifier) 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 9 with AbstractAction

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

the class CRAttributePatch method patchAllCRS.

private void patchAllCRS() {
    ChangeRequestQuery crq = new ChangeRequestQuery(new QueryFactory());
    logger.info("Updating [" + crq.getCount() + "] ChangeRequest records and patching in permissions info.");
    OIterator<? extends ChangeRequest> it = crq.getIterator();
    Outer: for (ChangeRequest cr : it) {
        String orgCode = null;
        String gotCode = null;
        String gotTypeCode = null;
        cr.appLock();
        boolean hasInvalidAction = false;
        OIterator<? extends AbstractAction> actionIt = cr.getAllAction();
        SetParentAction setParent = null;
        CreateGeoObjectAction createAction = null;
        for (AbstractAction action : actionIt) {
            if (action instanceof SetParentAction) {
                SetParentAction spa = ((SetParentAction) action);
                gotCode = spa.getChildCode();
                gotTypeCode = spa.getChildTypeCode();
                orgCode = Organization.getRootOrganizationCode(Universal.getByKey(gotTypeCode).getOwnerOid());
                setParent = (SetParentAction) action;
            } else if (action instanceof CreateGeoObjectAction) {
                CreateGeoObjectAction create = ((CreateGeoObjectAction) action);
                gotCode = GeoObjectOverTimeJsonAdapters.GeoObjectDeserializer.getCode(create.getGeoObjectJson());
                gotTypeCode = GeoObjectOverTimeJsonAdapters.GeoObjectDeserializer.getTypeCode(create.getGeoObjectJson());
                orgCode = Organization.getRootOrganizationCode(Universal.getByKey(gotTypeCode).getOwnerOid());
                createAction = (CreateGeoObjectAction) action;
            } else if (action instanceof UpdateGeoObjectAction) {
                UpdateGeoObjectAction update = ((UpdateGeoObjectAction) action);
                gotCode = GeoObjectOverTimeJsonAdapters.GeoObjectDeserializer.getCode(update.getGeoObjectJson());
                gotTypeCode = GeoObjectOverTimeJsonAdapters.GeoObjectDeserializer.getTypeCode(update.getGeoObjectJson());
                orgCode = Organization.getRootOrganizationCode(Universal.getByKey(gotTypeCode).getOwnerOid());
                hasInvalidAction = true;
            } else if (action instanceof UpdateAttributeAction) {
                continue Outer;
            } else {
                throw new UnsupportedOperationException("Unexpected action type [" + action.getType() + "].");
            }
        }
        if (setParent != null && createAction != null) {
            createAction.appLock();
            createAction.setParentJson(setParent.getJson());
            createAction.apply();
            setParent.delete();
        } else if (setParent != null || createAction != null) {
            // A set parent without a create (or vice versa)? This isn't supposed to exist
            cr.clearApprovalStatus();
            cr.addApprovalStatus(AllGovernanceStatus.INVALID);
        }
        cr.setOrganizationCode(orgCode);
        cr.setGeoObjectCode(gotCode);
        cr.setGeoObjectTypeCode(gotTypeCode);
        if (cr.getGovernanceStatus().equals(AllGovernanceStatus.PENDING) && hasInvalidAction) {
            cr.clearApprovalStatus();
            cr.addApprovalStatus(AllGovernanceStatus.INVALID);
        }
        cr.apply();
    }
}
Also used : CreateGeoObjectAction(net.geoprism.registry.action.geoobject.CreateGeoObjectAction) QueryFactory(com.runwaysdk.query.QueryFactory) UpdateGeoObjectAction(net.geoprism.registry.action.geoobject.UpdateGeoObjectAction) ChangeRequestQuery(net.geoprism.registry.action.ChangeRequestQuery) OIterator(com.runwaysdk.query.OIterator) SetParentAction(net.geoprism.registry.action.geoobject.SetParentAction) ChangeRequest(net.geoprism.registry.action.ChangeRequest) AbstractAction(net.geoprism.registry.action.AbstractAction) UpdateAttributeAction(net.geoprism.registry.action.geoobject.UpdateAttributeAction)

Example 10 with AbstractAction

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

the class ChangeRequestServiceTest method testUpdateGeoObjectCR_Verify.

@Request
private void testUpdateGeoObjectCR_Verify() {
    ChangeRequestQuery crq = new ChangeRequestQuery(new QueryFactory());
    Assert.assertEquals(1, crq.getCount());
    ChangeRequest cr = crq.getIterator().next();
    Assert.assertEquals(AllGovernanceStatus.PENDING.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());
}
Also used : QueryFactory(com.runwaysdk.query.QueryFactory) ChangeRequestQuery(net.geoprism.registry.action.ChangeRequestQuery) ChangeRequest(net.geoprism.registry.action.ChangeRequest) AbstractAction(net.geoprism.registry.action.AbstractAction) UpdateAttributeAction(net.geoprism.registry.action.geoobject.UpdateAttributeAction) Request(com.runwaysdk.session.Request) ChangeRequest(net.geoprism.registry.action.ChangeRequest)

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