Search in sources :

Example 31 with Version

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);
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) Version(org.alfresco.service.cmr.version.Version) BaseUnitTest(org.alfresco.module.org_alfresco_module_rm.test.util.BaseUnitTest) Test(org.junit.Test)

Example 32 with Version

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);
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) Version(org.alfresco.service.cmr.version.Version) BaseUnitTest(org.alfresco.module.org_alfresco_module_rm.test.util.BaseUnitTest) Test(org.junit.Test)

Example 33 with Version

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));
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) Version(org.alfresco.service.cmr.version.Version) Test(org.junit.Test) BaseUnitTest(org.alfresco.module.org_alfresco_module_rm.test.util.BaseUnitTest)

Example 34 with Version

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;
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) Version(org.alfresco.service.cmr.version.Version) VersionHistory(org.alfresco.service.cmr.version.VersionHistory)

Example 35 with Version

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);
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) Serializable(java.io.Serializable) Version(org.alfresco.service.cmr.version.Version) QName(org.alfresco.service.namespace.QName) VersionHistory(org.alfresco.service.cmr.version.VersionHistory)

Aggregations

Version (org.alfresco.service.cmr.version.Version)39 NodeRef (org.alfresco.service.cmr.repository.NodeRef)31 VersionHistory (org.alfresco.service.cmr.version.VersionHistory)17 Serializable (java.io.Serializable)12 QName (org.alfresco.service.namespace.QName)9 ArrayList (java.util.ArrayList)8 BaseUnitTest (org.alfresco.module.org_alfresco_module_rm.test.util.BaseUnitTest)8 Test (org.junit.Test)8 HashMap (java.util.HashMap)7 Set (java.util.Set)6 MapNode (org.alfresco.web.bean.repository.MapNode)5 Locale (java.util.Locale)4 Map (java.util.Map)4 Node (org.alfresco.rest.api.model.Node)4 WebApiDescription (org.alfresco.rest.framework.WebApiDescription)4 RunAsWork (org.alfresco.repo.security.authentication.AuthenticationUtil.RunAsWork)3 EntityNotFoundException (org.alfresco.rest.framework.core.exceptions.EntityNotFoundException)3 ContentWriter (org.alfresco.service.cmr.repository.ContentWriter)3 PropertyMap (org.alfresco.util.PropertyMap)3 Collection (java.util.Collection)2