1 |
42275
|
katerina.i
|
package eu.dnetlib.openaire.rest;
|
2 |
|
|
|
3 |
45960
|
argiro.kok
|
import com.google.gson.*;
|
4 |
57030
|
argiro.kok
|
import eu.dnetlib.data.claims.entity.Claim;
|
5 |
|
|
import eu.dnetlib.data.claims.entity.Notification;
|
6 |
|
|
import eu.dnetlib.data.claims.handler.*;
|
7 |
|
|
import eu.dnetlib.data.claims.sql.SQLStoreException;
|
8 |
|
|
import eu.dnetlib.data.claims.utils.ClaimValidationException;
|
9 |
|
|
import eu.dnetlib.data.claims.utils.CommunityUtils;
|
10 |
53892
|
konstantin
|
import eu.dnetlib.data.emailSender.EmailSender;
|
11 |
42277
|
katerina.i
|
import org.apache.commons.validator.EmailValidator;
|
12 |
42275
|
katerina.i
|
import org.apache.log4j.Logger;
|
13 |
58338
|
argiro.kok
|
import org.json.JSONObject;
|
14 |
42708
|
katerina.i
|
import org.json.XML;
|
15 |
42275
|
katerina.i
|
import org.springframework.beans.factory.annotation.Autowired;
|
16 |
|
|
import org.springframework.stereotype.Component;
|
17 |
58338
|
argiro.kok
|
import org.springframework.web.bind.annotation.CrossOrigin;
|
18 |
42275
|
katerina.i
|
|
19 |
|
|
import javax.servlet.http.HttpServletRequest;
|
20 |
|
|
import javax.ws.rs.*;
|
21 |
|
|
import javax.ws.rs.core.Context;
|
22 |
|
|
import javax.ws.rs.core.MediaType;
|
23 |
|
|
import javax.ws.rs.core.Response;
|
24 |
42708
|
katerina.i
|
import java.util.ArrayList;
|
25 |
42275
|
katerina.i
|
import java.util.List;
|
26 |
53619
|
konstantin
|
import java.util.Map;
|
27 |
42275
|
katerina.i
|
|
28 |
57030
|
argiro.kok
|
|
29 |
42275
|
katerina.i
|
/**
|
30 |
|
|
* Created by kiatrop on 15/4/2016.
|
31 |
|
|
*/
|
32 |
|
|
@Component
|
33 |
58338
|
argiro.kok
|
@CrossOrigin(origins = "*")
|
34 |
42275
|
katerina.i
|
@Path("/claimsService")
|
35 |
57030
|
argiro.kok
|
public class ClaimsService {
|
36 |
42275
|
katerina.i
|
|
37 |
57030
|
argiro.kok
|
private static final Logger logger = Logger.getLogger(ClaimsService.class);
|
38 |
42275
|
katerina.i
|
|
39 |
|
|
@Autowired
|
40 |
|
|
private FetchClaimHandler fetchClaimHandler = null;
|
41 |
|
|
|
42 |
47084
|
argiro.kok
|
@Autowired
|
43 |
|
|
private FetchProjectHandler fetchProjectHandler= null;
|
44 |
|
|
|
45 |
53619
|
konstantin
|
@Autowired
|
46 |
|
|
private FetchNotificationHandler fetchNotificationHandler = null;
|
47 |
|
|
|
48 |
|
|
@Autowired
|
49 |
|
|
private NotificationHandler notificationHandler = null;
|
50 |
|
|
|
51 |
42708
|
katerina.i
|
|
52 |
42275
|
katerina.i
|
@Autowired
|
53 |
|
|
private ClaimHandler claimHandler = null;
|
54 |
43441
|
katerina.i
|
|
55 |
46979
|
argiro.kok
|
@Autowired
|
56 |
|
|
private DirectIndexHandler directIndexHandler = null;
|
57 |
43441
|
katerina.i
|
|
58 |
48312
|
katerina.i
|
@Autowired
|
59 |
|
|
public Authorization authorization = null;
|
60 |
46979
|
argiro.kok
|
|
61 |
53619
|
konstantin
|
@Autowired
|
62 |
|
|
private String defaultFrequencyInHours;
|
63 |
46979
|
argiro.kok
|
|
64 |
53892
|
konstantin
|
@Autowired
|
65 |
|
|
private EmailSender emailSender;
|
66 |
|
|
|
67 |
42275
|
katerina.i
|
@GET
|
68 |
|
|
@Path("projects/{projectId}/claims")
|
69 |
43441
|
katerina.i
|
@Produces(MediaType.APPLICATION_JSON)
|
70 |
|
|
public Response getProjectClaims(@PathParam("projectId") String projectId,
|
71 |
42275
|
katerina.i
|
@DefaultValue("0") @QueryParam("offset") int offset,
|
72 |
|
|
@DefaultValue("20") @QueryParam("limit") int limit,
|
73 |
42763
|
argiro.kok
|
@DefaultValue("") @QueryParam("keyword") String keyword,
|
74 |
|
|
@DefaultValue("") @QueryParam("sortby") String orderby,
|
75 |
|
|
@DefaultValue("true") @QueryParam("descending") boolean descending,
|
76 |
50969
|
argiro.kok
|
@DefaultValue("") @QueryParam("types") List<String> types,
|
77 |
48312
|
katerina.i
|
@HeaderParam("X-XSRF-TOKEN") String token,
|
78 |
|
|
@CookieParam("AccessToken") String cookie,
|
79 |
42275
|
katerina.i
|
@Context HttpServletRequest request) {
|
80 |
|
|
|
81 |
48312
|
katerina.i
|
if(token == null || token.isEmpty() || cookie == null || cookie.isEmpty() || !cookie.equals(token)){
|
82 |
50948
|
argiro.kok
|
authorization.logStatus(token,cookie);
|
83 |
48312
|
katerina.i
|
return Response.status(Response.Status.FORBIDDEN).entity(compose403Message("Forbidden: You don't have permission to access. Maybe you are not registered."))
|
84 |
46888
|
sofia.balt
|
.type(MediaType.APPLICATION_JSON)
|
85 |
|
|
.build();
|
86 |
42275
|
katerina.i
|
}
|
87 |
46888
|
sofia.balt
|
|
88 |
51938
|
argiro.kok
|
if(authorization.isClaimCurator(token)) {
|
89 |
48312
|
katerina.i
|
|
90 |
46888
|
sofia.balt
|
int total = -1;
|
91 |
|
|
|
92 |
|
|
if (projectId == null || projectId.isEmpty()) {
|
93 |
|
|
return Response.status(Response.Status.BAD_REQUEST).entity(compose400Message("Project id cannot be empty."))
|
94 |
|
|
.type(MediaType.APPLICATION_JSON).build();
|
95 |
42763
|
argiro.kok
|
}
|
96 |
42275
|
katerina.i
|
|
97 |
46888
|
sofia.balt
|
List<Claim> claims = null;
|
98 |
|
|
try {
|
99 |
50969
|
argiro.kok
|
claims = fetchClaimHandler.fetchClaimsByProject(projectId, limit, offset, keyword, orderby, descending, types,false);
|
100 |
|
|
total = fetchClaimHandler.countClaimsByProject(projectId, keyword, types);
|
101 |
46888
|
sofia.balt
|
|
102 |
47226
|
katerina.i
|
} catch (SQLStoreException|Exception e) { //TODO check this with exception
|
103 |
46888
|
sofia.balt
|
logger.error("Could not fetch claims for project with id " + projectId, e);
|
104 |
|
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(compose500Message("Fail to fetch claims" +
|
105 |
|
|
" for projects with id " + projectId + ".", e)).type(MediaType.APPLICATION_JSON).build();
|
106 |
47226
|
katerina.i
|
|
107 |
46888
|
sofia.balt
|
}
|
108 |
|
|
|
109 |
|
|
return Response.status(200).entity(composeDataResponse(request, claims, total, offset, limit)).build();
|
110 |
42275
|
katerina.i
|
}
|
111 |
46889
|
sofia.balt
|
|
112 |
46888
|
sofia.balt
|
return Response.status(Response.Status.FORBIDDEN).entity(compose403Message("Forbidden: You don't have permission to access"))
|
113 |
|
|
.type(MediaType.APPLICATION_JSON)
|
114 |
|
|
.build();
|
115 |
42275
|
katerina.i
|
}
|
116 |
|
|
|
117 |
47040
|
argiro.kok
|
@GET
|
118 |
53619
|
konstantin
|
@Path("projects/{projectId}/all_claims")
|
119 |
|
|
@Produces(MediaType.APPLICATION_JSON)
|
120 |
|
|
public Response getAllProjectClaims(@PathParam("projectId") String projectId,
|
121 |
|
|
@DefaultValue("-1") @QueryParam("offset") int offset,
|
122 |
|
|
@DefaultValue("-1") @QueryParam("limit") int limit,
|
123 |
|
|
@DefaultValue("") @QueryParam("keyword") String keyword,
|
124 |
|
|
@DefaultValue("") @QueryParam("sortby") String orderby,
|
125 |
|
|
@DefaultValue("true") @QueryParam("descending") boolean descending,
|
126 |
|
|
@DefaultValue("") @QueryParam("types") List<String> types,
|
127 |
|
|
@HeaderParam("X-XSRF-TOKEN") String token,
|
128 |
|
|
@CookieParam("AccessToken") String cookie,
|
129 |
|
|
@Context HttpServletRequest request) {
|
130 |
|
|
|
131 |
|
|
if(token == null || token.isEmpty() || cookie == null || cookie.isEmpty() || !cookie.equals(token)){
|
132 |
|
|
authorization.logStatus(token,cookie);
|
133 |
|
|
return Response.status(Response.Status.FORBIDDEN).entity(compose403Message("Forbidden: You don't have permission to access. Maybe you are not registered."))
|
134 |
|
|
.type(MediaType.APPLICATION_JSON)
|
135 |
|
|
.build();
|
136 |
|
|
}
|
137 |
|
|
|
138 |
|
|
UserInfo userInfo = authorization.getUserHandler().getUserInfo(token);
|
139 |
|
|
// if(authorization.isProjectCurator(userInfo)) {
|
140 |
|
|
String userMail = userInfo.getEmail();
|
141 |
|
|
|
142 |
|
|
int total = -1;
|
143 |
|
|
|
144 |
|
|
if (projectId == null || projectId.isEmpty()) {
|
145 |
|
|
return Response.status(Response.Status.BAD_REQUEST).entity(compose400Message("Project id cannot be empty."))
|
146 |
|
|
.type(MediaType.APPLICATION_JSON).build();
|
147 |
|
|
}
|
148 |
|
|
|
149 |
|
|
List<Claim> claims = null;
|
150 |
|
|
try {
|
151 |
|
|
boolean forbidden = true;
|
152 |
|
|
if(authorization.isProjectCurator(userInfo)) {
|
153 |
|
|
forbidden = false;
|
154 |
|
|
} else {
|
155 |
|
|
List<String> contact_emails = fetchProjectHandler.fetchContactEmailsByProjectId(projectId);
|
156 |
|
|
logger.debug(contact_emails);
|
157 |
|
|
if(contact_emails != null && contact_emails.contains(userMail)) {
|
158 |
|
|
forbidden = false;
|
159 |
|
|
}
|
160 |
|
|
}
|
161 |
|
|
|
162 |
|
|
if(forbidden){
|
163 |
|
|
return Response.status(Response.Status.FORBIDDEN).entity(compose403Message("Forbidden: You don't have permission to access"))
|
164 |
|
|
.type(MediaType.APPLICATION_JSON)
|
165 |
|
|
.build();
|
166 |
|
|
}else{
|
167 |
|
|
if(offset == -1 && limit == -1) {
|
168 |
|
|
// when offset and limit are -1 fetch claims with null values, to ignore paging and limit clause
|
169 |
|
|
claims = fetchClaimHandler.fetchClaimsByProject(projectId, null, null, keyword, orderby, descending, types, true);
|
170 |
|
|
} else {
|
171 |
|
|
claims = fetchClaimHandler.fetchClaimsByProject(projectId, limit, offset, keyword, orderby, descending, types, true);
|
172 |
|
|
}
|
173 |
|
|
total = fetchClaimHandler.countClaimsByProject(projectId, keyword, types);
|
174 |
|
|
|
175 |
|
|
return Response.status(200).entity(composeDataResponse(request, claims, total, offset, limit)).build();
|
176 |
|
|
}
|
177 |
|
|
|
178 |
|
|
} catch (SQLStoreException|Exception e) {
|
179 |
|
|
logger.error("Could not fetch claims for project with id " + projectId, e);
|
180 |
|
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(compose500Message("Fail to fetch claims" +
|
181 |
|
|
" for projects with id " + projectId + ".", e)).type(MediaType.APPLICATION_JSON).build();
|
182 |
|
|
}
|
183 |
|
|
}
|
184 |
|
|
/*
|
185 |
|
|
@GET
|
186 |
47040
|
argiro.kok
|
@Path("project/claims")
|
187 |
|
|
@Produces(MediaType.APPLICATION_JSON)
|
188 |
|
|
public Response getProjectClaimsByToken(@QueryParam("projectToken") String projectToken,
|
189 |
47448
|
konstantin
|
@DefaultValue("-1") @QueryParam("offset") int offset,
|
190 |
|
|
@DefaultValue("-1") @QueryParam("limit") int limit,
|
191 |
47040
|
argiro.kok
|
@DefaultValue("") @QueryParam("keyword") String keyword,
|
192 |
|
|
@DefaultValue("") @QueryParam("sortby") String orderby,
|
193 |
|
|
@DefaultValue("true") @QueryParam("descending") boolean descending,
|
194 |
50969
|
argiro.kok
|
@DefaultValue("") @QueryParam("types") List<String> types,
|
195 |
48312
|
katerina.i
|
@HeaderParam("X-XSRF-TOKEN") String token,
|
196 |
|
|
@CookieParam("AccessToken") String cookie,
|
197 |
47040
|
argiro.kok
|
@Context HttpServletRequest request) {
|
198 |
42277
|
katerina.i
|
|
199 |
51938
|
argiro.kok
|
|
200 |
48312
|
katerina.i
|
if(token == null || token.isEmpty() || cookie == null || cookie.isEmpty() || !cookie.equals(token)){
|
201 |
50948
|
argiro.kok
|
authorization.logStatus(token,cookie);
|
202 |
48312
|
katerina.i
|
return Response.status(Response.Status.FORBIDDEN).entity(compose403Message("Forbidden: You don't have permission to access. Maybe you are not registered."))
|
203 |
47040
|
argiro.kok
|
.type(MediaType.APPLICATION_JSON)
|
204 |
|
|
.build();
|
205 |
|
|
}
|
206 |
|
|
|
207 |
48312
|
katerina.i
|
UserInfo userInfo = authorization.getUserHandler().getUserInfo(token);
|
208 |
52620
|
konstantin
|
// if(authorization.isProjectCurator(userInfo)) {
|
209 |
48312
|
katerina.i
|
String userMail = userInfo.getEmail();
|
210 |
|
|
|
211 |
47040
|
argiro.kok
|
int total = -1;
|
212 |
|
|
|
213 |
|
|
if (projectToken == null || projectToken.isEmpty()) {
|
214 |
|
|
return Response.status(Response.Status.BAD_REQUEST).entity(compose400Message("Project token cannot be empty."))
|
215 |
|
|
.type(MediaType.APPLICATION_JSON).build();
|
216 |
|
|
}
|
217 |
|
|
|
218 |
|
|
List<Claim> claims = null;
|
219 |
|
|
try {
|
220 |
52620
|
konstantin
|
String projectId = null;
|
221 |
|
|
if(authorization.isProjectCurator(userInfo)) {
|
222 |
|
|
projectId = fetchProjectHandler.fetchProjectIdByToken(projectToken);
|
223 |
|
|
} else {
|
224 |
|
|
projectId = fetchProjectHandler.fetchProjectIdByTokenAndEmail(projectToken, userMail);
|
225 |
|
|
}
|
226 |
|
|
//String projectId = fetchProjectHandler.fetchProjectIdByToken(projectToken,userMail);
|
227 |
47084
|
argiro.kok
|
if(projectId == null){
|
228 |
|
|
return Response.status(Response.Status.FORBIDDEN).entity(compose403Message("Forbidden: You don't have permission to access"))
|
229 |
|
|
.type(MediaType.APPLICATION_JSON)
|
230 |
|
|
.build();
|
231 |
|
|
}else{
|
232 |
47448
|
konstantin
|
if(offset == -1 && limit == -1) {
|
233 |
|
|
// when offset and limit are -1 fetch claims with null values, to ignore paging and limit clause
|
234 |
50969
|
argiro.kok
|
claims = fetchClaimHandler.fetchClaimsByProject(projectId, null, null, keyword, orderby, descending, types, true);
|
235 |
47448
|
konstantin
|
} else {
|
236 |
50969
|
argiro.kok
|
claims = fetchClaimHandler.fetchClaimsByProject(projectId, limit, offset, keyword, orderby, descending, types, true);
|
237 |
47448
|
konstantin
|
}
|
238 |
50969
|
argiro.kok
|
total = fetchClaimHandler.countClaimsByProject(projectId, keyword, types);
|
239 |
47448
|
konstantin
|
|
240 |
47084
|
argiro.kok
|
return Response.status(200).entity(composeDataResponse(request, claims, total, offset, limit)).build();
|
241 |
|
|
}
|
242 |
|
|
|
243 |
47226
|
katerina.i
|
} catch (SQLStoreException|Exception e) {
|
244 |
47040
|
argiro.kok
|
logger.error("Could not fetch claims for project token " + projectToken, e);
|
245 |
|
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(compose500Message("Fail to fetch claims" +
|
246 |
|
|
" for projects with token " + projectToken + ".", e)).type(MediaType.APPLICATION_JSON).build();
|
247 |
|
|
}
|
248 |
52620
|
konstantin
|
// }
|
249 |
47040
|
argiro.kok
|
|
250 |
52620
|
konstantin
|
// return Response.status(Response.Status.FORBIDDEN).entity(compose403Message("Forbidden: You don't have permission to access"))
|
251 |
|
|
// .type(MediaType.APPLICATION_JSON)
|
252 |
|
|
// .build();
|
253 |
47040
|
argiro.kok
|
}
|
254 |
53619
|
konstantin
|
*/
|
255 |
|
|
|
256 |
42275
|
katerina.i
|
@GET
|
257 |
|
|
@Path("/contexts/{contextId}/claims")
|
258 |
43441
|
katerina.i
|
@Produces(MediaType.APPLICATION_JSON)
|
259 |
42277
|
katerina.i
|
public Response getContextClaims(@PathParam("contextId") String contextId,
|
260 |
42275
|
katerina.i
|
@DefaultValue("0") @QueryParam("offset") int offset,
|
261 |
42277
|
katerina.i
|
@DefaultValue("20") @QueryParam("limit") int limit,
|
262 |
42763
|
argiro.kok
|
@DefaultValue("") @QueryParam("keyword") String keyword,
|
263 |
|
|
@DefaultValue("") @QueryParam("sortby") String orderby,
|
264 |
|
|
@DefaultValue("true") @QueryParam("descending") boolean descending,
|
265 |
50969
|
argiro.kok
|
@DefaultValue("") @QueryParam("types") List<String> types,
|
266 |
48312
|
katerina.i
|
@HeaderParam("X-XSRF-TOKEN") String token,
|
267 |
|
|
@CookieParam("AccessToken") String cookie,
|
268 |
42277
|
katerina.i
|
@Context HttpServletRequest request) {
|
269 |
50969
|
argiro.kok
|
// @RequestParam(value="includeStates[]", defaultValue="1,2,3") String[] includeStates
|
270 |
42275
|
katerina.i
|
|
271 |
48312
|
katerina.i
|
if(token == null || token.isEmpty() || cookie == null || cookie.isEmpty() || !cookie.equals(token)){
|
272 |
50948
|
argiro.kok
|
authorization.logStatus(token,cookie);
|
273 |
48312
|
katerina.i
|
return Response.status(Response.Status.FORBIDDEN).entity(compose403Message("Forbidden: You don't have permission to access. Maybe you are not registered."))
|
274 |
46889
|
sofia.balt
|
.type(MediaType.APPLICATION_JSON)
|
275 |
|
|
.build();
|
276 |
42275
|
katerina.i
|
}
|
277 |
50969
|
argiro.kok
|
// logger.debug("Calling API for context with token " + token);
|
278 |
58705
|
argiro.kok
|
UserInfo userInfo = authorization.getUserHandler().getUserInfo(token);
|
279 |
|
|
if(authorization.isCommunityCurator(userInfo) || authorization.isClaimCurator(token) || this.emailSender.getCommunityUtils().isCommunityManager(contextId, userInfo.email)) {
|
280 |
46944
|
sofia.balt
|
|
281 |
46889
|
sofia.balt
|
int total = -1;
|
282 |
|
|
if (contextId == null || contextId.isEmpty()) {
|
283 |
|
|
return Response.status(Response.Status.BAD_REQUEST).entity(compose400Message("Context id cannot be empty."))
|
284 |
|
|
.type(MediaType.APPLICATION_JSON).build();
|
285 |
42763
|
argiro.kok
|
}
|
286 |
50969
|
argiro.kok
|
logger.debug("Types are " + types);
|
287 |
|
|
List<Claim> claims = null;
|
288 |
42275
|
katerina.i
|
|
289 |
46889
|
sofia.balt
|
try {
|
290 |
50969
|
argiro.kok
|
claims = fetchClaimHandler.fetchClaimsByContext(contextId, limit, offset, keyword, orderby, descending, types,false);
|
291 |
|
|
total = fetchClaimHandler.countClaimsByContext(contextId, keyword, types);
|
292 |
46889
|
sofia.balt
|
|
293 |
47226
|
katerina.i
|
} catch (SQLStoreException|Exception e) {
|
294 |
46889
|
sofia.balt
|
logger.error("Could not fetch claims for context with id " + contextId, e);
|
295 |
|
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(compose500Message("Fail to fetch claims" +
|
296 |
|
|
" for context with id " + contextId + ".", e)).type(MediaType.APPLICATION_JSON).build();
|
297 |
|
|
}
|
298 |
|
|
|
299 |
|
|
return Response.status(200).entity(composeDataResponse(request, claims, total, offset, limit)).build();
|
300 |
42275
|
katerina.i
|
}
|
301 |
|
|
|
302 |
46889
|
sofia.balt
|
return Response.status(Response.Status.FORBIDDEN).entity(compose403Message("Forbidden: You don't have permission to access"))
|
303 |
|
|
.type(MediaType.APPLICATION_JSON)
|
304 |
|
|
.build();
|
305 |
42275
|
katerina.i
|
}
|
306 |
|
|
|
307 |
42277
|
katerina.i
|
|
308 |
42275
|
katerina.i
|
@GET
|
309 |
|
|
@Path("/results/{resultId}/claims")
|
310 |
43441
|
katerina.i
|
@Produces(MediaType.APPLICATION_JSON)
|
311 |
42275
|
katerina.i
|
public Response getResultClaims(@PathParam("resultId") String resultId,
|
312 |
42277
|
katerina.i
|
@DefaultValue("0") @QueryParam("offset") int offset,
|
313 |
|
|
@DefaultValue("20") @QueryParam("limit") int limit,
|
314 |
42763
|
argiro.kok
|
@DefaultValue("") @QueryParam("keyword") String keyword,
|
315 |
|
|
@DefaultValue("") @QueryParam("sortby") String orderby,
|
316 |
|
|
@DefaultValue("true") @QueryParam("descending") boolean descending,
|
317 |
50969
|
argiro.kok
|
@DefaultValue("") @QueryParam("types") List<String> types,
|
318 |
48312
|
katerina.i
|
@HeaderParam("X-XSRF-TOKEN") String token,
|
319 |
|
|
@CookieParam("AccessToken") String cookie,
|
320 |
42277
|
katerina.i
|
@Context HttpServletRequest request) {
|
321 |
42275
|
katerina.i
|
|
322 |
51938
|
argiro.kok
|
|
323 |
48312
|
katerina.i
|
if(token == null || token.isEmpty() || cookie == null || cookie.isEmpty() || !cookie.equals(token)){
|
324 |
50948
|
argiro.kok
|
authorization.logStatus(token,cookie);
|
325 |
48312
|
katerina.i
|
return Response.status(Response.Status.FORBIDDEN).entity(compose403Message("Forbidden: You don't have permission to access. Maybe you are not registered."))
|
326 |
46890
|
sofia.balt
|
.type(MediaType.APPLICATION_JSON)
|
327 |
|
|
.build();
|
328 |
42275
|
katerina.i
|
}
|
329 |
46890
|
sofia.balt
|
|
330 |
51938
|
argiro.kok
|
if(authorization.isClaimCurator(token)) {
|
331 |
48312
|
katerina.i
|
|
332 |
46890
|
sofia.balt
|
int total = -1;
|
333 |
|
|
if (resultId == null || resultId.isEmpty()) {
|
334 |
|
|
return Response.status(Response.Status.BAD_REQUEST).entity(compose400Message("Context id cannot be empty."))
|
335 |
|
|
.type(MediaType.APPLICATION_JSON).build();
|
336 |
42763
|
argiro.kok
|
}
|
337 |
46887
|
sofia.balt
|
|
338 |
46890
|
sofia.balt
|
List<Claim> claims = null;
|
339 |
|
|
try {
|
340 |
50969
|
argiro.kok
|
claims = fetchClaimHandler.fetchClaimsByResult(resultId, limit, offset, keyword, orderby, descending, types,false);
|
341 |
|
|
total = fetchClaimHandler.countClaimsByResult(resultId, keyword, types);
|
342 |
46890
|
sofia.balt
|
|
343 |
47226
|
katerina.i
|
} catch (SQLStoreException|Exception e) {
|
344 |
46890
|
sofia.balt
|
logger.error("Could not fetch claims for result with id " + resultId, e);
|
345 |
|
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(compose500Message("Fail to fetch claims" +
|
346 |
|
|
" for result with id " + resultId + ".", e)).type(MediaType.APPLICATION_JSON).build();
|
347 |
|
|
}
|
348 |
|
|
|
349 |
|
|
return Response.status(200).entity(composeDataResponse(request, claims, total, offset, limit)).build();
|
350 |
42275
|
katerina.i
|
}
|
351 |
|
|
|
352 |
46890
|
sofia.balt
|
return Response.status(Response.Status.FORBIDDEN).entity(compose403Message("Forbidden: You don't have permission to access"))
|
353 |
|
|
.type(MediaType.APPLICATION_JSON)
|
354 |
|
|
.build();
|
355 |
42275
|
katerina.i
|
}
|
356 |
|
|
|
357 |
|
|
|
358 |
|
|
@GET
|
359 |
48312
|
katerina.i
|
@Path("/users/claims")
|
360 |
43441
|
katerina.i
|
@Produces(MediaType.APPLICATION_JSON)
|
361 |
48312
|
katerina.i
|
public Response getUserClaims(@DefaultValue("0") @QueryParam("offset") int offset,
|
362 |
46883
|
katerina.i
|
@DefaultValue("20") @QueryParam("limit") int limit,
|
363 |
|
|
@DefaultValue("") @QueryParam("keyword") String keyword,
|
364 |
|
|
@DefaultValue("") @QueryParam("sortby") String orderby,
|
365 |
|
|
@DefaultValue("true") @QueryParam("descending") boolean descending,
|
366 |
50969
|
argiro.kok
|
@DefaultValue("") @QueryParam("types") List<String> types,
|
367 |
48312
|
katerina.i
|
@HeaderParam("X-XSRF-TOKEN") String token,
|
368 |
|
|
@CookieParam("AccessToken") String cookie,
|
369 |
46883
|
katerina.i
|
@Context HttpServletRequest request) {
|
370 |
42275
|
katerina.i
|
|
371 |
51938
|
argiro.kok
|
|
372 |
48312
|
katerina.i
|
if(token == null || token.isEmpty() || cookie == null || cookie.isEmpty() || !cookie.equals(token)){
|
373 |
|
|
return Response.status(Response.Status.FORBIDDEN).entity(compose403Message("Forbidden: You don't have permission to access. Maybe you are not registered."))
|
374 |
46891
|
sofia.balt
|
.type(MediaType.APPLICATION_JSON)
|
375 |
|
|
.build();
|
376 |
42275
|
katerina.i
|
}
|
377 |
48312
|
katerina.i
|
|
378 |
|
|
UserInfo userInfo = authorization.getUserHandler().getUserInfo(token);
|
379 |
|
|
if(authorization.isRegistered(userInfo)) {
|
380 |
|
|
String userMail = userInfo.getEmail();
|
381 |
|
|
logger.debug("User is registerd " );
|
382 |
46891
|
sofia.balt
|
int total = -1;
|
383 |
|
|
EmailValidator emailValidator = EmailValidator.getInstance();
|
384 |
|
|
|
385 |
|
|
if (userMail == null || userMail.isEmpty()) {
|
386 |
|
|
return Response.status(Response.Status.BAD_REQUEST).entity(compose400Message("User e-mail cannot be empty."))
|
387 |
|
|
.type(MediaType.APPLICATION_JSON).build();
|
388 |
42763
|
argiro.kok
|
}
|
389 |
42275
|
katerina.i
|
|
390 |
46891
|
sofia.balt
|
if (!emailValidator.isValid(userMail)) {
|
391 |
|
|
return Response.status(Response.Status.BAD_REQUEST).entity(compose400Message("User e-mail is not valid."))
|
392 |
|
|
.type(MediaType.APPLICATION_JSON).build();
|
393 |
|
|
}
|
394 |
|
|
|
395 |
|
|
List<Claim> claims = null;
|
396 |
|
|
try {
|
397 |
48312
|
katerina.i
|
logger.debug("About to fetch claims" );
|
398 |
50969
|
argiro.kok
|
claims = fetchClaimHandler.fetchClaimsByUser(userMail, limit, offset, keyword, orderby, descending, types,false);
|
399 |
|
|
total = fetchClaimHandler.countClaimsByUser(userMail, keyword, types);
|
400 |
46891
|
sofia.balt
|
|
401 |
47226
|
katerina.i
|
} catch (SQLStoreException|Exception e) {
|
402 |
50323
|
argiro.kok
|
logger.error("Could not fetch claims for user with mail " + userMail, e);
|
403 |
46891
|
sofia.balt
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(compose500Message("Fail to fetch claims" +
|
404 |
|
|
" for user with e-mail " + userMail + ".", e)).type(MediaType.APPLICATION_JSON).build();
|
405 |
|
|
}
|
406 |
|
|
|
407 |
|
|
return Response.status(200).entity(composeDataResponse(request, claims, total, offset, limit)).build();
|
408 |
42275
|
katerina.i
|
}
|
409 |
48312
|
katerina.i
|
logger.debug("User is *NOT* registerd " );
|
410 |
46891
|
sofia.balt
|
return Response.status(Response.Status.FORBIDDEN).entity(compose403Message("Forbidden: You don't have permission to access. You are not registered."))
|
411 |
|
|
.type(MediaType.APPLICATION_JSON)
|
412 |
|
|
.build();
|
413 |
42275
|
katerina.i
|
}
|
414 |
|
|
|
415 |
|
|
@GET
|
416 |
|
|
@Path("/claims/{claimId}")
|
417 |
43441
|
katerina.i
|
@Produces(MediaType.APPLICATION_JSON)
|
418 |
42275
|
katerina.i
|
public Response getClaimsById(@PathParam("claimId") String claimId,
|
419 |
|
|
@DefaultValue("0") @QueryParam("offset") int offset,
|
420 |
42277
|
katerina.i
|
@DefaultValue("20") @QueryParam("limit") int limit,
|
421 |
48312
|
katerina.i
|
@HeaderParam("X-XSRF-TOKEN") String token,
|
422 |
|
|
@CookieParam("AccessToken") String cookie,
|
423 |
42277
|
katerina.i
|
@Context HttpServletRequest request) {
|
424 |
42275
|
katerina.i
|
|
425 |
51938
|
argiro.kok
|
|
426 |
48312
|
katerina.i
|
if(token == null || token.isEmpty() || cookie == null || cookie.isEmpty() || !cookie.equals(token)){
|
427 |
|
|
return Response.status(Response.Status.FORBIDDEN).entity(compose403Message("Forbidden: You don't have permission to access. Maybe you are not registered."))
|
428 |
46917
|
sofia.balt
|
.type(MediaType.APPLICATION_JSON)
|
429 |
|
|
.build();
|
430 |
|
|
}
|
431 |
42275
|
katerina.i
|
|
432 |
48312
|
katerina.i
|
if(authorization.isRegistered(token)) {
|
433 |
|
|
|
434 |
46917
|
sofia.balt
|
List<Claim> claims = null;
|
435 |
42275
|
katerina.i
|
|
436 |
46917
|
sofia.balt
|
int total = -1;
|
437 |
|
|
if (claimId == null || claimId.isEmpty()) {
|
438 |
|
|
try {
|
439 |
47009
|
argiro.kok
|
claims = fetchClaimHandler.fetchAllClaims(limit, offset,false);
|
440 |
46917
|
sofia.balt
|
total = fetchClaimHandler.countAllClaims("", new ArrayList<String>());
|
441 |
42277
|
katerina.i
|
|
442 |
46917
|
sofia.balt
|
return Response.status(200).entity(composeDataResponse(request, claims, total, offset, limit)).type(MediaType.APPLICATION_JSON).build();
|
443 |
42275
|
katerina.i
|
|
444 |
47226
|
katerina.i
|
} catch (SQLStoreException|Exception e) {
|
445 |
46917
|
sofia.balt
|
logger.error("Could not fetch claims.", e);
|
446 |
|
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(compose500Message("Fail to fetch claims.", e))
|
447 |
|
|
.type(MediaType.APPLICATION_JSON).build();
|
448 |
|
|
}
|
449 |
42277
|
katerina.i
|
}
|
450 |
42275
|
katerina.i
|
|
451 |
46917
|
sofia.balt
|
try {
|
452 |
47009
|
argiro.kok
|
Claim claim = fetchClaimHandler.fetchClaimById(claimId,false);
|
453 |
46917
|
sofia.balt
|
if (claim == null) {
|
454 |
|
|
return Response.status(Response.Status.NOT_FOUND).entity(compose404Message("Cannot find claim with id " + claimId + "."))
|
455 |
|
|
.type(MediaType.APPLICATION_JSON).build();
|
456 |
|
|
}
|
457 |
42277
|
katerina.i
|
|
458 |
47217
|
katerina.i
|
return Response.status(200).entity(composeDataResponse(claim)).build();
|
459 |
46917
|
sofia.balt
|
|
460 |
47226
|
katerina.i
|
} catch (SQLStoreException|Exception e) {
|
461 |
46917
|
sofia.balt
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(compose500Message("Fail to fetch claim " +
|
462 |
|
|
"with id " + claimId + " id.", e)).type(MediaType.APPLICATION_JSON).build();
|
463 |
|
|
}
|
464 |
42275
|
katerina.i
|
}
|
465 |
46917
|
sofia.balt
|
return Response.status(Response.Status.FORBIDDEN).entity(compose403Message("Forbidden: You don't have permission to access. You are not registered."))
|
466 |
|
|
.type(MediaType.APPLICATION_JSON)
|
467 |
|
|
.build();
|
468 |
42275
|
katerina.i
|
}
|
469 |
|
|
|
470 |
42277
|
katerina.i
|
@GET
|
471 |
|
|
@Path("/claims")
|
472 |
43441
|
katerina.i
|
@Produces(MediaType.APPLICATION_JSON)
|
473 |
46789
|
sofia.balt
|
public Response getAllClaims(@DefaultValue("0") @QueryParam("offset") int offset,
|
474 |
42277
|
katerina.i
|
@DefaultValue("20") @QueryParam("limit") int limit,
|
475 |
42763
|
argiro.kok
|
@DefaultValue("") @QueryParam("keyword") String keyword,
|
476 |
|
|
@DefaultValue("date") @QueryParam("sortby") String orderby,
|
477 |
|
|
@DefaultValue("true") @QueryParam("descending") boolean descending,
|
478 |
50969
|
argiro.kok
|
@DefaultValue("") @QueryParam("types") List<String> types,
|
479 |
48312
|
katerina.i
|
@HeaderParam("X-XSRF-TOKEN") String token,
|
480 |
|
|
@HeaderParam("Origin") String origin,
|
481 |
|
|
@CookieParam("AccessToken") String cookie,
|
482 |
42277
|
katerina.i
|
@Context HttpServletRequest request) {
|
483 |
42275
|
katerina.i
|
|
484 |
51938
|
argiro.kok
|
|
485 |
48312
|
katerina.i
|
logger.debug("Header \"Origin\" has value " + origin);
|
486 |
|
|
|
487 |
|
|
|
488 |
51938
|
argiro.kok
|
|
489 |
48312
|
katerina.i
|
if(token == null || token.isEmpty() || cookie == null || cookie.isEmpty() || !cookie.equals(token)){
|
490 |
|
|
logger.debug("User is not authorized - Eroor 403");
|
491 |
|
|
|
492 |
|
|
return Response.status(Response.Status.FORBIDDEN).entity(compose403Message("Forbidden: You don't have permission to access. Maybe you are not registered."))
|
493 |
46806
|
sofia.balt
|
.type(MediaType.APPLICATION_JSON)
|
494 |
|
|
.build();
|
495 |
46789
|
sofia.balt
|
}
|
496 |
46887
|
sofia.balt
|
|
497 |
51938
|
argiro.kok
|
if(authorization.isClaimCurator(token)) {
|
498 |
48312
|
katerina.i
|
logger.debug("User is authorized ! !");
|
499 |
46887
|
sofia.balt
|
List<Claim> claims = null;
|
500 |
51938
|
argiro.kok
|
|
501 |
46887
|
sofia.balt
|
int total = -1;
|
502 |
|
|
try {
|
503 |
50969
|
argiro.kok
|
claims = fetchClaimHandler.fetchAllClaims(limit, offset, keyword, orderby, descending, types,false);
|
504 |
|
|
total = fetchClaimHandler.countAllClaims(keyword, types);
|
505 |
42277
|
katerina.i
|
|
506 |
46887
|
sofia.balt
|
return Response.status(200).entity(composeDataResponse(request, claims, total, offset, limit)).build();
|
507 |
42277
|
katerina.i
|
|
508 |
47226
|
katerina.i
|
} catch (SQLStoreException|Exception e) {
|
509 |
46887
|
sofia.balt
|
logger.error("Could not fetch claims.", e);
|
510 |
|
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(compose500Message("Fail to fetch claims.", e))
|
511 |
|
|
.type(MediaType.APPLICATION_JSON).build();
|
512 |
|
|
}
|
513 |
42277
|
katerina.i
|
}
|
514 |
46888
|
sofia.balt
|
|
515 |
|
|
return Response.status(Response.Status.FORBIDDEN).entity(compose403Message("Forbidden: You don't have permission to access"))
|
516 |
|
|
.type(MediaType.APPLICATION_JSON)
|
517 |
|
|
.build();
|
518 |
42277
|
katerina.i
|
}
|
519 |
|
|
|
520 |
42763
|
argiro.kok
|
@DELETE
|
521 |
46944
|
sofia.balt
|
@Path("/claims/bulk")
|
522 |
|
|
@Produces(MediaType.APPLICATION_JSON)
|
523 |
|
|
public Response deleteBulkClaims(@QueryParam("claimId") List<String> claimIds,
|
524 |
48312
|
katerina.i
|
@HeaderParam("X-XSRF-TOKEN") String token,
|
525 |
|
|
@HeaderParam("Origin") String origin,
|
526 |
|
|
@CookieParam("AccessToken") String cookie){
|
527 |
46917
|
sofia.balt
|
|
528 |
|
|
|
529 |
51938
|
argiro.kok
|
|
530 |
58338
|
argiro.kok
|
if(!authorization.hasBasicAuthorization(token, origin, cookie)){
|
531 |
48312
|
katerina.i
|
return Response.status(Response.Status.FORBIDDEN).entity(compose403Message("Forbidden: You don't have permission to access. Maybe you are not registered."))
|
532 |
|
|
.type(MediaType.APPLICATION_JSON)
|
533 |
|
|
.build();
|
534 |
|
|
}
|
535 |
|
|
|
536 |
|
|
|
537 |
46944
|
sofia.balt
|
ArrayList<String> deletedIds= new ArrayList<String>();
|
538 |
|
|
ArrayList<String> notFoundIds= new ArrayList<String>();
|
539 |
47217
|
katerina.i
|
|
540 |
46944
|
sofia.balt
|
if (claimIds == null || claimIds.size() == 0) {
|
541 |
|
|
return Response.status(Response.Status.NOT_FOUND).entity(compose404BulkDeleteMessage("Claim ids cannot be empty.",deletedIds,notFoundIds))
|
542 |
|
|
.type(MediaType.APPLICATION_JSON).build();
|
543 |
|
|
}
|
544 |
42763
|
argiro.kok
|
|
545 |
47217
|
katerina.i
|
logger.debug("Trying to delete claims with ids: " + claimIds.toString() + ".");
|
546 |
48572
|
argiro.kok
|
UserInfo userInfo = authorization.getUserHandler().getUserInfo(token);
|
547 |
46944
|
sofia.balt
|
for (String claimId : claimIds) {
|
548 |
|
|
try {
|
549 |
46906
|
sofia.balt
|
|
550 |
48572
|
argiro.kok
|
if (authorization.isRegistered(userInfo)) {
|
551 |
51938
|
argiro.kok
|
if (authorization.isClaimCurator(userInfo) || authorization.isCommunityCurator(userInfo) || userInfo.getEmail().equals(fetchClaimHandler.fetchClaimById(claimId,false).getUserMail())) {
|
552 |
46944
|
sofia.balt
|
if (claimHandler.deleteClaim(claimId)) {
|
553 |
|
|
deletedIds.add(claimId);
|
554 |
|
|
} else {
|
555 |
|
|
notFoundIds.add(claimId);
|
556 |
|
|
}
|
557 |
46906
|
sofia.balt
|
} else {
|
558 |
46944
|
sofia.balt
|
return Response.status(Response.Status.FORBIDDEN).entity(compose403Message("Forbidden: You don't have permission to delete."))
|
559 |
|
|
.type(MediaType.APPLICATION_JSON)
|
560 |
|
|
.build();
|
561 |
46906
|
sofia.balt
|
}
|
562 |
|
|
} else {
|
563 |
46944
|
sofia.balt
|
return Response.status(Response.Status.FORBIDDEN).entity(compose403Message("Forbidden: You don't have permission to access. Maybe you are not registered."))
|
564 |
46906
|
sofia.balt
|
.type(MediaType.APPLICATION_JSON)
|
565 |
|
|
.build();
|
566 |
|
|
}
|
567 |
47226
|
katerina.i
|
} catch (SQLStoreException|Exception e) {
|
568 |
46944
|
sofia.balt
|
logger.error("Fail to delete claim with id " + claimId + ".", e);
|
569 |
|
|
notFoundIds.add(claimId);
|
570 |
45960
|
argiro.kok
|
}
|
571 |
|
|
}
|
572 |
46944
|
sofia.balt
|
logger.debug("Successfully deleted " + deletedIds.size() + " from " + claimIds.size() +". Deleted claims with ids: " + deletedIds.toString() + ".");
|
573 |
|
|
if (claimIds.size() == notFoundIds.size()) {
|
574 |
|
|
return Response.status(Response.Status.NOT_FOUND).entity(compose404BulkDeleteMessage("Claim ids cannot be empty.",deletedIds,notFoundIds))
|
575 |
|
|
.type(MediaType.APPLICATION_JSON).build();
|
576 |
|
|
} else if (claimIds.size() == notFoundIds.size()) {
|
577 |
|
|
return Response.status(204).entity(compose204BulkDeleteMessage(deletedIds,notFoundIds)).type(MediaType.APPLICATION_JSON).build();
|
578 |
|
|
} else {
|
579 |
|
|
return Response.status(204).entity(compose204BulkDeleteMessage(deletedIds,notFoundIds)).type(MediaType.APPLICATION_JSON).build();
|
580 |
|
|
}
|
581 |
45960
|
argiro.kok
|
}
|
582 |
|
|
|
583 |
42275
|
katerina.i
|
@POST
|
584 |
42291
|
katerina.i
|
@Path("/claims")
|
585 |
42275
|
katerina.i
|
@Produces(MediaType.APPLICATION_JSON)
|
586 |
|
|
@Consumes(MediaType.APPLICATION_JSON)
|
587 |
46883
|
katerina.i
|
public Response addClaim(String input, @Context HttpServletRequest request,
|
588 |
48312
|
katerina.i
|
@HeaderParam("X-XSRF-TOKEN") String token,
|
589 |
|
|
@HeaderParam("Origin") String origin,
|
590 |
|
|
@CookieParam("AccessToken") String cookie) {
|
591 |
42291
|
katerina.i
|
|
592 |
51938
|
argiro.kok
|
|
593 |
58338
|
argiro.kok
|
if(!authorization.hasBasicAuthorization(token, origin, cookie)){
|
594 |
48312
|
katerina.i
|
return Response.status(Response.Status.FORBIDDEN).entity(compose403Message("Forbidden: You don't have permission to access. Maybe you are not registered."))
|
595 |
46917
|
sofia.balt
|
.type(MediaType.APPLICATION_JSON)
|
596 |
|
|
.build();
|
597 |
|
|
}
|
598 |
48312
|
katerina.i
|
|
599 |
|
|
UserInfo userInfo = authorization.getUserHandler().getUserInfo(token);
|
600 |
|
|
if(authorization.isRegistered(userInfo)) {
|
601 |
46917
|
sofia.balt
|
JsonObject jsonObject = new JsonParser().parse(input).getAsJsonObject();
|
602 |
42275
|
katerina.i
|
|
603 |
48312
|
katerina.i
|
String claimedBy = userInfo.getEmail();
|
604 |
46917
|
sofia.balt
|
logger.info("claimedBy " + claimedBy);
|
605 |
42291
|
katerina.i
|
|
606 |
46917
|
sofia.balt
|
EmailValidator emailValidator = EmailValidator.getInstance();
|
607 |
|
|
if (!emailValidator.isValid(claimedBy)) {
|
608 |
|
|
return Response.status(Response.Status.BAD_REQUEST).entity(compose400Message("User e-mail is invalid."))
|
609 |
|
|
.type(MediaType.APPLICATION_JSON).build();
|
610 |
|
|
}
|
611 |
42291
|
katerina.i
|
|
612 |
|
|
|
613 |
46917
|
sofia.balt
|
try {
|
614 |
58338
|
argiro.kok
|
String claimId = this.getInfoAndBuildClaim(jsonObject,claimedBy);
|
615 |
46917
|
sofia.balt
|
return Response.status(200).entity(compose201PostMessage(request, claimId)).type(MediaType.APPLICATION_JSON).build();
|
616 |
42275
|
katerina.i
|
|
617 |
46917
|
sofia.balt
|
} catch (ClaimValidationException ve) {
|
618 |
|
|
return Response.status(Response.Status.BAD_REQUEST).entity(compose400Message("The given ids are wrong.", ve))
|
619 |
|
|
.type(MediaType.APPLICATION_JSON).build();
|
620 |
42291
|
katerina.i
|
|
621 |
47226
|
katerina.i
|
} catch (SQLStoreException|Exception e) {
|
622 |
46917
|
sofia.balt
|
logger.error("Fail to add new claim.", e);
|
623 |
|
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(compose500Message("Fail to add new claim.", e))
|
624 |
|
|
.type(MediaType.APPLICATION_JSON).build();
|
625 |
|
|
}
|
626 |
42275
|
katerina.i
|
}
|
627 |
46917
|
sofia.balt
|
return Response.status(Response.Status.FORBIDDEN).entity(compose403Message("Forbidden: You don't have permission to access."))
|
628 |
|
|
.type(MediaType.APPLICATION_JSON)
|
629 |
|
|
.build();
|
630 |
42291
|
katerina.i
|
}
|
631 |
42275
|
katerina.i
|
|
632 |
45960
|
argiro.kok
|
@POST
|
633 |
|
|
@Path("/claims/bulk")
|
634 |
|
|
@Produces(MediaType.APPLICATION_JSON)
|
635 |
|
|
@Consumes(MediaType.APPLICATION_JSON)
|
636 |
46883
|
katerina.i
|
public Response addBulkClaims(String input, @Context HttpServletRequest request,
|
637 |
48312
|
katerina.i
|
@HeaderParam("X-XSRF-TOKEN") String token,
|
638 |
|
|
@HeaderParam("Origin") String origin,
|
639 |
|
|
@CookieParam("AccessToken") String cookie) {
|
640 |
45960
|
argiro.kok
|
|
641 |
51938
|
argiro.kok
|
|
642 |
58338
|
argiro.kok
|
if(!authorization.hasBasicAuthorization(token, origin, cookie)){
|
643 |
48312
|
katerina.i
|
return Response.status(Response.Status.FORBIDDEN).entity(compose403Message("Forbidden: You don't have permission to access. Maybe you are not registered."))
|
644 |
46917
|
sofia.balt
|
.type(MediaType.APPLICATION_JSON)
|
645 |
|
|
.build();
|
646 |
|
|
}
|
647 |
48312
|
katerina.i
|
|
648 |
|
|
UserInfo userInfo = authorization.getUserHandler().getUserInfo(token);
|
649 |
|
|
if(authorization.isRegistered(userInfo)) {
|
650 |
46893
|
sofia.balt
|
ArrayList<String> insertedIds = new ArrayList<String>();
|
651 |
|
|
JsonArray errorInClaims = new JsonArray();
|
652 |
47217
|
katerina.i
|
|
653 |
46893
|
sofia.balt
|
int code200 = 0;
|
654 |
|
|
int code400 = 0;
|
655 |
|
|
int code500 = 0;
|
656 |
47217
|
katerina.i
|
|
657 |
46893
|
sofia.balt
|
JsonArray jsonArray = new JsonParser().parse(input).getAsJsonArray();
|
658 |
|
|
for (JsonElement je : jsonArray) {
|
659 |
|
|
JsonObject jsonObject = je.getAsJsonObject();
|
660 |
45960
|
argiro.kok
|
|
661 |
48312
|
katerina.i
|
String claimedBy = userInfo.getEmail();
|
662 |
46893
|
sofia.balt
|
logger.info("claimedBy " + claimedBy);
|
663 |
58338
|
argiro.kok
|
logger.debug(jsonObject);
|
664 |
45960
|
argiro.kok
|
|
665 |
|
|
|
666 |
46893
|
sofia.balt
|
EmailValidator emailValidator = EmailValidator.getInstance();
|
667 |
|
|
if (!emailValidator.isValid(claimedBy)) {
|
668 |
|
|
jsonObject.addProperty("error", "user");
|
669 |
58338
|
argiro.kok
|
logger.error("no valid user");
|
670 |
46893
|
sofia.balt
|
// return Response.status(Response.Status.BAD_REQUEST).entity(compose400Message("User e-mail is invalid."))
|
671 |
|
|
// .type(MediaType.APPLICATION_JSON).build();
|
672 |
|
|
code400++;
|
673 |
|
|
errorInClaims.add(jsonObject);
|
674 |
|
|
}
|
675 |
45960
|
argiro.kok
|
|
676 |
|
|
|
677 |
46893
|
sofia.balt
|
try {
|
678 |
58338
|
argiro.kok
|
String claimId = this.getInfoAndBuildClaim(jsonObject,claimedBy);
|
679 |
46893
|
sofia.balt
|
insertedIds.add(claimId);
|
680 |
|
|
code200++;
|
681 |
|
|
// return Response.status(200).entity(compose201PostMessage(request, claimId)).type(MediaType.APPLICATION_JSON).build();
|
682 |
45960
|
argiro.kok
|
|
683 |
46893
|
sofia.balt
|
} catch (ClaimValidationException ve) {
|
684 |
58338
|
argiro.kok
|
// logger.error("Validation Failed fo claim "+jsonObject);
|
685 |
46893
|
sofia.balt
|
// return Response.status(Response.Status.BAD_REQUEST).entity(compose400Message("The given ids are wrong.", ve))
|
686 |
|
|
// .type(MediaType.APPLICATION_JSON).build();
|
687 |
|
|
jsonObject.addProperty("error", "validation");
|
688 |
|
|
errorInClaims.add(jsonObject);
|
689 |
|
|
code400++;
|
690 |
|
|
|
691 |
47226
|
katerina.i
|
} catch (SQLStoreException|Exception e) {
|
692 |
58338
|
argiro.kok
|
logger.error("Fail to add new claim.", e);
|
693 |
46893
|
sofia.balt
|
// return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(compose500Message("Fail to add new claim.", e))
|
694 |
|
|
// .type(MediaType.APPLICATION_JSON).build();
|
695 |
|
|
jsonObject.addProperty("error", "insertion");
|
696 |
|
|
errorInClaims.add(jsonObject);
|
697 |
|
|
code500++;
|
698 |
|
|
}
|
699 |
45960
|
argiro.kok
|
}
|
700 |
46893
|
sofia.balt
|
if (jsonArray.size() == code500) {
|
701 |
|
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(compose500BulkInsertMessage("Fail to add new claim.", insertedIds, errorInClaims))
|
702 |
|
|
.type(MediaType.APPLICATION_JSON).build();
|
703 |
|
|
} else if (code200 > 0) {
|
704 |
47217
|
katerina.i
|
return Response.status(200).entity(compose201BulkInsertMessage(insertedIds, errorInClaims)).type(MediaType.APPLICATION_JSON).build();
|
705 |
46893
|
sofia.balt
|
} else {
|
706 |
|
|
return Response.status(Response.Status.BAD_REQUEST).entity(compose400BulkInsertMessage("The given ids are wrong.", insertedIds, errorInClaims))
|
707 |
|
|
.type(MediaType.APPLICATION_JSON).build();
|
708 |
|
|
}
|
709 |
45960
|
argiro.kok
|
}
|
710 |
46893
|
sofia.balt
|
return Response.status(Response.Status.FORBIDDEN).entity(compose403Message("Forbidden: You don't have permission to access. You are not registered."))
|
711 |
|
|
.type(MediaType.APPLICATION_JSON)
|
712 |
|
|
.build();
|
713 |
45960
|
argiro.kok
|
|
714 |
|
|
}
|
715 |
47009
|
argiro.kok
|
@POST
|
716 |
|
|
@Path("/curate/bulk")
|
717 |
|
|
@Produces(MediaType.APPLICATION_JSON)
|
718 |
|
|
@Consumes(MediaType.APPLICATION_JSON)
|
719 |
|
|
public Response curateBulkClaims(String input, @Context HttpServletRequest request,
|
720 |
48312
|
katerina.i
|
@HeaderParam("X-XSRF-TOKEN") String token,
|
721 |
|
|
@HeaderParam("Origin") String origin,
|
722 |
|
|
@CookieParam("AccessToken") String cookie) {
|
723 |
45960
|
argiro.kok
|
|
724 |
51938
|
argiro.kok
|
|
725 |
58338
|
argiro.kok
|
if(!authorization.hasBasicAuthorization(token, origin, cookie)){
|
726 |
48312
|
katerina.i
|
return Response.status(Response.Status.FORBIDDEN).entity(compose403Message("Forbidden: You don't have permission to access. Maybe you are not registered."))
|
727 |
47009
|
argiro.kok
|
.type(MediaType.APPLICATION_JSON)
|
728 |
|
|
.build();
|
729 |
|
|
}
|
730 |
48572
|
argiro.kok
|
UserInfo userInfo = authorization.getUserHandler().getUserInfo(token);
|
731 |
|
|
if (authorization.isRegistered(userInfo)) {
|
732 |
47009
|
argiro.kok
|
ArrayList<String> insertedIds = new ArrayList<String>();
|
733 |
|
|
JsonArray errorInClaims = new JsonArray();
|
734 |
|
|
int code200 = 0;
|
735 |
|
|
int code400 = 0;
|
736 |
|
|
int code500 = 0;
|
737 |
|
|
JsonArray jsonArray = new JsonParser().parse(input).getAsJsonArray();
|
738 |
48572
|
argiro.kok
|
String curatedBy =userInfo.getEmail();
|
739 |
47009
|
argiro.kok
|
|
740 |
|
|
for (JsonElement je : jsonArray) {
|
741 |
|
|
JsonObject jsonObject = je.getAsJsonObject();
|
742 |
|
|
|
743 |
|
|
String id = jsonObject.get("id").getAsString();
|
744 |
|
|
logger.info("id " + id);
|
745 |
|
|
|
746 |
|
|
Boolean approved = jsonObject.get("approved").getAsBoolean();
|
747 |
|
|
logger.info("approved " + approved);
|
748 |
|
|
EmailValidator emailValidator = EmailValidator.getInstance();
|
749 |
|
|
if (!emailValidator.isValid(curatedBy)) {
|
750 |
|
|
jsonObject.addProperty("error", "user");
|
751 |
|
|
// return Response.status(Response.Status.BAD_REQUEST).entity(compose400Message("User e-mail is invalid."))
|
752 |
|
|
// .type(MediaType.APPLICATION_JSON).build();
|
753 |
|
|
code400++;
|
754 |
|
|
errorInClaims.add(jsonObject);
|
755 |
|
|
}
|
756 |
|
|
|
757 |
|
|
try {
|
758 |
|
|
claimHandler.updateClaimCurationInfo(curatedBy,id, approved);
|
759 |
|
|
insertedIds.add(id);
|
760 |
|
|
code200++;
|
761 |
|
|
|
762 |
47226
|
katerina.i
|
} catch (SQLStoreException|Exception e) {
|
763 |
47009
|
argiro.kok
|
jsonObject.addProperty("error", "insertion");
|
764 |
|
|
errorInClaims.add(jsonObject);
|
765 |
|
|
code500++;
|
766 |
|
|
}
|
767 |
|
|
}
|
768 |
|
|
if (jsonArray.size() == code500) {
|
769 |
|
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(compose500BulkInsertMessage("Fail to update claims.", insertedIds, errorInClaims))
|
770 |
|
|
.type(MediaType.APPLICATION_JSON).build();
|
771 |
|
|
} else if (code200 > 0) {
|
772 |
47217
|
katerina.i
|
return Response.status(200).entity(compose201BulkInsertMessage(insertedIds, errorInClaims)).type(MediaType.APPLICATION_JSON).build();
|
773 |
47009
|
argiro.kok
|
} else {
|
774 |
|
|
return Response.status(Response.Status.BAD_REQUEST).entity(compose400BulkInsertMessage("The given ids are wrong.", insertedIds, errorInClaims))
|
775 |
|
|
.type(MediaType.APPLICATION_JSON).build();
|
776 |
|
|
}
|
777 |
|
|
}
|
778 |
|
|
return Response.status(Response.Status.FORBIDDEN).entity(compose403Message("Forbidden: You don't have permission to access. You are not registered."))
|
779 |
|
|
.type(MediaType.APPLICATION_JSON)
|
780 |
|
|
.build();
|
781 |
|
|
|
782 |
|
|
}
|
783 |
46979
|
argiro.kok
|
@POST
|
784 |
|
|
@Path("/feed/bulk")
|
785 |
|
|
@Produces(MediaType.APPLICATION_JSON)
|
786 |
|
|
@Consumes(MediaType.APPLICATION_JSON)
|
787 |
48312
|
katerina.i
|
public Response feedBulkRecords(String input, @Context HttpServletRequest request,
|
788 |
|
|
@HeaderParam("X-XSRF-TOKEN") String token,
|
789 |
|
|
@HeaderParam("Origin") String origin,
|
790 |
|
|
@CookieParam("AccessToken") String cookie) {
|
791 |
46979
|
argiro.kok
|
|
792 |
50948
|
argiro.kok
|
|
793 |
58338
|
argiro.kok
|
if(!authorization.hasBasicAuthorization(token, origin, cookie)){
|
794 |
51938
|
argiro.kok
|
|
795 |
48312
|
katerina.i
|
return Response.status(Response.Status.FORBIDDEN).entity(compose403Message("Forbidden: You don't have permission to access. Maybe you are not registered."))
|
796 |
46979
|
argiro.kok
|
.type(MediaType.APPLICATION_JSON)
|
797 |
|
|
.build();
|
798 |
|
|
}
|
799 |
48312
|
katerina.i
|
|
800 |
|
|
if (authorization.isRegistered(token)) {
|
801 |
46979
|
argiro.kok
|
ArrayList<String> insertedIds = new ArrayList<String>();
|
802 |
|
|
JsonArray errorInClaims = new JsonArray();
|
803 |
|
|
int code200 = 0;
|
804 |
|
|
int code400 = 0;
|
805 |
|
|
int code500 = 0;
|
806 |
|
|
JsonArray jsonArray = new JsonParser().parse(input).getAsJsonArray();
|
807 |
|
|
for (JsonElement je : jsonArray) {
|
808 |
|
|
JsonObject jsonObject = je.getAsJsonObject();
|
809 |
|
|
Boolean inserted = directIndexHandler.insertRecord(new Gson().toJson(jsonObject.get("record")));
|
810 |
|
|
if (inserted) {
|
811 |
|
|
insertedIds.add(jsonObject.get("id").getAsString());
|
812 |
|
|
code200++;
|
813 |
|
|
} else {
|
814 |
|
|
errorInClaims.add(jsonObject.get("id").getAsString());
|
815 |
|
|
code400++;
|
816 |
|
|
}
|
817 |
|
|
|
818 |
|
|
|
819 |
|
|
}
|
820 |
|
|
if (jsonArray.size() == code500) {
|
821 |
|
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(compose500BulkInsertMessage("Fail to add new claim.", insertedIds, errorInClaims))
|
822 |
|
|
.type(MediaType.APPLICATION_JSON).build();
|
823 |
|
|
} else if (code200 > 0) {
|
824 |
47217
|
katerina.i
|
return Response.status(200).entity(compose201BulkInsertMessage(insertedIds, errorInClaims)).type(MediaType.APPLICATION_JSON).build();
|
825 |
46979
|
argiro.kok
|
} else {
|
826 |
|
|
return Response.status(Response.Status.BAD_REQUEST).entity(compose400BulkInsertMessage("The given ids are wrong.", insertedIds, errorInClaims))
|
827 |
|
|
.type(MediaType.APPLICATION_JSON).build();
|
828 |
|
|
}
|
829 |
|
|
}
|
830 |
|
|
return Response.status(Response.Status.FORBIDDEN).entity(compose403Message("Forbidden: You don't have permission to access. You are not registered."))
|
831 |
|
|
.type(MediaType.APPLICATION_JSON)
|
832 |
|
|
.build();
|
833 |
|
|
|
834 |
|
|
}
|
835 |
|
|
|
836 |
42275
|
katerina.i
|
@GET
|
837 |
53619
|
konstantin
|
@Path("/users/notification")
|
838 |
|
|
@Produces(MediaType.APPLICATION_JSON)
|
839 |
|
|
public Response getUserEmailNotificationPreferences(@QueryParam("communityId") String openaireId,
|
840 |
|
|
@HeaderParam("X-XSRF-TOKEN") String token,
|
841 |
|
|
@CookieParam("AccessToken") String cookie,
|
842 |
|
|
@Context HttpServletRequest request) {
|
843 |
|
|
|
844 |
|
|
if(token == null || token.isEmpty() || cookie == null || cookie.isEmpty() || !cookie.equals(token)){
|
845 |
|
|
return Response.status(Response.Status.FORBIDDEN).entity(compose403Message("Forbidden: You don't have permission to access. Maybe you are not registered."))
|
846 |
|
|
.type(MediaType.APPLICATION_JSON)
|
847 |
|
|
.build();
|
848 |
|
|
}
|
849 |
|
|
|
850 |
|
|
UserInfo userInfo = authorization.getUserHandler().getUserInfo(token);
|
851 |
|
|
if(authorization.isRegistered(userInfo)) {
|
852 |
|
|
String userMail = userInfo.getEmail();
|
853 |
|
|
logger.debug("User is registerd " );
|
854 |
|
|
|
855 |
|
|
EmailValidator emailValidator = EmailValidator.getInstance();
|
856 |
|
|
|
857 |
|
|
if (userMail == null || userMail.isEmpty()) {
|
858 |
|
|
return Response.status(Response.Status.BAD_REQUEST).entity(compose400Message("User e-mail cannot be empty."))
|
859 |
|
|
.type(MediaType.APPLICATION_JSON).build();
|
860 |
|
|
}
|
861 |
|
|
|
862 |
|
|
if (!emailValidator.isValid(userMail)) {
|
863 |
|
|
return Response.status(Response.Status.BAD_REQUEST).entity(compose400Message("User e-mail is not valid."))
|
864 |
|
|
.type(MediaType.APPLICATION_JSON).build();
|
865 |
|
|
}
|
866 |
|
|
|
867 |
|
|
List<Notification> notifications = null;
|
868 |
|
|
try {
|
869 |
|
|
if(openaireId != null) {
|
870 |
58705
|
argiro.kok
|
CommunityUtils communityInfo = this.emailSender.getCommunityUtils().getCommunityInfo(openaireId);
|
871 |
60399
|
argiro.kok
|
if(communityInfo.getManagers().contains(userMail) || authorization.isCommunityCurator(userInfo)) {
|
872 |
53619
|
konstantin
|
|
873 |
|
|
Notification notification = null;
|
874 |
|
|
logger.debug("About to fetch notification");
|
875 |
|
|
notification = fetchNotificationHandler.fetchNotification(openaireId, userMail);
|
876 |
|
|
|
877 |
|
|
if (notifications == null) {
|
878 |
|
|
notifications = new ArrayList<Notification>();
|
879 |
|
|
}
|
880 |
|
|
if (notification == null) {
|
881 |
|
|
notification = new Notification(openaireId, communityInfo.getName(), userMail, Integer.parseInt(defaultFrequencyInHours), true);
|
882 |
|
|
} else {
|
883 |
|
|
notification.setOpenaireName(communityInfo.getName());
|
884 |
|
|
}
|
885 |
|
|
notifications.add(notification);
|
886 |
|
|
}
|
887 |
|
|
} else {
|
888 |
|
|
Map<String, String> projectIdsAndNames = fetchProjectHandler.fetchProjectIdsAndNamesByProjectManagerMail(userMail);
|
889 |
|
|
if(projectIdsAndNames != null) {
|
890 |
|
|
for (Map.Entry<String, String> projectIdAndName : projectIdsAndNames.entrySet()) {
|
891 |
|
|
Notification notification = null;
|
892 |
|
|
logger.debug("About to fetch notification");
|
893 |
|
|
notification = fetchNotificationHandler.fetchNotification(projectIdAndName.getKey(), userMail);
|
894 |
|
|
|
895 |
|
|
if (notifications == null) {
|
896 |
|
|
notifications = new ArrayList<Notification>();
|
897 |
|
|
}
|
898 |
|
|
if(notification == null) {
|
899 |
|
|
notification = new Notification(projectIdAndName.getKey(), projectIdAndName.getValue(), userMail, Integer.parseInt(defaultFrequencyInHours), true);
|
900 |
|
|
} else {
|
901 |
|
|
notification.setOpenaireName(projectIdAndName.getValue());
|
902 |
|
|
}
|
903 |
|
|
notifications.add(notification);
|
904 |
|
|
logger.debug(notification);
|
905 |
|
|
logger.debug("notification openaireId:"+notification.getOpenaireId());
|
906 |
|
|
logger.debug(notifications.size());
|
907 |
|
|
}
|
908 |
|
|
}
|
909 |
|
|
}
|
910 |
|
|
|
911 |
|
|
} catch (SQLStoreException|Exception e) {
|
912 |
|
|
logger.error("Could not fetch notification preferences for user with mail " + userMail, e);
|
913 |
|
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(compose500Message("Fail to fetch notification preferences" +
|
914 |
|
|
" for user with e-mail " + userMail + ".", e)).type(MediaType.APPLICATION_JSON).build();
|
915 |
|
|
}
|
916 |
|
|
|
917 |
|
|
if (notifications == null || notifications.isEmpty()) {
|
918 |
|
|
return Response.status(204).entity(compose204Message("There are no notifications for user with mail " + userMail)).type(MediaType.APPLICATION_JSON).build();
|
919 |
|
|
}
|
920 |
|
|
|
921 |
|
|
return Response.status(200).entity(composeDataResponse(notifications)).build();
|
922 |
|
|
|
923 |
|
|
}
|
924 |
|
|
logger.debug("User is *NOT* registerd " );
|
925 |
|
|
return Response.status(Response.Status.FORBIDDEN).entity(compose403Message("Forbidden: You don't have permission to access. You are not registered."))
|
926 |
|
|
.type(MediaType.APPLICATION_JSON)
|
927 |
|
|
.build();
|
928 |
|
|
}
|
929 |
|
|
|
930 |
|
|
@POST
|
931 |
|
|
@Path("/users/notification/save")
|
932 |
|
|
@Produces(MediaType.APPLICATION_JSON)
|
933 |
|
|
@Consumes(MediaType.APPLICATION_JSON)
|
934 |
|
|
public Response saveOrUpdateUserEmailNotificationPreferences(String input, @Context HttpServletRequest request,
|
935 |
|
|
@HeaderParam("X-XSRF-TOKEN") String token,
|
936 |
|
|
@HeaderParam("Origin") String origin,
|
937 |
|
|
@CookieParam("AccessToken") String cookie) {
|
938 |
|
|
|
939 |
|
|
|
940 |
58338
|
argiro.kok
|
if(!authorization.hasBasicAuthorization(token, origin, cookie)){
|
941 |
53619
|
konstantin
|
return Response.status(Response.Status.FORBIDDEN).entity(compose403Message("Forbidden: You don't have permission to access. Maybe you are not registered."))
|
942 |
|
|
.type(MediaType.APPLICATION_JSON)
|
943 |
|
|
.build();
|
944 |
|
|
}
|
945 |
|
|
UserInfo userInfo = authorization.getUserHandler().getUserInfo(token);
|
946 |
|
|
if (authorization.isRegistered(userInfo)) {
|
947 |
|
|
ArrayList<String> insertedIds = new ArrayList<String>();
|
948 |
|
|
JsonArray errorInClaims = new JsonArray();
|
949 |
|
|
int code200 = 0;
|
950 |
|
|
int code400 = 0;
|
951 |
|
|
int code500 = 0;
|
952 |
|
|
JsonObject jsonObject = new JsonParser().parse(input).getAsJsonObject();
|
953 |
|
|
|
954 |
|
|
String userMail =userInfo.getEmail();
|
955 |
|
|
|
956 |
|
|
String openaireId = jsonObject.get("openaireId").getAsString();
|
957 |
|
|
logger.info("openaireId " + openaireId);
|
958 |
|
|
|
959 |
|
|
boolean notify = jsonObject.get("notify").getAsBoolean();
|
960 |
|
|
logger.info("notify "+notify);
|
961 |
|
|
|
962 |
|
|
int frequency = jsonObject.get("frequency").getAsInt();
|
963 |
|
|
logger.info("frequency " + frequency);
|
964 |
|
|
|
965 |
|
|
EmailValidator emailValidator = EmailValidator.getInstance();
|
966 |
|
|
if (!emailValidator.isValid(userMail)) {
|
967 |
|
|
jsonObject.addProperty("error", "user");
|
968 |
|
|
return Response.status(Response.Status.BAD_REQUEST).entity(compose400Message("User e-mail is invalid."))
|
969 |
|
|
.type(MediaType.APPLICATION_JSON).build();
|
970 |
|
|
}
|
971 |
|
|
|
972 |
|
|
try {
|
973 |
|
|
boolean continueProcedure = false;
|
974 |
|
|
List<String> managers = null;
|
975 |
|
|
try {
|
976 |
|
|
managers = fetchProjectHandler.fetchContactEmailsByProjectId(openaireId);
|
977 |
|
|
} catch (Exception e) {
|
978 |
|
|
e.printStackTrace();
|
979 |
|
|
} catch (SQLStoreException e) {
|
980 |
|
|
e.printStackTrace();
|
981 |
|
|
}
|
982 |
|
|
if(managers != null && managers.contains(userMail)) {
|
983 |
|
|
continueProcedure = true;
|
984 |
|
|
} else {
|
985 |
58705
|
argiro.kok
|
CommunityUtils communityInfo = this.emailSender.getCommunityUtils().getCommunityInfo(openaireId);
|
986 |
60399
|
argiro.kok
|
if(communityInfo.getManagers().contains(userMail) || authorization.isCommunityCurator(userInfo) ) {
|
987 |
53619
|
konstantin
|
continueProcedure = true;
|
988 |
|
|
}
|
989 |
|
|
}
|
990 |
|
|
|
991 |
|
|
if(continueProcedure) {
|
992 |
|
|
Notification notification = null;
|
993 |
|
|
logger.debug("About to fetch notification");
|
994 |
|
|
notification = fetchNotificationHandler.fetchNotification(openaireId, userMail);
|
995 |
|
|
|
996 |
|
|
if (notification == null) {
|
997 |
|
|
logger.debug("About to insert notification");
|
998 |
|
|
notificationHandler.buildAndInsertNotification(openaireId, userMail, frequency, notify);
|
999 |
|
|
} else {
|
1000 |
|
|
logger.debug("About to update notification");
|
1001 |
|
|
notificationHandler.updateNotificationPreferences(openaireId, userMail, frequency, notify);
|
1002 |
|
|
}
|
1003 |
|
|
} else {
|
1004 |
60399
|
argiro.kok
|
return Response.status(Response.Status.FORBIDDEN).entity(compose403Message("Forbidden: You don't have permission to access. You are not registered."))
|
1005 |
53619
|
konstantin
|
.type(MediaType.APPLICATION_JSON)
|
1006 |
|
|
.build();
|
1007 |
|
|
}
|
1008 |
|
|
} catch (SQLStoreException|Exception e) {
|
1009 |
|
|
logger.error("Could not save or update notification preferences for user with mail " + userMail, e);
|
1010 |
|
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(compose500Message("Fail to fetch notification preferences" +
|
1011 |
|
|
" for user with e-mail " + userMail + ".", e)).type(MediaType.APPLICATION_JSON).build();
|
1012 |
|
|
}
|
1013 |
|
|
|
1014 |
60399
|
argiro.kok
|
return Response.status(200).entity(compose200Message("Save or Update for notification successful")).type(MediaType.APPLICATION_JSON).build();
|
1015 |
53619
|
konstantin
|
}
|
1016 |
|
|
return Response.status(Response.Status.FORBIDDEN).entity(compose403Message("Forbidden: You don't have permission to access. You are not registered."))
|
1017 |
|
|
.type(MediaType.APPLICATION_JSON)
|
1018 |
|
|
.build();
|
1019 |
|
|
}
|
1020 |
|
|
|
1021 |
42724
|
katerina.i
|
private String xml2Json(List<String> input) {
|
1022 |
|
|
StringBuilder builder = new StringBuilder();
|
1023 |
|
|
for(String category: input) {
|
1024 |
|
|
builder.append(category);
|
1025 |
|
|
}
|
1026 |
|
|
return builder.toString();
|
1027 |
|
|
}
|
1028 |
|
|
|
1029 |
60399
|
argiro.kok
|
private String compose200Message(String message){
|
1030 |
|
|
return " { \"status\" : \"success\", \"code\": \"200\", \"message\" : \" " + message +" \" }";
|
1031 |
|
|
}
|
1032 |
|
|
|
1033 |
53619
|
konstantin
|
private String compose204Message(String message) {
|
1034 |
|
|
return "{ \"status\" : \"error\", \"code\" : \"204\", \"message\" : \" " + message +" \" }";
|
1035 |
|
|
}
|
1036 |
|
|
|
1037 |
42275
|
katerina.i
|
private String compose400Message(String message) {
|
1038 |
|
|
return "{ \"status\" : \"error\", \"code\" : \"400\", \"message\" : \" " + message +" \" }";
|
1039 |
|
|
}
|
1040 |
|
|
|
1041 |
42291
|
katerina.i
|
private String compose400Message(String message, Exception exception) {
|
1042 |
|
|
return "{ \"status\" : \"error\", \"code\" : \"400\", \"message\" : \" " + message +"\", " +
|
1043 |
|
|
"\"description\" : \""+ exception.getMessage() +"\" }";
|
1044 |
|
|
}
|
1045 |
|
|
|
1046 |
46887
|
sofia.balt
|
private String compose403Message(String message) {
|
1047 |
48494
|
argiro.kok
|
return "{ \"status\" : \"error\", \"code\" : \"403\", \"message\" : \" " + message +"\", " +
|
1048 |
47084
|
argiro.kok
|
"\"description\" : \"\" }";
|
1049 |
46887
|
sofia.balt
|
}
|
1050 |
|
|
|
1051 |
47217
|
katerina.i
|
private String compose404BulkDeleteMessage(String message, List<String> deletedIds, List<String> notFoundIds) {
|
1052 |
48572
|
argiro.kok
|
return "{ \"status\" : \"error\", \"code\" : \"404\", \"message\" : \" " + message +" \","+ "\"deletedIds\" : " + new Gson().toJson(deletedIds) +","+ "\"notFoundIds\" : " + new Gson().toJson(notFoundIds) + " }";
|
1053 |
45960
|
argiro.kok
|
}
|
1054 |
42275
|
katerina.i
|
private String compose404Message(String message) {
|
1055 |
|
|
return "{ \"status\" : \"error\", \"code\" : \"404\", \"message\" : \" " + message +" \" }";
|
1056 |
|
|
}
|
1057 |
|
|
|
1058 |
47217
|
katerina.i
|
private String compose400BulkInsertMessage(String message, List<String> insertedIds,JsonArray errorInClaims) {
|
1059 |
47040
|
argiro.kok
|
return "{ \"status\" : \"error\", \"code\" : \"400\", \"message\" : \" " + message +" \""+ ", \"insertedIds\" : " + new Gson().toJson(insertedIds) +","+ "\"errorInClaims\" : " + new Gson().toJson(errorInClaims) + " }";
|
1060 |
45960
|
argiro.kok
|
}
|
1061 |
|
|
|
1062 |
47226
|
katerina.i
|
private String compose500Message(String message, Throwable throwable) {
|
1063 |
42275
|
katerina.i
|
return "{ \"status\" : \"fail\", \"code\" : \"500\", \"message\" : \" " + message + "\", " +
|
1064 |
47226
|
katerina.i
|
"\"description\" : \""+ throwable.getMessage() +"\" }";
|
1065 |
42275
|
katerina.i
|
}
|
1066 |
|
|
|
1067 |
47217
|
katerina.i
|
private String compose500BulkInsertMessage(String message, List<String> insertedIds, JsonArray errorInClaims) {
|
1068 |
45960
|
argiro.kok
|
return "{ \"status\" : \"fail\", \"code\" : \"500\", \"message\" : \" " + message + "\", " +
|
1069 |
47040
|
argiro.kok
|
"\"description\" : \""+ "\" , " + "\"insertedIds\" : " + new Gson().toJson(insertedIds) +","+ "\"errorInClaims\" : " + new Gson().toJson(errorInClaims) + " }";
|
1070 |
45960
|
argiro.kok
|
}
|
1071 |
47217
|
katerina.i
|
|
1072 |
|
|
/*
|
1073 |
|
|
TODO check if needed
|
1074 |
|
|
private String compose500BulkDeleteMessage(String message, List<String> deletedIds, List<String> notFoundIds, Exception exception) {
|
1075 |
45960
|
argiro.kok
|
return "{ \"status\" : \"fail\", \"code\" : \"500\", \"message\" : \" " + message + "\", " +
|
1076 |
|
|
"\"description\" : \""+ exception.getMessage() +"\" ," + "\"deletedIds\" : " + new Gson().toJson(deletedIds) +","+ "\"notFoundIds\" : " + new Gson().toJson(notFoundIds) + " }";
|
1077 |
|
|
}
|
1078 |
47217
|
katerina.i
|
|
1079 |
42275
|
katerina.i
|
|
1080 |
60399
|
argiro.kok
|
|
1081 |
47217
|
katerina.i
|
TODO check if needed
|
1082 |
42291
|
katerina.i
|
private String compose204Message(){
|
1083 |
|
|
return " { \"status\" : \"success\", \"code\": \"204\" }";
|
1084 |
47217
|
katerina.i
|
} */
|
1085 |
|
|
|
1086 |
|
|
private String compose204BulkDeleteMessage(List<String> deletedIds, List<String> notFoundIds){
|
1087 |
45960
|
argiro.kok
|
return " { \"status\" : \"success\", \"code\": \"204\", "+ "\"deletedIds\" : " + new Gson().toJson(deletedIds) +","+ "\"notFoundIds\" : " + new Gson().toJson(notFoundIds) + "}";
|
1088 |
|
|
}
|
1089 |
42291
|
katerina.i
|
|
1090 |
45960
|
argiro.kok
|
|
1091 |
42291
|
katerina.i
|
private String compose201PostMessage(@Context HttpServletRequest request, String claimId){
|
1092 |
42275
|
katerina.i
|
String url = request.getRequestURL().toString();
|
1093 |
42291
|
katerina.i
|
//String query = request.getQueryString();
|
1094 |
42275
|
katerina.i
|
|
1095 |
42763
|
argiro.kok
|
return " { \"status\" : \"success\", \"code\": \"201\", \"link\": \"" + url +"/"+ claimId +"\" }";
|
1096 |
42275
|
katerina.i
|
}
|
1097 |
47217
|
katerina.i
|
private String compose201BulkInsertMessage(List<String> insertedIds, JsonArray errorInClaims){
|
1098 |
|
|
//String url = request.getRequestURL().toString();
|
1099 |
45960
|
argiro.kok
|
//String query = request.getQueryString();
|
1100 |
42275
|
katerina.i
|
|
1101 |
45960
|
argiro.kok
|
return " { \"status\" : \"success\", \"code\": \"201\","+ "\"insertedIds\" : " + new Gson().toJson(insertedIds) +","+ "\"errorInClaims\" : " + new Gson().toJson(errorInClaims)+ "}";
|
1102 |
|
|
}
|
1103 |
42275
|
katerina.i
|
private String composeDataResponse(HttpServletRequest request, List<Claim> claims, int total, int offset, int limit) {
|
1104 |
47448
|
konstantin
|
if(offset != -1 && limit != -1) { // if offset and limit are -1, no paging in the response
|
1105 |
|
|
return " { \"status\" : \"success\", \"code\": \"200\", "+composeTotalResults(total)+", " + composePaging(request, total, offset, limit) + ", "
|
1106 |
|
|
+ "\"data\" : " + new Gson().toJson(claims) + " }";
|
1107 |
|
|
} else {
|
1108 |
|
|
return " { \"status\" : \"success\", \"code\": \"200\", "+composeTotalResults(total)+", "
|
1109 |
|
|
+ "\"data\" : " + new Gson().toJson(claims) + " }";
|
1110 |
|
|
}
|
1111 |
42275
|
katerina.i
|
}
|
1112 |
|
|
|
1113 |
42708
|
katerina.i
|
private String composeDataResponse(String xml) {
|
1114 |
|
|
return " { \"status\" : \"success\", \"code\": \"200\", "
|
1115 |
|
|
+ "\"data\" : " + XML.toJSONObject(xml).toString() + " }";
|
1116 |
|
|
}
|
1117 |
|
|
|
1118 |
47217
|
katerina.i
|
private String composeDataResponse(Claim claim) {
|
1119 |
42277
|
katerina.i
|
return " { \"status\" : \"success\", \"code\": \"200\", " + "\"data\" : " + new Gson().toJson(claim) + " }";
|
1120 |
|
|
}
|
1121 |
|
|
|
1122 |
53619
|
konstantin
|
private String composeDataResponse(List<Notification> notifications) {
|
1123 |
|
|
return " { \"status\" : \"success\", \"code\": \"200\", " + "\"data\" : " + new Gson().toJson(notifications) + " }";
|
1124 |
|
|
}
|
1125 |
|
|
|
1126 |
46758
|
katerina.i
|
private static String composePaging(HttpServletRequest request, int total, int currentOffset, int limit) {
|
1127 |
42277
|
katerina.i
|
logger.info("total " + total);
|
1128 |
|
|
logger.info("currentOffset " + currentOffset);
|
1129 |
|
|
logger.info("limit " + limit);
|
1130 |
|
|
|
1131 |
42275
|
katerina.i
|
String url = request.getRequestURL().toString();
|
1132 |
42277
|
katerina.i
|
//String query = request.getQueryString();
|
1133 |
42275
|
katerina.i
|
|
1134 |
42277
|
katerina.i
|
String first = url+"?offset=0&limit=20";
|
1135 |
42275
|
katerina.i
|
|
1136 |
|
|
int previousPage;
|
1137 |
|
|
int nextPage;
|
1138 |
|
|
int lastPage;
|
1139 |
|
|
|
1140 |
42277
|
katerina.i
|
if (total <= limit) {
|
1141 |
42275
|
katerina.i
|
lastPage = 0;
|
1142 |
|
|
} else {
|
1143 |
|
|
if(total%limit == 0) {
|
1144 |
|
|
lastPage = total/limit-1;
|
1145 |
|
|
} else {
|
1146 |
|
|
lastPage = total/limit ;
|
1147 |
|
|
}
|
1148 |
|
|
}
|
1149 |
42277
|
katerina.i
|
String last = url+"?offset=" + lastPage + "&limit=20";
|
1150 |
42275
|
katerina.i
|
|
1151 |
42277
|
katerina.i
|
if (currentOffset-1 <= 0) {
|
1152 |
42275
|
katerina.i
|
previousPage = 0;
|
1153 |
|
|
} else {
|
1154 |
|
|
previousPage = currentOffset-1;
|
1155 |
|
|
}
|
1156 |
42277
|
katerina.i
|
String previous = url+"?offset=" + previousPage + "&limit=20";
|
1157 |
42275
|
katerina.i
|
|
1158 |
42277
|
katerina.i
|
if (currentOffset+1 >= lastPage) {
|
1159 |
42275
|
katerina.i
|
nextPage = lastPage;
|
1160 |
|
|
|
1161 |
|
|
} else {
|
1162 |
|
|
nextPage = currentOffset + 1;
|
1163 |
|
|
}
|
1164 |
42277
|
katerina.i
|
String next = url+"?offset=" + nextPage + "&limit=20";
|
1165 |
42275
|
katerina.i
|
|
1166 |
|
|
return "\"paging\": [" + "{\"rel\":\"first\", \"href\":\"" + first +"\"}, {\"rel\":\"last\", \"href\":\"" + last + "\"}, {\"rel\":\"previous\", \"href\": \"" + previous + "\"}, {\"rel\":\"next\", \"href\":\"" + next +"\"}"+ "]";
|
1167 |
|
|
}
|
1168 |
42763
|
argiro.kok
|
private String composeTotalResults(int total) {
|
1169 |
|
|
return "\"total\": \""+total+"\"";
|
1170 |
|
|
}
|
1171 |
42275
|
katerina.i
|
|
1172 |
42277
|
katerina.i
|
public static void main(String[] args) {
|
1173 |
42275
|
katerina.i
|
|
1174 |
45960
|
argiro.kok
|
/*
|
1175 |
42277
|
katerina.i
|
EmailValidator emailValidator = EmailValidator.getInstance();
|
1176 |
|
|
System.out.println(emailValidator.isValid("jate@gdddd"));
|
1177 |
|
|
|
1178 |
|
|
InternetAddress emailAddr = null;
|
1179 |
|
|
try {
|
1180 |
|
|
emailAddr = new InternetAddress("jate@gdddd");
|
1181 |
|
|
emailAddr.validate();
|
1182 |
|
|
} catch (AddressException e) {
|
1183 |
|
|
System.out.println("false");
|
1184 |
|
|
}
|
1185 |
|
|
System.out.println("true");
|
1186 |
47217
|
katerina.i
|
|
1187 |
46789
|
sofia.balt
|
ArrayList<String> insertedIds= new ArrayList<String>();
|
1188 |
45960
|
argiro.kok
|
insertedIds.add("1");
|
1189 |
|
|
insertedIds.add("2");
|
1190 |
|
|
insertedIds.add("3");
|
1191 |
47084
|
argiro.kok
|
System.out.println(helloWorldService.compose403Message("hello"));
|
1192 |
45960
|
argiro.kok
|
|
1193 |
47217
|
katerina.i
|
*/
|
1194 |
48312
|
katerina.i
|
// BasicConfigurator.configure();
|
1195 |
|
|
// ApplicationContext context = new ClassPathXmlApplicationContext("eu/dnetlib/openaire/rest/springContext-claims-authorization.xml");
|
1196 |
|
|
//
|
1197 |
|
|
// Authorization authorization = context.getBean(Authorization.class);
|
1198 |
|
|
// UserHandler userHandler = context.getBean(UserHandler.class);
|
1199 |
|
|
// System.out.println(authorization.getAdminRoles());
|
1200 |
51938
|
argiro.kok
|
// authorization.isClaimCurator("eyJraWQiOiJvaWRjIiwiYWxnIjoiUlMyNTYifQ.eyJzdWIiOiIwOTMxNzMwMTMyODMzNjMyQG9wZW5taW50ZWQuZXUiLCJhenAiOiIyNGU4MzE3Ni0xMzEyLTRiYTMtYmMwYi1mZmVlYmVhMTYwM2UiLCJpc3MiOiJodHRwczpcL1wvYWFpLm9wZW5taW50ZWQuZXVcL29pZGNcLyIsImV4cCI6MTQ5ODQ4NTk3NiwiaWF0IjoxNDk4NDcxNTc2LCJqdGkiOiJkMWRlZjc1Yi00MTEyLTRiZDktYTIyNi0wZThhOWI2M2Y3MWQifQ.WVYOb_yO8OaxIIt2jRYEDQBhGGFRDTBw3DgtVV_smuN5yx1ScCj6aehLu3JKPSArme4m2SGF4TEGhpwNJkwhM2WapGtxmtuCmCzYIo_QlC1Yki9hr2OT2rXMcQsJCiKaBSf6pLue6Sn78GMB5yaUTvOQHRgidXGiZXH5lsuZUx15Q6Equ_wzond_rgP9mRheRkTyIFuvvg4PuzmudBc11Ty863vIIQtoWF7_p98zTbHxiNF9lLPwzPZKxDoQ8JeayQEC-jsWVLgxmp-h0jG_Ko5jFVVJeeosqMMucOrs2FT_NKHVYVqB6VVh0C6nOufeiLrNDeMUlDT4dAvKD2zE9w");
|
1201 |
48312
|
katerina.i
|
|
1202 |
42277
|
katerina.i
|
}
|
1203 |
45960
|
argiro.kok
|
|
1204 |
57030
|
argiro.kok
|
// @GET
|
1205 |
|
|
// @Path("email-notifications")
|
1206 |
|
|
// public void forceSendEmailNotifications() {
|
1207 |
|
|
// emailSender.run();
|
1208 |
|
|
// }
|
1209 |
53892
|
konstantin
|
|
1210 |
53917
|
konstantin
|
@GET
|
1211 |
|
|
@Path("test-email")
|
1212 |
|
|
public void testEmail() {
|
1213 |
|
|
ArrayList<String> list = new ArrayList<String>();
|
1214 |
|
|
list.add("konstantinagalouni@gmail.com");
|
1215 |
|
|
list.add("argirok@di.uoa.gr");
|
1216 |
|
|
emailSender.send("openaire_id_test", "openaire_name_test", "community", list);
|
1217 |
|
|
}
|
1218 |
58338
|
argiro.kok
|
|
1219 |
|
|
private String getvalueOf(JsonObject jsonObject, String field){
|
1220 |
|
|
String value = (jsonObject.get(field) != null && !jsonObject.get(field).isJsonNull())?jsonObject.get(field).getAsString():null;
|
1221 |
|
|
logger.info(field + ": " + value);
|
1222 |
|
|
return value;
|
1223 |
|
|
|
1224 |
|
|
|
1225 |
|
|
}
|
1226 |
|
|
private String getvalueOfDefault(JsonObject jsonObject, String field, String defaultValue){
|
1227 |
|
|
String value = this.getvalueOf(jsonObject, field);
|
1228 |
|
|
logger.debug("Field:"+field+"->"+value+"<-");
|
1229 |
|
|
return (value!=null && !value.equals("")?value:defaultValue);
|
1230 |
|
|
}
|
1231 |
|
|
|
1232 |
|
|
private String getInfoAndBuildClaim(JsonObject jsonObject, String claimedBy ) throws SQLStoreException, Exception {
|
1233 |
|
|
String claimedInDashboard = getvalueOfDefault(jsonObject, "claimedInDashboard", null);
|
1234 |
|
|
|
1235 |
|
|
String sourceId = getvalueOf(jsonObject, "sourceId");
|
1236 |
|
|
String sourceType = getvalueOf(jsonObject, "sourceType");
|
1237 |
|
|
String sourceCollectedFrom = getvalueOf(jsonObject, "sourceCollectedFrom");
|
1238 |
|
|
String sourceAccessRights = getvalueOf(jsonObject, "sourceAccessRights");
|
1239 |
|
|
String sourceEmbargoEndDate = getvalueOfDefault(jsonObject, "sourceEmbargoEndDate", null);
|
1240 |
|
|
|
1241 |
|
|
String targetId = getvalueOf(jsonObject, "targetId");
|
1242 |
|
|
String targetType = getvalueOf(jsonObject, "targetType");
|
1243 |
|
|
String targetCollectedFrom = getvalueOf(jsonObject, "targetCollectedFrom");
|
1244 |
|
|
String targetAccessRights = getvalueOf(jsonObject, "targetAccessRights");
|
1245 |
|
|
String targetEmbargoEndDate = getvalueOfDefault(jsonObject, "targetEmbargoEndDate", null);
|
1246 |
|
|
|
1247 |
|
|
|
1248 |
|
|
logger.debug("Claimed in"+claimedInDashboard);
|
1249 |
|
|
return claimHandler.buildAndInsertClaim(claimedBy, sourceType, sourceId, sourceCollectedFrom, sourceAccessRights, sourceEmbargoEndDate, targetType, targetId, targetCollectedFrom, targetAccessRights, targetEmbargoEndDate,claimedInDashboard);
|
1250 |
|
|
}
|
1251 |
|
|
|
1252 |
|
|
|
1253 |
46789
|
sofia.balt
|
}
|