Search in sources :

Example 1 with ObjectId

use of org.apache.chemistry.opencmis.client.api.ObjectId in project alfresco-remote-api by Alfresco.

the class TestCMIS method testMnt11631.

@Test
public void testMnt11631() throws Exception {
    final TestNetwork network = getTestFixture().getRandomNetwork();
    String username = String.format(TEST_USER_NAME_PATTERN, System.currentTimeMillis());
    PersonInfo personInfo = new PersonInfo(username, username, username, TEST_PASSWORD, null, null, null, null, null, null, null);
    TestPerson person = network.createUser(personInfo);
    String personId = person.getId();
    final String siteName = String.format(TEST_SITE_NAME_PATTERN, System.currentTimeMillis());
    TenantUtil.runAsUserTenant(new TenantRunAsWork<NodeRef>() {

        @Override
        public NodeRef doWork() throws Exception {
            SiteInformation siteInfo = new SiteInformation(siteName, siteName, siteName, SiteVisibility.PRIVATE);
            TestSite site = repoService.createSite(null, siteInfo);
            String name = GUID.generate();
            NodeRef folderNodeRef = repoService.createFolder(site.getContainerNodeRef(DOCUMENT_LIBRARY_CONTAINER_NAME), name);
            return folderNodeRef;
        }
    }, personId, network.getId());
    publicApiClient.setRequestContext(new RequestContext(network.getId(), personId));
    CmisSession cmisSession = publicApiClient.createPublicApiCMISSession(Binding.atom, CMIS_VERSION_11);
    Folder docLibrary = (Folder) cmisSession.getObjectByPath(String.format(DOCUMENT_LIBRARY_PATH_PATTERN, siteName));
    String name = String.format(TEST_DOCUMENT_NAME_PATTERN, GUID.generate());
    Map<String, Object> properties = new HashMap<String, Object>();
    properties.put(PropertyIds.OBJECT_TYPE_ID, TYPE_CMIS_DOCUMENT);
    properties.put(PropertyIds.NAME, name);
    ContentStreamImpl fileContent = new ContentStreamImpl();
    ByteArrayInputStream stream = new ByteArrayInputStream(GUID.generate().getBytes());
    fileContent.setMimeType(MimetypeMap.MIMETYPE_TEXT_PLAIN);
    fileContent.setStream(stream);
    Document doc = docLibrary.createDocument(properties, fileContent, VersioningState.MAJOR);
    ObjectId pwcId = doc.checkOut();
    Document pwc = (Document) cmisSession.getObject(pwcId.getId());
    assertIsPwcProperty(pwc, false);
    cmisSession = publicApiClient.createPublicApiCMISSession(Binding.atom, CMIS_VERSION_10);
    CmisObject pwc10 = cmisSession.getObject(pwc.getId());
    assertIsPwcProperty(pwc10, true);
}
Also used : ContentStreamImpl(org.apache.chemistry.opencmis.commons.impl.dataobjects.ContentStreamImpl) CmisSession(org.alfresco.rest.api.tests.client.PublicApiClient.CmisSession) HashMap(java.util.HashMap) ObjectId(org.apache.chemistry.opencmis.client.api.ObjectId) TestSite(org.alfresco.rest.api.tests.RepoService.TestSite) 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) CmisUpdateConflictException(org.apache.chemistry.opencmis.commons.exceptions.CmisUpdateConflictException) CmisConstraintException(org.apache.chemistry.opencmis.commons.exceptions.CmisConstraintException) CmisPermissionDeniedException(org.apache.chemistry.opencmis.commons.exceptions.CmisPermissionDeniedException) CmisInvalidArgumentException(org.apache.chemistry.opencmis.commons.exceptions.CmisInvalidArgumentException) PublicApiException(org.alfresco.rest.api.tests.client.PublicApiException) CmisObjectNotFoundException(org.apache.chemistry.opencmis.commons.exceptions.CmisObjectNotFoundException) NodeRef(org.alfresco.service.cmr.repository.NodeRef) SiteInformation(org.alfresco.rest.api.tests.RepoService.SiteInformation) ByteArrayInputStream(java.io.ByteArrayInputStream) TestNetwork(org.alfresco.rest.api.tests.RepoService.TestNetwork) FileableCmisObject(org.apache.chemistry.opencmis.client.api.FileableCmisObject) CmisObject(org.apache.chemistry.opencmis.client.api.CmisObject) FileableCmisObject(org.apache.chemistry.opencmis.client.api.FileableCmisObject) CmisObject(org.apache.chemistry.opencmis.client.api.CmisObject) RequestContext(org.alfresco.rest.api.tests.client.RequestContext) TestPerson(org.alfresco.rest.api.tests.RepoService.TestPerson) VersionableAspectTest(org.alfresco.repo.version.VersionableAspectTest) Test(org.junit.Test)

