Changeset 4028
- Timestamp:
- 11/15/13 16:36:16 (11 years ago)
- Location:
- DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/AnnotationDao.java
r4010 r4028 19 19 20 20 import eu.dasish.annotation.schema.Annotation; 21 import eu.dasish.annotation.schema.AnnotationBody; 21 22 import eu.dasish.annotation.schema.AnnotationInfo; 22 23 import eu.dasish.annotation.schema.Permission; … … 162 163 163 164 /////// UPDATERS ////////////////// 164 /** 165 * 166 * @param annotationID 167 * @param newBodyText 165 166 int updateAnnotationBodyText(Number annotationID, String text); 167 168 /** 169 * 170 * @param annotationID 171 * @param annotationBody 168 172 * @return # of updated rows in "annotation" table after updating the annotation's body text with "newBodyText". Should return 1. 169 173 */ 170 public int updateBodyText(Number annotationID, String newBodyText); 171 172 /////// UPDATERS ////////////////// 173 /** 174 * 175 * @param annotationID 176 * @param newMimeType 177 * @return # of updated rows in "annotation" table after updating the annotation's body with "newMimeType". Should return 1. 178 */ 179 public int updateBodyMimeType(Number annotationID, String newMimeType); 174 public int updateAnnotationBody(Number annotationID, AnnotationBody annotationBody); 175 176 180 177 181 178 /** -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/DBIntegrityService.java
r4010 r4028 20 20 21 21 import eu.dasish.annotation.schema.Annotation; 22 import eu.dasish.annotation.schema.AnnotationBody; 22 23 import eu.dasish.annotation.schema.AnnotationInfoList; 23 24 import eu.dasish.annotation.schema.CachedRepresentationInfo; … … 247 248 * @param annotation 248 249 * @return 1 of the annotation if it is updated 249 * @throws SQLException250 250 */ 251 251 int updateUsersAnnotation(Number userID, Annotation annotation); 252 253 254 255 /** 256 * 257 * @param userID 258 * @param annotationBody 259 * @return 1 of the annotation if it is updated 260 */ 261 int updateAnnotationBody(Number internalID, AnnotationBody annotationBody); 262 252 263 253 264 -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/impl/DBIntegrityServiceImlp.java
r4010 r4028 26 26 import eu.dasish.annotation.backend.rest.AnnotationResource; 27 27 import eu.dasish.annotation.schema.Annotation; 28 import eu.dasish.annotation.schema.AnnotationBody; 28 29 import eu.dasish.annotation.schema.AnnotationInfo; 29 30 import eu.dasish.annotation.schema.AnnotationInfoList; … … 41 42 import java.io.InputStream; 42 43 import java.lang.Number; 43 import java.sql.Blob;44 import java.sql.SQLException;45 44 import java.sql.Timestamp; 46 45 import java.util.ArrayList; … … 389 388 return updatedAnnotations; 390 389 } 390 391 392 // TODO: unit test 393 @Override 394 public int updateAnnotationBody(Number internalID, AnnotationBody annotationBody) { 395 return annotationDao.updateAnnotationBody(internalID, annotationBody); 396 } 397 398 399 391 400 /////////////// ADDERS ///////////////////////////////// 392 401 @Override … … 511 520 List<TargetInfo> targets = annotation.getTargets().getTargetInfo(); 512 521 Map<String, String> targetIdPairs = addTargetsForAnnotation(annotationID, targets); 522 AnnotationBody annotationBody = annotation.getBody(); 513 523 String bodyText; 514 String newBody ;515 if (annotation .getBody().getXmlBody() != null) {524 String newBodyText; 525 if (annotationBody.getXmlBody() != null) { 516 526 bodyText = Helpers.elementToString(annotation.getBody().getXmlBody().getAny()); 517 527 } else { … … 524 534 } 525 535 } 526 newBody = Helpers.replace(bodyText, targetIdPairs);527 return annotationDao.update BodyText(annotationID, newBody);536 newBodyText = Helpers.replace(bodyText, targetIdPairs); 537 return annotationDao.updateAnnotationBodyText(annotationID, newBodyText); 528 538 } 529 539 -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/impl/JdbcAnnotationDao.java
r4010 r4028 326 326 //////////// UPDATERS ///////////// 327 327 @Override 328 public int update BodyText(Number annotationID, String newBodyText) {328 public int updateAnnotationBodyText(Number annotationID, String text) { 329 329 StringBuilder sql = new StringBuilder("UPDATE "); 330 sql.append(annotationTableName).append(" SET ").append(body_text).append("= '").append(newBodyText).append("' WHERE ").append(annotation_id).append("= ?"); 331 return getSimpleJdbcTemplate().update(sql.toString(), annotationID); 332 } 333 334 @Override 335 public int updateBodyMimeType(Number annotationID, String newMimeType) { 330 sql.append(annotationTableName).append(" SET "). 331 append(body_text).append("= '").append(text). 332 append("' WHERE ").append(annotation_id).append("= ?"); 333 int affectedRows = getSimpleJdbcTemplate().update(sql.toString(), annotationID); 334 return affectedRows; 335 } 336 337 338 339 @Override 340 public int updateAnnotationBody(Number annotationID, AnnotationBody annotationBody) { 341 String[] body = retrieveBodyComponents(annotationBody); 336 342 StringBuilder sql = new StringBuilder("UPDATE "); 337 sql.append(annotationTableName).append(" SET ").append(body_mimetype).append("= '").append(newMimeType).append("' WHERE ").append(annotation_id).append("= ?"); 338 return getSimpleJdbcTemplate().update(sql.toString(), annotationID); 339 } 343 sql.append(annotationTableName).append(" SET "). 344 append(body_text).append("= '").append(body[0]).append("',"). 345 append(body_mimetype).append("= '").append(body[1]).append("',"). 346 append(is_xml).append("= '").append(annotationBody.getXmlBody() != null). 347 append("' WHERE ").append(annotation_id).append("= ?"); 348 int affectedRows = getSimpleJdbcTemplate().update(sql.toString(), annotationID); 349 return affectedRows; 350 } 351 352 340 353 341 354 // TODO Unit test … … 343 356 public int updateAnnotation(Annotation annotation, Number ownerID){ 344 357 345 String[] body = retrieveBodyComponents(annotation );358 String[] body = retrieveBodyComponents(annotation.getBody()); 346 359 347 360 String externalID = stringURItoExternalID(annotation.getURI()); … … 373 386 public Number addAnnotation(Annotation annotation, Number ownerID){ 374 387 375 String[] body = retrieveBodyComponents(annotation );388 String[] body = retrieveBodyComponents(annotation.getBody()); 376 389 377 390 // generate a new annotation ID … … 457 470 458 471 /////////////// helpers ////////////////// 459 private String[] retrieveBodyComponents(Annotation annotation){460 boolean body_is_xml = annotation .getBody().getXmlBody() != null;472 private String[] retrieveBodyComponents(AnnotationBody annotationBody){ 473 boolean body_is_xml = annotationBody.getXmlBody() != null; 461 474 String[] result = new String[2]; 462 475 if (body_is_xml) { 463 result[0] = Helpers.elementToString(annotation .getBody().getXmlBody().getAny());464 result[1] = annotation .getBody().getXmlBody().getMimeType();476 result[0] = Helpers.elementToString(annotationBody.getXmlBody().getAny()); 477 result[1] = annotationBody.getXmlBody().getMimeType(); 465 478 } else { 466 TextBody textBody = annotation .getBody().getTextBody();479 TextBody textBody = annotationBody.getTextBody(); 467 480 if (textBody != null) { 468 481 result[0] = textBody.getValue(); -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/rest/AnnotationResource.java
r4013 r4028 25 25 import eu.dasish.annotation.schema.Action; 26 26 import eu.dasish.annotation.schema.ActionList; 27 import eu.dasish.annotation.schema.AnnotationBody; 27 28 import eu.dasish.annotation.schema.ObjectFactory; 28 29 import eu.dasish.annotation.schema.Permission; … … 269 270 270 271 } 272 273 @PUT 274 @Consumes(MediaType.APPLICATION_XML) 275 @Produces(MediaType.APPLICATION_XML) 276 @Path("{annotationid: " + BackendConstants.regExpIdentifier + "}/body") 277 @Secured("ROLE_USER") 278 public JAXBElement<ResponseBody> updateAnnotationBody(@PathParam("annotationid") String externalIdentifier, AnnotationBody annotationBody) { 279 String path = uriInfo.getBaseUri().toString(); 280 dbIntegrityService.setServiceURI(path); 281 282 final Number annotationID = dbIntegrityService.getAnnotationInternalIdentifier(UUID.fromString(externalIdentifier)); 283 final Number userID = dbIntegrityService.getUserInternalIDFromRemoteID(httpServletRequest.getRemoteUser()); 284 if (canWrite(userID, annotationID)) { 285 int updatedRows = dbIntegrityService.updateAnnotationBody(annotationID, annotationBody); 286 logger.info("updateAnnotationBody method: OK"); 287 return new ObjectFactory().createResponseBody(makeAnnotationResponseEnvelope(annotationID)); 288 289 } else { 290 logger.error("FORBIDDEN-access attempt."); 291 logger.error("The logged-in user is not authorised to alter this annotation. "); 292 try { 293 httpServletResponse.sendError(HttpServletResponse.SC_UNAUTHORIZED); 294 } catch (IOException ioe) { 295 logger.error("IOException: Cannot send server respond about unaithorized access."); 296 } 297 return null; 298 } 299 300 } 271 301 272 302 @PUT -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/rest/TargetResource.java
r3972 r4028 99 99 //how to overwork the input stream to make it downloadable 100 100 // using mime type as well 101 @DELETE102 @Produces(MediaType.TEXT_XML)103 @Path("{targetid: " + BackendConstants.regExpIdentifier + "}/cached/{cachedid: " + BackendConstants.regExpIdentifier + "}")104 @Secured("ROLE_ADMIN")105 public int deleteCached(@PathParam("targetid") String targetIdentifier, @PathParam("cachedid") String cachedIdentifier) throws SQLException {106 dbIntegrityService.setServiceURI(uriInfo.getBaseUri().toString());107 final Number targetID = dbIntegrityService.getCachedRepresentationInternalIdentifier(UUID.fromString(targetIdentifier));108 final Number cachedID = dbIntegrityService.getCachedRepresentationInternalIdentifier(UUID.fromString(cachedIdentifier));109 int[] result = dbIntegrityService.deleteCachedRepresentationOfTarget(targetID, cachedID);110 return result[1];111 }101 // @DELETE 102 // @Produces(MediaType.TEXT_XML) 103 // @Path("{targetid: " + BackendConstants.regExpIdentifier + "}/cached/{cachedid: " + BackendConstants.regExpIdentifier + "}") 104 // @Secured("ROLE_ADMIN") 105 // public int deleteCached(@PathParam("targetid") String targetIdentifier, @PathParam("cachedid") String cachedIdentifier) throws SQLException { 106 // dbIntegrityService.setServiceURI(uriInfo.getBaseUri().toString()); 107 // final Number targetID = dbIntegrityService.getCachedRepresentationInternalIdentifier(UUID.fromString(targetIdentifier)); 108 // final Number cachedID = dbIntegrityService.getCachedRepresentationInternalIdentifier(UUID.fromString(cachedIdentifier)); 109 // int[] result = dbIntegrityService.deleteCachedRepresentationOfTarget(targetID, cachedID); 110 // return result[1]; 111 // } 112 112 113 113 @POST -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/test/java/eu/dasish/annotation/backend/dao/impl/DBIntegrityServiceTest.java
r3972 r4028 690 690 /////////// 691 691 692 oneOf(annotationDao).update BodyText(6, testAnnotation.getBody().getTextBody().getValue());692 oneOf(annotationDao).updateAnnotationBodyText(6, testAnnotation.getBody().getTextBody().getValue()); 693 693 will(returnValue(1)); // the DB update will be called at perform anyway, even if the body is not changed (can be optimized) 694 694 -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/test/java/eu/dasish/annotation/backend/dao/impl/JdbcAnnotationDaoTest.java
r3972 r4028 376 376 System.out.println("test updateBodyText"); 377 377 String newBodyText = "new body"; 378 int result = jdbcAnnotationDao.update BodyText(2, newBodyText);378 int result = jdbcAnnotationDao.updateAnnotationBodyText(2, newBodyText); 379 379 assertEquals(1, result); 380 380 Map<Annotation,Number> getResult= jdbcAnnotationDao.getAnnotationWithoutTargetsAndPermissions(2); … … 384 384 } 385 385 386 ////////////////////////////////// 387 @Test 388 public void testUpdateMimeType() throws SQLException{ 389 System.out.println("test updateBodyMimeType"); 390 String newBodyMimeType = "text/xml"; 391 int result = jdbcAnnotationDao.updateBodyMimeType(2, newBodyMimeType); 392 assertEquals(1, result); 393 Map<Annotation,Number> getResult= jdbcAnnotationDao.getAnnotationWithoutTargetsAndPermissions(2); 394 Annotation[] annotations = new Annotation[1]; 395 getResult.keySet().toArray(annotations); 396 assertEquals(newBodyMimeType, annotations[0].getBody().getTextBody().getMimeType()); 397 } 386 398 387 399 388 // public List<Map<Number, String>> retrievePermissions(Number annotationId)
Note: See TracChangeset
for help on using the changeset viewer.