Search in sources :

Example 1 with CmisUpdateConflictException

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
    }
}
Also used : ContentStreamImpl(org.apache.chemistry.opencmis.commons.impl.dataobjects.ContentStreamImpl) HashMap(java.util.HashMap) CmisUpdateConflictException(org.apache.chemistry.opencmis.commons.exceptions.CmisUpdateConflictException) MemberOfSite(org.alfresco.rest.api.tests.client.data.MemberOfSite) AlfrescoFolder(org.alfresco.cmis.client.AlfrescoFolder) Folder(org.apache.chemistry.opencmis.client.api.Folder) AlfrescoDocument(org.alfresco.cmis.client.AlfrescoDocument) Document(org.apache.chemistry.opencmis.client.api.Document) NodeRef(org.alfresco.service.cmr.repository.NodeRef) RequestContext(org.alfresco.rest.api.tests.client.RequestContext) Comment(org.alfresco.rest.api.tests.client.data.Comment) AlfrescoObjectFactoryImpl(org.alfresco.cmis.client.impl.AlfrescoObjectFactoryImpl) CmisSession(org.alfresco.rest.api.tests.client.PublicApiClient.CmisSession) Comments(org.alfresco.rest.api.tests.client.PublicApiClient.Comments) FileContentWriter(org.alfresco.repo.content.filestore.FileContentWriter) ContentReader(org.alfresco.service.cmr.repository.ContentReader) Sites(org.alfresco.rest.api.tests.client.PublicApiClient.Sites) ContentWriter(org.alfresco.service.cmr.repository.ContentWriter) FileContentWriter(org.alfresco.repo.content.filestore.FileContentWriter) RetryingTransactionCallback(org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback) TenantRunAsWork(org.alfresco.repo.tenant.TenantUtil.TenantRunAsWork) TestNetwork(org.alfresco.rest.api.tests.RepoService.TestNetwork) VersionableAspectTest(org.alfresco.repo.version.VersionableAspectTest) Test(org.junit.Test)

Example 2 with CmisUpdateConflictException

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);
    }
}
Also used : HashMap(java.util.HashMap) CmisUpdateConflictException(org.apache.chemistry.opencmis.commons.exceptions.CmisUpdateConflictException) Folder(org.apache.chemistry.opencmis.client.api.Folder)

Aggregations

HashMap (java.util.HashMap)2 Folder (org.apache.chemistry.opencmis.client.api.Folder)2 CmisUpdateConflictException (org.apache.chemistry.opencmis.commons.exceptions.CmisUpdateConflictException)2 AlfrescoDocument (org.alfresco.cmis.client.AlfrescoDocument)1 AlfrescoFolder (org.alfresco.cmis.client.AlfrescoFolder)1 AlfrescoObjectFactoryImpl (org.alfresco.cmis.client.impl.AlfrescoObjectFactoryImpl)1 FileContentWriter (org.alfresco.repo.content.filestore.FileContentWriter)1 TenantRunAsWork (org.alfresco.repo.tenant.TenantUtil.TenantRunAsWork)1 RetryingTransactionCallback (org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback)1 VersionableAspectTest (org.alfresco.repo.version.VersionableAspectTest)1 TestNetwork (org.alfresco.rest.api.tests.RepoService.TestNetwork)1 CmisSession (org.alfresco.rest.api.tests.client.PublicApiClient.CmisSession)1 Comments (org.alfresco.rest.api.tests.client.PublicApiClient.Comments)1 Sites (org.alfresco.rest.api.tests.client.PublicApiClient.Sites)1 RequestContext (org.alfresco.rest.api.tests.client.RequestContext)1 Comment (org.alfresco.rest.api.tests.client.data.Comment)1 MemberOfSite (org.alfresco.rest.api.tests.client.data.MemberOfSite)1 ContentReader (org.alfresco.service.cmr.repository.ContentReader)1 ContentWriter (org.alfresco.service.cmr.repository.ContentWriter)1 NodeRef (org.alfresco.service.cmr.repository.NodeRef)1