Mercurial > hg > AnnotationManagerN4J
annotate src/main/java/de/mpiwg/itgroup/annotations/restlet/annotations_ui/PersonsResource.java @ 50:64aa756c60cc
annotations ui can show and delete annotations now.
author | casties |
---|---|
date | Thu, 27 Sep 2012 17:12:08 +0200 |
parents | 707902d468f6 |
children | c0dd5314bada |
rev | line source |
---|---|
32
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
diff
changeset
|
1 /** |
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
diff
changeset
|
2 * |
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
diff
changeset
|
3 */ |
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
diff
changeset
|
4 package de.mpiwg.itgroup.annotations.restlet.annotations_ui; |
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
diff
changeset
|
5 |
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
diff
changeset
|
6 import java.util.List; |
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
diff
changeset
|
7 |
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
diff
changeset
|
8 import org.apache.log4j.Logger; |
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
diff
changeset
|
9 import org.restlet.data.Form; |
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
diff
changeset
|
10 import org.restlet.data.MediaType; |
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
diff
changeset
|
11 import org.restlet.data.Reference; |
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
diff
changeset
|
12 import org.restlet.data.Status; |
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
diff
changeset
|
13 import org.restlet.representation.Representation; |
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
diff
changeset
|
14 import org.restlet.representation.StringRepresentation; |
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
diff
changeset
|
15 import org.restlet.resource.Get; |
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
diff
changeset
|
16 import org.restlet.resource.Post; |
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
diff
changeset
|
17 import org.restlet.resource.ResourceException; |
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
diff
changeset
|
18 import org.restlet.resource.ServerResource; |
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
diff
changeset
|
19 |
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
diff
changeset
|
20 import de.mpiwg.itgroup.annotations.Actor; |
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
diff
changeset
|
21 import de.mpiwg.itgroup.annotations.Person; |
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
diff
changeset
|
22 import de.mpiwg.itgroup.annotations.neo4j.AnnotationStore; |
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
diff
changeset
|
23 import de.mpiwg.itgroup.annotations.restlet.BaseRestlet; |
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
diff
changeset
|
24 |
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
diff
changeset
|
25 /** |
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
diff
changeset
|
26 * Resource class for the list of annotation users (Person class). |
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
diff
changeset
|
27 * |
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
diff
changeset
|
28 * @author casties |
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
diff
changeset
|
29 * |
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
diff
changeset
|
30 */ |
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
diff
changeset
|
31 public class PersonsResource extends ServerResource { |
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
diff
changeset
|
32 |
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
diff
changeset
|
33 public static Logger logger = Logger.getLogger(PersonsResource.class); |
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
diff
changeset
|
34 |
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
diff
changeset
|
35 private AnnotationStore store; |
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
diff
changeset
|
36 |
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
diff
changeset
|
37 @Override |
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
diff
changeset
|
38 protected void doInit() throws ResourceException { |
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
diff
changeset
|
39 super.doInit(); |
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
diff
changeset
|
40 // get store instance |
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
diff
changeset
|
41 if (store == null) { |
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
diff
changeset
|
42 store = ((BaseRestlet) getApplication()).getAnnotationStore(); |
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
diff
changeset
|
43 } |
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
diff
changeset
|
44 } |
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
diff
changeset
|
45 |
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
diff
changeset
|
46 /** |
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
diff
changeset
|
47 * GET with HTML content type. Lists all persons. |
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
diff
changeset
|
48 * |
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
diff
changeset
|
49 * @param entity |
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
diff
changeset
|
50 * @return |
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
diff
changeset
|
51 */ |
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
diff
changeset
|
52 @Get("html") |
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
diff
changeset
|
53 public Representation doGetHTML(Representation entity) { |
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
diff
changeset
|
54 String result = null; |
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
diff
changeset
|
55 // get form parameter |
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
diff
changeset
|
56 Form f = this.getQuery(); |
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
diff
changeset
|
57 String form = f.getFirstValue("form"); |
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
diff
changeset
|
58 if (form != null && form.equals("new_person")) { |
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
diff
changeset
|
59 // output new group form |
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
diff
changeset
|
60 result = "<html><body>\n"; |
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
diff
changeset
|
61 result += "<h1>New person</h1>\n"; |
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
diff
changeset
|
62 result += String.format("<p><a href=\"%s\">All persons</a></p>", this.getReference()); |
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
diff
changeset
|
63 result += String.format("<form method=\"post\" action=\"%s\">\n", this.getReference().getHierarchicalPart()); |
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
diff
changeset
|
64 result += "<table>"; |
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
diff
changeset
|
65 result += "<tr><td><b>id</b></td><td><input type=\"text\" name=\"id\"/></td></tr>\n"; |
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
diff
changeset
|
66 result += "<tr><td><b>name</b></td><td><input type=\"text\" name=\"name\"/></td></tr>\n"; |
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
diff
changeset
|
67 result += "</table>\n"; |
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
diff
changeset
|
68 result += "<p><input type=\"submit\"/></p>\n"; |
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
diff
changeset
|
69 result += "</form>\n</body>\n</html>"; |
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
diff
changeset
|
70 } else { |
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
diff
changeset
|
71 // list all groups |
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
diff
changeset
|
72 result = "<html><body>\n<h1>Persons</h1>\n<table>"; |
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
diff
changeset
|
73 result += "<tr><th>id</th><th>name</th><th>uri</th></tr>"; |
45 | 74 List<Person> persons = store.getPersons("uri", "*"); |
75 for (Person person : persons) { | |
32
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
diff
changeset
|
76 Reference url = this.getReference().clone(); |
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
diff
changeset
|
77 url.addSegment(person.getId()); |
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
diff
changeset
|
78 result += String.format("<tr><td><a href=\"%s\">%s</a></td><td>%s</td><td>%s</td></tr>\n", url, |
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
diff
changeset
|
79 person.getIdString(), person.getName(), person.getUri()); |
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
diff
changeset
|
80 } |
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
diff
changeset
|
81 result += "</table>\n"; |
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
diff
changeset
|
82 result += "<p><a href=\"?form=new_person\">Add new person</a></p>\n"; |
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
diff
changeset
|
83 result += "</body>\n</html>"; |
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
diff
changeset
|
84 } |
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
diff
changeset
|
85 return new StringRepresentation(result, MediaType.TEXT_HTML); |
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
diff
changeset
|
86 } |
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
diff
changeset
|
87 |
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
diff
changeset
|
88 /** |
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
diff
changeset
|
89 * POST creates a new Group. |
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
diff
changeset
|
90 * |
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
diff
changeset
|
91 * @return |
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
diff
changeset
|
92 */ |
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
diff
changeset
|
93 @Post |
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
diff
changeset
|
94 public Representation doPost(Representation entity) { |
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
diff
changeset
|
95 logger.debug("PersonsResource doPost!"); |
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
diff
changeset
|
96 // TODO: do authentication |
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
diff
changeset
|
97 Form form = new Form(entity); |
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
diff
changeset
|
98 String id = form.getFirstValue("id"); |
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
diff
changeset
|
99 if (id == null || id.isEmpty() || id.matches("\\W")) { |
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
diff
changeset
|
100 // invalid id |
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
diff
changeset
|
101 setStatus(Status.CLIENT_ERROR_BAD_REQUEST); |
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
diff
changeset
|
102 return null; |
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
diff
changeset
|
103 } |
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
diff
changeset
|
104 String name = form.getFirstValue("name"); |
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
diff
changeset
|
105 if (name == null || name.isEmpty()) { |
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
diff
changeset
|
106 name = ((BaseRestlet) getApplication()).getFullNameFromLdap(id); |
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
diff
changeset
|
107 } |
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
diff
changeset
|
108 String uri = form.getFirstValue("uri"); |
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
diff
changeset
|
109 if (uri != null && uri.isEmpty()) uri = null; |
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
diff
changeset
|
110 Person newPerson = new Person(id, uri, name); |
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
diff
changeset
|
111 Actor storedPerson = store.storeActor(newPerson); |
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
diff
changeset
|
112 id = storedPerson.getId(); |
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
diff
changeset
|
113 // return 303: see other |
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
diff
changeset
|
114 setStatus(Status.REDIRECTION_SEE_OTHER); |
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
diff
changeset
|
115 // go GET URL for this person |
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
diff
changeset
|
116 Reference url = this.getReference().clone(); |
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
diff
changeset
|
117 url.addSegment(id); |
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
diff
changeset
|
118 this.getResponse().setLocationRef(url); |
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
diff
changeset
|
119 return null; |
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
diff
changeset
|
120 } |
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
diff
changeset
|
121 |
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
diff
changeset
|
122 } |