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