annotate DVN-web/src/main/java/de/mpiwg/monographs/servlet/MonographUtils.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 org.codehaus.jettison.json.JSONArray;
2ae72563a29d Commit of the project with the correct structure.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
4 import org.codehaus.jettison.json.JSONObject;
2ae72563a29d Commit of the project with the correct structure.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
5 import org.swordapp.server.SwordServerException;
2ae72563a29d Commit of the project with the correct structure.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
6
2ae72563a29d Commit of the project with the correct structure.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
7 import edu.harvard.iq.dvn.core.admin.UserGroup;
2ae72563a29d Commit of the project with the correct structure.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
8 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
9 import edu.harvard.iq.dvn.core.study.FileMetadata;
4
9b408c9b05ab Integration with LGServices.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents: 2
diff changeset
10 import edu.harvard.iq.dvn.core.study.Metadata;
2
2ae72563a29d Commit of the project with the correct structure.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
11 import edu.harvard.iq.dvn.core.study.Study;
2ae72563a29d Commit of the project with the correct structure.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
12 import edu.harvard.iq.dvn.core.study.StudyVersion;
2ae72563a29d Commit of the project with the correct structure.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
13 import edu.harvard.iq.dvn.core.vdc.VDCGroup;
4
9b408c9b05ab Integration with LGServices.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents: 2
diff changeset
14 import edu.harvard.iq.dvn.core.web.study.StudyUI;
9b408c9b05ab Integration with LGServices.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents: 2
diff changeset
15 import edu.harvard.iq.dvn.core.vdc.VDC;
2
2ae72563a29d Commit of the project with the correct structure.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
16
2ae72563a29d Commit of the project with the correct structure.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
17 public class MonographUtils {
2ae72563a29d Commit of the project with the correct structure.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
18
4
9b408c9b05ab Integration with LGServices.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents: 2
diff changeset
19 public static JSONObject jsonStudyUI(StudyUI studyUI){
9b408c9b05ab Integration with LGServices.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents: 2
diff changeset
20 JSONObject json = null;
9b408c9b05ab Integration with LGServices.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents: 2
diff changeset
21
9b408c9b05ab Integration with LGServices.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents: 2
diff changeset
22 if(studyUI != null){
9b408c9b05ab Integration with LGServices.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents: 2
diff changeset
23 try {
9b408c9b05ab Integration with LGServices.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents: 2
diff changeset
24 json = jsonStudy(studyUI.getStudy());
9b408c9b05ab Integration with LGServices.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents: 2
diff changeset
25 json.put("metadata", jsonMetadata(studyUI.getMetadata()));
9b408c9b05ab Integration with LGServices.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents: 2
diff changeset
26
9b408c9b05ab Integration with LGServices.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents: 2
diff changeset
27 String status =
9b408c9b05ab Integration with LGServices.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents: 2
diff changeset
28 (studyUI.getStudy().getLatestVersion().isDraft()) ?
9b408c9b05ab Integration with LGServices.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents: 2
diff changeset
29 "Draft" :
9b408c9b05ab Integration with LGServices.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents: 2
diff changeset
30 ((studyUI.getStudy().getLatestVersion().isInReview()) ?
9b408c9b05ab Integration with LGServices.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents: 2
diff changeset
31 "In Review" :(studyUI.getStudy().getLatestVersion().isReleased()) ?
9b408c9b05ab Integration with LGServices.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents: 2
diff changeset
32 "Released" : "Deaccessioned");
9b408c9b05ab Integration with LGServices.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents: 2
diff changeset
33 json.put("status", status);
9b408c9b05ab Integration with LGServices.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents: 2
diff changeset
34
9b408c9b05ab Integration with LGServices.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents: 2
diff changeset
35 } catch (Exception e) {
9b408c9b05ab Integration with LGServices.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents: 2
diff changeset
36 e.printStackTrace();
9b408c9b05ab Integration with LGServices.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents: 2
diff changeset
37 }
9b408c9b05ab Integration with LGServices.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents: 2
diff changeset
38 }
9b408c9b05ab Integration with LGServices.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents: 2
diff changeset
39 return json;
9b408c9b05ab Integration with LGServices.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents: 2
diff changeset
40 }
9b408c9b05ab Integration with LGServices.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents: 2
diff changeset
41
9b408c9b05ab Integration with LGServices.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents: 2
diff changeset
42 public static JSONObject jsonMetadata(Metadata meta){
9b408c9b05ab Integration with LGServices.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents: 2
diff changeset
43 JSONObject json = new JSONObject();
9b408c9b05ab Integration with LGServices.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents: 2
diff changeset
44
9b408c9b05ab Integration with LGServices.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents: 2
diff changeset
45 try {
9b408c9b05ab Integration with LGServices.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents: 2
diff changeset
46
9b408c9b05ab Integration with LGServices.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents: 2
diff changeset
47 json.put("accessToSources", meta.getAccessToSources());
9b408c9b05ab Integration with LGServices.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents: 2
diff changeset
48 json.put("actionsToMinimizeLoss", meta.getActionsToMinimizeLoss());
9b408c9b05ab Integration with LGServices.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents: 2
diff changeset
49 json.put("authorsStr", meta.getAuthorsStr());
9b408c9b05ab Integration with LGServices.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents: 2
diff changeset
50 json.put("availabilityStatus", meta.getAvailabilityStatus());
9b408c9b05ab Integration with LGServices.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents: 2
diff changeset
51 json.put("citationRequirements", meta.getCitationRequirements());
9b408c9b05ab Integration with LGServices.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents: 2
diff changeset
52 json.put("subTitle", meta.getSubTitle());
9b408c9b05ab Integration with LGServices.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents: 2
diff changeset
53 json.put("title", meta.getTitle());
9b408c9b05ab Integration with LGServices.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents: 2
diff changeset
54
9b408c9b05ab Integration with LGServices.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents: 2
diff changeset
55 } catch (Exception e) {
9b408c9b05ab Integration with LGServices.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents: 2
diff changeset
56 e.printStackTrace();
9b408c9b05ab Integration with LGServices.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents: 2
diff changeset
57 }
9b408c9b05ab Integration with LGServices.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents: 2
diff changeset
58
9b408c9b05ab Integration with LGServices.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents: 2
diff changeset
59
9b408c9b05ab Integration with LGServices.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents: 2
diff changeset
60
9b408c9b05ab Integration with LGServices.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents: 2
diff changeset
61 return json;
9b408c9b05ab Integration with LGServices.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents: 2
diff changeset
62 }
9b408c9b05ab Integration with LGServices.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents: 2
diff changeset
63
2
2ae72563a29d Commit of the project with the correct structure.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
64 public static JSONObject jsonStudy(Study study){
2ae72563a29d Commit of the project with the correct structure.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
65 JSONObject json = new JSONObject();
2ae72563a29d Commit of the project with the correct structure.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
66
2ae72563a29d Commit of the project with the correct structure.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
67 if(study != null){
2ae72563a29d Commit of the project with the correct structure.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
68 try {
2ae72563a29d Commit of the project with the correct structure.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
69 json.put("authority", study.getAuthority());
2ae72563a29d Commit of the project with the correct structure.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
70 json.put("id", study.getId());
2ae72563a29d Commit of the project with the correct structure.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
71 json.put("globalId", study.getGlobalId());
2ae72563a29d Commit of the project with the correct structure.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
72 json.put("harvestIdentifier", study.getHarvestIdentifier());
2ae72563a29d Commit of the project with the correct structure.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
73 json.put("persistentURL", study.getPersistentURL());
2ae72563a29d Commit of the project with the correct structure.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
74 json.put("protocol", study.getProtocol());
2ae72563a29d Commit of the project with the correct structure.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
75 json.put("version", study.getVersion());
2ae72563a29d Commit of the project with the correct structure.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
76 json.put("studyId", study.getStudyId());
4
9b408c9b05ab Integration with LGServices.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents: 2
diff changeset
77 json.put("createTime", study.getCreateTime());
2
2ae72563a29d Commit of the project with the correct structure.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
78 json.put("numberOfDownloads", study.getNumberOfDownloads());
2ae72563a29d Commit of the project with the correct structure.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
79
4
9b408c9b05ab Integration with LGServices.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents: 2
diff changeset
80 JSONObject owner = jsonVDC(study.getOwner());
9b408c9b05ab Integration with LGServices.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents: 2
diff changeset
81 json.put("owner", owner);
9b408c9b05ab Integration with LGServices.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents: 2
diff changeset
82
9b408c9b05ab Integration with LGServices.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents: 2
diff changeset
83 JSONObject creator = jsonVDCUser(study.getCreator());
9b408c9b05ab Integration with LGServices.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents: 2
diff changeset
84 json.put("creator", creator);
9b408c9b05ab Integration with LGServices.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents: 2
diff changeset
85
2
2ae72563a29d Commit of the project with the correct structure.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
86 JSONArray array0 = new JSONArray();
2ae72563a29d Commit of the project with the correct structure.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
87 for(VDCUser user : study.getAllowedUsers()){
2ae72563a29d Commit of the project with the correct structure.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
88 array0.put(jsonVDCUser(user));
2ae72563a29d Commit of the project with the correct structure.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
89 }
2ae72563a29d Commit of the project with the correct structure.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
90 json.put("allowedUsers", array0);
2ae72563a29d Commit of the project with the correct structure.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
91
2ae72563a29d Commit of the project with the correct structure.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
92
2ae72563a29d Commit of the project with the correct structure.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
93 } catch (Exception e) {
2ae72563a29d Commit of the project with the correct structure.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
94 e.printStackTrace();
2ae72563a29d Commit of the project with the correct structure.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
95 }
2ae72563a29d Commit of the project with the correct structure.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
96 }
2ae72563a29d Commit of the project with the correct structure.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
97
2ae72563a29d Commit of the project with the correct structure.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
98 return json;
2ae72563a29d Commit of the project with the correct structure.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
99 }
4
9b408c9b05ab Integration with LGServices.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents: 2
diff changeset
100
9b408c9b05ab Integration with LGServices.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents: 2
diff changeset
101 public static JSONObject jsonVDC(VDC vdc){
9b408c9b05ab Integration with LGServices.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents: 2
diff changeset
102 JSONObject json = new JSONObject();
9b408c9b05ab Integration with LGServices.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents: 2
diff changeset
103
9b408c9b05ab Integration with LGServices.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents: 2
diff changeset
104 try {
9b408c9b05ab Integration with LGServices.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents: 2
diff changeset
105
9b408c9b05ab Integration with LGServices.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents: 2
diff changeset
106 json.put("name", vdc.getName());
9b408c9b05ab Integration with LGServices.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents: 2
diff changeset
107 json.put("aboutThis", vdc.getAboutThisDataverse());
9b408c9b05ab Integration with LGServices.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents: 2
diff changeset
108 json.put("visibility", vdc.getVisibility());
9b408c9b05ab Integration with LGServices.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents: 2
diff changeset
109 json.put("version", vdc.getVersion());
9b408c9b05ab Integration with LGServices.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents: 2
diff changeset
110 json.put("parentSite", vdc.getParentSite());
9b408c9b05ab Integration with LGServices.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents: 2
diff changeset
111 json.put("logo", vdc.getLogo());
9b408c9b05ab Integration with LGServices.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents: 2
diff changeset
112 json.put("header", vdc.getHeader());
9b408c9b05ab Integration with LGServices.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents: 2
diff changeset
113 json.put("alias", vdc.getAlias());
9b408c9b05ab Integration with LGServices.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents: 2
diff changeset
114
9b408c9b05ab Integration with LGServices.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents: 2
diff changeset
115 } catch (Exception e) {
9b408c9b05ab Integration with LGServices.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents: 2
diff changeset
116 e.printStackTrace();
9b408c9b05ab Integration with LGServices.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents: 2
diff changeset
117 }
9b408c9b05ab Integration with LGServices.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents: 2
diff changeset
118
9b408c9b05ab Integration with LGServices.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents: 2
diff changeset
119 return json;
9b408c9b05ab Integration with LGServices.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents: 2
diff changeset
120 }
2
2ae72563a29d Commit of the project with the correct structure.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
121
2ae72563a29d Commit of the project with the correct structure.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
122 public static JSONObject jsonVDCUser(VDCUser user){
2ae72563a29d Commit of the project with the correct structure.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
123 JSONObject json = new JSONObject();
2ae72563a29d Commit of the project with the correct structure.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
124
2ae72563a29d Commit of the project with the correct structure.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
125 try {
2ae72563a29d Commit of the project with the correct structure.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
126
2ae72563a29d Commit of the project with the correct structure.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
127 json.put("email", user.getEmail());
2ae72563a29d Commit of the project with the correct structure.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
128 json.put("firstName", user.getFirstName());
2ae72563a29d Commit of the project with the correct structure.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
129 json.put("id", user.getId());
2ae72563a29d Commit of the project with the correct structure.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
130 json.put("version", user.getVersion());
2ae72563a29d Commit of the project with the correct structure.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
131 json.put("userName", user.getUserName());
2ae72563a29d Commit of the project with the correct structure.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
132 json.put("position", user.getPosition());
2ae72563a29d Commit of the project with the correct structure.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
133 json.put("lastName", user.getLastName());
2ae72563a29d Commit of the project with the correct structure.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
134 json.put("institution", user.getInstitution());
2ae72563a29d Commit of the project with the correct structure.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
135
2ae72563a29d Commit of the project with the correct structure.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
136 JSONArray array0 = new JSONArray();
2ae72563a29d Commit of the project with the correct structure.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
137 for(UserGroup group : user.getUserGroups()){
2ae72563a29d Commit of the project with the correct structure.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
138 array0.put(jsonGroup(group));
2ae72563a29d Commit of the project with the correct structure.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
139 }
2ae72563a29d Commit of the project with the correct structure.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
140 json.put("userGroups", array0);
2ae72563a29d Commit of the project with the correct structure.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
141
2ae72563a29d Commit of the project with the correct structure.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
142 } catch (Exception e) {
2ae72563a29d Commit of the project with the correct structure.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
143 e.printStackTrace();
2ae72563a29d Commit of the project with the correct structure.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
144 }
2ae72563a29d Commit of the project with the correct structure.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
145
2ae72563a29d Commit of the project with the correct structure.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
146
2ae72563a29d Commit of the project with the correct structure.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
147 return json;
2ae72563a29d Commit of the project with the correct structure.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
148 }
2ae72563a29d Commit of the project with the correct structure.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
149
2ae72563a29d Commit of the project with the correct structure.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
150 public static JSONObject jsonGroup(UserGroup group){
2ae72563a29d Commit of the project with the correct structure.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
151 JSONObject json = new JSONObject();
2ae72563a29d Commit of the project with the correct structure.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
152
2ae72563a29d Commit of the project with the correct structure.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
153 if(group != null){
2ae72563a29d Commit of the project with the correct structure.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
154 try {
2ae72563a29d Commit of the project with the correct structure.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
155
2ae72563a29d Commit of the project with the correct structure.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
156 json.put("friendlyName", group.getFriendlyName());
2ae72563a29d Commit of the project with the correct structure.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
157 json.put("id", group.getId());
2ae72563a29d Commit of the project with the correct structure.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
158
2ae72563a29d Commit of the project with the correct structure.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
159 } catch (Exception e) {
2ae72563a29d Commit of the project with the correct structure.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
160 e.printStackTrace();
2ae72563a29d Commit of the project with the correct structure.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
161 }
2ae72563a29d Commit of the project with the correct structure.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
162 }
2ae72563a29d Commit of the project with the correct structure.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
163
2ae72563a29d Commit of the project with the correct structure.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
164 return json;
2ae72563a29d Commit of the project with the correct structure.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
165 }
2ae72563a29d Commit of the project with the correct structure.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
166
2ae72563a29d Commit of the project with the correct structure.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
167
2ae72563a29d Commit of the project with the correct structure.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
168 public static JSONObject jsonVDCGroup(VDCGroup group){
2ae72563a29d Commit of the project with the correct structure.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
169 JSONObject json = new JSONObject();
2ae72563a29d Commit of the project with the correct structure.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
170
2ae72563a29d Commit of the project with the correct structure.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
171 if(group != null){
2ae72563a29d Commit of the project with the correct structure.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
172 try {
2ae72563a29d Commit of the project with the correct structure.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
173
2ae72563a29d Commit of the project with the correct structure.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
174 json.put("Id", group.getId());
2ae72563a29d Commit of the project with the correct structure.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
175 json.put("name", group.getName());
2ae72563a29d Commit of the project with the correct structure.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
176 json.put("parent", group.getParent());
2ae72563a29d Commit of the project with the correct structure.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
177 json.put("description", group.getDescription());
2ae72563a29d Commit of the project with the correct structure.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
178 json.put("version", group.getVersion());
2ae72563a29d Commit of the project with the correct structure.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
179
2ae72563a29d Commit of the project with the correct structure.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
180 } catch (Exception e) {
2ae72563a29d Commit of the project with the correct structure.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
181 e.printStackTrace();
2ae72563a29d Commit of the project with the correct structure.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
182 }
2ae72563a29d Commit of the project with the correct structure.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
183 }
2ae72563a29d Commit of the project with the correct structure.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
184
2ae72563a29d Commit of the project with the correct structure.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
185 return json;
2ae72563a29d Commit of the project with the correct structure.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
186 }
2ae72563a29d Commit of the project with the correct structure.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
187
2ae72563a29d Commit of the project with the correct structure.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
188
2ae72563a29d Commit of the project with the correct structure.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
189 public static JSONObject jsonStudyVersion(StudyVersion study) throws SwordServerException{
2ae72563a29d Commit of the project with the correct structure.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
190
2ae72563a29d Commit of the project with the correct structure.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
191 JSONObject jsonStudy = new JSONObject();
2ae72563a29d Commit of the project with the correct structure.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
192
2ae72563a29d Commit of the project with the correct structure.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
193 try {
2ae72563a29d Commit of the project with the correct structure.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
194 jsonStudy.put("id", study.getId());
2ae72563a29d Commit of the project with the correct structure.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
195 jsonStudy.put("fileMetadataSize", study.getFileMetadatas().size());
2ae72563a29d Commit of the project with the correct structure.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
196 jsonStudy.put("fileCategoriesSize", study.getFileCategories().size());
2ae72563a29d Commit of the project with the correct structure.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
197 jsonStudy.put("version", study.getVersion());
2ae72563a29d Commit of the project with the correct structure.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
198 jsonStudy.put("archiveNote", study.getArchiveNote());
2ae72563a29d Commit of the project with the correct structure.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
199 jsonStudy.put("numberOfFiles", study.getNumberOfFiles());
2ae72563a29d Commit of the project with the correct structure.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
200 jsonStudy.put("versionNumber", study.getVersionNumber());
2ae72563a29d Commit of the project with the correct structure.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
201 jsonStudy.put("versionState", study.getVersionState());
2ae72563a29d Commit of the project with the correct structure.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
202 jsonStudy.put("versionNote", study.getVersionNote());
2ae72563a29d Commit of the project with the correct structure.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
203 jsonStudy.put("deaccessionLink", study.getDeaccessionLink());
2ae72563a29d Commit of the project with the correct structure.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
204 //jsonStudy.put("deaccessionLinkAsGlobalId", study.getDeaccessionLinkAsGlobalId());
2ae72563a29d Commit of the project with the correct structure.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
205
2ae72563a29d Commit of the project with the correct structure.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
206
2ae72563a29d Commit of the project with the correct structure.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
207 JSONObject jsonMetadata = new JSONObject();
2ae72563a29d Commit of the project with the correct structure.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
208 jsonMetadata.put("accessToSources", study.getMetadata().getAccessToSources());
2ae72563a29d Commit of the project with the correct structure.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
209 jsonMetadata.put("authorsStr", study.getMetadata().getAuthorsStr());
2ae72563a29d Commit of the project with the correct structure.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
210 jsonMetadata.put("contact", study.getMetadata().getContact());
2ae72563a29d Commit of the project with the correct structure.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
211 jsonMetadata.put("dataSources", study.getMetadata().getDataSources());
2ae72563a29d Commit of the project with the correct structure.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
212 jsonMetadata.put("dataCollector", study.getMetadata().getDataCollector());
2ae72563a29d Commit of the project with the correct structure.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
213 jsonMetadata.put("id", study.getMetadata().getId());
2ae72563a29d Commit of the project with the correct structure.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
214
2ae72563a29d Commit of the project with the correct structure.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
215
2ae72563a29d Commit of the project with the correct structure.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
216 JSONArray fileMetadatas = new JSONArray();
2ae72563a29d Commit of the project with the correct structure.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
217 for(FileMetadata fileMetadata : study.getFileMetadatas()){
2ae72563a29d Commit of the project with the correct structure.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
218 JSONObject tmp = new JSONObject();
2ae72563a29d Commit of the project with the correct structure.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
219 tmp.put("id", fileMetadata.getId());
2ae72563a29d Commit of the project with the correct structure.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
220 tmp.put("label", fileMetadata.getLabel());
2ae72563a29d Commit of the project with the correct structure.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
221 tmp.put("version", fileMetadata.getVersion());
2ae72563a29d Commit of the project with the correct structure.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
222 tmp.put("studyVersion", fileMetadata.getStudyVersion());
2ae72563a29d Commit of the project with the correct structure.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
223
2ae72563a29d Commit of the project with the correct structure.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
224 fileMetadatas.put(tmp);
2ae72563a29d Commit of the project with the correct structure.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
225 }
2ae72563a29d Commit of the project with the correct structure.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
226 jsonStudy.put("fileMetadatas", fileMetadatas);
2ae72563a29d Commit of the project with the correct structure.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
227
2ae72563a29d Commit of the project with the correct structure.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
228 JSONArray fileCategories = new JSONArray();
2ae72563a29d Commit of the project with the correct structure.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
229 for(String fileCategory : study.getFileCategories()){
2ae72563a29d Commit of the project with the correct structure.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
230 fileCategories.put(fileCategory);
2ae72563a29d Commit of the project with the correct structure.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
231 }
2ae72563a29d Commit of the project with the correct structure.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
232 jsonStudy.put("fileCategories", fileCategories);
2ae72563a29d Commit of the project with the correct structure.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
233 } catch (Exception e) {
2ae72563a29d Commit of the project with the correct structure.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
234 e.printStackTrace();
2ae72563a29d Commit of the project with the correct structure.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
235 }
2ae72563a29d Commit of the project with the correct structure.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
236 return jsonStudy;
2ae72563a29d Commit of the project with the correct structure.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
237 }
2ae72563a29d Commit of the project with the correct structure.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
238
2ae72563a29d Commit of the project with the correct structure.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
239 }