Search in sources :

Example 1 with ObjectType

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

the class TestCMIS method testCanConnectCMISUsingDefaultTenantImpl.

private void testCanConnectCMISUsingDefaultTenantImpl(Binding binding, String cmisVersion) {
    String url = httpClient.getPublicApiCmisUrl(TenantUtil.DEFAULT_TENANT, binding, cmisVersion, null);
    Map<String, String> parameters = new HashMap<String, String>();
    // user credentials
    parameters.put(SessionParameter.USER, "admin");
    parameters.put(SessionParameter.PASSWORD, "admin");
    parameters.put(SessionParameter.ATOMPUB_URL, url);
    parameters.put(SessionParameter.BROWSER_URL, url);
    parameters.put(SessionParameter.BINDING_TYPE, binding.getOpenCmisBinding().value());
    SessionFactory factory = SessionFactoryImpl.newInstance();
    // perform request : http://host:port/alfresco/api/-default-/public/cmis/versions/${cmisVersion}/${binding}
    List<Repository> repositories = factory.getRepositories(parameters);
    assertTrue(repositories.size() > 0);
    parameters.put(SessionParameter.REPOSITORY_ID, TenantUtil.DEFAULT_TENANT);
    Session session = factory.createSession(parameters);
    // perform request : http://host:port/alfresco/api/-default-/public/cmis/versions/${cmisVersion}/${binding}/type?id=cmis:document
    ObjectType objectType = session.getTypeDefinition("cmis:document");
    assertNotNull(objectType);
}
Also used : SessionFactory(org.apache.chemistry.opencmis.client.api.SessionFactory) ObjectType(org.apache.chemistry.opencmis.client.api.ObjectType) Repository(org.apache.chemistry.opencmis.client.api.Repository) HashMap(java.util.HashMap) CmisSession(org.alfresco.rest.api.tests.client.PublicApiClient.CmisSession) Session(org.apache.chemistry.opencmis.client.api.Session)

Example 2 with ObjectType

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

the class TestCMIS method testMNT10430.

@Test
public void testMNT10430() throws Exception {
    final TestNetwork network1 = getTestFixture().getRandomNetwork();
    String username = "user" + System.currentTimeMillis();
    PersonInfo personInfo = new PersonInfo(username, username, username, TEST_PASSWORD, null, null, null, null, null, null, null);
    TestPerson person1 = network1.createUser(personInfo);
    String person1Id = person1.getId();
    publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1Id));
    CmisSession cmisSession = publicApiClient.createPublicApiCMISSession(Binding.browser, CMIS_VERSION_11, AlfrescoObjectFactoryImpl.class.getName());
    ObjectType objectType = cmisSession.getTypeDefinition("D:testcmis:maDoc");
    // try and get the mandatory aspects
    List<String> mandatoryAspects = ((AlfrescoType) objectType).getMandatoryAspects();
    System.out.println("Mandatory Aspects");
    for (String mandatoryAspect : mandatoryAspects) {
        System.out.println(mandatoryAspect);
    }
    assertTrue("The aspects should have P:cm:generalclassifiable", mandatoryAspects.contains("P:cm:generalclassifiable"));
}
Also used : ObjectType(org.apache.chemistry.opencmis.client.api.ObjectType) AlfrescoType(org.alfresco.cmis.client.type.AlfrescoType) AlfrescoObjectFactoryImpl(org.alfresco.cmis.client.impl.AlfrescoObjectFactoryImpl) CmisSession(org.alfresco.rest.api.tests.client.PublicApiClient.CmisSession) 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 ObjectType

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

the class AbstractSessionTest method createItem.

/**
 * Creates a item.
 */
