Search in sources :

Example 36 with Version

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

the class RejectRecordTest method testRevertAfterReject.

/**
 */
public void testRevertAfterReject() throws Exception {
    doBehaviourDrivenTest(new BehaviourDrivenTest() {

        private NodeRef document;

        public void given() {
            NodeRef folder = fileFolderService.create(documentLibrary, GUID.generate(), TYPE_FOLDER).getNodeRef();
            document = fileFolderService.create(folder, GUID.generate(), TYPE_CONTENT).getNodeRef();
            assertFalse(recordService.isRecord(document));
            ownableService.setOwner(document, userName);
            versionService.ensureVersioningEnabled(document, null);
            // document is declared as a record by user
            AuthenticationUtil.runAs(new RunAsWork<Void>() {

                public Void doWork() throws Exception {
                    // declare record
                    recordService.createRecord(filePlan, document);
                    return null;
                }
            }, userName);
            assertTrue(nodeService.hasAspect(document, ASPECT_FILE_PLAN_COMPONENT));
        }

        public void when() {
            // reject the record
            recordService.rejectRecord(document, REASON);
            assertFalse(nodeService.hasAspect(document, ASPECT_FILE_PLAN_COMPONENT));
            // upload a new version of the document
            AuthenticationUtil.runAs(new RunAsWork<Void>() {

                public Void doWork() throws Exception {
                    ContentWriter writer = contentService.getWriter(document, ContentModel.PROP_CONTENT, true);
                    writer.putContent("This is a change to the content and should force a new version");
                    versionService.createVersion(document, null);
                    return null;
                }
            }, userName);
            assertFalse(nodeService.hasAspect(document, ASPECT_FILE_PLAN_COMPONENT));
            VersionHistory history = versionService.getVersionHistory(document);
            assertEquals(2, history.getAllVersions().size());
            final Version initial = history.getRootVersion();
            assertFalse(nodeService.hasAspect(initial.getFrozenStateNodeRef(), ASPECT_FILE_PLAN_COMPONENT));
            AuthenticationUtil.runAs(new RunAsWork<Void>() {

                public Void doWork() throws Exception {
                    // revert the document to a previous version
                    versionService.revert(document, initial);
                    return null;
                }
            }, userName);
        }

        public void then() {
            // document is no longer a record
            assertFalse(recordService.isRecord(document));
            // expected owner has be re-set
            assertEquals(userName, ownableService.getOwner(document));
        }
    });
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) ContentWriter(org.alfresco.service.cmr.repository.ContentWriter) RunAsWork(org.alfresco.repo.security.authentication.AuthenticationUtil.RunAsWork) Version(org.alfresco.service.cmr.version.Version) VersionHistory(org.alfresco.service.cmr.version.VersionHistory)

Example 37 with Version

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

the class AutoRecordableVersionsTest method testVersionRecordsRelated.

/**
 * Given that all revisions will be automatically recorded,
 * When I update a document 3 times,
 * Then all 3 created records will be related together using the "VersionedBy" relationship
 */
public void testVersionRecordsRelated() {
    doBehaviourDrivenTest(new BehaviourDrivenTest(dmCollaborator, false) {

        /**
         * given *
         */
        public void given() throws Exception {
            doTestInTransaction(new VoidTest() {

                @Override
                public void runImpl() throws Exception {
                    // set the recordable version policy
                    PropertyMap recordableVersionProperties = new PropertyMap(1);
                    recordableVersionProperties.put(PROP_RECORDABLE_VERSION_POLICY, RecordableVersionPolicy.ALL);
                    recordableVersionProperties.put(PROP_FILE_PLAN, filePlan);
                    nodeService.addAspect(dmDocument, RecordableVersionModel.ASPECT_VERSIONABLE, recordableVersionProperties);
                    // make the node versionable
                    PropertyMap versionableProperties = new PropertyMap(1);
                    versionableProperties.put(ContentModel.PROP_INITIAL_VERSION, false);
                    nodeService.addAspect(dmDocument, ContentModel.ASPECT_VERSIONABLE, versionableProperties);
                }
            });
        }

        /**
         * when *
         */
        public void when() {
            // update the content 3 times
            updateContent();
            updateContent();
            updateContent();
        }

        /**
         * then
         */
        public void then() {
            doTestInTransaction(new VoidTest() {

                @Override
                public void runImpl() throws Exception {
                    // check that the record has been recorded
                    checkRecordedVersion(dmDocument, null, "0.3");
                    Version version = versionService.getCurrentVersion(dmDocument);
                    NodeRef record = recordableVersionService.getVersionRecord(version);
                    boolean foundPrevious = false;
                    Set<Relationship> relationships = relationshipService.getRelationshipsFrom(record);
                    assertNotNull(relationships);
                    assertEquals(1, relationships.size());
                    for (Relationship relationship : relationships) {
                        if (relationship.getUniqueName().equals(CUSTOM_REF_VERSIONS.getLocalName())) {
                            NodeRef previousVersionRecord = relationship.getTarget();
                            assertNotNull(previousVersionRecord);
                            foundPrevious = true;
                        }
                    }
                    assertTrue(foundPrevious);
                }
            });
        }

        /**
         * Helper method to update content of dmDocument
         */
        private void updateContent() {
            doTestInTransaction(new VoidTest() {

                @Override
                public void runImpl() throws Exception {
                    ContentWriter writer = contentService.getWriter(dmDocument, ContentModel.PROP_CONTENT, true);
                    writer.putContent(MY_NEW_CONTENT);
                }
            });
        }
    });
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) ContentWriter(org.alfresco.service.cmr.repository.ContentWriter) PropertyMap(org.alfresco.util.PropertyMap) Version(org.alfresco.service.cmr.version.Version) Relationship(org.alfresco.module.org_alfresco_module_rm.relationship.Relationship)

