Mergeing form EC-MC: Completed. Removed intwined aspect deletion behaviour

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@5745 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Derek Hulley
2007-05-22 05:05:00 +00:00
parent d818c54e99
commit f6fbed84a0
18 changed files with 373 additions and 539 deletions

View File

@@ -0,0 +1,171 @@
/*
* 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 directMultilingualContentService;
@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 = directMultilingualContentService.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 = directMultilingualContentService.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 = directMultilingualContentService.getPivotTranslation(container);
}
else
{
// get the matched translation
matchedTranslation = directMultilingualContentService.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 setDirectMultilingualContentService(
MultilingualContentService multilingualContentService)
{
this.directMultilingualContentService = multilingualContentService;
}
public void setDirectNodeService(NodeService nodeService)
{
this.directNodeService = nodeService;
}
}

View File

@@ -600,10 +600,6 @@ public class DbNodeServiceImpl extends AbstractNodeServiceImpl
public void removeAspect(NodeRef nodeRef, QName aspectTypeQName)
throws InvalidNodeRefException, InvalidAspectException
{
// Invoke policy behaviours
invokeBeforeUpdateNode(nodeRef);
invokeBeforeRemoveAspect(nodeRef, aspectTypeQName);
// get the aspect
AspectDefinition aspectDef = dictionaryService.getAspect(aspectTypeQName);
if (aspectDef == null)
@@ -612,56 +608,64 @@ public class DbNodeServiceImpl extends AbstractNodeServiceImpl
}
// get the node
Node node = getNodeNotNull(nodeRef);
Set<QName> nodeAspects = node.getAspects();
if (!nodeAspects.contains(aspectTypeQName))
{
// The aspect isn't present so just leave it
return;
}
// Invoke policy behaviours
invokeBeforeUpdateNode(nodeRef);
invokeBeforeRemoveAspect(nodeRef, aspectTypeQName);
// remove the aspect, if present
boolean removed = node.getAspects().remove(aspectTypeQName);
// if the aspect was present, remove the associated properties and associations
if (removed)
node.getAspects().remove(aspectTypeQName);
Map<QName, PropertyValue> nodeProperties = node.getProperties();
Map<QName,PropertyDefinition> propertyDefs = aspectDef.getProperties();
for (QName propertyName : propertyDefs.keySet())
{
Map<QName, PropertyValue> nodeProperties = node.getProperties();
Map<QName,PropertyDefinition> propertyDefs = aspectDef.getProperties();
for (QName propertyName : propertyDefs.keySet())
{
nodeProperties.remove(propertyName);
}
// Remove child associations
Map<QName, ChildAssociationDefinition> childAssocDefs = aspectDef.getChildAssociations();
Collection<ChildAssoc> childAssocs = nodeDaoService.getChildAssocs(node);
for (ChildAssoc childAssoc : childAssocs)
{
// Ignore if the association type is not defined by the aspect
QName childAssocQName = childAssoc.getTypeQName();
if (!childAssocDefs.containsKey(childAssocQName))
{
continue;
}
// The association is of a type that should be removed
nodeDaoService.deleteChildAssoc(childAssoc, true);
}
// Remove regular associations
Map<QName, AssociationDefinition> assocDefs = aspectDef.getAssociations();
List<NodeAssoc> nodeAssocs = nodeDaoService.getTargetNodeAssocs(node);
for (NodeAssoc nodeAssoc : nodeAssocs)
{
// Ignore if the association type is not defined by the aspect
QName nodeAssocQName = nodeAssoc.getTypeQName();
if (!assocDefs.containsKey(nodeAssocQName))
{
continue;
}
// Delete the association
nodeDaoService.deleteNodeAssoc(nodeAssoc);
}
// Invoke policy behaviours
invokeOnUpdateNode(nodeRef);
invokeOnRemoveAspect(nodeRef, aspectTypeQName);
// update the node status
nodeDaoService.recordChangeId(nodeRef);
nodeProperties.remove(propertyName);
}
// Remove child associations
Map<QName, ChildAssociationDefinition> childAssocDefs = aspectDef.getChildAssociations();
Collection<ChildAssoc> childAssocs = nodeDaoService.getChildAssocs(node);
for (ChildAssoc childAssoc : childAssocs)
{
// Ignore if the association type is not defined by the aspect
QName childAssocQName = childAssoc.getTypeQName();
if (!childAssocDefs.containsKey(childAssocQName))
{
continue;
}
// The association is of a type that should be removed
nodeDaoService.deleteChildAssoc(childAssoc, true);
}
// Remove regular associations
Map<QName, AssociationDefinition> assocDefs = aspectDef.getAssociations();
List<NodeAssoc> nodeAssocs = nodeDaoService.getTargetNodeAssocs(node);
for (NodeAssoc nodeAssoc : nodeAssocs)
{
// Ignore if the association type is not defined by the aspect
QName nodeAssocQName = nodeAssoc.getTypeQName();
if (!assocDefs.containsKey(nodeAssocQName))
{
continue;
}
// Delete the association
nodeDaoService.deleteNodeAssoc(nodeAssoc);
}
// Invoke policy behaviours
invokeOnUpdateNode(nodeRef);
invokeOnRemoveAspect(nodeRef, aspectTypeQName);
// update the node status
nodeDaoService.recordChangeId(nodeRef);
}
/**