Files
alfresco-community-repo/source/java/org/alfresco/web/bean/content/VersionedDocumentDetailsDialog.java
Dave Ward ee798ddb37 Merged V4.1-BUG-FIX to HEAD
44674: Fix for ALF-17189 - The "Company Home" item in the top navigator menu and in the toolbar panel is invisible, if login as guest first then directly access the login page via URL.
   44701: Merged BRANCHES/DEV/V3.4-BUG-FIX to BRANCHES/DEV/V4.1-BUG-FIX
      44700: Fix for ALF-10369 - support for OPTIONS requests for WebScript framework and Share proxy
   44709: ALF-17164 Fix version.properties which was wrong in sdk zip
   44710: ALF-14570 ("Check out" outboud rule works incorrect)
   44722: MNT-246: Need the ability to configure a proxy with Enterprise Sync.
      - RemoteConnectorServiceImpl will now use an http/https proxy if the standard system properties for Java network proxy configuration are found. See http://docs.oracle.com/javase/6/docs/technotes/guides/net/proxies.html (Section 2.1 and 2.2)
   44730: Merged V4.1 to V4.1-BUG-FIX
      44461: Merged PATCHES/V4.1.1 to V4.1
         44060: ALF-16962 / MNT-221 Links from a deleted user cause error in the "Links" page 
         44129: ALF-17134 / MNT-223: Unbound SOLR result set (from Explorer trashcan query) consumes heap
         - Now we emulate the behaviour of ACLEntryAfterInvocationProvider in SolrQueryHTTPClient, thus limiting otherwise unconstrained SOLR queries to return a finite number of results
         - New solr subsystem parameter solr.query.maximumResultsFromUnlimitedQuery introduced
         - Its default value is ${system.acl.maxPermissionChecks}, thus providing backward compatibility with old behaviour (1000 results max)
         - When there are no other limits in the search parameters, this value will be used to limit the number of results
         - SolrJSONResultSet.getResultSetMetata().getLimitedBy() will return an appropriate LimitBy value, according to how the query was limited
         44130: ALF-17134 / MNT-223: Unbound SOLR result set (from Explorer trashcan query) consumes heap
         - Improved calculation of SolrJSONResultSet.getResultSetMetata().getLimitedBy() to better emulate ACLEntryAfterInvocationProvider
         44141: ALF-17134 / MNT-223: Unbound SOLR result set (from Explorer trashcan query) consumes heap
         - Correction to handling of limited queries (Share search works again!)
         44291: ALF-17094 / MNT-222 InvalidNodeRefException on user deletion in Share UI 
      44462: Merged PATCHES/V4.0.2 to V4.1
         44221: ALF-17038 / MNT-226: Out-of-order versions for existing data during migration from 3.4.9 to 4.0.2.19
            - Have been able to remove the need for any Comparators in the normal case.
              As Dave said, he thought it was ordered already. It is with "assoc.assoc_index ASC, assoc.id ASC".
              Required a bit of re factoring of Version2ServiceImpl to do it as they were referenced/used in a couple of other classes.
            - Modified all 43 Oracle sequences to include ORDER in the create statement.
              Probably only really was needed to do it on alf_child_assoc_seq to fix this issue, but it will stop similar issues in
              other clustered database setups. Did not change the upgrade scripts, as this will give us a clue that there will be
              existing data issues.
            - The name of a Comparator<Version> may be specified in the Alfresco global property:
              org.alfresco.repo.version.common.VersionLabelComparator and it will be used by BOTH Version2ServiceImpl and VersionServiceImpl.
              They in turn pass it on to Version2ServiceImpl instances when they create them.
            - A VersionLabelComparator already existed (still deprecated as we don't normally use it) and works:
              org.alfresco.repo.version.common.VersionLabelComparator.
            - Customers with out of sequence ids on Oracle RDBMS using a clustered database may 'correct on the fly' the order of their
              versions by setting the alfresco global property described above.
            - Have tested both with and without a comparator in development environment. Using break points and Collections.shuffle(version)
              in an expression was able to simulate out of order IDs.
            - New unit tests added to VersionHistoryImplTest and VersionServiceImplTest to test db ids out of order
         44336: ALF-15935: Fixed SecureContext errors when ticket has expired. MNT-180
      44467: Fixed compilation failure
      44520: ALF-16590: Improved fix after testing by Mark Lugert
      44563: Merged DEV to V4.1 (with corrections)
         44547: ALF-17132: Possible XSS - arbitrary url parameters re-sent to the browser
            Escaping of keys and values of request attributes
      44610: Merged PATCHES/V4.0.2 to V4.1
         44435: ALF-17183: Merged DEV to V4.0.2 (4.0.2.22)
            44429: MNT-232: Upgrade from 3.4.9 to 4.0.2 - FAILED
            - Initialize rootRefs in the property definition to prevent NPE.
         44591: Fix to CIFS reported user free space when disk quotas are not enabled. 
         44595: ALF-17184 / MNT-243 Minimal fix for disk size and user quotas.   (Bring values into line with API.)
         44601: ALF-17184 / MNT-243 - Implementation of file size on Abstract Tennant Routing Content Store.
         44608: ALF-15935 / MNT-180: Moved closeFile() call to closeConnection() cleanup method, always call closeFile()
         Do not check if file is marked as closed during cleanup, only open files should still be in the file table.
      44652: ALF-17117: Created article or publication cant be viewed on WQS site
      - Fixes by Dmitry Vaserin
      - Removed unnecessary outer read locks from getRelatedAssets and getRelatedAsset to prevent deadlock
      - Correct markup error when node doesn't have tags
      44653: ALF-17117: Created article or publication cant be viewed on WQS site
      - Missed file from previous checkin
      44682: ALF-17118 WQS: Impossible to upload document to publications space
         - Only first part to do with the transformation failure has been committed. 
   44731: Merged V4.1 to V4.1-BUG-FIX (RECORD ONLY)
      44441: Merge V4.1-BUG-FIX to V4.1
         44270: Merge V3.4-BUG-FIX to V4.1-BUG-FIX
            44266: BDE-111: harden generation of Windows installers
               - make sure build fails if installer generation fails
               - generate Windows unsigned installers in a place that is cleaned later, avoiding leftovers
      44598: Merged V4.1-BUG-FIX to V4.1
         44541: Fix for     ALF-17151   SOLR - add support to disable permission checks
         44577: Final part for     ALF-16558 SOLR tracking does not do incremental updates but one single chunk 
         - fixed code so SolrSearchers are held for as little time as possible
      44607: Merged V4.1-BUG-FIX to V4.1
         44603: ALF-14201: upgrade activiti to 5.7-20121211
         44606: ALF-14201: upgrade activiti to 5.7-20121211 in Maven poms


git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@44732 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
2012-12-15 10:12:46 +00:00

595 lines
21 KiB
Java

/*
* Copyright (C) 2005-2012 Alfresco Software Limited.
*
* This file is part of Alfresco
*
* Alfresco is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Alfresco is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
*/
package org.alfresco.web.bean.content;
import java.io.Serializable;
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import javax.faces.context.FacesContext;
import javax.faces.event.ActionEvent;
import org.alfresco.model.ContentModel;
import org.alfresco.repo.web.scripts.FileTypeImageUtils;
import org.alfresco.service.cmr.ml.ContentFilterLanguagesService;
import org.alfresco.service.cmr.ml.EditionService;
import org.alfresco.service.cmr.ml.MultilingualContentService;
import org.alfresco.service.cmr.repository.InvalidNodeRefException;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.NodeService;
import org.alfresco.service.cmr.version.Version;
import org.alfresco.service.cmr.version.VersionHistory;
import org.alfresco.service.cmr.version.VersionService;
import org.alfresco.service.namespace.QName;
import org.alfresco.web.app.Application;
import org.alfresco.web.app.servlet.DownloadContentServlet;
import org.alfresco.web.bean.BrowseBean;
import org.alfresco.web.bean.repository.MapNode;
import org.alfresco.web.bean.repository.Node;
import org.alfresco.web.bean.repository.Repository;
import org.alfresco.web.ui.common.Utils;
import org.alfresco.web.ui.common.component.UIActionLink;
import org.springframework.extensions.surf.util.I18NUtil;
import org.springframework.extensions.surf.util.ParameterCheck;
/**
* Bean with generic function helping the rendering of the versioned properties
*
* @author Yanick Pignot
*/
public class VersionedDocumentDetailsDialog implements Serializable
{
private static final long serialVersionUID = 1575175076564595262L;
/** Dependencies */
transient private VersionService versionService;
transient private EditionService editionService;
transient private NodeService nodeService;
transient private MultilingualContentService multilingualContentService;
transient private ContentFilterLanguagesService contentFilterLanguagesService;
/** Determine if the version is a translation of a old edition */
private boolean fromPreviousEditon;
/** The version selected by the user */
private Version documentVersion;
private VersionHistory versionHistory;
/** The multilingual information of the selected version selected by the user */
private Version documentEdition;
private VersionHistory editionHistory;
/** Common property resolvers accessed from the BrowseBean */
private BrowseBean browseBean;
public void init()
{
fromPreviousEditon = false;
documentVersion = null;
versionHistory = null;
documentEdition = null;
editionHistory = null;
}
/**
* @param browseBean The BrowseBean to set.
*/
public void setBrowseBean(BrowseBean browseBean)
{
this.browseBean = browseBean;
}
/**
* Set which version of the current node that the user want to display the properties
*/
public void setBrowsingVersion(ActionEvent event)
{
init();
// Get the properties of the action event
UIActionLink link = (UIActionLink)event.getComponent();
Map<String, String> params = link.getParameterMap();
String versionLabel = params.get("versionLabel");
String id = params.get("id");
String lang = params.get("lang");
setBrowsingVersion(id, versionLabel, lang);
}
/**
* Implementation of setBrowsingVersion action event to be use with the needed parameters.
*/
private void setBrowsingVersion(String id, String versionLabel, String lang)
{
// test if the mandatories parameter are valid
ParameterCheck.mandatoryString("The id of the node", id);
ParameterCheck.mandatoryString("The version of the node", versionLabel);
try
{
// try to get the nodeRef with the given ID. This node is not a versioned node.
NodeRef currentNodeRef = new NodeRef(Repository.getStoreRef(), id);
// the threatment is different if the node is a translation or a mlContainer
if(getNodeService().getType(currentNodeRef).equals(ContentModel.TYPE_MULTILINGUAL_CONTAINER))
{
// test if the lang parameter is valid
ParameterCheck.mandatoryString("The lang of the node", lang);
fromPreviousEditon = true;
versionLabel = cleanVersionLabel(versionLabel);
// set the edition information of the mlContainer of the selected translation version
this.editionHistory = getEditionService().getEditions(currentNodeRef);
this.documentEdition = editionHistory.getVersion(versionLabel);
// set the version to display
this.documentVersion = getBrowsingVersionForMLContainer(currentNodeRef, versionLabel, lang);
}
else
{
fromPreviousEditon = false;
// set the version history
this.versionHistory = getVersionService().getVersionHistory(currentNodeRef);
// set the version to display
this.documentVersion = getBrowsingVersionForDocument(currentNodeRef, versionLabel);
}
}
catch (InvalidNodeRefException refErr)
{
Utils.addErrorMessage(MessageFormat.format(Application.getMessage(
FacesContext.getCurrentInstance(), Repository.ERROR_NODEREF), new Object[] {id}) );
}
}
/**
* 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);
}
}
/**
* 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);
}
}
/**
* 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;
}
/**
* 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;
}
/**
* @return true if the version is a translation of a previous edition
*/
public boolean isFromPreviousEditon()
{
return fromPreviousEditon;
}
/**
* Returns the URL to download content for the current document
*
* @return Content url to download the current document
*/
public String getUrl()
{
return DownloadContentServlet.generateBrowserURL(getFrozenStateNodeRef(), getName());
}
/**
* @return the versioned node selected by the user
*/
public Node getFrozenStateDocument()
{
Node node = new Node(getFrozenStateNodeRef());
node.addPropertyResolver("mimetype", this.browseBean.resolverMimetype);
node.addPropertyResolver("encoding", this.browseBean.resolverEncoding);
node.addPropertyResolver("size", this.browseBean.resolverSize);
return node;
}
/**
* @return the versioned node ref selected by the user
*/
public NodeRef getFrozenStateNodeRef()
{
return documentVersion.getFrozenStateNodeRef();
}
/**
* @return the edition of the mlContainer of the selected verion of the translation
*/
public Node getMultilingualContainerDocument()
{
return new Node(documentEdition.getFrozenStateNodeRef());
}
/**
* @return the name of selected version
*/
public String getName()
{
String name = (String)getNodeService().getProperty(getFrozenStateNodeRef(), ContentModel.PROP_NAME);
return name;
}
/**
* @return the file type image URL of the version
*/
public String getFileType32()
{
String fileType = FileTypeImageUtils.getFileTypeImage(getName(), false);
return fileType;
}
public boolean isEmptyTranslation()
{
return getNodeService().hasAspect(getFrozenStateNodeRef(), ContentModel.ASPECT_MULTILINGUAL_EMPTY_TRANSLATION);
}
/**
* @return the version to display of the document selected by the user
*/
public Version getVersion()
{
return this.documentVersion;
}
/**
* @return the next page to display according to which page the dialog is coming from
*/
public String getOutcome()
{
return (this.fromPreviousEditon) ? "dialog:showMLContainerDetails" : "dialog:showDocDetails";
}
/**
* Util method which remove the eventual '(actual)' label from the version label.
*/
private String cleanVersionLabel(String versionLabel)
{
// remove the (actual vesrion) label if needed
int idx = versionLabel.indexOf(' ');
if(idx > -1)
{
versionLabel = versionLabel.substring(0, idx);
}
return versionLabel;
}
/**
* Util method which returns the given version of a node
*/
private Version getBrowsingVersionForDocument(NodeRef document, String versionLabel)
{
return this.getVersionService().getVersionHistory(document).getVersion(versionLabel);
}
/**
* Util method which returns the current version of a node
*/
private Version getBrowsingCurrentVersionForMLContainer(NodeRef document, String lang)
{
NodeRef translation = getMultilingualContentService().getTranslationForLocale(document, I18NUtil.parseLocale(lang));
this.versionHistory = getVersionService().getVersionHistory(translation);
return getVersionService().getCurrentVersion(translation);
}
/**
* 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;
}
}
/**
* @param versionService the Version Service to set
*/
public void setVersionService(VersionService versionService)
{
this.versionService = versionService;
}
protected VersionService getVersionService()
{
if (versionService == null)
{
versionService = Repository.getServiceRegistry(FacesContext.getCurrentInstance()).getVersionService();
}
return versionService;
}
/**
* @param editionService the Edition Service to set
*/
public void setEditionService(EditionService editionService)
{
this.editionService = editionService;
}
protected EditionService getEditionService()
{
if (editionService == null)
{
editionService = Repository.getServiceRegistry(FacesContext.getCurrentInstance()).getEditionService();
}
return editionService;
}
/**
* @param nodeService the Node Service to set
*/
public void setNodeService(NodeService nodeService)
{
this.nodeService = nodeService;
}
protected NodeService getNodeService()
{
if (nodeService == null)
{
nodeService = Repository.getServiceRegistry(FacesContext.getCurrentInstance()).getNodeService();
}
return nodeService;
}
/**
* @param contentFilterLanguagesService the Content Filter Languages Service to set
*/
public void setContentFilterLanguagesService(ContentFilterLanguagesService contentFilterLanguagesService)
{
this.contentFilterLanguagesService = contentFilterLanguagesService;
}
protected ContentFilterLanguagesService getContentFilterLanguagesService()
{
if (contentFilterLanguagesService == null)
{
contentFilterLanguagesService = Repository.getServiceRegistry(FacesContext.getCurrentInstance()).getContentFilterLanguagesService();
}
return contentFilterLanguagesService;
}
/**
* @param Multilingual Content Service the Multilingual Content Service to set
*/
public void setMultilingualContentService(MultilingualContentService multilingualContentService)
{
this.multilingualContentService = multilingualContentService;
}
protected MultilingualContentService getMultilingualContentService()
{
if (multilingualContentService == null)
{
multilingualContentService = Repository.getServiceRegistry(FacesContext.getCurrentInstance()).getMultilingualContentService();
}
return multilingualContentService;
}
}