Changeset 4260
- Timestamp:
- 01/13/14 17:06:18 (10 years ago)
- Location:
- DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/UserDao.java
r4252 r4260 50 50 51 51 public int deleteUser(Number intenralID); 52 53 public int deleteUserSafe(Number internalID); 52 54 53 55 -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/impl/DBIntegrityServiceImlp.java
r4252 r4260 98 98 } 99 99 100 101 100 @Override 102 101 public Number getTargetInternalIdentifier(UUID externalID) { … … 139 138 } 140 139 141 142 140 @Override 143 141 public Annotation getAnnotation(Number annotationID) { … … 349 347 350 348 @Override 351 public boolean userHasAdminRights(Number userID) {352 return userDao.hasAdminRights(userID);353 } 354 349 public boolean userHasAdminRights(Number userID) { 350 return userDao.hasAdminRights(userID); 351 } 352 355 353 ///// UPDATERS ///////////////// 356 354 @Override … … 366 364 for (UserWithPermission userWithPermission : usersWithPermissions) { 367 365 Number userID = userDao.getInternalID(UUID.fromString(userDao.stringURItoExternalID(userWithPermission.getRef()))); 368 Permission permission = userWithPermission.getPermission(); 369 Permission currentPermission = annotationDao.getPermission(annotationID, userID); 370 if (currentPermission != null) { 371 if (!permission.value().equals(currentPermission.value())) { 372 result = result + annotationDao.updateAnnotationPrincipalPermission(annotationID, userID, permission); 366 if (userID != null) { 367 Permission permission = userWithPermission.getPermission(); 368 Permission currentPermission = annotationDao.getPermission(annotationID, userID); 369 if (currentPermission != null) { 370 if (!permission.value().equals(currentPermission.value())) { 371 result = result + annotationDao.updateAnnotationPrincipalPermission(annotationID, userID, permission); 372 } 373 } else { 374 result = result + annotationDao.addAnnotationPrincipalPermission(annotationID, userID, permission); 373 375 } 374 } else {375 result = result + annotationDao.addAnnotationPrincipalPermission(annotationID, userID, permission);376 376 } 377 377 } … … 392 392 return updatedAnnotations; 393 393 } 394 395 394 396 395 // TODO: unit test 397 396 @Override 398 397 public int updateAnnotationBody(Number internalID, AnnotationBody annotationBody) { 399 398 String[] body = annotationDao.retrieveBodyComponents(annotationBody); 400 return annotationDao.updateAnnotationBody(internalID, body[0], body[1], annotationBody.getXmlBody()!=null); 401 } 402 403 404 399 return annotationDao.updateAnnotationBody(internalID, body[0], body[1], annotationBody.getXmlBody() != null); 400 } 401 405 402 /////////////// ADDERS ///////////////////////////////// 406 403 @Override … … 554 551 return addedPermissions; 555 552 } 556 557 553 554 private TargetInfo getTargetInfoFromTarget(Target target) { 558 555 TargetInfo targetInfo = new TargetInfo(); 559 556 targetInfo.setRef(target.getURI()); -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/impl/JdbcUserDao.java
r4257 r4260 146 146 147 147 ///////////////////// ADDERS //////////////////////////// 148 @Override 148 149 public Number addUser(User user, String remoteID){ 149 150 UUID externalIdentifier = UUID.randomUUID(); … … 161 162 162 163 ////////// UPDATERS /////////////////////// 163 164 @Override 164 165 public Number updateUser(User user){ 165 166 Number principalID = this.getInternalIDFromURI(user.getURI()); … … 175 176 176 177 ////// DELETERS //////////// 178 @Override 177 179 public int deleteUser(Number internalID){ 180 181 StringBuilder sql = new StringBuilder("DELETE FROM "); 182 sql.append(principalTableName).append(" where ").append(principal_id).append(" = ?"); 183 return getSimpleJdbcTemplate().update(sql.toString(), internalID); 184 185 } 186 187 @Override 188 public int deleteUserSafe(Number internalID){ 178 189 if (userIsInUse(internalID)) { 179 190 return 0; … … 184 195 185 196 } 186 187 197 } -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/rest/AnnotationResource.java
r4252 r4260 240 240 } 241 241 } else { 242 httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, "The annotation with the given id is not found in the database ");243 return null; 244 } 245 246 } else { 247 httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, "The logged in user is not found in the database ");242 httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, "The annotation with the given id is not found in the database."); 243 return null; 244 } 245 246 } else { 247 httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, "The logged in user is not found in the database."); 248 248 return null; 249 249 } … … 263 263 return new ObjectFactory().createResponseBody(makeAnnotationResponseEnvelope(annotationID)); 264 264 } else { 265 httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, "The logged in user is not found in the database ");265 httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, "The logged in user is not found in the database."); 266 266 return null; 267 267 } … … 297 297 } 298 298 } else { 299 httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, "The annotation with the given id is not found in the database ");300 return null; 301 } 302 } else { 303 httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, "The logged in user is not found in the database ");299 httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, "The annotation with the given id is not found in the database."); 300 return null; 301 } 302 } else { 303 httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, "The logged in user is not found in the database."); 304 304 return null; 305 305 } … … 322 322 return new ObjectFactory().createResponseBody(makeAnnotationResponseEnvelope(annotationID)); 323 323 } else { 324 httpServletResponse.sendError(HttpServletResponse.SC_UNAUTHORIZED );325 return null; 326 } 327 } else { 328 httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, "The annotation with the given id is not found in the database ");329 return null; 330 } 331 } else { 332 httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, "The logged in user is not found in the database ");324 httpServletResponse.sendError(HttpServletResponse.SC_UNAUTHORIZED, "The logged-in user cannot change the body of this annotation because (s)he is not its 'writer'."); 325 return null; 326 } 327 } else { 328 httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, "The annotation with the given id is not found in the database."); 329 return null; 330 } 331 } else { 332 httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, "The logged in user is not found in the database."); 333 333 return null; 334 334 } … … 341 341 public String updatePermission(@PathParam("annotationid") String annotationExternalId, @PathParam("userid") String userExternalId, Permission permission) throws IOException { 342 342 dbIntegrityService.setServiceURI(uriInfo.getBaseUri().toString()); 343 final Number annotationID = dbIntegrityService.getAnnotationInternalIdentifier(UUID.fromString(annotationExternalId));344 343 final Number remoteUserID = dbIntegrityService.getUserInternalIDFromRemoteID(httpServletRequest.getRemoteUser()); 345 final Number userID = dbIntegrityService.getUserInternalIdentifier(UUID.fromString(userExternalId));346 344 if (remoteUserID != null) { 347 if (annotationID != null) { 348 if (isOwner(remoteUserID, annotationID)) { 349 int result = (dbIntegrityService.getPermission(annotationID, userID) != null) 350 ? dbIntegrityService.updateAnnotationPrincipalPermission(annotationID, userID, permission) 351 : dbIntegrityService.addAnnotationPrincipalPermission(annotationID, userID, permission); 352 logger.info("updatePermission method: OK"); 353 return result + " rows are updated/added"; 354 355 } else { 356 httpServletResponse.sendError(HttpServletResponse.SC_UNAUTHORIZED); 357 return null; 358 } 359 } else { 360 httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, "The annotation with the given id is not found in the database"); 361 return null; 362 } 363 364 } else { 365 httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, "The logged in user is not found in the database"); 345 final Number userID = dbIntegrityService.getUserInternalIdentifier(UUID.fromString(userExternalId)); 346 if (userID != null) { 347 final Number annotationID = dbIntegrityService.getAnnotationInternalIdentifier(UUID.fromString(annotationExternalId)); 348 if (annotationID != null) { 349 if (isOwner(remoteUserID, annotationID)) { 350 int result = (dbIntegrityService.getPermission(annotationID, userID) != null) 351 ? dbIntegrityService.updateAnnotationPrincipalPermission(annotationID, userID, permission) 352 : dbIntegrityService.addAnnotationPrincipalPermission(annotationID, userID, permission); 353 logger.info("updatePermission method: OK"); 354 return result + " rows are updated/added"; 355 356 } else { 357 httpServletResponse.sendError(HttpServletResponse.SC_UNAUTHORIZED, "The logged-in user cannot change the rights on this annotation because (s)he is not its owner."); 358 return null; 359 } 360 } else { 361 httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, "The annotation with the given id is not found in the database."); 362 return null; 363 } 364 } else { 365 httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, "The user with the given id is not found in the database."); 366 return null; 367 } 368 369 } else { 370 httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, "The logged in user is not found in the database."); 366 371 return null; 367 372 } … … 380 385 if (isOwner(remoteUserID, annotationID)) { 381 386 int updatedRows = dbIntegrityService.updatePermissions(annotationID, permissions); 382 logger.info("updatePermissions method: OK");383 387 return new ObjectFactory().createResponseBody(makePermissionResponseEnvelope(annotationID)); 384 388 } else { 385 httpServletResponse.sendError(HttpServletResponse.SC_UNAUTHORIZED );386 return null; 387 } 388 } else { 389 httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, "The annotation with the given id is not found in the database ");390 return null; 391 } 392 } else { 393 httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, "The logged in user is not found in the database ");389 httpServletResponse.sendError(HttpServletResponse.SC_UNAUTHORIZED, "The logged-in user cannot change the rights on this annotation because (s)he is not its owner."); 390 return null; 391 } 392 } else { 393 httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, "The annotation with the given id is not found in the database."); 394 return null; 395 } 396 } else { 397 httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, "The logged in user is not found in the database."); 394 398 return null; 395 399 } 396 400 } 397 401 ///////////////////////////////////////// 402 398 403 private ResponseBody makeAnnotationResponseEnvelope(Number annotationID) { 399 404 ResponseBody result = new ResponseBody();
Note: See TracChangeset
for help on using the changeset viewer.