use of org.alfresco.service.cmr.version.Version in project records-management by Alfresco.
the class RecordableVersionServiceImplUnitTest method markAsDestroyedClearNodeRef.
/**
* given that the version node ref has the recorded version aspect applied
* and the associated version record has been deleted
* when I mark the version as destroyed
* then the version is marked as destroyed
* and the reference to the deleted version record is removed
*/
@Test
public void markAsDestroyedClearNodeRef() {
// set up version
Version mockedVersion = mock(VersionImpl.class);
NodeRef versionNodeRef = generateNodeRef();
NodeRef versionRecordNodeRef = generateNodeRef();
when(mockedVersion.getFrozenStateNodeRef()).thenReturn(versionNodeRef);
when(mockedDbNodeService.exists(versionRecordNodeRef)).thenReturn(false);
// indicate that the version doesn't have the aspect
when(mockedDbNodeService.hasAspect(versionNodeRef, RecordableVersionModel.ASPECT_RECORDED_VERSION)).thenReturn(true);
// indicate that the associated version record exists
when(mockedDbNodeService.getProperty(versionNodeRef, RecordableVersionModel.PROP_RECORD_NODE_REF)).thenReturn(versionRecordNodeRef);
// mark as destroyed
recordableVersionService.destroyRecordedVersion(mockedVersion);
// verify that the version was marked as destroyed
verify(mockedDbNodeService).setProperty(versionNodeRef, RecordableVersionModel.PROP_DESTROYED, Boolean.TRUE);
// and the reference to the version record was cleared
verify(mockedDbNodeService).setProperty(versionNodeRef, RecordableVersionModel.PROP_RECORD_NODE_REF, null);
}
use of org.alfresco.service.cmr.version.Version in project records-management by Alfresco.
the class RecordableVersionServiceImplUnitTest method markAsDestroyed.
/**
* given that the version node ref has the recorded version aspect applied
* and the record version reference exists
* when I mark the version as destroyed
* then the version is marked as destroyed
*/
@Test
public void markAsDestroyed() {
// set up version
Version mockedVersion = mock(VersionImpl.class);
NodeRef versionNodeRef = generateNodeRef();
NodeRef versionRecordNodeRef = generateNodeRef();
when(mockedVersion.getFrozenStateNodeRef()).thenReturn(versionNodeRef);
when(mockedDbNodeService.exists(versionRecordNodeRef)).thenReturn(true);
// indicate that the version doesn't have the aspect
when(mockedDbNodeService.hasAspect(versionNodeRef, RecordableVersionModel.ASPECT_RECORDED_VERSION)).thenReturn(true);
// indicate that the associated version record exists
when(mockedDbNodeService.getProperty(versionNodeRef, RecordableVersionModel.PROP_RECORD_NODE_REF)).thenReturn(versionRecordNodeRef);
// mark as destroyed
recordableVersionService.destroyRecordedVersion(mockedVersion);
// verify that the version was marked as destroyed
verify(mockedDbNodeService).setProperty(versionNodeRef, RecordableVersionModel.PROP_DESTROYED, Boolean.TRUE);
// and the reference to the version record was cleared
verify(mockedDbNodeService).setProperty(versionNodeRef, RecordableVersionModel.PROP_RECORD_NODE_REF, null);
}
use of org.alfresco.service.cmr.version.Version in project records-management by Alfresco.
the class VersionRecordAspectUnitTest method beforeDeleteNoVersionNodeRef.
/**
* given that there is no recorded version
* before delete of record
* then nothing happens
*/
@Test
public void beforeDeleteNoVersionNodeRef() {
NodeRef nodeRef = generateNodeRef();
when(mockedRecordableVersionService.getRecordedVersion(nodeRef)).thenReturn(null);
versionRecordAspect.beforeDeleteNode(nodeRef);
verify(mockedNodeService, never()).getProperty(nodeRef, RecordableVersionModel.PROP_VERSION_LABEL);
verify(mockedRecordableVersionService, never()).destroyRecordedVersion(any(Version.class));
}
use of org.alfresco.service.cmr.version.Version in project records-management by Alfresco.
the class RecordServiceImpl method getLatestVersionRecord.
/**
* Helper to get the latest version record for a given document (ie non-record)
*
* @param nodeRef node reference
* @return NodeRef latest version record, null otherwise
*/
private NodeRef getLatestVersionRecord(NodeRef nodeRef) {
NodeRef versionRecord = null;
recordableVersionService.createSnapshotVersion(nodeRef);
// wire record up to previous record
VersionHistory versionHistory = versionService.getVersionHistory(nodeRef);
if (versionHistory != null) {
Collection<Version> previousVersions = versionHistory.getAllVersions();
for (Version previousVersion : previousVersions) {
// look for the associated record
final NodeRef previousRecord = recordableVersionService.getVersionRecord(previousVersion);
if (previousRecord != null) {
versionRecord = previousRecord;
break;
}
}
}
return versionRecord;
}
use of org.alfresco.service.cmr.version.Version in project records-management by Alfresco.
the class RecordableVersionsBaseTest method checkRecordedVersion.
/**
* Helper to check that the current version is recorded
*/
protected void checkRecordedVersion(NodeRef document, String description, String versionLabel) {
// double check that the document is not a record
assertFalse(recordService.isRecord(document));
// store document state
Map<QName, Serializable> beforeProperties = nodeService.getProperties(document);
Set<QName> beforeAspects = nodeService.getAspects(document);
// get the current version
Version version = versionService.getCurrentVersion(document);
// version has been created
assertNotNull(version);
// check the version properties
assertEquals(description, version.getDescription());
assertEquals(versionLabel, version.getVersionLabel());
// get the frozen state
NodeRef frozen = version.getFrozenStateNodeRef();
// check the properties
checkProperties(frozen, beforeProperties);
// compare aspects
checkAspects(frozen, beforeAspects);
// record version node reference is available on version
NodeRef record = recordableVersionService.getVersionRecord(version);
assertNotNull(record);
// check that the version record information has been added
assertTrue(nodeService.hasAspect(record, ASPECT_VERSION_RECORD));
assertEquals(versionLabel, nodeService.getProperty(record, RecordableVersionModel.PROP_VERSION_LABEL));
assertEquals(description, nodeService.getProperty(record, RecordableVersionModel.PROP_VERSION_DESCRIPTION));
// record version is an unfiled record
assertTrue(recordService.isRecord(record));
assertFalse(recordService.isFiled(record));
// check that the created record does not have either of the versionable aspects
assertFalse(nodeService.hasAspect(record, RecordableVersionModel.ASPECT_VERSIONABLE));
// check the version history
VersionHistory versionHistory = versionService.getVersionHistory(document);
assertNotNull(versionHistory);
Version headVersion = versionHistory.getHeadVersion();
assertNotNull(headVersion);
}
Aggregations