Search in sources :

Example 1 with Session

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

the class CMISTestSupport method deleteAllContent.

protected void deleteAllContent() {
    Session session = createSession();
    Folder rootFolder = session.getRootFolder();
    ItemIterable<CmisObject> children = rootFolder.getChildren();
    for (CmisObject cmisObject : children) {
        if ("cmis:folder".equals(cmisObject.getPropertyValue(PropertyIds.OBJECT_TYPE_ID))) {
            List<String> notDeltedIdList = ((Folder) cmisObject).deleteTree(true, UnfileObject.DELETE, true);
            if (notDeltedIdList != null && notDeltedIdList.size() > 0) {
                throw new RuntimeException("Cannot empty repo");
            }
        } else {
            cmisObject.delete(true);
        }
    }
    session.getBinding().close();
}
Also used : CmisObject(org.apache.chemistry.opencmis.client.api.CmisObject) Folder(org.apache.chemistry.opencmis.client.api.Folder) Session(org.apache.chemistry.opencmis.client.api.Session)

Example 2 with Session

use of org.apache.chemistry.opencmis.client.api.Session in project iaf by ibissource.

the class CmisSender method connect.

private Session connect(String userName, String password) {
    log.debug(getLogPrefix() + "connecting with url [" + getUrl() + "] repository [" + getRepository() + "]");
    SessionFactory sessionFactory = SessionFactoryImpl.newInstance();
    Map<String, String> parameter = new HashMap<String, String>();
    parameter.put(SessionParameter.USER, userName);
    parameter.put(SessionParameter.PASSWORD, password);
    if (getBindingType().equalsIgnoreCase("atompub")) {
        parameter.put(SessionParameter.ATOMPUB_URL, getUrl());
        parameter.put(SessionParameter.BINDING_TYPE, BindingType.ATOMPUB.value());
    } else if (getBindingType().equalsIgnoreCase("browser")) {
        parameter.put(SessionParameter.BROWSER_URL, getUrl());
        parameter.put(SessionParameter.BINDING_TYPE, BindingType.BROWSER.value());
    } else {
        parameter.put(SessionParameter.WEBSERVICES_REPOSITORY_SERVICE, getUrl() + "/RepositoryService.svc?wsdl");
        parameter.put(SessionParameter.WEBSERVICES_NAVIGATION_SERVICE, getUrl() + "/NavigationService.svc?wsdl");
        parameter.put(SessionParameter.WEBSERVICES_OBJECT_SERVICE, getUrl() + "/ObjectService.svc?wsdl");
        parameter.put(SessionParameter.WEBSERVICES_VERSIONING_SERVICE, getUrl() + "/VersioningService.svc?wsdl");
        parameter.put(SessionParameter.WEBSERVICES_DISCOVERY_SERVICE, getUrl() + "/DiscoveryService.svc?wsdl");
        parameter.put(SessionParameter.WEBSERVICES_RELATIONSHIP_SERVICE, getUrl() + "/RelationshipService.svc?wsdl");
        parameter.put(SessionParameter.WEBSERVICES_MULTIFILING_SERVICE, getUrl() + "/MultiFilingService.svc?wsdl");
        parameter.put(SessionParameter.WEBSERVICES_POLICY_SERVICE, getUrl() + "/PolicyService.svc?wsdl");
        parameter.put(SessionParameter.WEBSERVICES_ACL_SERVICE, getUrl() + "/ACLService.svc?wsdl");
        parameter.put(SessionParameter.BINDING_TYPE, BindingType.WEBSERVICES.value());
    }
    parameter.put(SessionParameter.REPOSITORY_ID, getRepository());
    // SSL
    if (getCertificate() != null || getTruststore() != null || isAllowSelfSignedCertificates()) {
        CredentialFactory certificateCf = new CredentialFactory(getCertificateAuthAlias(), null, getCertificatePassword());
        CredentialFactory truststoreCf = new CredentialFactory(getTruststoreAuthAlias(), null, getTruststorePassword());
        parameter.put("certificateUrl", getCertificate());
        parameter.put("certificatePassword", certificateCf.getPassword());
        parameter.put("keystoreType", getKeystoreType());
        parameter.put("keyManagerAlgorithm", getKeyManagerAlgorithm());
        parameter.put("truststoreUrl", getTruststore());
        parameter.put("truststorePassword", truststoreCf.getPassword());
        parameter.put("truststoreType", getTruststoreType());
        parameter.put("trustManagerAlgorithm", getTrustManagerAlgorithm());
    }
    // SSL+
    parameter.put("isAllowSelfSignedCertificates", "" + isAllowSelfSignedCertificates());
    parameter.put("isVerifyHostname", "" + isVerifyHostname());
    parameter.put("isIgnoreCertificateExpiredException", "" + isIgnoreCertificateExpiredException());
    // PROXY
    if (StringUtils.isNotEmpty(getProxyHost())) {
        CredentialFactory pcf = new CredentialFactory(getProxyAuthAlias(), getProxyUserName(), getProxyPassword());
        parameter.put("proxyHost", getProxyHost());
        parameter.put("proxyPort", "" + getProxyPort());
        parameter.put("proxyUserName", pcf.getUsername());
        parameter.put("proxyPassword", pcf.getPassword());
    }
    // Custom IBIS HttpSender to support ssl connections and proxies
    parameter.put(SessionParameter.HTTP_INVOKER_CLASS, "nl.nn.adapterframework.extensions.cmis.CmisHttpInvoker");
    Session session = sessionFactory.createSession(parameter);
    log.debug(getLogPrefix() + "connected with repository [" + getRepositoryInfo(session) + "]");
    return session;
}
Also used : SessionFactory(org.apache.chemistry.opencmis.client.api.SessionFactory) HashMap(java.util.HashMap) CredentialFactory(nl.nn.adapterframework.util.CredentialFactory) IPipeLineSession(nl.nn.adapterframework.core.IPipeLineSession) Session(org.apache.chemistry.opencmis.client.api.Session)

