Fixed for MT Node Interceptor

- When MT is enabled, there is still a problem with the translation of NodeRefs for the UserUsage component


git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@10795 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Derek Hulley
2008-09-05 15:58:48 +00:00
parent 77eb167c2b
commit 178cd74b26
5 changed files with 51 additions and 215 deletions

View File

@@ -49,6 +49,11 @@
<import resource="classpath*:alfresco/patch/*-context.xml" /> <import resource="classpath*:alfresco/patch/*-context.xml" />
<import resource="classpath*:alfresco/domain/*-context.xml" /> <import resource="classpath*:alfresco/domain/*-context.xml" />
<!--
Import activation extensions for Multi-Tenancy.
-->
<import resource="classpath*:alfresco/extension/mt/*-context.xml"/>
<!-- <!--
Import all modules and related components. Import all modules and related components.
Extensions are explicitly imported after this so that the default Extensions are explicitly imported after this so that the default

View File

@@ -42,9 +42,9 @@
</property> </property>
<property name="interceptorNames"> <property name="interceptorNames">
<list> <list>
<value>multiTNodeServiceInterceptor</value>
<value>nodeRefPropertyInterceptor</value> <value>nodeRefPropertyInterceptor</value>
<value>mlPropertyInterceptor</value> <value>mlPropertyInterceptor</value>
<value>multiTNodeServiceInterceptor</value>
</list> </list>
</property> </property>
</bean> </bean>

View File

