Merging from EC-MC: Checkpoint before refactor

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@5744 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Derek Hulley
2007-05-22 05:03:16 +00:00
parent 2d461f5dd9
commit d818c54e99
22 changed files with 644 additions and 416 deletions

View File

@@ -30,9 +30,11 @@ import java.util.Locale;
import java.util.Map;
import org.alfresco.i18n.I18NUtil;
import org.alfresco.model.ContentModel;
import org.alfresco.service.cmr.dictionary.DataTypeDefinition;
import org.alfresco.service.cmr.dictionary.DictionaryService;
import org.alfresco.service.cmr.dictionary.PropertyDefinition;
import org.alfresco.service.cmr.ml.MultilingualContentService;
import org.alfresco.service.cmr.repository.MLText;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.NodeService;
@@ -72,6 +74,8 @@ public class MLPropertyInterceptor implements MethodInterceptor
/** Direct access to the NodeService */
private NodeService directNodeService;
/** Direct access to the ML Content Service */
private MultilingualContentService directMultilingualContentService;
/** Used to access property definitions */
private DictionaryService dictionaryService;
@@ -109,6 +113,11 @@ public class MLPropertyInterceptor implements MethodInterceptor
this.directNodeService = bean;
}
public void setDirectMultilingualContentService(MultilingualContentService directMultilingualContentService)
{
this.directMultilingualContentService = directMultilingualContentService;
}
public void setDictionaryService(DictionaryService dictionaryService)
{
this.dictionaryService = dictionaryService;
@@ -136,46 +145,29 @@ public class MLPropertyInterceptor implements MethodInterceptor
// Don't interfere
return invocation.proceed();
}
if (methodName.equals("getProperty"))
{
ret = invocation.proceed();
// The return value might need to be converted to a String
if (ret != null && ret instanceof MLText)
{
MLText mlText = (MLText) ret;
ret = mlText.getClosestValue(contentLocale);
// done
if (logger.isDebugEnabled())
{
logger.debug(
"Converted ML text: \n" +
" initial: " + mlText + "\n" +
" converted: " + ret);
}
}
NodeRef nodeRef = (NodeRef) args[0];
QName propertyQName = (QName) args[1];
Serializable value = (Serializable) invocation.proceed();
ret = convertOutboundProperty(contentLocale, nodeRef, propertyQName, value);
}
else if (methodName.equals("getProperties"))
{
NodeRef nodeRef = (NodeRef) args[0];
Map<QName, Serializable> properties = (Map<QName, Serializable>) invocation.proceed();
Map<QName, Serializable> convertedProperties = new HashMap<QName, Serializable>(properties.size() * 2);
// Check each return value type
for (Map.Entry<QName, Serializable> entry : properties.entrySet())
{
QName key = entry.getKey();
QName propertyQName = entry.getKey();
Serializable value = entry.getValue();
if (value != null && value instanceof MLText)
{
MLText mlText = (MLText) value;
value = mlText.getClosestValue(contentLocale);
// Store the converted value
convertedProperties.put(key, value);
}
else
{
// The value goes straight back in
convertedProperties.put(key, value);
}
Serializable convertedValue = convertOutboundProperty(contentLocale, nodeRef, propertyQName, value);
// Add it to the return map
convertedProperties.put(propertyQName, convertedValue);
}
ret = convertedProperties;
// Done
@@ -212,7 +204,6 @@ public class MLPropertyInterceptor implements MethodInterceptor
}
else if (methodName.equals("setProperty"))
{
//check if the property is of type MLText
NodeRef nodeRef = (NodeRef) args[0];
QName propertyQName = (QName) args[1];
Serializable inboundValue = (Serializable) args[2];
@@ -232,6 +223,64 @@ public class MLPropertyInterceptor implements MethodInterceptor
return ret;
}
/**
* Ensure that content is spoofed for empty translations.
*/
private Serializable convertOutboundProperty(
Locale contentLocale,
NodeRef nodeRef,
QName propertyQName,
Serializable outboundValue)
{
Serializable ret = null;
PropertyDefinition propertyDef = this.dictionaryService.getProperty(propertyQName);
// Is it content?
if (propertyDef != null && propertyDef.getDataType().getName().equals(DataTypeDefinition.CONTENT))
{
// Check if the document is an empty translation
if (directNodeService.hasAspect(nodeRef, ContentModel.ASPECT_MULTILINGUAL_EMPTY_TRANSLATION))
{
// Ignore the value and take it directly from the pivot translation
NodeRef pivotNodeRef = directMultilingualContentService.getPivotTranslation(nodeRef);
if (pivotNodeRef == null)
{
// This is very bad, but we don't fail the server for it
logger.warn("No pivot translation found for empty translation: " + nodeRef);
ret = outboundValue;
}
else
{
// Get the corresponding property from the pivot
ret = directNodeService.getProperty(pivotNodeRef, propertyQName);
}
}
else
{
ret = outboundValue;
}
}
else if (outboundValue != null && outboundValue instanceof MLText)
{
MLText mlText = (MLText) outboundValue;
ret = mlText.getClosestValue(contentLocale);
}
else
{
ret = outboundValue;
}
// Done
if (logger.isDebugEnabled())
{
logger.debug(
"Converted outbound property: \n" +
" NodeRef: " + nodeRef + "\n" +
" Property: " + propertyQName + "\n" +
" Before: " + outboundValue + "\n" +
" After: " + ret);
}
return ret;
}
/**
*
* @param inboundValue The value that must be set

View File

@@ -1,172 +0,0 @@
/*
* Copyright (C) 2005-2007 Alfresco Software Limited.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
* This program 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 General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
* As a special exception to the terms and conditions of version 2.0 of
* the GPL, you may redistribute this Program in connection with Free/Libre
* and Open Source Software ("FLOSS") applications as described in Alfresco's
* FLOSS exception. You should have recieved a copy of the text describing
* the FLOSS exception, and it is also available here:
* http://www.alfresco.com/legal/licensing"
*/
package org.alfresco.repo.node;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import java.util.Set;
import org.alfresco.i18n.I18NUtil;
import org.alfresco.model.ContentModel;
import org.alfresco.service.cmr.ml.MultilingualContentService;
import org.alfresco.service.cmr.repository.ChildAssociationRef;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.NodeService;
import org.alfresco.service.namespace.QName;
import org.aopalliance.intercept.MethodInterceptor;
import org.aopalliance.intercept.MethodInvocation;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
/**
* Interceptor to
* - filter the multilingual nodes to display the documents in the prefered language of teh user
*
* @author yanipig
*/
public class MLTranslationInterceptor implements MethodInterceptor
{
private static Log logger = LogFactory
.getLog(MLTranslationInterceptor.class);
private NodeService directNodeService;
private MultilingualContentService multilingualContentService;
@SuppressWarnings("unchecked")
public Object invoke(MethodInvocation invocation) throws Throwable
{
Object ret = null;
String methodName = invocation.getMethod().getName();
// intercept the methods getChildAssocs and getChildByNames to apply filter.
if (methodName.equals("getChildAssocs") || methodName.equals("getChildByName"))
{
ret = invocation.proceed();
NodeRef parent = (NodeRef) invocation.getArguments()[0];
// all the association returned by the method
List<ChildAssociationRef> allChildAssoc = (List<ChildAssociationRef>) ret;
// get the user content filter language
Locale filterLocale = I18NUtil.getContentLocaleOrNull();
if(filterLocale != null
&& directNodeService.getType(parent).equals(ContentModel.TYPE_FOLDER)
&& ret != null
&& !allChildAssoc.isEmpty()
)
{
// the list of Association to return
List<ChildAssociationRef> toReturn = new ArrayList();
// the ml containers found in the folder
List<NodeRef> mlContainers = new ArrayList();
// construct the list of ML Container
for (ChildAssociationRef assoc : allChildAssoc)
{
NodeRef child = assoc.getChildRef();
QName type = directNodeService.getType(child);
if(type.equals(ContentModel.TYPE_CONTENT) &&
directNodeService.hasAspect(child, ContentModel.ASPECT_MULTILINGUAL_DOCUMENT))
{
NodeRef container = multilingualContentService.getTranslationContainer(child);
if (!mlContainers.contains(container))
{
mlContainers.add(container);
}
}
else
{
// no specific treatment for folder and non-multilingual document
toReturn.add(assoc);
}
}
// for each mlContainer found, choose the unique document to return
for(NodeRef container : mlContainers)
{
// get each translation language
Set<Locale> locales = multilingualContentService.getTranslations(container).keySet();
if(locales != null && locales.size() > 0)
{
Locale matchedLocal = I18NUtil.getNearestLocale(filterLocale, locales);
NodeRef matchedTranslation = null;
// if the filter language is not found
if(matchedLocal == null)
{
// get the pivot translation
matchedTranslation = multilingualContentService.getPivotTranslation(container);
}
else
{
// get the matched translation
matchedTranslation = multilingualContentService.getTranslations(container).get(matchedLocal);
}
toReturn.add(new ChildAssociationRef(null, null, null, matchedTranslation));
}
}
ret = toReturn;
if (logger.isDebugEnabled())
{
logger.debug("Filter has found " +
allChildAssoc.size() + " entries, " +
mlContainers.size() + " different ML Container " +
"and returns " + toReturn.size() + " nodes");
}
}
}
else
{
ret = invocation.proceed();
}
return ret;
}
public void setMultilingualContentService(
MultilingualContentService multilingualContentService)
{
this.multilingualContentService = multilingualContentService;
}
public void setDirectNodeService(NodeService nodeService)
{
this.directNodeService = nodeService;
}
}

