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;
}
Aggregations