org.apache.chemistry.opencmis.client.api.SessionFactory Java Examples

The following examples show how to use org.apache.chemistry.opencmis.client.api.SessionFactory. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: OpenCmisLocalTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
private Repository getRepository(String user, String password)
{
    // default factory implementation
    SessionFactory sessionFactory = SessionFactoryImpl.newInstance();
    Map<String, String> parameters = new HashMap<String, String>();

    // user credentials
    parameters.put(SessionParameter.USER, "admin");
    parameters.put(SessionParameter.PASSWORD, "admin");

    // connection settings
    parameters.put(SessionParameter.BINDING_TYPE, BindingType.LOCAL.value());
    parameters.put(SessionParameter.LOCAL_FACTORY, "org.alfresco.opencmis.OpenCmisLocalTest$TestCmisServiceFactory");

    // create session
    List<Repository> repositories = sessionFactory.getRepositories(parameters);
    return repositories.size() > 0 ? repositories.get(0) : null;
}
 
Example #2
Source File: CMISDataCreatorTest.java    From SearchServices with GNU Lesser General Public License v3.0 6 votes vote down vote up
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;
}
 
Example #3
Source File: TestRemovePermissions.java    From alfresco-remote-api with GNU Lesser General Public License v3.0 6 votes vote down vote up
protected Session getATOMPUB_10_Session()
{
    try
    {
        Map<String, String> parameters = new HashMap<String, String>();
        int port = getTestFixture().getJettyComponent().getPort();

        parameters.put(SessionParameter.USER, ADMIN_USER);
        parameters.put(SessionParameter.PASSWORD, ADMIN_PASSWORD);
        parameters.put(SessionParameter.ATOMPUB_URL, MessageFormat.format(ATOMPUB_URL_OC, DEFAULT_HOSTNAME, String.valueOf(port)));
        parameters.put(SessionParameter.BINDING_TYPE, BindingType.ATOMPUB.value());

        SessionFactory sessionFactory = SessionFactoryImpl.newInstance();

        parameters.put(SessionParameter.REPOSITORY_ID, sessionFactory.getRepositories(parameters).get(0).getId());
        return sessionFactory.createSession(parameters);
    }
    catch (Exception ex)
    {
        logger.error(ex);
    }
    return null;
}
 
Example #4
Source File: TestRemovePermissions.java    From alfresco-remote-api with GNU Lesser General Public License v3.0 6 votes vote down vote up
protected Session getATOMPUB_11_Session()
{
    try
    {
        Map<String, String> parameters = new HashMap<String, String>();
        int port = getTestFixture().getJettyComponent().getPort();

        parameters.put(SessionParameter.USER, ADMIN_USER);
        parameters.put(SessionParameter.PASSWORD, ADMIN_PASSWORD);
        parameters.put(SessionParameter.ATOMPUB_URL, MessageFormat.format(ATOMPUB_URL_11, DEFAULT_HOSTNAME, String.valueOf(port)));
        parameters.put(SessionParameter.BINDING_TYPE, BindingType.ATOMPUB.value());

        SessionFactory sessionFactory = SessionFactoryImpl.newInstance();

        parameters.put(SessionParameter.REPOSITORY_ID, sessionFactory.getRepositories(parameters).get(0).getId());
        return sessionFactory.createSession(parameters);
    }
    catch (Exception ex)
    {
        logger.error(ex);

    }
    return null;
}
 