Example 2 with ObjectId

use of org.apache.chemistry.opencmis.client.api.ObjectId in project alfresco-remote-api by Alfresco.

the class TestCMIS method testCreationDate.

/**
 * MNT-12680
 * The creation date of version should be the same as creation date of the original node
 * @throws Exception
 */
@Test
public void testCreationDate() throws Exception {
    // create a site
    final TestNetwork network1 = getTestFixture().getRandomNetwork();
    String username = "user" + System.currentTimeMillis();
    PersonInfo personInfo = new PersonInfo(username, username, username, "password", null, null, null, null, null, null, null);
    TestPerson person1 = network1.createUser(personInfo);
    String person1Id = person1.getId();
    final String siteName = "site" + System.currentTimeMillis();
    TenantUtil.runAsUserTenant(new TenantRunAsWork<NodeRef>() {

        @Override
        public NodeRef doWork() throws Exception {
            SiteInformation siteInfo = new SiteInformation(siteName, siteName, siteName, SiteVisibility.PUBLIC);
            final TestSite site = network1.createSite(siteInfo);
            final NodeRef resNode = repoService.createDocument(site.getContainerNodeRef("documentLibrary"), "testdoc.txt", "Test Doc1 Title", "Test Doc1 Description", "Test Content");
            return resNode;
        }
    }, person1Id, network1.getId());
    // create a document
    publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1Id));
    CmisSession cmisSession = publicApiClient.createPublicApiCMISSession(Binding.atom, CMIS_VERSION_10, AlfrescoObjectFactoryImpl.class.getName());
    AlfrescoFolder docLibrary = (AlfrescoFolder) cmisSession.getObjectByPath("/Sites/" + siteName + "/documentLibrary");
    Map<String, String> properties = new HashMap<String, String>();
    {
        properties.put(PropertyIds.OBJECT_TYPE_ID, TYPE_CMIS_DOCUMENT);
        properties.put(PropertyIds.NAME, "mydoc-" + GUID.generate() + ".txt");
    }
    ContentStreamImpl fileContent = new ContentStreamImpl();
    {
        ContentWriter writer = new FileContentWriter(TempFileProvider.createTempFile(GUID.generate(), ".txt"));
        writer.putContent("some content");
        ContentReader reader = writer.getReader();
        fileContent.setMimeType(MimetypeMap.MIMETYPE_TEXT_PLAIN);
        fileContent.setStream(reader.getContentInputStream());
    }
    Document autoVersionedDoc = docLibrary.createDocument(properties, fileContent, VersioningState.MAJOR);
    String objectId = autoVersionedDoc.getId();
    String bareObjectId = stripCMISSuffix(objectId);
    // create versions
    for (int i = 0; i < 3; i++) {
        Document doc1 = (Document) cmisSession.getObject(bareObjectId);
        ObjectId pwcId = doc1.checkOut();
        Document pwc = (Document) cmisSession.getObject(pwcId.getId());
        ContentStreamImpl contentStream = new ContentStreamImpl();
        {
            ContentWriter writer = new FileContentWriter(TempFileProvider.createTempFile(GUID.generate(), ".txt"));
            writer.putContent(GUID.generate());
            ContentReader reader = writer.getReader();
            contentStream.setMimeType(MimetypeMap.MIMETYPE_TEXT_PLAIN);
            contentStream.setStream(reader.getContentInputStream());
        }
        pwc.checkIn(true, Collections.EMPTY_MAP, contentStream, "checkin " + i);
    }
    GregorianCalendar cDateFirst = cmisSession.getAllVersions(bareObjectId).get(0).getCreationDate();
    GregorianCalendar cDateSecond = cmisSession.getAllVersions(bareObjectId).get(2).getCreationDate();
    if (cDateFirst.before(cDateSecond) || cDateFirst.after(cDateSecond)) {
        fail("The creation date of version should be the same as creation date of the original node");
    }
}
Also used : ContentStreamImpl(org.apache.chemistry.opencmis.commons.impl.dataobjects.ContentStreamImpl) AlfrescoObjectFactoryImpl(org.alfresco.cmis.client.impl.AlfrescoObjectFactoryImpl) CmisSession(org.alfresco.rest.api.tests.client.PublicApiClient.CmisSession) HashMap(java.util.HashMap) ObjectId(org.apache.chemistry.opencmis.client.api.ObjectId) TestSite(org.alfresco.rest.api.tests.RepoService.TestSite) AlfrescoFolder(org.alfresco.cmis.client.AlfrescoFolder) FileContentWriter(org.alfresco.repo.content.filestore.FileContentWriter) ContentReader(org.alfresco.service.cmr.repository.ContentReader) GregorianCalendar(java.util.GregorianCalendar) AlfrescoDocument(org.alfresco.cmis.client.AlfrescoDocument) Document(org.apache.chemistry.opencmis.client.api.Document) CmisUpdateConflictException(org.apache.chemistry.opencmis.commons.exceptions.CmisUpdateConflictException) CmisConstraintException(org.apache.chemistry.opencmis.commons.exceptions.CmisConstraintException) CmisPermissionDeniedException(org.apache.chemistry.opencmis.commons.exceptions.CmisPermissionDeniedException) CmisInvalidArgumentException(org.apache.chemistry.opencmis.commons.exceptions.CmisInvalidArgumentException) PublicApiException(org.alfresco.rest.api.tests.client.PublicApiException) CmisObjectNotFoundException(org.apache.chemistry.opencmis.commons.exceptions.CmisObjectNotFoundException) NodeRef(org.alfresco.service.cmr.repository.NodeRef) ContentWriter(org.alfresco.service.cmr.repository.ContentWriter) FileContentWriter(org.alfresco.repo.content.filestore.FileContentWriter) SiteInformation(org.alfresco.rest.api.tests.RepoService.SiteInformation) TestNetwork(org.alfresco.rest.api.tests.RepoService.TestNetwork) RequestContext(org.alfresco.rest.api.tests.client.RequestContext) TestPerson(org.alfresco.rest.api.tests.RepoService.TestPerson) VersionableAspectTest(org.alfresco.repo.version.VersionableAspectTest) Test(org.junit.Test)

