Search in sources :

Example 1 with BulkUpdateObjectIdAndChangeToken

use of org.apache.chemistry.opencmis.commons.data.BulkUpdateObjectIdAndChangeToken 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)

Example 2 with BulkUpdateObjectIdAndChangeToken

use of org.apache.chemistry.opencmis.commons.data.BulkUpdateObjectIdAndChangeToken in project copper-cms by PogeyanOSS.

the class BulkUpdatePropertiesTest method run.

@Override
public void run(Session session) {
    if (session.getRepositoryInfo().getCmisVersion() == CmisVersion.CMIS_1_0) {
        addResult(createResult(SKIPPED, "Bulk Update Properties is not supported by CMIS 1.0. Test skipped!"));
        return;
    }
    CmisTestResult failure = null;
    int numOfObjects = 20;
    // create a test folder
    Folder testFolder = createTestFolder(session);
    try {
        Map<String, Folder> folders = new HashMap<String, Folder>();
        Map<String, Document> documents = new HashMap<String, Document>();
        // create folders and documents
        for (int i = 0; i < numOfObjects; i++) {
            Folder newFolder = createFolder(session, testFolder, "bufolder" + i);
            folders.put(newFolder.getId(), newFolder);
            Document newDocument = createDocument(session, newFolder, "budoc" + i + ".txt", CONTENT);
            documents.put(newDocument.getId(), newDocument);
        }
        // update cmis:name of all the documents
        List<CmisObject> objects = new ArrayList<CmisObject>(documents.values());
        Map<String, Object> properties = new HashMap<String, Object>();
        properties.put(PropertyIds.NAME, NEW_NAME);
        List<BulkUpdateObjectIdAndChangeToken> updatedIds = session.bulkUpdateProperties(objects, properties, null, null);
        // check the result
        if (getBinding() == BindingType.WEBSERVICES) {
            // TODO: review after TC clarification
            addResult(createResult(INFO, "The Web Services binding does not return the updated ids." + " This issue has to be clarified by the CMIS TC and the test to adopted later."));
        } else {
            if (updatedIds == null || updatedIds.isEmpty()) {
                addResult(createResult(FAILURE, "Bulk Update Properties did not update any documents!"));
            } else {
                failure = createResult(FAILURE, "Bulk Update Properties did not update all test documents!");
                addResult(assertEquals(documents.size(), updatedIds.size(), null, failure));
            }
        }
        // check all documents
        for (Folder folder : folders.values()) {
            List<CmisObject> children = new ArrayList<CmisObject>();
            for (CmisObject child : folder.getChildren(SELECT_ALL_NO_CACHE_OC)) {
                children.add(child);
            }
            if (children.size() != 1) {
                addResult(createResult(FAILURE, "Test folder should have exactly one child, but it has " + children.size() + "!"));
            } else {
                failure = createResult(FAILURE, "Document does not have the new name! Id: " + children.get(0).getId());
                addResult(assertEquals(NEW_NAME, children.get(0).getName(), null, failure));
            }
        }
        // delete folders and documents
        for (Folder folder : folders.values()) {
            folder.deleteTree(true, null, true);
        }
    } finally {
        // delete the test folder
        deleteTestFolder();
    }
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Folder(org.apache.chemistry.opencmis.client.api.Folder) Document(org.apache.chemistry.opencmis.client.api.Document) BulkUpdateObjectIdAndChangeToken(org.apache.chemistry.opencmis.commons.data.BulkUpdateObjectIdAndChangeToken) CmisTestResult(org.apache.chemistry.opencmis.tck.CmisTestResult) CmisObject(org.apache.chemistry.opencmis.client.api.CmisObject) CmisObject(org.apache.chemistry.opencmis.client.api.CmisObject)

Example 3 with BulkUpdateObjectIdAndChangeToken

use of org.apache.chemistry.opencmis.commons.data.BulkUpdateObjectIdAndChangeToken in project structr by structr.

the class CMISObjectService method bulkUpdateProperties.

@Override
public List<BulkUpdateObjectIdAndChangeToken> bulkUpdateProperties(final String repositoryId, final List<BulkUpdateObjectIdAndChangeToken> objectIdsAndChangeTokens, final Properties properties, final List<String> addSecondaryTypeIds, final List<String> removeSecondaryTypeIds, final ExtensionsData extension) {
    final List<BulkUpdateObjectIdAndChangeToken> result = new LinkedList<>();
    final App app = StructrApp.getInstance(securityContext);
    try (final Tx tx = app.tx()) {
        for (final BulkUpdateObjectIdAndChangeToken token : objectIdsAndChangeTokens) {
            final AbstractNode obj = app.get(AbstractNode.class, token.getId());
            if (obj != null) {
                final PropertyMap propertyMap = PropertyMap.cmisTypeToJavaType(securityContext, obj.getClass(), properties);
                if (propertyMap != null) {
                    obj.setProperties(securityContext, propertyMap);
                }
                result.add(token);
            }
        }
        tx.success();
    } catch (FrameworkException fex) {
        throw new CmisConstraintException(fex.getMessage(), fex);
    }
    return result;
}
Also used : App(org.structr.core.app.App) StructrApp(org.structr.core.app.StructrApp) BulkUpdateObjectIdAndChangeToken(org.apache.chemistry.opencmis.commons.data.BulkUpdateObjectIdAndChangeToken) PropertyMap(org.structr.core.property.PropertyMap) Tx(org.structr.core.graph.Tx) FrameworkException(org.structr.common.error.FrameworkException) AbstractNode(org.structr.core.entity.AbstractNode) CmisConstraintException(org.apache.chemistry.opencmis.commons.exceptions.CmisConstraintException) LinkedList(java.util.LinkedList)

Example 4 with BulkUpdateObjectIdAndChangeToken

use of org.apache.chemistry.opencmis.commons.data.BulkUpdateObjectIdAndChangeToken in project alfresco-remote-api by Alfresco.

the class BulkUpdatePropertiesCustomTest method run.

@Override
public void run(Session session) {
    if (session.getRepositoryInfo().getCmisVersion() == CmisVersion.CMIS_1_0) {
        addResult(createResult(SKIPPED, "Bulk Update Properties is not supported by CMIS 1.0. Test skipped!"));
        return;
    }
    CmisTestResult failure = null;
    int numOfObjects = 25;
    // create a test folder
    Folder testFolder = createTestFolder(session);
    try {
        Map<String, Folder> folders = new HashMap<String, Folder>();
        Map<String, Document> documents = new HashMap<String, Document>();
        // create folders and documents
        for (int i = 0; i < numOfObjects; i++) {
            Folder newFolder = createFolder(session, testFolder, "bufolder" + i);
            folders.put(newFolder.getId(), newFolder);
            Document newDocument = createDocument(session, newFolder, "budoc" + i + ".txt", CONTENT);
            documents.put(newDocument.getId(), newDocument);
        }
        // update cmis:description of all the documents
        List<CmisObject> objects = new ArrayList<CmisObject>(documents.values());
        Map<String, Object> properties = new HashMap<String, Object>();
        properties.put(PropertyIds.DESCRIPTION, NEW_DESCRIPTION_VALUE);
        List<BulkUpdateObjectIdAndChangeToken> updatedIds = session.bulkUpdateProperties(objects, properties, null, null);
        // check the result
        if (getBinding() == BindingType.WEBSERVICES) {
            addResult(createResult(INFO, "The Web Services binding does not return the updated ids." + " This issue has to be clarified by the CMIS TC and the test to adopted later."));
        } else {
            if (updatedIds == null || updatedIds.isEmpty()) {
                addResult(createResult(FAILURE, "Bulk Update Properties did not update any documents!"));
            } else {
                failure = createResult(FAILURE, "Bulk Update Properties did not update all test documents!");
                addResult(assertEquals(documents.size(), updatedIds.size(), null, failure));
            }
        }
        // check all documents
        for (Folder folder : folders.values()) {
            List<CmisObject> children = new ArrayList<CmisObject>();
            for (CmisObject child : folder.getChildren(SELECT_ALL_NO_CACHE_OC)) {
                children.add(child);
            }
            if (children.size() != 1) {
                String errorMessage = "Test folder should have exactly one child, but it has " + children.size() + "!";
                addResult(createResult(FAILURE, errorMessage));
            } else {
                failure = createResult(FAILURE, "Document does not have the new description! Id: " + children.get(0).getId());
                addResult(assertEquals(NEW_DESCRIPTION_VALUE, children.get(0).getDescription(), null, failure));
            }
        }
        // delete folders and documents
        for (Folder folder : folders.values()) {
            folder.deleteTree(true, null, true);
        }
    } finally {
        // delete the test folder
        deleteTestFolder();
    }
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Folder(org.apache.chemistry.opencmis.client.api.Folder) Document(org.apache.chemistry.opencmis.client.api.Document) BulkUpdateObjectIdAndChangeToken(org.apache.chemistry.opencmis.commons.data.BulkUpdateObjectIdAndChangeToken) CmisTestResult(org.apache.chemistry.opencmis.tck.CmisTestResult) CmisObject(org.apache.chemistry.opencmis.client.api.CmisObject) CmisObject(org.apache.chemistry.opencmis.client.api.CmisObject)

Aggregations

BulkUpdateObjectIdAndChangeToken (org.apache.chemistry.opencmis.commons.data.BulkUpdateObjectIdAndChangeToken)4 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)2 CmisObject (org.apache.chemistry.opencmis.client.api.CmisObject)2 Document (org.apache.chemistry.opencmis.client.api.Document)2 Folder (org.apache.chemistry.opencmis.client.api.Folder)2 CmisTestResult (org.apache.chemistry.opencmis.tck.CmisTestResult)2 LinkedList (java.util.LinkedList)1 Properties (org.apache.chemistry.opencmis.commons.data.Properties)1 CmisConstraintException (org.apache.chemistry.opencmis.commons.exceptions.CmisConstraintException)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 FrameworkException (org.structr.common.error.FrameworkException)1 App (org.structr.core.app.App)1 StructrApp (org.structr.core.app.StructrApp)1 AbstractNode (org.structr.core.entity.AbstractNode)1 Tx (org.structr.core.graph.Tx)1 PropertyMap (org.structr.core.property.PropertyMap)1