- Timestamp:
- 09/26/14 09:14:41 (10 years ago)
- Location:
- DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend
- Files:
-
- 1 added
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/UPDATE.txt
r5676 r5679 3 3 standard MPI deployment procedure, for webannotator-basic. 4 4 Consult the instructions from INSTALL.txt about placing war file if you have forgotten. 5 5 override="true 6 6 2. The web.xml stays intact because currently it is set for basic authentication. 7 7 -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/rest/AnnotationResource.java
r5661 r5679 19 19 20 20 import eu.dasish.annotation.backend.BackendConstants; 21 import eu.dasish.annotation.backend.ForbiddenException; 21 22 import eu.dasish.annotation.backend.NotInDataBaseException; 22 23 import eu.dasish.annotation.backend.Resource; … … 85 86 public JAXBElement<Annotation> getAnnotation(@PathParam("annotationid") String externalIdentifier) throws IOException { 86 87 Map params = new HashMap(); 87 Annotation result = (Annotation) (new RequestWrappers(this)).wrapRequestResource(params, new GetAnnotation(), Resource.ANNOTATION, ResourceAction.READ, externalIdentifier); 88 if (result != null) { 89 return (new ObjectFactory()).createAnnotation(result); 90 } else { 88 try { 89 Annotation result = (Annotation) (new RequestWrappers(this)).wrapRequestResource(params, new GetAnnotation(), Resource.ANNOTATION, ResourceAction.READ, externalIdentifier); 90 if (result != null) { 91 return (new ObjectFactory()).createAnnotation(result); 92 } else { 93 return (new ObjectFactory()).createAnnotation(new Annotation()); 94 } 95 } catch (NotInDataBaseException e1) { 96 httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, e1.getMessage()); 97 return (new ObjectFactory()).createAnnotation(new Annotation()); 98 } catch (ForbiddenException e2) { 99 httpServletResponse.sendError(HttpServletResponse.SC_FORBIDDEN, e2.getMessage()); 91 100 return (new ObjectFactory()).createAnnotation(new Annotation()); 92 101 } … … 108 117 public JAXBElement<ReferenceList> getAnnotationTargets(@PathParam("annotationid") String externalIdentifier) throws IOException { 109 118 Map params = new HashMap(); 110 ReferenceList result = (ReferenceList) (new RequestWrappers(this)).wrapRequestResource(params, new GetTargetList(), Resource.ANNOTATION, ResourceAction.READ, externalIdentifier); 111 if (result != null) { 112 return (new ObjectFactory()).createTargetList(result); 113 } else { 114 return (new ObjectFactory()).createTargetList(new ReferenceList()); 119 try { 120 ReferenceList result = (ReferenceList) (new RequestWrappers(this)).wrapRequestResource(params, new GetTargetList(), Resource.ANNOTATION, ResourceAction.READ, externalIdentifier); 121 if (result != null) { 122 return (new ObjectFactory()).createTargetList(result); 123 } else { 124 return (new ObjectFactory()).createTargetList(new ReferenceList()); 125 } 126 } catch (NotInDataBaseException e1) { 127 httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, e1.getMessage()); 128 return (new ObjectFactory()).createReferenceList(new ReferenceList()); 129 } catch (ForbiddenException e2) { 130 httpServletResponse.sendError(HttpServletResponse.SC_FORBIDDEN, e2.getMessage()); 131 return (new ObjectFactory()).createReferenceList(new ReferenceList()); 115 132 } 116 133 } … … 168 185 public JAXBElement<PermissionList> getAnnotationPermissions(@PathParam("annotationid") String externalIdentifier) throws IOException { 169 186 Map params = new HashMap(); 170 PermissionList result = (PermissionList) (new RequestWrappers(this)).wrapRequestResource(params, new GetPermissionList(), Resource.ANNOTATION, ResourceAction.READ, externalIdentifier); 171 if (result != null) { 172 return (new ObjectFactory()).createPermissionList(result); 173 } else { 187 try { 188 PermissionList result = (PermissionList) (new RequestWrappers(this)).wrapRequestResource(params, new GetPermissionList(), Resource.ANNOTATION, ResourceAction.READ, externalIdentifier); 189 if (result != null) { 190 return (new ObjectFactory()).createPermissionList(result); 191 } else { 192 return (new ObjectFactory()).createPermissionList(new PermissionList()); 193 } 194 } catch (NotInDataBaseException e1) { 195 httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, e1.getMessage()); 196 return (new ObjectFactory()).createPermissionList(new PermissionList()); 197 } catch (ForbiddenException e2) { 198 httpServletResponse.sendError(HttpServletResponse.SC_FORBIDDEN, e2.getMessage()); 174 199 return (new ObjectFactory()).createPermissionList(new PermissionList()); 175 200 } … … 189 214 public String deleteAnnotation(@PathParam("annotationid") String externalIdentifier) throws IOException { 190 215 Map params = new HashMap(); 191 int[] result = (int[]) (new RequestWrappers(this)).wrapRequestResource(params, new DeleteAnnotation(), Resource.ANNOTATION, ResourceAction.DELETE, externalIdentifier); 192 if (result != null) { 193 return result[0] + " annotation(s) is(are) deleted."; 194 } else { 195 return "Nothing is deleted."; 216 try { 217 int[] result = (int[]) (new RequestWrappers(this)).wrapRequestResource(params, new DeleteAnnotation(), Resource.ANNOTATION, ResourceAction.DELETE, externalIdentifier); 218 if (result != null) { 219 return result[0] + " annotation(s) is(are) deleted."; 220 } else { 221 return "Nothing is deleted."; 222 } 223 } catch (NotInDataBaseException e1) { 224 httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, e1.getMessage()); 225 return e1.getMessage(); 226 } catch (ForbiddenException e2) { 227 httpServletResponse.sendError(HttpServletResponse.SC_FORBIDDEN, e2.getMessage()); 228 return e2.getMessage(); 196 229 } 197 230 } … … 247 280 return null; 248 281 } 249 Map params = new HashMap(); 250 params.put("annotation", annotation); 251 ResponseBody result = (ResponseBody) (new RequestWrappers(this)).wrapRequestResource(params, new UpdateAnnotation(), Resource.ANNOTATION, ResourceAction.WRITE_W_METAINFO, externalId); 252 if (result != null) { 253 return (new ObjectFactory()).createResponseBody(result); 254 } else { 255 return (new ObjectFactory()).createResponseBody(new ResponseBody()); 256 } 257 258 282 try { 283 Map params = new HashMap(); 284 params.put("annotation", annotation); 285 ResponseBody result = (ResponseBody) (new RequestWrappers(this)).wrapRequestResource(params, new UpdateAnnotation(), Resource.ANNOTATION, ResourceAction.WRITE_W_METAINFO, externalId); 286 if (result != null) { 287 return (new ObjectFactory()).createResponseBody(result); 288 } else { 289 return (new ObjectFactory()).createResponseBody(new ResponseBody()); 290 } 291 } catch (NotInDataBaseException e1) { 292 httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, e1.getMessage()); 293 return (new ObjectFactory()).createResponseBody(new ResponseBody()); 294 } catch (ForbiddenException e2) { 295 httpServletResponse.sendError(HttpServletResponse.SC_FORBIDDEN, e2.getMessage()); 296 return (new ObjectFactory()).createResponseBody(new ResponseBody()); 297 } 259 298 } 260 299 … … 279 318 Map params = new HashMap(); 280 319 params.put("annotationBody", annotationBody); 281 ResponseBody result = (ResponseBody) (new RequestWrappers(this)).wrapRequestResource(params, new UpdateAnnotationBody(), Resource.ANNOTATION, ResourceAction.WRITE, externalIdentifier); 282 if (result != null) { 283 return (new ObjectFactory()).createResponseBody(result); 284 } else { 320 try { 321 ResponseBody result = (ResponseBody) (new RequestWrappers(this)).wrapRequestResource(params, new UpdateAnnotationBody(), Resource.ANNOTATION, ResourceAction.WRITE, externalIdentifier); 322 if (result != null) { 323 return (new ObjectFactory()).createResponseBody(result); 324 } else { 325 return (new ObjectFactory()).createResponseBody(new ResponseBody()); 326 } 327 } catch (NotInDataBaseException e1) { 328 httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, e1.getMessage()); 329 return (new ObjectFactory()).createResponseBody(new ResponseBody()); 330 } catch (ForbiddenException e2) { 331 httpServletResponse.sendError(HttpServletResponse.SC_FORBIDDEN, e2.getMessage()); 285 332 return (new ObjectFactory()).createResponseBody(new ResponseBody()); 286 333 } … … 307 354 Map params = new HashMap(); 308 355 params.put("headline", newHeadline); 309 ResponseBody result = (ResponseBody) (new RequestWrappers(this)).wrapRequestResource(params, new UpdateAnnotationHeadline(), Resource.ANNOTATION, ResourceAction.WRITE, externalIdentifier); 310 if (result != null) { 311 return (new ObjectFactory()).createResponseBody(result); 312 } else { 356 try { 357 ResponseBody result = (ResponseBody) (new RequestWrappers(this)).wrapRequestResource(params, new UpdateAnnotationHeadline(), Resource.ANNOTATION, ResourceAction.WRITE, externalIdentifier); 358 if (result != null) { 359 return (new ObjectFactory()).createResponseBody(result); 360 } else { 361 return (new ObjectFactory()).createResponseBody(new ResponseBody()); 362 } 363 } catch (NotInDataBaseException e1) { 364 httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, e1.getMessage()); 365 return (new ObjectFactory()).createResponseBody(new ResponseBody()); 366 } catch (ForbiddenException e2) { 367 httpServletResponse.sendError(HttpServletResponse.SC_FORBIDDEN, e2.getMessage()); 313 368 return (new ObjectFactory()).createResponseBody(new ResponseBody()); 314 369 } … … 327 382 } 328 383 } 329 384 330 385 ////////////////////////////////////////// 331 332 ////////////////////////////////////////////// 386 ////////////////////////////////////////////// 333 387 @POST 334 388 @Consumes(MediaType.APPLICATION_FORM_URLENCODED) … … 340 394 @FormParam("access") String access) 341 395 throws IOException { 342 396 343 397 if (access.trim().equals("")) { 344 398 access = "none"; 345 399 } 346 400 347 401 Access accessTyped = Access.fromValue(access); 348 402 int updatedAnnotations = 0; 349 403 350 404 if (annotationDatabaseId == null || annotationDatabaseId.trim().equals("")) { 351 405 List<Number> annotationIDs = dbDispatcher.getAnnotationInternalIDsFromHeadline(annotationHeadline); … … 356 410 for (Number annotationID : annotationIDs) { 357 411 count = dbDispatcher.updatePublicAttribute(annotationID, accessTyped);; 358 updatedAnnotations = updatedAnnotations +count;359 } 412 updatedAnnotations = updatedAnnotations + count; 413 } 360 414 return (updatedAnnotations + " row(s) are updated"); 361 415 } else { 362 416 try { 363 Number annotationID = dbDispatcher.getResourceInternalIdentifier(UUID.fromString(annotationDatabaseId), Resource.ANNOTATION);364 updatedAnnotations= dbDispatcher.updatePublicAttribute(annotationID, accessTyped);417 Number annotationID = dbDispatcher.getResourceInternalIdentifier(UUID.fromString(annotationDatabaseId), Resource.ANNOTATION); 418 updatedAnnotations = dbDispatcher.updatePublicAttribute(annotationID, accessTyped); 365 419 } catch (NotInDataBaseException e) { 366 httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, e.toString());420 httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, e.toString()); 367 421 } 368 422 } 369 423 return (updatedAnnotations + " annotation(s) are updated."); 370 424 } 371 425 372 426 //////////////////////////////////////////////////// 373 374 427 @PUT 375 428 @Consumes(MediaType.APPLICATION_XML) … … 378 431 public String updateAccess(@PathParam("annotationid") String annotationExternalId, 379 432 @PathParam("principalid") String principalExternalId, Access access) throws IOException { 380 return this.genericUpdateDeleteAccess(annotationExternalId, principalExternalId, access); 381 } 382 383 433 try { 434 return this.genericUpdateDeleteAccess(annotationExternalId, principalExternalId, access); 435 } catch (NotInDataBaseException e1) { 436 httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, e1.getMessage()); 437 return e1.getMessage(); 438 } catch (ForbiddenException e2) { 439 httpServletResponse.sendError(HttpServletResponse.SC_FORBIDDEN, e2.getMessage()); 440 return e2.getMessage(); 441 } 442 } 384 443 385 444 ////////////////////////////////////////////// … … 395 454 @FormParam("access") String access) 396 455 throws IOException { 397 398 if (access.trim().equals("")) { 399 access = null; 400 } 401 402 try { 456 457 try { 458 459 if (access.trim().equals("")) { 460 access = null; 461 } 462 403 463 if (principalDatabaseId == null || principalDatabaseId.trim().equals("")) { 404 464 if (remoteID != null && !remoteID.trim().equals("")) { … … 412 472 } 413 473 } 414 } catch (NotInDataBaseException e) { 415 httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, e.toString()); 416 } 417 418 if (annotationDatabaseId == null || annotationDatabaseId.trim().equals("")) { 419 List<UUID> annotationIds = dbDispatcher.getAnnotationExternalIdsFromHeadline(annotationHeadline); 420 if (annotationIds == null || annotationIds.isEmpty()) { 421 return "No annotations with this headline found"; 422 }; 423 int count = 0; 424 String tmp = null; 425 for (UUID annotationId : annotationIds) { 426 tmp = this.genericUpdateDeleteAccess(annotationId.toString(), principalDatabaseId, Access.fromValue(access)); 427 if (!tmp.startsWith("0")) { 428 count++; 474 475 if (annotationDatabaseId == null || annotationDatabaseId.trim().equals("")) { 476 List<UUID> annotationIds = dbDispatcher.getAnnotationExternalIdsFromHeadline(annotationHeadline); 477 if (annotationIds == null || annotationIds.isEmpty()) { 478 return "No annotations with this headline found"; 479 }; 480 int count = 0; 481 String tmp = null; 482 for (UUID annotationId : annotationIds) { 483 tmp = this.genericUpdateDeleteAccess(annotationId.toString(), principalDatabaseId, Access.fromValue(access)); 484 if (!tmp.startsWith("0")) { 485 count++; 486 } 429 487 } 430 } 431 return (count + " row(s) are updated"); 488 return (count + " row(s) are updated"); 489 } else { 490 return this.genericUpdateDeleteAccess(annotationDatabaseId, principalDatabaseId, Access.fromValue(access)); 491 } 492 493 } catch (NotInDataBaseException e1) { 494 httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, e1.getMessage()); 495 return e1.getMessage(); 496 } catch (ForbiddenException e2) { 497 httpServletResponse.sendError(HttpServletResponse.SC_FORBIDDEN, e2.getMessage()); 498 return e2.getMessage(); 499 } 500 } 501 502 //////////////////////////////////////////// 503 private String genericUpdateDeleteAccess(String annotationId, String principalId, Access access) throws IOException, NotInDataBaseException, ForbiddenException { 504 Map params = new HashMap(); 505 params.put("access", access); 506 final Number inputPrincipalID = dbDispatcher.getResourceInternalIdentifier(UUID.fromString(principalId), Resource.PRINCIPAL); 507 params.put("inputPrincipalID", inputPrincipalID); 508 Integer result = (Integer) (new RequestWrappers(this)).wrapRequestResource(params, new UpdatePrincipalAccess(), Resource.ANNOTATION, ResourceAction.WRITE_W_METAINFO, annotationId); 509 if (result != null) { 510 return result + " row(s) is(are) updated."; 432 511 } else { 433 return this.genericUpdateDeleteAccess(annotationDatabaseId, principalDatabaseId, Access.fromValue(access)); 434 } 435 } 436 437 //////////////////////////////////////////// 438 private String genericUpdateDeleteAccess(String annotationId, String principalId, Access access) throws IOException { 439 Map params = new HashMap(); 440 params.put("access", access); 441 try { 442 final Number inputPrincipalID = dbDispatcher.getResourceInternalIdentifier(UUID.fromString(principalId), Resource.PRINCIPAL); 443 params.put("inputPrincipalID", inputPrincipalID); 444 Integer result = (Integer) (new RequestWrappers(this)).wrapRequestResource(params, new UpdatePrincipalAccess(), Resource.ANNOTATION, ResourceAction.WRITE_W_METAINFO, annotationId); 445 if (result != null) { 446 return result + " row(s) is(are) updated."; 447 } else { 448 return "Nothing is updated."; 449 } 450 451 } catch (NotInDataBaseException e2) { 452 loggerServer.debug(e2.toString()); 453 httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, e2.toString()); 454 return "Nothing is deleted."; 455 } 512 return "0 rows are updated."; 513 } 514 515 456 516 } 457 517 … … 476 536 Map params = new HashMap(); 477 537 params.put("permissions", permissions); 478 479 ResponseBody result = (ResponseBody) (new RequestWrappers(this)).wrapRequestResource(params, new UpdatePermissions(), Resource.ANNOTATION, ResourceAction.WRITE_W_METAINFO, annotationExternalId); 480 if (result != null) { 481 return new ObjectFactory().createResponseBody(result); 482 } else { 538 try { 539 ResponseBody result = (ResponseBody) (new RequestWrappers(this)).wrapRequestResource(params, new UpdatePermissions(), Resource.ANNOTATION, ResourceAction.WRITE_W_METAINFO, annotationExternalId); 540 if (result != null) { 541 return new ObjectFactory().createResponseBody(result); 542 } else { 543 return new ObjectFactory().createResponseBody(new ResponseBody()); 544 } 545 } catch (NotInDataBaseException e1) { 546 httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, e1.getMessage()); 483 547 return new ObjectFactory().createResponseBody(new ResponseBody()); 484 } 485 548 } catch (ForbiddenException e2) { 549 httpServletResponse.sendError(HttpServletResponse.SC_FORBIDDEN, e2.getMessage()); 550 return new ObjectFactory().createResponseBody(new ResponseBody()); 551 } 486 552 487 553 } … … 505 571 public String deletePrincipalsAccess(@PathParam("annotationId") String annotationId, 506 572 @PathParam("principalId") String principalId) throws IOException { 507 return this.genericUpdateDeleteAccess(annotationId, principalId, null); 573 try { 574 return this.genericUpdateDeleteAccess(annotationId, principalId, null); 575 } catch (NotInDataBaseException e1) { 576 httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, e1.getMessage()); 577 return e1.getMessage(); 578 } catch (ForbiddenException e2) { 579 httpServletResponse.sendError(HttpServletResponse.SC_FORBIDDEN, e2.getMessage()); 580 return e2.getMessage(); 581 } 508 582 } 509 583 } -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/rest/CachedRepresentationResource.java
r5468 r5679 21 21 import com.sun.jersey.multipart.MultiPart; 22 22 import eu.dasish.annotation.backend.BackendConstants; 23 import eu.dasish.annotation.backend.ForbiddenException; 23 24 import eu.dasish.annotation.backend.NotInDataBaseException; 24 25 import eu.dasish.annotation.backend.Resource; … … 37 38 import javax.imageio.ImageIO; 38 39 import javax.servlet.http.HttpServletRequest; 40 import javax.servlet.http.HttpServletResponse; 39 41 import javax.ws.rs.Consumes; 40 42 import javax.ws.rs.GET; … … 68 70 public JAXBElement<CachedRepresentationInfo> getCachedRepresentationInfo(@PathParam("cachedid") String externalId) throws IOException { 69 71 Map params = new HashMap(); 70 CachedRepresentationInfo result = (CachedRepresentationInfo) (new RequestWrappers(this)).wrapRequestResource(params, new GetCachedRepresentationInfo(), Resource.CACHED_REPRESENTATION, ResourceAction.READ, externalId); 71 if (result != null) { 72 return (new ObjectFactory()).createCashedRepresentationInfo(result); 73 } else { 74 return (new ObjectFactory()).createCashedRepresentationInfo(new CachedRepresentationInfo()); 72 try { 73 CachedRepresentationInfo result = (CachedRepresentationInfo) (new RequestWrappers(this)).wrapRequestResource(params, new GetCachedRepresentationInfo(), Resource.CACHED_REPRESENTATION, ResourceAction.READ, externalId); 74 if (result != null) { 75 return (new ObjectFactory()).createCashedRepresentationInfo(result); 76 } else { 77 return (new ObjectFactory()).createCashedRepresentationInfo(new CachedRepresentationInfo()); 78 } 79 } catch (NotInDataBaseException e1) { 80 httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, e1.getMessage()); 81 return new ObjectFactory().createCashedRepresentationInfo(new CachedRepresentationInfo()); 82 } catch (ForbiddenException e2) { 83 httpServletResponse.sendError(HttpServletResponse.SC_FORBIDDEN, e2.getMessage()); 84 return new ObjectFactory().createCashedRepresentationInfo(new CachedRepresentationInfo()); 75 85 } 76 86 } … … 92 102 public BufferedImage getCachedRepresentationContent(@PathParam("cachedid") String externalId) throws IOException { 93 103 Map params = new HashMap(); 94 InputStream result = (InputStream) (new RequestWrappers(this)).wrapRequestResource(params, new GetCachedRepresentationInputStream(), Resource.CACHED_REPRESENTATION, ResourceAction.READ, externalId); 95 if (result != null) { 96 ImageIO.setUseCache(false); 97 try { 98 BufferedImage retVal = ImageIO.read(result); 99 return retVal; 100 } catch (IOException e1) { 101 loggerServer.info(e1.toString()); 102 104 try { 105 InputStream result = (InputStream) (new RequestWrappers(this)).wrapRequestResource(params, new GetCachedRepresentationInputStream(), Resource.CACHED_REPRESENTATION, ResourceAction.READ, externalId); 106 if (result != null) { 107 ImageIO.setUseCache(false); 108 try { 109 BufferedImage retVal = ImageIO.read(result); 110 return retVal; 111 } catch (IOException e1) { 112 loggerServer.info(e1.toString()); 113 114 return null; 115 } 116 } else { 117 loggerServer.info(" The cached representation with the id " + externalId + " has null blob."); 103 118 return null; 104 119 } 105 } else { 106 loggerServer.info(" The cached representation with the id " + externalId + " has null blob."); 120 } catch (NotInDataBaseException e1) { 121 httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, e1.getMessage()); 122 return null; 123 } catch (ForbiddenException e2) { 124 httpServletResponse.sendError(HttpServletResponse.SC_FORBIDDEN, e2.getMessage()); 107 125 return null; 108 126 } … … 116 134 public InputStream getCachedRepresentationContentStream(@PathParam("cachedid") String externalId) throws IOException { 117 135 Map params = new HashMap(); 118 return (InputStream) (new RequestWrappers(this)).wrapRequestResource(params, new GetCachedRepresentationInputStream(), Resource.CACHED_REPRESENTATION, ResourceAction.READ, externalId); 136 try { 137 return (InputStream) (new RequestWrappers(this)).wrapRequestResource(params, new GetCachedRepresentationInputStream(), Resource.CACHED_REPRESENTATION, ResourceAction.READ, externalId); 138 } catch (NotInDataBaseException e1) { 139 httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, e1.getMessage()); 140 return null; 141 } catch (ForbiddenException e2) { 142 httpServletResponse.sendError(HttpServletResponse.SC_FORBIDDEN, e2.getMessage()); 143 return null; 144 } 119 145 } 120 146 … … 138 164 BodyPartEntity bpe = (BodyPartEntity) multiPart.getBodyParts().get(0).getEntity(); 139 165 params.put("stream", bpe.getInputStream()); 140 Integer result = (Integer) (new RequestWrappers(this)).wrapRequestResource(params, new UpdateCachedBlob(), Resource.CACHED_REPRESENTATION, ResourceAction.WRITE, cachedIdentifier); 141 if (result != null) { 142 return result + "rows are updated"; 143 } else { 144 return "Nothing is updated. "; 145 } 146 166 try { 167 Integer result = (Integer) (new RequestWrappers(this)).wrapRequestResource(params, new UpdateCachedBlob(), Resource.CACHED_REPRESENTATION, ResourceAction.WRITE, cachedIdentifier); 168 if (result != null) { 169 return result + "rows are updated"; 170 } else { 171 return "Nothing is updated. "; 172 } 173 } catch (NotInDataBaseException e1) { 174 httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, e1.getMessage()); 175 return e1.getMessage(); 176 } catch (ForbiddenException e2) { 177 httpServletResponse.sendError(HttpServletResponse.SC_FORBIDDEN, e2.getMessage()); 178 return e2.getMessage(); 179 } 147 180 148 181 } … … 161 194 input = blob.openStream(); 162 195 } else { 163 input = new FileInputStream 196 input = new FileInputStream(blobPath); 164 197 } 165 198 166 199 params.put("stream", input); 167 Integer result = (Integer) (new RequestWrappers(this)).wrapRequestResource(params, new UpdateCachedBlob(), Resource.CACHED_REPRESENTATION, ResourceAction.WRITE, cachedIdentifier); 168 input.close(); 169 if (result != null) { 170 return result + "rows are updated"; 171 } else { 172 return "Nothing is updated. "; 173 } 174 200 try { 201 Integer result = (Integer) (new RequestWrappers(this)).wrapRequestResource(params, new UpdateCachedBlob(), Resource.CACHED_REPRESENTATION, ResourceAction.WRITE, cachedIdentifier); 202 input.close(); 203 if (result != null) { 204 return result + "rows are updated"; 205 } else { 206 return "Nothing is updated. "; 207 } 208 } catch (NotInDataBaseException e1) { 209 httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, e1.getMessage()); 210 return e1.getMessage(); 211 } catch (ForbiddenException e2) { 212 httpServletResponse.sendError(HttpServletResponse.SC_FORBIDDEN, e2.getMessage()); 213 return e2.getMessage(); 214 } 175 215 176 216 } … … 199 239 Map params = new HashMap(); 200 240 params.put("info", cachedInfo); 201 Integer result = (Integer) (new RequestWrappers(this)).wrapRequestResource(params, new UpdateCachedMetadata(), Resource.CACHED_REPRESENTATION, ResourceAction.WRITE_W_METAINFO, cachedInfo.getId()); 202 if (result != null) { 203 return result + "rows are updated"; 204 } else { 205 return "Nothing is updated. "; 206 } 207 241 try { 242 Integer result = (Integer) (new RequestWrappers(this)).wrapRequestResource(params, new UpdateCachedMetadata(), Resource.CACHED_REPRESENTATION, ResourceAction.WRITE_W_METAINFO, cachedInfo.getId()); 243 if (result != null) { 244 return result + "rows are updated"; 245 } else { 246 return "Nothing is updated. "; 247 } 248 } catch (NotInDataBaseException e1) { 249 httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, e1.getMessage()); 250 return e1.getMessage(); 251 } catch (ForbiddenException e2) { 252 httpServletResponse.sendError(HttpServletResponse.SC_FORBIDDEN, e2.getMessage()); 253 return e2.getMessage(); 254 } 208 255 } 209 256 -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/rest/PrincipalResource.java
r5385 r5679 18 18 package eu.dasish.annotation.backend.rest; 19 19 20 import eu.dasish.annotation.backend.ForbiddenException; 20 21 import eu.dasish.annotation.backend.NotInDataBaseException; 21 22 import eu.dasish.annotation.backend.PrincipalCannotBeDeleted; … … 217 218 218 219 dbDispatcher.setResourcesPaths(this.getRelativeServiceURI()); 219 return (new RequestWrappers(this)).wrapAddPrincipalRequest(params, new RegisterNonShibbolizedPrincipal()); 220 try { 221 return (new RequestWrappers(this)).wrapAddPrincipalRequest(params, new RegisterNonShibbolizedPrincipal()); 222 } catch (NotInDataBaseException e1) { 223 httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, e1.getMessage()); 224 return new ObjectFactory().createPrincipal(new Principal()); 225 } catch (PrincipalExists e2) { 226 httpServletResponse.sendError(HttpServletResponse.SC_CONFLICT, e2.getMessage()); 227 return new ObjectFactory().createPrincipal(new Principal()); 228 } 220 229 } 221 230 … … 251 260 252 261 dbDispatcher.setResourcesPaths(this.getRelativeServiceURI()); 253 return (new RequestWrappers(this)).wrapAddPrincipalRequest(params, new RegisterShibbolizedPrincipal()); 262 try { 263 return (new RequestWrappers(this)).wrapAddPrincipalRequest(params, new RegisterShibbolizedPrincipal()); 264 } catch (NotInDataBaseException e1) { 265 httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, e1.getMessage()); 266 return new ObjectFactory().createPrincipal(new Principal()); 267 } catch (PrincipalExists e2) { 268 httpServletResponse.sendError(HttpServletResponse.SC_CONFLICT, e2.getMessage()); 269 return new ObjectFactory().createPrincipal(new Principal()); 270 } 254 271 } 255 272 -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/rest/RequestWrappers.java
r5385 r5679 18 18 package eu.dasish.annotation.backend.rest; 19 19 20 import eu.dasish.annotation.backend.ForbiddenException; 20 21 import eu.dasish.annotation.backend.NotInDataBaseException; 21 22 import eu.dasish.annotation.backend.PrincipalExists; … … 67 68 } 68 69 69 public T wrapRequestResource(Map params, ILambda<Map, T> dbRequestor, Resource resource, ResourceAction action, String externalId) throws IOException {70 public T wrapRequestResource(Map params, ILambda<Map, T> dbRequestor, Resource resource, ResourceAction action, String externalId) throws IOException, ForbiddenException, NotInDataBaseException { 70 71 Number principalID = resourceResource.getPrincipalID(); 71 72 if (principalID == null) { … … 73 74 } 74 75 params.put(_principalID, principalID); 75 try { 76 final Number resourceID = resourceResource.dbDispatcher.getResourceInternalIdentifier(UUID.fromString(externalId), resource); 77 if (resourceResource.dbDispatcher.canDo(action, principalID, resourceID, resource)) { 78 params.put(_externalId, externalId); 79 params.put(_internalID, resourceID); 80 params.put(_resourceType, resource); 81 return dbRequestor.apply(params); 82 } else { 83 this.FORBIDDEN_RESOURCE_ACTION(externalId, resource.name(), action.name()); 84 resourceResource.loggerServer.debug("Principal " + resourceResource.dbDispatcher.getResourceExternalIdentifier(principalID, Resource.PRINCIPAL) + " cannot " + action.name() + " " + resource.name() + " with the id " + externalId); 85 resourceResource.httpServletResponse.sendError(HttpServletResponse.SC_FORBIDDEN); 86 return null; 87 } 88 } catch (NotInDataBaseException e2) { 89 resourceResource.loggerServer.debug(e2.toString()); 90 resourceResource.httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, e2.toString()); 91 return null; 92 } 93 } 94 95 public JAXBElement<Principal> wrapAddPrincipalRequest(Map params, ILambdaPrincipal<Map, Principal> dbRequestor) throws IOException { 96 97 try { 98 try { 99 return new ObjectFactory().createPrincipal(dbRequestor.apply(params)); 100 } catch (NotInDataBaseException e1) { 101 resourceResource.loggerServer.debug(e1.toString()); 102 resourceResource.httpServletResponse.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e1.toString()); 103 return new ObjectFactory().createPrincipal(new Principal()); 104 } 105 } catch (PrincipalExists e) { 106 resourceResource.loggerServer.debug(e.toString()); 107 resourceResource.httpServletResponse.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e.toString()); 108 return new ObjectFactory().createPrincipal(new Principal()); 76 final Number resourceID = resourceResource.dbDispatcher.getResourceInternalIdentifier(UUID.fromString(externalId), resource); 77 if (resourceResource.dbDispatcher.canDo(action, principalID, resourceID, resource)) { 78 params.put(_externalId, externalId); 79 params.put(_internalID, resourceID); 80 params.put(_resourceType, resource); 81 return dbRequestor.apply(params); 82 } else { 83 throw new ForbiddenException(this.FORBIDDEN_RESOURCE_ACTION(externalId, resource.name(), action.name())); 109 84 } 110 85 111 86 } 87 88 public JAXBElement<Principal> wrapAddPrincipalRequest(Map params, ILambdaPrincipal<Map, Principal> dbRequestor) throws IOException, NotInDataBaseException, PrincipalExists { 89 return new ObjectFactory().createPrincipal(dbRequestor.apply(params)); 90 } 112 91 } -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/rest/TargetResource.java
r5385 r5679 21 21 import com.sun.jersey.multipart.MultiPart; 22 22 import eu.dasish.annotation.backend.BackendConstants; 23 import eu.dasish.annotation.backend.ForbiddenException; 23 24 import eu.dasish.annotation.backend.NotInDataBaseException; 24 25 import eu.dasish.annotation.backend.Resource; … … 28 29 import eu.dasish.annotation.schema.ObjectFactory; 29 30 import eu.dasish.annotation.schema.ReferenceList; 31 import eu.dasish.annotation.schema.ResponseBody; 30 32 import eu.dasish.annotation.schema.Target; 31 33 import java.io.IOException; … … 79 81 public JAXBElement<Target> getTarget(@PathParam("targetid") String externalIdentifier) throws IOException { 80 82 Map params = new HashMap(); 81 Target result = (Target) (new RequestWrappers(this)).wrapRequestResource(params, new GetTarget(), Resource.TARGET, ResourceAction.READ, externalIdentifier); 82 if (result != null) { 83 return new ObjectFactory().createTarget(result); 84 } else { 83 try { 84 Target result = (Target) (new RequestWrappers(this)).wrapRequestResource(params, new GetTarget(), Resource.TARGET, ResourceAction.READ, externalIdentifier); 85 if (result != null) { 86 return new ObjectFactory().createTarget(result); 87 } else { 88 return new ObjectFactory().createTarget(new Target()); 89 } 90 } catch (NotInDataBaseException e1) { 91 httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, e1.getMessage()); 92 return new ObjectFactory().createTarget(new Target()); 93 } catch (ForbiddenException e2) { 94 httpServletResponse.sendError(HttpServletResponse.SC_FORBIDDEN, e2.getMessage()); 85 95 return new ObjectFactory().createTarget(new Target()); 86 96 } … … 103 113 public JAXBElement<ReferenceList> getSiblingTargets(@PathParam("targetid") String externalIdentifier) throws HTTPException, IOException { 104 114 Map params = new HashMap(); 105 ReferenceList result = (ReferenceList) (new RequestWrappers(this)).wrapRequestResource(params, new GetSiblingTargets(), Resource.TARGET, ResourceAction.READ, externalIdentifier); 106 if (result != null) { 107 return new ObjectFactory().createReferenceList(result); 108 } else { 115 try { 116 ReferenceList result = (ReferenceList) (new RequestWrappers(this)).wrapRequestResource(params, new GetSiblingTargets(), Resource.TARGET, ResourceAction.READ, externalIdentifier); 117 if (result != null) { 118 return new ObjectFactory().createReferenceList(result); 119 } else { 120 return new ObjectFactory().createReferenceList(new ReferenceList()); 121 } 122 } catch (NotInDataBaseException e1) { 123 httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, e1.getMessage()); 124 return new ObjectFactory().createReferenceList(new ReferenceList()); 125 } catch (ForbiddenException e2) { 126 httpServletResponse.sendError(HttpServletResponse.SC_FORBIDDEN, e2.getMessage()); 109 127 return new ObjectFactory().createReferenceList(new ReferenceList()); 110 128 } … … 134 152 params.put("cachedBlob", bpe.getInputStream()); 135 153 params.put("fragmentDescriptor", fragmentDescriptor); 136 137 CachedRepresentationInfo result = (CachedRepresentationInfo) (new RequestWrappers(this)).wrapRequestResource(params, new PostCached(), Resource.TARGET, ResourceAction.WRITE_W_METAINFO, targetIdentifier); 138 if (result != null) { 139 return new ObjectFactory().createCashedRepresentationInfo(result); 140 } else { 154 try { 155 CachedRepresentationInfo result = (CachedRepresentationInfo) (new RequestWrappers(this)).wrapRequestResource(params, new PostCached(), Resource.TARGET, ResourceAction.WRITE_W_METAINFO, targetIdentifier); 156 if (result != null) { 157 return new ObjectFactory().createCashedRepresentationInfo(result); 158 } else { 159 return new ObjectFactory().createCashedRepresentationInfo(new CachedRepresentationInfo()); 160 } 161 } catch (NotInDataBaseException e1) { 162 httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, e1.getMessage()); 163 return new ObjectFactory().createCashedRepresentationInfo(new CachedRepresentationInfo()); 164 } catch (ForbiddenException e2) { 165 httpServletResponse.sendError(HttpServletResponse.SC_FORBIDDEN, e2.getMessage()); 141 166 return new ObjectFactory().createCashedRepresentationInfo(new CachedRepresentationInfo()); 142 167 } … … 152 177 InputStream cachedSource = (InputStream) params.get("cachedBlob"); 153 178 try { 154 final Number[] respondDB = dbDispatcher.addCachedForTarget(targetID, fragmentDescriptor, metadata, cachedSource);155 return dbDispatcher.getCachedRepresentationInfo(respondDB[1]);179 final Number[] respondDB = dbDispatcher.addCachedForTarget(targetID, fragmentDescriptor, metadata, cachedSource); 180 return dbDispatcher.getCachedRepresentationInfo(respondDB[1]); 156 181 } catch (IOException e) { 157 182 loggerServer.info(e.toString());
Note: See TracChangeset
for help on using the changeset viewer.