Example 3 with ObjectId

use of org.apache.chemistry.opencmis.client.api.ObjectId in project iaf by ibissource.

the class CmisSender method sendMessageForActionFetch.

private String sendMessageForActionFetch(String correlationID, String message, ParameterResolutionContext prc) throws SenderException, TimeOutException {
    Element queryElement = null;
    try {
        if (XmlUtils.isWellFormed(message, "cmis")) {
            queryElement = XmlUtils.buildElement(message);
        } else {
            queryElement = XmlUtils.buildElement("<cmis/>");
        }
    } catch (DomBuilderException e) {
        throw new SenderException(e);
    }
    String objectIdstr = XmlUtils.getChildTagAsString(queryElement, "objectId");
    String filter = XmlUtils.getChildTagAsString(queryElement, "filter");
    boolean includeAllowableActions = XmlUtils.getChildTagAsBoolean(queryElement, "includeAllowableActions");
    boolean includePolicies = XmlUtils.getChildTagAsBoolean(queryElement, "includePolicies");
    boolean includeAcl = XmlUtils.getChildTagAsBoolean(queryElement, "includeAcl");
    OperationContext operationContext = session.createOperationContext();
    if (StringUtils.isNotEmpty(filter))
        operationContext.setFilterString(filter);
    operationContext.setIncludeAllowableActions(includeAllowableActions);
    operationContext.setIncludePolicies(includePolicies);
    operationContext.setIncludeAcls(includeAcl);
    CmisObject object = null;
    try {
        object = session.getObject(session.createObjectId(objectIdstr), operationContext);
    } catch (CmisObjectNotFoundException e) {
        if (StringUtils.isNotEmpty(getResultOnNotFound())) {
            log.info(getLogPrefix() + "document with id [" + message + "] not found", e);
            return getResultOnNotFound();
        } else {
            throw new SenderException(e);
        }
    }
    XmlBuilder cmisXml = new XmlBuilder("cmis");
    XmlBuilder propertiesXml = new XmlBuilder("properties");
    for (Iterator it = object.getProperties().iterator(); it.hasNext(); ) {
        Property property = (Property) it.next();
        propertiesXml.addSubElement(getPropertyXml(property));
    }
    cmisXml.addSubElement(propertiesXml);
    XmlBuilder allowableActionsXml = new XmlBuilder("allowableActions");
    Set<Action> actions = object.getAllowableActions().getAllowableActions();
    for (Action action : actions) {
        XmlBuilder actionXml = new XmlBuilder("action");
        actionXml.setValue(action.value());
        allowableActionsXml.addSubElement(actionXml);
    }
    cmisXml.addSubElement(allowableActionsXml);
    XmlBuilder isExactAclXml = new XmlBuilder("isExactAcl");
    if (object.getAcl() != null)
        isExactAclXml.setValue(object.getAcl().isExact().toString());
    cmisXml.addSubElement(isExactAclXml);
    XmlBuilder policiesXml = new XmlBuilder("policyIds");
    List<ObjectId> policies = object.getPolicyIds();
    if (policies != null) {
        for (ObjectId objectId : policies) {
            XmlBuilder policyXml = new XmlBuilder("policyId");
            policyXml.setValue(objectId.getId());
            policiesXml.addSubElement(policyXml);
        }
    }
    cmisXml.addSubElement(policiesXml);
    XmlBuilder relationshipsXml = new XmlBuilder("relationships");
    List<Relationship> relationships = object.getRelationships();
    if (relationships != null) {
        for (Relationship relation : relationships) {
            XmlBuilder policyXml = new XmlBuilder("relation");
            policyXml.setValue(relation.getId());
            relationshipsXml.addSubElement(policyXml);
        }
    }
    cmisXml.addSubElement(relationshipsXml);
    return cmisXml.toXML();
}
Also used : OperationContext(org.apache.chemistry.opencmis.client.api.OperationContext) Action(org.apache.chemistry.opencmis.commons.enums.Action) ObjectId(org.apache.chemistry.opencmis.client.api.ObjectId) Element(org.w3c.dom.Element) CmisObjectNotFoundException(org.apache.chemistry.opencmis.commons.exceptions.CmisObjectNotFoundException) Relationship(org.apache.chemistry.opencmis.client.api.Relationship) Iterator(java.util.Iterator) XmlBuilder(nl.nn.adapterframework.util.XmlBuilder) CmisObject(org.apache.chemistry.opencmis.client.api.CmisObject) DomBuilderException(nl.nn.adapterframework.util.DomBuilderException) SenderException(nl.nn.adapterframework.core.SenderException) Property(org.apache.chemistry.opencmis.client.api.Property)

