Search in sources :

Example 1 with VersionHistory

use of org.alfresco.service.cmr.version.VersionHistory in project acs-community-packaging by Alfresco.

the class MultilingualManageDialog method initEditionHistory.

/**
 * Constructs a list of objects representing the editions of the
 * logical document
 *
 * @return List of editions
 */
private List<SingleEditionBean> initEditionHistory() {
    // get the mlContainer
    NodeRef mlContainer = getDocumentMlContainer().getNodeRef();
    // get all editions (in descending order - ie. most recent first)
    List<Version> orderedEditionList = new ArrayList<Version>(getEditionService().getEditions(mlContainer).getAllVersions());
    // the list of Single Edition Bean to return
    editionHistory = new ArrayList<SingleEditionBean>(orderedEditionList.size());
    boolean firstEdition = true;
    // for each edition, init a SingleEditionBean
    for (Version edition : orderedEditionList) {
        SingleEditionBean editionBean = new SingleEditionBean();
        MapNode clientEdition = new MapNode(edition.getFrozenStateNodeRef());
        String editionLabel = edition.getVersionLabel();
        if (firstEdition) {
            editionLabel += " (" + Application.getMessage(FacesContext.getCurrentInstance(), MSG_CURRENT) + ")";
        }
        clientEdition.put("editionLabel", editionLabel);
        clientEdition.put("editionNotes", edition.getDescription());
        clientEdition.put("editionAuthor", edition.getCreator());
        clientEdition.put("editionDate", edition.getCreatedDate());
        // Set the edition of the edition bean
        editionBean.setEdition(clientEdition);
        // get translations
        List<VersionHistory> translationHistories = null;
        if (firstEdition) {
            // Get the translations because the current edition doesn't content link with its
            // translation in the version store.
            Map<Locale, NodeRef> translations = getMultilingualContentService().getTranslations(mlContainer);
            translationHistories = new ArrayList<VersionHistory>(translations.size());
            for (NodeRef translation : translations.values()) {
                translationHistories.add(getVersionService().getVersionHistory(translation));
            }
        } else {
            translationHistories = getEditionService().getVersionedTranslations(edition);
        }
        // add each translation in the SingleEditionBean
        for (VersionHistory versionHistory : translationHistories) {
            for (Version checkVersion : versionHistory.getAllVersions()) {
                NodeRef frozenStateNodeRef = checkVersion.getFrozenStateNodeRef();
                if (frozenStateNodeRef.getStoreRef().getIdentifier().equals("lightWeightVersionStore")) {
                    // It's the old one pulled back by serialization
                    // Repopulate the version history
                    NodeRef versionedNodeRef = checkVersion.getVersionedNodeRef();
                    versionHistory = versionService.getVersionHistory(versionedNodeRef);
                    break;
                }
            }
            // get the list of versions (in descending order - ie. most recent first)
            List<Version> orderedVersions = new ArrayList<Version>(versionHistory.getAllVersions());
            // the last version (ie. most recent) is the first version of the list
            Version lastVersion = orderedVersions.get(0);
            // get the properties of the lastVersion
            Map<QName, Serializable> lastVersionProperties = getEditionService().getVersionedMetadatas(lastVersion);
            Locale language = (Locale) lastVersionProperties.get(ContentModel.PROP_LOCALE);
            // create a map node representation of the last version
            MapNode clientLastVersion = new MapNode(lastVersion.getFrozenStateNodeRef());
            clientLastVersion.put("versionName", lastVersionProperties.get(ContentModel.PROP_NAME));
            // use the node service for the description to ensure that the returned value is a text and not a MLText
            clientLastVersion.put("versionDescription", getNodeService().getProperty(lastVersion.getFrozenStateNodeRef(), ContentModel.PROP_DESCRIPTION));
            clientLastVersion.put("versionAuthor", lastVersionProperties.get(ContentModel.PROP_AUTHOR));
            clientLastVersion.put("versionCreatedDate", lastVersionProperties.get(ContentModel.PROP_CREATED));
            clientLastVersion.put("versionModifiedDate", lastVersionProperties.get(ContentModel.PROP_MODIFIED));
            clientLastVersion.put("versionLanguage", getContentFilterLanguagesService().convertToNewISOCode(language.getLanguage()).toUpperCase());
            if (getNodeService().hasAspect(lastVersion.getFrozenStateNodeRef(), ContentModel.ASPECT_MULTILINGUAL_EMPTY_TRANSLATION)) {
                clientLastVersion.put("versionUrl", null);
            } else {
                clientLastVersion.put("versionUrl", DownloadContentServlet.generateBrowserURL(lastVersion.getFrozenStateNodeRef(), clientLastVersion.getName()));
            }
            // add a translation of the editionBean
            editionBean.addTranslations(clientLastVersion);
        }
        editionHistory.add(editionBean);
        firstEdition = false;
    }
    return editionHistory;
}
Also used : Locale(java.util.Locale) Serializable(java.io.Serializable) QName(org.alfresco.service.namespace.QName) ArrayList(java.util.ArrayList) MapNode(org.alfresco.web.bean.repository.MapNode) VersionHistory(org.alfresco.service.cmr.version.VersionHistory) NodeRef(org.alfresco.service.cmr.repository.NodeRef) Version(org.alfresco.service.cmr.version.Version)

