annotate DVN-web/src/main/java/de/mpiwg/monographs/servlet/GetAllUsers.java @ 4:9b408c9b05ab

Integration with LGServices.
author "jurzua <jurzua@mpiwg-berlin.mpg.de>"
date Thu, 07 May 2015 14:56:46 +0200
parents 2ae72563a29d
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2
2ae72563a29d Commit of the project with the correct structure.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
1 package de.mpiwg.monographs.servlet;
2ae72563a29d Commit of the project with the correct structure.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
2
2ae72563a29d Commit of the project with the correct structure.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
3 import java.io.IOException;
2ae72563a29d Commit of the project with the correct structure.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
4 import java.util.List;
2ae72563a29d Commit of the project with the correct structure.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
5
2ae72563a29d Commit of the project with the correct structure.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
6 import javax.inject.Inject;
2ae72563a29d Commit of the project with the correct structure.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
7 import javax.servlet.ServletException;
2ae72563a29d Commit of the project with the correct structure.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
8 import javax.servlet.http.HttpServletRequest;
2ae72563a29d Commit of the project with the correct structure.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
9 import javax.servlet.http.HttpServletResponse;
2ae72563a29d Commit of the project with the correct structure.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
10
2ae72563a29d Commit of the project with the correct structure.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
11 import org.codehaus.jettison.json.JSONArray;
2ae72563a29d Commit of the project with the correct structure.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
12 import org.codehaus.jettison.json.JSONException;
2ae72563a29d Commit of the project with the correct structure.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
13 import org.codehaus.jettison.json.JSONObject;
2ae72563a29d Commit of the project with the correct structure.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
14
2ae72563a29d Commit of the project with the correct structure.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
15 import edu.harvard.iq.dvn.api.datadeposit.SwordAuth;
2ae72563a29d Commit of the project with the correct structure.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
16 import edu.harvard.iq.dvn.core.admin.VDCUser;
2ae72563a29d Commit of the project with the correct structure.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
17
2ae72563a29d Commit of the project with the correct structure.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
18 public class GetAllUsers extends AbstractMonographServlet{
2ae72563a29d Commit of the project with the correct structure.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
19
2ae72563a29d Commit of the project with the correct structure.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
20 @Inject
2ae72563a29d Commit of the project with the correct structure.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
21 private SwordAuth swordAuth;
2ae72563a29d Commit of the project with the correct structure.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
22
2ae72563a29d Commit of the project with the correct structure.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
23 public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
2ae72563a29d Commit of the project with the correct structure.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
24 // Set response content type
2ae72563a29d Commit of the project with the correct structure.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
25 response.setContentType("application/json");
2ae72563a29d Commit of the project with the correct structure.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
26 JSONObject jsonResponse = new JSONObject();
2ae72563a29d Commit of the project with the correct structure.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
27
2ae72563a29d Commit of the project with the correct structure.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
28 List<VDCUser> userList = swordAuth.getAllUsers();
2ae72563a29d Commit of the project with the correct structure.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
29 JSONArray array = new JSONArray();
2ae72563a29d Commit of the project with the correct structure.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
30 for(VDCUser user : userList){
2ae72563a29d Commit of the project with the correct structure.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
31 JSONObject json = MonographUtils.jsonVDCUser(user);
2ae72563a29d Commit of the project with the correct structure.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
32 array.put(json);
2ae72563a29d Commit of the project with the correct structure.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
33 }
2ae72563a29d Commit of the project with the correct structure.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
34
2ae72563a29d Commit of the project with the correct structure.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
35 try {
2ae72563a29d Commit of the project with the correct structure.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
36 jsonResponse.put("state", "ok");
2ae72563a29d Commit of the project with the correct structure.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
37 jsonResponse.put("users", array);
2ae72563a29d Commit of the project with the correct structure.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
38 } catch (JSONException e) {
2ae72563a29d Commit of the project with the correct structure.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
39 e.printStackTrace();
4
9b408c9b05ab Integration with LGServices.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents: 2
diff changeset
40 }
2
2ae72563a29d Commit of the project with the correct structure.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
41
2ae72563a29d Commit of the project with the correct structure.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
42 java.io.PrintWriter out = response.getWriter();
2ae72563a29d Commit of the project with the correct structure.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
43 out.print(jsonResponse);
2ae72563a29d Commit of the project with the correct structure.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
44 out.flush();
2ae72563a29d Commit of the project with the correct structure.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
45 }
2ae72563a29d Commit of the project with the correct structure.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
46
2ae72563a29d Commit of the project with the correct structure.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
47 }