Search in sources :

Example 16 with Session

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

the class PublicApiClient method createPublicApiCMISSession.

public CmisSession createPublicApiCMISSession(Binding binding, String version, String objectFactoryName) {
    CmisSession cmisSession = null;
    RequestContext rc = getRequestContext();
    if (rc == null) {
        throw new RuntimeException("Must set a request context");
    }
    String networkId = rc.getNetworkId();
    String username = rc.getRunAsUser();
    UserData userData = findUser(rc.getRunAsUser());
    if (userData != null) {
        String password = userData.getPassword();
        // 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
        if (binding == Binding.atom) {
            parameters.put(SessionParameter.ATOMPUB_URL, client.getPublicApiCmisUrl(networkId, binding, version, null));
            parameters.put(SessionParameter.BINDING_TYPE, binding.getOpenCmisBinding().value());
        } else if (binding == Binding.browser) {
            parameters.put(SessionParameter.BROWSER_URL, client.getPublicApiCmisUrl(networkId, binding, version, null));
            parameters.put(SessionParameter.BINDING_TYPE, binding.getOpenCmisBinding().value());
        }
        if (networkId != null) {
            parameters.put(SessionParameter.REPOSITORY_ID, networkId);
        }
        if (objectFactoryName != null) {
            parameters.put(SessionParameter.OBJECT_FACTORY_CLASS, objectFactoryName);
        }
        // create session
        Session session = factory.createSession(parameters);
        cmisSession = new CmisSession(session);
    }
    return cmisSession;
}
Also used : SessionFactory(org.apache.chemistry.opencmis.client.api.SessionFactory) HashMap(java.util.HashMap) 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