Search in sources :

Example 1 with Version

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

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

the class RecordableVersionServiceImplUnitTest method notRecordedCreateRecordFromVersion.

/**
 * Given that a nodes last version is not recorded
 * When I try to create a record from the latest version
 * Then the latest version is marked as record and a new record version is created to store the version state
 */
@SuppressWarnings("unchecked")
@Test
public void notRecordedCreateRecordFromVersion() {
    // latest version is not recorded
    Version mockedVersion = mock(VersionImpl.class);
    NodeRef versionNodeRef = generateNodeRef();
    doReturn(Collections.emptyMap()).when(mockedVersion).getVersionProperties();
    doReturn(true).when(mockedNodeService).hasAspect(nodeRef, ContentModel.ASPECT_VERSIONABLE);
    // version history
    NodeRef versionHistoryNodeRef = generateNodeRef();
    doReturn(versionHistoryNodeRef).when(mockedDbNodeService).getChildByName(any(NodeRef.class), eq(Version2Model.CHILD_QNAME_VERSION_HISTORIES), any(String.class));
    // version number
    doReturn(mockedVersion).when(recordableVersionService).getCurrentVersion(nodeRef);
    doReturn(versionNodeRef).when(recordableVersionService).convertNodeRef(any(NodeRef.class));
    makePrimaryParentOf(versionNodeRef, versionHistoryNodeRef, ContentModel.ASSOC_CONTAINS, QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, "something-0"), mockedDbNodeService);
    // created version
    NodeRef newVersionNodeRef = generateNodeRef();
    doReturn(generateChildAssociationRef(versionHistoryNodeRef, newVersionNodeRef)).when(mockedDbNodeService).createNode(eq(versionHistoryNodeRef), eq(Version2Model.CHILD_QNAME_VERSIONS), any(QName.class), any(QName.class), any(Map.class));
    // created record
    NodeRef newRecordNodeRef = generateNodeRef();
    doReturn(newRecordNodeRef).when(mockedRecordService).createRecordFromContent(eq(filePlan), any(String.class), any(QName.class), any(Map.class), any(ContentReader.class));
    // create record from version
    recordableVersionService.createRecordFromLatestVersion(filePlan, nodeRef);
    // verify that the version is converted to a recorded version
    verify(mockedRecordService, times(1)).createRecordFromContent(eq(filePlan), any(String.class), any(QName.class), any(Map.class), any(ContentReader.class));
    verify(mockedDbNodeService, times(1)).deleteNode(any(NodeRef.class));
    verify(mockedDbNodeService, times(1)).createNode(eq(versionHistoryNodeRef), eq(Version2Model.CHILD_QNAME_VERSIONS), any(QName.class), any(QName.class), any(Map.class));
    verify(mockedNodeService, times(1)).addAspect(eq(newVersionNodeRef), eq(Version2Model.ASPECT_VERSION), any(Map.class));
    verify(mockedNodeService, times(1)).addAspect(newVersionNodeRef, RecordableVersionModel.ASPECT_RECORDED_VERSION, Collections.singletonMap(RecordableVersionModel.PROP_RECORD_NODE_REF, (Serializable) newRecordNodeRef));
}
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) ContentReader(org.alfresco.service.cmr.repository.ContentReader) Matchers.anyString(org.mockito.Matchers.anyString) HashMap(java.util.HashMap) Map(java.util.Map) Matchers.anyMap(org.mockito.Matchers.anyMap) BaseUnitTest(org.alfresco.module.org_alfresco_module_rm.test.util.BaseUnitTest) Test(org.junit.Test)

Example 3 with Version

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

the class RecordableVersionServiceImplUnitTest method alreadyRecordedCreateRecordFromVersion.

/**
 * Given that a nodes last version is recorded
 * When I try and create a record from the latest version
 * Then nothing will happen, because the latest version is already recorded
 */
@Test
public void alreadyRecordedCreateRecordFromVersion() {
    // latest version is already recorded
    Version mockedVersion = mock(VersionImpl.class);
    NodeRef versionNodeRef = generateNodeRef();
    when(mockedVersion.getFrozenStateNodeRef()).thenReturn(versionNodeRef);
    when(mockedNodeService.hasAspect(nodeRef, ContentModel.ASPECT_VERSIONABLE)).thenReturn(true);
    when(mockedDbNodeService.hasAspect(versionNodeRef, RecordableVersionModel.ASPECT_RECORDED_VERSION)).thenReturn(true);
    doReturn(mockedVersion).when(recordableVersionService).getCurrentVersion(nodeRef);
    // create record from version
    recordableVersionService.createRecordFromLatestVersion(filePlan, nodeRef);
    // nothing happens
    verify(mockedRecordService, never()).createRecordFromCopy(eq(filePlan), any(NodeRef.class));
}
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 4 with Version

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

the class RecordableVersionServiceImplUnitTest method noAspectMarkAsDestroyed.

/**
 * given that the version node doesn't have the recorded version aspect applied
 * when I mark the version as destroyed
 * then nothing happens
 */
@Test
public void noAspectMarkAsDestroyed() {
    // set up version
    Version mockedVersion = mock(VersionImpl.class);
    NodeRef versionNodeRef = generateNodeRef();
    when(mockedVersion.getFrozenStateNodeRef()).thenReturn(versionNodeRef);
    // indicate that the version doesn't have the aspect
    when(mockedDbNodeService.hasAspect(versionNodeRef, RecordableVersionModel.ASPECT_RECORDED_VERSION)).thenReturn(false);
    // mark as destroyed
    recordableVersionService.destroyRecordedVersion(mockedVersion);
    // verify nothing happened
    verify(mockedDbNodeService, never()).setProperty(versionNodeRef, RecordableVersionModel.PROP_DESTROYED, Boolean.TRUE);
}
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 5 with Version

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

the class RecordableVersionServiceImplUnitTest method propSetVersionDestroyed.

/**
 * given the destroyed prop is set
 * when I ask if the version is destroyed
 * then the result matches the value set in the destroy property
 */
@Test
public void propSetVersionDestroyed() {
    // set up version
    Version mockedVersion = mock(VersionImpl.class);
    NodeRef versionNodeRef = generateNodeRef();
    when(mockedVersion.getFrozenStateNodeRef()).thenReturn(versionNodeRef);
    // set prop
    when(mockedDbNodeService.getProperty(versionNodeRef, RecordableVersionModel.PROP_DESTROYED)).thenReturn(Boolean.TRUE);
    // is version destroyed
    assertTrue(recordableVersionService.isRecordedVersionDestroyed(mockedVersion));
    // set prop
    when(mockedDbNodeService.getProperty(versionNodeRef, RecordableVersionModel.PROP_DESTROYED)).thenReturn(Boolean.FALSE);
    // is version destroyed
    assertFalse(recordableVersionService.isRecordedVersionDestroyed(mockedVersion));
}
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)

Aggregations

Version (org.alfresco.service.cmr.version.Version)40 NodeRef (org.alfresco.service.cmr.repository.NodeRef)31 VersionHistory (org.alfresco.service.cmr.version.VersionHistory)18 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