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, assertIsTrue(versions.size() > 0, null, f));
if (versions.size() > 0) {
// 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 = doc.getObjectOfLatestVersion(true, SELECT_ALL_NO_CACHE_OC);
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) {
f = createResult(FAILURE,
"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));
}
version.getCreationDate().getTimeInMillis();
// 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