use of org.apache.chemistry.opencmis.commons.exceptions.CmisUpdateConflictException in project alfresco-remote-api by Alfresco.
the class TestCMIS method testScenario1.
/**
* Tests CMIS and non-CMIS public api interactions
*/
@SuppressWarnings("deprecation")
@Test
public void testScenario1() throws Exception {
final TestNetwork network1 = getTestFixture().getRandomNetwork();
Iterator<String> personIt = network1.getPersonIds().iterator();
final String person = personIt.next();
assertNotNull(person);
Sites sitesProxy = publicApiClient.sites();
Comments commentsProxy = publicApiClient.comments();
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person));
CmisSession cmisSession = publicApiClient.createPublicApiCMISSession(Binding.atom, CMIS_VERSION_10, AlfrescoObjectFactoryImpl.class.getName());
ListResponse<MemberOfSite> sites = sitesProxy.getPersonSites(person, null);
assertTrue(sites.getList().size() > 0);
MemberOfSite siteMember = sites.getList().get(0);
String siteId = siteMember.getSite().getSiteId();
Folder documentLibrary = (Folder) cmisSession.getObjectByPath("/Sites/" + siteId + "/documentLibrary");
System.out.println("documentLibrary id = " + documentLibrary.getId());
Map<String, String> fileProps = new HashMap<String, String>();
{
fileProps.put(PropertyIds.OBJECT_TYPE_ID, TYPE_CMIS_DOCUMENT);
fileProps.put(PropertyIds.NAME, "mydoc-" + GUID.generate() + ".txt");
}
ContentStreamImpl fileContent = new ContentStreamImpl();
{
ContentWriter writer = new FileContentWriter(TempFileProvider.createTempFile(GUID.generate(), ".txt"));
writer.putContent("Ipsum and so on");
ContentReader reader = writer.getReader();
fileContent.setMimeType(MimetypeMap.MIMETYPE_TEXT_PLAIN);
fileContent.setStream(reader.getContentInputStream());
}
Document doc = documentLibrary.createDocument(fileProps, fileContent, VersioningState.MAJOR);
System.out.println("Document id = " + doc.getId());
Comment c = commentsProxy.createNodeComment(doc.getId(), new Comment("comment title 1", "comment 1"));
System.out.println("Comment = " + c);
// Now lock the document
String nodeRefStr = (String) doc.getPropertyValue("alfcmis:nodeRef");
final NodeRef nodeRef = new NodeRef(nodeRefStr);
final TenantRunAsWork<Void> runAsWork = new TenantRunAsWork<Void>() {
@Override
public Void doWork() throws Exception {
lockService.lock(nodeRef, LockType.WRITE_LOCK);
return null;
}
};
RetryingTransactionCallback<Void> txnWork = new RetryingTransactionCallback<Void>() {
@Override
public Void execute() throws Throwable {
TenantUtil.runAsUserTenant(runAsWork, "bob", network1.getId());
return null;
}
};
transactionHelper.doInTransaction(txnWork);
// Now attempt to update the document's metadata
try {
doc.delete();
} catch (CmisUpdateConflictException e) {
// Expected: ACE-762 BM-0012: NodeLockedException not handled by CMIS
}
}
use of org.apache.chemistry.opencmis.commons.exceptions.CmisUpdateConflictException in project copper-cms by PogeyanOSS.
the class ChangeTokenTest method runAddChildFolderTest.
private void runAddChildFolderTest(Session session, Folder testFolder) {
Folder folder = createFolder(session, testFolder, "folder1");
try {
if (folder.getChangeToken() == null) {
addResult(createResult(SKIPPED, "Repository does not provide change tokens for folders. Test skipped!"));
return;
}
if (!folder.getAllowableActions().getAllowableActions().contains(Action.CAN_UPDATE_PROPERTIES)) {
addResult(createResult(SKIPPED, "Folder name can't be changed. Test skipped!"));
return;
}
createDocument(session, folder, "doc1", "content");
try {
Map<String, Object> properties2 = new HashMap<String, Object>();
properties2.put(PropertyIds.NAME, "folder2");
folder.updateProperties(properties2, false);
} catch (CmisUpdateConflictException e) {
addResult(createResult(WARNING, "Adding a child to a folder changes the change token of the folder. " + "CMIS clients might not expect that."));
}
} finally {
deleteObject(folder);
}
}
Aggregations