Example #5
Source File: TestRemovePermissions.java    From alfresco-remote-api with GNU Lesser General Public License v3.0 6 votes vote down vote up
protected Session getBROWSER_11_Session()
{
    try
    {
        Map<String, String> parameter = new HashMap<String, String>();
        int port = getTestFixture().getJettyComponent().getPort();

        parameter.put(SessionParameter.BINDING_TYPE, BindingType.BROWSER.value());
        parameter.put(SessionParameter.BROWSER_URL, MessageFormat.format(BROWSE_URL_11, DEFAULT_HOSTNAME, String.valueOf(port)));
        parameter.put(SessionParameter.COOKIES, "true");

        parameter.put(SessionParameter.USER, ADMIN_USER);
        parameter.put(SessionParameter.PASSWORD, ADMIN_PASSWORD);

        SessionFactory sessionFactory = SessionFactoryImpl.newInstance();

        parameter.put(SessionParameter.REPOSITORY_ID, sessionFactory.getRepositories(parameter).get(0).getId());
        return sessionFactory.createSession(parameter);
    }
    catch (Exception ex)
    {
        logger.error(ex);

    }
    return null;
}
 
Example #6
Source File: PublicApiClient.java    From alfresco-remote-api with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * 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;
}
 
Example #7
Source File: SampleClient.java    From document-management-software with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Connect to logicaldoc repository
 * 
 * @return root folder object
 */
private static Folder connect(String username, String password) {
	SessionFactory sessionFactory = SessionFactoryImpl.newInstance();
	Map<String, String> parameter = new HashMap<String, String>();
	parameter.put(SessionParameter.USER, username);
	parameter.put(SessionParameter.PASSWORD, password);
	parameter.put(SessionParameter.ATOMPUB_URL, CONNECTION_URL);
	parameter.put(SessionParameter.BINDING_TYPE, BindingType.ATOMPUB.value());
	parameter.put(SessionParameter.REPOSITORY_ID, Long.toString(5L));

	session = sessionFactory.createSession(parameter);
	return session.getRootFolder();
}
 
Example #8
Source File: TestCMIS.java    From alfresco-remote-api with GNU Lesser General Public License v3.0 5 votes vote down vote up
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);
}
 
Example #9
Source File: PublicApiClient.java    From alfresco-remote-api with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Get CMIS repositories (Enterprise AtomPub CMIS binding)
 *
 * @return List<Repository>
 */
public List<Repository> getCMISRepositories()
{
    List<Repository> repositories = null;

    RequestContext rc = getRequestContext();
    if(rc == null)
    {
        throw new RuntimeException("Must set a request context");
    }

    UserData userData = findUser(rc.getRunAsUser());
    if(userData != null)
    {
        // default factory implementation
        SessionFactory factory = SessionFactoryImpl.newInstance();
        Map<String, String> parameters = new HashMap<String, String>();

        // user credentials
        parameters.put(SessionParameter.USER, rc.getRunAsUser());
        parameters.put(SessionParameter.PASSWORD, userData.getPassword());

        // connection settings
        parameters.put(SessionParameter.ATOMPUB_URL, client.getCmisUrl(null, null));
        parameters.put(SessionParameter.BINDING_TYPE, BindingType.ATOMPUB.value());

        repositories = factory.getRepositories(parameters);
    }

    return repositories;
}
 
Example #10
Source File: PublicApiClient.java    From alfresco-remote-api with GNU Lesser General Public License v3.0 5 votes vote down vote up
public List<String> getNetworkIds(String version)
{
    RequestContext rc = getRequestContext();

    UserData userData = findUser(rc.getRunAsUser());
    if(userData == null)
    {
        throw new RuntimeException("Must provide a valid username");
    }

    SessionFactory factory = SessionFactoryImpl.newInstance();

    Map<String, String> parameters = new HashMap<String, String>();

    // connection settings
    parameters.put(SessionParameter.ATOMPUB_URL, client.getPublicApiCmisUrl(null, Binding.atom, version, null));
    parameters.put(SessionParameter.BINDING_TYPE, BindingType.ATOMPUB.value());

    // user credentials
    parameters.put(SessionParameter.USER, rc.getRunAsUser());
    parameters.put(SessionParameter.PASSWORD, userData.getPassword());
    List<Repository> repositories = factory.getRepositories(parameters);

    List<String> repositoryIds = new ArrayList<String>(repositories.size());
    for(Repository repository : repositories)
    {
        repositoryIds.add(repository.getId());
    }

    return repositoryIds;
}
 
