Changeset 4532
- Timestamp:
- 02/18/14 15:12:30 (10 years ago)
- Location:
- DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/rest
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/rest/AnnotationResource.java
r4529 r4532 122 122 return new ObjectFactory().createAnnotation(annotation); 123 123 } else { 124 verboseOutput.sendFailureMessage(VerboseOutput.FORBIDDEN_ANNOTATION_READING(externalIdentifier), HttpServletResponse.SC_FORBIDDEN); 125 } 126 } else { 127 verboseOutput.sendFailureMessage(VerboseOutput.REMOTE_PRINCIPAL_NOT_FOUND, httpServletResponse.SC_NOT_FOUND); 128 129 } 130 } else { 131 verboseOutput.sendFailureMessage(VerboseOutput.ANNOTATION_NOT_FOUND(externalIdentifier), HttpServletResponse.SC_NOT_FOUND); 132 } 133 } catch (IllegalArgumentException e) { 134 verboseOutput.sendFailureMessage(VerboseOutput.ILLEGAL_UUID(externalIdentifier), HttpServletResponse.SC_BAD_REQUEST); 124 verboseOutput.FORBIDDEN_ANNOTATION_READING(externalIdentifier); 125 } 126 } else { 127 verboseOutput.REMOTE_PRINCIPAL_NOT_FOUND(remoteUser); 128 } 129 } else { 130 verboseOutput.ANNOTATION_NOT_FOUND(externalIdentifier); 131 } 132 } catch (IllegalArgumentException e) { 133 verboseOutput.ILLEGAL_UUID(externalIdentifier); 135 134 } 136 135 return new ObjectFactory().createAnnotation(new Annotation()); … … 154 153 return new ObjectFactory().createTargetList(TargetList); 155 154 } else { 156 verboseOutput. sendFailureMessage(VerboseOutput.FORBIDDEN_ANNOTATION_READING(externalIdentifier), HttpServletResponse.SC_FORBIDDEN);157 } 158 } else { 159 verboseOutput. sendFailureMessage(VerboseOutput.REMOTE_PRINCIPAL_NOT_FOUND, httpServletResponse.SC_NOT_FOUND);160 161 } 162 } else { 163 verboseOutput. sendFailureMessage(VerboseOutput.ANNOTATION_NOT_FOUND(externalIdentifier), HttpServletResponse.SC_NOT_FOUND);164 165 } 166 } catch (IllegalArgumentException e) { 167 verboseOutput. sendFailureMessage(VerboseOutput.ILLEGAL_UUID(externalIdentifier), HttpServletResponse.SC_BAD_REQUEST);155 verboseOutput.FORBIDDEN_ANNOTATION_READING(externalIdentifier); 156 } 157 } else { 158 verboseOutput.REMOTE_PRINCIPAL_NOT_FOUND(remoteUser); 159 160 } 161 } else { 162 verboseOutput.ANNOTATION_NOT_FOUND(externalIdentifier); 163 164 } 165 } catch (IllegalArgumentException e) { 166 verboseOutput.ILLEGAL_UUID(externalIdentifier); 168 167 } 169 168 return new ObjectFactory().createTargetList(new ReferenceList()); … … 193 192 return new ObjectFactory().createAnnotationInfoList(annotationInfoList); 194 193 } catch (IllegalArgumentException e) { 195 verboseOutput. sendFailureMessage(VerboseOutput.ILLEGAL_UUID(ownerExternalId), HttpServletResponse.SC_BAD_REQUEST);194 verboseOutput.ILLEGAL_UUID(ownerExternalId); 196 195 } 197 196 } else { 198 verboseOutput. sendFailureMessage(VerboseOutput.REMOTE_PRINCIPAL_NOT_FOUND, httpServletResponse.SC_NOT_FOUND);197 verboseOutput.REMOTE_PRINCIPAL_NOT_FOUND(remoteUser); 199 198 200 199 } … … 219 218 return new ObjectFactory().createPermissionList(permissionList); 220 219 } else { 221 verboseOutput. sendFailureMessage(VerboseOutput.FORBIDDEN_ANNOTATION_READING(externalIdentifier), HttpServletResponse.SC_FORBIDDEN);222 } 223 } else { 224 verboseOutput. sendFailureMessage(VerboseOutput.ANNOTATION_NOT_FOUND(externalIdentifier), HttpServletResponse.SC_NOT_FOUND);225 } 226 } else { 227 verboseOutput. sendFailureMessage(VerboseOutput.REMOTE_PRINCIPAL_NOT_FOUND, httpServletResponse.SC_NOT_FOUND);228 229 } 230 } catch (IllegalArgumentException e) { 231 verboseOutput. sendFailureMessage(VerboseOutput.ILLEGAL_UUID(externalIdentifier), HttpServletResponse.SC_BAD_REQUEST);220 verboseOutput.FORBIDDEN_ANNOTATION_READING(externalIdentifier); 221 } 222 } else { 223 verboseOutput.ANNOTATION_NOT_FOUND(externalIdentifier); 224 } 225 } else { 226 verboseOutput.REMOTE_PRINCIPAL_NOT_FOUND(remoteUser); 227 228 } 229 } catch (IllegalArgumentException e) { 230 verboseOutput.ILLEGAL_UUID(externalIdentifier); 232 231 } 233 232 return new ObjectFactory().createUserWithPermissionList(new UserWithPermissionList()); … … 251 250 return result + " annotation(s) deleted."; 252 251 } else { 253 verboseOutput. sendFailureMessage(VerboseOutput.FORBIDDEN_ANNOTATION_WRITING(externalIdentifier) + " Only a principal with 'owner' access can delete the annotation.", HttpServletResponse.SC_FORBIDDEN);254 255 } 256 } else { 257 verboseOutput. sendFailureMessage(VerboseOutput.ANNOTATION_NOT_FOUND(externalIdentifier), HttpServletResponse.SC_NOT_FOUND);258 } 259 260 } else { 261 verboseOutput. sendFailureMessage(VerboseOutput.REMOTE_PRINCIPAL_NOT_FOUND, httpServletResponse.SC_NOT_FOUND);262 263 } 264 } catch (IllegalArgumentException e) { 265 verboseOutput. sendFailureMessage(VerboseOutput.ILLEGAL_UUID(externalIdentifier), HttpServletResponse.SC_BAD_REQUEST);252 verboseOutput.FORBIDDEN_ANNOTATION_WRITING(externalIdentifier); 253 254 } 255 } else { 256 verboseOutput.ANNOTATION_NOT_FOUND(externalIdentifier); 257 } 258 259 } else { 260 verboseOutput.REMOTE_PRINCIPAL_NOT_FOUND(remoteUser); 261 262 } 263 } catch (IllegalArgumentException e) { 264 verboseOutput.ILLEGAL_UUID(externalIdentifier); 266 265 } 267 266 … … 283 282 return new ObjectFactory().createResponseBody(makeAnnotationResponseEnvelope(annotationID)); 284 283 } else { 285 verboseOutput. sendFailureMessage(VerboseOutput.REMOTE_PRINCIPAL_NOT_FOUND, httpServletResponse.SC_NOT_FOUND);284 verboseOutput.REMOTE_PRINCIPAL_NOT_FOUND(remoteUser); 286 285 287 286 } … … 301 300 302 301 if (!(path + "annotations/" + externalIdentifier).equals(annotationURI)) { 303 verboseOutput. sendFailureMessage("Wrong request: the annotation identifier " + externalIdentifier + " and the annotation ID from the request body do not match. Correct the request and resend.", HttpServletResponse.SC_CONFLICT);302 verboseOutput.IDENTIFIER_MISMATCH(externalIdentifier); 304 303 return new ObjectFactory().createResponseBody(new ResponseBody()); 305 304 } … … 316 315 return new ObjectFactory().createResponseBody(makeAnnotationResponseEnvelope(annotationID)); 317 316 } else { 318 verboseOutput.sendFailureMessage(VerboseOutput.FORBIDDEN_PERMISSION_CHANGING(externalIdentifier) + " Permission changing is the part of the full update of the annotation.", HttpServletResponse.SC_FORBIDDEN); 319 } 320 } else { 321 verboseOutput.sendFailureMessage(VerboseOutput.REMOTE_PRINCIPAL_NOT_FOUND, httpServletResponse.SC_NOT_FOUND); 322 } 323 } else { 324 verboseOutput.sendFailureMessage(VerboseOutput.ANNOTATION_NOT_FOUND(externalIdentifier), HttpServletResponse.SC_NOT_FOUND); 325 } 326 } catch (IllegalArgumentException e) { 327 verboseOutput.sendFailureMessage(VerboseOutput.ILLEGAL_UUID(externalIdentifier), HttpServletResponse.SC_BAD_REQUEST); 317 verboseOutput.FORBIDDEN_PERMISSION_CHANGING(externalIdentifier); 318 loggerServer.debug(" Permission changing is the part of the full update of the annotation."); 319 } 320 } else { 321 verboseOutput.REMOTE_PRINCIPAL_NOT_FOUND(remoteUser); 322 } 323 } else { 324 verboseOutput.ANNOTATION_NOT_FOUND(externalIdentifier); 325 } 326 } catch (IllegalArgumentException e) { 327 verboseOutput.ILLEGAL_UUID(externalIdentifier); 328 328 } 329 329 return new ObjectFactory().createResponseBody(new ResponseBody()); … … 347 347 return new ObjectFactory().createResponseBody(makeAnnotationResponseEnvelope(annotationID)); 348 348 } else { 349 verboseOutput. sendFailureMessage(VerboseOutput.FORBIDDEN_ANNOTATION_WRITING(externalIdentifier), HttpServletResponse.SC_FORBIDDEN);350 } 351 } else { 352 verboseOutput. sendFailureMessage(VerboseOutput.ANNOTATION_NOT_FOUND(externalIdentifier), HttpServletResponse.SC_NOT_FOUND);353 } 354 } else { 355 verboseOutput. sendFailureMessage(VerboseOutput.REMOTE_PRINCIPAL_NOT_FOUND, httpServletResponse.SC_NOT_FOUND);356 357 } 358 } catch (IllegalArgumentException e) { 359 verboseOutput. sendFailureMessage(VerboseOutput.ILLEGAL_UUID(externalIdentifier), HttpServletResponse.SC_BAD_REQUEST);349 verboseOutput.FORBIDDEN_ANNOTATION_WRITING(externalIdentifier); 350 } 351 } else { 352 verboseOutput.ANNOTATION_NOT_FOUND(externalIdentifier); 353 } 354 } else { 355 verboseOutput.REMOTE_PRINCIPAL_NOT_FOUND(remoteUser); 356 357 } 358 } catch (IllegalArgumentException e) { 359 verboseOutput.ILLEGAL_UUID(externalIdentifier); 360 360 } 361 361 return new ObjectFactory().createResponseBody(new ResponseBody()); … … 385 385 386 386 } else { 387 verboseOutput. sendFailureMessage(VerboseOutput.FORBIDDEN_PERMISSION_CHANGING(annotationExternalId), HttpServletResponse.SC_FORBIDDEN);387 verboseOutput.FORBIDDEN_PERMISSION_CHANGING(annotationExternalId); 388 388 } 389 389 } else { 390 verboseOutput. sendFailureMessage(VerboseOutput.ANNOTATION_NOT_FOUND(annotationExternalId), HttpServletResponse.SC_NOT_FOUND);390 verboseOutput.ANNOTATION_NOT_FOUND(annotationExternalId); 391 391 } 392 392 } catch (IllegalArgumentException e) { 393 verboseOutput. sendFailureMessage(VerboseOutput.ILLEGAL_UUID(annotationExternalId), HttpServletResponse.SC_BAD_REQUEST);394 } 395 } else { 396 verboseOutput. sendFailureMessage(VerboseOutput.PRINCIPAL_NOT_FOUND(userExternalId), HttpServletResponse.SC_NOT_FOUND);393 verboseOutput.ILLEGAL_UUID(annotationExternalId); 394 } 395 } else { 396 verboseOutput.PRINCIPAL_NOT_FOUND(userExternalId); 397 397 } 398 398 } catch (IllegalArgumentException e) { 399 verboseOutput. sendFailureMessage(VerboseOutput.ILLEGAL_UUID(userExternalId), HttpServletResponse.SC_BAD_REQUEST);399 verboseOutput.ILLEGAL_UUID(userExternalId); 400 400 } 401 401 402 402 } else { 403 verboseOutput. sendFailureMessage(VerboseOutput.REMOTE_PRINCIPAL_NOT_FOUND, httpServletResponse.SC_NOT_FOUND);403 verboseOutput.REMOTE_PRINCIPAL_NOT_FOUND(remoteUser); 404 404 405 405 } … … 423 423 return new ObjectFactory().createResponseBody(makePermissionResponseEnvelope(annotationID)); 424 424 } else { 425 verboseOutput. sendFailureMessage(VerboseOutput.FORBIDDEN_PERMISSION_CHANGING(annotationExternalId), HttpServletResponse.SC_FORBIDDEN);426 } 427 } else { 428 verboseOutput. sendFailureMessage(VerboseOutput.ANNOTATION_NOT_FOUND(annotationExternalId), HttpServletResponse.SC_NOT_FOUND);429 } 430 } else { 431 verboseOutput. sendFailureMessage(VerboseOutput.REMOTE_PRINCIPAL_NOT_FOUND, httpServletResponse.SC_NOT_FOUND);425 verboseOutput.FORBIDDEN_PERMISSION_CHANGING(annotationExternalId); 426 } 427 } else { 428 verboseOutput.ANNOTATION_NOT_FOUND(annotationExternalId); 429 } 430 } else { 431 verboseOutput.REMOTE_PRINCIPAL_NOT_FOUND(remoteUser); 432 432 433 433 } … … 435 435 436 436 } catch (IllegalArgumentException e) { 437 verboseOutput. sendFailureMessage(VerboseOutput.ILLEGAL_UUID(annotationExternalId), HttpServletResponse.SC_BAD_REQUEST);437 verboseOutput.ILLEGAL_UUID(annotationExternalId); 438 438 return new ObjectFactory().createResponseBody(new ResponseBody()); 439 439 … … 459 459 460 460 } else { 461 verboseOutput. sendFailureMessage(VerboseOutput.PRINCIPAL_NOT_FOUND(userId), HttpServletResponse.SC_NOT_FOUND);461 verboseOutput.PRINCIPAL_NOT_FOUND(userId); 462 462 } 463 463 } else { 464 verboseOutput. sendFailureMessage(VerboseOutput.FORBIDDEN_PERMISSION_CHANGING(annotationId), HttpServletResponse.SC_FORBIDDEN);465 466 } 467 } else { 468 verboseOutput. sendFailureMessage(VerboseOutput.ANNOTATION_NOT_FOUND(annotationId), HttpServletResponse.SC_NOT_FOUND);469 } 470 } else { 471 verboseOutput. sendFailureMessage(VerboseOutput.REMOTE_PRINCIPAL_NOT_FOUND, httpServletResponse.SC_NOT_FOUND);472 473 } 474 } catch (IllegalArgumentException e) { 475 verboseOutput. sendFailureMessage(VerboseOutput.ILLEGAL_UUID(annotationId), HttpServletResponse.SC_BAD_REQUEST);464 verboseOutput.FORBIDDEN_PERMISSION_CHANGING(annotationId); 465 466 } 467 } else { 468 verboseOutput.ANNOTATION_NOT_FOUND(annotationId); 469 } 470 } else { 471 verboseOutput.REMOTE_PRINCIPAL_NOT_FOUND(remoteUser); 472 473 } 474 } catch (IllegalArgumentException e) { 475 verboseOutput.ILLEGAL_UUID(annotationId); 476 476 } 477 477 return (deletedRows + " is deleted."); -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/rest/CachedRepresentationResource.java
r4301 r4532 62 62 @Context 63 63 private UriInfo uriInfo; 64 private final Logger logger = LoggerFactory.getLogger(CachedRepresentationResource.class); 65 64 public static final Logger loggerServer = LoggerFactory.getLogger(HttpServletResponse.class); 65 private final VerboseOutput verboseOutput = new VerboseOutput(httpServletResponse, loggerServer); 66 67 66 68 public void setHttpRequest(HttpServletRequest request) { 67 69 this.httpServletRequest = request; … … 86 88 return new ObjectFactory().createCashedRepresentationInfo(cachedInfo); 87 89 } else { 88 AnnotationResource.loggerServer.debug(httpServletResponse.SC_NOT_FOUND + ": The cached representation with the given id is not found in the database"); 89 httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, "The cached representation with the given id is not found in the database"); 90 return null; 90 verboseOutput.CACHED_REPRESENTATION_NOT_FOUND(externalId); 91 91 } 92 92 } catch (IllegalArgumentException e) { 93 AnnotationResource.loggerServer.debug(HttpServletResponse.SC_BAD_REQUEST + ": Illegal argument UUID " + externalId); 94 httpServletResponse.sendError(HttpServletResponse.SC_BAD_REQUEST, "Illegal argument UUID " + externalId); 95 return null; 93 verboseOutput.ILLEGAL_UUID(externalId); 96 94 } 97 95 } else { 98 AnnotationResource.loggerServer.debug(httpServletResponse.SC_NOT_FOUND + ": the logged-in user is not found in the database"); 99 httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, "The logged in user is not found in the database"); 100 return null; 96 verboseOutput.REMOTE_PRINCIPAL_NOT_FOUND(remoteUser); 101 97 } 98 99 return new ObjectFactory().createCashedRepresentationInfo(new CachedRepresentationInfo()); 102 100 } 103 101 … … 119 117 return result; 120 118 } else { 121 AnnotationResource.loggerServer.debug(httpServletResponse.SC_NOT_FOUND + "The cached representation with the given id is not found in the database"); 122 httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, "The cached representation with the given id " + externalId + " is not found in the database"); 123 return null; 119 verboseOutput.ANNOTATION_NOT_FOUND(externalId); 124 120 } 125 121 } catch (IllegalArgumentException e) { 126 AnnotationResource.loggerServer.debug(HttpServletResponse.SC_BAD_REQUEST + ": Illegal argument UUID " + externalId); 127 httpServletResponse.sendError(HttpServletResponse.SC_BAD_REQUEST, "Illegal argument UUID " + externalId); 128 return null; 122 verboseOutput.ILLEGAL_UUID(externalId); 129 123 } 130 124 } else { 131 AnnotationResource.loggerServer.debug(httpServletResponse.SC_NOT_FOUND + ": the logged-in user is not found in the database"); 132 httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, "The logged-in user is not found in the database"); 133 return null; 125 verboseOutput.REMOTE_PRINCIPAL_NOT_FOUND(remoteUser); 134 126 } 127 128 return null; 135 129 } 136 130 } -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/rest/DebugResource.java
r4281 r4532 52 52 @Path("/debug") 53 53 public class DebugResource { 54 @Autowired 54 55 @Autowired 55 56 private DBIntegrityService dbIntegrityService; 56 57 @Context … … 60 61 @Context 61 62 private UriInfo uriInfo; 62 63 63 @Context 64 64 private ServletContext context; 65 66 65 final String default_permission = "reader"; 67 private final Logger logger = LoggerFactory.getLogger(DebugResource.class); 66 public static final Logger loggerServer = LoggerFactory.getLogger(HttpServletResponse.class); 67 private final VerboseOutput verboseOutput = new VerboseOutput(httpServletResponse, loggerServer); 68 68 private final String admin = "admin"; 69 private final String developer = "developer"; 70 69 private final String developer = "developer"; 70 71 71 @GET 72 72 @Produces(MediaType.TEXT_XML) … … 83 83 return new ObjectFactory().createAnnotationInfoList(annotationInfoList); 84 84 } else { 85 httpServletResponse.sendError(HttpServletResponse.SC_FORBIDDEN, "The logged-in user is neither developer nor admin, and therefore cannot perform this request."); 86 return null; 85 verboseOutput.DEVELOPER_RIGHTS_EXPECTED(); 87 86 } 88 87 } else { 89 httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, "The logged-in user is not found in the database"); 90 return null; 88 verboseOutput.REMOTE_PRINCIPAL_NOT_FOUND(remoteUser); 91 89 } 92 90 return new ObjectFactory().createAnnotationInfoList(new AnnotationInfoList()); 93 91 } 94 92 … … 98 96 @Transactional(readOnly = true) 99 97 public String getDasishBackendLog(@PathParam("n") int n) throws IOException { 100 return logFile("eu.dasish.annotation.backend.logDatabaseLocation", n); 98 dbIntegrityService.setServiceURI(uriInfo.getBaseUri().toString()); 99 String remoteUser = httpServletRequest.getRemoteUser(); 100 Number userID = dbIntegrityService.getUserInternalIDFromRemoteID(remoteUser); 101 if (userID != null) { 102 String typeOfAccount = dbIntegrityService.getTypeOfUserAccount(userID); 103 if (typeOfAccount.equals(admin) || typeOfAccount.equals(developer)) { 104 return logFile("eu.dasish.annotation.backend.logDatabaseLocation", n); 105 } else { 106 verboseOutput.DEVELOPER_RIGHTS_EXPECTED(); 107 } 108 } else { 109 verboseOutput.REMOTE_PRINCIPAL_NOT_FOUND(remoteUser); 110 } 111 return " "; 101 112 } 102 113 103 114 @GET 104 115 @Produces(MediaType.TEXT_PLAIN) … … 108 119 return httpServletRequest.getRemoteUser(); 109 120 } 110 121 111 122 ///// 112 113 123 @GET 114 124 @Produces(MediaType.TEXT_PLAIN) … … 116 126 @Transactional(readOnly = true) 117 127 public String getDasishServerLog(@PathParam("n") int n) throws IOException { 118 return logFile("eu.dasish.annotation.backend.logServerLocation", n); 128 String remoteUser = httpServletRequest.getRemoteUser(); 129 Number userID = dbIntegrityService.getUserInternalIDFromRemoteID(remoteUser); 130 if (userID != null) { 131 String typeOfAccount = dbIntegrityService.getTypeOfUserAccount(userID); 132 if (typeOfAccount.equals(admin) || typeOfAccount.equals(developer)) { 133 return logFile("eu.dasish.annotation.backend.logServerLocation", n); 134 } else { 135 verboseOutput.DEVELOPER_RIGHTS_EXPECTED(); 136 } 137 } else { 138 verboseOutput.REMOTE_PRINCIPAL_NOT_FOUND(remoteUser); 139 } 140 return " "; 141 119 142 } 120 143 121 144 ////////////////////////////////// 122 145 @PUT … … 134 157 return (update ? "The account is updated" : "The account is not updated, see the log."); 135 158 } else { 136 httpServletResponse.sendError(HttpServletResponse.SC_FORBIDDEN, "The logged-in user is not admin, and therefore cannot perform this request."); 137 return null; 159 verboseOutput.ADMIN_RIGHTS_EXPECTED(); 138 160 } 139 161 } else { 140 httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, "The logged-in user is not found in the database"); 141 return null; 162 verboseOutput.REMOTE_PRINCIPAL_NOT_FOUND(remoteUser); 142 163 } 143 164 return " "; 144 165 } 145 166 146 167 /////////////////////////////////////////////////// 147 private String logFile(String location, int n) throws IOException{ 148 dbIntegrityService.setServiceURI(uriInfo.getBaseUri().toString()); 149 String remoteUser = httpServletRequest.getRemoteUser(); 150 Number userID = dbIntegrityService.getUserInternalIDFromRemoteID(remoteUser); 151 if (userID != null) { 152 String typeOfAccount = dbIntegrityService.getTypeOfUserAccount(userID); 153 if (typeOfAccount.equals(admin) || typeOfAccount.equals(developer)) { 154 BufferedReader reader = new BufferedReader(new FileReader(context.getInitParameter(location))); 155 List<String> lines = new ArrayList<String>(); 156 StringBuilder result = new StringBuilder(); 157 int i = 0; 158 String line; 159 while ((line = reader.readLine()) != null) { 160 lines.add(line); 161 i++; 162 } 163 // want to read the last n rows, i.e. the rows (i-1), (i-1-1),...,(i-1-(n-1)) 164 int last = (i > n) ? (i - n) : 0; 165 for (int j = i - 1; j >= last; j--) { 166 result.append(lines.get(j)).append("\n"); 167 } 168 return result.toString(); 169 170 } else { 171 httpServletResponse.sendError(HttpServletResponse.SC_FORBIDDEN, "The logged-in user is neither developer nor admin, and therefore cannot perform this request."); 172 return null; 173 } 174 } else { 175 httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, "The logged-in user is not found in the database"); 176 return null; 177 } 168 private String logFile(String location, int n) throws IOException { 169 BufferedReader reader = new BufferedReader(new FileReader(context.getInitParameter(location))); 170 List<String> lines = new ArrayList<String>(); 171 StringBuilder result = new StringBuilder(); 172 int i = 0; 173 String line; 174 while ((line = reader.readLine()) != null) { 175 lines.add(line); 176 i++; 177 } 178 // want to read the last n rows, i.e. the rows (i-1), (i-1-1),...,(i-1-(n-1)) 179 int last = (i > n) ? (i - n) : 0; 180 for (int j = i - 1; j >= last; j--) { 181 result.append(lines.get(j)).append("\n"); 182 } 183 return result.toString(); 178 184 } 179 185 } -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/rest/NotebookResource.java
r4529 r4532 88 88 return new ObjectFactory().createNotebookInfoList(notebookInfos); 89 89 } else { 90 verboseOutput. sendFailureMessage(VerboseOutput.INVALID_PERMISSION_MODE(permissionMode), httpServletResponse.SC_BAD_REQUEST);91 } 92 } else { 93 verboseOutput. sendFailureMessage(VerboseOutput.REMOTE_PRINCIPAL_NOT_FOUND, httpServletResponse.SC_NOT_FOUND);90 verboseOutput.INVALID_PERMISSION_MODE(permissionMode); 91 } 92 } else { 93 verboseOutput.REMOTE_PRINCIPAL_NOT_FOUND(remoteUser); 94 94 } 95 95 return (new ObjectFactory()).createNotebookInfoList(new NotebookInfoList()); … … 110 110 return new ObjectFactory().createReferenceList(references); 111 111 } else { 112 verboseOutput. sendFailureMessage(VerboseOutput.REMOTE_PRINCIPAL_NOT_FOUND, httpServletResponse.SC_NOT_FOUND);112 verboseOutput.REMOTE_PRINCIPAL_NOT_FOUND(remoteUser); 113 113 } 114 114 return new ObjectFactory().createReferenceList(new ReferenceList()); … … 132 132 return new ObjectFactory().createReferenceList(principals); 133 133 } else { 134 verboseOutput. sendFailureMessage(VerboseOutput.FORBIDDEN_NOTEBOOK_READING(externalIdentifier), HttpServletResponse.SC_FORBIDDEN);134 verboseOutput.FORBIDDEN_NOTEBOOK_READING(externalIdentifier); 135 135 } 136 136 } else { 137 verboseOutput. sendFailureMessage(VerboseOutput.NOTEBOOK_NOT_FOUND(externalIdentifier), HttpServletResponse.SC_NOT_FOUND);138 } 139 } else { 140 verboseOutput. sendFailureMessage(VerboseOutput.REMOTE_PRINCIPAL_NOT_FOUND, HttpServletResponse.SC_NOT_FOUND);137 verboseOutput.NOTEBOOK_NOT_FOUND(externalIdentifier); 138 } 139 } else { 140 verboseOutput.REMOTE_PRINCIPAL_NOT_FOUND(remoteUser); 141 141 } 142 142 … … 164 164 return new ObjectFactory().createNotebook(notebook); 165 165 } else { 166 verboseOutput. sendFailureMessage(VerboseOutput.FORBIDDEN_NOTEBOOK_READING(externalIdentifier), HttpServletResponse.SC_FORBIDDEN);166 verboseOutput.FORBIDDEN_NOTEBOOK_READING(externalIdentifier); 167 167 } 168 168 } else { 169 verboseOutput. sendFailureMessage(VerboseOutput.NOTEBOOK_NOT_FOUND(externalIdentifier), HttpServletResponse.SC_NOT_FOUND);170 } 171 } else { 172 verboseOutput. sendFailureMessage(VerboseOutput.REMOTE_PRINCIPAL_NOT_FOUND, HttpServletResponse.SC_NOT_FOUND);169 verboseOutput.NOTEBOOK_NOT_FOUND(externalIdentifier); 170 } 171 } else { 172 verboseOutput.REMOTE_PRINCIPAL_NOT_FOUND(remoteUser); 173 173 } 174 174 return new ObjectFactory().createNotebook(new Notebook()); … … 196 196 return new ObjectFactory().createReferenceList(annotations); 197 197 } else { 198 verboseOutput. sendFailureMessage(VerboseOutput.FORBIDDEN_NOTEBOOK_READING(externalIdentifier), HttpServletResponse.SC_FORBIDDEN);198 verboseOutput.FORBIDDEN_NOTEBOOK_READING(externalIdentifier); 199 199 } 200 200 } else { 201 verboseOutput. sendFailureMessage(VerboseOutput.NOTEBOOK_NOT_FOUND(externalIdentifier), HttpServletResponse.SC_NOT_FOUND);202 } 203 } else { 204 verboseOutput. sendFailureMessage(VerboseOutput.REMOTE_PRINCIPAL_NOT_FOUND, HttpServletResponse.SC_NOT_FOUND);201 verboseOutput.NOTEBOOK_NOT_FOUND(externalIdentifier); 202 } 203 } else { 204 verboseOutput.REMOTE_PRINCIPAL_NOT_FOUND(remoteUser); 205 205 } 206 206 return new ObjectFactory().createReferenceList(new ReferenceList()); -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/rest/TargetResource.java
r4301 r4532 71 71 @Context 72 72 private UriInfo uriInfo; 73 p rivate final Logger logger = LoggerFactory.getLogger(TargetResource.class);74 73 public static final Logger loggerServer = LoggerFactory.getLogger(HttpServletResponse.class); 74 private final VerboseOutput verboseOutput = new VerboseOutput(httpServletResponse, loggerServer); 75 75 public void setHttpRequest(HttpServletRequest request) { 76 76 this.httpServletRequest = request; … … 96 96 return new ObjectFactory().createTarget(target); 97 97 } else { 98 AnnotationResource.loggerServer.debug(HttpServletResponse.SC_NOT_FOUND + ": The target with the given id " + externalIdentifier + " is not found in the database"); 99 httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, "The target with the given id " + externalIdentifier + " is not found in the database"); 100 return null; 101 } 102 } catch (IllegalArgumentException e) { 103 AnnotationResource.loggerServer.debug(HttpServletResponse.SC_BAD_REQUEST + ": Illegal argument UUID " + externalIdentifier); 104 httpServletResponse.sendError(HttpServletResponse.SC_BAD_REQUEST, "Illegal argument UUID " + externalIdentifier); 105 return null; 106 } 107 } else { 108 AnnotationResource.loggerServer.debug(httpServletResponse.SC_NOT_FOUND + ": the logged-in user is not found in the database"); 109 httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, "The logged-in user is not found in the database"); 110 return null; 111 } 98 verboseOutput.TARGET_NOT_FOUND(externalIdentifier); 99 } 100 } catch (IllegalArgumentException e) { 101 verboseOutput.ILLEGAL_UUID(externalIdentifier); 102 } 103 } else { 104 verboseOutput.REMOTE_PRINCIPAL_NOT_FOUND(remoteUser); 105 } 106 return new ObjectFactory().createTarget(new Target()); 112 107 } 113 108 … … 128 123 return new ObjectFactory().createReferenceList(siblings); 129 124 } else { 130 AnnotationResource.loggerServer.debug(HttpServletResponse.SC_NOT_FOUND + ": The target with the given id " + externalIdentifier + " is not found in the database"); 131 httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, "The target with the given id " + externalIdentifier + " is not found in the database"); 132 return null; 133 } 134 } catch (IllegalArgumentException e) { 135 AnnotationResource.loggerServer.debug(HttpServletResponse.SC_BAD_REQUEST + ": Illegal argument UUID " + externalIdentifier); 136 httpServletResponse.sendError(HttpServletResponse.SC_BAD_REQUEST, "Illegal argument UUID " + externalIdentifier); 137 return null; 138 } 139 } else { 140 AnnotationResource.loggerServer.debug(httpServletResponse.SC_NOT_FOUND + ": the logged-in user is not found in the database"); 141 httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, "The logged-in user is not found in the database"); 142 return null; 143 } 144 } 145 146 // TODO both unit tests 147 //changed path, /Targetpart is removed 148 //how to overwork the input stream to make it downloadable 149 // using mime type as well 150 // @DELETE 151 // @Produces(MediaType.TEXT_XML) 152 // @Path("{targetid: " + BackendConstants.regExpIdentifier + "}/cached/{cachedid: " + BackendConstants.regExpIdentifier + "}") 153 // @Secured("ROLE_ADMIN") 154 // public int deleteCached(@PathParam("targetid") String targetIdentifier, @PathParam("cachedid") String cachedIdentifier) throws SQLException { 155 // dbIntegrityService.setServiceURI(uriInfo.getBaseUri().toString()); 156 // final Number targetID = dbIntegrityService.getCachedRepresentationInternalIdentifier(UUID.fromString(targetIdentifier)); 157 // final Number cachedID = dbIntegrityService.getCachedRepresentationInternalIdentifier(UUID.fromString(cachedIdentifier)); 158 // int[] result = dbIntegrityService.deleteCachedRepresentationOfTarget(targetID, cachedID); 159 // return result[1]; 160 // } 125 verboseOutput.TARGET_NOT_FOUND(externalIdentifier); 126 } 127 } catch (IllegalArgumentException e) { 128 verboseOutput.ILLEGAL_UUID(externalIdentifier); 129 } 130 } else { 131 verboseOutput.REMOTE_PRINCIPAL_NOT_FOUND(remoteUser); 132 } 133 134 return new ObjectFactory().createReferenceList(new ReferenceList()); 135 } 136 137 161 138 @POST 162 139 @Consumes("multipart/mixed") … … 178 155 final Number[] respondDB = dbIntegrityService.addCachedForTarget(targetID, fragmentDescriptor, metadata, cachedSource); 179 156 final CachedRepresentationInfo cachedInfo = dbIntegrityService.getCachedRepresentationInfo(respondDB[1]); 180 return new ObjectFactory() 181 .createCashedRepresentationInfo(cachedInfo); 182 } else { 183 AnnotationResource.loggerServer.debug(HttpServletResponse.SC_NOT_FOUND + ": The target with the given id " + targetIdentifier + " is not found in the database"); 184 httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, "The target with the given id " + targetIdentifier + " is not found in the database"); 185 return null; 186 } 187 } catch (IllegalArgumentException e) { 188 AnnotationResource.loggerServer.debug(HttpServletResponse.SC_BAD_REQUEST + ": Illegal argument UUID " + targetIdentifier); 189 httpServletResponse.sendError(HttpServletResponse.SC_BAD_REQUEST, "Illegal argument UUID " + targetIdentifier); 190 return null; 191 } 192 } else { 193 AnnotationResource.loggerServer.debug(httpServletResponse.SC_NOT_FOUND + ": the logged-in user is not found in the database"); 194 httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, "The logged-in user is not found in the database"); 195 return null; 196 } 197 157 return new ObjectFactory().createCashedRepresentationInfo(cachedInfo); 158 } else { 159 verboseOutput.TARGET_NOT_FOUND(targetIdentifier); 160 } 161 } catch (IllegalArgumentException e) { 162 verboseOutput.ILLEGAL_UUID(targetIdentifier); 163 } 164 } else { 165 verboseOutput.REMOTE_PRINCIPAL_NOT_FOUND(remoteUser); 166 } 167 return new ObjectFactory().createCashedRepresentationInfo(new CachedRepresentationInfo()); 198 168 } 199 169 … … 215 185 return result + " pair(s) target-cached deleted."; 216 186 } else { 217 AnnotationResource.loggerServer.debug(HttpServletResponse.SC_NOT_FOUND + ": The target with the given id " + cachedExternalIdentifier + " is not found in the database"); 218 httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, "The cached representation with the given id " + cachedExternalIdentifier + " is not found in the database"); 219 return null; 187 verboseOutput.CACHED_REPRESENTATION_NOT_FOUND(cachedExternalIdentifier); 220 188 } 221 189 } else { 222 AnnotationResource.loggerServer.debug(HttpServletResponse.SC_NOT_FOUND + ": The target with the given id " + cachedExternalIdentifier + " is not found in the database"); 223 httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, "The target with the given id " + targetExternalIdentifier + " is not found in the database"); 224 return null; 225 } 226 } catch (IllegalArgumentException e) { 227 AnnotationResource.loggerServer.debug(HttpServletResponse.SC_BAD_REQUEST + ": Illegal argument UUID " + targetExternalIdentifier); 228 httpServletResponse.sendError(HttpServletResponse.SC_BAD_REQUEST, "Illegal argument UUID " + targetExternalIdentifier); 229 return null; 230 } 231 } else { 232 AnnotationResource.loggerServer.debug(httpServletResponse.SC_NOT_FOUND + ": the logged-in user is not found in the database"); 233 httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, "The logged in user is not found in the database"); 234 return null; 235 } 190 verboseOutput.TARGET_NOT_FOUND(targetExternalIdentifier); 191 } 192 } catch (IllegalArgumentException e) { 193 verboseOutput.ILLEGAL_UUID(targetExternalIdentifier); 194 } 195 } else { 196 verboseOutput.REMOTE_PRINCIPAL_NOT_FOUND(remoteUser); 197 } 198 return " "; 236 199 } 237 200 } -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/rest/UserResource.java
r4351 r4532 65 65 @Context 66 66 private UriInfo uriInfo; 67 private final Logger logger = LoggerFactory.getLogger(UserResource.class); 67 public static final Logger loggerServer = LoggerFactory.getLogger(HttpServletResponse.class); 68 private final VerboseOutput verboseOutput = new VerboseOutput(httpServletResponse, loggerServer); 69 68 70 final private String admin = "admin"; 69 71 … … 90 92 return new ObjectFactory().createUser(user); 91 93 } else { 92 AnnotationResource.loggerServer.debug(HttpServletResponse.SC_NOT_FOUND + ": The user with the given id " + externalIdentifier + " is not found in the database"); 93 httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, "The user with the given id " + externalIdentifier + " is not found in the database"); 94 return null; 94 verboseOutput.PRINCIPAL_NOT_FOUND(externalIdentifier); 95 95 } 96 96 } catch (IllegalArgumentException e) { 97 AnnotationResource.loggerServer.debug(HttpServletResponse.SC_BAD_REQUEST + ": Illegal argument UUID " + externalIdentifier); 98 httpServletResponse.sendError(HttpServletResponse.SC_BAD_REQUEST, "Illegal argument UUID " + externalIdentifier); 99 return null; 100 } 101 } else { 102 AnnotationResource.loggerServer.debug(httpServletResponse.SC_NOT_FOUND + ": the logged-in user is not found in the database"); 103 httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, "The logged-in user is not found in the database"); 104 return null; 105 } 97 verboseOutput.ILLEGAL_UUID(externalIdentifier); 98 } 99 } else { 100 verboseOutput.REMOTE_PRINCIPAL_NOT_FOUND(remoteUser); 101 } 102 return new ObjectFactory().createUser(new User()); 106 103 } 107 104 … … 119 116 return new ObjectFactory().createUser(user); 120 117 } else { 121 AnnotationResource.loggerServer.debug(HttpServletResponse.SC_NOT_FOUND + ": The user with the given info is not found in the database"); 122 httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, "The user with the given info is not found in the database"); 123 return null; 124 } 125 } else { 126 AnnotationResource.loggerServer.debug(httpServletResponse.SC_NOT_FOUND + ": the logged-in user is not found in the database"); 127 httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, "The logged-in user is not found in the database"); 128 return null; 129 } 118 verboseOutput.PRINCIPAL_NOT_FOUND_BY_INFO(email); 119 } 120 } else { 121 verboseOutput.REMOTE_PRINCIPAL_NOT_FOUND(remoteUser); 122 } 123 return new ObjectFactory().createUser(new User()); 130 124 } 131 125 … … 147 141 return new ObjectFactory().createCurrentUserInfo(userInfo); 148 142 } else { 149 AnnotationResource.loggerServer.debug(HttpServletResponse.SC_NOT_FOUND + ": The user with the given id " + externalIdentifier + " is not found in the database"); 150 httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, "The user with the given id " + externalIdentifier + " is not found in the database"); 151 return null; 143 verboseOutput.PRINCIPAL_NOT_FOUND(externalIdentifier); 152 144 } 153 145 } catch (IllegalArgumentException e) { 154 AnnotationResource.loggerServer.debug(HttpServletResponse.SC_BAD_REQUEST + ": Illegal argument UUID " + externalIdentifier); 155 httpServletResponse.sendError(HttpServletResponse.SC_BAD_REQUEST, "Illegal argument UUID " + externalIdentifier); 156 return null; 157 } 158 } else { 159 AnnotationResource.loggerServer.debug(httpServletResponse.SC_NOT_FOUND + ": the logged-in user is not found in the database"); 160 httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, "The logged-in user is not found in the database"); 161 return null; 162 } 146 verboseOutput.ILLEGAL_UUID(externalIdentifier); 147 } 148 } else { 149 verboseOutput.REMOTE_PRINCIPAL_NOT_FOUND(remoteUser); 150 } 151 152 return new ObjectFactory().createCurrentUserInfo(new CurrentUserInfo()); 163 153 } 164 154 … … 178 168 return new ObjectFactory().createUser(addedUser); 179 169 } else { 180 httpServletResponse.sendError(HttpServletResponse.SC_CONFLICT, "The user canot be added to the database, (possibly) because a user with the given e-mail already exist in the database."); 181 return null; 182 } 183 } else { 184 httpServletResponse.sendError(HttpServletResponse.SC_UNAUTHORIZED, "The logged-in user does not have admin rights to add a user to the database"); 185 return null; 186 } 187 } else { 188 httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, "The logged-in user is not found in the database"); 189 return null; 190 } 170 verboseOutput.PRINCIPAL_IS_NOT_ADDED_TO_DB(); 171 } 172 } else { 173 verboseOutput.ADMIN_RIGHTS_EXPECTED(); 174 } 175 } else { 176 verboseOutput.REMOTE_PRINCIPAL_NOT_FOUND(remoteUser); 177 } 178 return new ObjectFactory().createUser(new User()); 191 179 } 192 180 … … 206 194 return new ObjectFactory().createUser(addedUser); 207 195 } else { 208 AnnotationResource.loggerServer.debug(HttpServletResponse.SC_NOT_FOUND + ": The user with the given id is not found in the database"); 209 httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, "The user with the given id is not found in the database"); 210 return null; 211 } 212 } else { 213 httpServletResponse.sendError(HttpServletResponse.SC_UNAUTHORIZED, "The logged-in user does not have admin rights to update a user info in the database"); 214 return null; 215 } 216 } else { 217 httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, "The logged-in user is not found in the database"); 218 return null; 219 } 196 verboseOutput.PRINCIPAL_NOT_FOUND(user.getURI()); 197 } 198 } else { 199 verboseOutput.ADMIN_RIGHTS_EXPECTED(); 200 } 201 } else { 202 verboseOutput.REMOTE_PRINCIPAL_NOT_FOUND(remoteUser); 203 } 204 205 return new ObjectFactory().createUser(new User()); 220 206 } 221 207 … … 233 219 return "The account was updated to "+dbIntegrityService.getTypeOfUserAccount(dbIntegrityService.getUserInternalIdentifier(UUID.fromString(externalId))); 234 220 } else { 235 httpServletResponse.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "The account was not updated."); 236 return "The account was not updated."; 237 } 238 } else { 239 httpServletResponse.sendError(HttpServletResponse.SC_UNAUTHORIZED, "The logged-in user does not have admin rights to update an account type in the database"); 240 return null; 241 } 242 } else { 243 httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, "The logged-in user is not found in the database"); 244 return null; 245 } 221 verboseOutput.ACCOUNT_IS_NOT_UPDATED(); 222 } 223 } else { 224 verboseOutput.ADMIN_RIGHTS_EXPECTED(); 225 } 226 } else { 227 verboseOutput.REMOTE_PRINCIPAL_NOT_FOUND(remoteUser); 228 } 229 230 return " "; 246 231 } 247 232 … … 259 244 return "There is " + result.toString() + " row deleted"; 260 245 } else { 261 AnnotationResource.loggerServer.debug(HttpServletResponse.SC_NOT_FOUND + ": The user with the given id " + externalIdentifier + " is not found in the database"); 262 httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, "The user with the given id " + externalIdentifier + " is not found in the database"); 263 return null; 264 } 265 } else { 266 httpServletResponse.sendError(HttpServletResponse.SC_UNAUTHORIZED, "The logged-in user does not have admin rights to update a user info in the database"); 267 return null; 268 } 269 } else { 270 httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, "The logged-in user is not found in the database"); 271 return null; 272 } 246 verboseOutput.PRINCIPAL_NOT_FOUND(externalIdentifier); 247 } 248 } else { 249 verboseOutput.ADMIN_RIGHTS_EXPECTED(); 250 } 251 } else { 252 verboseOutput.REMOTE_PRINCIPAL_NOT_FOUND(remoteUser); 253 } 254 255 return " "; 273 256 } 274 257 … … 286 269 return "There is " + result.toString() + " row deleted"; 287 270 } else { 288 httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, "The user with the given id " + externalIdentifier + " is not found in the database"); 289 return null; 290 } 291 } else { 292 httpServletResponse.sendError(HttpServletResponse.SC_UNAUTHORIZED, "The logged-in user does not have admin rights to update a user info in the database"); 293 return null; 294 } 295 } else { 296 httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, "The logged-in user is not found in the database"); 297 return null; 298 } 271 verboseOutput.PRINCIPAL_NOT_FOUND(externalIdentifier); 272 } 273 } else { 274 verboseOutput.ADMIN_RIGHTS_EXPECTED(); 275 } 276 } else { 277 verboseOutput.REMOTE_PRINCIPAL_NOT_FOUND(remoteUser); 278 } 279 return " "; 299 280 } 300 281 -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/rest/VerboseOutput.java
r4529 r4532 31 31 private Logger logger; 32 32 33 final static public String REMOTE_PRINCIPAL_NOT_FOUND = "The logged-in principal is not found in the database"; 33 private class MessageStatus{ 34 String message; 35 int status; 36 37 public MessageStatus(String msg, int status){ 38 message = msg; 39 this.status = status; 40 } 41 } 34 42 35 43 public VerboseOutput(HttpServletResponse httpServletResponse, Logger logger) { … … 38 46 } 39 47 40 static public String FORBIDDEN_NOTEBOOK_READING(String identifier) { 41 return " The logged-in principal cannot read the notebook with the identifier " + identifier; 42 } 43 44 static public String FORBIDDEN_NOTEBOOK_WRITING(String identifier) { 45 return " The logged-in principal cannot write in the notebook with the identifier " + identifier; 46 } 47 48 static public String FORBIDDEN_ANNOTATION_READING(String identifier) { 49 return " The logged-in principal cannot read the annotation with the identifier " + identifier; 50 } 51 52 static public String FORBIDDEN_ANNOTATION_WRITING(String identifier) { 53 return " The logged-in principal cannot write in the annotation with the identifier " + identifier; 54 } 55 56 static public String FORBIDDEN_PERMISSION_CHANGING(String identifier) { 57 return " The logged-in principal cannot change the permission of the resource with with the identifier " + identifier+". Only the owner of the resource is allowed to chnange permissions."; 58 } 59 60 static public String ILLEGAL_UUID(String identifier) { 61 return ("The string '" + identifier + "' is not a valid UUID."); 62 } 63 64 static private String resourceNotFound(String externalIdentifier, String resourceType) { 65 return ("A(n) " + resourceType + " with the indentifier " + externalIdentifier + " is not found in the database."); 66 } 67 68 static public String PRINCIPAL_NOT_FOUND(String externalIdentifier) { 48 49 50 private MessageStatus _FORBIDDEN_NOTEBOOK_READING(String identifier) { 51 return new MessageStatus(" The logged-in principal cannot read the notebook with the identifier " + identifier, HttpServletResponse.SC_FORBIDDEN); 52 } 53 54 private MessageStatus _FORBIDDEN_NOTEBOOK_WRITING(String identifier) { 55 return new MessageStatus(" The logged-in principal cannot write in the notebook with the identifier " + identifier, HttpServletResponse.SC_FORBIDDEN); 56 } 57 58 private MessageStatus _FORBIDDEN_ANNOTATION_READING(String identifier) { 59 return new MessageStatus(" The logged-in principal cannot read the annotation with the identifier " + identifier, HttpServletResponse.SC_FORBIDDEN); 60 } 61 62 private MessageStatus _FORBIDDEN_ANNOTATION_WRITING(String identifier) { 63 return new MessageStatus(" The logged-in principal cannot write in the annotation with the identifier " + identifier, HttpServletResponse.SC_FORBIDDEN); 64 } 65 66 private MessageStatus _FORBIDDEN_PERMISSION_CHANGING(String identifier) { 67 return new MessageStatus(" The logged-in principal cannot change the permission of the resource with with the identifier " + identifier+". Only the owner of the resource is allowed to chnange permissions.",HttpServletResponse.SC_FORBIDDEN); 68 } 69 70 private MessageStatus _ILLEGAL_UUID(String identifier) { 71 return new MessageStatus("The string '" + identifier + "' is not a valid UUID.", HttpServletResponse.SC_BAD_REQUEST); 72 } 73 74 75 private MessageStatus _REMOTE_PRINCIPAL_NOT_FOUND(String remoteID) { 76 return new MessageStatus("The loggedinprincipal with the remote ID " + remoteID + " is not found in the database.", HttpServletResponse.SC_NOT_FOUND); 77 } 78 79 private MessageStatus resourceNotFound(String externalIdentifier, String resourceType) { 80 return new MessageStatus("A(n) " + resourceType + " with the indentifier " + externalIdentifier + " is not found in the database.", HttpServletResponse.SC_NOT_FOUND); 81 } 82 83 private MessageStatus _PRINCIPAL_NOT_FOUND(String externalIdentifier) { 69 84 return resourceNotFound(externalIdentifier, "principal"); 70 85 } 71 86 72 static public StringANNOTATION_NOT_FOUND(String externalIdentifier) {87 private MessageStatus _ANNOTATION_NOT_FOUND(String externalIdentifier) { 73 88 return resourceNotFound(externalIdentifier, "annotation"); 74 89 } 75 90 76 static public StringNOTEBOOK_NOT_FOUND(String externalIdentifier) {91 private MessageStatus _NOTEBOOK_NOT_FOUND(String externalIdentifier) { 77 92 return resourceNotFound(externalIdentifier, "notebook"); 78 93 } 79 94 80 static public StringTARGET_NOT_FOUND(String externalIdentifier) {95 private MessageStatus _TARGET_NOT_FOUND(String externalIdentifier) { 81 96 return resourceNotFound(externalIdentifier, "target"); 82 97 } 83 98 84 static public StringCACHED_REPRESENTATION_NOT_FOUND(String externalIdentifier) {99 private MessageStatus _CACHED_REPRESENTATION_NOT_FOUND(String externalIdentifier) { 85 100 return resourceNotFound(externalIdentifier, "cached representation"); 86 101 } 87 102 88 static public String INVALID_PERMISSION_MODE(String permissionMode) { 89 return permissionMode + " is an invalid permission value, which must be either owner, or reader, or writer."; 90 } 91 92 public void sendFailureMessage(String message, int responseCode) throws IOException { 93 logger.debug(responseCode + ": " + message); 94 httpServletResponse.sendError(responseCode, message); 103 private MessageStatus _INVALID_PERMISSION_MODE(String permissionMode) { 104 return new MessageStatus(permissionMode + " is an invalid permission value, which must be either owner, or reader, or writer.", HttpServletResponse.SC_BAD_REQUEST); 105 } 106 107 private MessageStatus _IDENTIFIER_MISMATCH(String identifier){ 108 return new MessageStatus("Wrong request: the annotation identifier " + identifier + " and the annotation ID from the request body do not match.", HttpServletResponse.SC_BAD_REQUEST); 109 } 110 111 private MessageStatus _ADMIN_RIGHTS_EXPECTED(){ 112 return new MessageStatus("The request can be performed only by the principal with the admin rights. The logged in principal does not have admin rights.", HttpServletResponse.SC_FORBIDDEN); 113 } 114 115 private MessageStatus _DEVELOPER_RIGHTS_EXPECTED(){ 116 return new MessageStatus("The request can be performed only by the principal with the developer's or admin rights. The logged in principal does not have either developer's or admin rights.", HttpServletResponse.SC_FORBIDDEN); 117 } 118 119 private MessageStatus _PRINCIPAL_NOT_FOUND_BY_INFO(String email) { 120 return new MessageStatus("The principal with the info (e-mail) "+email+" is not found in the database.", HttpServletResponse.SC_NOT_FOUND); 121 } 122 123 private MessageStatus _PRINCIPAL_IS_NOT_ADDED_TO_DB() { 124 return new MessageStatus("The principal is not added the database, probably becuase another principal with the same e-mail already exists in the data base.", HttpServletResponse.SC_BAD_REQUEST); 125 } 126 127 private MessageStatus _ACCOUNT_IS_NOT_UPDATED() { 128 return new MessageStatus("The account is not updated", HttpServletResponse.SC_INTERNAL_SERVER_ERROR); 129 } 130 131 private void sendMessage(MessageStatus msg) throws IOException { 132 logger.debug(msg.status + ": " + msg.message); 133 httpServletResponse.sendError(msg.status, msg.message); 134 } 135 136 /////////////////////////////// 137 138 public void FORBIDDEN_NOTEBOOK_READING(String identifier) throws IOException{ 139 this.sendMessage(this._FORBIDDEN_NOTEBOOK_READING(identifier)); 140 } 141 142 public void FORBIDDEN_NOTEBOOK_WRITING(String identifier) throws IOException{ 143 this.sendMessage(this._FORBIDDEN_NOTEBOOK_WRITING(identifier)); 144 } 145 146 public void FORBIDDEN_ANNOTATION_READING(String identifier) throws IOException { 147 this.sendMessage(this._FORBIDDEN_ANNOTATION_READING(identifier)); 148 } 149 150 public void FORBIDDEN_ANNOTATION_WRITING(String identifier) throws IOException{ 151 this.sendMessage(this._FORBIDDEN_ANNOTATION_WRITING(identifier)); 152 } 153 154 public void FORBIDDEN_PERMISSION_CHANGING(String identifier) throws IOException{ 155 this.sendMessage(this._FORBIDDEN_PERMISSION_CHANGING(identifier)); 156 } 157 158 public void ILLEGAL_UUID(String identifier) throws IOException{ 159 this.sendMessage(this._ILLEGAL_UUID(identifier)); 160 } 161 162 163 public void REMOTE_PRINCIPAL_NOT_FOUND(String remoteID) throws IOException{ 164 this.sendMessage(this._REMOTE_PRINCIPAL_NOT_FOUND(remoteID)); 165 } 166 167 168 public void PRINCIPAL_NOT_FOUND(String externalIdentifier) throws IOException { 169 this.sendMessage(this._PRINCIPAL_NOT_FOUND(externalIdentifier)); 170 } 171 172 public void ANNOTATION_NOT_FOUND(String externalIdentifier) throws IOException{ 173 this.sendMessage(this._ANNOTATION_NOT_FOUND(externalIdentifier)); 174 } 175 176 public void NOTEBOOK_NOT_FOUND(String externalIdentifier) throws IOException{ 177 this.sendMessage(this._NOTEBOOK_NOT_FOUND(externalIdentifier)); 178 } 179 180 public void TARGET_NOT_FOUND(String externalIdentifier) throws IOException{ 181 this.sendMessage(this._TARGET_NOT_FOUND(externalIdentifier)); 182 } 183 184 public void CACHED_REPRESENTATION_NOT_FOUND(String externalIdentifier) throws IOException{ 185 this.sendMessage(this._CACHED_REPRESENTATION_NOT_FOUND(externalIdentifier)); 186 } 187 188 public void INVALID_PERMISSION_MODE(String permissionMode) throws IOException{ 189 this.sendMessage(this._INVALID_PERMISSION_MODE(permissionMode)); 190 } 191 192 public void IDENTIFIER_MISMATCH(String externalIdentifier)throws IOException{ 193 this.sendMessage(this._IDENTIFIER_MISMATCH(externalIdentifier)); 194 } 195 196 public void ADMIN_RIGHTS_EXPECTED()throws IOException{ 197 this.sendMessage(this._ADMIN_RIGHTS_EXPECTED()); 198 } 199 200 public void DEVELOPER_RIGHTS_EXPECTED()throws IOException{ 201 this.sendMessage(this._DEVELOPER_RIGHTS_EXPECTED()); 202 } 203 204 public void PRINCIPAL_NOT_FOUND_BY_INFO(String email) throws IOException { 205 this.sendMessage(this._PRINCIPAL_NOT_FOUND_BY_INFO(email)); 206 } 207 208 public void PRINCIPAL_IS_NOT_ADDED_TO_DB() throws IOException { 209 this.sendMessage(this._PRINCIPAL_IS_NOT_ADDED_TO_DB()); 210 } 211 212 public void ACCOUNT_IS_NOT_UPDATED() throws IOException { 213 this.sendMessage(this._ACCOUNT_IS_NOT_UPDATED()); 95 214 } 96 215 }
Note: See TracChangeset
for help on using the changeset viewer.