@@ -26,6 +26,9 @@ package org.alfresco.repo.tenant;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import org.alfresco.repo.security.authentication.AuthenticationUtil; import org.alfresco.repo.security.authentication.AuthenticationUtil;
import org.alfresco.service.cmr.repository.AssociationRef; import org.alfresco.service.cmr.repository.AssociationRef;
@@ -91,218 +94,7 @@ public class MultiTNodeServiceInterceptor extends DelegatingIntroductionIntercep
{ {
this.tenantService = tenantService; this.tenantService = tenantService;
} }
//
// public void addAspect(NodeRef nodeRef, QName aspectTypeQName, Map<QName, Serializable> aspectProperties) throws InvalidNodeRefException, InvalidAspectException
// {
// throw new UnsupportedOperationException();
// }
//
// public ChildAssociationRef addChild(NodeRef parentRef, NodeRef childRef, QName assocTypeQName, QName qname) throws InvalidNodeRefException
// {
// throw new UnsupportedOperationException();
// }
//
// public List<String> cleanup()
// {
// throw new UnsupportedOperationException();
// }
//
// public AssociationRef createAssociation(NodeRef sourceRef, NodeRef targetRef, QName assocTypeQName) throws InvalidNodeRefException, AssociationExistsException
// {
// throw new UnsupportedOperationException();
// }
//
// public ChildAssociationRef createNode(NodeRef parentRef, QName assocTypeQName, QName assocQName, QName nodeTypeQName, Map<QName, Serializable> properties)
// throws InvalidNodeRefException, InvalidTypeException
// {
// throw new UnsupportedOperationException();
// }
//
// public ChildAssociationRef createNode(NodeRef parentRef, QName assocTypeQName, QName assocQName, QName nodeTypeQName) throws InvalidNodeRefException, InvalidTypeException
// {
// throw new UnsupportedOperationException();
// }
//
// public StoreRef createStore(String protocol, String identifier) throws StoreExistsException
// {
// throw new UnsupportedOperationException();
// }
//
// public void deleteNode(NodeRef nodeRef) throws InvalidNodeRefException
// {
// throw new UnsupportedOperationException();
// }
//
// public void deleteStore(StoreRef storeRef)
// {
// throw new UnsupportedOperationException();
// }
//
// public boolean exists(NodeRef nodeRef)
// {
// throw new UnsupportedOperationException();
// }
//
// public boolean exists(StoreRef storeRef)
// {
// throw new UnsupportedOperationException();
// }
//
// public Set<QName> getAspects(NodeRef nodeRef) throws InvalidNodeRefException
// {
// throw new UnsupportedOperationException();
// }
//
// public List<ChildAssociationRef> getChildAssocs(NodeRef nodeRef, QNamePattern typeQNamePattern, QNamePattern qnamePattern) throws InvalidNodeRefException
// {
// throw new UnsupportedOperationException();
// }
//
// public List<ChildAssociationRef> getChildAssocs(NodeRef nodeRef) throws InvalidNodeRefException
// {
// throw new UnsupportedOperationException();
// }
//
// public NodeRef getChildByName(NodeRef nodeRef, QName assocTypeQName, String childName)
// {
// throw new UnsupportedOperationException();
// }
//
// public Status getNodeStatus(NodeRef nodeRef)
// {
// throw new UnsupportedOperationException();
// }
//
// public List<ChildAssociationRef> getParentAssocs(NodeRef nodeRef, QNamePattern typeQNamePattern, QNamePattern qnamePattern) throws InvalidNodeRefException
// {
// throw new UnsupportedOperationException();
// }
//
// public List<ChildAssociationRef> getParentAssocs(NodeRef nodeRef) throws InvalidNodeRefException
// {
// throw new UnsupportedOperationException();
// }
//
// public Path getPath(NodeRef nodeRef) throws InvalidNodeRefException
// {
// throw new UnsupportedOperationException();
// }
//
// public List<Path> getPaths(NodeRef nodeRef, boolean primaryOnly) throws InvalidNodeRefException
// {
// throw new UnsupportedOperationException();
// }
//
// public ChildAssociationRef getPrimaryParent(NodeRef nodeRef) throws InvalidNodeRefException
// {
// throw new UnsupportedOperationException();
// }
//
// public Map<QName, Serializable> getProperties(NodeRef nodeRef) throws InvalidNodeRefException
// {
// throw new UnsupportedOperationException();
// }
//
// public Serializable getProperty(NodeRef nodeRef, QName qname) throws InvalidNodeRefException
// {
// throw new UnsupportedOperationException();
// }
//
// public NodeRef getRootNode(StoreRef storeRef) throws InvalidStoreRefException
// {
// throw new UnsupportedOperationException();
// }
//
// public List<AssociationRef> getSourceAssocs(NodeRef targetRef, QNamePattern qnamePattern) throws InvalidNodeRefException
// {
// throw new UnsupportedOperationException();
// }
//
// public NodeRef getStoreArchiveNode(StoreRef storeRef)
// {
// throw new UnsupportedOperationException();
// }
//
// public List<StoreRef> getStores()
// {
// throw new UnsupportedOperationException();
// }
//
// public List<AssociationRef> getTargetAssocs(NodeRef sourceRef, QNamePattern qnamePattern) throws InvalidNodeRefException
// {
// throw new UnsupportedOperationException();
// }
//
// public QName getType(NodeRef nodeRef) throws InvalidNodeRefException
// {
// throw new UnsupportedOperationException();
// }
//
// public boolean hasAspect(NodeRef nodeRef, QName aspectTypeQName) throws InvalidNodeRefException, InvalidAspectException
// {
// throw new UnsupportedOperationException();
// }
//
// public ChildAssociationRef moveNode(NodeRef nodeToMoveRef, NodeRef newParentRef, QName assocTypeQName, QName assocQName) throws InvalidNodeRefException
// {
// throw new UnsupportedOperationException();
// }
//
// public void removeAspect(NodeRef nodeRef, QName aspectTypeQName) throws InvalidNodeRefException, InvalidAspectException
// {
// throw new UnsupportedOperationException();
// }
//
// public void removeAssociation(NodeRef sourceRef, NodeRef targetRef, QName assocTypeQName) throws InvalidNodeRefException
// {
// throw new UnsupportedOperationException();
// }
//
// public void removeChild(NodeRef parentRef, NodeRef childRef) throws InvalidNodeRefException
// {
// throw new UnsupportedOperationException();
// }
//
// public boolean removeChildAssociation(ChildAssociationRef childAssocRef)
// {
// throw new UnsupportedOperationException();
// }
//
// public void removeProperty(NodeRef nodeRef, QName qname) throws InvalidNodeRefException
// {
// throw new UnsupportedOperationException();
// }
//
// public boolean removeSeconaryChildAssociation(ChildAssociationRef childAssocRef)
// {
// throw new UnsupportedOperationException();
// }
//
// public NodeRef restoreNode(NodeRef archivedNodeRef, NodeRef destinationParentNodeRef, QName assocTypeQName, QName assocQName)
// {
// throw new UnsupportedOperationException();
// }
//
// public void setChildAssociationIndex(ChildAssociationRef childAssocRef, int index) throws InvalidChildAssociationRefException
// {
// throw new UnsupportedOperationException();
// }
//
// public void setProperties(NodeRef nodeRef, Map<QName, Serializable> properties) throws InvalidNodeRefException
// {
// throw new UnsupportedOperationException();
// }
//
// public void setProperty(NodeRef nodeRef, QName qname, Serializable value) throws InvalidNodeRefException
// {
// throw new UnsupportedOperationException();
// }
//
// public void setType(NodeRef nodeRef, QName typeQName) throws InvalidNodeRefException
// {
// throw new UnsupportedOperationException();
// }
//
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public Object invoke(MethodInvocation invocation) throws Throwable public Object invoke(MethodInvocation invocation) throws Throwable
{ {
@@ -351,6 +143,18 @@ public class MultiTNodeServiceInterceptor extends DelegatingIntroductionIntercep
AssociationRef ref = (AssociationRef) arg; AssociationRef ref = (AssociationRef) arg;
newArg = tenantService.getName(ref); newArg = tenantService.getName(ref);
} }
if (logger.isDebugEnabled())
{
if (!EqualsHelper.nullSafeEquals(newArg, arg))
{
logger.debug(
"Argument converted: \n" +
" Before: " + arg + "\n" +
" After: " + newArg);
}
}
// Substitute the new value // Substitute the new value
args[i] = newArg; args[i] = newArg;
} }
@@ -370,7 +174,23 @@ public class MultiTNodeServiceInterceptor extends DelegatingIntroductionIntercep
*/ */
private Collection<Object> convertOutboundValues(Collection<Object> rawValues) private Collection<Object> convertOutboundValues(Collection<Object> rawValues)
{ {
Collection<Object> convertedValues = new ArrayList<Object>(rawValues.size()); /*
* Return types can be Lists or Sets, so cater for both.
*/
final Collection<Object> convertedValues;
if (rawValues instanceof List)
{
convertedValues = new ArrayList<Object>(rawValues.size());
}
else if (rawValues instanceof Set)
{
convertedValues = new HashSet<Object>(rawValues.size(), 1.0F);
}
else
{
throw new IllegalArgumentException("Interceptor can only handle List and Set return types.");
}
for (Object rawValue : rawValues) for (Object rawValue : rawValues)
{ {
Object convertedValue = convertOutboundValue(rawValue); Object convertedValue = convertOutboundValue(rawValue);

View File

@@ -29,6 +29,7 @@ import junit.framework.TestCase;
import org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback; import org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback;
import org.alfresco.service.transaction.TransactionService; import org.alfresco.service.transaction.TransactionService;
import org.alfresco.util.ApplicationContextHelper; import org.alfresco.util.ApplicationContextHelper;
import org.alfresco.util.GUID;
import org.springframework.beans.factory.NoSuchBeanDefinitionException; import org.springframework.beans.factory.NoSuchBeanDefinitionException;
import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContext;
@@ -42,7 +43,7 @@ public class MultiTNodeServiceInterceptorTest extends TestCase
{ {
public static ApplicationContext ctx = ApplicationContextHelper.getApplicationContext(); public static ApplicationContext ctx = ApplicationContextHelper.getApplicationContext();
private String tenant1 = "tenant1"; private String tenant1 = "tenant-" + GUID.generate();
private String tenant1Pwd = "pwd1"; private String tenant1Pwd = "pwd1";
private boolean enableTest = true; private boolean enableTest = true;
private TransactionService transactionService; private TransactionService transactionService;

View File

@@ -236,6 +236,11 @@ public class UserUsageTrackingComponent
for (NodeRef personNodeRef : allPeople) for (NodeRef personNodeRef : allPeople)
{ {
// Cater for Lucene indexes being stale
if (!nodeService.exists(personNodeRef))
{
continue;
}
Long currentUsage = (Long)nodeService.getProperty(personNodeRef, ContentModel.PROP_SIZE_CURRENT); Long currentUsage = (Long)nodeService.getProperty(personNodeRef, ContentModel.PROP_SIZE_CURRENT);
if (currentUsage == null) if (currentUsage == null)
{ {
@@ -361,6 +366,11 @@ public class UserUsageTrackingComponent
public Object execute() throws Throwable public Object execute() throws Throwable
{ {
NodeRef personNodeRef = personService.getPerson(username); NodeRef personNodeRef = personService.getPerson(username);
if (!nodeService.exists(personNodeRef))
{
// Ignore
return null;
}
contentUsageImpl.setUserStoredUsage(personNodeRef, currentUsage); contentUsageImpl.setUserStoredUsage(personNodeRef, currentUsage);
usageService.deleteDeltas(personNodeRef); usageService.deleteDeltas(personNodeRef);
return null; return null;