Example 4 with ObjectId

use of org.apache.chemistry.opencmis.client.api.ObjectId in project copper-cms by PogeyanOSS.

the class AbstractSessionTest method createRelationship.

/**
 * Creates a relationship.
 */
protected Relationship createRelationship(Session session, String name, ObjectId source, ObjectId target, String objectTypeId) {
    if (name == null) {
        throw new IllegalArgumentException("Name is not set!");
    }
    if (objectTypeId == null) {
        throw new IllegalArgumentException("Object Type ID is not set!");
    }
    // check type
    ObjectType type;
    try {
        type = session.getTypeDefinition(objectTypeId);
    } catch (CmisObjectNotFoundException e) {
        addResult(createResult(UNEXPECTED_EXCEPTION, "Relationship type '" + objectTypeId + "' is not available: " + e.getMessage(), e, true));
        return null;
    }
    if (Boolean.FALSE.equals(type.isCreatable())) {
        addResult(createResult(SKIPPED, "Relationship type '" + objectTypeId + "' is not creatable!", true));
        return null;
    }
    // create
    Map<String, Object> properties = new HashMap<String, Object>();
    properties.put(PropertyIds.NAME, name);
    properties.put(PropertyIds.OBJECT_TYPE_ID, objectTypeId);
    properties.put(PropertyIds.SOURCE_ID, source.getId());
    properties.put(PropertyIds.TARGET_ID, target.getId());
    ObjectId relId;
    Relationship result = null;
    try {
        relId = session.createRelationship(properties);
        result = (Relationship) session.getObject(relId, SELECT_ALL_NO_CACHE_OC);
    } catch (Exception e) {
        addResult(createResult(UNEXPECTED_EXCEPTION, "Relationship could not be created! Exception: " + e.getMessage(), e, true));
    }
    if (result != null) {
        try {
            // check the new relationship
            addResult(checkObject(session, result, getAllProperties(result), "New document object spec compliance"));
        } catch (CmisBaseException e) {
            addResult(createResult(UNEXPECTED_EXCEPTION, "Newly created document is invalid! Exception: " + e.getMessage(), e, true));
        }
    }
    return result;
}
Also used : ObjectType(org.apache.chemistry.opencmis.client.api.ObjectType) CmisObjectNotFoundException(org.apache.chemistry.opencmis.commons.exceptions.CmisObjectNotFoundException) HashMap(java.util.HashMap) ObjectId(org.apache.chemistry.opencmis.client.api.ObjectId) CmisBaseException(org.apache.chemistry.opencmis.commons.exceptions.CmisBaseException) Relationship(org.apache.chemistry.opencmis.client.api.Relationship) FileableCmisObject(org.apache.chemistry.opencmis.client.api.FileableCmisObject) CmisObject(org.apache.chemistry.opencmis.client.api.CmisObject) CmisObjectNotFoundException(org.apache.chemistry.opencmis.commons.exceptions.CmisObjectNotFoundException) CmisBaseException(org.apache.chemistry.opencmis.commons.exceptions.CmisBaseException) CmisNotSupportedException(org.apache.chemistry.opencmis.commons.exceptions.CmisNotSupportedException) IOException(java.io.IOException) CmisInvalidArgumentException(org.apache.chemistry.opencmis.commons.exceptions.CmisInvalidArgumentException)

