Mercurial > hg > AnnotationManagerN4J
annotate src/main/java/de/mpiwg/itgroup/annotations/restlet/annotations_ui/PersonsResource.java @ 45:707902d468f6
store reads and sends annotations resources now.
author | casties |
---|---|
date | Wed, 26 Sep 2012 17:28:31 +0200 |
parents | 0731c4549065 |
children | 64aa756c60cc |
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.neo4j.AnnotationStore.NodeTypes; |
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
diff
changeset
|
24 import de.mpiwg.itgroup.annotations.restlet.BaseRestlet; |
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 /** |
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
diff
changeset
|
27 * 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
|
28 * |
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
diff
changeset
|
29 * @author casties |
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 */ |
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
diff
changeset
|
32 public class PersonsResource extends ServerResource { |
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
diff
changeset
|
33 |
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
diff
changeset
|
34 public static Logger logger = Logger.getLogger(PersonsResource.class); |
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
diff
changeset
|
35 |
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
diff
changeset
|
36 private AnnotationStore store; |
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
diff
changeset
|
37 |
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
diff
changeset
|
38 @Override |
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
diff
changeset
|
39 protected void doInit() throws ResourceException { |
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
diff
changeset
|
40 super.doInit(); |
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
diff
changeset
|
41 // get store instance |
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
diff
changeset
|
42 if (store == null) { |
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
diff
changeset
|
43 store = ((BaseRestlet) getApplication()).getAnnotationStore(); |
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 /** |
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
diff
changeset
|
48 * GET with HTML content type. Lists all persons. |
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
diff
changeset
|
49 * |
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
diff
changeset
|
50 * @param entity |
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
diff
changeset
|
51 * @return |
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
diff
changeset
|
52 */ |
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
diff
changeset
|
53 @Get("html") |
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
diff
changeset
|
54 public Representation doGetHTML(Representation entity) { |
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
diff
changeset
|
55 String result = null; |
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
diff
changeset
|
56 // get form parameter |
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
diff
changeset
|
57 Form f = this.getQuery(); |
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
diff
changeset
|
58 String form = f.getFirstValue("form"); |
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
diff
changeset
|
59 if (form != null && form.equals("new_person")) { |
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
diff
changeset
|
60 // output new group form |
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
diff
changeset
|
61 result = "<html><body>\n"; |
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
diff
changeset
|
62 result += "<h1>New person</h1>\n"; |
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
diff
changeset
|
63 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
|
64 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
|
65 result += "<table>"; |
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
diff
changeset
|
66 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
|
67 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
|
68 result += "</table>\n"; |
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
diff
changeset
|
69 result += "<p><input type=\"submit\"/></p>\n"; |
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
diff
changeset
|
70 result += "</form>\n</body>\n</html>"; |
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
diff
changeset
|
71 } else { |
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
diff
changeset
|
72 // list all groups |
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
diff
changeset
|
73 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
|
74 result += "<tr><th>id</th><th>name</th><th>uri</th></tr>"; |
45 | 75 List<Person> persons = store.getPersons("uri", "*"); |
76 for (Person person : persons) { | |
32
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
diff
changeset
|
77 Reference url = this.getReference().clone(); |
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
diff
changeset
|
78 url.addSegment(person.getId()); |
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
diff
changeset
|
79 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
|
80 person.getIdString(), person.getName(), person.getUri()); |
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
diff
changeset
|
81 } |
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
diff
changeset
|
82 result += "</table>\n"; |
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
diff
changeset
|
83 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
|
84 result += "</body>\n</html>"; |
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
diff
changeset
|
85 } |
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
diff
changeset
|
86 return new StringRepresentation(result, MediaType.TEXT_HTML); |
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 /** |
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
diff
changeset
|
90 * POST creates a new Group. |
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
diff
changeset
|
91 * |
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
diff
changeset
|
92 * @return |
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
diff
changeset
|
93 */ |
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
diff
changeset
|
94 @Post |
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
diff
changeset
|
95 public Representation doPost(Representation entity) { |
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
diff
changeset
|
96 logger.debug("PersonsResource doPost!"); |
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
diff
changeset
|
97 // TODO: do authentication |
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
diff
changeset
|
98 Form form = new Form(entity); |
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
diff
changeset
|
99 String id = form.getFirstValue("id"); |
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
diff
changeset
|
100 if (id == null || id.isEmpty() || id.matches("\\W")) { |
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
diff
changeset
|
101 // invalid id |
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
diff
changeset
|
102 setStatus(Status.CLIENT_ERROR_BAD_REQUEST); |
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
diff
changeset
|
103 return null; |
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
diff
changeset
|
104 } |
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
diff
changeset
|
105 String name = form.getFirstValue("name"); |
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
diff
changeset
|
106 if (name == null || name.isEmpty()) { |
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
diff
changeset
|
107 name = ((BaseRestlet) getApplication()).getFullNameFromLdap(id); |
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
diff
changeset
|
108 } |
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
diff
changeset
|
109 String uri = form.getFirstValue("uri"); |
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
diff
changeset
|
110 if (uri != null && uri.isEmpty()) uri = null; |
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
diff
changeset
|
111 Person newPerson = new Person(id, uri, name); |
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
diff
changeset
|
112 Actor storedPerson = store.storeActor(newPerson); |
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
diff
changeset
|
113 id = storedPerson.getId(); |
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
diff
changeset
|
114 // return 303: see other |
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
diff
changeset
|
115 setStatus(Status.REDIRECTION_SEE_OTHER); |
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
diff
changeset
|
116 // go GET URL for this person |
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
diff
changeset
|
117 Reference url = this.getReference().clone(); |
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
diff
changeset
|
118 url.addSegment(id); |
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
diff
changeset
|
119 this.getResponse().setLocationRef(url); |
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
diff
changeset
|
120 return null; |
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 |
0731c4549065
UI for editing groups and persons works now. (still no authorisation!)
casties
parents:
diff
changeset
|
123 } |