MT - fix node service so that policies are triggered with base refs

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@8312 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Jan Vonka
2008-02-18 16:14:05 +00:00
parent 3d1d97523e
commit 2237d2f748
9 changed files with 41 additions and 79 deletions

View File

@@ -777,9 +777,6 @@
</property>
<property name="internalNodeService">
<ref bean="nodeService" />
</property>
<property name="tenantService">
<ref bean="tenantService" />
</property>
</bean>

View File

@@ -100,6 +100,9 @@
</property>
<property name="indexer">
<ref bean="indexerComponent" />
</property>
<property name="tenantService">
<ref bean="tenantService"/>
</property>
</bean>

View File

@@ -6,8 +6,7 @@
<bean id="usageService" class="org.alfresco.repo.usage.UsageServiceImpl">
<property name="usageDeltaDao" ref="usageDeltaDao"/>
<property name="nodeDaoService" ref="nodeDaoService"/>
<property name="tenantService" ref="tenantService"/>
<property name="nodeDaoService" ref="nodeDaoService"/>
</bean>
<bean id="contentUsageImpl" class="org.alfresco.repo.usage.ContentUsageImpl" init-method="init">

View File

@@ -40,7 +40,6 @@ import org.alfresco.repo.policy.ClassPolicyDelegate;
import org.alfresco.repo.policy.JavaBehaviour;
import org.alfresco.repo.policy.PolicyComponent;
import org.alfresco.repo.policy.PolicyScope;
import org.alfresco.repo.tenant.TenantService;
import org.alfresco.service.cmr.dictionary.AspectDefinition;
import org.alfresco.service.cmr.dictionary.AssociationDefinition;
import org.alfresco.service.cmr.dictionary.ChildAssociationDefinition;
@@ -101,9 +100,6 @@ public class CopyServiceImpl implements CopyService
/** Authentication service */
private AuthenticationService authenticationService;
/** Tenant service */
private TenantService tenantService;
/** Policy delegates */
private ClassPolicyDelegate<CopyServicePolicies.OnCopyNodePolicy> onCopyNodeDelegate;
@@ -188,16 +184,6 @@ public class CopyServiceImpl implements CopyService
{
this.authenticationService = authenticationService;
}
/**
* Sets the tenant service
*
* @param tenantService the tenant service
*/
public void setTenantService(TenantService tenantService)
{
this.tenantService = tenantService;
}
/**
* Initialise method
@@ -239,8 +225,7 @@ public class CopyServiceImpl implements CopyService
ParameterCheck.mandatory("Destination Parent", destinationParentRef);
ParameterCheck.mandatory("Destination Association Name", destinationQName);
// AR-2023, need to push down
if (tenantService.getName(sourceNodeRef.getStoreRef()).equals(tenantService.getName(destinationParentRef.getStoreRef())) == false)
if (sourceNodeRef.getStoreRef().equals(destinationParentRef.getStoreRef()) == false)
{
// TODO We need to create a new node in the other store with the same id as the source

View File

@@ -132,7 +132,7 @@ public class DbNodeServiceImpl extends AbstractNodeServiceImpl
{
ParameterCheck.mandatory("nodeRef", nodeRef);
Node unchecked = nodeDaoService.getNode(tenantService.getName(nodeRef));
Node unchecked = nodeDaoService.getNode(nodeRef);
if (unchecked == null)
{
throw new InvalidNodeRefException("Node does not exist: " + nodeRef, nodeRef);
@@ -150,7 +150,7 @@ public class DbNodeServiceImpl extends AbstractNodeServiceImpl
{
ParameterCheck.mandatory("nodeRef", nodeRef);
NodeStatus nodeStatus = nodeDaoService.getNodeStatus(tenantService.getName(nodeRef), false);
NodeStatus nodeStatus = nodeDaoService.getNodeStatus(nodeRef, false);
if (nodeStatus == null || nodeStatus.getNode() == null)
{
throw new InvalidNodeRefException("Node does not exist: " + nodeRef, nodeRef);
@@ -160,7 +160,6 @@ public class DbNodeServiceImpl extends AbstractNodeServiceImpl
public boolean exists(StoreRef storeRef)
{
storeRef = tenantService.getName(storeRef);
Store store = nodeDaoService.getStore(storeRef.getProtocol(), storeRef.getIdentifier());
boolean exists = (store != null);
// done
@@ -171,7 +170,6 @@ public class DbNodeServiceImpl extends AbstractNodeServiceImpl
{
ParameterCheck.mandatory("nodeRef", nodeRef);
nodeRef = tenantService.getName(nodeRef);
Node node = nodeDaoService.getNode(nodeRef);
boolean exists = (node != null);
// done
@@ -182,7 +180,6 @@ public class DbNodeServiceImpl extends AbstractNodeServiceImpl
{
ParameterCheck.mandatory("nodeRef", nodeRef);
nodeRef = tenantService.getName(nodeRef);
NodeStatus nodeStatus = nodeDaoService.getNodeStatus(nodeRef, false);
if (nodeStatus == null) // node never existed
{
@@ -234,8 +231,8 @@ public class DbNodeServiceImpl extends AbstractNodeServiceImpl
*/
public StoreRef createStore(String protocol, String identifier)
{
StoreRef storeRef = tenantService.getName(new StoreRef(protocol, identifier));
identifier = storeRef.getIdentifier();
StoreRef storeRef = new StoreRef(protocol, identifier);
// check that the store does not already exist
Store store = nodeDaoService.getStore(protocol, identifier);
if (store != null)
@@ -250,20 +247,22 @@ public class DbNodeServiceImpl extends AbstractNodeServiceImpl
store = nodeDaoService.createStore(protocol, identifier);
// get the root node
Node rootNode = store.getRootNode();
NodeRef rootNodeRef = tenantService.getBaseName(rootNode.getNodeRef());
// assign the root aspect - this is expected of all roots, even store roots
addAspect(rootNode.getNodeRef(),
addAspect(rootNodeRef,
ContentModel.ASPECT_ROOT,
Collections.<QName, Serializable>emptyMap());
// invoke policies
invokeOnCreateStore(rootNode.getNodeRef());
invokeOnCreateStore(rootNodeRef);
// done
if (!store.getStoreRef().equals(storeRef))
{
throw new RuntimeException("Incorrect store reference");
}
storeRef = tenantService.getBaseName(storeRef);
return storeRef;
}
@@ -272,8 +271,6 @@ public class DbNodeServiceImpl extends AbstractNodeServiceImpl
*/
public void deleteStore(StoreRef storeRef)
{
storeRef = tenantService.getName(storeRef);
String protocol = storeRef.getProtocol();
String identifier = storeRef.getIdentifier();
@@ -296,7 +293,6 @@ public class DbNodeServiceImpl extends AbstractNodeServiceImpl
public NodeRef getRootNode(StoreRef storeRef) throws InvalidStoreRefException
{
storeRef = tenantService.getName(storeRef);
Store store = nodeDaoService.getStore(storeRef.getProtocol(), storeRef.getIdentifier());
if (store == null)
{
@@ -308,10 +304,8 @@ public class DbNodeServiceImpl extends AbstractNodeServiceImpl
{
throw new InvalidStoreRefException("Store does not have a root node: " + storeRef, storeRef);
}
NodeRef nodeRef = node.getNodeRef();
nodeRef = tenantService.getBaseName(nodeRef);
// done
return nodeRef;
return tenantService.getBaseName(node.getNodeRef());
}
/**
@@ -341,7 +335,6 @@ public class DbNodeServiceImpl extends AbstractNodeServiceImpl
Assert.notNull(assocQName);
// Get the parent node
parentRef = tenantService.getName(parentRef);
Node parentNode = getNodeNotNull(parentRef);
// null property map is allowed
@@ -359,8 +352,7 @@ public class DbNodeServiceImpl extends AbstractNodeServiceImpl
invokeBeforeCreateNode(parentRef, assocTypeQName, assocQName, nodeTypeQName);
// get the store that the parent belongs to
StoreRef storeRef = parentRef.getStoreRef();
Store store = nodeDaoService.getStore(storeRef.getProtocol(), storeRef.getIdentifier());
Store store = nodeDaoService.getStore(parentRef.getStoreRef().getProtocol(), parentRef.getStoreRef().getIdentifier());
if (store == null)
{
throw new RuntimeException("No store found for parent node: " + parentRef);
@@ -378,7 +370,7 @@ public class DbNodeServiceImpl extends AbstractNodeServiceImpl
// create the node instance
Node childNode = nodeDaoService.newNode(store, newId, nodeTypeQName);
NodeRef childNodeRef = childNode.getNodeRef();
NodeRef childNodeRef = tenantService.getBaseName(childNode.getNodeRef());
// We now have enough to declare the child association creation
invokeBeforeCreateChildAssociation(parentRef, childNodeRef, assocTypeQName, assocQName, true);
@@ -407,7 +399,7 @@ public class DbNodeServiceImpl extends AbstractNodeServiceImpl
// Ensure child uniqueness
setChildUniqueName(childNode); // ensure uniqueness
ChildAssociationRef childAssocRef = childAssoc.getChildAssocRef();
ChildAssociationRef childAssocRef = tenantService.getBaseName(childAssoc.getChildAssocRef());
// Invoke policy behaviour
invokeOnCreateNode(childAssocRef);
@@ -468,10 +460,9 @@ public class DbNodeServiceImpl extends AbstractNodeServiceImpl
Node newParentNode = getNodeNotNull(newParentRef);
// get the primary parent assoc
ChildAssoc oldAssoc = nodeDaoService.getPrimaryParentAssoc(nodeToMove);
ChildAssociationRef oldAssocRef = oldAssoc.getChildAssocRef();
ChildAssociationRef oldAssocRef = tenantService.getBaseName(oldAssoc.getChildAssocRef());
// AR-2023, need to push down
boolean movingStore = !tenantService.getName(nodeToMoveRef.getStoreRef()).equals(tenantService.getName(newParentRef.getStoreRef()));
boolean movingStore = !nodeToMoveRef.getStoreRef().equals(newParentRef.getStoreRef());
// data needed for policy invocation
QName nodeToMoveTypeQName = nodeToMove.getTypeQName();
@@ -501,7 +492,7 @@ public class DbNodeServiceImpl extends AbstractNodeServiceImpl
assocTypeQName,
assocQName);
setChildUniqueName(nodeToMove); // ensure uniqueness
ChildAssociationRef newAssocRef = newAssoc.getChildAssocRef();
ChildAssociationRef newAssocRef = tenantService.getBaseName(newAssoc.getChildAssocRef());
// If the node is moving stores, then drag the node hierarchy with it
if (movingStore)
@@ -605,7 +596,6 @@ public class DbNodeServiceImpl extends AbstractNodeServiceImpl
Map<QName, Serializable> aspectProperties)
throws InvalidNodeRefException, InvalidAspectException
{
nodeRef = tenantService.getName(nodeRef);
// check that the aspect is legal
AspectDefinition aspectDef = dictionaryService.getAspect(aspectTypeQName);
if (aspectDef == null)
@@ -749,7 +739,6 @@ public class DbNodeServiceImpl extends AbstractNodeServiceImpl
public void deleteNode(NodeRef nodeRef)
{
nodeRef = tenantService.getName(nodeRef);
// First get the node to ensure that it exists
Node node = getNodeNotNull(nodeRef);
@@ -759,7 +748,8 @@ public class DbNodeServiceImpl extends AbstractNodeServiceImpl
invokeBeforeDeleteNode(nodeRef);
// get the primary parent-child relationship before it is gone
ChildAssociationRef childAssocRef = tenantService.getName(getPrimaryParent(nodeRef)); //note: tenant-specific for re-indexing
ChildAssociationRef childAssocRef = getPrimaryParent(nodeRef);
// get type and aspect QNames as they will be unavailable after the delete
QName nodeTypeQName = node.getTypeQName();
Set<QName> nodeAspectQNames = node.getAspects();
@@ -778,8 +768,6 @@ public class DbNodeServiceImpl extends AbstractNodeServiceImpl
StoreRef storeRef = nodeRef.getStoreRef();
// remove tenant domain - to retrieve archive store from map
storeRef = tenantService.getBaseName(storeRef);
archiveStoreRef = storeArchiveMap.getArchiveMap().get(storeRef);
// get the type and check if we need archiving
TypeDefinition typeDef = dictionaryService.getType(node.getTypeQName());
@@ -977,7 +965,6 @@ public class DbNodeServiceImpl extends AbstractNodeServiceImpl
public Map<QName, Serializable> getProperties(NodeRef nodeRef) throws InvalidNodeRefException
{
nodeRef = tenantService.getName(nodeRef);
Node node = getNodeNotNull(nodeRef);
return getPropertiesImpl(node);
}
@@ -1139,7 +1126,6 @@ public class DbNodeServiceImpl extends AbstractNodeServiceImpl
{
Assert.notNull(qname);
nodeRef = tenantService.getName(nodeRef);
// get the node
Node node = getNodeNotNull(nodeRef);
@@ -1193,7 +1179,6 @@ public class DbNodeServiceImpl extends AbstractNodeServiceImpl
throw new UnsupportedOperationException("The property " + qname + " may not be removed individually");
}
nodeRef = tenantService.getName(nodeRef);
// Get the node
Node node = getNodeNotNull(nodeRef);
@@ -1900,7 +1885,6 @@ public class DbNodeServiceImpl extends AbstractNodeServiceImpl
public NodeRef getStoreArchiveNode(StoreRef storeRef)
{
storeRef = tenantService.getBaseName(storeRef);
StoreRef archiveStoreRef = storeArchiveMap.getArchiveMap().get(storeRef);
if (archiveStoreRef == null)
{

View File

@@ -450,7 +450,7 @@ public class HibernateNodeDaoServiceImpl extends HibernateDaoSupport implements
public Store getStore(String protocol, String identifier)
{
StoreKey storeKey = new StoreKey(protocol, identifier);
StoreKey storeKey = new StoreKey(protocol, tenantService.getName(identifier));
Store store = (Store) getHibernateTemplate().get(StoreImpl.class, storeKey);
// done
return store;
@@ -461,7 +461,7 @@ public class HibernateNodeDaoServiceImpl extends HibernateDaoSupport implements
*/
public NodeStatus getNodeStatus(NodeRef nodeRef, boolean update)
{
NodeKey nodeKey = new NodeKey(nodeRef);
NodeKey nodeKey = new NodeKey(tenantService.getName(nodeRef));
NodeStatus status = null;
try
{
@@ -495,7 +495,7 @@ public class HibernateNodeDaoServiceImpl extends HibernateDaoSupport implements
public void recordChangeId(NodeRef nodeRef)
{
NodeKey key = new NodeKey(nodeRef);
NodeKey key = new NodeKey(tenantService.getName(nodeRef));
NodeStatus status = (NodeStatus) getHibernateTemplate().get(NodeStatusImpl.class, key);
if (status == null)
@@ -1434,7 +1434,7 @@ public class HibernateNodeDaoServiceImpl extends HibernateDaoSupport implements
{
Query query = session.getNamedQuery(QUERY_GET_NODE_COUNT_FOR_STORE);
query.setString("protocol", storeRef.getProtocol())
.setString("identifier", storeRef.getIdentifier())
.setString("identifier", tenantService.getName(storeRef.getIdentifier()))
.setMaxResults(1)
.setReadOnly(true);
return query.uniqueResult();
@@ -1455,7 +1455,7 @@ public class HibernateNodeDaoServiceImpl extends HibernateDaoSupport implements
{
Query query = session.getNamedQuery(QUERY_NODES_WITH_PROPERTY_STRING_VALUE_FOR_STORE);
query.setString("protocol", storeRef.getProtocol())
.setString("identifier", storeRef.getIdentifier())
.setString("identifier", tenantService.getName(storeRef.getIdentifier()))
.setParameter("propQName", propQName)
.setString("propStringValue", propStringValue)
.setReadOnly(true);

View File

@@ -28,6 +28,7 @@ import org.alfresco.repo.node.NodeServicePolicies;
import org.alfresco.repo.policy.JavaBehaviour;
import org.alfresco.repo.policy.PolicyComponent;
import org.alfresco.repo.search.Indexer;
import org.alfresco.repo.tenant.TenantService;
import org.alfresco.service.cmr.repository.ChildAssociationRef;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.namespace.NamespaceService;
@@ -50,6 +51,7 @@ public class NodeIndexer
private PolicyComponent policyComponent;
/** the component to index the node hierarchy */
private Indexer indexer;
private TenantService tenantService;
/**
* @param policyComponent used for registrations
@@ -66,6 +68,11 @@ public class NodeIndexer
{
this.indexer = indexer;
}
public void setTenantService(TenantService tenantService)
{
this.tenantService = tenantService;
}
/**
* Registers the policy behaviour methods
@@ -96,29 +103,29 @@ public class NodeIndexer
public void onCreateNode(ChildAssociationRef childAssocRef)
{
indexer.createNode(childAssocRef);
indexer.createNode(tenantService.getName(childAssocRef));
}
public void onUpdateNode(NodeRef nodeRef)
{
indexer.updateNode(nodeRef);
indexer.updateNode(tenantService.getName(nodeRef));
}
public void onDeleteNode(ChildAssociationRef childAssocRef, boolean isArchivedNode)
{
indexer.deleteNode(childAssocRef);
indexer.deleteNode(tenantService.getName(childAssocRef));
}
public void onCreateChildAssociation(ChildAssociationRef childAssocRef, boolean isNew)
{
if (!isNew)
{
indexer.createChildRelationship(childAssocRef);
indexer.createChildRelationship(tenantService.getName(childAssocRef));
}
}
public void onDeleteChildAssociation(ChildAssociationRef childAssocRef)
{
indexer.deleteChildRelationship(childAssocRef);
indexer.deleteChildRelationship(tenantService.getName(childAssocRef));
}
}

View File

@@ -566,9 +566,6 @@ public class ADMLuceneSearcherImpl extends AbstractLuceneBase implements LuceneS
boolean followAllParentLinks, String language) throws InvalidNodeRefException, XPathException
{
NodeSearcher nodeSearcher = new NodeSearcher(nodeService, getDictionaryService(), this);
contextNodeRef = tenantService.getName(contextNodeRef);
return nodeSearcher.selectNodes(contextNodeRef, xpath, parameters, namespacePrefixResolver, followAllParentLinks, language);
}

View File

@@ -29,7 +29,6 @@ import java.util.Set;
import org.alfresco.repo.domain.Node;
import org.alfresco.repo.node.db.NodeDaoService;
import org.alfresco.repo.tenant.TenantService;
import org.alfresco.repo.usage.hibernate.UsageDeltaImpl;
import org.alfresco.service.cmr.repository.InvalidNodeRefException;
import org.alfresco.service.cmr.repository.NodeRef;
@@ -44,10 +43,6 @@ public class UsageServiceImpl implements UsageService
{
private UsageDeltaDAO usageDeltaDao;
private NodeDaoService nodeDaoService;
private TenantService tenantService;
//private static Log logger = LogFactory.getLog(UsageServiceImpl.class);
public void setUsageDeltaDao(UsageDeltaDAO usageDeltaDao)
{
@@ -58,11 +53,6 @@ public class UsageServiceImpl implements UsageService
{
this.nodeDaoService = nodeDaoService;
}
public void setTenantService(TenantService tenantService)
{
this.tenantService = tenantService;
}
public void insertDelta(NodeRef usageNodeRef, long deltaSize)
@@ -103,7 +93,7 @@ public class UsageServiceImpl implements UsageService
{
ParameterCheck.mandatory("nodeRef", nodeRef);
Node unchecked = nodeDaoService.getNode(tenantService.getName(nodeRef));
Node unchecked = nodeDaoService.getNode(nodeRef);
if (unchecked == null)
{
throw new InvalidNodeRefException("Node does not exist: " + nodeRef, nodeRef);