Search in sources :

Example 21 with ChangeRequest

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

the class UpdateAttributeAction method execute.

@Override
public void execute() {
    ChangeRequest cr = this.getAllRequest().next();
    ServerGeoObjectType type = ServerGeoObjectType.get(cr.getGeoObjectTypeCode());
    VertexServerGeoObject go = new VertexGeoObjectStrategy(type).getGeoObjectByCode(cr.getGeoObjectCode());
    AbstractUpdateAttributeView view = UpdateAttributeViewJsonAdapters.deserialize(this.getJson(), this.getAttributeName(), type);
    view.execute(go);
    if (!this.getAttributeName().equals(UpdateAttributeViewJsonAdapters.PARENT_ATTR_NAME)) {
        String attributeName = this.getAttributeName();
        if (attributeName.equals("geometry")) {
            attributeName = go.getGeometryAttributeName();
        }
        ValueOverTimeCollection votc = go.getValuesOverTime(attributeName);
        votc.reorder();
        go.apply(false);
    }
}
Also used : VertexGeoObjectStrategy(net.geoprism.registry.conversion.VertexGeoObjectStrategy) ServerGeoObjectType(net.geoprism.registry.model.ServerGeoObjectType) ValueOverTimeCollection(com.runwaysdk.dataaccess.graph.attributes.ValueOverTimeCollection) AbstractUpdateAttributeView(net.geoprism.registry.view.action.AbstractUpdateAttributeView) VertexServerGeoObject(net.geoprism.registry.model.graph.VertexServerGeoObject) ChangeRequest(net.geoprism.registry.action.ChangeRequest)

Example 22 with ChangeRequest

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

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

the class ServerGeoObjectService method updateGeoObjectInTrans.

@Transaction
public JsonObject updateGeoObjectInTrans(String geoObjectCode, String geoObjectTypeCode, String actions, String masterListId, String notes) {
    final RolePermissionService perms = ServiceFactory.getRolePermissionService();
    final ServerGeoObjectType type = ServerGeoObjectType.get(geoObjectTypeCode);
    final String orgCode = type.getOrganization().getCode();
    final VertexServerGeoObject go = (VertexServerGeoObject) new ServerGeoObjectService().getGeoObjectByCode(geoObjectCode, geoObjectTypeCode);
    final JsonArray jaActions = JsonParser.parseString(actions).getAsJsonArray();
    if (perms.isSRA() || perms.isRA(orgCode) || perms.isRM(orgCode, type)) {
        this.executeActions(type, go, jaActions);
        if (masterListId != null) {
            ListTypeVersion.get(masterListId).updateRecord(go);
        }
        JsonObject resp = new JsonObject();
        resp.addProperty("isChangeRequest", false);
        resp.add("geoObject", go.toGeoObjectOverTime().toJSON(ServiceFactory.getRegistryService().serializer(Session.getCurrentSession().getOid())));
        return resp;
    } else if (ServiceFactory.getRolePermissionService().isRC(orgCode, type)) {
        ChangeRequest request = createChangeRequest(geoObjectCode, geoObjectTypeCode, notes, orgCode, jaActions);
        JsonObject resp = new JsonObject();
        resp.addProperty("isChangeRequest", true);
        resp.addProperty("changeRequestId", request.getOid());
        return resp;
    } else {
        throw new CGRPermissionException();
    }
}
Also used : RolePermissionService(net.geoprism.registry.permission.RolePermissionService) JsonArray(com.google.gson.JsonArray) CGRPermissionException(net.geoprism.registry.CGRPermissionException) ServerGeoObjectType(net.geoprism.registry.model.ServerGeoObjectType) JsonObject(com.google.gson.JsonObject) VertexServerGeoObject(net.geoprism.registry.model.graph.VertexServerGeoObject) ChangeRequest(net.geoprism.registry.action.ChangeRequest) Transaction(com.runwaysdk.dataaccess.transaction.Transaction)

Example 24 with ChangeRequest

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

the class ServerGeoObjectService method createChangeRequest.

public ChangeRequest createChangeRequest(String geoObjectCode, String geoObjectTypeCode, String notes, final String orgCode, final JsonArray jaActions) {
    Instant base = Instant.now();
    int sequence = 0;
    ChangeRequest request = new ChangeRequest();
    request.addApprovalStatus(AllGovernanceStatus.PENDING);
    request.setContributorNotes(notes);
    request.setGeoObjectCode(geoObjectCode);
    request.setGeoObjectTypeCode(geoObjectTypeCode);
    request.setOrganizationCode(orgCode);
    request.apply();
    for (int i = 0; i < jaActions.size(); ++i) {
        JsonObject joAction = jaActions.get(i).getAsJsonObject();
        String attributeName = joAction.get("attributeName").getAsString();
        JsonObject attributeDiff = joAction.get("attributeDiff").getAsJsonObject();
        UpdateAttributeAction action = new UpdateAttributeAction();
        action.addApprovalStatus(AllGovernanceStatus.PENDING);
        action.setCreateActionDate(Date.from(base.plus(sequence++, ChronoUnit.MINUTES)));
        action.setAttributeName(attributeName);
        action.setJson(attributeDiff.toString());
        action.setApiVersion(CGRAdapterProperties.getApiVersion());
        action.setContributorNotes(notes);
        action.apply();
        request.addAction(action).apply();
    }
    return request;
}
Also used : Instant(java.time.Instant) JsonObject(com.google.gson.JsonObject) ChangeRequest(net.geoprism.registry.action.ChangeRequest) UpdateAttributeAction(net.geoprism.registry.action.geoobject.UpdateAttributeAction)

