Changeset 4429
- Timestamp:
- 02/04/14 16:25:45 (10 years ago)
- Location:
- DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src
- Files:
-
- 15 edited
Legend:
- Unmodified
- Added
- Removed
-
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/AnnotationDao.java
r4406 r4429 66 66 * 67 67 */ 68 public List<Number> getFilteredAnnotationIDs(List<Number> annotationIDs, String text, String namespace, String after, String before);68 public List<Number> getFilteredAnnotationIDs(List<Number> annotationIDs, Number ownerID, String text, String namespace, String after, String before); 69 69 70 70 public List<Number> getAllAnnotationIDs(); … … 163 163 **/ 164 164 165 public Number addAnnotation(Annotation annotation );165 public Number addAnnotation(Annotation annotation, Number newOwnerID); 166 166 167 167 … … 179 179 * @throws SQLException 180 180 */ 181 public int updateAnnotation(Annotation annotation );181 public int updateAnnotation(Annotation annotation, Number ownerID); 182 182 183 183 -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/DBIntegrityService.java
r4406 r4429 87 87 * -- created after time-samp "after and before time-stamp "before". 88 88 */ 89 List<Number> getFilteredAnnotationIDs( String link, String text, Number inloggedUserID, String[] accessModes, String namespace, String after, String before);89 List<Number> getFilteredAnnotationIDs(UUID ownerId, String link, String text, Number inloggedUserID, String[] accessModes, String namespace, String after, String before); 90 90 91 91 AnnotationInfoList getAllAnnotationInfos(); … … 108 108 * -- created after time-samp "after and before time-stamp "before". 109 109 */ 110 AnnotationInfoList getFilteredAnnotationInfos(String word, String text, Number inloggedUserID, String[] accessModes, String namespace, UUID 111 ownerID, String after, String before); 110 AnnotationInfoList getFilteredAnnotationInfos(UUID ownerId, String word, String text, Number inloggedUserID, String[] accessModes, String namespace, String after, String before); 112 111 113 112 /** … … 162 161 Annotation getAnnotation(Number annotationID); 163 162 163 Number getAnnotationOwner(Number annotationID); 164 164 165 /** 165 166 * … … 170 171 ReferenceList getAnnotationTargets(Number annotationID); 171 172 173 172 174 173 175 /** … … 244 246 /** 245 247 * 246 * @param userID247 248 * @param annotation 248 249 * @return 1 of the annotation if it is updated 249 250 */ 250 int update UsersAnnotation(Number userID,Annotation annotation);251 int updateAnnotation(Annotation annotation); 251 252 252 253 … … 313 314 * @throws SQLException 314 315 */ 315 Number addUsersAnnotation(Number userID, Annotation annotation);316 Number addUsersAnnotation(Number ownerID, Annotation annotation); 316 317 317 318 /** -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/NotebookDao.java
r3781 r4429 19 19 20 20 21 import eu.dasish.annotation.schema.Permission; 21 22 import eu.dasish.annotation.schema.ReferenceList; 22 23 import eu.dasish.annotation.schema.Notebook; … … 41 42 * 42 43 */ 43 // Returns a list of notebook-info for the notebooks accessible to the current user. 44 List<NotebookInfo> getNotebookInfos(UUID userID); 44 // Returns a list of notebook Ids for the notebooks for which the given user "userID' has "permission" access. 45 List<Number> getNotebookIDs(Number userID, Permission acessMode); 46 47 // Returns a list of notebook Ids for the notebooks for which the given user "userID" is the owner. 48 List<Number> getOwnerNotebookIDs(Number userID); 49 50 /** 51 * 52 * @param notebookID 53 * @return the notebook info for the notebook with notebookID 54 */ 55 NotebookInfo getNotebookInfo(Number notebookID); 56 57 /** 58 * 59 * @param notebookID 60 * @return notebook metadata for the notebook with notebookID 61 */ 62 Notebook getNotebookWithoutAnnotationsAndPermissions(Number notebookID); 63 45 64 46 65 // Returns the list of all notebooks owned by the current logged user. 47 List<Notebook> getUsersNotebooks(UUID userID);66 //List<Notebook> getUsersNotebooks(UUID userID); 48 67 49 68 50 69 // Returns the list of annotation Id-s for the notebook id. 51 public List<Number> getAnnotationIDs(Number notebookID);70 //public List<Number> getAnnotationIDs(Number notebookID); 52 71 53 72 /*Returns the list of annotation info-s for the notebook id. … … 55 74 56 75 // Returns the list of annotations Id-s for the notebook id. 57 public List<String> getAnnotationREFsOfNotebook(Number notebookID);76 //public List<String> getAnnotationREFsOfNotebook(Number notebookID); 58 77 59 78 // Returns the Annotations object for the notebook id. 60 public ReferenceList getAnnotations(Number notebookID);79 //public ReferenceList getAnnotations(Number notebookID); 61 80 62 81 /** … … 66 85 * user in getting the metadata of a notebook 67 86 */ 68 NotebookInfo getNotebookInfo(Number notebookID);87 //NotebookInfo getNotebookInfo(Number notebookID); 69 88 70 89 … … 74 93 * @return returns the externalIds of the annotations contained in the notebookId 75 94 */ 76 List<UUID> getAnnotationExternalIDs(UUID notebookId);95 //List<UUID> getAnnotationExternalIDs(UUID notebookId); 77 96 78 97 … … 83 102 84 103 // Creates a new notebook and returns the _nid_ of the created Notebook 85 UUID addNotebook(UUID userID, String title);104 //UUID addNotebook(UUID userID, String title); 86 105 87 106 // Adds an annotation _aid_ to the list of annotations of _nid_. 88 public int addAnnotation(UUID notebookId, UUID annotationId);107 //public int addAnnotation(UUID notebookId, UUID annotationId); 89 108 90 109 … … 98 117 // Delete _nid_. Annotations stay, they just lose connection to _nid_.<br> 99 118 // returns the number of records deleted 100 public int deleteNotebook(UUID notebookId);119 //public int deleteNotebook(UUID notebookId); 101 120 /** 102 121 * … … 104 123 * @return removes the rows with annotationID from notebooks_annotations table 105 124 */ 106 int removeAnnotation(Number annotationID);125 //int removeAnnotation(Number annotationID); 107 126 } -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/impl/DBIntegrityServiceImlp.java
r4406 r4429 40 40 import eu.dasish.annotation.schema.User; 41 41 import eu.dasish.annotation.schema.UserWithPermission; 42 import java.io.IOException;43 42 import java.io.InputStream; 44 43 import java.lang.Number; 45 import java.sql.SQLException;46 import java.sql.Timestamp;47 44 import java.util.ArrayList; 48 45 import java.util.HashMap; … … 50 47 import java.util.Map; 51 48 import java.util.UUID; 52 import javax.xml.parsers.ParserConfigurationException;53 49 import org.springframework.beans.factory.annotation.Autowired; 54 50 import org.slf4j.Logger; 55 51 import org.slf4j.LoggerFactory; 56 import org.springframework.transaction.annotation.Transactional;57 52 58 53 /** … … 151 146 result.setTargets(sis); 152 147 153 result.setPermissions( getPermissionsForAnnotation(annotationID));148 result.setPermissions(this.getPermissionsForAnnotation(annotationID)); 154 149 return result; 155 150 } else { 156 151 return null; 157 152 } 153 } 154 155 @Override 156 public Number getAnnotationOwner(Number annotationID) { 157 return annotationDao.getOwner(annotationID); 158 158 } 159 159 … … 186 186 //////////////////////////////////////////////////////////////////////// 187 187 @Override 188 public List<Number> getFilteredAnnotationIDs( String link, String text, Number inloggedUserID, String[] accessModes, String namespace, String after, String before) {188 public List<Number> getFilteredAnnotationIDs(UUID ownerId, String link, String text, Number inloggedUserID, String[] accessModes, String namespace, String after, String before) { 189 189 190 190 if (accessModes == null) { … … 200 200 } 201 201 202 return annotationDao.getFilteredAnnotationIDs(annotationIDs, text, namespace, after, before); 202 Number ownerID = (ownerId != null) ? userDao.getInternalID(ownerId) : null; 203 return annotationDao.getFilteredAnnotationIDs(annotationIDs, ownerID, text, namespace, after, before); 203 204 } 204 205 … … 255 256 256 257 @Override 257 public AnnotationInfoList getFilteredAnnotationInfos(String word, String text, Number inloggedUserID, String[] accessModes, String namespace, UUID owner, String after, String before) { 258 List<Number> annotationIDs = getFilteredAnnotationIDs(word, text, inloggedUserID, accessModes, namespace, after, before); 259 Number givenOwnerID = (owner != null) ? userDao.getInternalID(owner) : null; 258 public AnnotationInfoList getFilteredAnnotationInfos(UUID ownerId, String word, String text, Number inloggedUserID, String[] accessModes, String namespace, String after, String before) { 259 List<Number> annotationIDs = this.getFilteredAnnotationIDs(ownerId, word, text, inloggedUserID, accessModes, namespace, after, before); 260 260 if (annotationIDs != null) { 261 261 AnnotationInfoList result = new AnnotationInfoList(); 262 262 for (Number annotationID : annotationIDs) { 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 } 263 AnnotationInfo annotationInfo = annotationDao.getAnnotationInfoWithoutTargets(annotationID); 264 annotationInfo.setTargets(this.getAnnotationTargets(annotationID)); 265 annotationInfo.setOwnerRef(userDao.getURIFromInternalID(annotationDao.getOwner(annotationID))); 266 result.getAnnotationInfo().add(annotationInfo); 267 271 268 } 272 269 … … 379 376 public int updateAnnotationPrincipalPermission(Number annotationID, Number userID, Permission permission) { 380 377 if (permission != null) { 381 return annotationDao.updateAnnotationPrincipalPermission(annotationID, userID, permission); 382 } 383 else { 378 return annotationDao.updateAnnotationPrincipalPermission(annotationID, userID, permission); 379 } else { 384 380 return annotationDao.deleteAnnotationPrincipalPermission(annotationID, userID); 385 381 } … … 412 408 // TODO: unit test 413 409 @Override 414 public int update UsersAnnotation(Number userID,Annotation annotation) {415 int updatedAnnotations = annotationDao.updateAnnotation(annotation );410 public int updateAnnotation(Annotation annotation) { 411 int updatedAnnotations = annotationDao.updateAnnotation(annotation, userDao.getInternalIDFromURI(annotation.getOwnerRef())); 416 412 Number annotationID = annotationDao.getInternalIDFromURI(annotation.getURI()); 417 413 int deletedTargets = annotationDao.deleteAllAnnotationTarget(annotationID); … … 463 459 464 460 @Override 465 public Number addUsersAnnotation(Number userID, Annotation annotation) {466 Number annotationID = annotationDao.addAnnotation(annotation );461 public Number addUsersAnnotation(Number ownerID, Annotation annotation) { 462 Number annotationID = annotationDao.addAnnotation(annotation, ownerID); 467 463 int affectedAnnotRows = addTargets(annotation, annotationID); 468 464 if (annotation.getPermissions() != null) { 469 465 if (annotation.getPermissions().getUserWithPermission() != null) { 470 int addedPrincipalsPermissions = addPrincipalsPermissions(annotation.getPermissions().getUserWithPermission(), annotationID); 471 } 472 } 473 int affectedPermissions = annotationDao.addAnnotationPrincipalPermission(annotationID, userID, Permission.OWNER); 466 int addedPrincipalsPermissions = this.addPrincipalsPermissions(annotation.getPermissions().getUserWithPermission(), annotationID); 467 } 468 } 474 469 return annotationID; 475 470 } … … 526 521 List<Number> cachedIDs = targetDao.getCachedRepresentations(TargetID); 527 522 for (Number cachedID : cachedIDs) { 528 int[] currentResult = deleteCachedRepresentationOfTarget(TargetID, cachedID);523 int[] currentResult = this.deleteCachedRepresentationOfTarget(TargetID, cachedID); 529 524 result[0] = result[0] + currentResult[0]; 530 525 result[1] = result[1] + currentResult[1]; … … 543 538 if (targetIDs != null) { 544 539 for (Number targetID : targetIDs) { 545 deleteAllCachedRepresentationsOfTarget(targetID);540 this.deleteAllCachedRepresentationsOfTarget(targetID); 546 541 result[3] = result[3] + targetDao.deleteTarget(targetID); 547 542 -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/impl/JdbcAnnotationDao.java
r4406 r4429 142 142 StringBuilder sql = new StringBuilder("SELECT "); 143 143 sql.append(annotation_id).append(" FROM ").append(permissionsTableName).append(" WHERE "). 144 append(principal_id).append(" = ").append(userID.toString()).append(" AND ").144 append(principal_id).append(" = ?").append(" AND "). 145 145 append(permission).append(" IN ").append(values); 146 return getSimpleJdbcTemplate().query(sql.toString(), internalIDRowMapper );146 return getSimpleJdbcTemplate().query(sql.toString(), internalIDRowMapper, userID); 147 147 } 148 148 … … 166 166 //////////////////////////////////////////////////////////////////////// 167 167 @Override 168 public List<Number> getFilteredAnnotationIDs(List<Number> annotationIDs, String text, String namespace, String after, String before) {168 public List<Number> getFilteredAnnotationIDs(List<Number> annotationIDs, Number ownerID, String text, String namespace, String after, String before) { 169 169 170 170 StringBuilder sql = new StringBuilder("SELECT DISTINCT "); … … 184 184 sql.append(" AND ").append(annotation_id).append(" IN ").append(values); 185 185 186 186 if (ownerID != null) { 187 sql.append(" AND ").append(owner_id).append(" = :ownerId"); 188 params.put("ownerId", ownerID); 189 } 190 187 191 if (after != null) { 188 192 sql.append(" AND ").append(last_modified).append(" > :afterTimestamp"); … … 334 338 } 335 339 StringBuilder sql = new StringBuilder("SELECT "); 336 sql.append(principal_id).append(" FROM ").append(permissionsTableName).append(" WHERE "). 337 append(permission).append("= 'owner' AND "). 340 sql.append(owner_id).append(" FROM ").append(annotationTableName).append(" WHERE "). 338 341 append(annotation_id).append("= ? LIMIT 1"); 339 List<Number> respond = getSimpleJdbcTemplate().query(sql.toString(), principalIDRowMapper, annotationID);342 List<Number> respond = getSimpleJdbcTemplate().query(sql.toString(), ownerIDRowMapper, annotationID); 340 343 return (respond.isEmpty() ? null : respond.get(0)); 341 344 } 345 346 342 347 343 348 ///////////////////////////// … … 386 391 // TODO Unit test 387 392 @Override 388 public int updateAnnotation(Annotation annotation ) {393 public int updateAnnotation(Annotation annotation, Number newOwnerID) { 389 394 390 395 String[] body = retrieveBodyComponents(annotation.getBody()); 391 396 String externalID = stringURItoExternalID(annotation.getURI()); 392 397 Map<String, Object> params = new HashMap<String, Object>(); 398 params.put("owner", newOwnerID); 393 399 params.put("bodyText", body[0]); 394 400 params.put("bodyMimeType", body[1]); … … 400 406 StringBuilder sql = new StringBuilder("UPDATE "); 401 407 sql.append(annotationTableName).append(" SET "). 408 append(owner_id).append("= :owner ,"). 402 409 append(body_text).append("= :bodyText ,"). 403 410 append(body_mimetype).append("= :bodyMimeType ,"). … … 452 459 //////////// ADDERS //////////////////////// 453 460 @Override 454 public Number addAnnotation(Annotation annotation ) {461 public Number addAnnotation(Annotation annotation, Number ownerID) { 455 462 456 463 String[] body = retrieveBodyComponents(annotation.getBody()); … … 465 472 Map<String, Object> params = new HashMap<String, Object>(); 466 473 params.put("externalId", externalID.toString()); 474 params.put("owner", ownerID); 467 475 params.put("headline", annotation.getHeadline()); 468 476 params.put("bodyText", body[0]); … … 471 479 472 480 StringBuilder sql = new StringBuilder("INSERT INTO "); 473 sql.append(annotationTableName).append("(").append(external_id) ;481 sql.append(annotationTableName).append("(").append(external_id).append(",").append(owner_id); 474 482 sql.append(",").append(headline).append(",").append(body_text).append(",").append(body_mimetype).append(",").append(is_xml). 475 append(" ) VALUES (:externalId, : headline, :bodyText, :bodyMimeType, :isXml)");483 append(" ) VALUES (:externalId, :owner, :headline, :bodyText, :bodyMimeType, :isXml)"); 476 484 int affectedRows = getSimpleJdbcTemplate().update(sql.toString(), params); 477 485 return ((affectedRows > 0) ? getInternalID(externalID) : null); -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/impl/JdbcNotebookDao.java
r4262 r4429 19 19 20 20 import eu.dasish.annotation.backend.dao.NotebookDao; 21 import eu.dasish.annotation.schema.ReferenceList;22 21 import eu.dasish.annotation.schema.Notebook; 23 22 import eu.dasish.annotation.schema.NotebookInfo; 23 import eu.dasish.annotation.schema.Permission; 24 24 import java.sql.ResultSet; 25 25 import java.sql.SQLException; 26 import java.util.ArrayList;27 26 import java.util.GregorianCalendar; 28 27 import java.util.HashMap; 29 28 import java.util.List; 30 29 import java.util.Map; 31 import java.util.UUID;32 30 import javax.sql.DataSource; 33 31 import org.springframework.jdbc.core.RowMapper; … … 35 33 import javax.xml.datatype.DatatypeFactory; 36 34 import javax.xml.datatype.XMLGregorianCalendar; 37 import org.springframework.dao.DataAccessException;38 import org.springframework.jdbc.core.simple.SimpleJdbcInsert;39 35 40 36 /** … … 57 53 } 58 54 55 /// GETTERS ///////// 56 59 57 //////////////////////////////////////////////// 60 58 @Override 61 public List<NotebookInfo> getNotebookInfos(UUID userID) { 62 String sql = "SELECT " + notebookTitle + ", " + notebookExternal_id + " FROM " + notebookTableName + ", " + principalTableName + " where " + principalPrincipal_id + " = " + notebookOwner_id + " and " + principalExternal_id + " = ?"; 63 return getSimpleJdbcTemplate().query(sql, notebookInfoRowMapper, userID.toString()); 59 public List<Number> getNotebookIDs(Number userID, Permission acessMode) { 60 Map<String, Object> params = new HashMap<String, Object>(); 61 params.put("principalID", userID); 62 params.put("accessMode", acessMode.value()); 63 String sql = "SELECT " + notebook_id + " FROM " + notebookPermissionsTableName +" WHERE " + principalPrincipal_id + " = :principalID" + " AND " + permission + " = :accessMode"; 64 return getSimpleJdbcTemplate().query(sql, internalIDRowMapper, params); 65 } 66 67 //////////////////////////////////////////////// 68 @Override 69 public List<Number> getOwnerNotebookIDs(Number userID) { 70 String sql = "SELECT " + notebook_id + " FROM " + notebookTableName +" WHERE " + owner_id + " = ?"; 71 return getSimpleJdbcTemplate().query(sql, internalIDRowMapper, userID); 72 } 73 74 75 76 @Override 77 public NotebookInfo getNotebookInfo(Number notebookID) { 78 if (notebookID == null) { 79 return null; 80 } 81 String sql = "SELECT " + notebookExternal_id + "," + notebookTitle + " FROM " + notebookTableName + " where " + notebook_id + " = ? LIMIT 1"; 82 List<NotebookInfo> result = getSimpleJdbcTemplate().query(sql, notebookInfoRowMapper, notebookID.toString()); 83 return (!result.isEmpty() ? result.get(0) : null); 64 84 } 65 85 … … 74 94 }; 75 95 76 //////////////////////////////////////////////// 77 78 @Override 79 public List<Notebook> getUsersNotebooks(UUID userID) { 80 String sql = "SELECT " + notebookStar + " FROM " + notebookTableName + ", " + principalTableName + " where " + principal_id + " = " + notebookOwner_id + " and " + principalExternal_id + " = ?"; 81 return getSimpleJdbcTemplate().query(sql, notebookRowMapper, userID.toString()); 82 } 96 97 @Override 98 public Notebook getNotebookWithoutAnnotationsAndPermissions(Number notebookID) { 99 if (notebookID == null) { 100 return null; 101 } 102 String sql = "SELECT " + notebookExternal_id + "," + notebookTitle + "," + last_modified +" FROM " + notebookTableName + " where " + notebook_id + " = ? LIMIT 1"; 103 List<Notebook> result = getSimpleJdbcTemplate().query(sql, notebookRowMapper, notebookID); 104 return (!result.isEmpty() ? result.get(0) : null); 105 } 106 107 83 108 84 109 private final RowMapper<Notebook> notebookRowMapper = new RowMapper<Notebook>() { … … 86 111 public Notebook mapRow(ResultSet rs, int rowNumber) throws SQLException { 87 112 Notebook notebook = new Notebook(); 88 // notebook.setId(rs.getInt("notebook_id"));89 113 notebook.setTitle(rs.getString(title)); 90 114 GregorianCalendar calendar = new GregorianCalendar(); … … 96 120 throw new SQLException(exception); 97 121 } 98 notebook.setURI(externalIDtoURI(rs.getString("external_id"))); 99 notebook.setAnnotations(getAnnotations(rs.getInt(notebook_id))); 122 notebook.setURI(externalIDtoURI(rs.getString(external_id))); 100 123 return notebook; 101 124 } 102 125 }; 103 126 104 @Override105 public UUID addNotebook(UUID userID, String title) {106 try {107 final UUID externalIdentifier = UUID.randomUUID();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 Map<String, Object> params = new HashMap<String, Object>();110 params.put("notebookId", externalIdentifier.toString());111 params.put("userID", userID.toString());112 params.put("title", title);113 final int updatedRowCount = getSimpleJdbcTemplate().update(sql, params);114 return externalIdentifier;115 } catch (DataAccessException exception) {116 throw exception;117 }118 }127 // @Override 128 // public UUID addNotebook(UUID userID, String title) { 129 // try { 130 // final UUID externalIdentifier = UUID.randomUUID(); 131 // String sql = "INSERT INTO " + notebookTableName + " (" + external_id + ", " + this.title + "," + notebookOwner_id + ") VALUES (:notebookId, :title, (SELECT " + principal_id + " FROM " + principalTableName + " WHERE " + principalExternal_id + " = :userID))"; 132 // Map<String, Object> params = new HashMap<String, Object>(); 133 // params.put("notebookId", externalIdentifier.toString()); 134 // params.put("userID", userID.toString()); 135 // params.put("title", title); 136 // final int updatedRowCount = getSimpleJdbcTemplate().update(sql, params); 137 // return externalIdentifier; 138 // } catch (DataAccessException exception) { 139 // throw exception; 140 // } 141 // } 119 142 120 143 121 144 122 145 // returns the number of affected annotations 123 @Override124 public int deleteNotebook(UUID notebookId) {125 String sql1 = "DELETE FROM " + notebooksAnnotationsTableName + " where " + notebook_id + "= (SELECT " + notebook_id + " FROM " + notebookTableName + " WHERE " + external_id + " = ?)";126 String sql2 = "DELETE FROM notebook where external_id = ?";127 int affectedAnnotations = getSimpleJdbcTemplate().update(sql1, notebookId.toString());128 int affectedNotebooks = getSimpleJdbcTemplate().update(sql2, notebookId.toString());129 return affectedAnnotations;130 }131 132 @Override133 public int addAnnotation(UUID notebookId, UUID annotationId) {134 try {135 SimpleJdbcInsert notebookInsert = new SimpleJdbcInsert(getDataSource()).withTableName(notebooksAnnotationsTableName);136 Map<String, Object> params = new HashMap<String, Object>();137 params.put(notebook_id, notebookId);138 params.put(annotation_id, annotationId);139 int rowsAffected = notebookInsert.execute(params);140 return rowsAffected;141 } catch (DataAccessException exception) {142 throw exception;143 }144 }146 // @Override 147 // public int deleteNotebook(UUID notebookId) { 148 // String sql1 = "DELETE FROM " + notebooksAnnotationsTableName + " where " + notebook_id + "= (SELECT " + notebook_id + " FROM " + notebookTableName + " WHERE " + external_id + " = ?)"; 149 // String sql2 = "DELETE FROM notebook where external_id = ?"; 150 // int affectedAnnotations = getSimpleJdbcTemplate().update(sql1, notebookId.toString()); 151 // int affectedNotebooks = getSimpleJdbcTemplate().update(sql2, notebookId.toString()); 152 // return affectedAnnotations; 153 // } 154 155 // @Override 156 // public int addAnnotation(UUID notebookId, UUID annotationId) { 157 // try { 158 // SimpleJdbcInsert notebookInsert = new SimpleJdbcInsert(getDataSource()).withTableName(notebooksAnnotationsTableName); 159 // Map<String, Object> params = new HashMap<String, Object>(); 160 // params.put(notebook_id, notebookId); 161 // params.put(annotation_id, annotationId); 162 // int rowsAffected = notebookInsert.execute(params); 163 // return rowsAffected; 164 // } catch (DataAccessException exception) { 165 // throw exception; 166 // } 167 // } 145 168 146 169 //////////////////////////////////////////////////////////////////////// … … 152 175 * do we need to return null here? using an additional check. 153 176 */ 154 @Override155 public List<Number> getAnnotationIDs(Number notebookID) {156 StringBuilder sql = new StringBuilder("SELECT DISTINCT ");157 sql.append(notebooksAnnotationsTableNameAnnotation_id).append(" FROM ").append(notebooksAnnotationsTableName).append(" where ").append(notebook_id).append(" = ?");158 return getSimpleJdbcTemplate().query(sql.toString(), annotationIDRowMapper, notebookID);159 }177 // @Override 178 // public List<Number> getAnnotationIDs(Number notebookID) { 179 // StringBuilder sql = new StringBuilder("SELECT DISTINCT "); 180 // sql.append(notebooksAnnotationsTableNameAnnotation_id).append(" FROM ").append(notebooksAnnotationsTableName).append(" where ").append(notebook_id).append(" = ?"); 181 // return getSimpleJdbcTemplate().query(sql.toString(), annotationIDRowMapper, notebookID); 182 // } 160 183 161 184 ////////////////////////////////////////////////// … … 179 202 * null if notebookID == null or it does not exists in the DB 180 203 */ 181 @Override182 public List<String> getAnnotationREFsOfNotebook(Number notebookID) {183 return null; //jdbcAnnotationDao.getAnnotationREFs(getAnnotationIDs(notebookID));184 }204 // @Override 205 // public List<String> getAnnotationREFsOfNotebook(Number notebookID) { 206 // return null; //jdbcAnnotationDao.getAnnotationREFs(getAnnotationIDs(notebookID)); 207 // } 185 208 186 209 //////////////////////////////////////////////////////////////////////////// … … 196 219 * 197 220 */ 198 @Override199 public ReferenceList getAnnotations(Number notebookID) {200 if (notebookID == null) {201 return null;202 }203 ReferenceList result = new ReferenceList();204 result.getRef().addAll(getAnnotationREFsOfNotebook(notebookID));205 return result;206 207 }221 // @Override 222 // public ReferenceList getAnnotations(Number notebookID) { 223 // if (notebookID == null) { 224 // return null; 225 // } 226 // ReferenceList result = new ReferenceList(); 227 // result.getRef().addAll(getAnnotationREFsOfNotebook(notebookID)); 228 // return result; 229 // 230 // } 208 231 209 232 /////////////////////////////////////////////////// 210 // REUSES notebookInfoRowMapper 211 @Override 212 public NotebookInfo getNotebookInfo(Number notebookID) { 213 if (notebookID == null) { 214 return null; 215 } 216 String sql = "SELECT " + notebookExternal_id + "," + notebookTitle + " FROM " + notebookTableName + " where " + notebook_id + " = ? LIMIT 1"; 217 List<NotebookInfo> result = getSimpleJdbcTemplate().query(sql, notebookInfoRowMapper, notebookID.toString()); 218 return (!result.isEmpty() ? result.get(0) : null); 219 } 220 233 234 221 235 222 236 ////////////////////////////////////////////////////////////////// 223 @Override224 public List<UUID> getAnnotationExternalIDs(UUID notebookId) {225 List<Number> internalIds = getAnnotationIDs(getInternalID(notebookId));226 if (internalIds == null) {227 return null;228 }229 List<UUID> annotationIds = new ArrayList<UUID>();230 // for (Number internalId : internalIds) {231 // annotationIds.add(jdbcAnnotationDao.getExternalID(internalId));232 // }233 return annotationIds;234 }237 // @Override 238 // public List<UUID> getAnnotationExternalIDs(UUID notebookId) { 239 // List<Number> internalIds = getAnnotationIDs(getInternalID(notebookId)); 240 // if (internalIds == null) { 241 // return null; 242 // } 243 // List<UUID> annotationIds = new ArrayList<UUID>(); 244 //// for (Number internalId : internalIds) { 245 //// annotationIds.add(jdbcAnnotationDao.getExternalID(internalId)); 246 //// } 247 // return annotationIds; 248 // } 235 249 236 250 //////////////////////////////////////////////////////////// 237 @Override238 public int removeAnnotation(Number annotationID) {239 String sqlNotebooks = "DELETE FROM " + notebooksAnnotationsTableName + " where " + annotation_id + " = ?";240 int affectedNotebooks = getSimpleJdbcTemplate().update(sqlNotebooks, annotationID);241 return affectedNotebooks;242 }251 // @Override 252 // public int removeAnnotation(Number annotationID) { 253 // String sqlNotebooks = "DELETE FROM " + notebooksAnnotationsTableName + " where " + annotation_id + " = ?"; 254 // int affectedNotebooks = getSimpleJdbcTemplate().update(sqlNotebooks, annotationID); 255 // return affectedNotebooks; 256 // } 243 257 } -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/impl/JdbcResourceDao.java
r4396 r4429 47 47 final static protected String notebooksAnnotationsTableName = "notebooks_annotations"; 48 48 final static protected String permissionsTableName = "annotations_principals_permissions"; 49 final static protected String notebookPermissionsTableName = "notebooks_principals_permissions"; 49 50 final static protected String annotationsTargetsTableName = "annotations_targets"; 50 51 final static protected String targetsCachedRepresentationsTableName = "targets_cached_representations"; … … 58 59 final static protected String target_id = "target_id"; 59 60 final static protected String external_id = "external_id"; 61 final static protected String owner_id = "owner_id"; 60 62 final static protected String headline = "headline"; 61 63 final static protected String body_text = "body_text"; … … 220 222 } 221 223 }; 224 225 protected final RowMapper<Number> ownerIDRowMapper = new RowMapper<Number>() { 226 @Override 227 public Number mapRow(ResultSet rs, int rowNumber) throws SQLException { 228 return rs.getInt(owner_id); 229 } 230 }; 231 222 232 protected final RowMapper<Number> notebookOwnerIDRowMapper = new RowMapper<Number>() { 223 233 @Override -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/rest/AnnotationResource.java
r4406 r4429 210 210 UUID ownerExternalUUID = (ownerExternalId != null) ? UUID.fromString(ownerExternalId) : null; 211 211 String access = (permission != null) ? permission : default_permission; 212 final AnnotationInfoList annotationInfoList = dbIntegrityService.getFilteredAnnotationInfos(link, text, userID, makeAccessModeChain(access), namespace, ownerExternalUUID, after, before); 213 logger.info("getFilteredAnnotations method: OK"); 212 final AnnotationInfoList annotationInfoList = dbIntegrityService.getFilteredAnnotationInfos(ownerExternalUUID, link, text, userID, this.makeAccessModeChain(access), namespace, after, before); 214 213 return new ObjectFactory().createAnnotationInfoList(annotationInfoList); 215 214 } catch (IllegalArgumentException e) { … … 277 276 if (userID != null) { 278 277 if (annotationID != null) { 279 if ( isOwner(userID, annotationID)) {278 if (userID.equals(dbIntegrityService.getAnnotationOwner(annotationID))) { 280 279 int[] resultDelete = dbIntegrityService.deleteAnnotation(annotationID); 281 280 String result = Integer.toString(resultDelete[0]); … … 342 341 } 343 342 344 List<UserWithPermission> permissions = annotation.getPermissions().getUserWithPermission();345 String ownerURI = annotation.getOwnerRef();346 if (!ownerIsListed(ownerURI, permissions)) {347 loggerServer.debug(httpServletResponse.SC_CONFLICT + "Wrong request body: the owner URI's is not listed in the list of permissions as 'owner'. Correct the request and resend.");348 httpServletResponse.sendError(HttpServletResponse.SC_CONFLICT, "Wrong request body: the owner URI's is not listed in the list of permissions as 'owner'. Correct the request and resend.");349 return null;350 }351 343 352 344 try { … … 356 348 Number userID = dbIntegrityService.getUserInternalIDFromRemoteID(remoteUser); 357 349 if (userID != null) { 358 if ( isOwner(userID, annotationID)) {359 int updatedRows = dbIntegrityService.update UsersAnnotation(userID,annotation);350 if (userID.equals(dbIntegrityService.getAnnotationOwner(annotationID))) { 351 int updatedRows = dbIntegrityService.updateAnnotation(annotation); 360 352 return new ObjectFactory().createResponseBody(makeAnnotationResponseEnvelope(annotationID)); 361 353 … … 436 428 final Number annotationID = dbIntegrityService.getAnnotationInternalIdentifier(UUID.fromString(annotationExternalId)); 437 429 if (annotationID != null) { 438 if ( isOwner(remoteUserID, annotationID)) {430 if (userID.equals(dbIntegrityService.getAnnotationOwner(annotationID))) { 439 431 int result = (dbIntegrityService.getPermission(annotationID, userID) != null) 440 432 ? dbIntegrityService.updateAnnotationPrincipalPermission(annotationID, userID, permission) … … 488 480 if (remoteUserID != null) { 489 481 if (annotationID != null) { 490 if ( isOwner(remoteUserID, annotationID)) {482 if (remoteUserID.equals(dbIntegrityService.getAnnotationOwner(annotationID))) { 491 483 int updatedRows = dbIntegrityService.updatePermissions(annotationID, permissions); 492 484 return new ObjectFactory().createResponseBody(makePermissionResponseEnvelope(annotationID)); … … 512 504 } 513 505 } 514 506 515 507 @DELETE 516 508 @Produces(MediaType.TEXT_PLAIN) … … 525 517 if (remoteUserID != null) { 526 518 if (annotationID != null) { 527 if ( isOwner(remoteUserID, annotationID)) {519 if (remoteUserID.equals(dbIntegrityService.getAnnotationOwner(annotationID))) { 528 520 Number userID = dbIntegrityService.getUserInternalIdentifier(UUID.fromString(userId)); 529 521 if (userID != null) { … … 605 597 606 598 private boolean canRead(Number userID, Number annotationID) { 599 if (userID.equals(dbIntegrityService.getAnnotationOwner(annotationID))) { 600 return true; 601 } 602 607 603 final Permission permission = dbIntegrityService.getPermission(annotationID, userID); 608 604 if (permission != null) { 609 return (permission.value().equals(Permission. OWNER.value()) || permission.value().equals(Permission.WRITER.value()) || permission.value().equals(Permission.READER.value()));605 return (permission.value().equals(Permission.WRITER.value()) || permission.value().equals(Permission.READER.value())); 610 606 } else { 611 607 return false; … … 614 610 615 611 private boolean canWrite(Number userID, Number annotationID) { 612 if (userID.equals(dbIntegrityService.getAnnotationOwner(annotationID))) { 613 return true; 614 } 616 615 final Permission permission = dbIntegrityService.getPermission(annotationID, userID); 617 616 if (permission != null) { 618 return (permission.value().equals(Permission. OWNER.value()) || permission.value().equals(Permission.WRITER.value()));617 return (permission.value().equals(Permission.WRITER.value())); 619 618 } else { 620 619 return false; … … 622 621 } 623 622 624 private boolean isOwner(Number userID, Number annotationID) {625 final Permission permission = dbIntegrityService.getPermission(annotationID, userID);626 if (permission != null) {627 return (permission.value().equals(Permission.OWNER.value()));628 } else {629 return false;630 }631 }632 633 623 private String[] makeAccessModeChain(String accessMode) { 634 624 if (accessMode != null) { 635 if (accessMode. contains(Permission.OWNER.value())) {625 if (accessMode.equals(Permission.READER.value())) { 636 626 String[] result = new String[1]; 637 result[0] = accessMode;627 result[0] = Permission.READER.value(); 638 628 return result; 639 629 } else { 640 630 if (accessMode.equals(Permission.WRITER.value())) { 641 631 String[] result = new String[2]; 642 result[0] = Permission. WRITER.value();643 result[1] = Permission. OWNER.value();632 result[0] = Permission.READER.value(); 633 result[1] = Permission.WRITER.value(); 644 634 return result; 645 635 } else { 646 if (accessMode.equals(Permission.READER.value())) { 647 String[] result = new String[3]; 648 result[0] = Permission.READER.value(); 649 result[1] = Permission.WRITER.value(); 650 result[2] = Permission.OWNER.value(); 651 return result; 652 } else { 653 logger.error("Invalide access " + accessMode); 654 return null; 655 } 656 657 } 636 logger.error("Invalide access " + accessMode); 637 return null; 638 } 639 658 640 } 659 641 … … 662 644 } 663 645 } 664 665 private boolean ownerIsListed(String uri, List<UserWithPermission> permissions) {666 for (UserWithPermission permissionPair : permissions) {667 if (permissionPair.getRef().equals(uri) && permissionPair.getPermission().equals(Permission.OWNER)) {668 return true;669 }670 }671 return false;672 }673 646 } -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/sql/DashishAnnotatorCreate.sql
r4276 r4429 51 51 notebook_id SERIAL UNIQUE NOT NULL, 52 52 external_id text UNIQUE NOT NULL, 53 owner_id integer REFERENCES principal(principal_id), 53 54 last_modified timestamp default current_timestamp AT TIME ZONE 'UTC', 54 title text, 55 owner_id integer NOT NULL 55 title text 56 56 ); 57 57 … … 60 60 annotation_id SERIAL UNIQUE NOT NULL, 61 61 external_id text UNIQUE NOT NULL, 62 owner_id integer REFERENCES principal(principal_id), 62 63 last_modified timestamp default current_timestamp AT TIME ZONE 'UTC', 63 64 headline text, … … 119 120 120 121 121 122 122 CREATE TABLE annotations_principals_permissions ( 123 123 annotation_id integer REFERENCES annotation(annotation_id), … … 127 127 ); 128 128 129 CREATE TABLE notebooks_principals_permissions ( 130 notebook_id integer REFERENCES notebook(notebook_id), 131 principal_id integer REFERENCES principal(principal_id), 132 permission_ text REFERENCES permission_(permission_mode), 133 unique(notebook_id, principal_id) 134 ); 135 129 136 130 137 --------------------------------------------------------------------------------------------- 131 ALTER TABLE ONLY annotation132 ADD CONSTRAINT annotation_primary_key PRIMARY KEY (annotation_id);138 -- ALTER TABLE ONLY annotation 139 -- ADD CONSTRAINT annotation_primary_key PRIMARY KEY (annotation_id); 133 140 134 ALTER TABLE ONLY notebooks_annotations135 ADD CONSTRAINT pk_notebooks_annotations PRIMARY KEY (notebook_id, annotation_id);141 -- ALTER TABLE ONLY notebooks_annotations 142 -- ADD CONSTRAINT pk_notebooks_annotations PRIMARY KEY (notebook_id, annotation_id); 136 143 137 144 138 CREATE INDEX fki_annotation_owner_principal_id ON annotation USING btree (owner_id); 145 -- ALTER TABLE ONLY annotation 146 -- ADD CONSTRAINT fk_annotation_owner_principal_id FOREIGN KEY (owner_id) REFERENCES principal(principal_id); 139 147 140 CREATE INDEX fki_owner_id_principal_id ON notebook USING btree (owner_id); 141 142 ALTER TABLE ONLY annotation 143 ADD CONSTRAINT fk_annotation_owner_principal_id FOREIGN KEY (owner_id) REFERENCES principal(principal_id); 144 145 ALTER TABLE ONLY notebook 146 ADD CONSTRAINT fk_notebook_owner_id_principal_id FOREIGN KEY (owner_id) REFERENCES principal(principal_id); 148 -- ALTER TABLE ONLY notebook 149 -- ADD CONSTRAINT fk_notebook_owner_id_principal_id FOREIGN KEY (owner_id) REFERENCES principal(principal_id); 147 150 148 151 --ALTER TABLE ONLY notebooks_annotations -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/webapp/META-INF/context.xml
r4324 r4429 20 20 --> 21 21 <Context antiJARLocking="true" path="/annotator-backend"> 22 <Resource auth="Container" driverClassName="org.postgresql.Driver" logAbandoned="true" maxActive="10" maxIdle="5" maxWait="4000" name="jdbc/DASISHAnnotator" password="dasish" removeAbandoned="false" removeAbandonedTimeout="10" type="javax.sql.DataSource" url="jdbc:postgresql:annotator" username="dasish"/> 22 <Resource auth="Container" 23 driverClassName="org.postgresql.Driver" 24 logAbandoned="true" maxActive="10" maxIdle="5" maxWait="4000" 25 name="jdbc/DASISHAnnotator" 26 password="dasish" 27 removeAbandoned="false" 28 removeAbandonedTimeout="10" 29 type="javax.sql.DataSource" 30 url="jdbc:postgresql:annotator" 31 username="dasish"/> 23 32 </Context> -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/test/java/eu/dasish/annotation/backend/dao/impl/DBIntegrityServiceTest.java
r4406 r4429 319 319 320 320 321 oneOf(annotationDao).getFilteredAnnotationIDs(mockAnnotationIDs1, "some html", null, after, before);321 oneOf(annotationDao).getFilteredAnnotationIDs(mockAnnotationIDs1, null, "some html", null, after, before); 322 322 will(returnValue(mockRetval)); 323 323 … … 326 326 327 327 328 List result = dbIntegrityService.getFilteredAnnotationIDs( word, "some html", 3, accessModes, null, after, before);328 List result = dbIntegrityService.getFilteredAnnotationIDs(null, word, "some html", 3, accessModes, null, after, before); 329 329 assertEquals(1, result.size()); 330 330 assertEquals(3, result.get(0)); … … 430 430 431 431 432 oneOf(annotationDao).getFilteredAnnotationIDs(mockAnnotationIDs1, text, null, after, before);432 oneOf(annotationDao).getFilteredAnnotationIDs(mockAnnotationIDs1, 4, text, null, after, before); 433 433 will(returnValue(mockAnnotIDs)); 434 434 … … 458 458 459 459 460 AnnotationInfoList result = dbIntegrityService.getFilteredAnnotationInfos( word, text, 3, accessModes, null, ownerUUID, after, before);460 AnnotationInfoList result = dbIntegrityService.getFilteredAnnotationInfos(ownerUUID, word, text, 3, accessModes, null, after, before); 461 461 assertEquals(1, result.getAnnotationInfo().size()); 462 462 AnnotationInfo resultAnnotInfo = result.getAnnotationInfo().get(0); … … 674 674 mockeryDao.checking(new Expectations() { 675 675 { 676 oneOf(annotationDao).addAnnotation(testAnnotation );676 oneOf(annotationDao).addAnnotation(testAnnotation, 5); 677 677 will(returnValue(6)); // the next free number is 6 678 678 … … 689 689 will(returnValue(1)); // the DB update will be called at perform anyway, even if the body is not changed (can be optimized) 690 690 691 oneOf(annotationDao).addAnnotationPrincipalPermission(6, 5, Permission.OWNER); 692 will(returnValue(1)); 691 693 692 } 694 693 }); -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/test/java/eu/dasish/annotation/backend/dao/impl/JdbcAnnotationDaoTest.java
r4406 r4429 104 104 System.out.println("test deleteAllAnnotationTargets"); 105 105 int result = jdbcAnnotationDao.deleteAnnotationPrincipalPermissions(2); 106 assertEquals( 3, result);106 assertEquals(2, result); 107 107 assertEquals(0, jdbcAnnotationDao.deleteAnnotationPrincipalPermissions(2)); 108 108 } … … 272 272 assertEquals(null, annotationToAdd.getLastModified()); 273 273 274 Number newAnnotationID = jdbcAnnotationDao.addAnnotation(annotationToAdd );274 Number newAnnotationID = jdbcAnnotationDao.addAnnotation(annotationToAdd, 5); 275 275 assertEquals(6, newAnnotationID); 276 276 … … 335 335 annotationIDs.add(3); 336 336 337 List<Number> result_1 = jdbcAnnotationDao.getFilteredAnnotationIDs(annotationIDs, null, null, null, null );337 List<Number> result_1 = jdbcAnnotationDao.getFilteredAnnotationIDs(annotationIDs, null, null, null, null, null); 338 338 assertEquals(2, result_1.size()); 339 339 assertEquals(2, result_1.get(0)); … … 341 341 342 342 343 List<Number> result_2 = jdbcAnnotationDao.getFilteredAnnotationIDs(annotationIDs, "some html", null, null, null);343 List<Number> result_2 = jdbcAnnotationDao.getFilteredAnnotationIDs(annotationIDs, null, "some html", null, null, null); 344 344 assertEquals(2, result_2.size()); 345 345 assertEquals(2, result_2.get(0)); … … 351 351 final String before = (new Timestamp(System.currentTimeMillis())).toString(); 352 352 353 List<Number> result_4 = jdbcAnnotationDao.getFilteredAnnotationIDs(annotationIDs, "some html", null, after, before); 354 assertEquals(2, result_4.size()); 355 assertEquals(2, result_4.get(0)); 356 assertEquals(3, result_2.get(1)); 353 List<Number> result_4 = jdbcAnnotationDao.getFilteredAnnotationIDs(annotationIDs, 4, "some html", null, after, before); 354 assertEquals(1, result_4.size()); 355 assertEquals(3, result_4.get(0)); 357 356 358 357 final String after_1 = (new Timestamp(System.currentTimeMillis())).toString();// no annotations added after "now" 359 List<Number> result_5 = jdbcAnnotationDao.getFilteredAnnotationIDs(annotationIDs, "some html", null, after_1, null);358 List<Number> result_5 = jdbcAnnotationDao.getFilteredAnnotationIDs(annotationIDs, 4, "some html", null, after_1, null); 360 359 assertEquals(0, result_5.size()); 361 360 … … 373 372 System.out.println("test Permissions"); 374 373 List<Map<Number, String>> result = jdbcAnnotationDao.getPermissions(2); 375 assertEquals(3, result.size()); 376 assertEquals("owner", result.get(0).get(3)); 377 assertEquals("writer", result.get(1).get(4)); 378 assertEquals("reader", result.get(2).get(5)); 374 assertEquals(2, result.size()); 375 assertEquals("writer", result.get(0).get(4)); 376 assertEquals("reader", result.get(1).get(5)); 379 377 380 378 -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/test/java/eu/dasish/annotation/backend/rest/AnnotationResourceTest.java
r4281 r4429 116 116 will(returnValue("developer")); 117 117 118 oneOf(mockDbIntegrityService).get Permission(2, 3);119 will(returnValue( Permission.OWNER));118 oneOf(mockDbIntegrityService).getAnnotationOwner(2); 119 will(returnValue(3)); 120 120 121 121 oneOf(mockDbIntegrityService).getAnnotation(2); … … 152 152 153 153 oneOf(mockDbIntegrityService).getUserInternalIDFromRemoteID("twan"); 154 will(returnValue( 3));154 will(returnValue(5)); 155 155 156 156 oneOf(mockDbIntegrityService).setServiceURI(with(any(String.class))); … … 161 161 162 162 163 oneOf(mockDbIntegrityService).get Permission(5, 3);164 will(returnValue( Permission.OWNER));163 oneOf(mockDbIntegrityService).getAnnotationOwner(5); 164 will(returnValue(5)); 165 165 166 166 oneOf(mockDbIntegrityService).deleteAnnotation(5); -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/test/java/eu/dasish/annotation/backend/rest/AnnotationsTest.java
r4276 r4429 161 161 assertEquals(testAnnotation.getHeadline(), entity.getHeadline()); 162 162 assertEquals(testAnnotation.getOwnerRef(), entity.getOwnerRef()); 163 assertEquals(3, entity.getPermissions().getUserWithPermission().size()); 164 assertEquals("owner", entity.getPermissions().getUserWithPermission().get(0).getPermission().value()); 165 assertEquals(resource().getURI()+"users/"+TestBackendConstants._TEST_USER_3_EXT_ID, entity.getPermissions().getUserWithPermission().get(0).getRef()); 166 assertEquals("writer", entity.getPermissions().getUserWithPermission().get(1).getPermission().value()); 167 assertEquals(resource().getURI()+"users/"+TestBackendConstants._TEST_USER_4_EXT_ID, entity.getPermissions().getUserWithPermission().get(1).getRef()); 168 assertEquals("reader", entity.getPermissions().getUserWithPermission().get(2).getPermission().value()); 169 assertEquals(resource().getURI()+"users/"+TestBackendConstants._TEST_USER_5_EXT_ID, entity.getPermissions().getUserWithPermission().get(2).getRef()); 163 assertEquals(2, entity.getPermissions().getUserWithPermission().size()); 164 assertEquals("writer", entity.getPermissions().getUserWithPermission().get(0).getPermission().value()); 165 assertEquals(resource().getURI()+"users/"+TestBackendConstants._TEST_USER_4_EXT_ID, entity.getPermissions().getUserWithPermission().get(0).getRef()); 166 assertEquals("reader", entity.getPermissions().getUserWithPermission().get(1).getPermission().value()); 167 assertEquals(resource().getURI()+"users/"+TestBackendConstants._TEST_USER_5_EXT_ID, entity.getPermissions().getUserWithPermission().get(1).getRef()); 170 168 assertEquals(2, entity.getTargets().getTargetInfo().size()); 171 169 assertEquals(resource().getURI().toString()+"targets/"+TestBackendConstants._TEST_Target_1_EXT_ID, entity.getTargets().getTargetInfo().get(0).getRef()); … … 233 231 assertEquals(annotationToAdd.getBody().getTextBody().getMimeType(), entityA.getBody().getTextBody().getMimeType()); 234 232 assertEquals(annotationToAdd.getHeadline(), entityA.getHeadline()); 235 assertEquals(1, entityA.getPermissions().getUserWithPermission().size()); 236 assertEquals("owner", entityA.getPermissions().getUserWithPermission().get(0).getPermission().value()); 237 assertEquals(annotationToAdd.getOwnerRef(), entityA.getPermissions().getUserWithPermission().get(0).getRef()); 233 assertEquals(0, entityA.getPermissions().getUserWithPermission().size()); 234 assertEquals(annotationToAdd.getOwnerRef(), entityA.getOwnerRef()); 238 235 assertEquals(annotationToAdd.getTargets().getTargetInfo().get(0).getLink(), entityA.getTargets().getTargetInfo().get(0).getLink()); 239 236 // new ref is generated -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/test/resources/test-data/InsertTestData.sql
r4276 r4429 27 27 -- INSERT INTO notebook (title, owner_id, external_id) VALUES ('a notebook', 1, 1); 28 28 29 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); --129 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); --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 ( 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); --251 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); --352 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); --453 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); --550 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); --2 51 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); --3 52 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); --4 53 INSERT INTO annotation (owner_id, headline,body_text, body_mimetype, external_id, is_xml) VALUES (5, 'Annotation to delete','<html><body>some html 4</body></html>', 'text/html' , '00000000-0000-0000-0000-000000000024',false); --5 54 54 55 55 … … 104 104 ---- PERMISSIONS -------------------------------------------------------------------------------------------- 105 105 106 INSERT INTO permission_(permission_mode) VALUES ('owner'); 106 107 107 INSERT INTO permission_(permission_mode) VALUES ('writer'); 108 108 INSERT INTO permission_(permission_mode) VALUES ('reader'); 109 109 110 INSERT INTO annotations_principals_permissions (annotation_id, principal_id, permission_) VALUES (2, 3, 'owner');111 110 INSERT INTO annotations_principals_permissions (annotation_id, principal_id, permission_) VALUES (2, 4, 'writer'); 112 111 INSERT INTO annotations_principals_permissions (annotation_id, principal_id, permission_) VALUES (2, 5, 'reader'); 113 112 114 INSERT INTO annotations_principals_permissions (annotation_id, principal_id, permission_) VALUES (3, 4, 'owner');115 113 INSERT INTO annotations_principals_permissions (annotation_id, principal_id, permission_) VALUES (3, 3, 'reader'); 116 114 INSERT INTO annotations_principals_permissions (annotation_id, principal_id, permission_) VALUES (3, 5, 'writer'); 117 115 118 INSERT INTO annotations_principals_permissions (annotation_id, principal_id, permission_) VALUES (4, 5, 'owner');119 116 INSERT INTO annotations_principals_permissions (annotation_id, principal_id, permission_) VALUES (4, 3, 'reader'); 120 117 INSERT INTO annotations_principals_permissions (annotation_id, principal_id, permission_) VALUES (4, 4, 'reader'); 121 118 122 INSERT INTO annotations_principals_permissions (annotation_id, principal_id, permission_) VALUES (5, 5, 'owner');123 119 INSERT INTO annotations_principals_permissions (annotation_id, principal_id, permission_) VALUES (5, 4, 'writer'); 124 120 INSERT INTO annotations_principals_permissions (annotation_id, principal_id, permission_) VALUES (5, 3, 'writer');
Note: See TracChangeset
for help on using the changeset viewer.