1 package org.argeo.people.ui.exports;
2
3 import static org.argeo.eclipse.ui.EclipseUiUtils.notEmpty;
4
5 import javax.jcr.Node;
6 import javax.jcr.RepositoryException;
7
8 import org.argeo.connect.util.ConnectJcrUtils;
9 import org.argeo.eclipse.ui.EclipseUiUtils;
10 import org.argeo.eclipse.ui.jcr.lists.SimpleJcrNodeLabelProvider;
11 import org.argeo.people.PeopleException;
12 import org.argeo.people.PeopleNames;
13 import org.argeo.people.PeopleService;
14 import org.argeo.people.PeopleTypes;
15 import org.argeo.people.util.PeopleJcrUtils;
16
17
18 public class PrimAddressLP extends SimpleJcrNodeLabelProvider {
19 private static final long serialVersionUID = 1L;
20
21 private String selectorName;
22 private String propertyName;
23 private PeopleService peopleService;
24
25 public PrimAddressLP(PeopleService peopleService, String selectorName, String propertyName) {
26 super(propertyName);
27 this.peopleService = peopleService;
28 if (notEmpty(selectorName))
29 this.selectorName = selectorName;
30 this.propertyName = propertyName;
31 }
32
33 @Override
34 public String getText(Object element) {
35 try {
36 Node currNode = ConnectJcrUtils.getNodeFromElement(element, selectorName);
37 Node currContact = PeopleJcrUtils.getPrimaryContact(currNode, PeopleTypes.PEOPLE_POSTAL_ADDRESS);
38
39
40 if (currContact == null)
41 return "";
42
43
44
45 if (currContact.isNodeType(PeopleTypes.PEOPLE_CONTACT_REF)) {
46 String refUid = ConnectJcrUtils.get(currContact, PeopleNames.PEOPLE_REF_UID);
47 if (EclipseUiUtils.isEmpty(refUid)) {
48
49
50
51
52
53
54
55 return "";
56 }
57 Node referencedEntity = peopleService.getEntityByUid(ConnectJcrUtils.getSession(currContact), null,
58 refUid);
59 if (referencedEntity == null)
60 return "";
61 Node referencedContact = PeopleJcrUtils.getPrimaryContact(referencedEntity,
62 PeopleTypes.PEOPLE_POSTAL_ADDRESS);
63 if (referencedContact == null)
64 return "";
65 else
66 currContact = referencedContact;
67 }
68 return ConnectJcrUtils.get(currContact, propertyName);
69 } catch (RepositoryException re) {
70 throw new PeopleException("Unable to get text from row " + element, re);
71 }
72 }
73 }