How to get value of aspect association?

cancel
Showing results for 
Search instead for 
Did you mean: 
pnature
Established Member

How to get value of aspect association?

Jump to solution

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 Solution

Accepted Solutions
pnature
Established Member

Re: How to get value of aspect association?

Jump to solution

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 solution in original post

3 Replies
jpotts
Professional

Re: How to get value of aspect association?

Jump to solution

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
Established Member

Re: How to get value of aspect association?

Jump to solution

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
Established Member

Re: How to get value of aspect association?

Jump to solution

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();