Changeset 5684
- Timestamp:
- 09/26/14 14:04:57 (10 years ago)
- Location:
- DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/rest
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/rest/AnnotationResource.java
r5679 r5684 247 247 Map params = new HashMap(); 248 248 params.put("annotation", annotation); 249 ResponseBody result = (ResponseBody) (new RequestWrappers(this)).wrapRequestResource(params, new AddAnnotation()); 250 if (result != null) { 251 return (new ObjectFactory()).createResponseBody(result); 252 } else { 249 try { 250 ResponseBody result = (ResponseBody) (new RequestWrappers(this)).wrapRequestResource(params, new AddAnnotation()); 251 if (result != null) { 252 return (new ObjectFactory()).createResponseBody(result); 253 } else { 254 return (new ObjectFactory()).createResponseBody(new ResponseBody()); 255 } 256 } catch (NotInDataBaseException e) { 257 httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, e.getMessage()); 253 258 return (new ObjectFactory()).createResponseBody(new ResponseBody()); 254 259 } … … 399 404 } 400 405 401 Access accessTyped = Access.fromValue(access); 402 int updatedAnnotations = 0; 403 404 if (annotationDatabaseId == null || annotationDatabaseId.trim().equals("")) { 405 List<Number> annotationIDs = dbDispatcher.getAnnotationInternalIDsFromHeadline(annotationHeadline); 406 if (annotationIDs == null || annotationIDs.isEmpty()) { 407 return "No annotations with this headline have been found"; 408 }; 409 int count = 0; 410 for (Number annotationID : annotationIDs) { 411 count = dbDispatcher.updatePublicAttribute(annotationID, accessTyped);; 412 updatedAnnotations = updatedAnnotations + count; 413 } 414 return (updatedAnnotations + " row(s) are updated"); 415 } else { 416 try { 417 Number annotationID = dbDispatcher.getResourceInternalIdentifier(UUID.fromString(annotationDatabaseId), Resource.ANNOTATION); 418 updatedAnnotations = dbDispatcher.updatePublicAttribute(annotationID, accessTyped); 419 } catch (NotInDataBaseException e) { 420 httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, e.toString()); 421 } 422 } 423 return (updatedAnnotations + " annotation(s) are updated."); 406 try { 407 408 Access accessTyped = Access.fromValue(access); 409 if (annotationDatabaseId == null || annotationDatabaseId.trim().equals("")) { 410 List<UUID> annotationIds = dbDispatcher.getAnnotationExternalIdsFromHeadline(annotationHeadline); 411 if (annotationIds == null || annotationIds.isEmpty()) { 412 httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, "No annotations with this headline have been found"); 413 return "No annotations with this headline have been found"; 414 }; 415 int updatedAnnotations = 0; 416 for (UUID annotationId : annotationIds) { 417 Map params = new HashMap(); 418 params.put("access", accessTyped); 419 Integer result = (Integer) (new RequestWrappers(this)).wrapRequestResource(params, new UpdatePublicAccess(), Resource.ANNOTATION, ResourceAction.WRITE_W_METAINFO, annotationId.toString()); 420 updatedAnnotations = (result != null) ? updatedAnnotations + result.intValue() : updatedAnnotations; 421 } 422 return (updatedAnnotations + " row(s) are updated"); 423 } else { 424 Map params = new HashMap(); 425 params.put("access", accessTyped); 426 Integer result = (Integer) (new RequestWrappers(this)).wrapRequestResource(params, new UpdatePublicAccess(), Resource.ANNOTATION, ResourceAction.WRITE_W_METAINFO, annotationDatabaseId); 427 if (result != null) { 428 return result + " row(s) is(are) updated."; 429 } else { 430 return "0 rows are updated."; 431 } 432 } 433 } catch (NotInDataBaseException e1) { 434 httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, e1.toString()); 435 return "0 rows are updated."; 436 } catch (ForbiddenException e2) { 437 httpServletResponse.sendError(HttpServletResponse.SC_FORBIDDEN, e2.toString()); 438 return "0 rows are updated."; 439 } 440 } 441 442 private class UpdatePublicAccess implements ILambda<Map, Integer> { 443 444 @Override 445 public Integer apply(Map params) throws NotInDataBaseException { 446 Number annotationID = (Number) params.get("internalID"); 447 Access access = (Access) params.get("access"); 448 return dbDispatcher.updatePublicAttribute(annotationID, access); 449 } 424 450 } 425 451 … … 512 538 return "0 rows are updated."; 513 539 } 514 515 516 540 } 517 541 -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/rest/PrincipalResource.java
r5679 r5684 77 77 Map params = new HashMap<String, String>(); 78 78 params.put("externalId", externalIdentifier); 79 Principal result = (Principal) (new RequestWrappers(this)).wrapRequestResource(params, new GetPrincipal()); 80 return (result != null) ? (new ObjectFactory().createPrincipal(result)) : (new ObjectFactory().createPrincipal(new Principal())); 79 try { 80 Principal result = (Principal) (new RequestWrappers(this)).wrapRequestResource(params, new GetPrincipal()); 81 return (result != null) ? (new ObjectFactory().createPrincipal(result)) : (new ObjectFactory().createPrincipal(new Principal())); 82 } catch (NotInDataBaseException e) { 83 httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, e.getMessage()); 84 return new ObjectFactory().createPrincipal(new Principal()); 85 } 81 86 } 82 87 … … 111 116 Map params = new HashMap<String, String>(); 112 117 params.put("email", email); 113 Principal result = (Principal) (new RequestWrappers(this)).wrapRequestResource(params, new GetPrincipalByInfo()); 114 return (result != null) ? (new ObjectFactory().createPrincipal(result)) : (new ObjectFactory().createPrincipal(new Principal())); 118 try { 119 Principal result = (Principal) (new RequestWrappers(this)).wrapRequestResource(params, new GetPrincipalByInfo()); 120 return (result != null) ? (new ObjectFactory().createPrincipal(result)) : (new ObjectFactory().createPrincipal(new Principal())); 121 } catch (NotInDataBaseException e) { 122 httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, e.getMessage()); 123 return new ObjectFactory().createPrincipal(new Principal()); 124 } 115 125 } 116 126 … … 131 141 Map params = new HashMap<String, String>(); 132 142 params.put("externalId", externalIdentifier); 133 CurrentPrincipalInfo result = (CurrentPrincipalInfo) (new RequestWrappers(this)).wrapRequestResource(params, new GetCurrentPrincipalInfo()); 134 return (result != null) ? (new ObjectFactory().createCurrentPrincipalInfo(result)) : (new ObjectFactory().createCurrentPrincipalInfo(new CurrentPrincipalInfo())); 143 try { 144 CurrentPrincipalInfo result = (CurrentPrincipalInfo) (new RequestWrappers(this)).wrapRequestResource(params, new GetCurrentPrincipalInfo()); 145 return (result != null) ? (new ObjectFactory().createCurrentPrincipalInfo(result)) : (new ObjectFactory().createCurrentPrincipalInfo(new CurrentPrincipalInfo())); 146 } catch (NotInDataBaseException e) { 147 httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, e.getMessage()); 148 return new ObjectFactory().createCurrentPrincipalInfo(new CurrentPrincipalInfo()); 149 } 135 150 } 136 151 … … 309 324 Map params = new HashMap<String, Object>(); 310 325 params.put("newPrincipal", principal); 311 Principal result = (Principal) (new RequestWrappers(this)).wrapRequestResource(params, new UpdatePrincipal()); 312 return (result != null) ? (new ObjectFactory().createPrincipal(result)) : (new ObjectFactory().createPrincipal(new Principal())); 313 326 try { 327 Principal result = (Principal) (new RequestWrappers(this)).wrapRequestResource(params, new UpdatePrincipal()); 328 return (result != null) ? (new ObjectFactory().createPrincipal(result)) : (new ObjectFactory().createPrincipal(new Principal())); 329 } catch (NotInDataBaseException e) { 330 httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, e.getMessage()); 331 return new ObjectFactory().createPrincipal(new Principal()); 332 } 314 333 } else { 315 334 this.ADMIN_RIGHTS_EXPECTED(); -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/rest/RequestWrappers.java
r5679 r5684 53 53 } 54 54 55 public T wrapRequestResource(Map params, ILambda<Map, T> dbRequestor) throws IOException {55 public T wrapRequestResource(Map params, ILambda<Map, T> dbRequestor) throws IOException, NotInDataBaseException { 56 56 Number remotePrincipalID = resourceResource.getPrincipalID(); 57 57 if (remotePrincipalID == null) { … … 59 59 } 60 60 params.put(_principalID, remotePrincipalID); 61 try { 62 return dbRequestor.apply(params); 63 } catch (NotInDataBaseException e1) { 64 resourceResource.loggerServer.debug(e1.toString()); 65 resourceResource.httpServletResponse.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e1.toString()); 66 return null; 67 } 61 return dbRequestor.apply(params); 68 62 } 69 63 … … 85 79 86 80 } 81 82 87 83 88 84 public JAXBElement<Principal> wrapAddPrincipalRequest(Map params, ILambdaPrincipal<Map, Principal> dbRequestor) throws IOException, NotInDataBaseException, PrincipalExists {
Note: See TracChangeset
for help on using the changeset viewer.