use of org.apache.chemistry.opencmis.commons.definitions.DocumentTypeDefinition in project copper-cms by PogeyanOSS.
the class AbstractSessionTest method checkDocumentContent.
private void checkDocumentContent(Session session, List<CmisTestResult> results, CmisObject object) {
if (!(object instanceof Document)) {
// only documents have content
return;
}
CmisTestResult f;
Document doc = (Document) object;
DocumentTypeDefinition type = (DocumentTypeDefinition) doc.getType();
// check ContentStreamAllowed flag
boolean hasContentProperties = (doc.getContentStreamFileName() != null) || (doc.getContentStreamId() != null) || (doc.getContentStreamLength() > -1) || (doc.getContentStreamMimeType() != null);
if (hasContentProperties) {
if (type.getContentStreamAllowed() == ContentStreamAllowed.NOTALLOWED) {
addResult(results, createResult(FAILURE, "Content properties have values but the document type doesn't allow content!"));
}
} else {
if (type.getContentStreamAllowed() == ContentStreamAllowed.REQUIRED) {
addResult(results, createResult(FAILURE, "Content properties are not set but the document type demands content!"));
}
}
// get the content stream
ContentStream contentStream = doc.getContentStream();
if (contentStream == null) {
if (hasContentProperties && doc.getContentStreamLength() > 0) {
addResult(results, createResult(FAILURE, "Content properties have values but the document has no content!"));
}
if (type.getContentStreamAllowed() == ContentStreamAllowed.REQUIRED) {
addResult(results, createResult(FAILURE, "The document type demands content but the document has no content!"));
}
return;
}
if (type.getContentStreamAllowed() == ContentStreamAllowed.NOTALLOWED) {
addResult(results, createResult(FAILURE, "Document type doesn't allow content but document has content!"));
}
// file name check
f = createResult(FAILURE, "Content file names don't match!");
addResult(results, assertEquals(doc.getContentStreamFileName(), contentStream.getFileName(), null, f));
if (doc.getContentStreamLength() > -1 && contentStream.getLength() > -1) {
f = createResult(FAILURE, "Content lengths don't match!");
addResult(results, assertEquals(doc.getContentStreamLength(), contentStream.getLength(), null, f));
}
// MIME type check
String docMimeType = doc.getContentStreamMimeType();
if (docMimeType != null) {
int x = docMimeType.indexOf(';');
if (x > -1) {
docMimeType = docMimeType.substring(0, x);
}
docMimeType = docMimeType.trim();
}
String contentMimeType = contentStream.getMimeType();
if (contentMimeType != null) {
int x = contentMimeType.indexOf(';');
if (x > -1) {
contentMimeType = contentMimeType.substring(0, x);
}
contentMimeType = contentMimeType.trim();
}
f = createResult(FAILURE, "Content MIME types don't match!");
addResult(results, assertEquals(docMimeType, contentMimeType, null, f));
if (contentStream.getMimeType() != null) {
if (contentMimeType.equals(docMimeType)) {
f = createResult(WARNING, "Content MIME types don't match!");
addResult(results, assertEquals(doc.getContentStreamMimeType(), contentStream.getMimeType(), null, f));
}
f = createResult(FAILURE, "Content MIME types is invalid: " + contentStream.getMimeType());
addResult(results, assertIsTrue(contentStream.getMimeType().length() > 2 && contentStream.getMimeType().indexOf('/') > 0, null, f));
}
// check stream
InputStream stream = contentStream.getStream();
if (stream == null) {
addResult(results, createResult(FAILURE, "Docuemnt has no content stream!"));
return;
}
try {
long bytes = 0;
byte[] buffer = new byte[64 * 1024];
int b = stream.read(buffer);
while (b > -1) {
bytes += b;
b = stream.read(buffer);
}
stream.close();
// check content length
if (doc.getContentStreamLength() > -1) {
f = createResult(FAILURE, "Content stream length property value doesn't match the actual content length!");
addResult(results, assertEquals(doc.getContentStreamLength(), bytes, null, f));
}
if (contentStream.getLength() > -1) {
f = createResult(FAILURE, "Content length value doesn't match the actual content length!");
addResult(results, assertEquals(contentStream.getLength(), bytes, null, f));
}
} catch (Exception e) {
addResult(results, createResult(FAILURE, "Reading content failed: " + e, e, false));
} finally {
IOUtils.closeQuietly(stream);
}
}
use of org.apache.chemistry.opencmis.commons.definitions.DocumentTypeDefinition in project copper-cms by PogeyanOSS.
the class AbstractSessionTest method checkVersionHistory.
protected CmisTestResult checkVersionHistory(Session session, CmisObject object, String[] properties, String message) {
List<CmisTestResult> results = new ArrayList<CmisTestResult>();
CmisTestResult f;
if (object.getBaseTypeId() != BaseTypeId.CMIS_DOCUMENT) {
// skip non-document objects
return null;
}
if (!Boolean.TRUE.equals(((DocumentTypeDefinition) object.getType()).isVersionable())) {
// skip non-versionable types
return null;
}
Document doc = (Document) object;
// check version series ID
String versionSeriesId = doc.getVersionSeriesId();
f = createResult(FAILURE, "Versionable document has no version series ID property!");
addResult(results, assertStringNotEmpty(versionSeriesId, null, f));
if (versionSeriesId == null) {
CmisTestResultImpl result = createResult(getWorst(results), message);
result.getChildren().addAll(results);
return result;
}
// get version history
List<Document> versions = doc.getAllVersions(SELECT_ALL_NO_CACHE_OC);
f = createResult(FAILURE, "Version history is null!");
addResult(results, assertNotNull(versions, null, f));
if (versions == null) {
CmisTestResultImpl result = createResult(getWorst(results), message);
result.getChildren().addAll(results);
return result;
}
f = createResult(FAILURE, "Version history must have at least one version!");
addResult(results, assertListNotEmpty(versions, null, f));
if (!versions.isEmpty()) {
// get latest version
Document lastestVersion = doc.getObjectOfLatestVersion(false, SELECT_ALL_NO_CACHE_OC);
addResult(results, checkObject(session, lastestVersion, properties, "Latest version check: " + lastestVersion.getId()));
f = createResult(FAILURE, "Latest version is not flagged as latest version! ID: " + lastestVersion.getId());
addResult(results, assertIsTrue(lastestVersion.isLatestVersion(), null, f));
// get latest major version
Document lastestMajorVersion = null;
try {
lastestMajorVersion = doc.getObjectOfLatestVersion(true, SELECT_ALL_NO_CACHE_OC);
f = createResult(FAILURE, "getObjectOfLatestVersion returned an invalid object!");
addResult(results, assertNotNull(lastestMajorVersion, null, f));
} catch (CmisObjectNotFoundException e) {
// no latest major version
}
if (lastestMajorVersion != null) {
addResult(results, checkObject(session, lastestMajorVersion, properties, "Latest major version check: " + lastestMajorVersion.getId()));
f = createResult(FAILURE, "Latest major version is not flagged as latest major version! ID: " + lastestMajorVersion.getId());
addResult(results, assertIsTrue(lastestMajorVersion.isLatestMajorVersion(), null, f));
}
// iterate through the version history and test each version
// document
long creatationDate = Long.MAX_VALUE;
int latestVersion = 0;
int latestMajorVersion = 0;
long latestModificationDate = Long.MAX_VALUE;
int latestModifictaionIndex = Integer.MIN_VALUE;
Set<String> versionLabels = new HashSet<String>();
boolean found = false;
boolean foundLastestVersion = false;
boolean foundLastestMajorVersion = false;
for (int i = 0; i < versions.size(); i++) {
Document version = versions.get(i);
f = createResult(FAILURE, "Version " + i + " is null!");
addResult(results, assertNotNull(version, null, f));
if (version == null) {
continue;
}
addResult(results, checkObject(session, version, properties, "Version check: " + version.getId()));
// check first entry
if (i == 0) {
if (version.isVersionSeriesCheckedOut()) {
f = createResult(WARNING, "Version series is checked-out and the PWC is not the latest version! ID: " + version.getId() + " (Note: The words of the CMIS specification define that the PWC is the latest version." + " But that is not the intention of the spec and will be changed in CMIS 1.1." + " Thus this a warning, not an error.)");
addResult(results, assertIsTrue(version.isLatestVersion(), null, f));
} else {
f = createResult(FAILURE, "Version series is not checked-out and first version history entry is not the latest version! ID: " + version.getId());
addResult(results, assertIsTrue(version.isLatestVersion(), null, f));
}
}
// check version ID
f = createResult(FAILURE, "Version series id does not match! ID: " + version.getId());
addResult(results, assertEquals(versionSeriesId, version.getVersionSeriesId(), null, f));
// check creation date
if (creatationDate == version.getCreationDate().getTimeInMillis()) {
addResult(results, createResult(WARNING, "Two or more versions have the same creation date!"));
} else {
f = createResult(FAILURE, "Version history order incorrect! Must be sorted bei creation date!");
addResult(results, assertIsTrue(version.getCreationDate().getTimeInMillis() <= creatationDate, null, f));
}
// count latest versions and latest major versions
if (version.isLatestVersion()) {
latestVersion++;
}
if (version.isLatestMajorVersion()) {
latestMajorVersion++;
}
// find latest modification date
if (latestModificationDate == version.getLastModificationDate().getTimeInMillis()) {
addResult(results, createResult(WARNING, "Two or more versions have the same last modification date!"));
} else if (latestModificationDate < version.getLastModificationDate().getTimeInMillis()) {
latestModificationDate = version.getLastModificationDate().getTimeInMillis();
latestModifictaionIndex = i;
}
// check for version label duplicates
String versionLabel = version.getVersionLabel();
f = createResult(WARNING, "More than one version have this version label: " + versionLabel);
addResult(results, assertIsFalse(versionLabels.contains(versionLabel), null, f));
versionLabels.add(versionLabel);
// check PWC
if (version.getId().equals(version.getVersionSeriesCheckedOutId())) {
f = createResult(FAILURE, "PWC must not be flagged as latest major version! ID: " + version.getId());
addResult(results, assertIsFalse(version.isLatestMajorVersion(), null, f));
}
// check checked out
if (Boolean.TRUE.equals(doc.isVersionSeriesCheckedOut())) {
f = createResult(WARNING, "Version series is marked as checked out but cmis:versionSeriesCheckedOutId is not set! ID: " + version.getId());
addResult(results, assertStringNotEmpty(doc.getVersionSeriesCheckedOutId(), null, f));
f = createResult(WARNING, "Version series is marked as checked out but cmis:versionSeriesCheckedOutBy is not set! ID: " + version.getId());
addResult(results, assertStringNotEmpty(doc.getVersionSeriesCheckedOutBy(), null, f));
} else if (Boolean.FALSE.equals(doc.isVersionSeriesCheckedOut())) {
f = createResult(FAILURE, "Version series is not marked as checked out but cmis:versionSeriesCheckedOutId is set! ID: " + version.getId());
addResult(results, assertNull(doc.getVersionSeriesCheckedOutId(), null, f));
f = createResult(FAILURE, "Version series is not marked as checked out but cmis:versionSeriesCheckedOutIdBy is set! ID: " + version.getId());
addResult(results, assertNull(doc.getVersionSeriesCheckedOutBy(), null, f));
}
// found origin object?
if (version.getId().equals(object.getId())) {
found = true;
}
// found latest version?
if (version.getId().equals(lastestVersion.getId())) {
foundLastestVersion = true;
}
// found latest major version?
if (lastestMajorVersion != null && version.getId().equals(lastestMajorVersion.getId())) {
foundLastestMajorVersion = true;
}
}
// check latest versions
f = createResult(FAILURE, "Version series ID has " + latestVersion + " latest versions! There must be only one!");
addResult(results, assertEquals(1, latestVersion, null, f));
if (!foundLastestVersion) {
addResult(results, createResult(FAILURE, "Latest version not found in version history!"));
}
// check latest major versions
if (lastestMajorVersion == null) {
f = createResult(FAILURE, "Version series ID has " + latestMajorVersion + " latest major version(s) but getObjectOfLatestVersion() didn't return a major version!");
addResult(results, assertEquals(0, latestMajorVersion, null, f));
} else {
f = createResult(FAILURE, "Version series ID has " + latestMajorVersion + " latest major versions but there should be exactly one!");
addResult(results, assertEquals(1, latestMajorVersion, null, f));
if (!foundLastestMajorVersion) {
addResult(results, createResult(FAILURE, "Latest major version not found in version history!"));
}
}
// check latest version
if (latestModifictaionIndex >= 0) {
f = createResult(FAILURE, "Version with the latest modification date is not flagged as latest version! ID: " + versions.get(latestModifictaionIndex));
addResult(results, assertIsTrue(versions.get(latestModifictaionIndex).isLatestVersion(), null, f));
}
// check if the origin object was found
if (!found) {
addResult(results, createResult(FAILURE, "Document not found in its version history!"));
}
}
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 AbstractSessionTest method createDocument.
/**
* Creates a document.
*/
protected Document createDocument(Session session, Folder parent, String name, String objectTypeId, String[] secondaryTypeIds, String content) {
if (parent == null) {
throw new IllegalArgumentException("Parent is not set!");
}
if (name == null) {
throw new IllegalArgumentException("Name is not set!");
}
if (objectTypeId == null) {
throw new IllegalArgumentException("Object Type ID is not set!");
}
if (content == null) {
content = "";
}
// check type
ObjectType type;
try {
type = session.getTypeDefinition(objectTypeId);
} catch (CmisObjectNotFoundException e) {
addResult(createResult(UNEXPECTED_EXCEPTION, "Document type '" + objectTypeId + "' is not available: " + e.getMessage(), e, true));
return null;
}
if (Boolean.FALSE.equals(type.isCreatable())) {
addResult(createResult(SKIPPED, "Document type '" + objectTypeId + "' is not creatable!", true));
return null;
}
// create
Map<String, Object> properties = new HashMap<String, Object>();
properties.put(PropertyIds.NAME, name);
properties.put(PropertyIds.OBJECT_TYPE_ID, objectTypeId);
if (secondaryTypeIds != null) {
properties.put(PropertyIds.SECONDARY_OBJECT_TYPE_IDS, Arrays.asList(secondaryTypeIds));
}
type = session.getTypeDefinition(objectTypeId);
if (!(type instanceof DocumentTypeDefinition)) {
addResult(createResult(FAILURE, "Type is not a document type! Type: " + objectTypeId, true));
return null;
}
DocumentTypeDefinition docType = (DocumentTypeDefinition) type;
VersioningState versioningState = (Boolean.TRUE.equals(docType.isVersionable()) ? VersioningState.MAJOR : VersioningState.NONE);
byte[] contentBytes = null;
Document result = null;
try {
contentBytes = IOUtils.toUTF8Bytes(content);
ContentStream contentStream = new ContentStreamImpl(name, BigInteger.valueOf(contentBytes.length), "text/plain", new ByteArrayInputStream(contentBytes));
// create the document
result = parent.createDocument(properties, contentStream, versioningState, null, null, null, SELECT_ALL_NO_CACHE_OC);
contentStream.getStream().close();
} catch (Exception e) {
addResult(createResult(UNEXPECTED_EXCEPTION, "Document could not be created! Exception: " + e.getMessage(), e, true));
return null;
}
try {
CmisTestResult f;
// check document name
f = createResult(FAILURE, "Document name does not match!", false);
addResult(assertEquals(name, result.getName(), null, f));
// check content length
f = createResult(WARNING, "Content length does not match!", false);
addResult(assertEquals((long) contentBytes.length, result.getContentStreamLength(), null, f));
// check the new document
addResult(checkObject(session, result, getAllProperties(result), "New document object spec compliance"));
// check content
try {
ContentStream contentStream = result.getContentStream();
f = createResult(WARNING, "Document filename and the filename of the content stream do not match!", false);
addResult(assertEquals(name, contentStream.getFileName(), null, f));
f = createResult(WARNING, "cmis:contentStreamFileName and the filename of the content stream do not match!", false);
addResult(assertEquals(result.getContentStreamFileName(), contentStream.getFileName(), null, f));
String fetchedContent = getStringFromContentStream(result.getContentStream());
if (!content.equals(fetchedContent)) {
addResult(createResult(FAILURE, "Content of newly created document doesn't match the orign content!"));
}
} catch (IOException e) {
addResult(createResult(UNEXPECTED_EXCEPTION, "Content of newly created document couldn't be read! Exception: " + e.getMessage(), e, true));
}
} catch (CmisBaseException e) {
addResult(createResult(UNEXPECTED_EXCEPTION, "Newly created document is invalid! Exception: " + e.getMessage(), e, true));
}
// check parents
List<Folder> parents = result.getParents(SELECT_ALL_NO_CACHE_OC);
boolean found = false;
for (Folder folder : parents) {
if (parent.getId().equals(folder.getId())) {
found = true;
break;
}
}
if (!found) {
addResult(createResult(FAILURE, "The folder the document has been created in is not in the list of the document parents!"));
}
return result;
}
use of org.apache.chemistry.opencmis.commons.definitions.DocumentTypeDefinition in project copper-cms by PogeyanOSS.
the class AbstractSessionTest method checkTypeDefinition.
protected CmisTestResult checkTypeDefinition(Session session, TypeDefinition type, String message) {
List<CmisTestResult> results = new ArrayList<CmisTestResult>();
CmisTestResult f;
f = createResult(FAILURE, "Type is null!");
addResult(results, assertNotNull(type, null, f));
if (type != null) {
f = createResult(FAILURE, "Type ID is not set!");
addResult(results, assertStringNotEmpty(type.getId(), null, f));
f = createResult(FAILURE, "Base type ID is not set!");
addResult(results, assertNotNull(type.getBaseTypeId(), null, f));
f = createResult(FAILURE, "Local name is not set!");
addResult(results, assertStringNotEmpty(type.getLocalName(), null, f));
// f = createResult(FAILURE, "Local namespace is not set!");
// addResult(results, assertStringNotEmpty(type.(), null, f));
boolean isQueryNameRequired = Boolean.TRUE.equals(type.isQueryable());
addResult(results, checkQueryName(type.getQueryName(), isQueryNameRequired, "Type Query Name: " + type.getQueryName()));
if ((type.getId() != null) && (type.getBaseTypeId() != null)) {
if (type.getBaseTypeId().value().equals(type.getId())) {
f = createResult(FAILURE, "Base type has parent type!");
addResult(results, assertStringNullOrEmpty(type.getParentTypeId(), null, f));
f = createResult(FAILURE, "Query name of base type is wrong!");
addResult(results, assertEquals(type.getId(), type.getQueryName(), null, f));
} else {
f = createResult(FAILURE, "Parent type is not set!");
addResult(results, assertStringNotEmpty(type.getParentTypeId(), null, f));
}
}
f = createResult(FAILURE, "Creatable flag is not set!");
addResult(results, assertNotNull(type.isCreatable(), null, f));
f = createResult(FAILURE, "Fileable flag is not set!");
addResult(results, assertNotNull(type.isFileable(), null, f));
f = createResult(FAILURE, "Controllable ACL flag is not set!");
addResult(results, assertNotNull(type.isControllableAcl(), null, f));
f = createResult(FAILURE, "Controllable Policy flag is not set!");
addResult(results, assertNotNull(type.isControllablePolicy(), null, f));
f = createResult(FAILURE, "Fulltext indexed flag is not set!");
addResult(results, assertNotNull(type.isFulltextIndexed(), null, f));
f = createResult(FAILURE, "Included in super type flag is not set!");
addResult(results, assertNotNull(type.isIncludedInSupertypeQuery(), null, f));
f = createResult(FAILURE, "Queryable flag is not set!");
addResult(results, assertNotNull(type.isQueryable(), null, f));
f = createResult(WARNING, "Type display name is not set!");
addResult(results, assertStringNotEmpty(type.getDisplayName(), null, f));
f = createResult(WARNING, "Type description is not set!");
addResult(results, assertStringNotEmpty(type.getDescription(), null, f));
if (BaseTypeId.CMIS_DOCUMENT.equals(type.getBaseTypeId())) {
DocumentTypeDefinition docType = (DocumentTypeDefinition) type;
f = createResult(FAILURE, "Versionable flag is not set!");
addResult(results, assertNotNull(docType.isVersionable(), null, f));
f = createResult(FAILURE, "Content stream allowed flag is not set!");
addResult(results, assertNotNull(docType.getContentStreamAllowed(), null, f));
} else if (BaseTypeId.CMIS_FOLDER.equals(type.getBaseTypeId())) {
if (type.isFileable() != null) {
f = createResult(FAILURE, "Folder types must be fileable!");
addResult(results, assertIsTrue(type.isFileable(), null, f));
}
} else if (BaseTypeId.CMIS_RELATIONSHIP.equals(type.getBaseTypeId())) {
RelationshipTypeDefinition relType = (RelationshipTypeDefinition) type;
f = createResult(FAILURE, "Allowed Source Type IDs are not set!");
addResult(results, assertNotNull(relType.getAllowedSourceTypeIds(), null, f));
if (relType.getAllowedSourceTypeIds() != null) {
for (String typeId : relType.getAllowedSourceTypeIds()) {
try {
session.getTypeDefinition(typeId);
} catch (CmisInvalidArgumentException e) {
addResult(results, createResult(WARNING, "Allowed Source Type IDs contain a type ID that doesn't exist: " + typeId));
} catch (CmisObjectNotFoundException e) {
addResult(results, createResult(WARNING, "Allowed Source Type IDs contain a type ID that doesn't exist: " + typeId));
}
}
}
f = createResult(FAILURE, "Allowed Target Type IDs are not set!");
addResult(results, assertNotNull(relType.getAllowedTargetTypeIds(), null, f));
if (relType.getAllowedTargetTypeIds() != null) {
for (String typeId : relType.getAllowedTargetTypeIds()) {
try {
session.getTypeDefinition(typeId);
} catch (CmisInvalidArgumentException e) {
addResult(results, createResult(WARNING, "Allowed Target Type IDs contain a type ID that doesn't exist: " + typeId));
} catch (CmisObjectNotFoundException e) {
addResult(results, createResult(WARNING, "Allowed Target Type IDs contain a type ID that doesn't exist: " + typeId));
}
}
}
if (type.isFileable() != null) {
f = createResult(FAILURE, "Relationship types must not be fileable!");
addResult(results, assertIsFalse(type.isFileable(), null, f));
}
} else if (BaseTypeId.CMIS_POLICY.equals(type.getBaseTypeId())) {
// nothing to do
} else if (BaseTypeId.CMIS_SECONDARY.equals(type.getBaseTypeId())) {
if (type.isCreatable() != null) {
f = createResult(FAILURE, "Secondary types must not be creatable!");
addResult(results, assertIsFalse(type.isCreatable(), null, f));
}
if (type.isFileable() != null) {
f = createResult(FAILURE, "Secondary types must not be fileable!");
addResult(results, assertIsFalse(type.isFileable(), null, f));
}
if (type.isControllableAcl() != null) {
f = createResult(FAILURE, "The controllable ACL flag must be false for secondary types!");
addResult(results, assertIsFalse(type.isControllableAcl(), null, f));
}
if (type.isControllablePolicy() != null) {
f = createResult(FAILURE, "The controllable policy flag must be false for secondary types!");
addResult(results, assertIsFalse(type.isControllablePolicy(), null, f));
}
}
// check properties
if (!BaseTypeId.CMIS_SECONDARY.equals(type.getBaseTypeId())) {
f = createResult(FAILURE, "Type has no property definitions!");
addResult(results, assertNotNull(type.getPropertyDefinitions(), null, f));
if (type.getPropertyDefinitions() != null) {
for (PropertyDefinition<?> propDef : type.getPropertyDefinitions().values()) {
if (propDef == null) {
addResult(results, createResult(FAILURE, "A property definition is null!"));
} else if (propDef.getId() == null) {
addResult(results, createResult(FAILURE, "A property definition ID is null!"));
} else {
addResult(results, checkPropertyDefinition(propDef, "Property definition: " + propDef.getId()));
}
}
}
CmisPropertyDefintion cpd;
// cmis:name
cpd = new CmisPropertyDefintion(PropertyIds.NAME, null, PropertyType.STRING, Cardinality.SINGLE, null, null, null);
addResult(results, cpd.check(type));
// cmis:objectId
cpd = new CmisPropertyDefintion(PropertyIds.OBJECT_ID, false, PropertyType.ID, Cardinality.SINGLE, Updatability.ONCREATE, null, null);
addResult(results, cpd.check(type));
// cmis:baseTypeId
cpd = new CmisPropertyDefintion(PropertyIds.BASE_TYPE_ID, false, PropertyType.ID, Cardinality.SINGLE, Updatability.READONLY, null, null);
addResult(results, cpd.check(type));
// cmis:objectTypeId
cpd = new CmisPropertyDefintion(PropertyIds.OBJECT_TYPE_ID, true, PropertyType.ID, Cardinality.SINGLE, Updatability.ONCREATE, null, null);
addResult(results, cpd.check(type));
// cmis:createdBy
cpd = new CmisPropertyDefintion(PropertyIds.CREATED_BY, false, PropertyType.STRING, Cardinality.SINGLE, Updatability.READONLY, true, true);
addResult(results, cpd.check(type));
// cmis:creationDate
cpd = new CmisPropertyDefintion(PropertyIds.CREATION_DATE, false, PropertyType.DATETIME, Cardinality.SINGLE, Updatability.READONLY, true, true);
addResult(results, cpd.check(type));
// cmis:lastModifiedBy
cpd = new CmisPropertyDefintion(PropertyIds.LAST_MODIFIED_BY, false, PropertyType.STRING, Cardinality.SINGLE, Updatability.READONLY, true, true);
addResult(results, cpd.check(type));
// cmis:lastModificationDate
cpd = new CmisPropertyDefintion(PropertyIds.LAST_MODIFICATION_DATE, false, PropertyType.DATETIME, Cardinality.SINGLE, Updatability.READONLY, true, true);
addResult(results, cpd.check(type));
// cmis:changeToken
cpd = new CmisPropertyDefintion(PropertyIds.CHANGE_TOKEN, false, PropertyType.STRING, Cardinality.SINGLE, Updatability.READONLY, null, null);
addResult(results, cpd.check(type));
// CMIS 1.1 properties
if (session.getRepositoryInfo().getCmisVersion() == CmisVersion.CMIS_1_1) {
// cmis:description
cpd = new CmisPropertyDefintion(PropertyIds.DESCRIPTION, null, PropertyType.STRING, Cardinality.SINGLE, null, null, null);
addResult(results, cpd.check(type));
// cmis:secondaryObjectTypeIds
cpd = new CmisPropertyDefintion(PropertyIds.SECONDARY_OBJECT_TYPE_IDS, false, PropertyType.ID, Cardinality.MULTI, null, null, false);
addResult(results, cpd.check(type));
if (BaseTypeId.CMIS_DOCUMENT.equals(type.getBaseTypeId())) {
// cmis:isPrivateWorkingCopy
cpd = new CmisPropertyDefintion(PropertyIds.IS_PRIVATE_WORKING_COPY, null, PropertyType.BOOLEAN, Cardinality.SINGLE, Updatability.READONLY, null, null);
addResult(results, cpd.check(type));
}
}
if (BaseTypeId.CMIS_DOCUMENT.equals(type.getBaseTypeId())) {
// cmis:isImmutable
cpd = new CmisPropertyDefintion(PropertyIds.IS_IMMUTABLE, false, PropertyType.BOOLEAN, Cardinality.SINGLE, Updatability.READONLY, null, null);
addResult(results, cpd.check(type));
// cmis:isLatestVersion
cpd = new CmisPropertyDefintion(PropertyIds.IS_LATEST_VERSION, false, PropertyType.BOOLEAN, Cardinality.SINGLE, Updatability.READONLY, null, null);
addResult(results, cpd.check(type));
// cmis:isMajorVersion
cpd = new CmisPropertyDefintion(PropertyIds.IS_MAJOR_VERSION, false, PropertyType.BOOLEAN, Cardinality.SINGLE, Updatability.READONLY, null, null);
addResult(results, cpd.check(type));
// cmis:isLatestMajorVersion
cpd = new CmisPropertyDefintion(PropertyIds.IS_LATEST_MAJOR_VERSION, false, PropertyType.BOOLEAN, Cardinality.SINGLE, Updatability.READONLY, null, null);
addResult(results, cpd.check(type));
// cmis:versionLabel
cpd = new CmisPropertyDefintion(PropertyIds.VERSION_LABEL, false, PropertyType.STRING, Cardinality.SINGLE, Updatability.READONLY, null, null);
addResult(results, cpd.check(type));
// cmis:versionSeriesId
cpd = new CmisPropertyDefintion(PropertyIds.VERSION_SERIES_ID, false, PropertyType.ID, Cardinality.SINGLE, Updatability.READONLY, null, null);
addResult(results, cpd.check(type));
// cmis:isVersionSeriesCheckedOut
cpd = new CmisPropertyDefintion(PropertyIds.IS_VERSION_SERIES_CHECKED_OUT, false, PropertyType.BOOLEAN, Cardinality.SINGLE, Updatability.READONLY, null, null);
addResult(results, cpd.check(type));
// cmis:versionSeriesCheckedOutBy
cpd = new CmisPropertyDefintion(PropertyIds.VERSION_SERIES_CHECKED_OUT_BY, false, PropertyType.STRING, Cardinality.SINGLE, Updatability.READONLY, null, null);
addResult(results, cpd.check(type));
// cmis:versionSeriesCheckedOutId
cpd = new CmisPropertyDefintion(PropertyIds.VERSION_SERIES_CHECKED_OUT_ID, false, PropertyType.ID, Cardinality.SINGLE, Updatability.READONLY, null, null);
addResult(results, cpd.check(type));
// cmis:checkinComment
cpd = new CmisPropertyDefintion(PropertyIds.CHECKIN_COMMENT, false, PropertyType.STRING, Cardinality.SINGLE, Updatability.READONLY, null, null);
addResult(results, cpd.check(type));
// cmis:contentStreamLength
cpd = new CmisPropertyDefintion(PropertyIds.CONTENT_STREAM_LENGTH, false, PropertyType.INTEGER, Cardinality.SINGLE, Updatability.READONLY, null, null);
addResult(results, cpd.check(type));
// cmis:contentStreamMimeType
cpd = new CmisPropertyDefintion(PropertyIds.CONTENT_STREAM_MIME_TYPE, false, PropertyType.STRING, Cardinality.SINGLE, Updatability.READONLY, null, null);
addResult(results, cpd.check(type));
// cmis:contentStreamFileName
cpd = new CmisPropertyDefintion(PropertyIds.CONTENT_STREAM_FILE_NAME, false, PropertyType.STRING, Cardinality.SINGLE, Updatability.READONLY, null, null);
addResult(results, cpd.check(type));
// cmis:contentStreamId
cpd = new CmisPropertyDefintion(PropertyIds.CONTENT_STREAM_ID, false, PropertyType.ID, Cardinality.SINGLE, Updatability.READONLY, null, null);
addResult(results, cpd.check(type));
} else if (BaseTypeId.CMIS_FOLDER.equals(type.getBaseTypeId())) {
// cmis:parentId
cpd = new CmisPropertyDefintion(PropertyIds.PARENT_ID, false, PropertyType.ID, Cardinality.SINGLE, Updatability.READONLY, null, null);
addResult(results, cpd.check(type));
// cmis:path
cpd = new CmisPropertyDefintion(PropertyIds.PATH, false, PropertyType.STRING, Cardinality.SINGLE, Updatability.READONLY, null, null);
addResult(results, cpd.check(type));
// cmis:allowedChildObjectTypeIds
cpd = new CmisPropertyDefintion(PropertyIds.ALLOWED_CHILD_OBJECT_TYPE_IDS, false, PropertyType.ID, Cardinality.MULTI, Updatability.READONLY, null, false);
addResult(results, cpd.check(type));
} else if (BaseTypeId.CMIS_RELATIONSHIP.equals(type.getBaseTypeId())) {
// cmis:sourceId
cpd = new CmisPropertyDefintion(PropertyIds.SOURCE_ID, true, PropertyType.ID, Cardinality.SINGLE, null, null, null);
addResult(results, cpd.check(type));
// cmis:targetId
cpd = new CmisPropertyDefintion(PropertyIds.TARGET_ID, true, PropertyType.ID, Cardinality.SINGLE, null, null, null);
addResult(results, cpd.check(type));
} else if (BaseTypeId.CMIS_POLICY.equals(type.getBaseTypeId())) {
// cmis:policyText
cpd = new CmisPropertyDefintion(PropertyIds.POLICY_TEXT, null, PropertyType.STRING, Cardinality.SINGLE, null, null, null);
addResult(results, cpd.check(type));
}
}
}
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 ChangeTokenTest method runUpdateDocumentTest.
private void runUpdateDocumentTest(Session session, Folder testFolder) {
Document doc = createDocument(session, testFolder, "update1.txt", "Hello World!");
try {
if (doc.getChangeToken() == null) {
addResult(createResult(SKIPPED, "Repository does not provide change tokens for documents. Test skipped!"));
return;
}
DocumentTypeDefinition type = (DocumentTypeDefinition) doc.getType();
PropertyDefinition<?> namePropDef = type.getPropertyDefinitions().get(PropertyIds.NAME);
if (namePropDef.getUpdatability() == Updatability.WHENCHECKEDOUT || !doc.getAllowableActions().getAllowableActions().contains(Action.CAN_UPDATE_PROPERTIES)) {
addResult(createResult(SKIPPED, "Document name can't be changed. Test skipped!"));
return;
}
// the first update should succeed
Map<String, Object> properties2 = new HashMap<String, Object>();
properties2.put(PropertyIds.NAME, "update2.txt");
ObjectId newId = doc.updateProperties(properties2, false);
if (!doc.getId().equals(newId.getId())) {
// the repository created a new version
// -> a change token test does not make sense
addResult(createResult(INFO, "The repository created a new version. Change tokens are not relevant here."));
} else {
try {
Map<String, Object> properties3 = new HashMap<String, Object>();
properties3.put(PropertyIds.NAME, "update3.txt");
doc.updateProperties(properties3, false);
addResult(createResult(FAILURE, "Updating properties a second time with the same change token " + "should result in an UpdateConflict exception!"));
// } catch (CmisUpdateConflictException e) {
} catch (CmisConstraintException e) {
// expected exception
}
}
} finally {
deleteObject(doc);
}
}
Aggregations