use of org.apache.chemistry.opencmis.client.api.ObjectId in project copper-cms by PogeyanOSS.
the class SetAndDeleteContentTest method run.
@Override
public void run(Session session) {
CmisTestResult f;
if (getContentStreamUpdatesCapbility(session) == CapabilityContentStreamUpdates.NONE) {
addResult(createResult(SKIPPED, "Stream updates are not supported. Test skipped!"));
return;
}
try {
// create folder and document
Folder testFolder = createTestFolder(session);
Document doc = createDocument(session, testFolder, "contenttest.txt", CONTENT1);
Document workDoc = doc;
DocumentTypeDefinition docType = (DocumentTypeDefinition) doc.getType();
// test if check out is required and possible
boolean checkedout = false;
if (!doc.getAllowableActions().getAllowableActions().contains(Action.CAN_SET_CONTENT_STREAM)) {
if (!docType.isVersionable()) {
addResult(createResult(SKIPPED, "The test document does not accept a new content stream. Test skipped!"));
doc.delete(true);
return;
} else {
workDoc = (Document) session.getObject(doc.checkOut(), SELECT_ALL_NO_CACHE_OC);
checkedout = true;
if (!workDoc.getAllowableActions().getAllowableActions().contains(Action.CAN_SET_CONTENT_STREAM)) {
addResult(createResult(SKIPPED, "The test PWC does not accept a new content stream. Test skipped!"));
workDoc.cancelCheckOut();
doc.delete(true);
return;
}
}
}
// test if the content stream can be deleted
if (docType.getContentStreamAllowed() == ContentStreamAllowed.REQUIRED) {
addResult(createResult(SKIPPED, "A content stream is required for this document type. deleteContentStream() test skipped!"));
} else {
// delete content stream
try {
ObjectId newObjectId = workDoc.deleteContentStream(true);
// deleteContentStream may have created a new version
Document contentDoc = getNewVersion(session, workDoc, checkedout, newObjectId, "deleteContentStream()");
f = createResult(FAILURE, "Document still has content after deleteContentStream() has been called!");
addResult(assertNull(contentDoc.getContentStream(), null, f));
f = createResult(FAILURE, "Document still has a MIME type after deleteContentStream() has been called: " + contentDoc.getContentStreamMimeType());
addResult(assertNull(contentDoc.getContentStreamMimeType(), null, f));
f = createResult(FAILURE, "Document still has a content length after deleteContentStream() has been called: " + contentDoc.getContentStreamLength());
addResult(assertEquals(-1L, contentDoc.getContentStreamLength(), null, f));
f = createResult(FAILURE, "Document still has a file name after deleteContentStream() has been called: " + contentDoc.getContentStreamFileName());
addResult(assertNull(contentDoc.getContentStreamFileName(), null, f));
workDoc = contentDoc;
} catch (CmisNotSupportedException e) {
addResult(createResult(WARNING, "deleteContentStream() is not supported!"));
}
}
// set a new content stream
byte[] contentBytes = IOUtils.toUTF8Bytes(CONTENT2);
try {
ContentStream contentStream = session.getObjectFactory().createContentStream(workDoc.getName(), contentBytes.length, "text/plain", new ByteArrayInputStream(contentBytes));
ObjectId newObjectId = workDoc.setContentStream(contentStream, true, true);
IOUtils.closeQuietly(contentStream);
// setContentStream may have created a new version
Document contentDoc = getNewVersion(session, workDoc, checkedout, newObjectId, "setContentStream()");
// test new content
try {
String content = getStringFromContentStream(contentDoc.getContentStream());
f = createResult(FAILURE, "Document content doesn't match the content set by setContentStream()!");
addResult(assertEquals(CONTENT2, content, null, f));
} catch (IOException e) {
addResult(createResult(UNEXPECTED_EXCEPTION, "Document content couldn't be read! Exception: " + e.getMessage(), e, true));
}
workDoc = contentDoc;
} catch (CmisNotSupportedException e) {
addResult(createResult(WARNING, "setContentStream() is not supported!"));
}
// test appendContentStream
if (session.getRepositoryInfo().getCmisVersion() != CmisVersion.CMIS_1_0) {
contentBytes = IOUtils.toUTF8Bytes(CONTENT3);
try {
ContentStream contentStream = session.getObjectFactory().createContentStream(workDoc.getName(), contentBytes.length, "text/plain", new ByteArrayInputStream(contentBytes));
ObjectId newObjectId = workDoc.appendContentStream(contentStream, true);
// appendContentStream may have created a new version
Document contentDoc = getNewVersion(session, workDoc, checkedout, newObjectId, "appendContentStream()");
// test new content
try {
String content = getStringFromContentStream(contentDoc.getContentStream());
f = createResult(FAILURE, "Document content doesn't match the content set by setContentStream() followed by appendContentStream()!");
addResult(assertEquals(CONTENT2 + CONTENT3, content, null, f));
} catch (IOException e) {
addResult(createResult(UNEXPECTED_EXCEPTION, "Document content couldn't be read! Exception: " + e.getMessage(), e, true));
}
// test append stream
testAppendStream(session, testFolder, 16 * 1024);
testAppendStream(session, testFolder, 8);
testAppendStream(session, testFolder, 0);
} catch (CmisNotSupportedException e) {
addResult(createResult(WARNING, "appendContentStream() is not supported!"));
}
}
// cancel a possible check out
if (checkedout) {
workDoc.cancelCheckOut();
}
// remove the document
deleteObject(doc);
} finally {
deleteTestFolder();
}
}
use of org.apache.chemistry.opencmis.client.api.ObjectId in project copper-cms by PogeyanOSS.
the class UpdateSmokeTest method updateFolder.
private void updateFolder(Session session, Folder testFolder) {
CmisTestResult f;
Folder folder = createFolder(session, testFolder, FOLDER_NAME1);
f = createResult(FAILURE, "Folder name doesn't match the given name!");
addResult(assertEquals(FOLDER_NAME1, folder.getName(), null, f));
// update
Map<String, Object> properties = new HashMap<String, Object>();
properties.put(PropertyIds.NAME, FOLDER_NAME2);
ObjectId newId = folder.updateProperties(properties, false);
f = createResult(WARNING, "Folder id changed after name update! The folder id should never change!");
addResult(assertEquals(folder.getId(), newId.getId(), null, f));
// get the new folder object and check the new name
folder.refresh();
f = createResult(FAILURE, "Folder name doesn't match updated value!");
addResult(assertEquals(FOLDER_NAME2, folder.getName(), null, f));
// update again with the same name
folder.rename(FOLDER_NAME2, true);
f = createResult(FAILURE, "Folder name doesn't match updated value!");
addResult(assertEquals(FOLDER_NAME2, folder.getName(), null, f));
deleteObject(folder);
}
use of org.apache.chemistry.opencmis.client.api.ObjectId in project iaf by ibissource.
the class CmisSender method sendMessageForActionCreate.
private String sendMessageForActionCreate(String correlationID, String message, ParameterResolutionContext prc) throws SenderException, TimeOutException {
String fileName = (String) prc.getSession().get(getFileNameSessionKey());
InputStream inputStream = null;
if (StringUtils.isNotEmpty(fileInputStreamSessionKey)) {
inputStream = (FileInputStream) prc.getSession().get(getFileInputStreamSessionKey());
} else {
String fileContent = (String) prc.getSession().get(getFileContentSessionKey());
byte[] bytes = Base64.decodeBase64((String) fileContent);
inputStream = new ByteArrayInputStream(bytes);
}
long fileLength = 0;
try {
fileLength = inputStream.available();
} catch (IOException e) {
log.warn(getLogPrefix() + "could not determine file size", e);
}
String mediaType;
Map props = new HashMap();
Element cmisElement;
try {
if (XmlUtils.isWellFormed(message, "cmis")) {
cmisElement = XmlUtils.buildElement(message);
} else {
cmisElement = XmlUtils.buildElement("<cmis/>");
}
String objectTypeId = XmlUtils.getChildTagAsString(cmisElement, "objectTypeId");
if (StringUtils.isNotEmpty(objectTypeId)) {
props.put(PropertyIds.OBJECT_TYPE_ID, objectTypeId);
} else {
props.put(PropertyIds.OBJECT_TYPE_ID, "cmis:document");
}
String name = XmlUtils.getChildTagAsString(cmisElement, "name");
if (StringUtils.isEmpty(fileName)) {
fileName = XmlUtils.getChildTagAsString(cmisElement, "fileName");
}
mediaType = XmlUtils.getChildTagAsString(cmisElement, "mediaType");
if (StringUtils.isNotEmpty(name)) {
props.put(PropertyIds.NAME, name);
} else if (StringUtils.isNotEmpty(fileName)) {
props.put(PropertyIds.NAME, fileName);
} else {
props.put(PropertyIds.NAME, "[unknown]");
}
Element propertiesElement = XmlUtils.getFirstChildTag(cmisElement, "properties");
if (propertiesElement != null) {
processProperties(propertiesElement, props);
}
} catch (DomBuilderException e) {
throw new SenderException(getLogPrefix() + "exception parsing [" + message + "]", e);
}
if (StringUtils.isEmpty(mediaType)) {
mediaType = getDefaultMediaType();
}
if (isUseRootFolder()) {
Folder folder = session.getRootFolder();
ContentStream contentStream = session.getObjectFactory().createContentStream(fileName, fileLength, mediaType, inputStream);
Document document = folder.createDocument(props, contentStream, null);
log.debug(getLogPrefix() + "created new document [ " + document.getId() + "]");
return document.getId();
} else {
ContentStream contentStream = session.getObjectFactory().createContentStream(fileName, fileLength, mediaType, inputStream);
ObjectId objectId = session.createDocument(props, null, contentStream, null);
log.debug(getLogPrefix() + "created new document [ " + objectId.getId() + "]");
return objectId.getId();
}
}
use of org.apache.chemistry.opencmis.client.api.ObjectId in project alfresco-remote-api by Alfresco.
the class TestCMIS method testCMIS.
/**
* Tests OpenCMIS api.
*/
@SuppressWarnings("unchecked")
@Test
public void testCMIS() throws Exception {
// Test Case cloud-2353
// Test Case cloud-2354
// Test Case cloud-2356
// Test Case cloud-2378
// Test Case cloud-2357
// Test Case cloud-2358
// Test Case cloud-2360
final TestNetwork network1 = getTestFixture().getRandomNetwork();
Iterator<String> personIt = network1.getPersonIds().iterator();
final String personId = personIt.next();
assertNotNull(personId);
Person person = repoService.getPerson(personId);
assertNotNull(person);
// Create a site
final TestSite site = TenantUtil.runAsUserTenant(new TenantRunAsWork<TestSite>() {
@Override
public TestSite doWork() throws Exception {
String siteName = "site" + System.currentTimeMillis();
SiteInformation siteInfo = new SiteInformation(siteName, siteName, siteName, SiteVisibility.PRIVATE);
TestSite site = network1.createSite(siteInfo);
return site;
}
}, personId, network1.getId());
publicApiClient.setRequestContext(new RequestContext(network1.getId(), personId));
CmisSession cmisSession = publicApiClient.createPublicApiCMISSession(Binding.atom, CMIS_VERSION_10, AlfrescoObjectFactoryImpl.class.getName());
Nodes nodesProxy = publicApiClient.nodes();
Comments commentsProxy = publicApiClient.comments();
String expectedContent = "Ipsum and so on";
Document doc = null;
Folder documentLibrary = (Folder) cmisSession.getObjectByPath("/Sites/" + site.getSiteId() + "/documentLibrary");
FolderNode expectedDocumentLibrary = (FolderNode) CMISNode.createNode(documentLibrary);
Document testDoc = null;
Folder testFolder = null;
FolderNode testFolderNode = null;
// create some sub-folders and documents
{
for (int i = 0; i < 3; i++) {
Map<String, String> properties = new HashMap<String, String>();
{
properties.put(PropertyIds.OBJECT_TYPE_ID, "cmis:folder");
properties.put(PropertyIds.NAME, "folder-" + i);
}
Folder f = documentLibrary.createFolder(properties);
FolderNode fn = (FolderNode) CMISNode.createNode(f);
if (testFolder == null) {
testFolder = f;
testFolderNode = fn;
}
expectedDocumentLibrary.addFolder(fn);
for (int k = 0; k < 3; k++) {
properties = new HashMap<String, String>();
{
properties.put(PropertyIds.OBJECT_TYPE_ID, "cmis:folder");
properties.put(PropertyIds.NAME, "folder-" + k);
}
Folder f1 = f.createFolder(properties);
FolderNode childFolder = (FolderNode) CMISNode.createNode(f1);
fn.addFolder(childFolder);
}
for (int j = 0; j < 3; j++) {
properties = new HashMap<String, String>();
{
properties.put(PropertyIds.OBJECT_TYPE_ID, TYPE_CMIS_DOCUMENT);
properties.put(PropertyIds.NAME, "doc-" + j);
}
ContentStreamImpl fileContent = new ContentStreamImpl();
{
ContentWriter writer = new FileContentWriter(TempFileProvider.createTempFile(GUID.generate(), ".txt"));
writer.putContent(expectedContent);
ContentReader reader = writer.getReader();
fileContent.setMimeType(MimetypeMap.MIMETYPE_TEXT_PLAIN);
fileContent.setStream(reader.getContentInputStream());
}
Document d = f.createDocument(properties, fileContent, VersioningState.MAJOR);
if (testDoc == null) {
testDoc = d;
}
CMISNode childDocument = CMISNode.createNode(d);
fn.addNode(childDocument);
}
}
for (int i = 0; i < 10; i++) {
Map<String, String> properties = new HashMap<String, String>();
{
properties.put(PropertyIds.OBJECT_TYPE_ID, TYPE_CMIS_DOCUMENT);
properties.put(PropertyIds.NAME, "doc-" + i);
}
ContentStreamImpl fileContent = new ContentStreamImpl();
{
ContentWriter writer = new FileContentWriter(TempFileProvider.createTempFile(GUID.generate(), ".txt"));
writer.putContent(expectedContent);
ContentReader reader = writer.getReader();
fileContent.setMimeType(MimetypeMap.MIMETYPE_TEXT_PLAIN);
fileContent.setStream(reader.getContentInputStream());
}
documentLibrary.createDocument(properties, fileContent, VersioningState.MAJOR);
}
}
// try to add and remove ratings, comments, tags to folders created by CMIS
{
Aggregate aggregate = new Aggregate(1, null);
NodeRating expectedNodeRating = new NodeRating("likes", true, aggregate);
Comment expectedComment = new Comment("commenty", "commenty", false, null, person, person);
Tag expectedTag = new Tag("taggy");
NodeRating rating = nodesProxy.createNodeRating(testFolder.getId(), expectedNodeRating);
expectedNodeRating.expected(rating);
assertNotNull(rating.getId());
// REPO-2028 - remove lucene tests
// Tag tag = nodesProxy.createNodeTag(testFolder.getId(), expectedTag);
// expectedTag.expected(tag);
// assertNotNull(tag.getId());
Comment comment = commentsProxy.createNodeComment(testFolder.getId(), expectedComment);
expectedComment.expected(comment);
assertNotNull(comment.getId());
}
// try to add and remove ratings, comments, tags to documents created by CMIS
{
Aggregate aggregate = new Aggregate(1, null);
NodeRating expectedNodeRating = new NodeRating("likes", true, aggregate);
Comment expectedComment = new Comment("commenty", "commenty", false, null, person, person);
Tag expectedTag = new Tag("taggy");
NodeRating rating = nodesProxy.createNodeRating(testDoc.getId(), expectedNodeRating);
expectedNodeRating.expected(rating);
assertNotNull(rating.getId());
// REPO-2028 - remove lucene tests
// Tag tag = nodesProxy.createNodeTag(testDoc.getId(), expectedTag);
// expectedTag.expected(tag);
// assertNotNull(tag.getId());
Comment comment = commentsProxy.createNodeComment(testDoc.getId(), expectedComment);
expectedComment.expected(comment);
assertNotNull(comment.getId());
}
// descendants
{
List<Tree<FileableCmisObject>> descendants = documentLibrary.getDescendants(4);
expectedDocumentLibrary.checkDescendants(descendants);
}
// upload/setContent
{
Map<String, String> fileProps = new HashMap<String, String>();
{
fileProps.put(PropertyIds.OBJECT_TYPE_ID, TYPE_CMIS_DOCUMENT);
fileProps.put(PropertyIds.NAME, "mydoc-" + GUID.generate() + ".txt");
}
ContentStreamImpl fileContent = new ContentStreamImpl();
{
ContentWriter writer = new FileContentWriter(TempFileProvider.createTempFile(GUID.generate(), ".txt"));
writer.putContent(expectedContent);
ContentReader reader = writer.getReader();
fileContent.setMimeType(MimetypeMap.MIMETYPE_TEXT_PLAIN);
fileContent.setStream(reader.getContentInputStream());
}
doc = documentLibrary.createDocument(fileProps, fileContent, VersioningState.MAJOR);
String nodeId = stripCMISSuffix(doc.getId());
final NodeRef nodeRef = new NodeRef(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, nodeId);
ContentReader reader = TenantUtil.runAsUserTenant(new TenantRunAsWork<ContentReader>() {
@Override
public ContentReader doWork() throws Exception {
ContentReader reader = repoService.getContent(nodeRef, ContentModel.PROP_CONTENT);
return reader;
}
}, personId, network1.getId());
String actualContent = reader.getContentString();
assertEquals(expectedContent, actualContent);
}
// get content
{
ContentStream stream = doc.getContentStream();
StringWriter writer = new StringWriter();
IOUtils.copy(stream.getStream(), writer, "UTF-8");
String actualContent = writer.toString();
assertEquals(expectedContent, actualContent);
}
// get children
{
Folder folder = (Folder) cmisSession.getObjectByPath("/Sites/" + site.getSiteId() + "/documentLibrary/" + testFolder.getName());
ItemIterable<CmisObject> children = folder.getChildren();
testFolderNode.checkChildren(children);
}
// REPO-2028 - remove lucene tests
// query
// {
// Folder folder = (Folder)cmisSession.getObjectByPath("/Sites/" + site.getSiteId() + "/documentLibrary/" + testFolder.getName());
// String folderId = folder.getId();
//
// Set<String> expectedFolderNames = new HashSet<String>();
// for(CMISNode n : testFolderNode.getFolderNodes().values())
// {
// expectedFolderNames.add((String)n.getProperty("cmis:name"));
// }
// int expectedNumFolders = expectedFolderNames.size();
// int numMatchingFoldersFound = 0;
// List<CMISNode> results = cmisSession.query("SELECT * FROM cmis:folder WHERE IN_TREE('" + folderId + "')", false, 0, Integer.MAX_VALUE);
// for(CMISNode node : results)
// {
// String name = (String)node.getProperties().get("cmis:name");
// if(expectedFolderNames.contains(name))
// {
// numMatchingFoldersFound++;
// }
// }
// assertEquals(expectedNumFolders, numMatchingFoldersFound);
//
// Set<String> expectedDocNames = new HashSet<String>();
// for(CMISNode n : testFolderNode.getDocumentNodes().values())
// {
// expectedDocNames.add((String)n.getProperty("cmis:name"));
// }
// int expectedNumDocs = expectedDocNames.size();
// int numMatchingDocsFound = 0;
// results = cmisSession.query("SELECT * FROM cmis:document where IN_TREE('" + folderId + "')", false, 0, Integer.MAX_VALUE);
// for(CMISNode node : results)
// {
// String name = (String)node.getProperties().get("cmis:name");
// if(expectedDocNames.contains(name))
// {
// numMatchingDocsFound++;
// }
// }
// assertEquals(expectedNumDocs, numMatchingDocsFound);
// }
// versioning
{
String nodeId = stripCMISSuffix(doc.getId());
final NodeRef nodeRef = new NodeRef(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, nodeId);
// checkout
ObjectId pwcId = doc.checkOut();
Document pwc = (Document) cmisSession.getObject(pwcId.getId());
Boolean isCheckedOut = TenantUtil.runAsUserTenant(new TenantRunAsWork<Boolean>() {
@Override
public Boolean doWork() throws Exception {
Boolean isCheckedOut = repoService.isCheckedOut(nodeRef);
return isCheckedOut;
}
}, personId, network1.getId());
assertTrue(isCheckedOut);
// checkin with new content
expectedContent = "Big bad wolf";
ContentStreamImpl fileContent = new ContentStreamImpl();
{
ContentWriter writer = new FileContentWriter(TempFileProvider.createTempFile(GUID.generate(), ".txt"));
writer.putContent(expectedContent);
ContentReader reader = writer.getReader();
fileContent.setMimeType(MimetypeMap.MIMETYPE_TEXT_PLAIN);
fileContent.setStream(reader.getContentInputStream());
}
ObjectId checkinId = pwc.checkIn(true, Collections.EMPTY_MAP, fileContent, "checkin 1");
doc = (Document) cmisSession.getObject(checkinId.getId());
isCheckedOut = TenantUtil.runAsUserTenant(new TenantRunAsWork<Boolean>() {
@Override
public Boolean doWork() throws Exception {
Boolean isCheckedOut = repoService.isCheckedOut(nodeRef);
return isCheckedOut;
}
}, personId, network1.getId());
assertFalse(isCheckedOut);
// check that the content has been updated
ContentStream stream = doc.getContentStream();
StringWriter writer = new StringWriter();
IOUtils.copy(stream.getStream(), writer, "UTF-8");
String actualContent = writer.toString();
assertEquals(expectedContent, actualContent);
List<Document> allVersions = doc.getAllVersions();
assertEquals(2, allVersions.size());
assertEquals("2.0", allVersions.get(0).getVersionLabel());
assertEquals(CMIS_VERSION_10, allVersions.get(1).getVersionLabel());
}
{
// https://issues.alfresco.com/jira/browse/PUBLICAPI-95
// Test that documents are created with autoVersion=true
Map<String, String> fileProps = new HashMap<String, String>();
{
fileProps.put(PropertyIds.OBJECT_TYPE_ID, TYPE_CMIS_DOCUMENT);
fileProps.put(PropertyIds.NAME, "mydoc-" + GUID.generate() + ".txt");
}
ContentStreamImpl fileContent = new ContentStreamImpl();
{
ContentWriter writer = new FileContentWriter(TempFileProvider.createTempFile(GUID.generate(), ".txt"));
writer.putContent("Ipsum and so on");
ContentReader reader = writer.getReader();
fileContent.setMimeType(MimetypeMap.MIMETYPE_TEXT_PLAIN);
fileContent.setStream(reader.getContentInputStream());
}
{
// a versioned document
Document autoVersionedDoc = documentLibrary.createDocument(fileProps, fileContent, VersioningState.MAJOR);
String objectId = autoVersionedDoc.getId();
String bareObjectId = stripCMISSuffix(objectId);
final NodeRef nodeRef = new NodeRef(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, bareObjectId);
Boolean autoVersion = TenantUtil.runAsUserTenant(new TenantRunAsWork<Boolean>() {
@Override
public Boolean doWork() throws Exception {
Boolean autoVersion = (Boolean) repoService.getProperty(nodeRef, ContentModel.PROP_AUTO_VERSION);
return autoVersion;
}
}, personId, network1.getId());
assertEquals(Boolean.TRUE, autoVersion);
}
// https://issues.alfresco.com/jira/browse/PUBLICAPI-92
// Test that a get on an objectId without a version suffix returns the current version of the document
{
// do a few checkout, checkin cycles to create some versions
fileProps = new HashMap<String, String>();
{
fileProps.put(PropertyIds.OBJECT_TYPE_ID, TYPE_CMIS_DOCUMENT);
fileProps.put(PropertyIds.NAME, "mydoc-" + GUID.generate() + ".txt");
}
Document autoVersionedDoc = documentLibrary.createDocument(fileProps, fileContent, VersioningState.MAJOR);
String objectId = autoVersionedDoc.getId();
String bareObjectId = stripCMISSuffix(objectId);
for (int i = 0; i < 3; i++) {
Document doc1 = (Document) cmisSession.getObject(bareObjectId);
ObjectId pwcId = doc1.checkOut();
Document pwc = (Document) cmisSession.getObject(pwcId.getId());
ContentStreamImpl contentStream = new ContentStreamImpl();
{
ContentWriter writer = new FileContentWriter(TempFileProvider.createTempFile(GUID.generate(), ".txt"));
expectedContent = GUID.generate();
writer.putContent(expectedContent);
ContentReader reader = writer.getReader();
contentStream.setMimeType(MimetypeMap.MIMETYPE_TEXT_PLAIN);
contentStream.setStream(reader.getContentInputStream());
}
pwc.checkIn(true, Collections.EMPTY_MAP, contentStream, "checkin " + i);
}
// get the object, supplying an objectId without a version suffix
Document doc1 = (Document) cmisSession.getObject(bareObjectId);
String versionLabel = doc1.getVersionLabel();
ContentStream cs = doc1.getContentStream();
String content = IOUtils.toString(cs.getStream());
assertEquals("4.0", versionLabel);
assertEquals(expectedContent, content);
}
}
}
use of org.apache.chemistry.opencmis.client.api.ObjectId in project alfresco-remote-api by Alfresco.
the class TestCMIS method testMNT_10687.
/* MNT-10687 related test - appendContent to PWC CMIS 1.1 */
@Test
public void testMNT_10687() 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();
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);
String name = GUID.generate();
NodeRef folderNodeRef = repoService.createFolder(site.getContainerNodeRef(DOCUMENT_LIBRARY_CONTAINER_NAME), name);
return folderNodeRef;
}
}, person1Id, network1.getId());
// Create a document...
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1Id));
CmisSession cmisSession = publicApiClient.createPublicApiCMISSession(Binding.atom, CMIS_VERSION_11);
Folder docLibrary = (Folder) cmisSession.getObjectByPath("/Sites/" + siteName + "/documentLibrary");
String name = "mydoc-" + GUID.generate() + ".txt";
Map<String, Object> properties = new HashMap<String, Object>();
{
properties.put(PropertyIds.OBJECT_TYPE_ID, TYPE_CMIS_DOCUMENT);
properties.put(PropertyIds.NAME, name);
}
ContentStreamImpl fileContent = new ContentStreamImpl();
{
ContentWriter writer = new FileContentWriter(TempFileProvider.createTempFile(GUID.generate(), ".txt"));
writer.putContent("Ipsum");
ContentReader reader = writer.getReader();
fileContent.setMimeType(MimetypeMap.MIMETYPE_TEXT_PLAIN);
fileContent.setStream(reader.getContentInputStream());
}
/* Create document */
Document doc = docLibrary.createDocument(properties, fileContent, VersioningState.MAJOR);
/* Checkout document */
ObjectId pwcId = doc.checkOut();
Document pwc = (Document) cmisSession.getObject(pwcId.getId());
/* append content to PWC */
fileContent = new ContentStreamImpl();
{
ContentWriter writer = new FileContentWriter(TempFileProvider.createTempFile(GUID.generate(), ".txt"));
writer.putContent(" and so on");
ContentReader reader = writer.getReader();
fileContent.setMimeType(MimetypeMap.MIMETYPE_TEXT_PLAIN);
fileContent.setStream(reader.getContentInputStream());
}
pwc.appendContentStream(fileContent, true);
pwc.checkIn(false, null, null, "Check In");
ContentStream contentStream = doc.getObjectOfLatestVersion(false).getContentStream();
InputStream in = contentStream.getStream();
StringWriter writer = new StringWriter();
IOUtils.copy(in, writer, "UTF-8");
String content = writer.toString();
assertEquals("Ipsum and so on", content);
}
Aggregations