Example #11
Source File: CmisIntegrationTest.java    From wildfly-camel with Apache License 2.0 5 votes vote down vote up
private Session createSession() {
    SessionFactory sessionFactory = SessionFactoryImpl.newInstance();
    Map<String, String> parameter = new HashMap<String, String>();
    parameter.put(SessionParameter.ATOMPUB_URL, "http://127.0.0.1:8080/chemistry-opencmis-server-inmemory/atom11/atom11");
    parameter.put(SessionParameter.BINDING_TYPE, BindingType.ATOMPUB.value());
    Repository repository = sessionFactory.getRepositories(parameter).get(0);
    return repository.createSession();
}
 
Example #12
Source File: TestRemovePermissions.java    From alfresco-remote-api with GNU Lesser General Public License v3.0 4 votes vote down vote up
protected Session getWEBSERVICE_10_Session()
{
    try
    {
        SessionFactory sessionFactory = SessionFactoryImpl.newInstance();
        int port = 8080;

        Map<String, String> parameters = new HashMap<String, String>();

        parameters.put(SessionParameter.USER, ADMIN_USER);
        parameters.put(SessionParameter.PASSWORD, ADMIN_PASSWORD);
        parameters.put(SessionParameter.BINDING_TYPE, BindingType.WEBSERVICES.value());

        parameters.put(SessionParameter.WEBSERVICES_ACL_SERVICE,
                MessageFormat.format(ACLSERVICE_OC_URL, DEFAULT_HOSTNAME, String.valueOf(port)));
        parameters.put(SessionParameter.WEBSERVICES_DISCOVERY_SERVICE,
                MessageFormat.format(DISCOVERYSERVICE_OC_URL, DEFAULT_HOSTNAME, String.valueOf(port)));
        parameters.put(SessionParameter.WEBSERVICES_MULTIFILING_SERVICE,
                MessageFormat.format(MULTIFILINGSERVICE_OC_URL, DEFAULT_HOSTNAME, String.valueOf(port)));
        parameters.put(SessionParameter.WEBSERVICES_NAVIGATION_SERVICE,
                MessageFormat.format(NAVIGATIONSERVICE_OC_URL, DEFAULT_HOSTNAME, String.valueOf(port)));
        parameters.put(SessionParameter.WEBSERVICES_OBJECT_SERVICE,
                MessageFormat.format(OBJECTSERVICE_OC_URL, DEFAULT_HOSTNAME, String.valueOf(port)));
        parameters.put(SessionParameter.WEBSERVICES_POLICY_SERVICE,
                MessageFormat.format(POLICYSERVICE_OC_URL, DEFAULT_HOSTNAME, String.valueOf(port)));
        parameters.put(SessionParameter.WEBSERVICES_RELATIONSHIP_SERVICE,
                MessageFormat.format(RELATIONSHIPSERVICE_OC_URL, DEFAULT_HOSTNAME, String.valueOf(port)));
        parameters.put(SessionParameter.WEBSERVICES_REPOSITORY_SERVICE,
                MessageFormat.format(REPOSITORYSERVICE_OC_URL, DEFAULT_HOSTNAME, String.valueOf(port)));
        parameters.put(SessionParameter.WEBSERVICES_VERSIONING_SERVICE,
                MessageFormat.format(REPOSITORYSERVICE_OC_URL, DEFAULT_HOSTNAME, String.valueOf(port)));
        parameters.put(SessionParameter.REPOSITORY_ID, sessionFactory.getRepositories(parameters).get(0).getId());

        return sessionFactory.createSession(parameters);
    }
    catch (Exception ex)
    {
        logger.error(ex);
    }
    return null;
}
 
Example #13
Source File: PublicApiClient.java    From alfresco-remote-api with GNU Lesser General Public License v3.0 4 votes vote down vote up
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;
}