Search in sources :

Example 11 with VersionHistory

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

the class VersionedDocumentDetailsDialog method getTranslations.

/**
 * Returns a list of objects representing the translations of the given version of the mlContainer
 *
 * @return List of translations
 */
@SuppressWarnings("unchecked")
public List getTranslations() {
    // get the version of the mlContainer and its translations
    List<VersionHistory> translationsList = getEditionService().getVersionedTranslations(this.documentEdition);
    Map<Locale, NodeRef> translationNodeRef;
    // if translation size == 0, the edition is the current edition and the translations are not yet attached.
    if (translationsList.size() == 0) {
        // the selection edition is the current: use the multilingual content service
        translationNodeRef = getMultilingualContentService().getTranslations(this.documentEdition.getVersionedNodeRef());
    } else {
        translationNodeRef = new HashMap<Locale, NodeRef>(translationsList.size());
        // get the last (most recent) version of the translation in the given lang of the edition
        for (VersionHistory history : translationsList) {
            // get the list of versions (in descending order - ie. most recent first)
            List<Version> orderedVersions = new ArrayList<Version>(history.getAllVersions());
            // the last (most recent) version is the first version of the list
            Version lastVersion = orderedVersions.get(0);
            // fill the list of translation
            if (lastVersion != null) {
                NodeRef versionNodeRef = lastVersion.getFrozenStateNodeRef();
                Locale locale = (Locale) getNodeService().getProperty(versionNodeRef, ContentModel.PROP_LOCALE);
                translationNodeRef.put(locale, versionNodeRef);
            }
        }
    }
    // the list of client-side translation to return
    List<MapNode> translations = new ArrayList<MapNode>(translationNodeRef.size());
    for (Map.Entry<Locale, NodeRef> entry : translationNodeRef.entrySet()) {
        Locale locale = entry.getKey();
        NodeRef nodeRef = entry.getValue();
        // create a map node representation of the translation
        MapNode mapNode = new MapNode(nodeRef);
        String lgge = (locale != null) ? // convert the locale into new ISO codes
        getContentFilterLanguagesService().convertToNewISOCode(locale.getLanguage()).toUpperCase() : null;
        mapNode.put("name", getNodeService().getProperty(nodeRef, ContentModel.PROP_NAME));
        mapNode.put("language", lgge);
        mapNode.put("url", DownloadContentServlet.generateBrowserURL(nodeRef, mapNode.getName()));
        mapNode.put("notEmpty", new Boolean(!getNodeService().hasAspect(nodeRef, ContentModel.ASPECT_MULTILINGUAL_EMPTY_TRANSLATION)));
        // add the client side version to the list
        translations.add(mapNode);
    }
    return translations;
}
Also used : Locale(java.util.Locale) 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) HashMap(java.util.HashMap) Map(java.util.Map)

Example 12 with VersionHistory

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

the class VersionedDocumentDetailsDialog method getBrowsingVersionForMLContainer.

/**
 * Util method which return the last (most recent) version of a translation of a given edition of a mlContainer according its language
 */
@SuppressWarnings("unchecked")
private Version getBrowsingVersionForMLContainer(NodeRef document, String editionLabel, String lang) {
    // get the list of translations of the given edition of the mlContainer
    List<VersionHistory> translations = getEditionService().getVersionedTranslations(this.documentEdition);
    // if translation size == 0, the edition is the current edition and the translations are not yet attached.
    if (translations.size() == 0) {
        // the selection edition is the current.
        return getBrowsingCurrentVersionForMLContainer(document, lang);
    } else {
        Version versionToReturn = null;
        // get the last (most recent) version of the translation in the given lang of the edition
        for (VersionHistory history : translations) {
            // get the list of versions (in descending order - ie. most recent first)
            List<Version> orderedVersions = new ArrayList<Version>(history.getAllVersions());
            // the last version (ie. most recent) is the first version of the list
            Version lastVersion = orderedVersions.get(0);
            if (lastVersion != null) {
                Map<QName, Serializable> properties = getEditionService().getVersionedMetadatas(lastVersion);
                Locale locale = (Locale) properties.get(ContentModel.PROP_LOCALE);
                if (locale.getLanguage().equalsIgnoreCase(lang)) {
                    versionToReturn = lastVersion;
                    this.versionHistory = history;
                    break;
                }
            }
        }
        return versionToReturn;
    }
}
Also used : Locale(java.util.Locale) Serializable(java.io.Serializable) Version(org.alfresco.service.cmr.version.Version) QName(org.alfresco.service.namespace.QName) ArrayList(java.util.ArrayList) VersionHistory(org.alfresco.service.cmr.version.VersionHistory)

