use of org.apache.chemistry.opencmis.client.api.FileableCmisObject 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.FileableCmisObject in project copper-cms by PogeyanOSS.
the class AbstractSessionTest method checkChildren.
protected CmisTestResult checkChildren(Session session, Folder folder, String message) {
List<CmisTestResult> results = new ArrayList<CmisTestResult>();
CmisTestResult f;
if (folder == null) {
return createResult(FAILURE, "Folder is null!");
}
// getChildren
boolean supportsOrderByName = isOrderByNameSupported(session);
OperationContext orderContext = (supportsOrderByName ? SELECT_ALL_NO_CACHE_OC_ORDER_BY_NAME : SELECT_ALL_NO_CACHE_OC);
long childrenCount = 0;
long childrenFolderCount = 0;
ItemIterable<CmisObject> children = folder.getChildren(orderContext);
int orderByNameIssues = 0;
String lastName = null;
for (CmisObject child : children) {
childrenCount++;
if (child instanceof Folder) {
childrenFolderCount++;
}
checkChild(session, results, folder, child);
if (lastName != null && child.getName() != null) {
if (child.getName().compareToIgnoreCase(lastName) < 0) {
orderByNameIssues++;
}
}
lastName = child.getName();
}
if (children.getTotalNumItems() >= 0) {
f = createResult(WARNING, "Number of children doesn't match the reported total number of items!");
addResult(results, assertEquals(childrenCount, children.getTotalNumItems(), null, f));
} else {
addResult(results, createResult(WARNING, "getChildren did not report the total number of items!"));
}
if (supportsOrderByName) {
f = createResult(WARNING, "Children should be ordered by cmis:name, but they are not! (It might be a collation mismtach.)");
addResult(results, assertEquals(0, orderByNameIssues, null, f));
} else {
addResult(results, createResult(INFO, "Repository doesn't support Order By for getChildren()."));
}
// test path segments
ObjectInFolderList pathSegementChildren = session.getBinding().getNavigationService().getChildren(session.getRepositoryInfo().getId(), folder.getId(), "cmis:objectId,cmis:name", null, null, null, null, Boolean.TRUE, BigInteger.valueOf(10), BigInteger.ZERO, null);
if (pathSegementChildren != null && pathSegementChildren.getObjects() != null) {
for (ObjectInFolderData objectInFolder : pathSegementChildren.getObjects()) {
String pathSegement = objectInFolder.getPathSegment();
String objectId = (String) objectInFolder.getObject().getProperties().getProperties().get(PropertyIds.OBJECT_ID).getFirstValue();
if (pathSegement == null) {
addResult(results, createResult(FAILURE, "getChildren omitted path segement! ID: " + objectId));
} else {
CmisObject pathSegementChild = session.getObjectByPath(folder.getPath(), pathSegement);
f = createResult(FAILURE, "Combining the path of the parent folder and the path segement of a child returns a different object! ID: " + objectId);
addResult(results, assertEquals(objectId, pathSegementChild.getId(), null, f));
}
}
}
if (isGetDescendantsSupported(session)) {
long descendantsCount = 0;
List<Tree<FileableCmisObject>> descendants = folder.getDescendants(1, SELECT_ALL_NO_CACHE_OC);
for (Tree<FileableCmisObject> child : descendants) {
descendantsCount++;
if (child == null) {
addResult(results, createResult(FAILURE, "Folder descendants contain a null tree!"));
} else {
checkChild(session, results, folder, child.getItem());
}
}
f = createResult(FAILURE, "Number of descendants doesn't match the number of children returned by getChildren!");
addResult(results, assertEquals(childrenCount, descendantsCount, null, f));
} else {
addResult(results, createResult(SKIPPED, "getDescendants is not supported."));
}
if (isGetFolderTreeSupported(session)) {
long folderTreeCount = 0;
List<Tree<FileableCmisObject>> folderTree = folder.getFolderTree(1, SELECT_ALL_NO_CACHE_OC);
for (Tree<FileableCmisObject> child : folderTree) {
folderTreeCount++;
if (child == null) {
addResult(results, createResult(FAILURE, "Folder tree contains a null tree!"));
} else {
checkChild(session, results, folder, child.getItem());
}
}
f = createResult(FAILURE, "Number of folders doesn't match the number of folders returned by getChildren!");
addResult(results, assertEquals(childrenFolderCount, folderTreeCount, null, f));
} else {
addResult(results, createResult(SKIPPED, "getFolderTree is not supported."));
}
// --- wrap up ---
CmisTestResultImpl result = createResult(getWorst(results), message);
result.getChildren().addAll(results);
return result.getStatus().getLevel() <= OK.getLevel() ? null : result;
}
use of org.apache.chemistry.opencmis.client.api.FileableCmisObject in project copper-cms by PogeyanOSS.
the class AbstractSessionTest method checkChild.
private void checkChild(Session session, List<CmisTestResult> results, Folder folder, CmisObject child) {
CmisTestResult f;
if (child == null) {
addResult(results, createResult(FAILURE, "Folder contains a null child!"));
} else {
String[] propertiesToCheck = new String[child.getType().getPropertyDefinitions().size()];
int i = 0;
for (String propId : child.getType().getPropertyDefinitions().keySet()) {
propertiesToCheck[i++] = propId;
}
addResult(results, checkObject(session, child, propertiesToCheck, "Child check: " + child.getId()));
addResult(results, checkVersionHistory(session, child, propertiesToCheck, "Child version history check: " + child.getId()));
f = createResult(FAILURE, "Child is not fileable! ID: " + child.getId() + " / Type: " + child.getType().getId());
addResult(results, assertIsTrue(child instanceof FileableCmisObject, null, f));
if (child instanceof FileableCmisObject) {
FileableCmisObject fileableChild = (FileableCmisObject) child;
Set<Action> actions = fileableChild.getAllowableActions().getAllowableActions();
boolean hasObjectParentsAction = actions.contains(Action.CAN_GET_OBJECT_PARENTS);
boolean hasFolderParentAction = actions.contains(Action.CAN_GET_FOLDER_PARENT);
if (hasObjectParentsAction || hasFolderParentAction) {
List<Folder> parents = fileableChild.getParents();
f = createResult(FAILURE, "Child has no parents! ID: " + child.getId());
addResult(results, assertListNotEmpty(parents, null, f));
if (child instanceof Folder) {
f = createResult(FAILURE, "Child is a folder and has more than one parent! ID: " + child.getId());
addResult(results, assertIsFalse(parents.size() > 1, null, f));
Folder folderParent = ((Folder) child).getFolderParent();
if (folderParent == null) {
addResult(results, createResult(FAILURE, "getFolderParent() returns null for a non-root folder object! ID: " + child.getId()));
} else {
f = createResult(FAILURE, "getFolderParent() returns wrong parent object! ID: " + child.getId());
addResult(results, assertEquals(folder.getId(), folderParent.getId(), null, f));
if (parents.size() > 0 && parents.get(0) != null) {
f = createResult(FAILURE, "getFolderParent() and getParents() return different parents for a folder object! ID: " + child.getId());
addResult(results, assertEquals(parents.get(0).getId(), folderParent.getId(), null, f));
}
}
}
boolean foundParent = false;
for (Folder parent : parents) {
if (parent == null) {
f = createResult(FAILURE, "One of childs parents is null! ID: " + child.getId());
addResult(results, assertListNotEmpty(parents, null, f));
} else if (folder.getId().equals(parent.getId())) {
foundParent = true;
break;
}
}
if (!foundParent) {
addResult(results, createResult(FAILURE, "Parent folder is not in parents of the child! ID: " + child.getId()));
}
}
// get object by ID and compare
CmisObject objectById = session.getObject(child.getId(), SELECT_ALL_NO_CACHE_OC);
f = createResult(FAILURE, "Child and object fetched by ID don't match! ID: " + child.getId());
addResult(results, assertEquals(child, objectById, null, f, false, false));
// get object by path and compare
List<String> paths = ((FileableCmisObject) child).getPaths();
if (isNullOrEmpty(paths)) {
addResult(results, createResult(FAILURE, "Child has no path! " + child.getId()));
} else {
for (String path : paths) {
CmisObject objectByPath = session.getObjectByPath(path, SELECT_ALL_NO_CACHE_OC);
f = createResult(FAILURE, "Child and object fetched by path don't match! ID: " + child.getId() + " / Path: " + path);
addResult(results, assertEquals(child, objectByPath, null, f, false, false));
f = createResult(FAILURE, "Object fetched by id and object fetched by path don't match! ID: " + child.getId() + " / Path: " + path);
addResult(results, assertEquals(objectById, objectByPath, null, f, true, true));
}
}
}
if (child instanceof Folder) {
f = createResult(WARNING, "Child has no CAN_GET_FOLDER_PARENT allowable action! ID: " + child.getId());
addResult(results, assertAllowableAction(child, Action.CAN_GET_FOLDER_PARENT, null, f));
} else {
f = createResult(WARNING, "Child has no CAN_GET_OBJECT_PARENTS allowable action! ID: " + child.getId());
addResult(results, assertAllowableAction(child, Action.CAN_GET_OBJECT_PARENTS, null, f));
}
}
}
use of org.apache.chemistry.opencmis.client.api.FileableCmisObject 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;
}
Aggregations