Search in sources :

Example 21 with Version

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

the class DocumentDetailsDialog method initEditionHistory.

/**
 * Constructs a list of objects representing the editions of the
 * logical document
 *
 * @return List of editions
 */
@SuppressWarnings("unused")
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) {
            // 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", this.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) SingleEditionBean(org.alfresco.web.bean.ml.SingleEditionBean)

Example 22 with Version

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

the class VersionedDocumentDetailsDialog method getVersionHistory.

/**
 * Returns a list of objects representing the versions of the
 * current document
 *
 * @return List of previous versions
 */
public List getVersionHistory() {
    List<MapNode> versions = new ArrayList<MapNode>();
    for (Version version : this.versionHistory.getAllVersions()) {
        // create a map node representation of the version
        MapNode clientVersion = new MapNode(version.getFrozenStateNodeRef());
        clientVersion.put("versionLabel", version.getVersionLabel());
        clientVersion.put("notes", version.getDescription());
        clientVersion.put("author", version.getCreator());
        clientVersion.put("versionDate", version.getCreatedDate());
        if (getFrozenStateDocument().hasAspect(ContentModel.ASPECT_MULTILINGUAL_EMPTY_TRANSLATION)) {
            clientVersion.put("url", null);
        } else {
            clientVersion.put("url", DownloadContentServlet.generateBrowserURL(version.getFrozenStateNodeRef(), clientVersion.getName()));
        }
        // add the client side version to the list
        versions.add(clientVersion);
    }
    return versions;
}
Also used : Version(org.alfresco.service.cmr.version.Version) ArrayList(java.util.ArrayList) MapNode(org.alfresco.web.bean.repository.MapNode)

Example 23 with Version

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

the class VersionedDocumentDetailsDialog method nextItem.

/**
 * Navigates to next item in the list of versioned content for the current VersionHistory
 */
public void nextItem(ActionEvent event) {
    // Get the properties of the action event
    UIActionLink link = (UIActionLink) event.getComponent();
    Map<String, String> params = link.getParameterMap();
    String versionLabel = params.get("versionLabel");
    // if the version is not specified, get the next version
    if (versionLabel == null) {
        List<Version> nextVersions = new ArrayList<Version>(this.versionHistory.getSuccessors(this.documentVersion));
        // if the version history doesn't contains successor, get the root version (the first one)
        if (nextVersions == null || nextVersions.size() < 1) {
            this.documentVersion = versionHistory.getRootVersion();
        } else {
            this.documentVersion = nextVersions.get(0);
        }
    } else {
        this.documentVersion = this.versionHistory.getVersion(versionLabel);
    }
}
Also used : Version(org.alfresco.service.cmr.version.Version) UIActionLink(org.alfresco.web.ui.common.component.UIActionLink) ArrayList(java.util.ArrayList)

Example 24 with Version

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

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

the class VersionedDocumentDetailsDialog method previousItem.

/**
 * Navigates to previous item in the list of versioned content for the current VersionHistory
 */
public void previousItem(ActionEvent event) {
    // Get the properties of the action event
    UIActionLink link = (UIActionLink) event.getComponent();
    Map<String, String> params = link.getParameterMap();
    String versionLabel = params.get("versionLabel");
    // if the version is not specified, get the next version
    if (versionLabel == null) {
        Version prevVersion = this.versionHistory.getPredecessor(this.documentVersion);
        // if the version history doesn't contains predecessor, get the last version (ie. most recent)
        if (prevVersion == null) {
            List<Version> allVersions = new ArrayList<Version>(this.versionHistory.getAllVersions());
            this.documentVersion = allVersions.get(0);
        } else {
            this.documentVersion = prevVersion;
        }
    } else {
        this.documentVersion = this.versionHistory.getVersion(versionLabel);
    }
}
Also used : Version(org.alfresco.service.cmr.version.Version) UIActionLink(org.alfresco.web.ui.common.component.UIActionLink) ArrayList(java.util.ArrayList)

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