protected Item createItem(Session session, Folder parent, String name, String objectTypeId) {
    if (parent == null) {
        throw new IllegalArgumentException("Parent is not set!");
    }
    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, "Item type '" + objectTypeId + "' is not available: " + e.getMessage(), e, true));
        return null;
    }
    if (Boolean.FALSE.equals(type.isCreatable())) {
        addResult(createResult(SKIPPED, "Item 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);
    Item result = null;
    try {
        // create the item
        result = parent.createItem(properties, null, null, null, SELECT_ALL_NO_CACHE_OC);
    } catch (CmisBaseException e) {
        addResult(createResult(UNEXPECTED_EXCEPTION, "Item could not be created! Exception: " + e.getMessage(), e, true));
        return null;
    }
    try {
        CmisTestResult f;
        // check item name
        f = createResult(FAILURE, "Item name does not match!", false);
        addResult(assertEquals(name, result.getName(), null, f));
        addResult(checkObject(session, result, getAllProperties(result), "New item object spec compliance"));
    } catch (CmisBaseException e) {
        addResult(createResult(UNEXPECTED_EXCEPTION, "Newly created item is invalid! Exception: " + e.getMessage(), e, true));
    }
    // check parents
    List<Folder> parents = result.getParents(SELECT_ALL_NO_CACHE_OC);
    boolean found = false;
    for (Folder folder : parents) {
        if (parent.getId().equals(folder.getId())) {
            found = true;
            break;
        }
    }
    if (!found) {
        addResult(createResult(FAILURE, "The folder the item has been created in is not in the list of the item parents!"));
    }
    return result;
}
Also used : HashMap(java.util.HashMap) Folder(org.apache.chemistry.opencmis.client.api.Folder) ObjectType(org.apache.chemistry.opencmis.client.api.ObjectType) Item(org.apache.chemistry.opencmis.client.api.Item) CmisObjectNotFoundException(org.apache.chemistry.opencmis.commons.exceptions.CmisObjectNotFoundException) CmisBaseException(org.apache.chemistry.opencmis.commons.exceptions.CmisBaseException) CmisTestResult(org.apache.chemistry.opencmis.tck.CmisTestResult) FileableCmisObject(org.apache.chemistry.opencmis.client.api.FileableCmisObject) CmisObject(org.apache.chemistry.opencmis.client.api.CmisObject)

Example 4 with ObjectType

use of org.apache.chemistry.opencmis.client.api.ObjectType 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 ObjectType

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

the class AbstractSessionTest method createDocument.

/**
 * Creates a document.
 */
protected Document createDocument(Session session, Folder parent, String name, String objectTypeId, String[] secondaryTypeIds, String content) {
    if (parent == null) {
        throw new IllegalArgumentException("Parent is not set!");
    }
    if (name == null) {
        throw new IllegalArgumentException("Name is not set!");
    }
    if (objectTypeId == null) {
        throw new IllegalArgumentException("Object Type ID is not set!");
    }
    if (content == null) {
        content = "";
    }
    // check type
    ObjectType type;
    try {
        type = session.getTypeDefinition(objectTypeId);
    } catch (CmisObjectNotFoundException e) {
        addResult(createResult(UNEXPECTED_EXCEPTION, "Document type '" + objectTypeId + "' is not available: " + e.getMessage(), e, true));
        return null;
    }
    if (Boolean.FALSE.equals(type.isCreatable())) {
        addResult(createResult(SKIPPED, "Document 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);
    if (secondaryTypeIds != null) {
        properties.put(PropertyIds.SECONDARY_OBJECT_TYPE_IDS, Arrays.asList(secondaryTypeIds));
    }
    type = session.getTypeDefinition(objectTypeId);
    if (!(type instanceof DocumentTypeDefinition)) {
        addResult(createResult(FAILURE, "Type is not a document type! Type: " + objectTypeId, true));
        return null;
    }
    DocumentTypeDefinition docType = (DocumentTypeDefinition) type;
    VersioningState versioningState = (Boolean.TRUE.equals(docType.isVersionable()) ? VersioningState.MAJOR : VersioningState.NONE);
    byte[] contentBytes = null;
    Document result = null;
    try {
        contentBytes = IOUtils.toUTF8Bytes(content);
        ContentStream contentStream = new ContentStreamImpl(name, BigInteger.valueOf(contentBytes.length), "text/plain", new ByteArrayInputStream(contentBytes));
        // create the document
        result = parent.createDocument(properties, contentStream, versioningState, null, null, null, SELECT_ALL_NO_CACHE_OC);
        contentStream.getStream().close();
    } catch (Exception e) {
        addResult(createResult(UNEXPECTED_EXCEPTION, "Document could not be created! Exception: " + e.getMessage(), e, true));
        return null;
    }
    try {
        CmisTestResult f;
        // check document name
        f = createResult(FAILURE, "Document name does not match!", false);
        addResult(assertEquals(name, result.getName(), null, f));
        // check content length
        f = createResult(WARNING, "Content length does not match!", false);
        addResult(assertEquals((long) contentBytes.length, result.getContentStreamLength(), null, f));
        // check the new document
        addResult(checkObject(session, result, getAllProperties(result), "New document object spec compliance"));
        // check content
        try {
            ContentStream contentStream = result.getContentStream();
            f = createResult(WARNING, "Document filename and the filename of the content stream do not match!", false);
            addResult(assertEquals(name, contentStream.getFileName(), null, f));
            f = createResult(WARNING, "cmis:contentStreamFileName and the filename of the content stream do not match!", false);
            addResult(assertEquals(result.getContentStreamFileName(), contentStream.getFileName(), null, f));
            String fetchedContent = getStringFromContentStream(result.getContentStream());
            if (!content.equals(fetchedContent)) {
                addResult(createResult(FAILURE, "Content of newly created document doesn't match the orign content!"));
            }
        } catch (IOException e) {
            addResult(createResult(UNEXPECTED_EXCEPTION, "Content of newly created document couldn't be read! Exception: " + e.getMessage(), e, true));
        }
    } catch (CmisBaseException e) {
        addResult(createResult(UNEXPECTED_EXCEPTION, "Newly created document is invalid! Exception: " + e.getMessage(), e, true));
    }
    // check parents
    List<Folder> parents = result.getParents(SELECT_ALL_NO_CACHE_OC);
    boolean found = false;
    for (Folder folder : parents) {
        if (parent.getId().equals(folder.getId())) {
            found = true;
            break;
        }
    }
    if (!found) {
        addResult(createResult(FAILURE, "The folder the document has been created in is not in the list of the document parents!"));
    }
    return result;
}
Also used : ContentStreamImpl(org.apache.chemistry.opencmis.commons.impl.dataobjects.ContentStreamImpl) DocumentTypeDefinition(org.apache.chemistry.opencmis.commons.definitions.DocumentTypeDefinition) HashMap(java.util.HashMap) IOException(java.io.IOException) Document(org.apache.chemistry.opencmis.client.api.Document) Folder(org.apache.chemistry.opencmis.client.api.Folder) 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) ObjectType(org.apache.chemistry.opencmis.client.api.ObjectType) ContentStream(org.apache.chemistry.opencmis.commons.data.ContentStream) CmisObjectNotFoundException(org.apache.chemistry.opencmis.commons.exceptions.CmisObjectNotFoundException) ByteArrayInputStream(java.io.ByteArrayInputStream) CmisBaseException(org.apache.chemistry.opencmis.commons.exceptions.CmisBaseException) CmisTestResult(org.apache.chemistry.opencmis.tck.CmisTestResult) FileableCmisObject(org.apache.chemistry.opencmis.client.api.FileableCmisObject) CmisObject(org.apache.chemistry.opencmis.client.api.CmisObject) VersioningState(org.apache.chemistry.opencmis.commons.enums.VersioningState)

Aggregations

ObjectType (org.apache.chemistry.opencmis.client.api.ObjectType)15 CmisObjectNotFoundException (org.apache.chemistry.opencmis.commons.exceptions.CmisObjectNotFoundException)9 HashMap (java.util.HashMap)8 CmisTestResult (org.apache.chemistry.opencmis.tck.CmisTestResult)8 CmisBaseException (org.apache.chemistry.opencmis.commons.exceptions.CmisBaseException)7 CmisObject (org.apache.chemistry.opencmis.client.api.CmisObject)5 FileableCmisObject (org.apache.chemistry.opencmis.client.api.FileableCmisObject)5 Folder (org.apache.chemistry.opencmis.client.api.Folder)5 ObjectId (org.apache.chemistry.opencmis.client.api.ObjectId)3 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 CmisSession (org.alfresco.rest.api.tests.client.PublicApiClient.CmisSession)2 Document (org.apache.chemistry.opencmis.client.api.Document)2 CmisInvalidArgumentException (org.apache.chemistry.opencmis.commons.exceptions.CmisInvalidArgumentException)2 CmisNotSupportedException (org.apache.chemistry.opencmis.commons.exceptions.CmisNotSupportedException)2 DocumentTypeDefinitionImpl (org.apache.chemistry.opencmis.commons.impl.dataobjects.DocumentTypeDefinitionImpl)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 Map (java.util.Map)1 AlfrescoObjectFactoryImpl (org.alfresco.cmis.client.impl.AlfrescoObjectFactoryImpl)1 AlfrescoType (org.alfresco.cmis.client.type.AlfrescoType)1