cancel
Showing results for 
Search instead for 
Did you mean: 

How to get value of aspect association?

pnature
Star Contributor
Star Contributor

Hi

I am trying to get values of aspect association in alfresco bpmn workflow java task service but I have no luck.

When I have aspect only with string properties I have no problem to get values of aspect properties.

I have changed some properties to associations cmSmiley Tongueerson because I need select people from list and not to write them in form as strings.

I get values like this:

Map<QName,Serializable> docProperties = nodeService.getProperties(docref);
QName a = QName.createQName(namespace, varName);
Serializable personSer = docProperties.get(a);
username = personSer.toString();

This piece of java code list aspect's definition but only properties are listed.

Map<QName, PropertyDefinition> aspectPropDefs = dictionaryService.getAspect(aspectQname).getProperties();
for (QName propQName : aspectPropDefs.keySet())
{
   PropertyDefinition value = aspectPropDefs.get(propQName);
   if (value != null) {
      logger.debug("aspectProperty.key " + propQName.toString() + " = " + value); //nodeProps.containsKey(propQName)
   }
}


Please how to get values of aspect associations using java?
Thanks in advance.

1 ACCEPTED ANSWER

pnature
Star Contributor
Star Contributor

Now I have got it.

List<AssociationRef> tar = nodeService.getTargetAssocs(docref, QName.createQName(myNamespace, varName));
AssociationRef ar = tar.get(0);
Map<QName,Serializable> arProperties = nodeService.getProperties(ar.getTargetRef());
private static final String cmNamespace = "http://www.alfresco.org/model/content/1.0";
String username = arProperties.get(QName.createQName(cmNamespace, "userName")).toString();

View answer in original post

3 REPLIES 3

jpotts
World-Class Innovator
World-Class Innovator

The NodeService can retrieve the peer associations (getSourceAssociations, getTargetAssociations) and the child associations (getChildAssociations) for a given node:

NodeService (Alfresco 5.1.3 Public Java API) 

Or, if you are looking for a list of the associations defined for a type (not a node's actual associations) you can ask the DictionaryService by using getAllAssociations: DictionaryService (Alfresco 5.1.3 Public Java API) 

pnature
Star Contributor
Star Contributor

Thank you for reply. I am interested in values.

QNamePattern matchAll=RegexQNamePattern.MATCH_ALL;
List<AssociationRef> tar = nodeService.getTargetAssocs(docref, matchAll);
logger.debug("TargetAssociationRef size= " + tar.size());
Iterator<AssociationRef> li = tar.iterator();
while (li.hasNext()) {
   AssociationRef ar = li.next();
   logger.debug("AssociationRef " + ar.getTypeQName());// + " src " + ar.getSourceRef() + " > " + ar.getTargetRef());
}

I can get associations this way but I don't know how to get values.

Can you give me snippet of code as an example?

pnature
Star Contributor
Star Contributor

Now I have got it.

List<AssociationRef> tar = nodeService.getTargetAssocs(docref, QName.createQName(myNamespace, varName));
AssociationRef ar = tar.get(0);
Map<QName,Serializable> arProperties = nodeService.getProperties(ar.getTargetRef());
private static final String cmNamespace = "http://www.alfresco.org/model/content/1.0";
String username = arProperties.get(QName.createQName(cmNamespace, "userName")).toString();