Search in sources :

Example 1 with UpdateGeoObjectAction

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

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

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

the class GovernanceTest method testActionSerialization.

/**
 * Tests serialization on the DTOs and also conversion to/from DTO
 */
@Test
public void testActionSerialization() {
    TestGeoObjectInfo testGo = FastTestDataset.CAMBODIA;
    // GeoObjectOverTime go = testGo.asGeoObject();
    GeoObjectOverTime goTime = testData.adapter.getGeoObjectOverTimeByCode(FastTestDataset.CAMBODIA.getCode(), FastTestDataset.CAMBODIA.getGeoObjectType().getCode());
    testGo.setRegistryId(goTime.getUid());
    /*
     * UpdateGeoObject
     */
    UpdateGeoObjectActionDTO updateDTO = new UpdateGeoObjectActionDTO();
    updateDTO.setGeoObject(goTime.toJSON());
    updateDTO.setCreateActionDate(Date.from(Instant.now().minus(6, ChronoUnit.HOURS)));
    updateDTO.setContributorNotes("UPDATE_CONTRIB_NOTES");
    updateDTO.setMaintainerNotes("UPDATE_MAINTAIN_NOTES");
    String updateJson = updateDTO.toJSON().toString();
    String updateJson2 = AbstractActionDTO.parseAction(updateJson).toJSON().toString();
    Assert.assertEquals(updateJson, updateJson2);
    UpdateGeoObjectAction updateRA = (UpdateGeoObjectAction) AbstractAction.dtoToRegistry(updateDTO);
    GeoObjectOverTime updateRAGO = GeoObjectOverTime.fromJSON(testData.adapter, updateRA.getGeoObjectJson());
    // testGo.assertEquals(updateRAGO);
    Assert.assertEquals(updateDTO.getContributorNotes(), updateRA.getContributorNotes());
    Assert.assertEquals(updateDTO.getMaintainerNotes(), updateRA.getMaintainerNotes());
    Assert.assertEquals(updateDTO.getApiVersion(), updateRA.getApiVersion());
// Assert.assertEquals(updateDTO.getCreateActionDate().getTime(),
// updateRA.getCreateActionDate().getTime()); // TODO : Runway dates are
// accurate to the second, but epoch is accurate to the milisecond.
/*
     * TODO : The rest of the supported actions
     */
}
Also used : UpdateGeoObjectActionDTO(org.commongeoregistry.adapter.action.geoobject.UpdateGeoObjectActionDTO) UpdateGeoObjectAction(net.geoprism.registry.action.geoobject.UpdateGeoObjectAction) GeoObjectOverTime(org.commongeoregistry.adapter.dataaccess.GeoObjectOverTime) TestGeoObjectInfo(net.geoprism.registry.test.TestGeoObjectInfo) Test(org.junit.Test)

Example 4 with UpdateGeoObjectAction

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

the class GovernanceTest method testUpdateAction.

@Test
public void testUpdateAction() {
    Date startDate = new Date();
    Date endDate = new Date();
    GeoObjectOverTime goTime = testData.adapter.getGeoObjectOverTimeByCode(FastTestDataset.CAMBODIA.getCode(), FastTestDataset.CAMBODIA.getGeoObjectType().getCode());
    goTime.setDisplayLabel(new LocalizedValue("test 123"), startDate, endDate);
    UpdateGeoObjectActionDTO updateDTO = new UpdateGeoObjectActionDTO();
    updateDTO.setGeoObject(goTime.toJSON());
    updateDTO.setCreateActionDate(Date.from(Instant.now().minus(6, ChronoUnit.HOURS)));
    updateDTO.setContributorNotes("UPDATE_CONTRIB_NOTES");
    updateDTO.setMaintainerNotes("UPDATE_MAINTAIN_NOTES");
    UpdateGeoObjectAction updateRA = (UpdateGeoObjectAction) AbstractAction.dtoToRegistry(updateDTO);
    execute(updateRA);
    GeoObjectOverTime goTime2 = testData.adapter.getGeoObjectOverTimeByCode(FastTestDataset.CAMBODIA.getCode(), FastTestDataset.CAMBODIA.getGeoObjectType().getCode());
    Assert.assertEquals("test 123", goTime2.getDisplayLabel(startDate).getValue());
}
Also used : UpdateGeoObjectActionDTO(org.commongeoregistry.adapter.action.geoobject.UpdateGeoObjectActionDTO) UpdateGeoObjectAction(net.geoprism.registry.action.geoobject.UpdateGeoObjectAction) LocalizedValue(org.commongeoregistry.adapter.dataaccess.LocalizedValue) GeoObjectOverTime(org.commongeoregistry.adapter.dataaccess.GeoObjectOverTime) Date(java.util.Date) Test(org.junit.Test)

Aggregations

UpdateGeoObjectAction (net.geoprism.registry.action.geoobject.UpdateGeoObjectAction)4 Date (java.util.Date)2 ChangeRequest (net.geoprism.registry.action.ChangeRequest)2 CreateGeoObjectAction (net.geoprism.registry.action.geoobject.CreateGeoObjectAction)2 UpdateGeoObjectActionDTO (org.commongeoregistry.adapter.action.geoobject.UpdateGeoObjectActionDTO)2 GeoObjectOverTime (org.commongeoregistry.adapter.dataaccess.GeoObjectOverTime)2 Test (org.junit.Test)2 Transaction (com.runwaysdk.dataaccess.transaction.Transaction)1 Endpoint (com.runwaysdk.mvc.Endpoint)1 OIterator (com.runwaysdk.query.OIterator)1 QueryFactory (com.runwaysdk.query.QueryFactory)1 Instant (java.time.Instant)1 AbstractAction (net.geoprism.registry.action.AbstractAction)1 ChangeRequestQuery (net.geoprism.registry.action.ChangeRequestQuery)1 SetParentAction (net.geoprism.registry.action.geoobject.SetParentAction)1 UpdateAttributeAction (net.geoprism.registry.action.geoobject.UpdateAttributeAction)1 ServerGeoObjectService (net.geoprism.registry.geoobject.ServerGeoObjectService)1 ServerGeoObjectIF (net.geoprism.registry.model.ServerGeoObjectIF)1 TestGeoObjectInfo (net.geoprism.registry.test.TestGeoObjectInfo)1 GeoObject (org.commongeoregistry.adapter.dataaccess.GeoObject)1