Search in sources :

Example 1 with BulkUpdateObjectIdAndChangeTokenImpl

use of org.apache.chemistry.opencmis.commons.impl.dataobjects.BulkUpdateObjectIdAndChangeTokenImpl in project copper-cms by PogeyanOSS.

the class ObjectActor method bulkUpdate.

private JSONArray bulkUpdate(PostRequest request) throws CmisInvalidArgumentException, CmisRuntimeException {
    // get object ids and change tokens
    String permission = request.getUserObject().getPermission();
    if (!Helpers.checkingUserPremission(permission, "post")) {
        throw new CmisRuntimeException(request.getUserName() + " is not authorized to applyAcl.");
    }
    List<BulkUpdateObjectIdAndChangeToken> objectIdAndChangeToken = new ArrayList<BulkUpdateObjectIdAndChangeToken>();
    List<String> objectIds = request.getObjectIds();
    List<String> changeTokens = request.getChangeTokens();
    if (CmisPropertyConverter.Impl.isNullOrEmpty(objectIds)) {
        throw new CmisInvalidArgumentException("No object ids provided!");
    }
    int n = objectIds.size();
    for (int i = 0; i < n; i++) {
        String id = objectIds.get(i);
        String changeToken = (changeTokens != null && changeTokens.size() > i ? changeTokens.get(i) : null);
        if (changeToken != null && changeToken.length() == 0) {
            changeToken = null;
        }
        objectIdAndChangeToken.add(new BulkUpdateObjectIdAndChangeTokenImpl(id, changeToken));
    }
    // get secondary type ids
    List<String> addSecondaryTypes = request.getAddSecondaryTypes();
    List<String> removeSecondaryTypes = request.getRemoveSecondaryTypes();
    Properties properties = CmisPropertyConverter.Impl.createUpdateProperties(request.getPropertyData(), null, addSecondaryTypes, objectIds, request.getRepositoryId(), null);
    List<BulkUpdateObjectIdAndChangeToken> result = CmisObjectService.Impl.bulkUpdateProperties(request.getRepositoryId(), objectIdAndChangeToken, properties, addSecondaryTypes, removeSecondaryTypes, null, request.getUserObject());
    // return result
    JSONArray jsonList = new JSONArray();
    if (result != null) {
        for (BulkUpdateObjectIdAndChangeToken oc : result) {
            if (oc != null) {
                jsonList.add(JSONConverter.convert(oc));
            }
        }
    }
    return jsonList;
}
Also used : BulkUpdateObjectIdAndChangeToken(org.apache.chemistry.opencmis.commons.data.BulkUpdateObjectIdAndChangeToken) CmisRuntimeException(org.apache.chemistry.opencmis.commons.exceptions.CmisRuntimeException) BulkUpdateObjectIdAndChangeTokenImpl(org.apache.chemistry.opencmis.commons.impl.dataobjects.BulkUpdateObjectIdAndChangeTokenImpl) ArrayList(java.util.ArrayList) CmisInvalidArgumentException(org.apache.chemistry.opencmis.commons.exceptions.CmisInvalidArgumentException) JSONArray(org.apache.chemistry.opencmis.commons.impl.json.JSONArray) Properties(org.apache.chemistry.opencmis.commons.data.Properties)

Aggregations

ArrayList (java.util.ArrayList)1 BulkUpdateObjectIdAndChangeToken (org.apache.chemistry.opencmis.commons.data.BulkUpdateObjectIdAndChangeToken)1 Properties (org.apache.chemistry.opencmis.commons.data.Properties)1 CmisInvalidArgumentException (org.apache.chemistry.opencmis.commons.exceptions.CmisInvalidArgumentException)1 CmisRuntimeException (org.apache.chemistry.opencmis.commons.exceptions.CmisRuntimeException)1 BulkUpdateObjectIdAndChangeTokenImpl (org.apache.chemistry.opencmis.commons.impl.dataobjects.BulkUpdateObjectIdAndChangeTokenImpl)1 JSONArray (org.apache.chemistry.opencmis.commons.impl.json.JSONArray)1