Various methods using Alfresco's RegexQNamePattern to get associations using:
- RegexQnamePattern.MATCH_ALL to get all associations
- Getting associations by name without a namespace
- Getting all associations in a particular namespace
private static List<String> ASSOC_NAMES_TO_EXTRACT = Arrays.asList(new String[]{"imageRef","thumbnailRef"}); | |
/** | |
* Gets a list of associations of type my:imageRef and my:thumbnailRef, given an Alfresco node; | |
* Implementation is not optimal | |
* @param nodeRef The Alfresco NodeRef that contains the associations we want to extract | |
* @return a List of associations of type my:imageRef and my:thumbnailRef | |
*/ | |
public List<AssociationRef> getAssociations(NodeRef nodeRef) { | |
List<AssociationRef> associations = serviceRegistry.getNodeService().getTargetAssocs(nodeRef, RegexQNamePattern.MATCH_ALL); | |
List<AssociationRef> toReturn = new ArrayList<AssociationRef>(); | |
// extract only my:imageRef and my:thumbnailRef assocs | |
for(AssociationRef association : associations) { | |
QName assocQname = association.getTypeQName(); | |
if (ASSOC_NAMES_TO_EXTRACT.contains(assocQname.getLocalName())) { | |
toReturn.add(association); | |
} | |
} | |
return toReturn; | |
} |
private static final RegexQNamePattern IMAGE_ASSOCIATIONS = new RegexQNamePattern( | |
".*thumbnailRef$|.*imageRef$"); | |
/** | |
* Gets a list of associations of type my:imageRef and my:thumbnailRef, given an Alfresco node; | |
* @param nodeRef The Alfresco NodeRef that contains the associations we want to extract | |
* @return a List of associations of type my:imageRef and my:thumbnailRef | |
*/ | |
public List<AssociationRef> getAssociations(NodeRef nodeRef) { | |
return serviceRegistry.getNodeService().getTargetAssocs(nodeRef, IMAGE_ASSOCIATIONS); | |
} |
/** | |
* I am assuming that your custom Alfresco contentModel defines the following namespace | |
* <namespace uri="http:/session.it/alfresco/model/content/1.0" prefix="my"/> | |
*/ | |
static final RegexQNamePattern ALL_MY_ASSOCIATIONS = | |
new RegexQNamePattern("^\\{http:\\/session.it\\/alfresco\\/model\\/content\\/1.0\\}.*"); |
Various methods using Alfresco's RegexQNamePattern to get associations using: