use of org.apache.chemistry.opencmis.client.api.Document in project camel by apache.
the class RecursiveTreeWalker method processNonFolderNode.
private void processNonFolderNode(CmisObject cmisObject, Folder parentFolder) throws Exception {
InputStream inputStream = null;
Map<String, Object> properties = CMISHelper.objectProperties(cmisObject);
properties.put(CamelCMISConstants.CMIS_FOLDER_PATH, parentFolder.getPath());
if (CMISHelper.isDocument(cmisObject) && readContent) {
ContentStream contentStream = ((Document) cmisObject).getContentStream();
if (contentStream != null) {
inputStream = contentStream.getStream();
}
}
sendNode(properties, inputStream);
}
use of org.apache.chemistry.opencmis.client.api.Document in project camel by apache.
the class CMISProducerTest method getDocumentMimeTypeFromMessageContentType.
@Test
public void getDocumentMimeTypeFromMessageContentType() throws Exception {
Exchange exchange = createExchangeWithInBody("Some content to be store");
exchange.getIn().getHeaders().put(Exchange.CONTENT_TYPE, "text/plain");
exchange.getIn().getHeaders().put(PropertyIds.NAME, "test.file");
template.send(exchange);
String newNodeId = exchange.getOut().getBody(String.class);
CmisObject cmisObject = retrieveCMISObjectByIdFromServer(newNodeId);
Document doc = (Document) cmisObject;
assertEquals("text/plain", doc.getPropertyValue(PropertyIds.CONTENT_STREAM_MIME_TYPE));
}
use of org.apache.chemistry.opencmis.client.api.Document in project camel by apache.
the class CMISProducerTest method createDocumentAtSpecificPath.
@Test
public void createDocumentAtSpecificPath() throws Exception {
Folder folder1 = createFolderWithName("Folder1");
createChildFolderWithName(folder1, "Folder2");
String existingFolderStructure = "/Folder1/Folder2";
Exchange exchange = createExchangeWithInBody("Some content to be stored");
exchange.getIn().getHeaders().put(PropertyIds.CONTENT_STREAM_MIME_TYPE, "text/plain; charset=UTF-8");
exchange.getIn().getHeaders().put(PropertyIds.NAME, "test.file");
exchange.getIn().getHeaders().put(CamelCMISConstants.CMIS_FOLDER_PATH, existingFolderStructure);
template.send(exchange);
String newNodeId = exchange.getOut().getBody(String.class);
Document document = (Document) retrieveCMISObjectByIdFromServer(newNodeId);
String documentFullPath = document.getPaths().get(0);
assertEquals(existingFolderStructure + "/test.file", documentFullPath);
}
use of org.apache.chemistry.opencmis.client.api.Document in project alfresco-remote-api by Alfresco.
the class TestCMIS method testMNT_10161.
/* MNT-10161 related test - mapping of cmis:description for CMIS 1.1 */
@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()));
}
use of org.apache.chemistry.opencmis.client.api.Document in project alfresco-remote-api by Alfresco.
the class TestCMIS method testContentDisposition_MNT_17477.
@Test
public void testContentDisposition_MNT_17477() 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();
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1Id));
CmisSession cmisSession = publicApiClient.createPublicApiCMISSession(Binding.browser, CMIS_VERSION_11, AlfrescoObjectFactoryImpl.class.getName());
Folder folder = (Folder) cmisSession.getObjectByPath("/Shared");
//
// Upload test JPG document
//
String name = GUID.generate() + ".jpg";
Map<String, Object> properties = new HashMap<>();
{
properties.put(PropertyIds.OBJECT_TYPE_ID, TYPE_CMIS_DOCUMENT);
properties.put(PropertyIds.NAME, name);
}
ContentStreamImpl fileContent = new ContentStreamImpl();
{
fileContent.setMimeType(MimetypeMap.MIMETYPE_IMAGE_JPEG);
fileContent.setStream(this.getClass().getResourceAsStream("/test.jpg"));
}
Document doc = folder.createDocument(properties, fileContent, VersioningState.MAJOR);
String docId = doc.getId();
// note: Content-Disposition can be "inline or "attachment" for content types that are white-listed (eg. specific image types & pdf)
HttpResponse response = publicApiClient.get(network1.getId() + "/public/cmis/versions/1.1/browser/root/Shared/" + name, null);
assertEquals(200, response.getStatusCode());
assertTrue(response.getHeaders().get("Content-Disposition").startsWith("inline"));
response = publicApiClient.get(network1.getId() + "/public/cmis/versions/1.1/browser/root/Shared/" + name + "?download=inline", null);
assertEquals(200, response.getStatusCode());
assertTrue(response.getHeaders().get("Content-Disposition").startsWith("inline"));
response = publicApiClient.get(network1.getId() + "/public/cmis/versions/1.1/browser/root/Shared/" + name + "?download=attachment", null);
assertEquals(200, response.getStatusCode());
assertTrue(response.getHeaders().get("Content-Disposition").startsWith("attachment"));
// note: AtomPub binding (via OpenCMIS) does not support "download" query parameter
response = publicApiClient.get(network1.getId() + "/public/cmis/versions/1.1/atom/content?id=" + docId, null);
assertEquals(200, response.getStatusCode());
assertTrue(response.getHeaders().get("Content-Disposition").startsWith("attachment"));
//
// Create test HTML document
//
name = GUID.generate() + ".html";
properties = new HashMap<>();
{
properties.put(PropertyIds.OBJECT_TYPE_ID, TYPE_CMIS_DOCUMENT);
properties.put(PropertyIds.NAME, name);
}
fileContent = new ContentStreamImpl();
{
ContentWriter writer = new FileContentWriter(TempFileProvider.createTempFile(GUID.generate(), ".html"));
writer.putContent("<html><script>alert(123);</script><body>Hello <b>world</b></body</html>");
ContentReader reader = writer.getReader();
fileContent.setMimeType(MimetypeMap.MIMETYPE_HTML);
fileContent.setStream(reader.getContentInputStream());
}
doc = folder.createDocument(properties, fileContent, VersioningState.MAJOR);
docId = doc.getId();
// note: Content-Disposition will always be "attachment" for content types that are not white-listed
response = publicApiClient.get(network1.getId() + "/public/cmis/versions/1.1/browser/root/Shared/" + name, null);
assertEquals(200, response.getStatusCode());
assertTrue(response.getHeaders().get("Content-Disposition").startsWith("attachment;"));
response = publicApiClient.get(network1.getId() + "/public/cmis/versions/1.1/browser/root/Shared/" + name + "?download=inline", null);
assertEquals(200, response.getStatusCode());
assertTrue(response.getHeaders().get("Content-Disposition").startsWith("attachment;"));
// note: AtomPub binding (via OpenCMIS) does not support "download" query parameter
response = publicApiClient.get(network1.getId() + "/public/cmis/versions/1.1/atom/content?id=" + docId, null);
assertEquals(200, response.getStatusCode());
assertTrue(response.getHeaders().get("Content-Disposition").startsWith("attachment;"));
}
Aggregations