Search in sources :

Example 1 with SetParentAction

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

Aggregations

OIterator (com.runwaysdk.query.OIterator)1 QueryFactory (com.runwaysdk.query.QueryFactory)1 AbstractAction (net.geoprism.registry.action.AbstractAction)1 ChangeRequest (net.geoprism.registry.action.ChangeRequest)1 ChangeRequestQuery (net.geoprism.registry.action.ChangeRequestQuery)1 CreateGeoObjectAction (net.geoprism.registry.action.geoobject.CreateGeoObjectAction)1 SetParentAction (net.geoprism.registry.action.geoobject.SetParentAction)1 UpdateAttributeAction (net.geoprism.registry.action.geoobject.UpdateAttributeAction)1 UpdateGeoObjectAction (net.geoprism.registry.action.geoobject.UpdateGeoObjectAction)1