View File

@@ -694,7 +694,6 @@ public class DbNodeServiceImpl extends AbstractNodeServiceImpl
// First get the node to ensure that it exists
Node node = getNodeNotNull(nodeRef);
boolean isArchivedNode = false;
boolean requiresDelete = false;
// Invoke policy behaviours
@@ -713,7 +712,6 @@ public class DbNodeServiceImpl extends AbstractNodeServiceImpl
// the node has the temporary aspect meaning
// it can not be archived
requiresDelete = true;
isArchivedNode = false;
}
else
{
@@ -731,17 +729,15 @@ public class DbNodeServiceImpl extends AbstractNodeServiceImpl
{
// perform a normal deletion
nodeDaoService.deleteNode(node, true);
isArchivedNode = false;
// Invoke policy behaviours
invokeOnDeleteNode(childAssocRef, nodeTypeQName, nodeAspectQNames, false);
}
else
{
// archive it
archiveNode(nodeRef, archiveStoreRef);
isArchivedNode = true;
// The archive performs a move, which will fire the appropriate OnDeleteNode
}
// Invoke policy behaviours
invokeOnDeleteNode(childAssocRef, nodeTypeQName, nodeAspectQNames, isArchivedNode);
}
public ChildAssociationRef addChild(NodeRef parentRef, NodeRef childRef, QName assocTypeQName, QName assocQName)

View File

@@ -66,7 +66,7 @@ public class DbNodeServiceImplTest extends BaseNodeServiceTest
protected NodeService getNodeService()
{
return (NodeService) applicationContext.getBean("nodeService");
return (NodeService) applicationContext.getBean("dbNodeService");
}
@Override