org.apache.chemistry.opencmis.client.api.Document Java Examples
The following examples show how to use
org.apache.chemistry.opencmis.client.api.Document.
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: CmisSender.java From iaf with Apache License 2.0 | 6 votes |
private String sendMessageForActionDelete(String message, IPipeLineSession session) throws SenderException, TimeOutException { if (StringUtils.isEmpty(message)) { throw new SenderException(getLogPrefix() + "input string cannot be empty but must contain a documentId"); } CmisObject object = null; try { object = getCmisObject(message); } catch (CmisObjectNotFoundException e) { if (StringUtils.isNotEmpty(getResultOnNotFound())) { log.info(getLogPrefix() + "document with id [" + message + "] not found", e); return getResultOnNotFound(); } else { throw new SenderException(e); } } if (object.hasAllowableAction(Action.CAN_DELETE_OBJECT)) { //// You can delete Document suppDoc = (Document) object; suppDoc.delete(true); String correlationID = session==null ? null : session.getMessageId(); return correlationID; } else { //// You can't delete throw new SenderException(getLogPrefix() + "Document cannot be deleted"); } }
Example #2
Source File: CmisRead.java From cloud-espm-v2 with Apache License 2.0 | 6 votes |
/** * This is a custom implementation of the doGet method of the * {@link HttpServlet}. * <p> * Here, we expect an "objectId" to be passed as input parameter. This * objectId will be fetched to the {@link Session} to fetch the existing * document(if present). */ protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { final String objectId = request.getParameter("objectId"); try { if (openCmisSession != null) { Document doc = (Document) openCmisSession.getObject(objectId); ContentStream content = doc.getContentStream(); String type = content.getMimeType(); String name = content.getFileName(); int length = (int) content.getLength(); InputStream stream = content.getStream(); response.setContentType(type); response.setHeader("Content-Disposition", "attachment; filename*=UTF-8''" + name); response.setContentLength(length); ioCopy(stream, response.getOutputStream()); } else { response.setStatus(501); } } catch (Exception exception) { LOGGER.error(exception.getMessage()); } }
Example #3
Source File: OpenCmisLocalTest.java From alfresco-repository with GNU Lesser General Public License v3.0 | 6 votes |
private static Document createDocument(Folder target, String newDocName, Session session) { Map<String, String> props = new HashMap<String, String>(); props.put(PropertyIds.OBJECT_TYPE_ID, "cmis:document"); props.put(PropertyIds.NAME, newDocName); String content = "aegif Mind Share Leader Generating New Paradigms by aegif corporation."; byte[] buf = null; try { buf = content.getBytes("ISO-8859-1"); // set the encoding here for the content stream } catch (UnsupportedEncodingException e) { e.printStackTrace(); } ByteArrayInputStream input = new ByteArrayInputStream(buf); ContentStream contentStream = session.getObjectFactory().createContentStream(newDocName, buf.length, "text/plain; charset=UTF-8", input); // additionally set the charset here // NOTE that we intentionally specified the wrong charset here (as UTF-8) // because Alfresco does automatic charset detection, so we will ignore this explicit request return target.createDocument(props, contentStream, VersioningState.MAJOR); }
Example #4
Source File: CMISDataCreatorTest.java From SearchServices with GNU Lesser General Public License v3.0 | 6 votes |
private Document createUniqueDocument(Folder newFolder) throws UnsupportedEncodingException { String uniqueName = getUniqueName(); Map<String, Object> uProperties = new HashMap<String, Object>(); uProperties.put(PropertyIds.OBJECT_TYPE_ID, "cmis:document"); uProperties.put(PropertyIds.NAME, uniqueName); ContentStreamImpl contentStream = new ContentStreamImpl(); contentStream.setFileName("bob"); String shortString = "short"; contentStream.setStream(new ByteArrayInputStream(shortString.getBytes("UTF-8"))); contentStream.setLength(new BigInteger("5")); contentStream.setMimeType("text/plain"); Document uniqueDocument = newFolder.createDocument(uProperties, contentStream, VersioningState.MAJOR); return uniqueDocument; }
Example #5
Source File: SampleClient.java From document-management-software with GNU Lesser General Public License v3.0 | 5 votes |
/** * Delete test document * * @param target * @param delDocName */ private static void deleteDocument(Folder target, String delDocName) { try { CmisObject object = session.getObjectByPath(target.getPath() + delDocName); Document delDoc = (Document) object; delDoc.delete(true); } catch (CmisObjectNotFoundException e) { System.err.println("Document is not found: " + delDocName); } }
Example #6
Source File: PublicApiClient.java From alfresco-remote-api with GNU Lesser General Public License v3.0 | 5 votes |
public ObjectId checkoutObject(String objectId) { CmisObject o = getObject(objectId); if(o instanceof Document) { Document d = (Document)o; ObjectId res = d.checkOut(); return res; } else { throw new IllegalArgumentException("Object does not exist or is not a document"); } }
Example #7
Source File: PublicApiClient.java From alfresco-remote-api with GNU Lesser General Public License v3.0 | 5 votes |
public Document createDocument(String parentId, String name, Map<String, Serializable> properties, ContentStream contentStream, VersioningState versioningState) { CmisObject o = getObject(parentId); if(o instanceof Folder) { Folder f = (Folder)o; if(properties == null) { properties = new HashMap<String, Serializable>(); } String objectTypeId = (String)properties.get(PropertyIds.OBJECT_TYPE_ID); String type = "cmis:document"; if(objectTypeId == null) { objectTypeId = type; } if(objectTypeId.indexOf(type) == -1) { StringBuilder sb = new StringBuilder(objectTypeId); if(sb.length() > 0) { sb.append(","); } sb.append(type); objectTypeId = sb.toString(); } properties.put(PropertyIds.NAME, name); properties.put(PropertyIds.OBJECT_TYPE_ID, objectTypeId); Document res = f.createDocument(properties, contentStream, versioningState); return res; } else { throw new IllegalArgumentException("Parent does not exists or is not a folder"); } }
Example #8
Source File: PublicApiClient.java From alfresco-remote-api with GNU Lesser General Public License v3.0 | 5 votes |
public List<Document> getAllVersions(String objectId) { CmisObject o = getObject(objectId); if(o instanceof Document) { Document d = (Document)o; OperationContext ctx = new OperationContextImpl(); List<Document> res = d.getAllVersions(ctx); return res; } else { throw new IllegalArgumentException("Object does not exist or is not a document"); } }
Example #9
Source File: PublicApiClient.java From alfresco-remote-api with GNU Lesser General Public License v3.0 | 5 votes |
public void removeAllVersions(String objectId) { CmisObject o = getObject(objectId); if(o instanceof Document) { Document d = (Document)o; d.deleteAllVersions(); } else { throw new IllegalArgumentException("Object does not exist or is not a document"); } }
Example #10
Source File: PublicApiClient.java From alfresco-remote-api with GNU Lesser General Public License v3.0 | 5 votes |
public void putContent(String objectId, String filename, BigInteger length, String mimetype, InputStream content, boolean overwrite) { CmisObject o = getObject(objectId); if(o instanceof Document) { Document d = (Document)o; ContentStream contentStream = new ContentStreamImpl(filename, length, mimetype, content); try { d.setContentStream(contentStream, overwrite); } finally { try { contentStream.getStream().close(); } catch (Exception e) { } } } else { throw new IllegalArgumentException("Object does not exist or is not a document"); } }
Example #11
Source File: PublicApiClient.java From alfresco-remote-api with GNU Lesser General Public License v3.0 | 5 votes |
public ContentData getContent(String objectId) throws IOException { CmisObject o = getObject(objectId); if(o instanceof Document) { Document d = (Document)o; ContentStream res = d.getContentStream(); ContentData c = new ContentData(res); return c; } else { throw new IllegalArgumentException("Object does not exist or is not a document"); } }
Example #12
Source File: PublicApiClient.java From alfresco-remote-api with GNU Lesser General Public License v3.0 | 5 votes |
public void deleteContent(String objectId, boolean refresh) { CmisObject o = getObject(objectId); if(o instanceof Document) { Document d = (Document)o; d.deleteContentStream(refresh); } else { throw new IllegalArgumentException("Object does not exists or is not a document"); } }
Example #13
Source File: TestCMIS.java From alfresco-remote-api with GNU Lesser General Public License v3.0 | 5 votes |
private void checkSecondaryTypes(Document doc, Set<String> expectedSecondaryTypes, Set<String> expectedMissingSecondaryTypes) { final List<SecondaryType> secondaryTypesList = doc.getSecondaryTypes(); assertNotNull(secondaryTypesList); List<String> secondaryTypes = new AbstractList<String>() { @Override public String get(int index) { SecondaryType type = secondaryTypesList.get(index); return type.getId(); } @Override public int size() { return secondaryTypesList.size(); } }; if(expectedSecondaryTypes != null) { assertTrue("Missing secondary types: " + secondaryTypes, secondaryTypes.containsAll(expectedSecondaryTypes)); } if(expectedMissingSecondaryTypes != null) { assertTrue("Expected missing secondary types but at least one is still present: " + secondaryTypes, !secondaryTypes.containsAll(expectedMissingSecondaryTypes)); } }
Example #14
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 #15
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 #16
Source File: SampleClient.java From document-management-software with GNU Lesser General Public License v3.0 | 4 votes |
private static void checkoutCheckin() throws IOException { // Folder root = connect("admin", "admin"); // Folder root = connect("manager", "12345678"); // user solely in group // author Folder root = connect("admin", "12345678"); // user in groups // author and // admin root.getName(); CmisObject object = session.getObjectByPath(TEST_FOLDER_PATH); System.out.println(object.getId() + " " + object.getName()); object = session.getObjectByPath(TEST_FOLDER_PATH + "/" + TEST_DOCUMENT_NAME_1); System.out.println(object.getId() + " " + object.getProperty(PropertyIds.NAME).getValues().get(0)); Document pwc = (Document) object; ObjectId oid = pwc.checkOut(); // default values if the document has no content String filename = "test.txt"; String mimetype = "text/plain; fileNameCharset=UTF-8"; File myFile = new File("C:/tmp/test.txt"); FileInputStream fis = new FileInputStream(myFile); byte[] buf = IOUtils.toByteArray(fis); ByteArrayInputStream input = new ByteArrayInputStream(buf); ContentStream contentStream = session.getObjectFactory().createContentStream(filename, buf.length, mimetype, input); boolean major = false; // Check in the pwc try { Map<String, Object> properties = new HashMap<String, Object>(); properties.put("cmis:name","test-doc.txt"); pwc.checkIn(major, properties, contentStream, "minor version"); System.out.println("checkin completed!"); } catch (RuntimeException e) { e.printStackTrace(); System.out.println("checkin failed, trying to cancel the checkout"); try { pwc.cancelCheckOut(); // this can also generate a permission // exception System.out.println("checkout status canceled"); } catch (Exception e1) { // TODO Auto-generated catch block e1.printStackTrace(); } } }
Example #17
Source File: CmisIntegrationTest.java From wildfly-camel with Apache License 2.0 | 4 votes |
private String getDocumentContentAsString(String nodeId) throws Exception { CmisObject cmisObject = retrieveCMISObjectByIdFromServer(nodeId); Document doc = (Document)cmisObject; InputStream inputStream = doc.getContentStream().getStream(); return readFromStream(inputStream); }
Example #18
Source File: CmisTestObject.java From iaf with Apache License 2.0 | 4 votes |
@Override public Document copy(ObjectId targetFolderId, Map<String, ?> properties, VersioningState versioningState, List<Policy> policies, List<Ace> addACEs, List<Ace> removeACEs, OperationContext context) { // TODO Auto-generated method stub return null; }
Example #19
Source File: CmisTestObject.java From iaf with Apache License 2.0 | 4 votes |
@Override public Document copy(ObjectId targetFolderId) { // TODO Auto-generated method stub return null; }
Example #20
Source File: CmisTestObject.java From iaf with Apache License 2.0 | 4 votes |
@Override public List<Document> getAllVersions(OperationContext context) { // TODO Auto-generated method stub return null; }
Example #21
Source File: CmisTestObject.java From iaf with Apache License 2.0 | 4 votes |
@Override public List<Document> getAllVersions() { // TODO Auto-generated method stub return null; }
Example #22
Source File: CmisTestObject.java From iaf with Apache License 2.0 | 4 votes |
@Override public Document getObjectOfLatestVersion(boolean major, OperationContext context) { // TODO Auto-generated method stub return null; }
Example #23
Source File: CmisTestObject.java From iaf with Apache License 2.0 | 4 votes |
@Override public Document getObjectOfLatestVersion(boolean major) { // TODO Auto-generated method stub return null; }
Example #24
Source File: CmisTestObject.java From iaf with Apache License 2.0 | 4 votes |
@Override public Document deleteContentStream() { // TODO Auto-generated method stub return null; }
Example #25
Source File: CmisTestObject.java From iaf with Apache License 2.0 | 4 votes |
@Override public Document appendContentStream(ContentStream contentStream, boolean isLastChunk) { // TODO Auto-generated method stub return null; }
Example #26
Source File: CmisTestObject.java From iaf with Apache License 2.0 | 4 votes |
@Override public Document setContentStream(ContentStream contentStream, boolean overwrite) { // TODO Auto-generated method stub return null; }
Example #27
Source File: TestCMIS.java From alfresco-remote-api with GNU Lesser General Public License v3.0 | 4 votes |
@Test public void testMNT_10161() throws Exception { final TestNetwork network1 = getTestFixture().getRandomNetwork(); String username = "user" + System.currentTimeMillis(); PersonInfo personInfo = new PersonInfo(username, username, username, TEST_PASSWORD, null, null, null, null, null, null, null); TestPerson person1 = network1.createUser(personInfo); String person1Id = person1.getId(); final String siteName = "site" + System.currentTimeMillis(); final String nodeDescription = "Test description"; final String nodeName = GUID.generate(); TenantUtil.runAsUserTenant(new TenantRunAsWork<NodeRef>() { @Override public NodeRef doWork() throws Exception { SiteInformation siteInfo = new SiteInformation(siteName, siteName, siteName, SiteVisibility.PRIVATE); TestSite site = repoService.createSite(null, siteInfo); NodeRef folderNodeRef = repoService.createFolder(site.getContainerNodeRef(DOCUMENT_LIBRARY_CONTAINER_NAME), nodeName); /* create node with property description */ return repoService.createDocument(folderNodeRef, nodeName, "title", nodeDescription, "content"); } }, person1Id, network1.getId()); publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1Id)); CmisSession cmisSession = publicApiClient.createPublicApiCMISSession(Binding.atom, CMIS_VERSION_11); Document doc = (Document)cmisSession.getObjectByPath("/Sites/" + siteName + "/documentLibrary/" + nodeName + "/" + nodeName); /* ensure we got the node */ assertNotNull(doc); /* get mapped cmis:description */ Property<?> descrProperty = doc.getProperty(PropertyIds.DESCRIPTION); /* ensure that cmis:description is set properly */ assertTrue(nodeDescription.equals(descrProperty.getValue())); }
Example #28
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 #29
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)); }
Example #30
Source File: PublicApiClient.java From alfresco-remote-api with GNU Lesser General Public License v3.0 | 4 votes |
public ItemIterable<Document> getCheckedOutDocs() { OperationContextImpl ctx = new OperationContextImpl(); ItemIterable<Document> res = session.getCheckedOutDocs(ctx); return res; }