Example 38 with Version

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

the class DeleteRecordVersionTest method testDeleteCurrentVersion.

/**
 * Given a chain of version records (1.0, 1.1, 1.2) which are all related
 * When I delete version record 1.2
 * Then 1.1 is the most recent version
 */
public void testDeleteCurrentVersion() {
    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 version12 = versionHistory.getVersion("1.2");
            NodeRef recordVersion12 = recordableVersionService.getVersionRecord(version12);
            // delete record version 1.2
            nodeService.deleteNode(recordVersion12);
        }

        public void then() {
            // check 1.2
            Version version12 = versionHistory.getVersion("1.2");
            assertNotNull(version12);
            assertTrue(recordableVersionService.isRecordedVersionDestroyed(version12));
            assertNull(recordableVersionService.getVersionRecord(version12));
            // verify 1.1
            Version version11 = versionHistory.getVersion("1.1");
            assertNotNull(version11);
            NodeRef recordVersion11 = recordableVersionService.getVersionRecord(version11);
            assertNotNull(recordVersion11);
            assertTrue(relationshipService.getRelationshipsTo(recordVersion11, RelationshipService.RELATIONSHIP_VERSIONS).isEmpty());
            Set<Relationship> from11 = relationshipService.getRelationshipsFrom(recordVersion11, RelationshipService.RELATIONSHIP_VERSIONS);
            assertEquals(1, from11.size());
            // verify 1.0
            Version version10 = versionHistory.getVersion("1.0");
            assertNotNull(version10);
            NodeRef recordVersion10 = recordableVersionService.getVersionRecord(version10);
            assertNotNull(recordVersion10);
            Set<Relationship> to10 = relationshipService.getRelationshipsTo(recordVersion10, RelationshipService.RELATIONSHIP_VERSIONS);
            assertEquals(1, to10.size());
            assertEquals(recordVersion11, to10.iterator().next().getSource());
            assertTrue(relationshipService.getRelationshipsFrom(recordVersion10, 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 39 with Version

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

the class DeleteRecordVersionTest method testDeleteMiddleVersion.

/**
 * Given a chain of version records (1.0, 1.1, 1.2) which are all related
 * When I delete version record 1.1
 * Then 1.2 now 'versions' 1.0
 */
public void testDeleteMiddleVersion() {
    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 version11 = versionHistory.getVersion("1.1");
            NodeRef recordVersion11 = recordableVersionService.getVersionRecord(version11);
            // delete record version 1.1
            nodeService.deleteNode(recordVersion11);
        }

        public void then() {
            // check the deleted version
            Version version11 = versionHistory.getVersion("1.1");
            assertNotNull(version11);
            assertTrue(recordableVersionService.isRecordedVersionDestroyed(version11));
            NodeRef recordVersion11 = recordableVersionService.getVersionRecord(version11);
            assertNull(recordVersion11);
            // 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.0 setup as expected
            Version version10 = versionHistory.getVersion("1.0");
            assertEquals("1.0", version10.getVersionLabel());
            NodeRef recordVersion10 = recordableVersionService.getVersionRecord(version10);
            assertNotNull(recordVersion10);
            Set<Relationship> to10 = relationshipService.getRelationshipsTo(recordVersion10, RelationshipService.RELATIONSHIP_VERSIONS);
            assertEquals(1, to10.size());
            assertEquals(recordVersion12, to10.iterator().next().getSource());
            assertTrue(relationshipService.getRelationshipsFrom(recordVersion10, 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)

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