Example 13 with VersionHistory

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

the class RecordableVersionServiceImpl method getLatestVersionRecord.

/**
 * Helper to get the latest version record for a given document (ie non-record)
 *
 * @param nodeRef node reference
 * @return NodeRef latest version record, null otherwise
 */
private NodeRef getLatestVersionRecord(NodeRef nodeRef) {
    NodeRef versionRecord = null;
    // wire record up to previous record
    VersionHistory versionHistory = getVersionHistory(nodeRef);
    if (versionHistory != null) {
        Collection<Version> previousVersions = versionHistory.getAllVersions();
        for (Version previousVersion : previousVersions) {
            // look for the associated record
            final NodeRef previousRecord = (NodeRef) previousVersion.getVersionProperties().get(PROP_VERSION_RECORD);
            if (previousRecord != null && nodeService.exists(previousRecord)) {
                versionRecord = previousRecord;
                break;
            }
        }
    }
    return versionRecord;
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) Version(org.alfresco.service.cmr.version.Version) VersionHistory(org.alfresco.service.cmr.version.VersionHistory)

Example 14 with VersionHistory

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

the class RecordServiceImpl method getLatestVersionRecord.

/**
 * Helper to get the latest version record for a given document (ie non-record)
 *
 * @param nodeRef   node reference
 * @return NodeRef  latest version record, null otherwise
 */
private NodeRef getLatestVersionRecord(NodeRef nodeRef) {
    NodeRef versionRecord = null;
    recordableVersionService.createSnapshotVersion(nodeRef);
    // wire record up to previous record
    VersionHistory versionHistory = versionService.getVersionHistory(nodeRef);
    if (versionHistory != null) {
        Collection<Version> previousVersions = versionHistory.getAllVersions();
        for (Version previousVersion : previousVersions) {
            // look for the associated record
            final NodeRef previousRecord = recordableVersionService.getVersionRecord(previousVersion);
            if (previousRecord != null) {
                versionRecord = previousRecord;
                break;
            }
        }
    }
    return versionRecord;
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) Version(org.alfresco.service.cmr.version.Version) VersionHistory(org.alfresco.service.cmr.version.VersionHistory)

Example 15 with VersionHistory

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

the class RecordableVersionsBaseTest method checkRecordedVersion.

/**
 * Helper to check that the current version is recorded
 */
protected void checkRecordedVersion(NodeRef document, String description, String versionLabel) {
    // double check that the document is not a record
    assertFalse(recordService.isRecord(document));
    // store document state
    Map<QName, Serializable> beforeProperties = nodeService.getProperties(document);
    Set<QName> beforeAspects = nodeService.getAspects(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());
    // get the frozen state
    NodeRef frozen = version.getFrozenStateNodeRef();
    // check the properties
    checkProperties(frozen, beforeProperties);
    // compare aspects
    checkAspects(frozen, beforeAspects);
    // record version node reference is available on version
    NodeRef record = recordableVersionService.getVersionRecord(version);
    assertNotNull(record);
    // check that the version record information has been added
    assertTrue(nodeService.hasAspect(record, ASPECT_VERSION_RECORD));
    assertEquals(versionLabel, nodeService.getProperty(record, RecordableVersionModel.PROP_VERSION_LABEL));
    assertEquals(description, nodeService.getProperty(record, RecordableVersionModel.PROP_VERSION_DESCRIPTION));
    // record version is an unfiled record
    assertTrue(recordService.isRecord(record));
    assertFalse(recordService.isFiled(record));
    // check that the created record does not have either of the versionable aspects
    assertFalse(nodeService.hasAspect(record, RecordableVersionModel.ASPECT_VERSIONABLE));
    // 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) Serializable(java.io.Serializable) Version(org.alfresco.service.cmr.version.Version) QName(org.alfresco.service.namespace.QName) VersionHistory(org.alfresco.service.cmr.version.VersionHistory)

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