Merged V2.1 to HEAD

6383: ML contributions
   6400: AR-1625 Empty translations track pivot translation


git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@6406 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Derek Hulley
2007-08-02 23:57:38 +00:00
parent 7c4ddd4fdd
commit 4ffc28f0bf
28 changed files with 2461 additions and 848 deletions

View File

@@ -29,7 +29,6 @@ import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
@@ -44,6 +43,7 @@ import org.alfresco.model.ContentModel;
import org.alfresco.repo.content.MimetypeMap;
import org.alfresco.repo.transaction.RetryingTransactionHelper;
import org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback;
import org.alfresco.repo.version.common.VersionLabelComparator;
import org.alfresco.service.cmr.coci.CheckOutCheckInService;
import org.alfresco.service.cmr.lock.LockService;
import org.alfresco.service.cmr.ml.ContentFilterLanguagesService;
@@ -59,6 +59,7 @@ 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.ml.MultilingualUtils;
import org.alfresco.web.bean.repository.MapNode;
import org.alfresco.web.bean.repository.Node;
import org.alfresco.web.bean.repository.Repository;
@@ -95,6 +96,8 @@ public class DocumentDetailsBean extends BaseDetailsBean
private NodeRef addedCategory;
private List categories;
private Node translationDocument;
// ------------------------------------------------------------------------------
// Construction
@@ -213,7 +216,7 @@ public class DocumentDetailsBean extends BaseDetailsBean
{
this.navigator.setupDispatchContext(getDocument());
}
/**
* Save the state of the panel that was expanded/collapsed
*/
@@ -252,8 +255,17 @@ public class DocumentDetailsBean extends BaseDetailsBean
clientVersion.put("notes", version.getDescription());
clientVersion.put("author", version.getCreator());
clientVersion.put("versionDate", version.getCreatedDate());
clientVersion.put("url", DownloadContentServlet.generateBrowserURL(version.getFrozenStateNodeRef(),
clientVersion.getName()));
if(getDocument().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);
@@ -264,23 +276,6 @@ public class DocumentDetailsBean extends BaseDetailsBean
return versions;
}
/**
* The comparator to sort a version list according their version label ascending
*
* TODO add this code in the repository as Version Util class ?
*/
private Comparator versionComparator = new Comparator()
{
public int compare(Object o1, Object o2)
{
String label01 = ((Version) o1).getVersionLabel();
String label02 = ((Version) o2).getVersionLabel();
// sort the list ascending
return label02.compareTo(label01);
}
};
/** List of client light weight edition histories */
private List<SingleEditionBean> editionHistory = null;
@@ -366,102 +361,115 @@ public class DocumentDetailsBean extends BaseDetailsBean
private List<SingleEditionBean> initEditionHistory()
{
// get the mlContainer
NodeRef mlContainer = getDocumentMlContainer().getNodeRef();
NodeRef mlContainer = getDocumentMlContainer().getNodeRef();
// get all editions and sort them ascending according their version label
List<Version> orderedEditionList = new ArrayList<Version>(editionService.getEditions(mlContainer).getAllVersions());
Collections.sort(orderedEditionList, versionComparator);
// get all editions and sort them ascending according their version label
List<Version> orderedEditionList = new ArrayList<Version>(editionService.getEditions(mlContainer).getAllVersions());
Collections.sort(orderedEditionList, new VersionLabelComparator());
// the list of Single Edition Bean to return
editionHistory = new ArrayList<SingleEditionBean>(orderedEditionList.size());
// the list of Single Edition Bean to return
editionHistory = new ArrayList<SingleEditionBean>(orderedEditionList.size());
boolean firstEdition = true;
boolean firstEdition = true;
// for each edition, init a SingleEditionBean
for (Version edition : orderedEditionList)
{
SingleEditionBean editionBean = new SingleEditionBean();
// for each edition, init a SingleEditionBean
for (Version edition : orderedEditionList)
{
SingleEditionBean editionBean = new SingleEditionBean();
MapNode clientEdition = new MapNode(edition.getFrozenStateNodeRef());
MapNode clientEdition = new MapNode(edition.getFrozenStateNodeRef());
String editionLabel = edition.getVersionLabel();
if (firstEdition)
{
editionLabel += " (" + Application.getMessage(FacesContext.getCurrentInstance(), MSG_CURRENT) + ")";
}
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());
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);
// Set the edition of the edition bean
editionBean.setEdition(clientEdition);
// get translations
List<VersionHistory> translationHistories = null;
// 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 = multilingualContentService.getTranslations(mlContainer);
translationHistories = new ArrayList<VersionHistory>(translations.size());
for (NodeRef translation : translations.values())
{
translationHistories.add(versionService.getVersionHistory(translation));
}
}
else
{
if (firstEdition)
{
// Get the translations because the current edition doesn't content link with its
// translation in the version store.
Map<Locale, NodeRef> translations = multilingualContentService.getTranslations(mlContainer);
translationHistories = new ArrayList<VersionHistory>(translations.size());
for (NodeRef translation : translations.values())
{
translationHistories.add(versionService.getVersionHistory(translation));
}
}
else
{
translationHistories = editionService.getVersionedTranslations(edition);
}
}
// add each translation in the SingleEditionBean
for (VersionHistory versionHistory : translationHistories)
{
// get the list of versions and sort them ascending according their version label
List<Version> orderedVersions = new ArrayList<Version>(versionHistory.getAllVersions());
Collections.sort(orderedVersions, versionComparator);
// add each translation in the SingleEditionBean
for (VersionHistory versionHistory : translationHistories)
{
// get the list of versions and sort them ascending according their version label
List<Version> orderedVersions = new ArrayList<Version>(versionHistory.getAllVersions());
Collections.sort(orderedVersions, new VersionLabelComparator());
// the last version is the first version of the list
Version lastVersion = orderedVersions.get(0);
// the last version is the first version of the list
Version lastVersion = orderedVersions.get(0);
// get the properties of the lastVersion
Map<QName, Serializable> lastVersionProperties = editionService.getVersionedMetadatas(lastVersion);
Locale language = (Locale) lastVersionProperties.get(ContentModel.PROP_LOCALE);
// get the properties of the lastVersion
Map<QName, Serializable> lastVersionProperties = editionService.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());
// create a map node representation of the last version
MapNode clientLastVersion = new MapNode(lastVersion.getFrozenStateNodeRef());
clientLastVersion.put("versionName", lastVersionProperties.get(ContentModel.PROP_NAME));
clientLastVersion.put("versionDescription", lastVersionProperties.get(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.contentFilterLanguagesService.convertToNewISOCode(language.getLanguage()).toUpperCase());
clientLastVersion.put("versionUrl", DownloadContentServlet.generateBrowserURL(lastVersion.getFrozenStateNodeRef(), clientLastVersion.getName()));
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", nodeService.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.contentFilterLanguagesService.convertToNewISOCode(language.getLanguage()).toUpperCase());
// add a translation of the editionBean
editionBean.addTranslations(clientLastVersion);
}
editionHistory.add(editionBean);
firstEdition = false;
}
if(nodeService.hasAspect(lastVersion.getFrozenStateNodeRef(), ContentModel.ASPECT_MULTILINGUAL_EMPTY_TRANSLATION))
{
clientLastVersion.put("versionUrl", null);
}
else
{
clientLastVersion.put("versionUrl", DownloadContentServlet.generateBrowserURL(lastVersion.getFrozenStateNodeRef(), clientLastVersion.getName()));
}
return editionHistory;
// add a translation of the editionBean
editionBean.addTranslations(clientLastVersion);
}
editionHistory.add(editionBean);
firstEdition = false;
}
return editionHistory;
}
/**
* Returns a list of objects representing the translations of the current document
*
* Returns a list of objects representing the translations of the current document
*
* @return List of translations
*/
public List getTranslations()
{
List<MapNode> translations = new ArrayList<MapNode>();
if (getDocument().hasAspect(ContentModel.ASPECT_MULTILINGUAL_DOCUMENT))
Node document = getDocument();
boolean canNewEdtion = MultilingualUtils.canStartNewEditon(document, FacesContext.getCurrentInstance());
if (document.hasAspect(ContentModel.ASPECT_MULTILINGUAL_DOCUMENT) || ContentModel.TYPE_MULTILINGUAL_CONTAINER.equals(document.getType()))
{
Map<Locale, NodeRef> translationsMap = this.multilingualContentService.getTranslations(getDocument().getNodeRef());
@@ -485,6 +493,8 @@ public class DocumentDetailsBean extends BaseDetailsBean
mapNode.put("language", lgge);
mapNode.put("url", DownloadContentServlet.generateBrowserURL(nodeRef, mapNode.getName()));
mapNode.put("notEmpty", new Boolean(!nodeService.hasAspect(nodeRef, ContentModel.ASPECT_MULTILINGUAL_EMPTY_TRANSLATION)));
mapNode.put("userHasRight", new Boolean(canNewEdtion));
// add the client side version to the list
translations.add(mapNode);
}
@@ -593,23 +603,23 @@ public class DocumentDetailsBean extends BaseDetailsBean
/**
* Sets the category added from the multi value editor
*
*
* @param addedCategory The added category
*/
public void setAddedCategory(NodeRef addedCategory)
{
this.addedCategory = addedCategory;
}
/**
* Updates the categories for the current document
*
*
* @return The outcome
*/
public String saveCategories()
{
String outcome = "cancel";
try
{
RetryingTransactionHelper txnHelper = Repository.getRetryingTransactionHelper(FacesContext.getCurrentInstance());
@@ -617,22 +627,22 @@ public class DocumentDetailsBean extends BaseDetailsBean
{
public Object execute() throws Throwable
{
// firstly retrieve all the properties for the current node
// firstly retrieve all the properties for the current node
Map<QName, Serializable> updateProps = nodeService.getProperties(getDocument().getNodeRef());
// create a node ref representation of the selected id and set the new properties
// create a node ref representation of the selected id and set the new properties
updateProps.put(ContentModel.PROP_CATEGORIES, (Serializable) categories);
// set the properties on the node
// set the properties on the node
nodeService.setProperties(getDocument().getNodeRef(), updateProps);
return null;
}
};
txnHelper.doInTransaction(callback);
// reset the state of the current document so it reflects the changes just made
getDocument().reset();
outcome = "finish";
}
catch (Throwable e)
@@ -640,10 +650,10 @@ public class DocumentDetailsBean extends BaseDetailsBean
Utils.addErrorMessage(MessageFormat.format(Application.getMessage(
FacesContext.getCurrentInstance(), MSG_ERROR_UPDATE_CATEGORY), e.getMessage()), e);
}
return outcome;
}
/**
* Applies the classifiable aspect to the current document
*/
@@ -656,13 +666,13 @@ public class DocumentDetailsBean extends BaseDetailsBean
{
public Object execute() throws Throwable
{
// add the general classifiable aspect to the node
// add the general classifiable aspect to the node
nodeService.addAspect(getDocument().getNodeRef(), ContentModel.ASPECT_GEN_CLASSIFIABLE, null);
return null;
}
};
txnHelper.doInTransaction(callback);
// reset the state of the current document
getDocument().reset();
}
@@ -672,7 +682,7 @@ public class DocumentDetailsBean extends BaseDetailsBean
FacesContext.getCurrentInstance(), MSG_ERROR_ASPECT_CLASSIFY), e.getMessage()), e);
}
}
/**
* Applies the versionable aspect to the current document
*/
@@ -685,13 +695,13 @@ public class DocumentDetailsBean extends BaseDetailsBean
{
public Object execute() throws Throwable
{
// add the versionable aspect to the node
// add the versionable aspect to the node
nodeService.addAspect(getDocument().getNodeRef(), ContentModel.ASPECT_VERSIONABLE, null);
return null;
}
};
txnHelper.doInTransaction(callback);
// reset the state of the current document
getDocument().reset();
}
@@ -701,14 +711,14 @@ public class DocumentDetailsBean extends BaseDetailsBean
FacesContext.getCurrentInstance(), MSG_ERROR_ASPECT_VERSIONING), e.getMessage()), e);
}
}
/**
* Action Handler to unlock a locked document
*/
public void unlock(final ActionEvent event)
{
final FacesContext fc = FacesContext.getCurrentInstance();
try
{
RetryingTransactionHelper txnHelper = Repository.getRetryingTransactionHelper(FacesContext.getCurrentInstance());
@@ -717,13 +727,13 @@ public class DocumentDetailsBean extends BaseDetailsBean
public Object execute() throws Throwable
{
lockService.unlock(getNode().getNodeRef());
String msg = Application.getMessage(fc, MSG_SUCCESS_UNLOCK);
FacesMessage facesMsg = new FacesMessage(FacesMessage.SEVERITY_INFO, msg, msg);
String formId = Utils.getParentForm(fc, event.getComponent()).getClientId(fc);
fc.addMessage(formId + ':' + getPropertiesPanelId(), facesMsg);
getNode().reset();
String msg = Application.getMessage(fc, MSG_SUCCESS_UNLOCK);
FacesMessage facesMsg = new FacesMessage(FacesMessage.SEVERITY_INFO, msg, msg);
String formId = Utils.getParentForm(fc, event.getComponent()).getClientId(fc);
fc.addMessage(formId + ':' + getPropertiesPanelId(), facesMsg);
getNode().reset();
return null;
}
};
@@ -735,7 +745,7 @@ public class DocumentDetailsBean extends BaseDetailsBean
fc, Repository.ERROR_GENERIC), e.getMessage()), e);
}
}
/**
* Applies the inlineeditable aspect to the current document
*/
@@ -748,33 +758,33 @@ public class DocumentDetailsBean extends BaseDetailsBean
{
public Object execute() throws Throwable
{
// add the inlineeditable aspect to the node
Map<QName, Serializable> props = new HashMap<QName, Serializable>(1, 1.0f);
String contentType = null;
ContentData contentData = (ContentData)getDocument().getProperties().get(ContentModel.PROP_CONTENT);
if (contentData != null)
{
contentType = contentData.getMimetype();
}
if (contentType != null)
{
// set the property to true by default if the filetype is a known content type
if (MimetypeMap.MIMETYPE_HTML.equals(contentType) ||
MimetypeMap.MIMETYPE_TEXT_PLAIN.equals(contentType) ||
MimetypeMap.MIMETYPE_XML.equals(contentType) ||
MimetypeMap.MIMETYPE_TEXT_CSS.equals(contentType) ||
MimetypeMap.MIMETYPE_JAVASCRIPT.equals(contentType))
{
props.put(ApplicationModel.PROP_EDITINLINE, true);
}
}
// add the inlineeditable aspect to the node
Map<QName, Serializable> props = new HashMap<QName, Serializable>(1, 1.0f);
String contentType = null;
ContentData contentData = (ContentData)getDocument().getProperties().get(ContentModel.PROP_CONTENT);
if (contentData != null)
{
contentType = contentData.getMimetype();
}
if (contentType != null)
{
// set the property to true by default if the filetype is a known content type
if (MimetypeMap.MIMETYPE_HTML.equals(contentType) ||
MimetypeMap.MIMETYPE_TEXT_PLAIN.equals(contentType) ||
MimetypeMap.MIMETYPE_XML.equals(contentType) ||
MimetypeMap.MIMETYPE_TEXT_CSS.equals(contentType) ||
MimetypeMap.MIMETYPE_JAVASCRIPT.equals(contentType))
{
props.put(ApplicationModel.PROP_EDITINLINE, true);
}
}
nodeService.addAspect(getDocument().getNodeRef(), ApplicationModel.ASPECT_INLINEEDITABLE, props);
return null;
}
};
txnHelper.doInTransaction(callback);
// reset the state of the current document
getDocument().reset();
}
@@ -970,6 +980,27 @@ public class DocumentDetailsBean extends BaseDetailsBean
return this.getNode();
}
/**
* Before opening the ml container details, remeber the translation
* from which the action comes.
*
* @param node
*/
public void setTranslationDocument(Node node)
{
this.translationDocument = node;
}
/**
* Restore the translationf from which the ml container
* details dialog comes.
*/
public void resetMLDocument(ActionEvent event)
{
this.browseBean.setupCommonBindingProperties(this.translationDocument);
this.browseBean.setDocument(this.translationDocument);
}
/**
* Returns the ml container of the document this bean is currently representing
*
@@ -977,11 +1008,19 @@ public class DocumentDetailsBean extends BaseDetailsBean
*/
public Node getDocumentMlContainer()
{
NodeRef nodeRef = getNode().getNodeRef();
Node currentNode = getNode();
return new Node(multilingualContentService.getTranslationContainer(nodeRef));
if(ContentModel.TYPE_MULTILINGUAL_CONTAINER.equals(currentNode.getType()))
{
return currentNode;
}
else
{
NodeRef nodeRef = getNode().getNodeRef();
return new Node(multilingualContentService.getTranslationContainer(nodeRef));
}
}
/**
* Sets the lock service instance the bean should use
*