]> git.aero2k.de Git - tmp/jakarta-migration.git/blob
ecad94865486385df4529a1121ecdc29ba0b28ea
[tmp/jakarta-migration.git] /
1 package org.collectionspace.hello.services;
2
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;
8 import java.util.List;
9 import javax.ws.rs.Consumes;
10 import javax.ws.rs.GET;
11 import javax.ws.rs.Path;
12 import javax.ws.rs.Produces;
13 import java.util.Map;
14 import javax.ws.rs.core.Context;
15 import javax.ws.rs.core.UriInfo;
16 import org.collectionspace.hello.*;
17
18
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;
26
27 @Path("/persons")
28 @Consumes("application/xml")
29 @Produces("application/xml")
30 public class PersonDocResource {
31
32     final Logger logger = LoggerFactory.getLogger(PersonDocResource.class);
33
34     public PersonDocResource() {
35     }
36
37     @GET
38     public People getPeople(@Context UriInfo ui) {
39         People p = new People();
40         try {
41             List<People.PeopleItem> list = p.getPeopleItem();
42             NuxeoRESTClient nxClient = getClient();
43
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"));
59                 list.add(pli);
60             }
61
62         } catch (Exception e) {
63             e.printStackTrace();
64         }
65         return p;
66     }
67
68
69 //    private void getQueryModel() throws IOException {
70 //        NuxeoRESTClient nxClient = getClient();
71 //
72 //        List<String> pathParams = new ArrayList<String>();
73 //        Map<String, String> queryParams = new HashMap<String, String>();
74 //
75 //        //query model for user documents
76 //        pathParams = Arrays.asList("execQueryModel", "USER_DOCUMENTS");
77 //        queryParams.put("QP1", "Administrator");
78 //        queryParams.put("format", "XML");
79 //
80 //
81 //        Representation res = nxClient.get(pathParams, queryParams);
82 //        String resStr = res.getText();
83 //        verbose("getQueryModel:" + resStr);
84 //
85 //    }
86 //
87 //    private void getVocabulary() throws IOException {
88 //        NuxeoRESTClient nxClient = getClient();
89 //
90 //        List<String> pathParams = new ArrayList<String>();
91 //        Map<String, String> queryParams = new HashMap<String, String>();
92 //        //get vocabulary
93 //        pathParams = Arrays.asList("vocabulary", "continent_country");
94 //        queryParams.put("lang", "en");
95 //
96 //        Representation res = nxClient.get(pathParams, queryParams);
97 //        String resStr = res.getText();
98 //        verbose("getVocabulary:" + resStr);
99 //
100 //    }
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");
105         return nxClient;
106     }
107
108     private void verbose(String msg) {
109         System.out.println("PersonDocResource: " + msg);
110     }
111 }