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();
}
}
Aggregations