1 package org.collectionspace.hello.services;
3 import org.collectionspace.hello.services.nuxeo.NuxeoRESTClient;
4 import java.util.ArrayList;
5 import java.util.Arrays;
6 import java.util.HashMap;
7 import java.util.Iterator;
9 import javax.ws.rs.Consumes;
10 import javax.ws.rs.GET;
11 import javax.ws.rs.Path;
12 import javax.ws.rs.Produces;
14 import javax.ws.rs.core.Context;
15 import javax.ws.rs.core.UriInfo;
16 import org.collectionspace.hello.*;
19 import org.collectionspace.hello.People.PeopleItem;
20 import org.dom4j.Document;
21 import org.dom4j.Element;
22 import org.dom4j.io.SAXReader;
23 import org.restlet.resource.Representation;
24 import org.slf4j.Logger;
25 import org.slf4j.LoggerFactory;
28 @Consumes("application/xml")
29 @Produces("application/xml")
30 public class PersonDocResource {
32 final Logger logger = LoggerFactory.getLogger(PersonDocResource.class);
34 public PersonDocResource() {
38 public People getPeople(@Context UriInfo ui) {
39 People p = new People();
41 List<People.PeopleItem> list = p.getPeopleItem();
42 NuxeoRESTClient nxClient = getClient();
44 List<String> pathParams = new ArrayList<String>();
45 Map<String, String> queryParams = new HashMap<String, String>();
46 //browse default repository for People
47 //For sanjay, People repository id is f084243e-4b81-42a1-9a05-518e974facbd
48 pathParams = Arrays.asList("default", "f084243e-4b81-42a1-9a05-518e974facbd", "browse");
49 Representation res = nxClient.get(pathParams, queryParams);
50 SAXReader reader = new SAXReader();
51 Document document = reader.read(res.getStream());
52 Element root = document.getRootElement();
53 for (Iterator i = root.elementIterator(); i.hasNext();) {
54 Element element = (Element) i.next();
55 PeopleItem pli = new PeopleItem();
56 pli.setTitle(element.attributeValue("title"));
57 pli.setUri(element.attributeValue("url"));
58 pli.setId(element.attributeValue("id"));
62 } catch (Exception e) {
69 // private void getQueryModel() throws IOException {
70 // NuxeoRESTClient nxClient = getClient();
72 // List<String> pathParams = new ArrayList<String>();
73 // Map<String, String> queryParams = new HashMap<String, String>();
75 // //query model for user documents
76 // pathParams = Arrays.asList("execQueryModel", "USER_DOCUMENTS");
77 // queryParams.put("QP1", "Administrator");
78 // queryParams.put("format", "XML");
81 // Representation res = nxClient.get(pathParams, queryParams);
82 // String resStr = res.getText();
83 // verbose("getQueryModel:" + resStr);
87 // private void getVocabulary() throws IOException {
88 // NuxeoRESTClient nxClient = getClient();
90 // List<String> pathParams = new ArrayList<String>();
91 // Map<String, String> queryParams = new HashMap<String, String>();
93 // pathParams = Arrays.asList("vocabulary", "continent_country");
94 // queryParams.put("lang", "en");
96 // Representation res = nxClient.get(pathParams, queryParams);
97 // String resStr = res.getText();
98 // verbose("getVocabulary:" + resStr);
101 private NuxeoRESTClient getClient() {
102 NuxeoRESTClient nxClient = new NuxeoRESTClient("http://127.0.0.1:8080/nuxeo");
103 nxClient.setAuthType(NuxeoRESTClient.AUTH_TYPE_BASIC);
104 nxClient.setBasicAuthentication("Administrator", "Administrator");
108 private void verbose(String msg) {
109 System.out.println("PersonDocResource: " + msg);