Example 25 with ChangeRequest

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

the class ChangeRequestService method getAllRequests.

@SuppressWarnings({ "unchecked", "rawtypes" })
@Request(RequestType.SESSION)
public Page<ChangeRequest> getAllRequests(String sessionId, int pageSize, int pageNumber, String filter, String sort, String oid) {
    ChangeRequestQuery query = new ChangeRequestQuery(new QueryFactory());
    if (filter != null && filter.length() > 0 && !filter.equals("ALL")) {
        query.WHERE(query.getApprovalStatus().containsAll(AllGovernanceStatus.valueOf(filter)));
    }
    filterQueryBasedOnPermissions(query);
    if (oid != null && oid.length() > 0) {
        pageNumber = this.findPageNumber(oid, query, pageSize);
    }
    query.restrictRows(pageSize, pageNumber);
    if (sort != null && sort.length() > 0 && sort != "[]") {
        JsonArray ja = JsonParser.parseString(sort).getAsJsonArray();
        for (int i = 0; i < ja.size(); ++i) {
            JsonObject jo = ja.get(i).getAsJsonObject();
            boolean ascending = jo.get("ascending").getAsBoolean();
            String attribute = jo.get("attribute").getAsString();
            Selectable sel = query.get(attribute);
            if (attribute.equals(ChangeRequest.GEOOBJECTLABEL) || attribute.equals(ChangeRequest.GEOOBJECTTYPELABEL)) {
                sel = ((AttributeLocal) sel).localize();
            } else if (attribute.equals(ChangeRequest.APPROVALSTATUS)) {
                sel = query.getApprovalStatus().getEnumName();
            }
            query.ORDER_BY(sel, ascending ? SortOrder.ASC : SortOrder.DESC);
        }
    } else {
        query.ORDER_BY_DESC(query.getCreateDate());
    }
    List<? extends ChangeRequest> list = query.getIterator().getAll();
    for (ChangeRequest cr : list) {
        if (!ServiceFactory.getMetadataCache().getGeoObjectType(cr.getGeoObjectTypeCode()).isPresent()) {
            cr.lock();
            cr.clearApprovalStatus();
            cr.addApprovalStatus(AllGovernanceStatus.INVALID);
            cr.apply();
        }
    }
    return new Page(query.getCount(), pageNumber, pageSize, list);
}
Also used : JsonArray(com.google.gson.JsonArray) QueryFactory(com.runwaysdk.query.QueryFactory) Selectable(com.runwaysdk.query.Selectable) ChangeRequestQuery(net.geoprism.registry.action.ChangeRequestQuery) JsonObject(com.google.gson.JsonObject) Page(net.geoprism.registry.view.Page) ChangeRequest(net.geoprism.registry.action.ChangeRequest) Request(com.runwaysdk.session.Request) ChangeRequest(net.geoprism.registry.action.ChangeRequest)

Aggregations

ChangeRequest (net.geoprism.registry.action.ChangeRequest)38 Request (com.runwaysdk.session.Request)21 Date (java.util.Date)16 UpdateAttributeAction (net.geoprism.registry.action.geoobject.UpdateAttributeAction)14 JsonObject (com.google.gson.JsonObject)13 AbstractAction (net.geoprism.registry.action.AbstractAction)13 QueryFactory (com.runwaysdk.query.QueryFactory)12 ChangeRequestQuery (net.geoprism.registry.action.ChangeRequestQuery)12 JsonArray (com.google.gson.JsonArray)10 ValueOverTime (com.runwaysdk.dataaccess.graph.attributes.ValueOverTime)10 Transaction (com.runwaysdk.dataaccess.transaction.Transaction)10 VertexServerGeoObject (net.geoprism.registry.model.graph.VertexServerGeoObject)10 CGRPermissionException (net.geoprism.registry.CGRPermissionException)9 ValueOverTimeCollection (com.runwaysdk.dataaccess.graph.attributes.ValueOverTimeCollection)7 SimpleDateFormat (java.text.SimpleDateFormat)7 CreateGeoObjectAction (net.geoprism.registry.action.geoobject.CreateGeoObjectAction)7 UpdateAttributeActionBase (net.geoprism.registry.action.geoobject.UpdateAttributeActionBase)6 ServerGeoObjectIF (net.geoprism.registry.model.ServerGeoObjectIF)6 VaultFile (com.runwaysdk.system.VaultFile)4 ServerGeoObjectType (net.geoprism.registry.model.ServerGeoObjectType)4