Example 5 with ObjectId

use of org.apache.chemistry.opencmis.client.api.ObjectId in project copper-cms by PogeyanOSS.

the class ChangeTokenTest method runUpdateDocumentTest.

private void runUpdateDocumentTest(Session session, Folder testFolder) {
    Document doc = createDocument(session, testFolder, "update1.txt", "Hello World!");
    try {
        if (doc.getChangeToken() == null) {
            addResult(createResult(SKIPPED, "Repository does not provide change tokens for documents. Test skipped!"));
            return;
        }
        DocumentTypeDefinition type = (DocumentTypeDefinition) doc.getType();
        PropertyDefinition<?> namePropDef = type.getPropertyDefinitions().get(PropertyIds.NAME);
        if (namePropDef.getUpdatability() == Updatability.WHENCHECKEDOUT || !doc.getAllowableActions().getAllowableActions().contains(Action.CAN_UPDATE_PROPERTIES)) {
            addResult(createResult(SKIPPED, "Document name can't be changed. Test skipped!"));
            return;
        }
        // the first update should succeed
        Map<String, Object> properties2 = new HashMap<String, Object>();
        properties2.put(PropertyIds.NAME, "update2.txt");
        ObjectId newId = doc.updateProperties(properties2, false);
        if (!doc.getId().equals(newId.getId())) {
            // the repository created a new version
            // -> a change token test does not make sense
            addResult(createResult(INFO, "The repository created a new version. Change tokens are not relevant here."));
        } else {
            try {
                Map<String, Object> properties3 = new HashMap<String, Object>();
                properties3.put(PropertyIds.NAME, "update3.txt");
                doc.updateProperties(properties3, false);
                addResult(createResult(FAILURE, "Updating properties a second time with the same change token " + "should result in an UpdateConflict exception!"));
            // } catch (CmisUpdateConflictException e) {
            } catch (CmisConstraintException e) {
            // expected exception
            }
        }
    } finally {
        deleteObject(doc);
    }
}
Also used : DocumentTypeDefinition(org.apache.chemistry.opencmis.commons.definitions.DocumentTypeDefinition) HashMap(java.util.HashMap) ObjectId(org.apache.chemistry.opencmis.client.api.ObjectId) CmisConstraintException(org.apache.chemistry.opencmis.commons.exceptions.CmisConstraintException) Document(org.apache.chemistry.opencmis.client.api.Document)

Aggregations

ObjectId (org.apache.chemistry.opencmis.client.api.ObjectId)22 HashMap (java.util.HashMap)17 Document (org.apache.chemistry.opencmis.client.api.Document)17 Folder (org.apache.chemistry.opencmis.client.api.Folder)13 CmisTestResult (org.apache.chemistry.opencmis.tck.CmisTestResult)12 ContentStream (org.apache.chemistry.opencmis.commons.data.ContentStream)9 ByteArrayInputStream (java.io.ByteArrayInputStream)8 ContentStreamImpl (org.apache.chemistry.opencmis.commons.impl.dataobjects.ContentStreamImpl)8 CmisObject (org.apache.chemistry.opencmis.client.api.CmisObject)7 DocumentTypeDefinition (org.apache.chemistry.opencmis.commons.definitions.DocumentTypeDefinition)7 CmisObjectNotFoundException (org.apache.chemistry.opencmis.commons.exceptions.CmisObjectNotFoundException)7 CmisConstraintException (org.apache.chemistry.opencmis.commons.exceptions.CmisConstraintException)6 ArrayList (java.util.ArrayList)5 FileableCmisObject (org.apache.chemistry.opencmis.client.api.FileableCmisObject)5 CmisInvalidArgumentException (org.apache.chemistry.opencmis.commons.exceptions.CmisInvalidArgumentException)5 Map (java.util.Map)4 AlfrescoDocument (org.alfresco.cmis.client.AlfrescoDocument)4 AlfrescoFolder (org.alfresco.cmis.client.AlfrescoFolder)4 VersionableAspectTest (org.alfresco.repo.version.VersionableAspectTest)4 SiteInformation (org.alfresco.rest.api.tests.RepoService.SiteInformation)4