Search in sources :

Example 11 with Session

use of org.apache.chemistry.opencmis.client.api.Session in project SearchServices by Alfresco.

the class CMISDataCreatorTest method getSession.

private static Session getSession(String user, String pwd) {
    String url = "http://localhost:8080/alfresco/api/-default-/public/cmis/versions/1.1/atom";
    SessionFactory factory = SessionFactoryImpl.newInstance();
    Map<String, String> parameter = new HashMap<String, String>();
    parameter.put(SessionParameter.USER, user);
    parameter.put(SessionParameter.PASSWORD, pwd);
    parameter.put(SessionParameter.ATOMPUB_URL, url);
    parameter.put(SessionParameter.BINDING_TYPE, BindingType.ATOMPUB.value());
    List<Repository> repositories = factory.getRepositories(parameter);
    Session session = repositories.get(0).createSession();
    return session;
}
Also used : SessionFactory(org.apache.chemistry.opencmis.client.api.SessionFactory) Repository(org.apache.chemistry.opencmis.client.api.Repository) HashMap(java.util.HashMap) Session(org.apache.chemistry.opencmis.client.api.Session)

Example 12 with Session

use of org.apache.chemistry.opencmis.client.api.Session in project SearchServices by Alfresco.

the class CMISDataCreatorTest method testQueryDocumentProperties.

public void testQueryDocumentProperties() throws Exception {
    Session session = getSession("admin", "admin");
    String folderName = getRootFolderName();
    Folder root = session.getRootFolder();
    Map<String, Object> properties = new HashMap<String, Object>();
    properties.put(PropertyIds.OBJECT_TYPE_ID, "cmis:folder");
    properties.put(PropertyIds.NAME, folderName);
    // create the folder
    Folder newFolder = root.createFolder(properties);
    ItemIterable<QueryResult> result = session.query("select * from cmis:folder where cmis:name = '" + folderName + "'", false);
    assertEquals(1, result.getTotalNumItems());
    Document uniqueDocument = createUniqueDocument(newFolder);
    result = session.query("select * from cmis:document where cmis:name = '" + uniqueDocument.getName() + "'", false);
    assertEquals(1, result.getTotalNumItems());
    result = session.query("select * from cmis:document where cmis:name = '" + uniqueDocument.getName() + "' AND IN_FOLDER('" + newFolder.getId() + "')", false);
    assertEquals(1, result.getTotalNumItems());
    result = session.query("select * from cmis:document where IN_FOLDER('" + newFolder.getId() + "')", false);
    assertEquals(1, result.getTotalNumItems());
    result = session.query("select * from cmis:document where cmis:name = '" + uniqueDocument.getName() + "' AND cmis:createdBy = '" + uniqueDocument.getCreatedBy() + "'", false);
    assertEquals(1, result.getTotalNumItems());
    result = session.query("select * from cmis:document where cmis:name = '" + uniqueDocument.getName() + "' AND cmis:objectId = '" + uniqueDocument.getId() + "'", false);
    assertEquals(1, result.getTotalNumItems());
    result = session.query("select * from cmis:document where cmis:name = '" + uniqueDocument.getName() + "' AND cmis:lastModifiedBy = '" + uniqueDocument.getLastModifiedBy() + "'", false);
    assertEquals(1, result.getTotalNumItems());
    result = session.query("select * from cmis:document where cmis:name = '" + uniqueDocument.getName() + "'", false);
    assertEquals(1, result.getTotalNumItems());
    String creationDate = ISO8601DateFormat.format(uniqueDocument.getCreationDate().getTime());
    result = session.query("select * from cmis:document where cmis:name = '" + uniqueDocument.getName() + "' AND cmis:creationDate = '" + creationDate + "'", false);
    assertEquals(1, result.getTotalNumItems());
    String modificationDate = ISO8601DateFormat.format(uniqueDocument.getLastModificationDate().getTime());
    result = session.query("select * from cmis:document where cmis:name = '" + uniqueDocument.getName() + "' AND cmis:lastModificationDate = '" + modificationDate + "'", false);
    assertEquals(1, result.getTotalNumItems());
    result = session.query("select * from cmis:document where cmis:name = '" + uniqueDocument.getName() + "' AND cmis:objectTypeId = '" + uniqueDocument.getType().getQueryName() + "'", false);
    assertEquals(1, result.getTotalNumItems());
    result = session.query("select * from cmis:document where cmis:name = '" + uniqueDocument.getName() + "' AND cmis:baseTypeId = '" + uniqueDocument.getBaseType().getQueryName() + "'", false);
    assertEquals(1, result.getTotalNumItems());
    result = session.query("select * from cmis:document where cmis:name = '" + uniqueDocument.getName() + "' AND cmis:contentStreamFileName = '" + uniqueDocument.getContentStreamFileName() + "'", false);
    assertEquals(1, result.getTotalNumItems());
    result = session.query("select * from cmis:document where cmis:name = '" + uniqueDocument.getName() + "' AND cmis:contentStreamLength = '" + uniqueDocument.getContentStreamLength() + "'", false);
    assertEquals(1, result.getTotalNumItems());
    result = session.query("select * from cmis:document where cmis:name = '" + uniqueDocument.getName() + "' AND cmis:contentStreamMimeType = '" + uniqueDocument.getContentStreamMimeType() + "'", false);
    assertEquals(1, result.getTotalNumItems());
}
Also used : QueryResult(org.apache.chemistry.opencmis.client.api.QueryResult) HashMap(java.util.HashMap) CmisObject(org.apache.chemistry.opencmis.client.api.CmisObject) Folder(org.apache.chemistry.opencmis.client.api.Folder) Document(org.apache.chemistry.opencmis.client.api.Document) Session(org.apache.chemistry.opencmis.client.api.Session)

Example 13 with Session

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

the class TestRemovePermissions method testRemoveAllPermissions_WEBSERVICE_10.

/**
 * cmisws?wsdl is not available using jetty in automated test suite should
 * be runned using an external alfresco server
 */
// @Test
public void testRemoveAllPermissions_WEBSERVICE_10() {
    Folder testFolder = null;
    try {
        Session session = getWEBSERVICE_10_Session();
        if (session == null) {
            fail("WEBSERVICE 1.0 session cannot be null");
        }
        testFolder = createFolder(session, "testRemoveAllPermissions_WEBSERVICE_10");
        List<Ace> acl = create2TestACLs(session);
        // adding new ACE
        testFolder.addAcl(acl, AclPropagation.PROPAGATE);
        Acl allacl = session.getAcl(session.createObjectId(testFolder.getId()), false);
        int oldSize = allacl.getAces().size();
        // Removing ALL ACEs
        Acl newAcl = testFolder.removeAcl(allacl.getAces(), AclPropagation.PROPAGATE);
        int newsize = newAcl.getAces().size();
        System.out.println("Old ace size -->" + oldSize);
        System.out.println("New ace size --> " + newsize);
        assertTrue(newsize == oldSize - acl.size());
    } catch (Exception ex) {
        fail(ex.getMessage());
    } finally {
        if (testFolder != null) {
            testFolder.delete();
        }
    }
}
Also used : Ace(org.apache.chemistry.opencmis.commons.data.Ace) Acl(org.apache.chemistry.opencmis.commons.data.Acl) Folder(org.apache.chemistry.opencmis.client.api.Folder) Session(org.apache.chemistry.opencmis.client.api.Session)

Example 14 with Session

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

the class TestRemovePermissions method testRemoveAllPermissions_ATOMPUB_10.

