Changeset 4262
- Timestamp:
- 01/14/14 17:52:21 (10 years ago)
- Location:
- DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src
- Files:
-
- 13 edited
Legend:
- Unmodified
- Added
- Removed
-
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/AnnotationDao.java
r4207 r4262 49 49 * 50 50 */ 51 public Map<Annotation, Number>getAnnotationWithoutTargetsAndPermissions(Number annotationID);51 public Annotation getAnnotationWithoutTargetsAndPermissions(Number annotationID); 52 52 53 53 … … 66 66 * 67 67 */ 68 public List<Number> getFilteredAnnotationIDs(List<Number> annotationIDs, String text, String namespace, Number ownerID,Timestamp after, Timestamp before);68 public List<Number> getFilteredAnnotationIDs(List<Number> annotationIDs, String text, String namespace, Timestamp after, Timestamp before); 69 69 70 70 /** 71 71 * unit test is missing 72 72 * @param annotationIDs 73 * @return pair <annotationInfo, owner_id>for the annotation with the internal annotationID.74 * 75 */ 76 public Map<AnnotationInfo, Number>getAnnotationInfoWithoutTargets(Number annotationID);73 * @return annotationInfo for the annotation with the internal annotationID. 74 * 75 */ 76 public AnnotationInfo getAnnotationInfoWithoutTargets(Number annotationID); 77 77 78 78 /** … … 105 105 */ 106 106 public List<Map<Number, String>> getPermissions(Number annotationID); 107 108 public Number getOwner(Number annotationID); 107 109 108 110 /** … … 159 161 **/ 160 162 161 public Number addAnnotation(Annotation annotation , Number ownerID);163 public Number addAnnotation(Annotation annotation); 162 164 163 165 … … 172 174 * 173 175 * @param annotation 174 * @param ownerID175 176 * @return # of updated rows in "annotation" table after updating the annotation. Should return 1 if update happens 176 177 * @throws SQLException 177 178 */ 178 public int updateAnnotation(Annotation annotation , Number ownerID);179 public int updateAnnotation(Annotation annotation); 179 180 180 181 -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/DBIntegrityService.java
r4252 r4262 77 77 * @param access 78 78 * @param namespace 79 * @param owner80 79 * @param after 81 80 * @param before … … 88 87 * -- created after time-samp "after and before time-stamp "before". 89 88 */ 90 List<Number> getFilteredAnnotationIDs(String link, String text, Number inloggedUserID, String[] accessModes, String namespace, UUID 91 owner, Timestamp after, Timestamp before); 89 List<Number> getFilteredAnnotationIDs(String link, String text, Number inloggedUserID, String[] accessModes, String namespace, Timestamp after, Timestamp before); 92 90 93 91 … … 145 143 String getTargetURI(Number targetID); 146 144 147 145 UUID getTargetExternalIdentifier(Number targetID); 148 146 149 147 String getUserURI(Number userID); … … 340 338 public int deleteUser(Number userID); 341 339 340 /** 341 * 342 * @param userID 343 * @return # of affected rows in the table "principal". 344 * It is 1 if the userId is found and deleted; 345 * it is 0 if it is not found or not deleted, e.g. because it is in use in the table "annotationsPreincipalsPermissions" 346 */ 347 public int deleteUserSafe(Number userID); 348 342 349 /** 343 350 * -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/impl/DBIntegrityServiceImlp.java
r4260 r4262 141 141 public Annotation getAnnotation(Number annotationID) { 142 142 if (annotationID != null) { 143 Map<Annotation, Number> annotationOwner = annotationDao.getAnnotationWithoutTargetsAndPermissions(annotationID); 144 145 Annotation[] annotations = new Annotation[1]; 146 annotationOwner.keySet().toArray(annotations); 147 Annotation result = annotations[0]; 148 result.setOwnerRef(userDao.getURIFromInternalID(annotationOwner.get(result))); 149 143 Annotation result = annotationDao.getAnnotationWithoutTargetsAndPermissions(annotationID); 144 result.setOwnerRef(userDao.getURIFromInternalID(annotationDao.getOwner(annotationID))); 150 145 List<Number> targetIDs = annotationDao.retrieveTargetIDs(annotationID); 151 146 TargetInfoList sis = new TargetInfoList(); … … 191 186 //////////////////////////////////////////////////////////////////////// 192 187 @Override 193 public List<Number> getFilteredAnnotationIDs(String link, String text, Number inloggedUserID, String[] accessModes, String namespace, UUID owner,Timestamp after, Timestamp before) {188 public List<Number> getFilteredAnnotationIDs(String link, String text, Number inloggedUserID, String[] accessModes, String namespace, Timestamp after, Timestamp before) { 194 189 195 190 if (accessModes == null) { … … 205 200 } 206 201 207 return annotationDao.getFilteredAnnotationIDs(annotationIDs, text, namespace, userDao.getInternalID(owner),after, before);202 return annotationDao.getFilteredAnnotationIDs(annotationIDs, text, namespace, after, before); 208 203 } 209 204 … … 261 256 @Override 262 257 public AnnotationInfoList getFilteredAnnotationInfos(String word, String text, Number inloggedUserID, String[] accessModes, String namespace, UUID owner, Timestamp after, Timestamp before) { 263 List<Number> annotationIDs = getFilteredAnnotationIDs(word, text, inloggedUserID, accessModes, namespace, owner, after, before); 258 List<Number> annotationIDs = getFilteredAnnotationIDs(word, text, inloggedUserID, accessModes, namespace, after, before); 259 Number givenOwnerID = userDao.getInternalID(owner); 264 260 if (annotationIDs != null) { 265 261 AnnotationInfoList result = new AnnotationInfoList(); 266 262 for (Number annotationID : annotationIDs) { 267 Map<AnnotationInfo, Number> annotationInfoOwnerId = annotationDao.getAnnotationInfoWithoutTargets(annotationID);268 ReferenceList targets = getAnnotationTargets(annotationID);269 AnnotationInfo[] annotationInfos = new AnnotationInfo[1];270 annotationInfoOwnerId.keySet().toArray(annotationInfos);271 AnnotationInfo annotationInfo = annotationInfos[0];272 annotationInfo.setTargets(targets);273 annotationInfo.setOwnerRef(userDao.getURIFromInternalID(annotationInfoOwnerId.get(annotationInfo)));274 result.getAnnotationInfo().add(annotationInfo);263 Number ownerID = annotationDao.getOwner(annotationID); 264 if ((owner == null) || ownerID.equals(givenOwnerID)) { 265 ReferenceList targets = getAnnotationTargets(annotationID); 266 AnnotationInfo annotationInfo = annotationDao.getAnnotationInfoWithoutTargets(annotationID); 267 annotationInfo.setTargets(targets); 268 annotationInfo.setOwnerRef(userDao.getURIFromInternalID(ownerID)); 269 result.getAnnotationInfo().add(annotationInfo); 270 } 275 271 } 276 272 … … 384 380 @Override 385 381 public int updateUsersAnnotation(Number userID, Annotation annotation) { 386 int updatedAnnotations = annotationDao.updateAnnotation(annotation , userID);382 int updatedAnnotations = annotationDao.updateAnnotation(annotation); 387 383 Number annotationID = annotationDao.getInternalIDFromURI(annotation.getURI()); 388 384 int deletedTargets = annotationDao.deleteAllAnnotationTarget(annotationID); 389 385 int deletedPrinsipalsPermissions = annotationDao.deleteAnnotationPrincipalPermissions(annotationID); 390 386 int addedTargets = addTargets(annotation, annotationID); 391 int addedPrincipalsPermissions = addPrincipalsPermissions(annotation, annotationID); 387 int addedPrincipalsPermissions = addPrincipalsPermissions(annotation.getPermissions().getUserWithPermission(), annotationID); 388 int addedOwner = annotationDao.addAnnotationPrincipalPermission(annotationID, userID, Permission.OWNER); 392 389 return updatedAnnotations; 393 390 } … … 435 432 @Override 436 433 public Number addUsersAnnotation(Number userID, Annotation annotation) { 437 Number annotationID = annotationDao.addAnnotation(annotation , userID);434 Number annotationID = annotationDao.addAnnotation(annotation); 438 435 int affectedAnnotRows = addTargets(annotation, annotationID); 439 436 int affectedPermissions = annotationDao.addAnnotationPrincipalPermission(annotationID, userID, Permission.OWNER); … … 464 461 public int deleteUser(Number userID) { 465 462 return userDao.deleteUser(userID); 463 } 464 465 ////////////// DELETERS ////////////////// 466 @Override 467 public int deleteUserSafe(Number userID) { 468 return userDao.deleteUserSafe(userID); 466 469 } 467 470 … … 542 545 } 543 546 544 private int addPrincipalsPermissions(Annotation annotation, Number annotationID) { 545 List<UserWithPermission> permissions = annotation.getPermissions().getUserWithPermission(); 547 private int addPrincipalsPermissions(List<UserWithPermission> permissions, Number annotationID) { 546 548 int addedPermissions = 0; 547 549 for (UserWithPermission permission : permissions) { -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/impl/JdbcAnnotationDao.java
r4207 r4262 26 26 import eu.dasish.annotation.schema.AnnotationInfo; 27 27 import eu.dasish.annotation.schema.Permission; 28 import java.io.IOException;29 28 import java.lang.String; 30 29 import java.sql.ResultSet; … … 37 36 import java.util.UUID; 38 37 import javax.sql.DataSource; 39 import javax.xml.datatype.DatatypeConfigurationException;40 import javax.xml.parsers.ParserConfigurationException;41 38 import org.springframework.jdbc.core.RowMapper; 42 import org.xml.sax.SAXException;43 39 44 40 /** … … 143 139 String result = "("; 144 140 for (int i = 0; i < length - 1; i++) { 145 result = result + "'" +strings[i] + "', ";146 } 147 result = result + "'" +strings[length - 1] + "')";141 result = result + "'" + strings[i] + "', "; 142 } 143 result = result + "'" + strings[length - 1] + "')"; 148 144 return result; 149 145 } … … 151 147 //////////////////////////////////////////////////////////////////////// 152 148 @Override 153 public List<Number> getFilteredAnnotationIDs(List<Number> annotationIDs, String text, String namespace, Number ownerID,Timestamp after, Timestamp before) {149 public List<Number> getFilteredAnnotationIDs(List<Number> annotationIDs, String text, String namespace, Timestamp after, Timestamp before) { 154 150 155 151 StringBuilder sql = new StringBuilder("SELECT DISTINCT "); … … 168 164 sql.append(" AND ").append(annotation_id).append(" IN ").append(values); 169 165 170 171 if (ownerID != null) { 172 sql.append(" AND ").append(owner_id).append(" = :owner "); 173 params.put("owner", ownerID); 174 } 175 166 176 167 if (after != null) { 177 168 sql.append(" AND ").append(last_modified).append(" > :after"); … … 208 199 209 200 @Override 210 public Map<AnnotationInfo, Number>getAnnotationInfoWithoutTargets(Number annotationID) {201 public AnnotationInfo getAnnotationInfoWithoutTargets(Number annotationID) { 211 202 if (annotationID == null) { 212 203 return null; … … 214 205 StringBuilder sql = new StringBuilder("SELECT "); 215 206 sql.append(annotationStar).append(" FROM ").append(annotationTableName).append(" WHERE ").append(annotation_id).append(" = ? "); 216 List< Map<AnnotationInfo, Number>> result = getSimpleJdbcTemplate().query(sql.toString(), annotationInfoRowMapper, annotationID);207 List<AnnotationInfo> result = getSimpleJdbcTemplate().query(sql.toString(), annotationInfoRowMapper, annotationID); 217 208 if (result == null) { 218 209 return null; … … 224 215 return result.get(0); 225 216 } 226 private final RowMapper< Map<AnnotationInfo, Number>> annotationInfoRowMapper = new RowMapper<Map<AnnotationInfo, Number>>() {217 private final RowMapper<AnnotationInfo> annotationInfoRowMapper = new RowMapper<AnnotationInfo>() { 227 218 @Override 228 public Map<AnnotationInfo, Number> mapRow(ResultSet rs, int rowNumber) throws SQLException { 229 Map<AnnotationInfo, Number> result = new HashMap<AnnotationInfo, Number>(); 219 public AnnotationInfo mapRow(ResultSet rs, int rowNumber) throws SQLException { 230 220 AnnotationInfo annotationInfo = new AnnotationInfo(); 231 221 annotationInfo.setRef(externalIDtoURI(rs.getString(external_id))); 232 222 annotationInfo.setHeadline(rs.getString(headline)); 233 223 annotationInfo.setLastModified(timeStampToXMLGregorianCalendar(rs)); 234 result.put(annotationInfo, rs.getInt(owner_id)); 235 return result; 224 return annotationInfo; 236 225 } 237 226 }; … … 269 258 ////////////////////////////////////////////////////////////////////////// 270 259 @Override 271 public Map<Annotation, Number>getAnnotationWithoutTargetsAndPermissions(Number annotationID) {260 public Annotation getAnnotationWithoutTargetsAndPermissions(Number annotationID) { 272 261 if (annotationID == null) { 273 262 return null; … … 275 264 StringBuilder sql = new StringBuilder("SELECT "); 276 265 sql.append(annotationStar).append(" FROM ").append(annotationTableName).append(" WHERE ").append(annotationAnnotation_id).append("= ? LIMIT 1"); 277 List< Map<Annotation, Number>> respond = getSimpleJdbcTemplate().query(sql.toString(), annotationRowMapper, annotationID);266 List<Annotation> respond = getSimpleJdbcTemplate().query(sql.toString(), annotationRowMapper, annotationID); 278 267 return (respond.isEmpty() ? null : respond.get(0)); 279 268 } 280 private final RowMapper< Map<Annotation, Number>> annotationRowMapper = new RowMapper<Map<Annotation, Number>>() {269 private final RowMapper<Annotation> annotationRowMapper = new RowMapper<Annotation>() { 281 270 @Override 282 public Map<Annotation, Number> mapRow(ResultSet rs, int rowNumber) throws SQLException { 283 Map<Annotation, Number> result = new HashMap<Annotation, Number>(); 284 271 public Annotation mapRow(ResultSet rs, int rowNumber) throws SQLException { 285 272 Annotation annotation = new Annotation(); 286 result.put(annotation, rs.getInt(owner_id));287 288 273 annotation.setHeadline(rs.getString(headline)); 289 290 274 AnnotationBody body = new AnnotationBody(); 291 275 if (rs.getBoolean(is_xml)) { … … 307 291 annotation.setURI(externalIDtoURI(rs.getString(external_id))); 308 292 annotation.setLastModified(timeStampToXMLGregorianCalendar(rs)); 309 return result;293 return annotation; 310 294 } 311 295 }; 312 296 297 @Override 298 public Number getOwner(Number annotationID){ 299 if (annotationID == null) { 300 return null; 301 } 302 StringBuilder sql = new StringBuilder("SELECT "); 303 sql.append(principal_id).append(" FROM ").append(permissionsTableName).append(" WHERE "). 304 append(permission).append("= 'owner' AND "). 305 append(annotation_id).append("= ? LIMIT 1"); 306 List<Number> respond = getSimpleJdbcTemplate().query(sql.toString(), principalIDRowMapper, annotationID); 307 return (respond.isEmpty() ? null : respond.get(0)); 308 } 309 313 310 ///////////////////////////// 314 311 @Override … … 335 332 336 333 //////////// UPDATERS ///////////// 337 338 339 334 @Override 340 335 public int updateAnnotationBody(Number annotationID, String text, String mimeType, Boolean isXml) { … … 358 353 // TODO Unit test 359 354 @Override 360 public int updateAnnotation(Annotation annotation , Number ownerID) {355 public int updateAnnotation(Annotation annotation) { 361 356 362 357 String[] body = retrieveBodyComponents(annotation.getBody()); … … 386 381 387 382 Map<String, Object> params = new HashMap<String, Object>(); 388 params.put("permission", permission.value()); 383 389 384 params.put("annotationID", annotationID); 390 385 params.put("principalID", userID); 391 386 392 StringBuilder sql = new StringBuilder("UPDATE "); 393 sql.append(permissionsTableName).append(" SET "). 394 append(this.permission).append("= :permission"). 395 append(" WHERE ").append(annotation_id).append("= :annotationID"). 396 append(" AND ").append(principal_id).append("= :principalID"); 397 return getSimpleJdbcTemplate().update(sql.toString(), params); 387 if (permission != null) { 388 params.put("permission", permission.value()); 389 StringBuilder sql = new StringBuilder("UPDATE "); 390 sql.append(permissionsTableName).append(" SET "). 391 append(this.permission).append("= :permission"). 392 append(" WHERE ").append(annotation_id).append("= :annotationID"). 393 append(" AND ").append(principal_id).append("= :principalID"); 394 return getSimpleJdbcTemplate().update(sql.toString(), params); 395 } else { 396 StringBuilder sql = new StringBuilder("DELETE FROM "); 397 sql.append(permissionsTableName).append(" WHERE ").append(annotation_id).append("= :annotationID"). 398 append(" AND ").append(principal_id).append("= :principalID"); 399 return (getSimpleJdbcTemplate().update(sql.toString(), params)); 400 } 401 398 402 } 399 403 400 404 //////////// ADDERS //////////////////////// 401 405 @Override 402 public Number addAnnotation(Annotation annotation , Number ownerID) {406 public Number addAnnotation(Annotation annotation) { 403 407 404 408 String[] body = retrieveBodyComponents(annotation.getBody()); … … 408 412 Map<String, Object> params = new HashMap<String, Object>(); 409 413 params.put("externalId", externalID.toString()); 410 params.put("ownerId", ownerID);411 414 params.put("headline", annotation.getHeadline()); 412 415 params.put("bodyText", body[0]); … … 415 418 416 419 StringBuilder sql = new StringBuilder("INSERT INTO "); 417 sql.append(annotationTableName).append("(").append(external_id) .append(",").append(owner_id);420 sql.append(annotationTableName).append("(").append(external_id); 418 421 sql.append(",").append(headline).append(",").append(body_text).append(",").append(body_mimetype).append(",").append(is_xml). 419 append(" ) VALUES (:externalId, : ownerId, :headline, :bodyText, :bodyMimeType, :isXml)");422 append(" ) VALUES (:externalId, :headline, :bodyText, :bodyMimeType, :isXml)"); 420 423 int affectedRows = getSimpleJdbcTemplate().update(sql.toString(), params); 421 424 return ((affectedRows > 0) ? getInternalID(externalID) : null); … … 487 490 488 491 /////////////// helpers ////////////////// 492 @Override 489 493 public String[] retrieveBodyComponents(AnnotationBody annotationBody) { 490 494 boolean body_is_xml = annotationBody.getXmlBody() != null; -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/impl/JdbcNotebookDao.java
r4146 r4262 78 78 @Override 79 79 public List<Notebook> getUsersNotebooks(UUID userID) { 80 String sql = "SELECT " + notebookStar + " FROM " + notebookTableName + ", " + principalTableName + " where " + principal_id + " = " + owner_id + " and " + principalExternal_id + " = ?";80 String sql = "SELECT " + notebookStar + " FROM " + notebookTableName + ", " + principalTableName + " where " + principal_id + " = " + notebookOwner_id + " and " + principalExternal_id + " = ?"; 81 81 return getSimpleJdbcTemplate().query(sql, notebookRowMapper, userID.toString()); 82 82 } … … 106 106 try { 107 107 final UUID externalIdentifier = UUID.randomUUID(); 108 String sql = "INSERT INTO " + notebookTableName + " (" + external_id + ", " + this.title + "," + owner_id + ") VALUES (:notebookId, :title, (SELECT " + principal_id + " FROM " + principalTableName + " WHERE " + principalExternal_id + " = :userID))";108 String sql = "INSERT INTO " + notebookTableName + " (" + external_id + ", " + this.title + "," + notebookOwner_id + ") VALUES (:notebookId, :title, (SELECT " + principal_id + " FROM " + principalTableName + " WHERE " + principalExternal_id + " = :userID))"; 109 109 Map<String, Object> params = new HashMap<String, Object>(); 110 110 params.put("notebookId", externalIdentifier.toString()); -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/impl/JdbcResourceDao.java
r4252 r4262 55 55 final static protected String target_id = "target_id"; 56 56 final static protected String external_id = "external_id"; 57 final static protected String owner_id = "owner_id";58 57 final static protected String headline = "headline"; 59 58 final static protected String body_text = "body_text"; … … 61 60 final static protected String title = "title"; 62 61 final static protected String principal_id = "principal_id"; 62 final static protected String notebookOwner_id = "owner_id"; 63 63 final static protected String last_modified = "last_modified"; 64 64 final static protected String version = "version"; … … 85 85 final static protected String notebookTitle = notebookTableName + "." + title; 86 86 final static protected String notebookExternal_id = notebookTableName + "." + external_id; 87 final static protected String notebookOwner_id = notebookTableName + "." + owner_id;88 87 final static protected String notebooksAnnotationsTableNameAnnotation_id = notebooksAnnotationsTableName + "." + annotation_id; 89 88 final static protected String principalPrincipal_id = principalTableName + "." + principal_id; … … 200 199 } 201 200 }; 202 protected final RowMapper<Number> ownerIDRowMapper = new RowMapper<Number>() { 203 @Override 204 public Number mapRow(ResultSet rs, int rowNumber) throws SQLException { 205 return rs.getInt(owner_id); 201 202 protected final RowMapper<Number> notebookOwnerIDRowMapper = new RowMapper<Number>() { 203 @Override 204 public Number mapRow(ResultSet rs, int rowNumber) throws SQLException { 205 return rs.getInt(notebookOwner_id); 206 206 } 207 207 }; -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/impl/JdbcUserDao.java
r4260 r4262 86 86 87 87 StringBuilder sqlNotebooks = new StringBuilder("SELECT "); 88 sqlNotebooks.append( owner_id).append(" FROM ").append(notebookTableName).append(" WHERE ").append(owner_id).append("= ? LIMIT 1");89 List<Number> resultNotebooks = getSimpleJdbcTemplate().query(sqlNotebooks.toString(), ownerIDRowMapper, userID);88 sqlNotebooks.append(notebookOwner_id).append(" FROM ").append(notebookTableName).append(" WHERE ").append(notebookOwner_id).append("= ? LIMIT 1"); 89 List<Number> resultNotebooks = getSimpleJdbcTemplate().query(sqlNotebooks.toString(), notebookOwnerIDRowMapper, userID); 90 90 if (resultNotebooks.size() > 0) { 91 91 return true; -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/rest/AnnotationResource.java
r4260 r4262 32 32 import eu.dasish.annotation.schema.ReferenceList; 33 33 import eu.dasish.annotation.schema.ResponseBody; 34 import eu.dasish.annotation.schema.UserWithPermission; 34 35 import java.io.IOException; 35 36 import java.net.URI; … … 100 101 public AnnotationResource() { 101 102 } 103 104 102 105 103 106 @GET … … 164 167 // TODO Unit test 165 168 169 170 171 166 172 @GET 167 173 @Produces(MediaType.TEXT_XML) … … 249 255 } 250 256 } 257 258 // TODO: how to return the status code? 259 260 251 261 /////////////////////////////////////////////////////// 252 262 … … 278 288 dbIntegrityService.setServiceURI(path); 279 289 String annotationURI = annotation.getURI(); 290 280 291 if (!(path + "annotations/" + externalIdentifier).equals(annotationURI)) { 281 logger.error("Wrong request: the external annotation ID and the annotation ID from the request body do not match."); 282 logger.error("Will do nothing."); 283 return null; 284 } 292 httpServletResponse.sendError(HttpServletResponse.SC_CONFLICT, "Wrong request: the external annotation ID and the annotation ID from the request body do not match. Correct the request and resend."); 293 return null; 294 } 295 296 List<UserWithPermission> permissions = annotation.getPermissions().getUserWithPermission(); 297 298 285 299 final Number annotationID = dbIntegrityService.getAnnotationInternalIdentifier(UUID.fromString(externalIdentifier)); 286 300 if (annotationID != null) { 287 301 final Number userID = dbIntegrityService.getUserInternalIDFromRemoteID(httpServletRequest.getRemoteUser()); 288 302 if (userID != null) { 289 if ( canWrite(userID, annotationID)) {303 if (isOwner(userID, annotationID)) { 290 304 int updatedRows = dbIntegrityService.updateUsersAnnotation(userID, annotation); 291 305 logger.info("updateAnnotation method: OK"); … … 293 307 294 308 } else { 295 httpServletResponse.sendError(HttpServletResponse.SC_UNAUTHORIZED );309 httpServletResponse.sendError(HttpServletResponse.SC_UNAUTHORIZED, "Only owner can update the annotation fully (incl. permissions). Only writer can update the annotation's body."); 296 310 return null; 297 311 } … … 449 463 final Permission permission = dbIntegrityService.getPermission(annotationID, userID); 450 464 if (permission != null) { 451 return (permission.value() == Permission.OWNER.value() || permission.value() == Permission.WRITER.value() || permission.value() == Permission.READER.value());465 return (permission.value().equals(Permission.OWNER.value()) || permission.value().equals(Permission.WRITER.value()) || permission.value().equals(Permission.READER.value())); 452 466 } else { 453 467 return false; … … 458 472 final Permission permission = dbIntegrityService.getPermission(annotationID, userID); 459 473 if (permission != null) { 460 return (permission.value() == Permission.OWNER.value() || permission.value() == Permission.WRITER.value());474 return (permission.value().equals(Permission.OWNER.value()) || permission.value().equals(Permission.WRITER.value())); 461 475 } else { 462 476 return false; … … 467 481 final Permission permission = dbIntegrityService.getPermission(annotationID, userID); 468 482 if (permission != null) { 469 return (permission.value() == Permission.OWNER.value());483 return (permission.value().equals(Permission.OWNER.value())); 470 484 } else { 471 485 return false; … … 475 489 private String[] makeAccessModeChain(String accessMode) { 476 490 if (accessMode != null) { 477 if (accessMode == Permission.OWNER.value()) {491 if (accessMode.contains(Permission.OWNER.value())) { 478 492 String[] result = new String[1]; 479 493 result[0] = accessMode; 480 494 return result; 481 495 } else { 482 if (accessMode == Permission.WRITER.value()) {496 if (accessMode.equals(Permission.WRITER.value())) { 483 497 String[] result = new String[2]; 484 498 result[0] = Permission.WRITER.value(); … … 486 500 return result; 487 501 } else { 488 if (accessMode == Permission.READER.value()) {502 if (accessMode.equals(Permission.READER.value())) { 489 503 String[] result = new String[3]; 490 504 result[0] = Permission.READER.value(); … … 504 518 } 505 519 } 520 521 506 522 } -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/rest/UserResource.java
r4254 r4262 216 216 } 217 217 } 218 219 220 @DELETE 221 @Path("{userId}/safe") 222 public String deleteUserSafe(@PathParam("userId") String externalIdentifier) throws IOException { 223 final Number remoteUserID = dbIntegrityService.getUserInternalIDFromRemoteID(httpServletRequest.getRemoteUser()); 224 if (remoteUserID != null) { 225 if (dbIntegrityService.userHasAdminRights(remoteUserID)) { 226 dbIntegrityService.setServiceURI(uriInfo.getBaseUri().toString()); 227 final Number userID = dbIntegrityService.getUserInternalIdentifier(UUID.fromString(externalIdentifier)); 228 if (userID != null) { 229 final Integer result = dbIntegrityService.deleteUserSafe(userID); 230 return "There is " + result.toString() + " row deleted"; 231 } else { 232 httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, "The user with the given id is not found in the database"); 233 return null; 234 } 235 } else { 236 httpServletResponse.sendError(HttpServletResponse.SC_UNAUTHORIZED, "The logged in user does not have admin rights to update a user info in the database"); 237 return null; 238 } 239 } else { 240 httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, "The logged in user is not found in the database"); 241 return null; 242 } 243 } 218 244 219 245 private boolean ifLoggedIn(Number userID) { -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/sql/DashishAnnotatorCreate.sql
r4183 r4262 60 60 external_id text UNIQUE NOT NULL, 61 61 last_modified timestamp default current_timestamp AT TIME ZONE 'UTC', 62 owner_id integer REFERENCES principal(principal_id),63 62 headline text, 64 63 body_text text, -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/test/java/eu/dasish/annotation/backend/dao/impl/DBIntegrityServiceTest.java
r4207 r4262 210 210 listMap.add(map5); 211 211 212 final UUID externalID3 = UUID.fromString(TestBackendConstants._TEST_USER_3_EXT_ID);213 final UUID externalID4 = UUID.fromString(TestBackendConstants._TEST_USER_4_EXT_ID);214 final UUID externalID5 = UUID.fromString(TestBackendConstants._TEST_USER_5_EXT_ID);215 216 212 final String uri3 = TestBackendConstants._TEST_SERVLET_URI_users +TestBackendConstants._TEST_USER_3_EXT_ID; 217 213 final String uri4 = TestBackendConstants._TEST_SERVLET_URI_users +TestBackendConstants._TEST_USER_4_EXT_ID; 218 214 final String uri5 = TestBackendConstants._TEST_SERVLET_URI_users +TestBackendConstants._TEST_USER_5_EXT_ID; 219 215 220 final Map<Annotation, Number> mockAnnotationOwnerID = new HashMap<Annotation, Number>();221 mockAnnotationOwnerID.put(mockAnnotation, 3);222 216 223 217 mockeryDao.checking(new Expectations() { 224 218 { 225 219 oneOf(annotationDao).getAnnotationWithoutTargetsAndPermissions(2); 226 will(returnValue(mockAnnotationOwnerID)); 220 will(returnValue(mockAnnotation)); 221 222 oneOf(annotationDao).getOwner(2); 223 will(returnValue(3)); 227 224 228 225 oneOf(userDao).getURIFromInternalID(3); … … 300 297 mockAnnotationIDs2.add(2); 301 298 mockAnnotationIDs2.add(3); 302 303 304 final UUID owner = UUID.fromString(TestBackendConstants._TEST_USER_4_EXT_ID); 299 305 300 final Timestamp after = new Timestamp(0); 306 301 final Timestamp before = new Timestamp(System.currentTimeMillis()); … … 325 320 will(returnValue(mockAnnotationIDs2)); 326 321 327 oneOf(userDao).getInternalID(owner);328 will(returnValue(4));329 330 322 331 oneOf(annotationDao).getFilteredAnnotationIDs(mockAnnotationIDs1, "some html", null, 4,after, before);323 oneOf(annotationDao).getFilteredAnnotationIDs(mockAnnotationIDs1, "some html", null, after, before); 332 324 will(returnValue(mockRetval)); 333 325 … … 336 328 337 329 338 List result = dbIntegrityService.getFilteredAnnotationIDs(word, "some html", 3, accessModes, null, owner,after, before);330 List result = dbIntegrityService.getFilteredAnnotationIDs(word, "some html", 3, accessModes, null, after, before); 339 331 assertEquals(1, result.size()); 340 332 assertEquals(3, result.get(0)); … … 417 409 TargetIDs.add(2); 418 410 419 final Map<AnnotationInfo,Number> mockPair = new HashMap<AnnotationInfo, Number>(); // annotationInfo-ownerID420 mockPair.put(mockAnnotInfo, 4);421 411 422 412 final String[] accessModes = new String[2]; … … 426 416 mockeryDao.checking(new Expectations() { 427 417 { 418 oneOf(userDao).getInternalID(ownerUUID); 419 will(returnValue(4)); 420 428 421 oneOf(annotationDao).getAnnotationIDsForUserWithPermission(3, accessModes); 429 422 will(returnValue(mockAnnotationIDs1)); 430 423 431 424 425 432 426 // getFilteredAnnotationIds 433 427 oneOf(targetDao).getTargetsReferringTo(word); … … 437 431 will(returnValue(mockAnnotationIDs2)); 438 432 439 oneOf(userDao).getInternalID(ownerUUID); 440 will(returnValue(4)); 441 442 oneOf(annotationDao).getFilteredAnnotationIDs(mockAnnotationIDs1, text, null, 4, after, before); 433 434 oneOf(annotationDao).getFilteredAnnotationIDs(mockAnnotationIDs1, text, null, after, before); 443 435 will(returnValue(mockAnnotIDs)); 444 436 … … 447 439 // 448 440 oneOf(annotationDao).getAnnotationInfoWithoutTargets(3); 449 will(returnValue(mockPair)); 441 will(returnValue(mockAnnotInfo)); 442 443 oneOf(annotationDao).getOwner(3); 444 will(returnValue(4)); 445 446 oneOf(userDao).getURIFromInternalID(4); 447 will(returnValue(TestBackendConstants._TEST_SERVLET_URI_users+"00000000-0000-0000-0000-000000000112")); 450 448 451 449 //// … … 456 454 oneOf(targetDao).getURIFromInternalID(2); 457 455 will(returnValue(TestBackendConstants._TEST_SERVLET_URI_Targets +TestBackendConstants._TEST_Target_2_EXT_ID)); 458 //// 459 460 oneOf(userDao).getURIFromInternalID(4); 461 will(returnValue(TestBackendConstants._TEST_SERVLET_URI_users +TestBackendConstants._TEST_USER_4_EXT_ID)); 462 456 463 457 464 458 } … … 682 676 mockeryDao.checking(new Expectations() { 683 677 { 684 oneOf(annotationDao).addAnnotation(testAnnotation , 5);678 oneOf(annotationDao).addAnnotation(testAnnotation); 685 679 will(returnValue(6)); // the next free number is 6 686 680 -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/test/java/eu/dasish/annotation/backend/dao/impl/JdbcAnnotationDaoTest.java
r4207 r4262 232 232 System.out.println("test getAnnotationWithoutTargets"); 233 233 jdbcAnnotationDao.setServiceURI(TestBackendConstants._TEST_SERVLET_URI_annotations); 234 final Map<Annotation, Number> result= jdbcAnnotationDao.getAnnotationWithoutTargetsAndPermissions(2); 235 Annotation[] annotations = new Annotation[1]; 236 result.keySet().toArray(annotations); 237 238 assertEquals(TestBackendConstants._TEST_ANNOT_2_HEADLINE, annotations[0].getHeadline()); 239 assertEquals(3, result.get(annotations[0])); 240 assertEquals(TestBackendConstants._TEST_ANNOT_2_BODY, annotations[0].getBody().getTextBody().getValue()); 241 assertEquals(TestBackendConstants._TEST_BODY_MIMETYPE_HTML, annotations[0].getBody().getTextBody().getMimeType()); 234 final Annotation result= jdbcAnnotationDao.getAnnotationWithoutTargetsAndPermissions(2); 235 236 assertEquals(TestBackendConstants._TEST_ANNOT_2_HEADLINE, result.getHeadline()); 237 assertEquals(TestBackendConstants._TEST_ANNOT_2_BODY, result.getBody().getTextBody().getValue()); 238 assertEquals(TestBackendConstants._TEST_BODY_MIMETYPE_HTML, result.getBody().getTextBody().getMimeType()); 242 239 assertEquals(TestBackendConstants._TEST_SERVLET_URI_annotations+ 243 TestBackendConstants._TEST_ANNOT_2_EXT, annotations[0].getURI());244 assertEquals(DatatypeFactory.newInstance().newXMLGregorianCalendar(TestBackendConstants._TEST_ANNOT_2_TIME_STAMP), annotations[0].getLastModified());240 TestBackendConstants._TEST_ANNOT_2_EXT, result.getURI()); 241 assertEquals(DatatypeFactory.newInstance().newXMLGregorianCalendar(TestBackendConstants._TEST_ANNOT_2_TIME_STAMP), result.getLastModified()); 245 242 } 246 243 … … 276 273 assertEquals(null, annotationToAdd.getLastModified()); 277 274 278 Number newAnnotationID = jdbcAnnotationDao.addAnnotation(annotationToAdd , 5);275 Number newAnnotationID = jdbcAnnotationDao.addAnnotation(annotationToAdd); 279 276 assertEquals(6, newAnnotationID); 280 277 281 278 // checking 282 Map<Annotation, Number> getResult= jdbcAnnotationDao.getAnnotationWithoutTargetsAndPermissions(6); 283 Annotation[] annotations = new Annotation[1]; 284 getResult.keySet().toArray(annotations); 285 Annotation addedAnnotation = annotations[0]; 279 Annotation addedAnnotation= jdbcAnnotationDao.getAnnotationWithoutTargetsAndPermissions(6); 286 280 assertFalse(null == addedAnnotation.getURI()); 287 281 assertFalse(null == addedAnnotation.getLastModified()); 288 assertEquals(5, getResult.get(addedAnnotation));289 282 assertEquals(annotationToAdd.getBody().getTextBody().getMimeType(), addedAnnotation.getBody().getTextBody().getMimeType()); 290 283 assertEquals(annotationToAdd.getBody().getTextBody().getValue(), addedAnnotation.getBody().getTextBody().getValue()); … … 343 336 annotationIDs.add(3); 344 337 345 List<Number> result_1 = jdbcAnnotationDao.getFilteredAnnotationIDs(annotationIDs, null, null, null, null , null);338 List<Number> result_1 = jdbcAnnotationDao.getFilteredAnnotationIDs(annotationIDs, null, null, null, null); 346 339 assertEquals(2, result_1.size()); 347 340 assertEquals(2, result_1.get(0)); … … 349 342 350 343 351 List<Number> result_2 = jdbcAnnotationDao.getFilteredAnnotationIDs(annotationIDs, "some html", null, null, null , null);344 List<Number> result_2 = jdbcAnnotationDao.getFilteredAnnotationIDs(annotationIDs, "some html", null, null, null); 352 345 assertEquals(2, result_2.size()); 353 346 assertEquals(2, result_2.get(0)); … … 355 348 356 349 357 358 List<Number> result_3 = jdbcAnnotationDao.getFilteredAnnotationIDs(annotationIDs, "some html", null, 3, null, null); 359 assertEquals(1, result_3.size()); 360 assertEquals(2, result_3.get(0)); 361 362 350 363 351 Timestamp after = new Timestamp(0); 364 352 Timestamp before = new Timestamp(System.currentTimeMillis()); 365 List<Number> result_4 = jdbcAnnotationDao.getFilteredAnnotationIDs(annotationIDs, "some html", null, 3,after, before);366 assertEquals( 1, result_4.size());353 List<Number> result_4 = jdbcAnnotationDao.getFilteredAnnotationIDs(annotationIDs, "some html", null, after, before); 354 assertEquals(2, result_4.size()); 367 355 assertEquals(2, result_4.get(0)); 368 356 assertEquals(3, result_2.get(1)); 369 357 370 358 Timestamp after_1 = new Timestamp(System.currentTimeMillis()); // no annotations added after "now" 371 List<Number> result_5 = jdbcAnnotationDao.getFilteredAnnotationIDs(annotationIDs, "some html", null, 3,after_1, null);359 List<Number> result_5 = jdbcAnnotationDao.getFilteredAnnotationIDs(annotationIDs, "some html", null, after_1, null); 372 360 assertEquals(0, result_5.size()); 373 361 -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/test/resources/test-data/InsertTestData.sql
r4181 r4262 27 27 -- INSERT INTO notebook (title, owner_id, external_id) VALUES ('a notebook', 1, 1); 28 28 29 INSERT INTO annotation ( owner_id,headline, body_text, body_mimetype, external_id, is_xml) VALUES (1,'a headline', '<html><body>some html</body></html>', 'text/html' , '00000000-0000-0000-0000-000000000005', false); --129 INSERT INTO annotation (headline, body_text, body_mimetype, external_id, is_xml) VALUES ('a headline', '<html><body>some html</body></html>', 'text/html' , '00000000-0000-0000-0000-000000000005', false); --1 30 30 31 31 INSERT INTO notebook (title, owner_id, external_id) VALUES ('a second notebook', 2, '00000000-0000-0000-0000-000000000002'); --2 … … 48 48 INSERT INTO notebook (title, owner_id, external_id) VALUES ('Notebook 6', 5, '00000000-0000-0000-0000-000000000014'); --6 49 49 50 INSERT INTO annotation ( owner_id,headline,body_text, body_mimetype, external_id, last_modified, is_xml) VALUES (3,'Sagrada Famiglia','<html><body>some html 1</body></html>', 'text/html' , '00000000-0000-0000-0000-000000000021', '2013-08-12 09:25:00.383', false); --251 INSERT INTO annotation ( owner_id,headline,body_text, body_mimetype, external_id, is_xml) VALUES (4,'Gaudi','<html><body>some html 2</body></html>', 'text/html' , '00000000-0000-0000-0000-000000000022',false); --352 INSERT INTO annotation ( owner_id,headline,body_text, body_mimetype, external_id, is_xml) VALUES (5,'Art Nuveau','some plain text', 'text/plain' , '00000000-0000-0000-0000-000000000023', false); --453 INSERT INTO annotation ( owner_id,headline,body_text, body_mimetype, external_id, is_xml) VALUES (3,'Annotation to delete','<html><body>some html 4</body></html>', 'text/html' , '00000000-0000-0000-0000-000000000024',false); --550 INSERT INTO annotation (headline,body_text, body_mimetype, external_id, last_modified, is_xml) VALUES ('Sagrada Famiglia','<html><body>some html 1</body></html>', 'text/html' , '00000000-0000-0000-0000-000000000021', '2013-08-12 09:25:00.383', false); --2 51 INSERT INTO annotation (headline,body_text, body_mimetype, external_id, is_xml) VALUES ('Gaudi','<html><body>some html 2</body></html>', 'text/html' , '00000000-0000-0000-0000-000000000022',false); --3 52 INSERT INTO annotation (headline,body_text, body_mimetype, external_id, is_xml) VALUES ('Art Nuveau','some plain text', 'text/plain' , '00000000-0000-0000-0000-000000000023', false); --4 53 INSERT INTO annotation (headline,body_text, body_mimetype, external_id, is_xml) VALUES ('Annotation to delete','<html><body>some html 4</body></html>', 'text/html' , '00000000-0000-0000-0000-000000000024',false); --5 54 54 55 55
Note: See TracChangeset
for help on using the changeset viewer.