Search in sources :

Example 6 with Session

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

the class TestRemovePermissions method testRemoveAllPermissions_ATOMPUB_11.

@Test
public void testRemoveAllPermissions_ATOMPUB_11() {
    Folder testFolder = null;
    try {
        Session session = getATOMPUB_11_Session();
        if (session == null) {
            fail("ATOMPUB 1.1 session cannot be null");
        }
        testFolder = createFolder(session, "testRemoveAllPermissions_ATOMPUB_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)

Example 7 with Session

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

the class PublicApiClient method createCMISSession.

/**
 * Create a CMIS session using Enterprise AtomPub binding.
 *
 * @param repositoryId String
 * @param username String
 * @param password String
 * @return CmisSession
 */
public CmisSession createCMISSession(String repositoryId, String username, String password) {
    // default factory implementation
    SessionFactory factory = SessionFactoryImpl.newInstance();
    Map<String, String> parameters = new HashMap<String, String>();
    // user credentials
    parameters.put(SessionParameter.USER, username);
    parameters.put(SessionParameter.PASSWORD, password);
    // connection settings
    parameters.put(SessionParameter.ATOMPUB_URL, client.getCmisUrl(repositoryId, null));
    parameters.put(SessionParameter.BINDING_TYPE, BindingType.ATOMPUB.value());
    if (repositoryId != null) {
        parameters.put(SessionParameter.REPOSITORY_ID, repositoryId);
    }
    parameters.put(SessionParameter.OBJECT_FACTORY_CLASS, AlfrescoObjectFactoryImpl.class.getName());
    // create session
    Session session = factory.createSession(parameters);
    CmisSession cmisSession = new CmisSession(session);
    return cmisSession;
}
Also used : SessionFactory(org.apache.chemistry.opencmis.client.api.SessionFactory) AlfrescoObjectFactoryImpl(org.alfresco.cmis.client.impl.AlfrescoObjectFactoryImpl) HashMap(java.util.HashMap) Session(org.apache.chemistry.opencmis.client.api.Session)

Example 8 with Session

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

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

the class CMISDataCreatorTest method testCreate.

public void testCreate() {
    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);
    for (int i = 0; i < 50; i++) {
        AccessControlPrincipalDataImpl principal = new AccessControlPrincipalDataImpl("user" + i);
        List<String> permissions = new ArrayList<String>(1);
        permissions.add(BasicPermissions.READ);
        List<Ace> addAces = new ArrayList<Ace>(1);
        addAces.add(new AccessControlEntryImpl(principal, permissions));
        newFolder.addAcl(addAces, AclPropagation.PROPAGATE);
        Map<String, Object> updateProperties = new HashMap<String, Object>();
        updateProperties.put("cm:title", "Update title " + i);
        newFolder.updateProperties(properties);
        if (i % 10 == 0) {
            System.out.println("@ " + i);
        }
    }
    ItemIterable<QueryResult> result = session.query("select * from cmis:folder", false);
    assertTrue(result.getTotalNumItems() > 0);
    result = session.query("select * from cmis:folder where cmis:name = '" + folderName + "'", false);
    assertTrue(result.getTotalNumItems() > 0);
}
Also used : AccessControlEntryImpl(org.apache.chemistry.opencmis.commons.impl.dataobjects.AccessControlEntryImpl) Ace(org.apache.chemistry.opencmis.commons.data.Ace) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Folder(org.apache.chemistry.opencmis.client.api.Folder) QueryResult(org.apache.chemistry.opencmis.client.api.QueryResult) CmisObject(org.apache.chemistry.opencmis.client.api.CmisObject) AccessControlPrincipalDataImpl(org.apache.chemistry.opencmis.commons.impl.dataobjects.AccessControlPrincipalDataImpl) Session(org.apache.chemistry.opencmis.client.api.Session)

Example 10 with Session

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

the class CMISDataCreatorTest method testQueryForMultipleDocumentProperties.

public void testQueryForMultipleDocumentProperties() 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 document1 = createUniqueDocument(newFolder);
    Document document2 = createUniqueDocument(newFolder);
    // result = session.query("SELECT * FROM cmis:folder d join sys:hidden t on  d.cmis:objectId = t.cmis:objectId", false);
    // assertTrue(0 < result.getTotalNumItems());
    // result = session.query("SELECT * FROM cmis:folder d join sys:hidden t on  d.cmis:objectId = t.cmis:objectId where t.sys:cascadeHidden = false", false);
    // assertTrue(0 < result.getTotalNumItems());
    result = session.query("SELECT * FROM cmis:document d join exif:exif t on  d.cmis:objectId = t.cmis:objectId", false);
    long count = result.getTotalNumItems();
    Map<String, Object> props = new HashMap<String, Object>();
    props.put("exif:focalLength", 10.33d);
    ArrayList<String> aspects = new ArrayList<String>();
    aspects.add("P:exif:exif");
    props.put("cmis:secondaryObjectTypeIds", aspects);
    document1.updateProperties(props);
    result = session.query("SELECT * FROM cmis:document d join exif:exif t on  d.cmis:objectId = t.cmis:objectId", false);
    assertEquals(count + 1, result.getTotalNumItems());
    result = session.query("select * from cmis:document where cmis:name = '" + document1.getName() + "' OR  cmis:name = '" + document2.getName() + "'", false);
    assertEquals(2, result.getTotalNumItems());
    result = session.query("select * from cmis:document where cmis:name = '" + document1.getName() + "' AND cmis:contentStreamLength = 5 AND cmis:contentStreamMimeType = 'text/plain'", false);
    assertEquals(1, result.getTotalNumItems());
    result = session.query("SELECT * FROM cmis:document", false);
    long docCount = result.getTotalNumItems();
    result = session.query("SELECT * FROM cmis:document d left outer join exif:exif t on  d.cmis:objectId = t.cmis:objectId", false);
    assertEquals(docCount, result.getTotalNumItems());
}
Also used : QueryResult(org.apache.chemistry.opencmis.client.api.QueryResult) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) 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)

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