Skip to content

Instantly share code, notes, and snippets.

@skuro
Created April 9, 2013 15:14
Show Gist options
  • Save skuro/5346541 to your computer and use it in GitHub Desktop.
Save skuro/5346541 to your computer and use it in GitHub Desktop.
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\\}.*");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment