06-13-2017 01:05 PM
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 cmerson 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.
06-14-2017 08:04 AM
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();
06-13-2017 02:37 PM
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)
06-14-2017 02:54 AM
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?
06-14-2017 08:04 AM
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();
Explore our Alfresco products with the links below. Use labels to filter content by product module.