use of org.apache.chemistry.opencmis.commons.definitions.DocumentTypeDefinition in project copper-cms by PogeyanOSS.
the class SetAndDeleteContentTest method getNewVersion.
private Document getNewVersion(Session session, Document orgDoc, boolean checkedout, ObjectId newObjectId, String operation) {
Document result = orgDoc;
if (newObjectId != null) {
// -> Non AtomPub binding
if (!orgDoc.getId().equals(newObjectId.getId())) {
if (checkedout) {
addResult(createResult(FAILURE, operation + " created a new version from a PWC!"));
} else {
result = (Document) session.getObject(newObjectId, SELECT_ALL_NO_CACHE_OC);
addResult(checkObject(session, result, getAllProperties(result), "Version created by " + operation + " compliance"));
}
}
} else {
if (getBinding() != BindingType.ATOMPUB) {
addResult(createResult(FAILURE, operation + " did not return an object id!"));
}
// -> AtomPub binding or incompliant other binding
if (checkedout) {
// we cannot check if the repository does the right thing,
// but if there is a problem the versioning tests should
// catch it
} else if (Boolean.TRUE.equals(((DocumentTypeDefinition) orgDoc.getType()).isVersionable())) {
List<Document> versions = orgDoc.getAllVersions();
if (versions == null || versions.isEmpty()) {
addResult(createResult(FAILURE, operation + " created a new version but the version history is empty!"));
} else if (!orgDoc.getId().equals(versions.get(0).getId())) {
result = (Document) session.getObject(versions.get(0), SELECT_ALL_NO_CACHE_OC);
addResult(checkObject(session, result, getAllProperties(result), "Version created by " + operation + " compliance"));
}
}
}
return result;
}
use of org.apache.chemistry.opencmis.commons.definitions.DocumentTypeDefinition 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.commons.definitions.DocumentTypeDefinition in project copper-cms by PogeyanOSS.
the class AbstractSessionTest method checkObject.
protected CmisTestResult checkObject(Session session, CmisObject object, String[] properties, String message) {
List<CmisTestResult> results = new ArrayList<CmisTestResult>();
CmisTestResult f;
f = createResult(FAILURE, "Object is null!", true);
addResult(results, assertNotNull(object, null, f));
if (object != null) {
f = createResult(FAILURE, "Object ID is not set!");
addResult(results, assertStringNotEmpty(object.getId(), null, f));
GregorianCalendar creationDate = null;
GregorianCalendar lastModificationDate = null;
// properties
for (String propId : properties) {
Property<?> prop = object.getProperty(propId);
// values of non-spec properties are not checked here
PropertyCheckEnum propertyCheck = PropertyCheckEnum.NO_VALUE_CHECK;
// known properties that are strings and must be set
if (PropertyIds.OBJECT_ID.equals(propId) || PropertyIds.BASE_TYPE_ID.equals(propId) || PropertyIds.OBJECT_TYPE_ID.equals(propId) || PropertyIds.PATH.equals(propId) || PropertyIds.SOURCE_ID.equals(propId) || PropertyIds.TARGET_ID.equals(propId)) {
propertyCheck = PropertyCheckEnum.STRING_MUST_NOT_BE_EMPTY;
}
if (!(object instanceof Relationship)) {
if (PropertyIds.CREATED_BY.equals(propId) || PropertyIds.LAST_MODIFIED_BY.equals(propId)) {
propertyCheck = PropertyCheckEnum.STRING_MUST_NOT_BE_EMPTY;
}
}
// known properties that are strings and should be set
if (PropertyIds.NAME.equals(propId) || PropertyIds.POLICY_TEXT.equals(propId)) {
propertyCheck = PropertyCheckEnum.STRING_SHOULD_NOT_BE_EMPTY;
}
// known properties that are not strings and must be set
if (PropertyIds.IS_IMMUTABLE.equals(propId)) {
propertyCheck = PropertyCheckEnum.MUST_BE_SET;
}
if (!(object instanceof Relationship)) {
if (PropertyIds.CREATION_DATE.equals(propId) || PropertyIds.LAST_MODIFICATION_DATE.equals(propId)) {
propertyCheck = PropertyCheckEnum.MUST_BE_SET;
}
}
// special case: parent
if (PropertyIds.PARENT_ID.equals(propId)) {
if (object instanceof Folder) {
if (((Folder) object).isRootFolder()) {
propertyCheck = PropertyCheckEnum.MUST_NOT_BE_SET;
} else {
propertyCheck = PropertyCheckEnum.STRING_MUST_NOT_BE_EMPTY;
}
} else {
addResult(results, createResult(FAILURE, "Property " + PropertyIds.PARENT_ID + " is only defined for folders!"));
}
}
// special case: path
if (PropertyIds.PATH.equals(propId) && prop.getFirstValue() != null) {
Object path = prop.getFirstValue();
if (path instanceof String) {
f = createResult(FAILURE, "Path does not start with '/': " + path);
addResult(results, assertIsTrue(((String) path).length() > 0 && ((String) path).charAt(0) == '/', null, f));
} else {
addResult(results, createResult(FAILURE, "Property " + PropertyIds.PATH + " is not a string!"));
}
}
// check property
addResult(results, checkProperty(prop, "Property " + propId, propertyCheck));
// catch creationDate and lastModificationDate
if (PropertyIds.CREATION_DATE.equals(propId)) {
if (prop != null) {
creationDate = (GregorianCalendar) prop.getFirstValue();
}
} else if (PropertyIds.LAST_MODIFICATION_DATE.equals(propId)) {
if (prop != null) {
lastModificationDate = (GregorianCalendar) prop.getFirstValue();
}
}
}
// check creationDate <= lastModificationDate
if (creationDate != null && lastModificationDate != null) {
f = createResult(FAILURE, "Last modification date precedes creation date!");
addResult(results, assertIsTrue(creationDate.getTimeInMillis() <= lastModificationDate.getTimeInMillis(), null, f));
f = createResult(WARNING, "Creation date and last modification date have different timezones.");
addResult(assertIsTrue(creationDate.getTimeZone().hasSameRules(lastModificationDate.getTimeZone()), null, f));
}
// allowable actions
if ((object.getAllowableActions() == null) || (object.getAllowableActions().getAllowableActions() == null)) {
addResult(results, createResult(FAILURE, "Object has no allowable actions!"));
} else {
Set<Action> actions = object.getAllowableActions().getAllowableActions();
f = createResult(FAILURE, "Object has no CAN_GET_PROPERTIES allowable action!");
addResult(results, assertAllowableAction(object, Action.CAN_GET_PROPERTIES, null, f));
addResult(results, assertIsTrue(object.hasAllowableAction(Action.CAN_GET_PROPERTIES), null, f));
if (object instanceof Document) {
if (actions.contains(Action.CAN_CHECK_OUT) && actions.contains(Action.CAN_CHECK_IN)) {
addResult(results, createResult(FAILURE, "Document object has CAN_CHECK_OUT and CAN_CHECK_IN allowable actions!"));
}
if (actions.contains(Action.CAN_CHECK_OUT) && actions.contains(Action.CAN_CANCEL_CHECK_OUT)) {
addResult(results, createResult(FAILURE, "Document object has CAN_CHECK_OUT and CAN_CANCEL_CHECK_OUT allowable actions!"));
}
Document doc = (Document) object;
DocumentTypeDefinition docType = (DocumentTypeDefinition) doc.getType();
if (doc.isVersionSeriesCheckedOut() != null) {
if (doc.isVersionSeriesCheckedOut()) {
f = createResult(WARNING, "Document is checked out and has CAN_CHECK_OUT allowable action!");
addResult(results, assertNotAllowableAction(object, Action.CAN_CHECK_OUT, null, f));
if (doc.getVersionSeriesCheckedOutId() == null) {
addResult(results, createResult(WARNING, "Document is checked out and but the property cmis:versionSeriesCheckedOutId is not set!"));
} else {
if (doc.getVersionSeriesCheckedOutId().equals(object.getId())) {
// object is PWC
f = createResult(FAILURE, "PWC doesn't have CAN_CHECK_IN allowable action!");
addResult(results, assertAllowableAction(object, Action.CAN_CHECK_IN, null, f));
f = createResult(FAILURE, "PWC doesn't have CAN_CANCEL_CHECK_OUT allowable action!");
addResult(results, assertAllowableAction(object, Action.CAN_CANCEL_CHECK_OUT, null, f));
} else {
// object is not PWC
f = createResult(WARNING, "Non-PWC has CAN_CHECK_IN allowable action!");
addResult(results, assertNotAllowableAction(object, Action.CAN_CHECK_IN, null, f));
f = createResult(WARNING, "Non-PWC has CAN_CANCEL_CHECK_OUT allowable action!");
addResult(results, assertNotAllowableAction(object, Action.CAN_CANCEL_CHECK_OUT, null, f));
}
}
} else {
f = createResult(FAILURE, "Document is not checked out and has CAN_CHECK_IN allowable action!");
addResult(results, assertNotAllowableAction(object, Action.CAN_CHECK_IN, null, f));
f = createResult(FAILURE, "Document is not checked out and has CAN_CANCEL_CHECK_OUT allowable action!");
addResult(results, assertNotAllowableAction(object, Action.CAN_CANCEL_CHECK_OUT, null, f));
// versionable check
if (docType.isVersionable()) {
//
if (Boolean.TRUE.equals(doc.isLatestVersion())) {
f = createResult(WARNING, "Document is versionable and not checked but has no CAN_CHECK_OUT allowable action!");
addResult(results, assertAllowableAction(object, Action.CAN_CHECK_OUT, null, f));
}
} else {
f = createResult(FAILURE, "Document is not versionable but has CAN_CHECK_OUT allowable action!");
addResult(results, assertNotAllowableAction(object, Action.CAN_CHECK_OUT, null, f));
}
}
} else {
addResult(results, createResult(WARNING, "Property cmis:isVersionSeriesCheckedOut is not set!"));
}
// immutable check
if (Boolean.TRUE.equals(doc.isImmutable())) {
f = createResult(FAILURE, "Document is immutable and has CAN_UPDATE_PROPERTIES allowable action!");
addResult(results, assertNotAllowableAction(object, Action.CAN_UPDATE_PROPERTIES, null, f));
f = createResult(FAILURE, "Document is immutable and has CAN_DELETE_OBJECT allowable action!");
addResult(results, assertNotAllowableAction(object, Action.CAN_DELETE_OBJECT, null, f));
}
} else {
f = createResult(FAILURE, "Non-Document object has CAN_CHECK_IN allowable action!");
addResult(results, assertNotAllowableAction(object, Action.CAN_CHECK_IN, null, f));
f = createResult(FAILURE, "Non-Document object has CAN_CHECK_OUT allowable action!");
addResult(results, assertNotAllowableAction(object, Action.CAN_CHECK_OUT, null, f));
f = createResult(FAILURE, "Non-Document object has CAN_CANCEL_CHECK_OUT allowable action!");
addResult(results, assertNotAllowableAction(object, Action.CAN_CANCEL_CHECK_OUT, null, f));
f = createResult(FAILURE, "Non-Document object has CAN_GET_CONTENT_STREAM allowable action!");
addResult(results, assertNotAllowableAction(object, Action.CAN_GET_CONTENT_STREAM, null, f));
f = createResult(FAILURE, "Non-Document object has CAN_DELETE_CONTENT_STREAM allowable action!");
addResult(results, assertNotAllowableAction(object, Action.CAN_DELETE_CONTENT_STREAM, null, f));
f = createResult(FAILURE, "Non-Document object has CAN_GET_ALL_VERSIONS allowable action!");
addResult(results, assertNotAllowableAction(object, Action.CAN_GET_ALL_VERSIONS, null, f));
}
if (object instanceof Folder) {
Folder folder = (Folder) object;
if (folder.isRootFolder()) {
f = createResult(FAILURE, "Root folder has CAN_DELETE_OBJECT allowable action!");
addResult(results, assertNotAllowableAction(object, Action.CAN_DELETE_OBJECT, null, f));
f = createResult(FAILURE, "Root folder has CAN_GET_FOLDER_PARENT allowable action!");
addResult(results, assertNotAllowableAction(object, Action.CAN_GET_FOLDER_PARENT, null, f));
f = createResult(FAILURE, "Root folder has CAN_MOVE_OBJECT allowable action!");
addResult(results, assertNotAllowableAction(object, Action.CAN_MOVE_OBJECT, null, f));
}
} else {
f = createResult(FAILURE, "Non-Folder object has CAN_GET_DESCENDANTS allowable action!");
addResult(results, assertNotAllowableAction(object, Action.CAN_GET_DESCENDANTS, null, f));
f = createResult(FAILURE, "Non-Folder object has CAN_GET_FOLDER_PARENT allowable action!");
addResult(results, assertNotAllowableAction(object, Action.CAN_GET_FOLDER_PARENT, null, f));
f = createResult(FAILURE, "Non-Folder object has CAN_GET_CHILDREN allowable action!");
addResult(results, assertNotAllowableAction(object, Action.CAN_GET_CHILDREN, null, f));
f = createResult(FAILURE, "Non-Folder object has CAN_DELETE_TREE allowable action!");
addResult(results, assertNotAllowableAction(object, Action.CAN_DELETE_TREE, null, f));
f = createResult(FAILURE, "Non-Folder object has CAN_GET_FOLDER_PARENT allowable action!");
addResult(results, assertNotAllowableAction(object, Action.CAN_GET_FOLDER_PARENT, null, f));
f = createResult(FAILURE, "Non-Folder object has CAN_CREATE_DOCUMENT allowable action!");
addResult(results, assertNotAllowableAction(object, Action.CAN_CREATE_DOCUMENT, null, f));
f = createResult(FAILURE, "Non-Folder object has CAN_CREATE_FOLDER allowable action!");
addResult(results, assertNotAllowableAction(object, Action.CAN_CREATE_FOLDER, null, f));
}
if (!(object instanceof FileableCmisObject) || (object instanceof Folder)) {
f = createResult(FAILURE, "Non-Filable object or folder has CAN_ADD_OBJECT_TO_FOLDER allowable action!");
addResult(results, assertNotAllowableAction(object, Action.CAN_ADD_OBJECT_TO_FOLDER, null, f));
f = createResult(FAILURE, "Non-Filable object or folder has CAN_REMOVE_OBJECT_FROM_FOLDER allowable action!");
addResult(results, assertNotAllowableAction(object, Action.CAN_REMOVE_OBJECT_FROM_FOLDER, null, f));
}
if (!(object instanceof FileableCmisObject)) {
f = createResult(FAILURE, "Non-Fileable object has CAN_MOVE_OBJECT allowable action!");
addResult(results, assertNotAllowableAction(object, Action.CAN_MOVE_OBJECT, null, f));
}
// get allowable actions again
AllowableActions allowableActions = session.getBinding().getObjectService().getAllowableActions(session.getRepositoryInfo().getId(), object.getId(), null);
if (allowableActions.getAllowableActions() == null) {
addResult(results, createResult(FAILURE, "getAllowableActions() didn't returned allowable actions!"));
} else {
f = createResult(FAILURE, "Object allowable actions don't match the allowable actions returned by getAllowableActions()!");
addResult(results, assertEqualSet(object.getAllowableActions().getAllowableActions(), allowableActions.getAllowableActions(), null, f));
}
}
// check ACL
if (object.getAcl() != null && object.getAcl().getAces() != null) {
addResult(results, checkACL(session, object.getAcl(), true, "ACL"));
}
// check policies
if (hasPolicies(session)) {
try {
List<ObjectData> appliedPolicies = session.getBinding().getPolicyService().getAppliedPolicies(session.getRepositoryInfo().getId(), object.getId(), "*", null);
if (appliedPolicies == null) {
appliedPolicies = Collections.emptyList();
}
List<Policy> objectPolicies = object.getPolicies();
if (objectPolicies == null) {
objectPolicies = Collections.emptyList();
}
f = createResult(FAILURE, "The number of policies returned by getAppliedPolicies() and the number of object policies don't match!");
addResult(results, assertEquals(appliedPolicies.size(), objectPolicies.size(), null, f));
} catch (CmisNotSupportedException e) {
addResult(results, createResult(WARNING, "getAppliedPolicies() not supported for object: " + object.getId()));
}
}
// check relationships
checkRelationships(session, results, object);
// check document content
checkDocumentContent(session, results, object);
// check renditions
if (object.getRenditions() != null) {
addResult(results, checkRenditions(session, object, "Rendition check"));
}
// check allowed child object type ids
if (object instanceof Folder) {
List<String> otids = object.getPropertyValue(PropertyIds.ALLOWED_CHILD_OBJECT_TYPE_IDS);
if (otids != null) {
for (String otid : otids) {
try {
session.getTypeDefinition(otid);
} catch (CmisBaseException e) {
addResult(results, createResult(FAILURE, "The cmis:allowedChildObjectTypeIds property contains the type ID '" + otid + "' but the type doesn't exists. Folder ID: " + object.getId()));
}
}
}
}
// check path
if (object instanceof FileableCmisObject) {
List<String> paths = ((FileableCmisObject) object).getPaths();
if (object instanceof Folder) {
f = createResult(FAILURE, "Folder does not have excatly one path! This is an OpenCMIS bug!");
addResult(results, assertEquals(1, paths.size(), null, f));
} else {
if (Boolean.FALSE.equals(session.getRepositoryInfo().getCapabilities().isMultifilingSupported())) {
f = createResult(FAILURE, "Repository does not support multi-filing, but the object has more than one parent!");
addResult(results, assertIsTrue(paths.size() < 2, null, f));
}
}
}
}
CmisTestResultImpl result = createResult(getWorst(results), message);
result.getChildren().addAll(results);
return result.getStatus().getLevel() <= OK.getLevel() ? null : result;
}
use of org.apache.chemistry.opencmis.commons.definitions.DocumentTypeDefinition in project copper-cms by PogeyanOSS.
the class SetAndDeleteContentTest method testAppendStream.
private void testAppendStream(Session session, Folder testFolder, int bufferSize) {
CmisTestResult f;
// create an empty document
Document doc = createDocument(session, testFolder, "appendstreamtest.txt", "");
Document workDoc = doc;
boolean checkedout = false;
DocumentTypeDefinition docType = (DocumentTypeDefinition) doc.getType();
if (Boolean.TRUE.equals(docType.isVersionable())) {
workDoc = (Document) session.getObject(doc.checkOut(), SELECT_ALL_NO_CACHE_OC);
checkedout = true;
}
try {
// create an overwrite OutputStream
OutputStream out1 = workDoc.createOverwriteOutputStream("appendstreamtest", "text/plain", bufferSize);
out1.write(IOUtils.toUTF8Bytes("line 1\n"));
out1.write(IOUtils.toUTF8Bytes("line 2\n"));
out1.flush();
out1.write(IOUtils.toUTF8Bytes("line 3\n"));
out1.close();
// check document content
workDoc.refresh();
String content1 = getStringFromContentStream(workDoc.getContentStream());
f = createResult(FAILURE, "Overwrite OutputStream: wrong content!");
addResult(assertEquals("line 1\nline 2\nline 3\n", content1, null, f));
// create an append OutputStream
OutputStream out2 = workDoc.createAppendOutputStream(bufferSize);
out2.write(IOUtils.toUTF8Bytes("line 4\n"));
out2.write(IOUtils.toUTF8Bytes("line 5\n"));
out2.flush();
out2.write(IOUtils.toUTF8Bytes("line 6\n"));
out2.close();
// check document content
workDoc.refresh();
String content2 = getStringFromContentStream(workDoc.getContentStream());
f = createResult(FAILURE, "Overwrite OutputStream: wrong content!");
addResult(assertEquals("line 1\nline 2\nline 3\nline 4\nline 5\nline 6\n", content2, null, f));
} catch (IOException e) {
addResult(createResult(UNEXPECTED_EXCEPTION, "Appending content via an OutputStream failed! Exception: " + e.getMessage(), e, false));
} finally {
// cancel a possible check out
if (checkedout) {
workDoc.cancelCheckOut();
}
// remove the document
deleteObject(doc);
}
}
use of org.apache.chemistry.opencmis.commons.definitions.DocumentTypeDefinition in project copper-cms by PogeyanOSS.
the class UpdateSmokeTest method updateDocument.
private void updateDocument(Session session, Folder testFolder) {
CmisTestResult f;
// create document
Document doc1 = createDocument(session, testFolder, DOC_NAME1, "rename me!");
Document workDoc = doc1;
f = createResult(FAILURE, "Document name doesn't match the given name!");
addResult(assertEquals(DOC_NAME1, doc1.getName(), null, f));
// test if check out is required
boolean checkedout = false;
DocumentTypeDefinition type = (DocumentTypeDefinition) doc1.getType();
PropertyDefinition<?> namePropDef = type.getPropertyDefinitions().get(PropertyIds.NAME);
if (namePropDef.getUpdatability() == Updatability.WHENCHECKEDOUT || (!doc1.getAllowableActions().getAllowableActions().contains(Action.CAN_UPDATE_PROPERTIES) && Boolean.TRUE.equals(type.isVersionable()))) {
workDoc = (Document) session.getObject(doc1.checkOut(), SELECT_ALL_NO_CACHE_OC);
checkedout = true;
}
// update
Map<String, Object> properties = new HashMap<String, Object>();
properties.put(PropertyIds.NAME, DOC_NAME2);
ObjectId newId = workDoc.updateProperties(properties, false);
Document doc2 = (Document) session.getObject(newId, SELECT_ALL_NO_CACHE_OC);
addResult(checkObject(session, doc2, getAllProperties(doc2), "Updated document compliance"));
f = createResult(FAILURE, "Document name doesn't match updated value!");
addResult(assertEquals(DOC_NAME2, doc2.getName(), null, f));
// delete
if (!workDoc.getId().equals(doc2.getId())) {
deleteObject(doc2);
}
// cancel a possible check out
if (checkedout) {
workDoc.cancelCheckOut();
}
if (!doc1.getId().equals(doc2.getId())) {
if (exists(doc1)) {
deleteObject(doc1);
}
}
}
Aggregations