org.apache.chemistry.opencmis.client.api.Repository Java Examples
The following examples show how to use
org.apache.chemistry.opencmis.client.api.Repository.
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 |
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 |
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: OpenCmisLocalTest.java From alfresco-repository with GNU Lesser General Public License v3.0 | 5 votes |
public void DISABLED_testBasicFileOps() { Repository repository = getRepository("admin", "admin"); Session session = repository.createSession(); Folder rootFolder = session.getRootFolder(); // create folder Map<String,String> folderProps = new HashMap<String, String>(); { folderProps.put(PropertyIds.OBJECT_TYPE_ID, "cmis:folder"); folderProps.put(PropertyIds.NAME, getName() + "-" + GUID.generate()); } Folder folder = rootFolder.createFolder(folderProps, null, null, null, session.getDefaultContext()); Map<String, String> fileProps = new HashMap<String, String>(); { fileProps.put(PropertyIds.OBJECT_TYPE_ID, "cmis:document"); fileProps.put(PropertyIds.NAME, "mydoc-" + GUID.generate() + ".txt"); } ContentStreamImpl fileContent = new ContentStreamImpl(); { ContentWriter writer = new FileContentWriter(TempFileProvider.createTempFile(getName(), ".txt")); writer.putContent("Ipsum and so on"); ContentReader reader = writer.getReader(); fileContent.setMimeType(MimetypeMap.MIMETYPE_TEXT_PLAIN); fileContent.setStream(reader.getContentInputStream()); } folder.createDocument(fileProps, fileContent, VersioningState.MAJOR); }
Example #4
Source File: OpenCmisLocalTest.java From alfresco-repository with GNU Lesser General Public License v3.0 | 5 votes |
public void testDownloadEvent() throws InterruptedException { Repository repository = getRepository("admin", "admin"); Session session = repository.createSession(); Folder rootFolder = session.getRootFolder(); String docname = "mydoc-" + GUID.generate() + ".txt"; Map<String, String> props = new HashMap<String, String>(); { props.put(PropertyIds.OBJECT_TYPE_ID, "D:cmiscustom:document"); props.put(PropertyIds.NAME, docname); } // content byte[] byteContent = "Hello from Download testing class".getBytes(); InputStream stream = new ByteArrayInputStream(byteContent); ContentStream contentStream = new ContentStreamImpl(docname, BigInteger.valueOf(byteContent.length), "text/plain", stream); Document doc1 = rootFolder.createDocument(props, contentStream, VersioningState.MAJOR); NodeRef doc1NodeRef = cmisIdToNodeRef(doc1.getId()); ContentStream content = doc1.getContentStream(); assertNotNull(content); //range request content = doc1.getContentStream(BigInteger.valueOf(2),BigInteger.valueOf(4)); assertNotNull(content); }
Example #5
Source File: OpenCmisLocalTest.java From alfresco-repository with GNU Lesser General Public License v3.0 | 5 votes |
public void testEncodingForCreateContentStream() { ServiceRegistry serviceRegistry = (ServiceRegistry) ctx.getBean(ServiceRegistry.SERVICE_REGISTRY); FileFolderService ffs = serviceRegistry.getFileFolderService(); // Authenticate as system AuthenticationComponent authenticationComponent = (AuthenticationComponent) ctx .getBean(BEAN_NAME_AUTHENTICATION_COMPONENT); authenticationComponent.setSystemUserAsCurrentUser(); try { /* Create the document using openCmis services */ Repository repository = getRepository("admin", "admin"); Session session = repository.createSession(); Folder rootFolder = session.getRootFolder(); Document document = createDocument(rootFolder, "test_file_" + GUID.generate() + ".txt", session); ContentStream content = document.getContentStream(); assertNotNull(content); content = document.getContentStream(BigInteger.valueOf(2), BigInteger.valueOf(4)); assertNotNull(content); NodeRef doc1NodeRef = cmisIdToNodeRef(document.getId()); FileInfo fileInfo = ffs.getFileInfo(doc1NodeRef); Map<QName, Serializable> properties = fileInfo.getProperties(); ContentDataWithId contentData = (ContentDataWithId) properties .get(QName.createQName("{http://www.alfresco.org/model/content/1.0}content")); String encoding = contentData.getEncoding(); assertEquals("ISO-8859-1", encoding); } finally { authenticationComponent.clearCurrentSecurityContext(); } }
Example #6
Source File: TestCMIS.java From alfresco-remote-api with GNU Lesser General Public License v3.0 | 5 votes |
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 #7
Source File: PublicApiClient.java From alfresco-remote-api with GNU Lesser General Public License v3.0 | 5 votes |
/** * 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 #8
Source File: PublicApiClient.java From alfresco-remote-api with GNU Lesser General Public License v3.0 | 5 votes |
public CmisSession getCMISSession(Repository respository) { RequestContext rc = getRequestContext(); if(rc == null) { throw new RuntimeException("Must set a request context"); } CmisSession session = createCMISSession(respository.getId(), rc); return session; }
Example #9
Source File: PublicApiClient.java From alfresco-remote-api with GNU Lesser General Public License v3.0 | 5 votes |
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 #10
Source File: CmisIntegrationTest.java From wildfly-camel with Apache License 2.0 | 5 votes |
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 #11
Source File: OpenCmisLocalTest.java From alfresco-repository with GNU Lesser General Public License v3.0 | 4 votes |
public void DISABLED_testSetUp() throws Exception { Repository repository = getRepository("admin", "admin"); assertNotNull("No repository available for testing", repository); }
Example #12
Source File: OpenCmisLocalTest.java From alfresco-repository with GNU Lesser General Public License v3.0 | 4 votes |
public void testALF10085() throws InterruptedException { Repository repository = getRepository("admin", "admin"); Session session = repository.createSession(); Folder rootFolder = session.getRootFolder(); Map<String, String> props = new HashMap<String, String>(); { props.put(PropertyIds.OBJECT_TYPE_ID, "D:cmiscustom:document"); props.put(PropertyIds.NAME, "mydoc-" + GUID.generate() + ".txt"); } Document doc1 = rootFolder.createDocument(props, null, null); props = new HashMap<String, String>(); { props.put(PropertyIds.OBJECT_TYPE_ID, "D:cmiscustom:document"); props.put(PropertyIds.NAME, "mydoc-" + GUID.generate() + ".txt"); } Document doc2 = rootFolder.createDocument(props, null, null); Thread.sleep(6000); session.getObject(doc1); doc1.refresh(); Calendar doc1LastModifiedBefore = (Calendar)doc1.getProperty(PropertyIds.LAST_MODIFICATION_DATE).getFirstValue(); assertNotNull(doc1LastModifiedBefore); doc2.refresh(); Calendar doc2LastModifiedBefore = (Calendar)doc2.getProperty(PropertyIds.LAST_MODIFICATION_DATE).getFirstValue(); assertNotNull(doc2LastModifiedBefore); // Add relationship A to B props = new HashMap<String, String>(); { props.put(PropertyIds.OBJECT_TYPE_ID, "R:cmiscustom:assoc"); props.put(PropertyIds.NAME, "A Relationship"); props.put(PropertyIds.SOURCE_ID, doc1.getId()); props.put(PropertyIds.TARGET_ID, doc2.getId()); } session.createRelationship(props); doc1.refresh(); Calendar doc1LastModifiedAfter = (Calendar)doc1.getProperty(PropertyIds.LAST_MODIFICATION_DATE).getFirstValue(); assertNotNull(doc1LastModifiedAfter); doc2.refresh(); Calendar doc2LastModifiedAfter = (Calendar)doc2.getProperty(PropertyIds.LAST_MODIFICATION_DATE).getFirstValue(); assertNotNull(doc2LastModifiedAfter); assertEquals(doc1LastModifiedBefore, doc1LastModifiedAfter); assertEquals(doc2LastModifiedBefore, doc2LastModifiedAfter); }
Example #13
Source File: OpenCmisLocalTest.java From alfresco-repository with GNU Lesser General Public License v3.0 | 4 votes |
/** * MNT-14687 - Creating a document as checkedout and then cancelling the * checkout should delete the document. * * This test would have fit better within CheckOutCheckInServiceImplTest but * was added here to make use of existing methods */ public void testCancelCheckoutWhileInCheckedOutState() { ServiceRegistry serviceRegistry = (ServiceRegistry) ctx.getBean(ServiceRegistry.SERVICE_REGISTRY); CheckOutCheckInService cociService = serviceRegistry.getCheckOutCheckInService(); // Authenticate as system AuthenticationComponent authenticationComponent = (AuthenticationComponent) ctx.getBean(BEAN_NAME_AUTHENTICATION_COMPONENT); authenticationComponent.setSystemUserAsCurrentUser(); /* Create the document using openCmis services */ Repository repository = getRepository("admin", "admin"); Session session = repository.createSession(); Folder rootFolder = session.getRootFolder(); // Set file properties String docname = "myDoc-" + GUID.generate() + ".txt"; Map<String, String> props = new HashMap<String, String>(); { props.put(PropertyIds.OBJECT_TYPE_ID, BaseTypeId.CMIS_DOCUMENT.value()); props.put(PropertyIds.NAME, docname); } // Create some content byte[] byteContent = "Some content".getBytes(); InputStream stream = new ByteArrayInputStream(byteContent); ContentStream contentStream = new ContentStreamImpl(docname, BigInteger.valueOf(byteContent.length), MIME_PLAIN_TEXT, stream); // Create the document Document doc1 = rootFolder.createDocument(props, contentStream, VersioningState.CHECKEDOUT); NodeRef doc1NodeRef = cmisIdToNodeRef(doc1.getId()); NodeRef doc1WorkingCopy = cociService.getWorkingCopy(doc1NodeRef); /* Cancel Checkout */ cociService.cancelCheckout(doc1WorkingCopy); /* Check if both the working copy and the document were deleted */ NodeService nodeService = serviceRegistry.getNodeService(); assertFalse(nodeService.exists(doc1NodeRef)); assertFalse(nodeService.exists(doc1WorkingCopy)); }