mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-31 17:39:05 +00:00
Addressing review comment - don't have assoc types in the service API - have aspect names instead.
I agree with this comment. I think assoc types are an implementation detail of this service. git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/modules/recordsmanagement/BRANCHES/classified_renditions@111779 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -50,9 +50,8 @@
|
|||||||
<value>
|
<value>
|
||||||
org.alfresco.module.org_alfresco_module_rm.referredmetadata.ReferralAdminService.attachReferrer=ACL_ALLOW
|
org.alfresco.module.org_alfresco_module_rm.referredmetadata.ReferralAdminService.attachReferrer=ACL_ALLOW
|
||||||
org.alfresco.module.org_alfresco_module_rm.referredmetadata.ReferralAdminService.detachReferrer=ACL_ALLOW
|
org.alfresco.module.org_alfresco_module_rm.referredmetadata.ReferralAdminService.detachReferrer=ACL_ALLOW
|
||||||
org.alfresco.module.org_alfresco_module_rm.referredmetadata.ReferralAdminService.getDefinedReferrals=ACL_ALLOW
|
|
||||||
org.alfresco.module.org_alfresco_module_rm.referredmetadata.ReferralAdminService.getReferralFor=ACL_ALLOW
|
|
||||||
org.alfresco.module.org_alfresco_module_rm.referredmetadata.ReferralAdminService.getAttachedReferralsFrom=ACL_ALLOW
|
org.alfresco.module.org_alfresco_module_rm.referredmetadata.ReferralAdminService.getAttachedReferralsFrom=ACL_ALLOW
|
||||||
|
org.alfresco.module.org_alfresco_module_rm.referredmetadata.ReferralAdminService.getAttachedReferralFrom=ACL_ALLOW
|
||||||
org.alfresco.module.org_alfresco_module_rm.referredmetadata.ReferralAdminService.*=ACL_DENY
|
org.alfresco.module.org_alfresco_module_rm.referredmetadata.ReferralAdminService.*=ACL_DENY
|
||||||
</value>
|
</value>
|
||||||
</property>
|
</property>
|
||||||
|
@@ -85,7 +85,7 @@ public class ClassifiedRenditions extends BaseBehaviourBean
|
|||||||
if (contentClassificationService.isClassified(sourceNode) &&
|
if (contentClassificationService.isClassified(sourceNode) &&
|
||||||
referralAdminService.getAttachedReferralFrom(renditionNodeRef, ASPECT_CLASSIFIED) != null)
|
referralAdminService.getAttachedReferralFrom(renditionNodeRef, ASPECT_CLASSIFIED) != null)
|
||||||
{
|
{
|
||||||
referralAdminService.attachReferrer(renditionNodeRef, sourceNode, ASSOC_CLASSIFIED_RENDITION);
|
referralAdminService.attachReferrer(renditionNodeRef, sourceNode, ASPECT_CLASSIFIED);
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
|
@@ -148,9 +148,9 @@ public class ClassifiedAspect extends BaseBehaviourBean implements NodeServicePo
|
|||||||
for (ChildAssociationRef chAssRef : renditions)
|
for (ChildAssociationRef chAssRef : renditions)
|
||||||
{
|
{
|
||||||
final NodeRef renditionNode = chAssRef.getChildRef();
|
final NodeRef renditionNode = chAssRef.getChildRef();
|
||||||
if (referralAdminService.getAttachedReferralFrom(renditionNode, ASPECT_CLASSIFIED_RENDITION) == null)
|
if (referralAdminService.getAttachedReferralFrom(renditionNode, ASPECT_CLASSIFIED) == null)
|
||||||
{
|
{
|
||||||
referralAdminService.attachReferrer(renditionNode, classifiedNode, ASSOC_CLASSIFIED_RENDITION);
|
referralAdminService.attachReferrer(renditionNode, classifiedNode, ASPECT_CLASSIFIED);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -32,7 +32,8 @@ import java.util.Set;
|
|||||||
* Then any read request for relevant metadata such as hasAspect or getProperties can be delegated to the
|
* Then any read request for relevant metadata such as hasAspect or getProperties can be delegated to the
|
||||||
* linked node.
|
* linked node.
|
||||||
* <p/>
|
* <p/>
|
||||||
* For a link to be made, there must be a {@link #getDefinedReferrals() defined MetadataReferral} already in the system.
|
* For a link to be made, there must be a {@link ReferralRegistry#getMetadataReferrals()} defined MetadataReferral}
|
||||||
|
* already in the system.
|
||||||
* This means that a peer-association type will have to have been declared and that a spring bean will have to have
|
* This means that a peer-association type will have to have been declared and that a spring bean will have to have
|
||||||
* defined which aspects are to be handled by this {@link MetadataReferral}.
|
* defined which aspects are to be handled by this {@link MetadataReferral}.
|
||||||
*
|
*
|
||||||
@@ -45,41 +46,30 @@ public interface ReferralAdminService
|
|||||||
* Creates a link between two nodes such that the first {@code referrer} can 'inherit' or reuse some aspect
|
* Creates a link between two nodes such that the first {@code referrer} can 'inherit' or reuse some aspect
|
||||||
* metadata from another node - the {@code referrer}.
|
* metadata from another node - the {@code referrer}.
|
||||||
* <p/>
|
* <p/>
|
||||||
|
* Note that attaching a referrer for the specified aspect will also link the two nodes for
|
||||||
|
* all aspects defined in the {@link MetadataReferral}.
|
||||||
|
* <p/>
|
||||||
* Note that links can currently only extend between two pairs of nodes and cannot be chained.
|
* Note that links can currently only extend between two pairs of nodes and cannot be chained.
|
||||||
*
|
*
|
||||||
* @param referrer the node which is to inherit additional metadata.
|
* @param referrer the node which is to inherit additional metadata.
|
||||||
* @param referent the node which will provide the additional metadata.
|
* @param referent the node which will provide the additional metadata.
|
||||||
* @param assocType the type of the peer association which will link the two nodes.
|
* @param aspectName the name of the aspect whose metadata is to be attached.
|
||||||
* @return a {@link MetadataReferral} object which defines the link type.
|
* @return a {@link MetadataReferral} object which defines the link type.
|
||||||
* @throws ChainedMetadataReferralUnsupported if an attempt is made to attach nodes such that a chain would be made.
|
* @throws ChainedMetadataReferralUnsupported if an attempt is made to attach nodes such that a chain would be made.
|
||||||
*/
|
*/
|
||||||
// FIXME Remove assocType entirely from the API
|
MetadataReferral attachReferrer(NodeRef referrer, NodeRef referent, QName aspectName);
|
||||||
MetadataReferral attachReferrer(NodeRef referrer, NodeRef referent, QName assocType);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Removes an existing metadata link between two nodes.
|
* Removes an existing metadata link between two nodes.
|
||||||
|
* <p/>
|
||||||
|
* Note that detaching a referrer for the specified aspect will also unlink the two nodes for
|
||||||
|
* all aspects defined in the {@link MetadataReferral}.
|
||||||
*
|
*
|
||||||
* @param referrer the node which has been linked to a metadata source.
|
* @param referrer the node which has been linked to a metadata source.
|
||||||
* @param assocType the type of the peer association forming the link.
|
* @param aspectName the name of the aspect whose metadata is to be detached.
|
||||||
* @return the removed {@link MetadataReferral}.
|
* @return the removed {@link MetadataReferral}.
|
||||||
*/
|
*/
|
||||||
MetadataReferral detachReferrer(NodeRef referrer, QName assocType);
|
MetadataReferral detachReferrer(NodeRef referrer, QName aspectName); // FIXME Chase all references
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the set of defined {@link MetadataReferral}s.
|
|
||||||
*
|
|
||||||
* @return the set of defined {@link MetadataReferral}.
|
|
||||||
*/
|
|
||||||
Set<MetadataReferral> getDefinedReferrals();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the {@link MetadataReferral} which contains the specified {@code aspectName} if there is one.
|
|
||||||
* Note that only one {@link MetadataReferral} may declare that it handles any particular aspect.
|
|
||||||
*
|
|
||||||
* @param aspectName the name of the aspect whose {@link MetadataReferral} is sought.
|
|
||||||
* @return the {@link MetadataReferral} which handles the specified aspect, if there is one.
|
|
||||||
*/
|
|
||||||
MetadataReferral getReferralFor(QName aspectName);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the set of {@link MetadataReferral}s which are currently applied from the specified {@code referrer}.
|
* Gets the set of {@link MetadataReferral}s which are currently applied from the specified {@code referrer}.
|
||||||
|
@@ -79,9 +79,15 @@ public class ReferralAdminServiceImpl implements ReferralAdminService
|
|||||||
this.registry = registry;
|
this.registry = registry;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override public MetadataReferral attachReferrer(NodeRef referrer, NodeRef referent, QName assocType)
|
@Override public MetadataReferral attachReferrer(NodeRef referrer, NodeRef referent, QName aspectName)
|
||||||
{
|
{
|
||||||
final MetadataReferral metadataReferral = getReferralForAssociation(assocType);
|
final MetadataReferral metadataReferral = registry.getReferralForAspect(aspectName);
|
||||||
|
if (metadataReferral == null)
|
||||||
|
{
|
||||||
|
throw new IllegalArgumentException("No defined " + MetadataReferral.class.getSimpleName() +
|
||||||
|
" for aspect " + aspectName);
|
||||||
|
}
|
||||||
|
final QName assocType = metadataReferral.getAssocType();
|
||||||
|
|
||||||
// Prevent the creation of chains of metadata linking from node A to B to C.
|
// Prevent the creation of chains of metadata linking from node A to B to C.
|
||||||
|
|
||||||
@@ -135,8 +141,11 @@ public class ReferralAdminServiceImpl implements ReferralAdminService
|
|||||||
return metadataReferral;
|
return metadataReferral;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override public MetadataReferral detachReferrer(NodeRef referrer, QName assocType)
|
@Override public MetadataReferral detachReferrer(NodeRef referrer, QName aspectName)
|
||||||
{
|
{
|
||||||
|
final MetadataReferral referral = registry.getReferralForAspect(aspectName);
|
||||||
|
final QName assocType = referral.getAssocType();
|
||||||
|
|
||||||
// Is the association there?
|
// Is the association there?
|
||||||
final List<AssociationRef> assocs = nodeService.getTargetAssocs(referrer, assocType);
|
final List<AssociationRef> assocs = nodeService.getTargetAssocs(referrer, assocType);
|
||||||
|
|
||||||
@@ -146,36 +155,19 @@ public class ReferralAdminServiceImpl implements ReferralAdminService
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
MetadataReferral result = getReferralForAssociation(assocType);
|
|
||||||
|
|
||||||
// There should only be one such association... but we'll remove them all just in case
|
// There should only be one such association... but we'll remove them all just in case
|
||||||
for (AssociationRef assocRef : assocs)
|
for (AssociationRef assocRef : assocs)
|
||||||
{
|
{
|
||||||
nodeService.removeAssociation(referrer, assocRef.getTargetRef(), assocType);
|
nodeService.removeAssociation(referrer, assocRef.getTargetRef(), assocType);
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return referral;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override public MetadataReferral getReferralFor(QName aspectName)
|
|
||||||
{
|
|
||||||
MetadataReferral metadataReferral = null;
|
|
||||||
|
|
||||||
for (MetadataReferral d : getDefinedReferrals())
|
|
||||||
{
|
|
||||||
if (d.getAspects().contains(aspectName))
|
|
||||||
{
|
|
||||||
metadataReferral = d;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return metadataReferral;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override public Set<MetadataReferral> getAttachedReferralsFrom(NodeRef referrer)
|
@Override public Set<MetadataReferral> getAttachedReferralsFrom(NodeRef referrer)
|
||||||
{
|
{
|
||||||
final Set<MetadataReferral> allMetadataReferrals = getDefinedReferrals();
|
final Set<MetadataReferral> allMetadataReferrals = registry.getMetadataReferrals();
|
||||||
|
|
||||||
final Set<MetadataReferral> result = new HashSet<>();
|
final Set<MetadataReferral> result = new HashSet<>();
|
||||||
for (MetadataReferral d : allMetadataReferrals)
|
for (MetadataReferral d : allMetadataReferrals)
|
||||||
@@ -200,9 +192,4 @@ public class ReferralAdminServiceImpl implements ReferralAdminService
|
|||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override public Set<MetadataReferral> getDefinedReferrals()
|
|
||||||
{
|
|
||||||
return registry.getMetadataReferrals();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@@ -29,8 +29,8 @@ import java.io.Serializable;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This service provides read-only access to linked metadata.
|
* This service provides read-only access to linked metadata. It is primarily concerned with data transfer.
|
||||||
* TODO complete! Include definition of referent etc or link to package.html
|
* For an overview, see the package javadoc.
|
||||||
*
|
*
|
||||||
* @author Neil Mc Erlean
|
* @author Neil Mc Erlean
|
||||||
* @since 2.4.a
|
* @since 2.4.a
|
||||||
|
@@ -142,7 +142,7 @@ public class ClassifiedAspectUnitTest implements ClassifiedContentModel
|
|||||||
|
|
||||||
for (NodeRef rendition : asList(RENDITION_1, RENDITION_2))
|
for (NodeRef rendition : asList(RENDITION_1, RENDITION_2))
|
||||||
{
|
{
|
||||||
verify(mockReferralAdminService).attachReferrer(rendition, NODE_REF, ASSOC_CLASSIFIED_RENDITION);
|
verify(mockReferralAdminService).attachReferrer(rendition, NODE_REF, ASPECT_CLASSIFIED);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -84,17 +84,17 @@ public class ReferralAdminServiceImplUnitTest
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected=IllegalArgumentException.class)
|
@Test(expected=IllegalArgumentException.class)
|
||||||
public void attachingReferrerWithNoAssociationConfiguredShouldFail()
|
public void attachingReferrerWithNoAspectConfiguredShouldFail()
|
||||||
{
|
{
|
||||||
referralAdminService.attachReferrer(node2, node1, assoc1);
|
referralAdminService.attachReferrer(node2, node1, aspect1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test public void attachDetach()
|
@Test public void attachDetach()
|
||||||
{
|
{
|
||||||
when(mockRegistry.getReferralForAssociation(assoc1)).thenReturn(referral1);
|
when(mockRegistry.getReferralForAspect(aspect1)).thenReturn(referral1);
|
||||||
|
|
||||||
// attach
|
// attach
|
||||||
MetadataReferral d = attachReferrer(node1, node2, assoc1);
|
MetadataReferral d = attachReferrer(node1, node2, aspect1);
|
||||||
|
|
||||||
// validate
|
// validate
|
||||||
assertEquals(assoc1, d.getAssocType());
|
assertEquals(assoc1, d.getAssocType());
|
||||||
@@ -103,24 +103,25 @@ public class ReferralAdminServiceImplUnitTest
|
|||||||
assertFalse(mockReferredMetadataService.isReferringMetadata(node1, aspect3));
|
assertFalse(mockReferredMetadataService.isReferringMetadata(node1, aspect3));
|
||||||
|
|
||||||
// detach
|
// detach
|
||||||
assertEquals(d, referralAdminService.detachReferrer(node1, assoc1));
|
assertEquals(d, referralAdminService.detachReferrer(node1, aspect1));
|
||||||
}
|
}
|
||||||
|
|
||||||
private MetadataReferral attachReferrer(NodeRef referrer, NodeRef referent, QName assocType)
|
private MetadataReferral attachReferrer(NodeRef referrer, NodeRef referent, QName aspectName)
|
||||||
{
|
{
|
||||||
MetadataReferral d = referralAdminService.attachReferrer(referrer, referent, assocType);
|
MetadataReferral mr = referralAdminService.attachReferrer(referrer, referent, aspectName);
|
||||||
|
final QName assocType = mr.getAssocType();
|
||||||
when(mockNodeService.getSourceAssocs(referent, assocType)).thenReturn(asList(new AssociationRef(referrer, assocType, referent)));
|
when(mockNodeService.getSourceAssocs(referent, assocType)).thenReturn(asList(new AssociationRef(referrer, assocType, referent)));
|
||||||
when(mockNodeService.getTargetAssocs(referrer, assocType)).thenReturn(asList(new AssociationRef(referrer, assocType, referent)));
|
when(mockNodeService.getTargetAssocs(referrer, assocType)).thenReturn(asList(new AssociationRef(referrer, assocType, referent)));
|
||||||
for (QName aspect : d.getAspects())
|
for (QName aspect : mr.getAspects())
|
||||||
{
|
{
|
||||||
when(mockReferredMetadataService.isReferringMetadata(referrer, aspect)).thenReturn(true);
|
when(mockReferredMetadataService.isReferringMetadata(referrer, aspect)).thenReturn(true);
|
||||||
}
|
}
|
||||||
return d;
|
return mr;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test public void chainsOfDelegationShouldBePrevented()
|
@Test public void chainsOfDelegationShouldBePrevented()
|
||||||
{
|
{
|
||||||
when(mockRegistry.getReferralForAssociation(assoc1)).thenReturn(referral1);
|
when(mockRegistry.getReferralForAspect(aspect1)).thenReturn(referral1);
|
||||||
|
|
||||||
// The node already has a delegation in place: node1 -> node2. We're trying to add to the
|
// The node already has a delegation in place: node1 -> node2. We're trying to add to the
|
||||||
// end of the chain: node2 -> node3
|
// end of the chain: node2 -> node3
|
||||||
@@ -128,13 +129,13 @@ public class ReferralAdminServiceImplUnitTest
|
|||||||
when(mockNodeService.getTargetAssocs(node1, assoc1)).thenReturn(asList(new AssociationRef(node1, assoc1, node2)));
|
when(mockNodeService.getTargetAssocs(node1, assoc1)).thenReturn(asList(new AssociationRef(node1, assoc1, node2)));
|
||||||
|
|
||||||
expectedException(ChainedMetadataReferralUnsupported.class, () -> {
|
expectedException(ChainedMetadataReferralUnsupported.class, () -> {
|
||||||
referralAdminService.attachReferrer(node2, node3, assoc1);
|
referralAdminService.attachReferrer(node2, node3, aspect1);
|
||||||
return null;
|
return null;
|
||||||
});
|
});
|
||||||
|
|
||||||
// Now try to add to the start of the chain: node3 -> node1
|
// Now try to add to the start of the chain: node3 -> node1
|
||||||
expectedException(ChainedMetadataReferralUnsupported.class, () -> {
|
expectedException(ChainedMetadataReferralUnsupported.class, () -> {
|
||||||
referralAdminService.attachReferrer(node3, node1, assoc1);
|
referralAdminService.attachReferrer(node3, node1, aspect1);
|
||||||
return null;
|
return null;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user