Mercurial > hg > NamedIdentityManager
comparison src/de/mpiwg/itgroup/nimanager/persons/PersonListService.java @ 5:cdc4c12262b1
minor changes
author | dwinter |
---|---|
date | Wed, 21 Dec 2011 22:10:38 +0100 |
parents | f986e74583eb |
children | e0aca5ffc4df |
comparison
equal
deleted
inserted
replaced
4:f986e74583eb | 5:cdc4c12262b1 |
---|---|
1 package de.mpiwg.itgroup.nimanager.persons; | 1 package de.mpiwg.itgroup.nimanager.persons; |
2 | 2 |
3 import java.io.File; | 3 import java.io.File; |
4 import java.io.IOException; | 4 import java.io.IOException; |
5 import java.io.UnsupportedEncodingException; | |
6 import java.net.URLDecoder; | |
5 import java.util.ArrayList; | 7 import java.util.ArrayList; |
6 import java.util.HashMap; | 8 import java.util.HashMap; |
7 import java.util.List; | 9 import java.util.List; |
8 import java.util.Map; | 10 import java.util.Map; |
9 | 11 |
20 import org.apache.lucene.util.Version; | 22 import org.apache.lucene.util.Version; |
21 import org.json.JSONArray; | 23 import org.json.JSONArray; |
22 import org.restlet.Context; | 24 import org.restlet.Context; |
23 import org.restlet.data.Form; | 25 import org.restlet.data.Form; |
24 import org.restlet.data.MediaType; | 26 import org.restlet.data.MediaType; |
27 import org.restlet.data.Status; | |
25 import org.restlet.engine.component.ChildContext; | 28 import org.restlet.engine.component.ChildContext; |
26 import org.restlet.ext.json.JsonRepresentation; | 29 import org.restlet.ext.json.JsonRepresentation; |
27 import org.restlet.representation.Representation; | 30 import org.restlet.representation.Representation; |
28 import org.restlet.representation.StringRepresentation; | 31 import org.restlet.representation.StringRepresentation; |
29 import org.restlet.resource.Get; | 32 import org.restlet.resource.Get; |
107 getResponse().getAttributes().put("org.restlet.http.headers", | 110 getResponse().getAttributes().put("org.restlet.http.headers", |
108 responseHeaders); | 111 responseHeaders); |
109 } | 112 } |
110 responseHeaders.add("Access-Control-Allow-Origin", "*"); | 113 responseHeaders.add("Access-Control-Allow-Origin", "*"); |
111 Form form = getRequest().getResourceRef().getQueryAsForm(); | 114 Form form = getRequest().getResourceRef().getQueryAsForm(); |
112 String term = form.getFirstValue("term"); | 115 |
113 | 116 |
114 String [] array = getPersonsAsArray(term); | 117 String [] array= null; |
115 String ret=""; | 118 String term=""; |
116 | 119 |
117 for (int i=0;i<array.length;i++){ | 120 String ret="Search Name:<form method=\"get\" ><input name=\"term\" size=\"30\"/></form>"; |
118 ret+=String.format("<div class=\"personName\"><a href=\"./person/name/%s\">%s</a></div>", array[i],array[i]); | 121 |
119 } | 122 if (form.getValuesMap().keySet().contains("term")){ |
120 | 123 term = form.getFirstValue("term"); |
124 | |
125 } else { | |
126 return new StringRepresentation(ret,MediaType.TEXT_HTML); | |
127 } | |
128 | |
129 array = getPersonsAsArray(term); | |
130 // String personId=""; | |
131 // | |
132 // if (form.getValuesMap().keySet().contains("personID")){ | |
133 // personId = form.getFirstValue("personID"); | |
134 // array = new String[]{personId}; | |
135 // } | |
136 | |
137 | |
138 | |
139 | |
140 | |
141 String mode="short"; | |
142 if (form.getValuesMap().keySet().contains("mode")){ | |
143 mode = form.getFirstValue("mode"); | |
144 } | |
145 | |
146 | |
147 | |
148 if (mode.equals("short")){ | |
149 for (int i=0;i<array.length;i++){ | |
150 ret+=String.format("<div class=\"personName\"><a href=\"./person/name/%s\">%s</a></div>", array[i],array[i]); | |
151 } | |
152 } else if (mode.equals("long")){ | |
153 PersonByNameService ps = new PersonByNameService(); | |
154 for (int i=0;i<array.length;i++){ | |
155 | |
156 try { | |
157 List<Map<String, String>> maps = ps.getMaps(URLDecoder.decode(array[i],"utf-8")); | |
158 for (Map<String,String>map:maps){ | |
159 ret+=String.format("<div class=\"personName\">%s (%s-%s)</div>", array[i],map.get("birthDate"),map.get("deathDate")); | |
160 ret+=String.format("<div><a href=\"%s\">view in GND</a></div>",map.get("gnd")); | |
161 } | |
162 } catch (UnsupportedEncodingException e) { | |
163 // TODO Auto-generated catch block | |
164 e.printStackTrace(); | |
165 } | |
166 | |
167 } | |
168 } else { | |
169 setStatus(Status.SERVER_ERROR_NOT_IMPLEMENTED); | |
170 return new StringRepresentation("MODE "+mode+" unknown!",MediaType.TEXT_HTML); | |
171 } | |
121 | 172 |
122 return new StringRepresentation(ret,MediaType.TEXT_HTML); | 173 return new StringRepresentation(ret,MediaType.TEXT_HTML); |
123 } | 174 } |
124 | 175 |
125 | 176 |