Changeset 4539 for DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/rest/AnnotationResource.java
- Timestamp:
- 02/20/14 15:52:16 (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/rest/AnnotationResource.java
r4532 r4539 19 19 20 20 import eu.dasish.annotation.backend.BackendConstants; 21 import eu.dasish.annotation.backend.Resource; 21 22 import eu.dasish.annotation.backend.dao.DBIntegrityService; 22 23 import eu.dasish.annotation.schema.Annotation; 23 import eu.dasish.annotation.schema.Annotation ActionName;24 import eu.dasish.annotation.schema.AnnotationBody; 24 25 import eu.dasish.annotation.schema.AnnotationInfoList; 25 import eu.dasish.annotation.schema.Action;26 import eu.dasish.annotation.schema.ActionList;27 import eu.dasish.annotation.schema.AnnotationBody;28 26 import eu.dasish.annotation.schema.ObjectFactory; 29 27 import eu.dasish.annotation.schema.Permission; 30 import eu.dasish.annotation.schema.PermissionActionName;31 28 import eu.dasish.annotation.schema.UserWithPermissionList; 32 29 import eu.dasish.annotation.schema.ReferenceList; 33 30 import eu.dasish.annotation.schema.ResponseBody; 34 import eu.dasish.annotation.schema.UserWithPermission;35 31 import java.io.IOException; 36 import java.net.URI;37 import java.sql.Timestamp;38 import java.util.ArrayList;39 import java.util.List;40 32 import java.util.UUID; 41 33 import javax.servlet.ServletContext; … … 113 105 dbIntegrityService.setServiceURI(uriInfo.getBaseUri().toString()); 114 106 try { 115 final Number annotationID = dbIntegrityService.get AnnotationInternalIdentifier(UUID.fromString(externalIdentifier));107 final Number annotationID = dbIntegrityService.getResourceInternalIdentifier(UUID.fromString(externalIdentifier), Resource.ANNOTATION); 116 108 if (annotationID != null) { 117 109 String remoteUser = httpServletRequest.getRemoteUser(); … … 144 136 dbIntegrityService.setServiceURI(uriInfo.getBaseUri().toString()); 145 137 try { 146 final Number annotationID = dbIntegrityService.get AnnotationInternalIdentifier(UUID.fromString(externalIdentifier));138 final Number annotationID = dbIntegrityService.getResourceInternalIdentifier(UUID.fromString(externalIdentifier), Resource.ANNOTATION); 147 139 if (annotationID != null) { 148 140 String remoteUser = httpServletRequest.getRemoteUser(); … … 157 149 } else { 158 150 verboseOutput.REMOTE_PRINCIPAL_NOT_FOUND(remoteUser); 159 160 151 } 161 152 } else { … … 209 200 dbIntegrityService.setServiceURI(uriInfo.getBaseUri().toString()); 210 201 try { 211 final Number annotationID = dbIntegrityService.get AnnotationInternalIdentifier(UUID.fromString(externalIdentifier));202 final Number annotationID = dbIntegrityService.getResourceInternalIdentifier(UUID.fromString(externalIdentifier), Resource.ANNOTATION); 212 203 String remoteUser = httpServletRequest.getRemoteUser(); 213 204 Number userID = dbIntegrityService.getUserInternalIDFromRemoteID(remoteUser); … … 215 206 if (annotationID != null) { 216 207 if (dbIntegrityService.canRead(userID, annotationID)) { 217 final UserWithPermissionList permissionList = dbIntegrityService.getPermissions ForAnnotation(annotationID);208 final UserWithPermissionList permissionList = dbIntegrityService.getPermissions(annotationID, Resource.ANNOTATION); 218 209 return new ObjectFactory().createPermissionList(permissionList); 219 210 } else { … … 240 231 dbIntegrityService.setServiceURI(uriInfo.getBaseUri().toString()); 241 232 try { 242 final Number annotationID = dbIntegrityService.get AnnotationInternalIdentifier(UUID.fromString(externalIdentifier));233 final Number annotationID = dbIntegrityService.getResourceInternalIdentifier(UUID.fromString(externalIdentifier), Resource.ANNOTATION); 243 234 String remoteUser = httpServletRequest.getRemoteUser(); 244 235 Number userID = dbIntegrityService.getUserInternalIDFromRemoteID(remoteUser); … … 280 271 if (userID != null) { 281 272 Number annotationID = dbIntegrityService.addUsersAnnotation(userID, annotation); 282 return new ObjectFactory().createResponseBody( makeAnnotationResponseEnvelope(annotationID));273 return new ObjectFactory().createResponseBody(dbIntegrityService.makeAnnotationResponseEnvelope(annotationID)); 283 274 } else { 284 275 verboseOutput.REMOTE_PRINCIPAL_NOT_FOUND(remoteUser); … … 306 297 307 298 try { 308 final Number annotationID = dbIntegrityService.get AnnotationInternalIdentifier(UUID.fromString(externalIdentifier));299 final Number annotationID = dbIntegrityService.getResourceInternalIdentifier(UUID.fromString(externalIdentifier), Resource.ANNOTATION); 309 300 if (annotationID != null) { 310 301 String remoteUser = httpServletRequest.getRemoteUser(); … … 313 304 if (userID.equals(dbIntegrityService.getAnnotationOwner(annotationID)) || dbIntegrityService.getTypeOfUserAccount(userID).equals(admin)) { 314 305 int updatedRows = dbIntegrityService.updateAnnotation(annotation); 315 return new ObjectFactory().createResponseBody( makeAnnotationResponseEnvelope(annotationID));306 return new ObjectFactory().createResponseBody(dbIntegrityService.makeAnnotationResponseEnvelope(annotationID)); 316 307 } else { 317 308 verboseOutput.FORBIDDEN_PERMISSION_CHANGING(externalIdentifier); … … 338 329 dbIntegrityService.setServiceURI(path); 339 330 try { 340 final Number annotationID = dbIntegrityService.get AnnotationInternalIdentifier(UUID.fromString(externalIdentifier));331 final Number annotationID = dbIntegrityService.getResourceInternalIdentifier(UUID.fromString(externalIdentifier), Resource.ANNOTATION); 341 332 String remoteUser = httpServletRequest.getRemoteUser(); 342 333 Number userID = dbIntegrityService.getUserInternalIDFromRemoteID(remoteUser); … … 345 336 if (dbIntegrityService.canWrite(userID, annotationID)) { 346 337 int updatedRows = dbIntegrityService.updateAnnotationBody(annotationID, annotationBody); 347 return new ObjectFactory().createResponseBody( makeAnnotationResponseEnvelope(annotationID));338 return new ObjectFactory().createResponseBody(dbIntegrityService.makeAnnotationResponseEnvelope(annotationID)); 348 339 } else { 349 340 verboseOutput.FORBIDDEN_ANNOTATION_WRITING(externalIdentifier); … … 373 364 if (remoteUserID != null) { 374 365 try { 375 final Number userID = dbIntegrityService.get UserInternalIdentifier(UUID.fromString(userExternalId));366 final Number userID = dbIntegrityService.getResourceInternalIdentifier(UUID.fromString(userExternalId), Resource.PRINCIPAL); 376 367 if (userID != null) { 377 368 try { 378 final Number annotationID = dbIntegrityService.get AnnotationInternalIdentifier(UUID.fromString(annotationExternalId));369 final Number annotationID = dbIntegrityService.getResourceInternalIdentifier(UUID.fromString(annotationExternalId), Resource.ANNOTATION); 379 370 if (annotationID != null) { 380 371 if (remoteUserID.equals(dbIntegrityService.getAnnotationOwner(annotationID)) || dbIntegrityService.getTypeOfUserAccount(remoteUserID).equals(admin)) { … … 414 405 dbIntegrityService.setServiceURI(uriInfo.getBaseUri().toString()); 415 406 try { 416 final Number annotationID = dbIntegrityService.get AnnotationInternalIdentifier(UUID.fromString(annotationExternalId));407 final Number annotationID = dbIntegrityService.getResourceInternalIdentifier(UUID.fromString(annotationExternalId), Resource.ANNOTATION); 417 408 String remoteUser = httpServletRequest.getRemoteUser(); 418 409 Number remoteUserID = dbIntegrityService.getUserInternalIDFromRemoteID(remoteUser); … … 421 412 if (remoteUserID.equals(dbIntegrityService.getAnnotationOwner(annotationID)) || dbIntegrityService.getTypeOfUserAccount(remoteUserID).equals(admin)) { 422 413 int updatedRows = dbIntegrityService.updatePermissions(annotationID, permissions); 423 return new ObjectFactory().createResponseBody( makePermissionResponseEnvelope(annotationID));414 return new ObjectFactory().createResponseBody(dbIntegrityService.makePermissionResponseEnvelope(annotationID, Resource.ANNOTATION)); 424 415 } else { 425 416 verboseOutput.FORBIDDEN_PERMISSION_CHANGING(annotationExternalId); … … 448 439 int deletedRows = 0; 449 440 try { 450 final Number annotationID = dbIntegrityService.get AnnotationInternalIdentifier(UUID.fromString(annotationId));441 final Number annotationID = dbIntegrityService.getResourceInternalIdentifier(UUID.fromString(annotationId), Resource.ANNOTATION); 451 442 String remoteUser = httpServletRequest.getRemoteUser(); 452 443 Number remoteUserID = dbIntegrityService.getUserInternalIDFromRemoteID(remoteUser); … … 454 445 if (annotationID != null) { 455 446 if (remoteUserID.equals(dbIntegrityService.getAnnotationOwner(annotationID)) || dbIntegrityService.getTypeOfUserAccount(remoteUserID).equals(admin)) { 456 Number userID = dbIntegrityService.get UserInternalIdentifier(UUID.fromString(userId));447 Number userID = dbIntegrityService.getResourceInternalIdentifier(UUID.fromString(userId), Resource.PRINCIPAL); 457 448 if (userID != null) { 458 449 deletedRows = dbIntegrityService.updateAnnotationPrincipalPermission(annotationID, userID, null); … … 477 468 return (deletedRows + " is deleted."); 478 469 } 479 ///////////////////////////////////////// 480 481 private ResponseBody makeAnnotationResponseEnvelope(Number annotationID) { 482 ResponseBody result = new ResponseBody(); 483 result.setPermissions(null); 484 Annotation annotation = dbIntegrityService.getAnnotation(annotationID); 485 result.setAnnotation(annotation); 486 List<String> targetsNoCached = dbIntegrityService.getTargetsWithNoCachedRepresentation(annotationID); 487 ActionList actionList = new ActionList(); 488 result.setActionList(actionList); 489 actionList.getAction().addAll(makeActionList(targetsNoCached, AnnotationActionName.CREATE_CACHED_REPRESENTATION.value())); 490 return result; 491 } 492 493 ///////////////////////////////////////// 494 private ResponseBody makePermissionResponseEnvelope(Number annotationID) { 495 ResponseBody result = new ResponseBody(); 496 result.setAnnotation(null); 497 UserWithPermissionList permissions = dbIntegrityService.getPermissionsForAnnotation(annotationID); 498 result.setPermissions(permissions); 499 List<String> usersWithNoInfo = dbIntegrityService.getUsersWithNoInfo(annotationID); 500 ActionList actionList = new ActionList(); 501 result.setActionList(actionList); 502 actionList.getAction().addAll(makeActionList(usersWithNoInfo, PermissionActionName.PROVIDE_USER_INFO.value())); 503 return result; 504 } 505 506 // REFACTOR : move to the integrity service all te methods below 507 private List<Action> makeActionList(List<String> resourceURIs, String message) { 508 if (resourceURIs != null) { 509 if (resourceURIs.isEmpty()) { 510 return (new ArrayList<Action>()); 511 } else { 512 List<Action> result = new ArrayList<Action>(); 513 for (String resourceURI : resourceURIs) { 514 Action action = new Action(); 515 result.add(action); 516 action.setMessage(message); 517 action.setObject(resourceURI); 518 } 519 return result; 520 } 521 } else { 522 return null; 523 } 524 } 470 525 471 }
Note: See TracChangeset
for help on using the changeset viewer.