Example 3 with Session

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

the class AbstractSessionTest method run.

@Override
public void run() throws Exception {
    Session session;
    SessionParameterMap parameters = new SessionParameterMap(getParameters());
    if (!parameters.containsKey(SessionParameter.USER_AGENT)) {
        parameters.setUserAgent(TCK_USER_AGENT);
    }
    String repId = parameters.get(SessionParameter.REPOSITORY_ID);
    if (repId != null && repId.length() > 0) {
        session = factory.createSession(parameters);
    } else {
        session = factory.getRepositories(parameters).get(0).createSession();
    }
    // switch off the cache
    session.getDefaultContext().setCacheEnabled(false);
    try {
        run(session);
    } catch (Exception e) {
        if (!(e instanceof FatalTestException)) {
            addResult(createResult(UNEXPECTED_EXCEPTION, "Exception: " + e, e, true));
        }
    } catch (Error err) {
        addResult(createResult(UNEXPECTED_EXCEPTION, "Error: " + err, err, true));
    } finally {
        testFolder = null;
    }
}
Also used : SessionParameterMap(org.apache.chemistry.opencmis.client.SessionParameterMap) 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) Session(org.apache.chemistry.opencmis.client.api.Session)

Example 4 with Session

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

the class CMISDataCreatorTest method testCreateLots.

public void testCreateLots() throws Exception {
    Session session = getSession("admin", "admin");
    Folder root = session.getRootFolder();
    String folderNameBase = getRootFolderName();
    Map<String, Object> properties = new HashMap<String, Object>();
    properties.put(PropertyIds.OBJECT_TYPE_ID, "cmis:folder");
    properties.put(PropertyIds.NAME, folderNameBase);
    Folder base = root.createFolder(properties);
    for (int i = 0; i < 10; i++) {
        AccessControlPrincipalDataImpl principal = new AccessControlPrincipalDataImpl("" + i + i + i);
        List<String> permissions = new ArrayList<String>(1);
        permissions.add(BasicPermissions.ALL);
        List<Ace> addAces = new ArrayList<Ace>(1);
        addAces.add(new AccessControlEntryImpl(principal, permissions));
        base.addAcl(addAces, AclPropagation.PROPAGATE);
    }
    Thread last = null;
    for (int i = 0; i < 10; i++) {
        Creator creator = new Creator(base.getPath(), i);
        Thread thread = new Thread(creator);
        thread.start();
        last = thread;
    }
    if (last != null) {
        last.join();
    }
    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 5 with Session

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

the class CMISDataCreatorTest method testQueryFolderProperties.

public void testQueryFolderProperties() {
    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());
    String uniqueName = getUniqueName();
    Map<String, Object> uProperties = new HashMap<String, Object>();
    uProperties.put(PropertyIds.OBJECT_TYPE_ID, "cmis:folder");
    uProperties.put(PropertyIds.NAME, uniqueName);
    Folder uniqueFolder = newFolder.createFolder(uProperties);
    result = session.query("select * from cmis:folder where cmis:name = '" + uniqueName + "'", false);
    assertEquals(1, result.getTotalNumItems());
    result = session.query("select * from cmis:folder where cmis:name = '" + uniqueName + "' AND IN_FOLDER('" + uniqueFolder.getParentId() + "')", false);
    assertEquals(1, result.getTotalNumItems());
    result = session.query("select * from cmis:folder where IN_FOLDER('" + uniqueFolder.getParentId() + "')", false);
    assertEquals(1, result.getTotalNumItems());
    result = session.query("select * from cmis:folder where cmis:name = '" + uniqueName + "' AND cmis:createdBy = '" + uniqueFolder.getCreatedBy() + "'", false);
    assertEquals(1, result.getTotalNumItems());
    result = session.query("select * from cmis:folder where cmis:name = '" + uniqueName + "' AND cmis:objectId = '" + uniqueFolder.getId() + "'", false);
    assertEquals(1, result.getTotalNumItems());
    result = session.query("select * from cmis:folder where cmis:name = '" + uniqueName + "' AND cmis:lastModifiedBy = '" + uniqueFolder.getLastModifiedBy() + "'", false);
    assertEquals(1, result.getTotalNumItems());
    result = session.query("select * from cmis:folder where cmis:name = '" + uniqueFolder.getName() + "'", false);
    assertEquals(1, result.getTotalNumItems());
    String creationDate = ISO8601DateFormat.format(uniqueFolder.getCreationDate().getTime());
    result = session.query("select * from cmis:folder where cmis:name = '" + uniqueName + "' AND cmis:creationDate = '" + creationDate + "'", false);
    assertEquals(1, result.getTotalNumItems());
    String modificationDate = ISO8601DateFormat.format(uniqueFolder.getLastModificationDate().getTime());
    result = session.query("select * from cmis:folder where cmis:name = '" + uniqueName + "' AND cmis:lastModificationDate = '" + modificationDate + "'", false);
    assertEquals(1, result.getTotalNumItems());
    result = session.query("select * from cmis:folder where cmis:name = '" + uniqueName + "' AND cmis:objectTypeId = '" + uniqueFolder.getType().getQueryName() + "'", false);
    assertEquals(1, result.getTotalNumItems());
    result = session.query("select * from cmis:folder where cmis:name = '" + uniqueName + "' AND cmis:baseTypeId = '" + uniqueFolder.getBaseType().getQueryName() + "'", 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) 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