Search in sources :

Example 11 with Version

use of org.alfresco.service.cmr.version.Version in project records-management by Alfresco.

the class RecordableVersionsBaseTest method checkNotRecordedAspect.

/**
 * Helper method to check that the current version is not recorded
 */
protected void checkNotRecordedAspect(NodeRef document, String description, String versionLabel) {
    // double check that the document is not a record
    assertFalse(recordService.isRecord(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());
    // record version node reference is available on version
    NodeRef record = recordableVersionService.getVersionRecord(version);
    assertNull(record);
    // 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) Version(org.alfresco.service.cmr.version.Version) VersionHistory(org.alfresco.service.cmr.version.VersionHistory)

Example 12 with Version

use of org.alfresco.service.cmr.version.Version in project records-management by Alfresco.

the class DeleteRecordVersionTest method testDeleteOldestVersion.

/**
 * Given a chain of version records (1.0, 1.1, 1.2) which are all related
 * When I delete version record 1.0
 * Then 1.1 is the oldest version
 */
public void testDeleteOldestVersion() {
    final NodeRef myDocument = createDocumentWithRecordVersions();
    doBehaviourDrivenTest(new BehaviourDrivenTest() {

        private VersionHistory versionHistory;

        public void given() throws Exception {
            // get version history
            versionHistory = versionService.getVersionHistory(myDocument);
        }

        public void when() {
            Version version10 = versionHistory.getVersion("1.0");
            NodeRef recordVersion10 = recordableVersionService.getVersionRecord(version10);
            // delete record version 1.0
            nodeService.deleteNode(recordVersion10);
        }

        public void then() {
            // check the deleted version
            Version version10 = versionHistory.getVersion("1.0");
            assertNotNull(version10);
            assertTrue(recordableVersionService.isRecordedVersionDestroyed(version10));
            NodeRef recordVersion10 = recordableVersionService.getVersionRecord(version10);
            assertNull(recordVersion10);
            // verify 1.2 setup as expected
            Version version12 = versionHistory.getHeadVersion();
            assertEquals("1.2", version12.getVersionLabel());
            NodeRef recordVersion12 = recordableVersionService.getVersionRecord(version12);
            assertNotNull(recordVersion12);
            assertTrue(relationshipService.getRelationshipsTo(recordVersion12, RelationshipService.RELATIONSHIP_VERSIONS).isEmpty());
            Set<Relationship> from12 = relationshipService.getRelationshipsFrom(recordVersion12, RelationshipService.RELATIONSHIP_VERSIONS);
            assertEquals(1, from12.size());
            // verify 1.1 setup as expected
            Version version11 = versionHistory.getPredecessor(version12);
            assertEquals("1.1", version11.getVersionLabel());
            NodeRef recordVersion11 = recordableVersionService.getVersionRecord(version11);
            assertNotNull(recordVersion11);
            Set<Relationship> to11 = relationshipService.getRelationshipsTo(recordVersion11, RelationshipService.RELATIONSHIP_VERSIONS);
            assertEquals(1, to11.size());
            assertEquals(recordVersion12, to11.iterator().next().getSource());
            assertTrue(relationshipService.getRelationshipsFrom(recordVersion11, RelationshipService.RELATIONSHIP_VERSIONS).isEmpty());
        }
    });
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) Set(java.util.Set) Version(org.alfresco.service.cmr.version.Version) VersionHistory(org.alfresco.service.cmr.version.VersionHistory)

Example 13 with Version

use of org.alfresco.service.cmr.version.Version in project records-management by Alfresco.

the class DeleteRecordVersionTest method testDestroyVersionRecordWithMetadata.

/**
 * Given that a version record
 * When the version record is destroyed whilst retaining the meta data
 * Then the version is marked as destroyed in the collab version history
 */
public void testDestroyVersionRecordWithMetadata() {
    final NodeRef myDocument = createDocumentWithRecordVersions();
    doBehaviourDrivenTest(new BehaviourDrivenTest() {

        private VersionHistory versionHistory;

        private NodeRef recordVersion11;

        public void given() throws Exception {
            // create file plan structure
            NodeRef myCategory = filePlanService.createRecordCategory(filePlan, GUID.generate());
            utils.createBasicDispositionSchedule(myCategory, GUID.generate(), GUID.generate(), true, true);
            NodeRef myRecordFolder = recordFolderService.createRecordFolder(myCategory, GUID.generate());
            // get version history
            versionHistory = versionService.getVersionHistory(myDocument);
            // file and complete all the version records into my record folder
            for (Version version : versionHistory.getAllVersions()) {
                NodeRef record = recordableVersionService.getVersionRecord(version);
                fileFolderService.move(record, myRecordFolder, null);
                utils.completeRecord(record);
            }
        }

        public void when() {
            Version version11 = versionHistory.getVersion("1.1");
            recordVersion11 = recordableVersionService.getVersionRecord(version11);
            Map<String, Serializable> params = new HashMap<String, Serializable>(1);
            params.put(CompleteEventAction.PARAM_EVENT_NAME, CommonRMTestUtils.DEFAULT_EVENT_NAME);
            rmActionService.executeRecordsManagementAction(recordVersion11, CompleteEventAction.NAME, params);
            rmActionService.executeRecordsManagementAction(recordVersion11, CutOffAction.NAME);
            rmActionService.executeRecordsManagementAction(recordVersion11, DestroyAction.NAME);
        }

        public void then() {
            // verify that the version history looks as expected
            VersionHistory versionHistory = versionService.getVersionHistory(myDocument);
            assertNotNull(versionHistory);
            Collection<Version> versions = versionHistory.getAllVersions();
            assertEquals(3, versions.size());
            // verify 1.2 setup as expected
            Version version12 = versionHistory.getHeadVersion();
            assertEquals("1.2", version12.getVersionLabel());
            assertFalse(recordableVersionService.isRecordedVersionDestroyed(version12));
            NodeRef recordVersion12 = recordableVersionService.getVersionRecord(version12);
            assertNotNull(recordVersion12);
            assertFalse(recordService.isMetadataStub(recordVersion12));
            assertTrue(relationshipService.getRelationshipsTo(recordVersion12, "versions").isEmpty());
            Set<Relationship> from12 = relationshipService.getRelationshipsFrom(recordVersion12, "versions");
            assertEquals(1, from12.size());
            // verify 1.1 setup as expected
            Version version11 = versionHistory.getPredecessor(version12);
            assertEquals("1.1", version11.getVersionLabel());
            assertTrue(recordableVersionService.isRecordedVersionDestroyed(version11));
            assertNotNull(recordVersion11);
            assertTrue(recordService.isMetadataStub(recordVersion11));
            Set<Relationship> to11 = relationshipService.getRelationshipsTo(recordVersion11, "versions");
            assertEquals(1, to11.size());
            assertEquals(recordVersion12, to11.iterator().next().getSource());
            Set<Relationship> from11 = relationshipService.getRelationshipsFrom(recordVersion11, "versions");
            assertEquals(1, from11.size());
            // verify 1.0 setup as expected
            Version version10 = versionHistory.getPredecessor(version11);
            assertEquals("1.0", version10.getVersionLabel());
            assertFalse(recordableVersionService.isRecordedVersionDestroyed(version10));
            NodeRef recordVersion10 = recordableVersionService.getVersionRecord(version10);
            assertNotNull(recordVersion10);
            assertFalse(recordService.isMetadataStub(recordVersion10));
            Set<Relationship> to10 = relationshipService.getRelationshipsTo(recordVersion10, "versions");
            assertEquals(1, to10.size());
            assertEquals(recordVersion11, to10.iterator().next().getSource());
            assertTrue(relationshipService.getRelationshipsFrom(recordVersion10, "versions").isEmpty());
        }
    });
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) Serializable(java.io.Serializable) Set(java.util.Set) Version(org.alfresco.service.cmr.version.Version) Collection(java.util.Collection) VersionHistory(org.alfresco.service.cmr.version.VersionHistory) MimetypeMap(org.alfresco.repo.content.MimetypeMap) HashMap(java.util.HashMap) Map(java.util.Map)

Example 14 with Version

use of org.alfresco.service.cmr.version.Version in project records-management by Alfresco.

the class DestroyAction method executeRecordLevelDisposition.

/**
 * @see org.alfresco.module.org_alfresco_module_rm.action.RMDispositionActionExecuterAbstractBase#executeRecordLevelDisposition(org.alfresco.service.cmr.action.Action, org.alfresco.service.cmr.repository.NodeRef)
 */
@Override
protected void executeRecordLevelDisposition(Action action, NodeRef record) {
    if (isGhostOnDestroySetForAction(action, record)) {
        // mark version as destroyed
        Version version = recordableVersionService.getRecordedVersion(record);
        if (version != null) {
            recordableVersionService.destroyRecordedVersion(version);
        }
        // Hide from inplace users to give the impression of destruction
        inplaceRecordService.hideRecord(record);
        // Add the ghosted aspect
        getNodeService().addAspect(record, ASPECT_GHOSTED, null);
        // destroy content
        contentDestructionComponent.destroyContent(record);
    } else {
        // just delete the node
        getNodeService().deleteNode(record);
    }
}
Also used : Version(org.alfresco.service.cmr.version.Version)

Example 15 with Version

use of org.alfresco.service.cmr.version.Version in project records-management by Alfresco.

the class AdHocRecordableVersionsTest method testRecordedVersionWithRecordMetadataAspect.

/**
 * Test recorded version with record metadata aspect (want to ensure additional non-rm URI properties and aspects
 * don't find their way into the frozen state)
 */
public void testRecordedVersionWithRecordMetadataAspect() {
    doBehaviourDrivenTest(new BehaviourDrivenTest(dmCollaborator) {

        private Map<String, Serializable> versionProperties;

        public void given() throws Exception {
            // setup version properties
            versionProperties = new HashMap<String, Serializable>(4);
            versionProperties.put(Version.PROP_DESCRIPTION, DESCRIPTION);
            versionProperties.put(VersionModel.PROP_VERSION_TYPE, VersionType.MINOR);
            versionProperties.put(RecordableVersionServiceImpl.KEY_RECORDABLE_VERSION, true);
            versionProperties.put(RecordableVersionServiceImpl.KEY_FILE_PLAN, filePlan);
        }

        public void when() {
            // create version
            final Version version = versionService.createVersion(dmDocument, versionProperties);
            AuthenticationUtil.runAs(new RunAsWork<Void>() {

                public Void doWork() throws Exception {
                    // add custom meta-data to record
                    NodeRef record = recordableVersionService.getVersionRecord(version);
                    assertNotNull(record);
                    recordService.addRecordType(record, TestModel.ASPECT_RECORD_METADATA);
                    nodeService.setProperty(record, TestModel.PROPERTY_RECORD_METADATA, "Peter Wetherall");
                    return null;
                }
            }, AuthenticationUtil.getAdminUserName());
        }

        public void then() {
            // check that the record has been recorded
            checkRecordedVersion(dmDocument, DESCRIPTION, "0.1");
        }
    });
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) Serializable(java.io.Serializable) HashMap(java.util.HashMap) Version(org.alfresco.service.cmr.version.Version) RunAsWork(org.alfresco.repo.security.authentication.AuthenticationUtil.RunAsWork) AlfrescoRuntimeException(org.alfresco.error.AlfrescoRuntimeException)

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