@Override public void afterPropertiesSet() throws Exception { String defaultRepositoryId = (String)cmisSessionInitProperties.get(SessionParameter.REPOSITORY_ID); if (defaultRepositoryId == null){ // If not repository is specified, the first repository is taken as default List<Repository> repositories = sessionFactory.getRepositories(cmisSessionInitProperties); Repository repository = repositories.get(0); cmisSessionInitProperties.put(SessionParameter.REPOSITORY_ID, repository.getId()); } }
public static String getRepositoryID(Map<String, String> parameters, String baseURL) { String repoID = null; try { logger.debug("Attempting to dynamically obtain the repository ID."); List<Repository> repositoryList = SessionFactoryImpl.newInstance().getRepositories(parameters); if (repositoryList.isEmpty()) { logger.error("No repositories were returned at the CMIS server URL \"" + baseURL + "\". " + "The connector is currently non-functional."); } else { // Get the first repo in the list. Repository firstRepo = repositoryList.get(0); // Extract the ID of this repo, and add it to the parameters list. repoID = firstRepo.getId(); logger.debug("The repository ID that will be used is " + repoID + "."); } } catch (Exception repoIDEx) { throw new CMISConnectorConnectionException("An error occurred while attempting to dynamically obtain a repository ID: " + repoIDEx.getMessage() + ". The connector is currently non-functional. ", repoIDEx); } return repoID; // end getRepositoryID }
protected Session getCmisSession() { if (cachedSession == null) { synchronized (this) { if (cachedSession == null) { Map<String, String> parameters = new HashMap<String, String>(); parameters.put(SessionParameter.USER, cmisUser); parameters.put(SessionParameter.PASSWORD, cmisPassword); parameters.put(SessionParameter.ATOMPUB_URL, cmisAtompubUrl); parameters.put(SessionParameter.BINDING_TYPE, BindingType.ATOMPUB.value()); // We're using the Alfresco extensions parameters.put(SessionParameter.OBJECT_FACTORY_CLASS, "org.alfresco.cmis.client.impl.AlfrescoObjectFactoryImpl"); // First need to fetch the repository info to know the repo id SessionFactory sessionFactory = SessionFactoryImpl.newInstance(); List<Repository> repositories = sessionFactory.getRepositories(parameters); String repositoryId = repositories.get(0).getId(); parameters.put(SessionParameter.REPOSITORY_ID, repositoryId); cachedSession = sessionFactory.createSession(parameters); } } } return cachedSession; }