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:
Neil McErlean
2015-09-09 10:42:29 +00:00
parent 3efb64f11b
commit aeafa9fbbd
8 changed files with 46 additions and 69 deletions

View File

@@ -85,7 +85,7 @@ public class ClassifiedRenditions extends BaseBehaviourBean
if (contentClassificationService.isClassified(sourceNode) &&
referralAdminService.getAttachedReferralFrom(renditionNodeRef, ASPECT_CLASSIFIED) != null)
{
referralAdminService.attachReferrer(renditionNodeRef, sourceNode, ASSOC_CLASSIFIED_RENDITION);
referralAdminService.attachReferrer(renditionNodeRef, sourceNode, ASPECT_CLASSIFIED);
}
return null;

View File

@@ -148,9 +148,9 @@ public class ClassifiedAspect extends BaseBehaviourBean implements NodeServicePo
for (ChildAssociationRef chAssRef : renditions)
{
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);
}
}

View File

@@ -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
* linked node.
* <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
* 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
* metadata from another node - the {@code referrer}.
* <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.
*
* @param referrer the node which is to inherit 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.
* @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 assocType);
MetadataReferral attachReferrer(NodeRef referrer, NodeRef referent, QName aspectName);
/**
* 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 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}.
*/
MetadataReferral detachReferrer(NodeRef referrer, QName assocType);
/**
* 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);
MetadataReferral detachReferrer(NodeRef referrer, QName aspectName); // FIXME Chase all references
/**
* Gets the set of {@link MetadataReferral}s which are currently applied from the specified {@code referrer}.

View File

@@ -79,9 +79,15 @@ public class ReferralAdminServiceImpl implements ReferralAdminService
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.
@@ -135,8 +141,11 @@ public class ReferralAdminServiceImpl implements ReferralAdminService
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?
final List<AssociationRef> assocs = nodeService.getTargetAssocs(referrer, assocType);
@@ -146,36 +155,19 @@ public class ReferralAdminServiceImpl implements ReferralAdminService
}
else
{
MetadataReferral result = getReferralForAssociation(assocType);
// There should only be one such association... but we'll remove them all just in case
for (AssociationRef assocRef : assocs)
{
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)
{
final Set<MetadataReferral> allMetadataReferrals = getDefinedReferrals();
final Set<MetadataReferral> allMetadataReferrals = registry.getMetadataReferrals();
final Set<MetadataReferral> result = new HashSet<>();
for (MetadataReferral d : allMetadataReferrals)
@@ -200,9 +192,4 @@ public class ReferralAdminServiceImpl implements ReferralAdminService
}
return null;
}
@Override public Set<MetadataReferral> getDefinedReferrals()
{
return registry.getMetadataReferrals();
}
}

View File

@@ -29,8 +29,8 @@ import java.io.Serializable;
import java.util.Map;
/**
* This service provides read-only access to linked metadata.
* TODO complete! Include definition of referent etc or link to package.html
* This service provides read-only access to linked metadata. It is primarily concerned with data transfer.
* For an overview, see the package javadoc.
*
* @author Neil Mc Erlean
* @since 2.4.a