Revision 46887
Added by Sofia Baltzi about 7 years ago
modules/uoa-openaire-connector/branches/newClaimAPI/src/main/java/eu/dnetlib/openaire/rest/HelloWorldService.java | ||
---|---|---|
7 | 7 |
import eu.dnetlib.data.claims.migration.entity.Claim; |
8 | 8 |
import eu.dnetlib.data.claims.migration.handler.ClaimHandler; |
9 | 9 |
import eu.dnetlib.data.claims.migration.handler.FetchClaimHandler; |
10 |
import eu.dnetlib.openaire.rest.authorization.Authorization; |
|
10 | 11 |
import eu.dnetlib.openaire.rest.security.JWTValidator; |
11 | 12 |
import gr.uoa.di.driver.util.ServiceLocator; |
12 | 13 |
import org.apache.commons.validator.EmailValidator; |
... | ... | |
154 | 155 |
listTypes.add(types_array[i]); |
155 | 156 |
} |
156 | 157 |
} |
158 |
|
|
157 | 159 |
try { |
158 | 160 |
claims = fetchClaimHandler.fetchClaimsByResult(resultId, limit, offset,keyword, orderby, descending, listTypes); |
159 | 161 |
total = fetchClaimHandler.countClaimsByResult(resultId,keyword, listTypes); |
... | ... | |
276 | 278 |
.build(); |
277 | 279 |
} |
278 | 280 |
|
279 |
List<Claim> claims = null; |
|
280 |
List<String> listTypes = new ArrayList<String>(); |
|
281 |
String [] types_array = types.split(","); |
|
282 |
for(int i = 0; i< types_array.length; i++){ |
|
283 |
if(types_array[i].length()>0) { |
|
284 |
listTypes.add(types_array[i]); |
|
281 |
if(Authorization.isAdmin(token)) { |
|
282 |
|
|
283 |
List<Claim> claims = null; |
|
284 |
List<String> listTypes = new ArrayList<String>(); |
|
285 |
String[] types_array = types.split(","); |
|
286 |
for (int i = 0; i < types_array.length; i++) { |
|
287 |
if (types_array[i].length() > 0) { |
|
288 |
listTypes.add(types_array[i]); |
|
289 |
} |
|
285 | 290 |
} |
286 |
} |
|
287 |
logger.debug("Types: "+ listTypes.toString()); |
|
291 |
logger.debug("Types: " + listTypes.toString()); |
|
288 | 292 |
|
289 |
int total = -1; |
|
290 |
try { |
|
291 |
claims = fetchClaimHandler.fetchAllClaims(limit, offset,keyword,orderby,descending,listTypes);
|
|
292 |
total = fetchClaimHandler.countAllClaims(keyword, listTypes); |
|
293 |
int total = -1;
|
|
294 |
try {
|
|
295 |
claims = fetchClaimHandler.fetchAllClaims(limit, offset, keyword, orderby, descending, listTypes);
|
|
296 |
total = fetchClaimHandler.countAllClaims(keyword, listTypes);
|
|
293 | 297 |
|
294 |
return Response.status(200).entity(composeDataResponse(request, claims, total, offset, limit)).build(); |
|
298 |
return Response.status(200).entity(composeDataResponse(request, claims, total, offset, limit)).build();
|
|
295 | 299 |
|
296 |
} catch (Exception e) { |
|
297 |
logger.error("Could not fetch claims.", e); |
|
298 |
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(compose500Message("Fail to fetch claims.", e)) |
|
299 |
.type(MediaType.APPLICATION_JSON).build(); |
|
300 |
} catch (Exception e) { |
|
301 |
logger.error("Could not fetch claims.", e); |
|
302 |
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(compose500Message("Fail to fetch claims.", e)) |
|
303 |
.type(MediaType.APPLICATION_JSON).build(); |
|
304 |
} |
|
300 | 305 |
} |
301 |
|
|
306 |
else |
|
307 |
return Response.status(Response.Status.FORBIDDEN).entity(compose403Message("Forbidden: You don't have permission to access")) |
|
308 |
.type(MediaType.APPLICATION_JSON) |
|
309 |
.build(); |
|
302 | 310 |
} |
303 | 311 |
|
304 | 312 |
|
... | ... | |
345 | 353 |
.header("Access-Control-Allow-Methods", "DELETE").type(MediaType.APPLICATION_JSON).build(); |
346 | 354 |
} |
347 | 355 |
|
348 |
} catch (Exception e) { |
|
356 |
} catch (Exception e) {return Response.status(Response.Status.UNAUTHORIZED).entity(compose404Message("Not valid Token")) |
|
357 |
.type(MediaType.APPLICATION_JSON) |
|
358 |
.build(); |
|
349 | 359 |
logger.error("Fail to delete claim with id " + claimId + ".", e); |
350 | 360 |
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(compose500Message("Fail to delete claim with id " + claimId +".", e)) |
351 | 361 |
.header("Access-Control-Allow-Origin", "*") |
... | ... | |
616 | 626 |
"\"description\" : \""+ exception.getMessage() +"\" }"; |
617 | 627 |
} |
618 | 628 |
|
629 |
private String compose403Message(String message) { |
|
630 |
return "{ \"status\" : \"error\", \"code\" : \"400\", \"message\" : \" " + message +"\", " + |
|
631 |
"\"description\" : \" }"; |
|
632 |
} |
|
633 |
|
|
619 | 634 |
private String compose404BulkDeleteMessage(String message, ArrayList<String> deletedIds, ArrayList<String> notFoundIds) { |
620 | 635 |
return "{ \"status\" : \"error\", \"code\" : \"404\", \"message\" : \" " + message +" \""+ "\"deletedIds\" : " + new Gson().toJson(deletedIds) +","+ "\"notFoundIds\" : " + new Gson().toJson(notFoundIds) + " }"; |
621 | 636 |
} |
Also available in: Unified diff
Update HelloWorldService, check if user is admin at getAllClaims