@Test
public void testRemoveAllPermissions_ATOMPUB_10() {
    Folder testFolder = null;
    try {
        Session session = getATOMPUB_10_Session();
        if (session == null) {
            fail("ATOMPUB 1.0 session cannot be null");
        }
        testFolder = createFolder(session, "testRemoveAllPermissions_ATOMPUB_10");
        List<Ace> acl = create2TestACLs(session);
        // adding new ACE
        testFolder.addAcl(acl, AclPropagation.PROPAGATE);
        Acl allacl = session.getAcl(session.createObjectId(testFolder.getId()), false);
        int oldSize = allacl.getAces().size();
        // Removing ALL ACEs
        Acl newAcl = testFolder.removeAcl(allacl.getAces(), AclPropagation.PROPAGATE);
        int newsize = newAcl.getAces().size();
        System.out.println("Old ace size -->" + oldSize);
        System.out.println("New ace size --> " + newsize);
        assertTrue(newsize == oldSize - acl.size());
    } catch (Exception ex) {
        fail(ex.getMessage());
    } finally {
        if (testFolder != null) {
            testFolder.delete();
        }
    }
}
Also used : Ace(org.apache.chemistry.opencmis.commons.data.Ace) Acl(org.apache.chemistry.opencmis.commons.data.Acl) Folder(org.apache.chemistry.opencmis.client.api.Folder) Session(org.apache.chemistry.opencmis.client.api.Session) Test(org.junit.Test)

Example 15 with Session

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

the class TestRemovePermissions method testRemoveAllPermissions_BROWSER_11.

@Test
public void testRemoveAllPermissions_BROWSER_11() {
    Folder testFolder = null;
    try {
        Session session = getBROWSER_11_Session();
        if (session == null) {
            fail("ATOMPUB 1.1 session cannot be null");
        }
        testFolder = createFolder(session, "testRemoveAllPermissions_BROWSER_11");
        List<Ace> acl = create2TestACLs(session);
        // adding new ACE
        testFolder.addAcl(acl, AclPropagation.PROPAGATE);
        Acl allacl = session.getAcl(session.createObjectId(testFolder.getId()), false);
        int oldSize = allacl.getAces().size();
        // Removing ALL ACEs
        Acl newAcl = testFolder.removeAcl(allacl.getAces(), AclPropagation.PROPAGATE);
        int newsize = newAcl.getAces().size();
        System.out.println("Old ace size -->" + oldSize);
        System.out.println("New ace size --> " + newsize);
        assertTrue(newsize == oldSize - acl.size());
    } catch (Exception ex) {
        fail(ex.getMessage());
    } finally {
        if (testFolder != null) {
            testFolder.delete();
        }
    }
}
Also used : Ace(org.apache.chemistry.opencmis.commons.data.Ace) Acl(org.apache.chemistry.opencmis.commons.data.Acl) Folder(org.apache.chemistry.opencmis.client.api.Folder) Session(org.apache.chemistry.opencmis.client.api.Session) Test(org.junit.Test)

Aggregations

Session (org.apache.chemistry.opencmis.client.api.Session)16 HashMap (java.util.HashMap)10 Folder (org.apache.chemistry.opencmis.client.api.Folder)10 CmisObject (org.apache.chemistry.opencmis.client.api.CmisObject)6 Ace (org.apache.chemistry.opencmis.commons.data.Ace)6 QueryResult (org.apache.chemistry.opencmis.client.api.QueryResult)5 SessionFactory (org.apache.chemistry.opencmis.client.api.SessionFactory)5 Acl (org.apache.chemistry.opencmis.commons.data.Acl)4 ArrayList (java.util.ArrayList)3 Test (org.junit.Test)3 Document (org.apache.chemistry.opencmis.client.api.Document)2 Repository (org.apache.chemistry.opencmis.client.api.Repository)2 AccessControlEntryImpl (org.apache.chemistry.opencmis.commons.impl.dataobjects.AccessControlEntryImpl)2 AccessControlPrincipalDataImpl (org.apache.chemistry.opencmis.commons.impl.dataobjects.AccessControlPrincipalDataImpl)2 IOException (java.io.IOException)1 IPipeLineSession (nl.nn.adapterframework.core.IPipeLineSession)1 CredentialFactory (nl.nn.adapterframework.util.CredentialFactory)1 AlfrescoObjectFactoryImpl (org.alfresco.cmis.client.impl.AlfrescoObjectFactoryImpl)1 CmisSession (org.alfresco.rest.api.tests.client.PublicApiClient.CmisSession)1 SessionParameterMap (org.apache.chemistry.opencmis.client.SessionParameterMap)1