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

@@ -32,8 +32,11 @@ import java.util.Locale;
import java.util.Map;
import javax.faces.context.FacesContext;
import javax.faces.model.SelectItem;
import javax.faces.event.ActionEvent;
import javax.faces.model.DataModel;
import javax.faces.model.ListDataModel;
import org.alfresco.i18n.I18NUtil;
import org.alfresco.model.ContentModel;
import org.alfresco.repo.version.VersionModel;
import org.alfresco.service.cmr.lock.LockService;
@@ -44,36 +47,47 @@ import org.alfresco.service.cmr.ml.MultilingualContentService;
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.VersionService;
import org.alfresco.service.cmr.version.VersionType;
import org.alfresco.util.ParameterCheck;
import org.alfresco.web.app.AlfrescoNavigationHandler;
import org.alfresco.web.app.Application;
import org.alfresco.web.bean.repository.Node;
import org.alfresco.web.bean.wizard.BaseWizardBean;
import org.alfresco.web.ui.common.component.UIActionLink;
/**
* Wizard bean to create a new edition from an existing MLContainer.
*
* @author yanipig
* @author Yanick Pignot
*/
public class NewEditionWizard extends BaseWizardBean
{
public static final String ID_MESSAGE_MINOR_CHANGE = "minor_change";
public static final String ID_MESSAGE_MAJOR_CHANGE = "major_change";
protected EditionService editionService;
protected MultilingualContentService multilingualContentService;
protected ContentFilterLanguagesService contentFilterLanguagesService;
protected LockService lockService;
protected VersionService versionService;
protected NodeRef mlContainerToVersion;
private List<SelectItem> selectableTranslations;
private String startingItemNodeString;
private List<TranslationWrapper> selectableTranslations;
private List<TranslationWrapper> translationsCheckedOut;
private String editionNotes;
private boolean minorChange;
private boolean otherProperties;
private List<SelectItem> translationCheckedOut;
private boolean skipFirstStep;
private String language;
private String title;
private String author;
private boolean hasTranslationCheckedOut;
private NodeRef startingElement;
private String author;
private String selectedLanguage;
@Override
public void init(Map<String, String> parameters)
@@ -81,32 +95,50 @@ public class NewEditionWizard extends BaseWizardBean
super.init(parameters);
// reset the fileds
startingItemNodeString = null;
editionNotes = null;
minorChange = true;
otherProperties = false;
translationCheckedOut = null;
language = "lang";
title = "title";
author = "author";
translationsCheckedOut = null;
selectableTranslations = null;
// set the mlContainer to version
NodeRef currentNodeRef = this.browseBean.getDocument().getNodeRef();
if(ContentModel.TYPE_MULTILINGUAL_CONTAINER.equals(nodeService.getType(currentNodeRef)))
if(!skipFirstStep)
{
mlContainerToVersion = currentNodeRef;
}
else
{
mlContainerToVersion = multilingualContentService.getTranslationContainer(currentNodeRef);
// this properties is set by the skipFirstStep action event method.
language = null;
title = null;
// set the current mlContainer
setMLContainer();
}
translationCheckedOut = getTranslationCheckedOut();
hasTranslationCheckedOut = getHasTranslationCheckedOut();
// init the list of the available translations and the list of translations checked out
initTranslationList();
// true if they are at leat one translation checked out
hasTranslationCheckedOut = this.translationsCheckedOut.size() > 0;
}
/**
* Force the the lang of the new pivot translation for the new edition and skip the first step
*/
public void skipFirstStep(ActionEvent event)
{
skipFirstStep = true;
// Get the lang of the new
UIActionLink link = (UIActionLink)event.getComponent();
Map<String, String> params = link.getParameterMap();
String lang = params.get("lang");
// test if the parameter is valid
ParameterCheck.mandatoryString("The lang of the node", lang);
// set the current mlContainer
setMLContainer();
setStartingItem(lang.toLowerCase());
}
@Override
@@ -127,6 +159,7 @@ public class NewEditionWizard extends BaseWizardBean
// create the edition and get the reference of the new starting translation
NodeRef newPivot = editionService.createEdition(startingElement, versionProperties);
// redirect the user at the 'modify translation properties' page if desire.
if (otherProperties == true)
{
this.browseBean.setDocument(new Node(newPivot));
@@ -137,9 +170,30 @@ public class NewEditionWizard extends BaseWizardBean
outcome = AlfrescoNavigationHandler.CLOSE_DIALOG_OUTCOME + AlfrescoNavigationHandler.OUTCOME_SEPARATOR + "browse";
}
skipFirstStep = false;
return outcome;
}
/**
* Returns the properties for checked out translations JSF DataModel
*
* @return JSF DataModel representing the translations checked out
*/
public DataModel getTranslationsCheckedOutDataModel()
{
return getDataModel(this.translationsCheckedOut);
}
/**
* Returns the properties for available translations JSF DataModel
*
* @return JSF DataModel representing the available translation for a new edition
*/
public DataModel getAvailableTranslationsDataModel()
{
return getDataModel(this.selectableTranslations);
}
/**
* Determines whether there are any translation checked out.
@@ -148,8 +202,6 @@ public class NewEditionWizard extends BaseWizardBean
*/
public boolean getHasTranslationCheckedOut()
{
hasTranslationCheckedOut = getTranslationCheckedOut().size() > 0;
return hasTranslationCheckedOut;
}
@@ -165,117 +217,94 @@ public class NewEditionWizard extends BaseWizardBean
return super.getNextButtonDisabled() || hasTranslationCheckedOut;
}
/**
* @param language of the starting translation to set as the new pivot of the new edition
*/
private void setStartingItem(String language)
{
// get the starting point translation with its locale
startingElement = multilingualContentService.getTranslationForLocale(mlContainerToVersion, I18NUtil.parseLocale(language));
// set the futur properties of the new starting element (only usefull for the summary step)
setLanguage(language);
setTitle((String) nodeService.getProperty(startingElement, ContentModel.PROP_TITLE));
setAuthor((String) nodeService.getProperty(startingElement, ContentModel.PROP_AUTHOR));
}
/**
* Return the list of cecked out document found in the mlContainer.
*
* @return the list of checked out translation
* Util metho which construct a data model with rows passed in parameter
*/
public List<SelectItem> getTranslationCheckedOut()
private DataModel getDataModel(Object rows)
{
if(translationCheckedOut == null )
DataModel translationDataModel = new ListDataModel();
translationDataModel.setWrappedData(rows);
return translationDataModel;
}
/**
* Util method which init the lists of translations
*/
private void initTranslationList()
{
this.translationsCheckedOut = new ArrayList<TranslationWrapper>();
this.selectableTranslations = new ArrayList<TranslationWrapper>();
// get all translations of the mlContainer
Map<Locale, NodeRef> translations = multilingualContentService.getTranslations(mlContainerToVersion);
// fill the data table rows list
for(Map.Entry<Locale, NodeRef> entry : translations.entrySet())
{
// first call, init the list
NodeRef nodeRef = entry.getValue();
this.translationCheckedOut = new ArrayList<SelectItem>();
String name = (String) nodeService.getProperty(nodeRef, ContentModel.PROP_NAME);
String langCode = ((Locale) nodeService.getProperty(nodeRef, ContentModel.PROP_LOCALE)).getLanguage();
String langText = contentFilterLanguagesService.getLabelByCode(langCode);
String lockOwner = (String) nodeService.getProperty(nodeRef, ContentModel.PROP_LOCK_OWNER);
// get all translations of the mlContainer
Map<Locale, NodeRef> translations = multilingualContentService.getTranslations(mlContainerToVersion);
// create the row with the current translation
TranslationWrapper wrapper = new TranslationWrapper(name, langCode, lockOwner, langText);
// fill the select itms
for(Map.Entry<Locale, NodeRef> entry : translations.entrySet())
if(!nodeService.hasAspect(nodeRef, ContentModel.ASPECT_MULTILINGUAL_EMPTY_TRANSLATION))
{
NodeRef nodeRef = entry.getValue();
if(nodeService.hasAspect(nodeRef, ContentModel.ASPECT_LOCKABLE))
// add it to the selectable list if it is not empty
this.selectableTranslations.add(wrapper);
}
if(nodeService.hasAspect(nodeRef, ContentModel.ASPECT_LOCKABLE))
{
LockStatus lockStatus = lockService.getLockStatus(nodeRef);
if (lockStatus != LockStatus.NO_LOCK)
{
LockStatus lockStatus = lockService.getLockStatus(nodeRef);
if (lockStatus != LockStatus.NO_LOCK)
{
// if the node is locked, add it to the locked translation list
String name = (String) nodeService.getProperty(nodeRef, ContentModel.PROP_NAME);
Locale lang = (Locale) nodeService.getProperty(nodeRef, ContentModel.PROP_LOCALE);
String lockOwner = (String) nodeService.getProperty(nodeRef, ContentModel.PROP_WORKING_COPY_OWNER);
this.translationCheckedOut.add(new SelectItem(
"(" + lang.getLanguage() + ")",
name,
lockOwner
));
}
// if the node is locked, add it to the locked translation list
this.translationsCheckedOut.add(wrapper);
}
}
}
return this.translationCheckedOut;
}
}
/**
* Return the list of available translations to begin the starting translations of the new edition.
*
* @return the list of available translations
*/
public List<SelectItem> getSelectableTranslations()
private void setMLContainer()
{
if(selectableTranslations == null)
// set the mlContainer to version
NodeRef currentNodeRef = this.browseBean.getDocument().getNodeRef();
if(ContentModel.TYPE_MULTILINGUAL_CONTAINER.equals(nodeService.getType(currentNodeRef)))
{
// first call, init the list
selectableTranslations = new ArrayList<SelectItem>();
// get all translations of the mlContainer
Map<Locale, NodeRef> translations = multilingualContentService.getTranslations(mlContainerToVersion);
// fill the select items
for(Map.Entry<Locale, NodeRef> entry : translations.entrySet())
{
NodeRef nodeRef = entry.getValue();
//add each non empty translation
if(!nodeService.hasAspect(nodeRef, ContentModel.ASPECT_MULTILINGUAL_EMPTY_TRANSLATION))
{
String name = (String) nodeService.getProperty(nodeRef, ContentModel.PROP_NAME);
Locale lang = (Locale) nodeService.getProperty(nodeRef, ContentModel.PROP_LOCALE);
selectableTranslations.add(new SelectItem(
nodeRef.toString(),
name + " - " + contentFilterLanguagesService.getLabelByCode(lang.getLanguage())
));
}
}
mlContainerToVersion = currentNodeRef;
}
else
{
mlContainerToVersion = multilingualContentService.getTranslationContainer(currentNodeRef);
}
return selectableTranslations;
}
/**
* @param multilingualContentService the Multilingual Content Service to set
*/
public void setMultilingualContentService(MultilingualContentService multilingualContentService)
{
this.multilingualContentService = multilingualContentService;
}
/**
* @param nodeService the Node Service to set
*/
public void setNodeService(NodeService nodeService)
{
this.nodeService = nodeService;
}
/**
* @param editionService the Edition Service to set
*/
public void setEditionService(EditionService editionService)
{
this.editionService = editionService;
if(!skipFirstStep)
{
// init the pivot language (it will be selected by default)
selectedLanguage = ((Locale) nodeService.getProperty(mlContainerToVersion, ContentModel.PROP_LOCALE)).getLanguage();
}
}
/**
@@ -326,49 +355,6 @@ public class NewEditionWizard extends BaseWizardBean
this.otherProperties = otherProperties;
}
/**
* @return the starting translation being the new pivot of tne new edition
*/
public String getStartingItemNodeString()
{
return startingItemNodeString;
}
/**
* @param startingItemNodeString the starting translation to set as the new pivot of tne new edition
*/
public void setStartingItemNodeString(String startingItemNodeString)
{
// get the starting point translation with its id
startingElement = new NodeRef(startingItemNodeString);
// set the futur properties of the new starting element (only usefull for the summary step)
setLanguage((Locale) nodeService.getProperty(startingElement, ContentModel.PROP_LOCALE));
setAuthor((String) nodeService.getProperty(startingElement, ContentModel.PROP_AUTHOR));
setTitle((String) nodeService.getProperty(startingElement, ContentModel.PROP_TITLE));
this.startingItemNodeString = startingItemNodeString;
}
/**
* @param contentFilterLanguagesService the Content Filter Languages Service to set
*/
public void setContentFilterLanguagesService(ContentFilterLanguagesService contentFilterLanguagesService)
{
this.contentFilterLanguagesService = contentFilterLanguagesService;
}
/**
* @param lockService the Lock Service to set
*/
public void setLockService(LockService lockService)
{
this.lockService = lockService;
}
/**
* @return the author
*/
@@ -378,21 +364,12 @@ public class NewEditionWizard extends BaseWizardBean
}
/**
* @param author the author to set
*/
public void setAuthor(String author)
{
this.author = author;
}
/**
* @return the language
*/
public String getLanguage()
{
return language;
return contentFilterLanguagesService.getLabelByCode(language);
}
@@ -429,19 +406,170 @@ public class NewEditionWizard extends BaseWizardBean
this.title = title;
}
/**
* @param author the author to set
*/
public void setAuthor(String author)
{
this.author = author;
}
/**
* @return the versionLabel
*/
public String getVersionLabel()
{
String toReturn = "Version Label";
String label = versionService.getCurrentVersion(mlContainerToVersion).getVersionLabel();
String nextLabel = null;
try
{
int dotPosition = label.indexOf('.');
int major = Integer.parseInt(label.substring(0, dotPosition));
int minor = Integer.parseInt(label.substring(dotPosition + 1));
if(minorChange)
{
nextLabel = major + "." + (minor + 1);
}
else
{
nextLabel = (major + 1) + ".0";
}
}
catch(Exception e)
{
nextLabel = "";
}
if(minorChange)
{
toReturn += " (minor change)";
String minorString = Application.getMessage(
FacesContext.getCurrentInstance(),
ID_MESSAGE_MINOR_CHANGE);
return nextLabel + " (" + minorString + ')' ;
}
else
{
return nextLabel;
}
}
/**
* @return the selectedTranslationLanguage
*/
public String getSelectedTranslationLanguage()
{
return selectedLanguage;
}
/**
* @param selectedTranslationLanguage the selectedTranslationLanguage to set
*/
public void setSelectedTranslationLanguage(String language)
{
// only the selected language is not set as null
if(language != null)
{
setStartingItem(language);
}
return toReturn;
}
/**
* @param multilingualContentService the Multilingual Content Service to set
*/
public void setMultilingualContentService(MultilingualContentService multilingualContentService)
{
this.multilingualContentService = multilingualContentService;
}
/**
* @param nodeService the Node Service to set
*/
public void setNodeService(NodeService nodeService)
{
this.nodeService = nodeService;
}
/**
* @param contentFilterLanguagesService the Content Filter Languages Service to set
*/
public void setContentFilterLanguagesService(ContentFilterLanguagesService contentFilterLanguagesService)
{
this.contentFilterLanguagesService = contentFilterLanguagesService;
}
/**
* @param lockService the Lock Service to set
*/
public void setLockService(LockService lockService)
{
this.lockService = lockService;
}
/**
* @param editionService the Edition Service to set
*/
public void setEditionService(EditionService editionService)
{
this.editionService = editionService;
}
/**
* @param versionService the version Service to set
*/
public void setVersionService(VersionService versionService)
{
this.versionService = versionService;
}
/**
* Simple wrapper class to represent a translation in the data table
*/
public static class TranslationWrapper
{
private String language;
private String name;
private String checkedOutBy;
private String languageLabel;
public TranslationWrapper(String name, String language, String checkedOutBy, String languageLabel)
{
this.name = name;
this.language = language;
this.checkedOutBy = checkedOutBy;
this.languageLabel = languageLabel;
}
public String getCheckedOutBy()
{
return checkedOutBy;
}
public String getLanguage()
{
return language;
}
public String getName()
{
return name;
}
public String getLanguageLabel()
{
return this.languageLabel;
}
}
}