cancel
Showing results for 
Search instead for 
Did you mean: 

get all Child associations with a specific Association Type

nicola_peluchet
Champ in-the-making
Champ in-the-making
Hi,

i'm a total newbie to java and Alfresco and i have this simple problem: i need to get all child Associations of a noderef with Association Type = "risposteAssociate". In Javascript i do something like:

var risposte = node.childAssocs["crl:risposteAssociate"];

In Java i have to do something like:

List<ChildAssociationRef> risposteAssociate = nodeService.getChildAssocs(node,….);

I just don't know how to specify the association type!

Then i must get the value of a property of the child associations. I have to do something like
for (ChildAssociationRef childAssocRef : risposteAssociate) {
       // do something with each document in the workflow package
       NodeRef risposta = childAssocRef.getChildRef();
       String dataRisposta = nodeService.getProperty(risposta , arg1)
}

Where arg1 is the qname of the property…in that case should i use something like "crl:data_risposta" or something like {http://www.somesite.it/model/atti/1.0}data_risposta"?

Thanx in advance
3 REPLIES 3

openpj
Elite Collaborator
Elite Collaborator
Try to use the following code:

String CRL_MODEL_URI = "TheModelURIThatYouHaveInYourCustomModel";
QName ASSOC_NAME_RISPOSTE_ASSOCIATE = QName.createQName(CRL_MODEL_URI, "risposteAssociate");
List<ChildAssociationRef> risposteAssociate = nodeService.getChildAssocs(node, RegexQNamePattern.MATCH_ALL, ASSOC_NAME_RISPOSTE_ASSOCIATE);
Hope this helps.

isloat
Champ in-the-making
Champ in-the-making
I'll do the following:
List<ChildAssociationRef> nodes = nodeService.getChildAssocs(node);
List<ChildAssociationRef> risposteAssociate = new List<ChildAssociationRef>();
for (ChildAssociationRef element : nodes) {
   if ("risposteAssociate".equalsIgnoreCase(element.getTypeQName().toString())) {
      risposteAssociate.add(element);
   }
}
But the OpenPj solution is smarter

timharder
Champ in-the-making
Champ in-the-making
Hi, you can also use the DBNodeService:

List<ChildAssociationRef> childAssocs = dbNodeService.getChildAssocs(someNodeRef, new HashSet<QName>(Arrays.asList(someTypeQName1, someTypeQName2,…));

Here you can directly search by type.

Regards