Example 2 with VersionHistory

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

the class RecordableVersionsBaseTest method createDocumentWithRecordVersions.

/**
 * Creates a document with three versions (1.0, 1.1, 1.2) all of which
 * are recorded.
 *
 * @return  NodeRef node reference
 */
protected NodeRef createDocumentWithRecordVersions() {
    // create document and initial version (1.0)
    final NodeRef myDocument = doTestInTransaction(new Test<NodeRef>() {

        @Override
        public NodeRef run() throws Exception {
            // create a document
            NodeRef testDoc = fileFolderService.create(dmFolder, GUID.generate(), ContentModel.TYPE_CONTENT).getNodeRef();
            ContentWriter writer = fileFolderService.getWriter(testDoc);
            writer.setEncoding("UTF-8");
            writer.setMimetype(MimetypeMap.MIMETYPE_TEXT_PLAIN);
            writer.putContent(GUID.generate());
            // make versionable
            Map<QName, Serializable> props = new HashMap<QName, Serializable>(2);
            props.put(RecordableVersionModel.PROP_RECORDABLE_VERSION_POLICY, RecordableVersionPolicy.ALL);
            props.put(RecordableVersionModel.PROP_FILE_PLAN, filePlan);
            nodeService.addAspect(testDoc, RecordableVersionModel.ASPECT_VERSIONABLE, props);
            nodeService.addAspect(testDoc, ContentModel.ASPECT_VERSIONABLE, null);
            return testDoc;
        }
    });
    // create 1.1
    doTestInTransaction(new Test<Void>() {

        @Override
        public Void run() throws Exception {
            // update content
            ContentWriter writer = fileFolderService.getWriter(myDocument);
            writer.putContent(GUID.generate());
            return null;
        }
    });
    // create 1.2
    doTestInTransaction(new Test<Void>() {

        @Override
        public Void run() throws Exception {
            // update content
            ContentWriter writer = fileFolderService.getWriter(myDocument);
            writer.putContent(GUID.generate());
            return null;
        }
    });
    // we do these checks to ensure that the test data is in the correct state before we
    // start to manipulate the versions and execute tests
    doTestInTransaction(new Test<Void>() {

        @Override
        public Void run() throws Exception {
            // 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());
            NodeRef recordVersion12 = recordableVersionService.getVersionRecord(version12);
            assertNotNull(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());
            NodeRef recordVersion11 = recordableVersionService.getVersionRecord(version11);
            assertNotNull(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());
            NodeRef recordVersion10 = recordableVersionService.getVersionRecord(version10);
            assertNotNull(recordVersion10);
            Set<Relationship> to10 = relationshipService.getRelationshipsTo(recordVersion10, "versions");
            assertEquals(1, to10.size());
            assertEquals(recordVersion11, to10.iterator().next().getSource());
            assertTrue(relationshipService.getRelationshipsFrom(recordVersion10, "versions").isEmpty());
            return null;
        }
    });
    return myDocument;
}
Also used : Serializable(java.io.Serializable) Set(java.util.Set) HashSet(java.util.HashSet) QName(org.alfresco.service.namespace.QName) VersionHistory(org.alfresco.service.cmr.version.VersionHistory) NodeRef(org.alfresco.service.cmr.repository.NodeRef) ContentWriter(org.alfresco.service.cmr.repository.ContentWriter) Version(org.alfresco.service.cmr.version.Version) Collection(java.util.Collection) MimetypeMap(org.alfresco.repo.content.MimetypeMap) HashMap(java.util.HashMap) Map(java.util.Map) PropertyMap(org.alfresco.util.PropertyMap)

Example 3 with VersionHistory

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

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

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

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