Search in sources :

Example 16 with VersionHistory

use of org.alfresco.service.cmr.version.VersionHistory 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 17 with VersionHistory

use of org.alfresco.service.cmr.version.VersionHistory 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 18 with VersionHistory

use of org.alfresco.service.cmr.version.VersionHistory 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)

Example 19 with VersionHistory

use of org.alfresco.service.cmr.version.VersionHistory in project alfresco-remote-api by Alfresco.

the class RenditionsImpl method findVersionIfApplicable.

private NodeRef findVersionIfApplicable(NodeRef nodeRef, String versionLabelId) {
    if (versionLabelId != null) {
        nodeRef = nodes.validateOrLookupNode(nodeRef.getId(), null);
        VersionHistory vh = versionService.getVersionHistory(nodeRef);
        if (vh != null) {
            try {
                Version v = vh.getVersion(versionLabelId);
                nodeRef = VersionUtil.convertNodeRef(v.getFrozenStateNodeRef());
            } catch (VersionDoesNotExistException vdne) {
                throw new NotFoundException("Couldn't find version: [" + nodeRef.getId() + ", " + versionLabelId + "]");
            }
        }
    }
    return nodeRef;
}
Also used : VersionDoesNotExistException(org.alfresco.service.cmr.version.VersionDoesNotExistException) Version(org.alfresco.service.cmr.version.Version) NotFoundException(org.alfresco.rest.framework.core.exceptions.NotFoundException) VersionHistory(org.alfresco.service.cmr.version.VersionHistory)

Example 20 with VersionHistory

use of org.alfresco.service.cmr.version.VersionHistory in project alfresco-remote-api by Alfresco.

the class NodeVersionsRelation method readAll.

/**
 * List version history
 *
 * @param nodeId String id of (live) node
 */
@Override
@WebApiDescription(title = "Return version history as a paged list of version node infos")
public CollectionWithPagingInfo<Node> readAll(String nodeId, Parameters parameters) {
    NodeRef nodeRef = nodes.validateOrLookupNode(nodeId, null);
    VersionHistory vh = versionService.getVersionHistory(nodeRef);
    Map<String, UserInfo> mapUserInfo = new HashMap<>(10);
    List<String> includeParam = parameters.getInclude();
    List<Node> collection = null;
    if (vh != null) {
        collection = new ArrayList<>(vh.getAllVersions().size());
        for (Version v : vh.getAllVersions()) {
            Node node = nodes.getFolderOrDocument(v.getFrozenStateNodeRef(), null, null, includeParam, mapUserInfo);
            mapVersionInfo(v, node);
            collection.add(node);
        }
    }
    return listPage(collection, parameters.getPaging());
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) HashMap(java.util.HashMap) Version(org.alfresco.service.cmr.version.Version) Node(org.alfresco.rest.api.model.Node) UserInfo(org.alfresco.rest.api.model.UserInfo) VersionHistory(org.alfresco.service.cmr.version.VersionHistory) WebApiDescription(org.alfresco.rest.framework.WebApiDescription)

Aggregations

VersionHistory (org.alfresco.service.cmr.version.VersionHistory)20 Version (org.alfresco.service.cmr.version.Version)18 NodeRef (org.alfresco.service.cmr.repository.NodeRef)17 Serializable (java.io.Serializable)7 ArrayList (java.util.ArrayList)6 QName (org.alfresco.service.namespace.QName)6 HashMap (java.util.HashMap)5 Set (java.util.Set)5 Locale (java.util.Locale)4 Map (java.util.Map)4 MapNode (org.alfresco.web.bean.repository.MapNode)4 Collection (java.util.Collection)2 MimetypeMap (org.alfresco.repo.content.MimetypeMap)2 Node (org.alfresco.rest.api.model.Node)2 UserInfo (org.alfresco.rest.api.model.UserInfo)2 ContentWriter (org.alfresco.service.cmr.repository.ContentWriter)2 HashSet (java.util.HashSet)1 List (java.util.List)1 RunAsWork (org.alfresco.repo.security.authentication.AuthenticationUtil.RunAsWork)1 VersionImpl (org.alfresco.repo.version.common.VersionImpl)1