Changeset 3408
- Timestamp:
- 08/18/13 16:21:58 (11 years ago)
- Location:
- DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src
- Files:
-
- 5 deleted
- 17 edited
- 2 moved
Legend:
- Unmodified
- Added
- Removed
-
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/AnnotationDao.java
r3407 r3408 21 21 import eu.dasish.annotation.schema.Annotation; 22 22 import eu.dasish.annotation.schema.AnnotationInfo; 23 import eu.dasish.annotation.schema.Permission; 23 24 import eu.dasish.annotation.schema.ResourceREF; 25 import eu.dasish.annotation.schema.UserWithPermission; 24 26 import java.sql.SQLException; 25 27 import java.sql.Timestamp; … … 50 52 * @param annotationID 51 53 * @return the Annotation object with empty list of sources 52 * constructing a complete Annotation object from there sult and "retrieveSourceIDs" is done in "CompoundRequests"54 * constructing a complete Annotation object from there sult and "retrieveSourceIDs" is done in "DaoDispatchter" 53 55 * 54 56 */ … … 59 61 * 60 62 * @param annotationId 61 * @return 62 * result[0] = # removed "annotations_principals_perissions" rows 63 * result[1] = # removed "annotatiobs_target_sources" rows 64 * result[2] = # removed annotation rows (should be 1) 63 * @return removed annotation rows (should be 1) 65 64 */ 66 65 67 public int []deleteAnnotation(Number annotationId) throws SQLException;66 public int deleteAnnotation(Number annotationId) throws SQLException; 68 67 68 /** 69 * 70 * @param annotationId 71 * @return # removed annotation_source rows for given annotationID 72 */ 73 74 public int deleteAllAnnotationSource(Number annotationId) throws SQLException; 69 75 70 76 … … 131 137 public int addAnnotationSourcePair(Number annotationID, Number sourceID) throws SQLException; 132 138 139 public int deleteAnnotationPrincipalPermissions(Number annotationID) throws SQLException ; 140 141 /** 142 * 143 * @param annotationID 144 * @param userID 145 * @param permission 146 * @return the amount of rows added to the table annotations_principals_permissions 147 */ 148 public int addAnnotationPrincipalPermission(Number annotationID, Number userID, Permission permission) throws SQLException; 149 150 /** 151 * 152 * @param annotationId 153 * @return retrieves all the pairs (user-permission) for "annotationId" from the table annotations_principals permissions 154 */ 155 public List<Map<Number, String>> retrievePermissions(Number annotationId); 156 133 157 } -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/SourceDao.java
r3407 r3408 19 19 20 20 import eu.dasish.annotation.backend.identifiers.SourceIdentifier; 21 import eu.dasish.annotation.schema.NewOrExistingSourceInfo;22 21 import eu.dasish.annotation.schema.Source; 23 22 import eu.dasish.annotation.schema.SourceInfo; 24 23 import java.sql.SQLException; 25 24 import java.util.List; 26 import java.util.Map;27 25 28 26 /** … … 53 51 * 54 52 * @param internalId 55 * @return result[0] # deleted rows in "sources_versions" table name 56 * result[1] # deleted rows in "source" table 53 * @return # deleted rows in "source" table 57 54 */ 58 public int []deleteSource(Number internalID);55 public int deleteSource(Number internalID); 59 56 60 57 /** … … 69 66 70 67 public int addSourceVersion(Number sourceID, Number versionID) throws SQLException; 68 69 public int deleteAllSourceVersion(Number sourceID) throws SQLException; 70 71 71 72 72 -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/VersionDao.java
r3407 r3408 19 19 20 20 import eu.dasish.annotation.backend.identifiers.VersionIdentifier; 21 import eu.dasish.annotation.schema.CachedRepresentationInfo;22 21 import eu.dasish.annotation.schema.Version; 23 22 import java.util.List; … … 56 55 57 56 /** @param versionID 58 * @return 59 * result[0] # deleted rows in the joit table "versions_cached_representations" 60 * result[1] # deleted rows in "version" table 57 * @return deleted rows in "version" table 61 58 */ 62 59 63 public int []deleteVersion(Number versionID);60 public int deleteVersion(Number versionID); 64 61 65 62 /** … … 85 82 public int addVersionCachedRepresentation(Number versionID, Number cachedID); 86 83 84 public int deleteAllVersionCachedRepresentation(Number versionID); 85 86 // Not tested 87 public boolean versionIsInUse(Number versionsID); 87 88 } 88 89 -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/impl/JdbcAnnotationDao.java
r3407 r3408 23 23 import eu.dasish.annotation.schema.Annotation; 24 24 import eu.dasish.annotation.schema.AnnotationInfo; 25 import eu.dasish.annotation.schema.NewOrExistingSourceInfo; 26 import eu.dasish.annotation.schema.NewOrExistingSourceInfos; 25 import eu.dasish.annotation.schema.Permission; 27 26 import eu.dasish.annotation.schema.ResourceREF; 28 import eu.dasish.annotation.schema. SourceInfo;27 import eu.dasish.annotation.schema.UserWithPermission; 29 28 import java.lang.String; 30 29 import java.sql.ResultSet; … … 202 201 @Override 203 202 public Annotation mapRow(ResultSet rs, int rowNumber) throws SQLException { 204 205 Map<String, Object> result = new HashMap<String, Object>();206 207 203 Annotation annotation = new Annotation(); 208 204 … … 234 230 ////////////////////////////////////////////////////// 235 231 @Override 236 public int[] deleteAnnotation(Number annotationID) throws SQLException { 237 238 int[] result = new int[3]; 232 public int deleteAnnotation(Number annotationID) throws SQLException { 233 if (annotationIsInUse(annotationID)) { 234 return 0; 235 } 239 236 240 if (annotationIsInUse(annotationID)) { 241 result[0] =0; 242 result[1] =0; 243 result[2] =0; 244 return result; 245 } 246 247 String sqlPermissions = "DELETE FROM " + permissionsTableName + " where " + annotation_id + " = ?"; 248 result[0] = getSimpleJdbcTemplate().update(sqlPermissions, annotationID); // removed "permission" rows 249 237 String sqlAnnotation = "DELETE FROM " + annotationTableName + " where " + annotation_id + " = ?"; 238 return (getSimpleJdbcTemplate().update(sqlAnnotation, annotationID)); 239 } 240 241 ////////////////////////////////////////////////////// 242 @Override 243 public int deleteAllAnnotationSource(Number annotationID) throws SQLException { 250 244 String sqlTargetSources = "DELETE FROM " + annotationsSourcesTableName + " where " + annotation_id + " = ?"; 251 re sult[1] =getSimpleJdbcTemplate().update(sqlTargetSources, annotationID); // removed "annotations_target_sources" rows245 return getSimpleJdbcTemplate().update(sqlTargetSources, annotationID); // removed "annotations_target_sources" rows 252 246 253 String sqlAnnotation = "DELETE FROM " + annotationTableName + " where " + annotation_id + " = ?"; 254 result[2] = getSimpleJdbcTemplate().update(sqlAnnotation, annotationID); // removed annotations rows 255 256 return result; 257 } 247 } 248 258 249 259 250 // TODO: so far URI in the xml is the same as the external_id in the DB!! … … 295 286 } 296 287 297 /////////////////////////////////////////////////////////// 298 private ResourceREF getResourceREF(String resourceID) { 299 ResourceREF result = new ResourceREF(); 300 result.setRef(resourceID); 301 return result; 302 } 288 303 289 304 290 … … 317 303 /////////////// helpers ////////////////// 318 304 305 /////////////////////////////////////////////////////////// 306 private ResourceREF getResourceREF(String resourceID) { 307 ResourceREF result = new ResourceREF(); 308 result.setRef(resourceID); 309 return result; 310 } 311 319 312 ////////////////////////////// 320 313 private boolean annotationIsInUse(Number sourceID) { … … 334 327 }; 335 328 329 ////////////////////////////////////////////////////// 330 @Override 331 public int deleteAnnotationPrincipalPermissions(Number annotationID) throws SQLException { 332 String sqlPermissions = "DELETE FROM " + permissionsTableName + " where " + annotation_id + " = ?"; 333 return getSimpleJdbcTemplate().update(sqlPermissions, annotationID); // removed "permission" rows 334 335 } 336 337 ///////////////////////////////////////////////////////////////////////////////////////// 338 @Override 339 public int addAnnotationPrincipalPermission(Number annotationID, Number userID, Permission permission) throws SQLException { 340 Map<String, Object> paramsPermissions = new HashMap<String, Object>(); 341 paramsPermissions.put("annotationId", annotationID); 342 paramsPermissions.put("principalId", userID); 343 paramsPermissions.put("status", permission.value()); 344 String sqlUpdatePermissionTable = "INSERT INTO " + permissionsTableName + " (" + annotation_id + "," + principal_id + "," + permission + ") VALUES (:annotationId, :principalId, :status)"; 345 final int affectedPermissions = getSimpleJdbcTemplate().update(sqlUpdatePermissionTable, paramsPermissions); 346 return affectedPermissions; 347 } 348 349 350 /////////////////////////////////////////////////////////////////// 351 @Override 352 public List<Map<Number, String>> retrievePermissions(Number annotationId) { 353 if (annotationId == null) { 354 return null; 355 } 356 String sql = "SELECT " + principal_id + "," + permission + " FROM " + permissionsTableName + " WHERE " + annotation_id + " = ?"; 357 List<Map<Number, String>> result = getSimpleJdbcTemplate().query(sql, principalsPermissionsRowMapper, annotationId.toString()); 358 return result; 359 } 360 private final RowMapper<Map<Number, String>> principalsPermissionsRowMapper = new RowMapper<Map<Number, String>>() { 361 @Override 362 public Map<Number, String> mapRow(ResultSet rs, int rowNumber) throws SQLException { 363 Map<Number,String> result = new HashMap<Number, String>(); 364 result.put(rs.getInt(principal_id),rs.getString(permission)); 365 return result; 366 } 367 }; 368 336 369 } -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/impl/JdbcCachedRepresentationDao.java
r3407 r3408 102 102 @Override 103 103 public int deleteCachedRepresentationInfo(Number internalID) { 104 // ask the higher level if it can be deleted105 104 if (cachedIsInUse(internalID)){ 106 105 return 0; -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/impl/JdbcResourceDao.java
r3395 r3408 23 23 import java.sql.ResultSet; 24 24 import java.sql.SQLException; 25 import java.util.ArrayList;26 25 import java.util.List; 27 26 import javax.xml.datatype.DatatypeConfigurationException; -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/impl/JdbcSourceDao.java
r3407 r3408 76 76 }; 77 77 78 79 /////////////////////////////////////////////////////////////////// 80 @Override 81 public int[] deleteSource(Number internalID) { 82 int[] result = new int[2]; 78 /////////////////////////////////////////////////////////////////// 79 @Override 80 public int deleteSource(Number internalID) { 83 81 if (sourceIsInUse(internalID)){ 84 result[0] =0; 85 result[1] =0; 86 return result; 87 } 88 82 return 0; 83 } 84 String sqlSourcesVersions = "DELETE FROM " + sourceTableName + " WHERE " + source_id + " = ? LIMIT 1"; 85 int result = getSimpleJdbcTemplate().update(sqlSourcesVersions, internalID); 86 return result; 87 88 } 89 90 91 /////////////////////////////////////////////////////////////////// 92 @Override 93 public int deleteAllSourceVersion(Number internalID) { 89 94 String sqlSourcesVersions = "DELETE FROM " + sourcesVersionsTableName + " WHERE " + source_id + " = ?"; 90 result[0] = getSimpleJdbcTemplate().update(sqlSourcesVersions, internalID); 91 92 String sql = "DELETE FROM " + sourceTableName + " WHERE " + source_id + " = ?"; 93 result[1] = getSimpleJdbcTemplate().update(sql, internalID); 94 95 int result = getSimpleJdbcTemplate().update(sqlSourcesVersions, internalID); 95 96 return result; 96 97 -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/impl/JdbcVersionDao.java
r3407 r3408 103 103 ///////////////////////////////////////// 104 104 @Override 105 public int []deleteVersion(Number internalID) {105 public int deleteVersion(Number internalID) { 106 106 107 int [] result = new int[2];107 int result = 0; 108 108 if (versionIsInUse(internalID)) { 109 // firs delete sources that refer to it!110 result[0]=0;111 result[1]=0;112 109 return result; 113 110 } 114 111 115 // remove all the pairs (internalID, cached_representation) from the joint table "versions_cahched_representations"116 String sqlVersionsCachedRepresentations = "DELETE FROM " + versionsCachedRepresentationsTableName + " where " + version_id + " = ?";117 result[0] = getSimpleJdbcTemplate().update(sqlVersionsCachedRepresentations, internalID);118 119 // the main action: remove the version with internalID from "version" table120 112 String sql = "DELETE FROM " + versionTableName + " where " + version_id + " = ?"; 121 result [1]= getSimpleJdbcTemplate().update(sql, internalID);113 result = getSimpleJdbcTemplate().update(sql, internalID); 122 114 return result; 123 115 … … 150 142 return (getSimpleJdbcTemplate().update(sql.toString(), params)); 151 143 } 144 145 //////////////////////////////////////////// 146 @Override 147 public int deleteAllVersionCachedRepresentation(Number versionID){ 148 StringBuilder sql = new StringBuilder("DELETE FROM "); 149 sql.append(versionsCachedRepresentationsTableName).append(" WHERE ").append(version_id).append(" = ?"); 150 return (getSimpleJdbcTemplate().update(sql.toString(), versionID)); 151 } 152 152 153 153 //////////////////////////////////////////// … … 166 166 167 167 168 ///////////////////// PRIVATE ////////////////////////////// 169 170 private boolean versionIsInUse(Number versionsID) { 168 @Override 169 public boolean versionIsInUse(Number versionsID) { 171 170 String sql = "SELECT " + source_id + " FROM " + sourcesVersionsTableName + " WHERE " + version_id + "= ? LIMIT 1"; 172 171 List<Number> result = getSimpleJdbcTemplate().query(sql, sourceIDRowMapper, versionsID); -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/integration/DaoDispatcher.java
r3407 r3408 22 22 import eu.dasish.annotation.backend.dao.CachedRepresentationDao; 23 23 import eu.dasish.annotation.backend.dao.NotebookDao; 24 import eu.dasish.annotation.backend.dao.PermissionsDao;25 24 import eu.dasish.annotation.backend.dao.SourceDao; 26 25 import eu.dasish.annotation.backend.dao.UserDao; … … 49 48 * @author olhsha 50 49 */ 51 public class Dao Requestor {50 public class DaoDispatcher { 52 51 53 52 @Autowired 54 53 UserDao userDao; 55 54 @Autowired 56 PermissionsDao permissionsDao;57 @Autowired58 55 CachedRepresentationDao cachedRepresentationDao; 59 56 @Autowired … … 65 62 @Autowired 66 63 NotebookDao notebookDao; 67 68 69 70 public Number getAnnotationInternalIdentifier(AnnotationIdentifier annotationIdentifier){ 64 65 public Number getAnnotationInternalIdentifier(AnnotationIdentifier annotationIdentifier) { 71 66 return annotationDao.getInternalID(annotationIdentifier); 72 67 } 73 74 public AnnotationIdentifier getAnnotationExternalIdentifier(Number annotationID){68 69 public AnnotationIdentifier getAnnotationExternalIdentifier(Number annotationID) { 75 70 return annotationDao.getExternalID(annotationID); 76 71 } 77 72 78 public Number getUserInternalIdentifier(UserIdentifier userIdentifier){73 public Number getUserInternalIdentifier(UserIdentifier userIdentifier) { 79 74 return userDao.getInternalID(userIdentifier); 80 75 } 81 82 public UserIdentifier getUserExternalIdentifier(Number userID){76 77 public UserIdentifier getUserExternalIdentifier(Number userID) { 83 78 return userDao.getExternalID(userID); 84 } 85 79 } 80 86 81 /** 87 82 * … … 121 116 return result; 122 117 } 123 124 /** 125 * 118 119 /** 120 * 126 121 * @param versionID 127 * @return 128 * result[0] # deleted rows in the joit table "versions_cached_representations" 129 * result[1] # deleted rows in "version" table 130 * result[2] # deleted cached representations (which are not referred by other versions) 131 * 132 */ 133 122 * @return result[0] # deleted rows in "version" table result[1] # deleted 123 * rows in the joint table "versions_cached_representations" result[2] # 124 * deleted cached representations (which are not referred by other versions) 125 * 126 */ 134 127 public int[] deleteVersionWithCachedRepresentations(Number versionID) { 135 128 int[] result = new int[3]; 136 List<Number> cachedRepresentations = versionDao.retrieveCachedRepresentationList(versionID); 137 int[] deleteVersion = versionDao.deleteVersion(versionID); 138 result[0] = deleteVersion[0]; 139 result[1] = deleteVersion[1]; 129 if (!versionDao.versionIsInUse(versionID)) { 130 List<Number> cachedRepresentations = versionDao.retrieveCachedRepresentationList(versionID); 131 result[1] = versionDao.deleteAllVersionCachedRepresentation(versionID); 132 result[0] = versionDao.deleteVersion(versionID); 133 result[2] = 0; 134 for (Number cachedID : cachedRepresentations) { 135 result[2] = result[2] + cachedRepresentationDao.deleteCachedRepresentationInfo(cachedID); 136 137 } 138 } else { 139 result[0] = 0; 140 result[1] = 0; 141 result[2] = 0; 142 } 143 return result; 144 } 145 146 /** 147 * 148 * @param sourceID 149 * @return result[0] # deleted rows in "source" table result[1] # deleted 150 * rows in "sources_versions" table name result[2] # deleted rows in 151 * "version" table 152 */ 153 public int[] deleteSourceWithVersions(Number sourceID) throws SQLException { 154 int[] result = new int[3]; 155 List<Number> versions = sourceDao.retrieveVersionList(sourceID); 156 result[1] = sourceDao.deleteAllSourceVersion(sourceID); 157 result[0] = sourceDao.deleteSource(sourceID); 140 158 result[3] = 0; 141 for (Number cachedID : cachedRepresentations) {142 result[3] = result[3] + cachedRepresentationDao.deleteCachedRepresentationInfo(cachedID);143 144 }145 return result;146 }147 148 /**149 *150 * @param sourceID151 * @return result[0] # deleted rows in "sources_versions" table name152 * result[1] # deleted rows in "source" table153 * result[2] # deleted rows in "version" table (not used by the other sources)154 */155 public int[] deleteSourceWithVersions(Number sourceID){156 int[] result = new int[3];157 List<Number> versions = sourceDao.retrieveVersionList(sourceID);158 int[] deleteSource = sourceDao.deleteSource(sourceID);159 result[0] = deleteSource[0];160 result[1]=deleteSource[1];161 result[3] =0;162 159 for (Number versionID : versions) { 163 160 int[] deleteVersion = deleteVersionWithCachedRepresentations(versionID); 164 result[3] =result[3]+deleteVersion[1];165 } 166 return result;167 168 } 169 161 result[3] = result[3] + deleteVersion[1]; 162 } 163 return result; 164 165 } 166 170 167 /** 171 168 * @param source 172 * @return internal Id of the newly added source or -1 if the source is not added because no version for it; 173 * in the last case the rest-interface will return envelope asking to add a version (with the cached representation); 174 * after the clinet adds the version (s)he gets the version external ID which is to be set in source; 175 * the the client asks to add the source again. 176 * @throws SQLException 177 */ 178 public Number addSourceAndPairSourceVersion(NewSourceInfo newSource) throws SQLException{ 169 * @return internal Id of the newly added source or -1 if the source is not 170 * added because no version for it; in the last case the rest-interface will 171 * return envelope asking to add a version (with the cached representation); 172 * after the clinet adds the version (s)he gets the version external ID 173 * which is to be set in source; the the client asks to add the source 174 * again. 175 * @throws SQLException 176 */ 177 public Number addSourceAndPairSourceVersion(NewSourceInfo newSource) throws SQLException { 179 178 Number versionID = versionDao.getInternalID(new VersionIdentifier(newSource.getVersion())); 180 179 if (versionID == null) { … … 186 185 source.setURI(externalIdentifier.toString()); 187 186 source.setLink(newSource.getLink()); 188 source.setVersion(newSource.getVersion()); 187 source.setVersion(newSource.getVersion()); 189 188 Number result = sourceDao.addSource(source); 190 189 final int sourceVersions = sourceDao.addSourceVersion(result, versionID); 191 190 return result; 192 191 } 193 194 195 192 196 193 /////////////////////////////////////////////// 197 198 /** 199 * 194 /** 195 * 200 196 * @param annotationID 201 197 * @param sources 202 * @return the mapping temporarySourceID -> peristenExternalSOurceId 203 * adds a source from "sources" to the DB if it is not there, to the table "target_source" 204 * adds the wro (annotationID, sourceID) to the joint table "annotations_sources" 205 * @throws SQLException 198 * @return the mapping temporarySourceID -> peristenExternalSOurceId adds a 199 * source from "sources" to the DB if it is not there, to the table 200 * "target_source" adds the wro (annotationID, sourceID) to the joint table 201 * "annotations_sources" 202 * @throws SQLException 206 203 */ 207 204 public Map<String, String> addTargetSourcesToAnnotation(Number annotationID, List<NewOrExistingSourceInfo> sources) throws SQLException { … … 222 219 } 223 220 return result; 224 } 225 226 227 //////////////////////////////////////////////////////////////////////// 228 221 } 222 223 //////////////////////////////////////////////////////////////////////// 229 224 public List<Number> getFilteredAnnotationIDs(String link, String text, String access, String namespace, UserIdentifier owner, Timestamp after, Timestamp before) { 230 225 231 226 List<Number> annotationIDs = null; 232 227 233 228 if (link != null) { 234 229 List<Number> sourceIDs = sourceDao.getSourcesForLink(link); 235 230 annotationIDs = annotationDao.retrieveAnnotationList(sourceIDs); 236 231 } 237 238 Number ownerID = null;232 233 Number ownerID = null; 239 234 if (owner != null) { 240 235 ownerID = userDao.getInternalID(owner); … … 244 239 } 245 240 246 247 * 241 /** 242 * 248 243 * @param annotationId 249 * @return 250 * result[0] = # removed "annotations_principals_permissions" rows 251 * result[1] = # removed "annotations_target_sources" rows 252 * result[2] = # removed annotation rows (should be 1) 253 * result[3] = # deleted sources 254 */ 255 public int[] deleteAnnotationWithSources(Number annotationID) throws SQLException { 244 * @return result[0] = # removed annotation rows (should be 1) result[1] = # 245 * removed "annotations_principals_permissions" rows result[2] = # removed 246 * "annotations_target_sources" rows result[3] = # deleted sources 247 */ 248 public int[] deleteAnnotationWithSourcesAndPermissions(Number annotationID) throws SQLException { 256 249 int[] result = new int[4]; 257 List<Number> sourceIDs = annotationDao.retrieveSourceIDs(annotationID); 258 int[] deleteAnnotation = annotationDao.deleteAnnotation(annotationID); 259 result[0]= deleteAnnotation[0]; 260 result[1]= deleteAnnotation[1]; 261 result[2] = deleteAnnotation[2]; 262 result[3]=0; 250 result[1] = annotationDao.deleteAnnotationPrincipalPermissions(annotationID); 251 List<Number> sourceIDs = annotationDao.retrieveSourceIDs(annotationID); 252 result[2] = annotationDao.deleteAllAnnotationSource(annotationID); 253 result[0] = annotationDao.deleteAnnotation(annotationID); 254 result[3] = 0; 263 255 for (Number sourceID : sourceIDs) { 264 256 int[] deleteSource = deleteSourceWithVersions(sourceID); … … 267 259 return result; 268 260 } 269 270 271 public Annotation getAnnotation(Number annotationID) throws SQLException{ 261 262 public Annotation getAnnotation(Number annotationID) throws SQLException { 272 263 Annotation result = annotationDao.getAnnotationWithoutSources(annotationID); 273 264 List<Number> sourceIDs = annotationDao.retrieveSourceIDs(annotationID); 274 265 for (Number sourceID : sourceIDs) { 275 NewOrExistingSourceInfo noesi = new 266 NewOrExistingSourceInfo noesi = new NewOrExistingSourceInfo(); 276 267 Source source = sourceDao.getSource(sourceID); 277 268 SourceInfo sourceInfo = new SourceInfo(); … … 284 275 return result; 285 276 } 286 287 277 288 278 //need to return an envelope! 289 public Annotation addAnnotationWithTargetSources(Annotation annotation, Number userID) throws SQLException {290 279 public Annotation addAnnotationWithTargetSources(Annotation annotation, Number userID) throws SQLException { 280 291 281 Number annotationID = annotationDao.addAnnotation(annotation, userID); 292 282 293 283 List<NewOrExistingSourceInfo> sources = annotation.getTargetSources().getTarget(); 294 Map<String, String> sourceIdPairs = addTargetSourcesToAnnotation(annotationID, sources);295 296 if (sourceIdPairs.containsValue(null)) {297 // for one of the soirces there was no version and cached representation284 Map<String, String> sourceIdPairs = addTargetSourcesToAnnotation(annotationID, sources); 285 286 if (sourceIdPairs.containsValue(null)) { 287 // for one of the soirces there was no version and cached representation 298 288 // envelope 299 return annotation;289 return annotation; 300 290 } 301 291 String body = Helpers.serializeBody(annotation.getBody()); 302 292 String newBody = Helpers.replace(body, sourceIdPairs); 303 293 int affectedAnnotRows = annotationDao.updateBody(annotationID, newBody); 304 294 305 295 // Add the permission (annotation_id, owner); 306 int affectedPermissions = permissionsDao.addAnnotationPrincipalPermission(annotationID, userID, Permission.OWNER);307 296 int affectedPermissions = annotationDao.addAnnotationPrincipalPermission(annotationID, userID, Permission.OWNER); 297 308 298 Annotation newAnnotation = getAnnotation(annotationID); 309 299 return newAnnotation; 310 300 } 311 312 } 301 } -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/rest/AnnotationResource.java
r3407 r3408 19 19 20 20 import eu.dasish.annotation.backend.BackendConstants; 21 import eu.dasish.annotation.backend.dao.integration.Dao Requestor;21 import eu.dasish.annotation.backend.dao.integration.DaoDispatcher; 22 22 import eu.dasish.annotation.backend.identifiers.AnnotationIdentifier; 23 23 import eu.dasish.annotation.backend.identifiers.UserIdentifier; … … 46 46 public class AnnotationResource { 47 47 48 private Dao Requestor requestor;48 private DaoDispatcher requestor; 49 49 @Context 50 50 private HttpServletRequest httpServletRequest; … … 72 72 public String deleteAnnotation(@PathParam("annotationid") String annotationIdentifier) throws SQLException { 73 73 final Number annotationID = requestor.getAnnotationInternalIdentifier(new AnnotationIdentifier(annotationIdentifier)); 74 int[] resultDelete = requestor.deleteAnnotationWithSources (annotationID);75 String result = Integer.toString(resultDelete[ 4]);74 int[] resultDelete = requestor.deleteAnnotationWithSourcesAndPermissions(annotationID); 75 String result = Integer.toString(resultDelete[0]); 76 76 return result; 77 77 } -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/test/java/eu/dasish/annotation/backend/MockObjectsFactory.java
r3221 r3408 21 21 import eu.dasish.annotation.backend.dao.CachedRepresentationDao; 22 22 import eu.dasish.annotation.backend.dao.NotebookDao; 23 import eu.dasish.annotation.backend.dao.PermissionsDao;24 23 import eu.dasish.annotation.backend.dao.SourceDao; 25 24 import eu.dasish.annotation.backend.dao.UserDao; … … 52 51 } 53 52 54 public PermissionsDao newPermissionsDao() { 55 return context.mock(PermissionsDao.class); 56 } 57 53 58 54 public SourceDao newSourceDao() { 59 55 return context.mock(SourceDao.class); -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/test/java/eu/dasish/annotation/backend/dao/impl/JdbcAnnotationDaoTest.java
r3407 r3408 18 18 package eu.dasish.annotation.backend.dao.impl; 19 19 20 import eu.dasish.annotation.backend.Helpers; 20 21 import eu.dasish.annotation.backend.TestBackendConstants; 21 22 import eu.dasish.annotation.backend.TestInstances; 22 23 import eu.dasish.annotation.backend.identifiers.AnnotationIdentifier; 23 import eu.dasish.annotation.backend.identifiers.UserIdentifier;24 24 import eu.dasish.annotation.schema.Annotation; 25 25 import eu.dasish.annotation.schema.AnnotationInfo; 26 import eu.dasish.annotation.schema.NewOrExistingSourceInfo; 27 import eu.dasish.annotation.schema.NewOrExistingSourceInfos; 26 import eu.dasish.annotation.schema.Permission; 28 27 import eu.dasish.annotation.schema.ResourceREF; 29 import eu.dasish.annotation.schema.SourceInfo;30 28 import java.sql.SQLException; 31 29 import java.sql.Timestamp; … … 33 31 import java.util.List; 34 32 import java.util.Map; 35 import org.jmock.Expectations;36 33 import static org.junit.Assert.*; 37 34 import org.junit.Test; … … 53 50 TestInstances testInstances = new TestInstances(); 54 51 55 /**56 * Test of getAnnotationInfos method, of class JdbcAnnotationDao.57 * List<AnnotationInfo> getAnnotationInfos(List<Number> annotationIDs)58 */59 52 60 53 /** 61 * Test of retrieveSourceIDs method, of class Jdbc SourceDao.54 * Test of retrieveSourceIDs method, of class JdbcAnnotationDao. 62 55 */ 63 56 @Test … … 71 64 } 72 65 66 /////////////////////////////////////////// 67 @Test 68 public void testDeleteAllAnnotationSource() throws SQLException{ 69 System.out.println("test deleteAllAnnotationSources"); 70 assertEquals(2, jdbcAnnotationDao.deleteAllAnnotationSource(2)); 71 assertEquals(0, jdbcAnnotationDao.deleteAllAnnotationSource(2)); 72 } 73 74 /////////////////////////////////////////// 75 @Test 76 public void testDeleteAnnotationPrinciplePermissions() throws SQLException{ 77 System.out.println("test deleteAllAnnotationSources"); 78 int result = jdbcAnnotationDao.deleteAnnotationPrincipalPermissions(2); 79 assertEquals(3, result); 80 assertEquals(0, jdbcAnnotationDao.deleteAnnotationPrincipalPermissions(2)); 81 } 82 83 /////////////////////////////////////////// 84 @Test 85 public void testAddAnnotationPrinciplePermission() throws SQLException{ 86 System.out.println("test addAnnotationSources"); 87 int result = jdbcAnnotationDao.addAnnotationPrincipalPermission(2, 1, Permission.READER); 88 assertEquals(1, result); 89 } 90 91 /////////////////////////////////////////// 92 @Test 93 public void testAddAnnotationSourcePair() throws SQLException{ 94 System.out.println("test addAnnotationSourcePair"); 95 assertEquals(1, jdbcAnnotationDao.addAnnotationSourcePair(1,2)); 96 } 97 98 //////////////////////////////// 99 73 100 @Test 74 101 public void testGetAnnotationInfos() { … … 150 177 /** 151 178 * 152 * Test of getAnnotation method, of class JdbcAnnotationDao. Annotation179 * Test of getAnnotationWithoutSources method, of class JdbcAnnotationDao. Annotation 153 180 * getAnnotation(Number annotationlID) 154 181 */ 155 182 @Test 156 public void getAnnotation () throws SQLException {157 System.out.println("test getAnnotation ");183 public void getAnnotationWithoutSources() throws SQLException { 184 System.out.println("test getAnnotationWithoutSources"); 158 185 159 186 /// dummy test … … 174 201 * Test of deletAnnotation method, of class JdbcAnnotationDao. 175 202 */ 203 /** 204 * 205 * @param annotationId 206 * @return removed annotation rows (should be 1) 207 */ 176 208 @Test 177 209 public void testDeleteAnnotation() throws SQLException { 178 210 System.out.println("deleteAnnotation"); 179 // result[0] = # removed "annotations_principals_perissions" rows 180 // result[1] = # removed "annotatiobs_target_sources" rows 181 // result[2] = # removed annotation rows (should be 1) 182 183 int[] result = jdbcAnnotationDao.deleteAnnotation(5); 184 assertEquals(3, result[0]); 185 assertEquals(2, result[1]); 186 assertEquals(1, result[2]); 187 188 // now, try to delete the same annotation one more time 189 // if it has been already deleted then the method under testing should return 0 190 191 result = jdbcAnnotationDao.deleteAnnotation(5); 192 assertEquals(0, result[0]); 193 assertEquals(0, result[1]); 194 assertEquals(0, result[2]); 211 212 // to provide integrity, first delete rows in the joint tables 213 jdbcAnnotationDao.deleteAllAnnotationSource(5); 214 jdbcAnnotationDao.deleteAnnotationPrincipalPermissions(5); 215 216 assertEquals(1, jdbcAnnotationDao.deleteAnnotation(5)); 217 assertEquals(0, jdbcAnnotationDao.deleteAnnotation(5)); 195 218 } 196 219 … … 219 242 220 243 221 222 // NewOrExistingSourceInfo noesi = new NewOrExistingSourceInfo(); 223 // NewSourceInfo nsi = new NewSourceInfo(); 224 // nsi.setLink(TestBackendConstants._TEST_NEW_SOURCE_LINK); 225 // nsi.setId(TestBackendConstants._TEST_TEMP_SOURCE_ID); 226 // nsi.setVersion(null); 227 // noesi.setNewSource(nsi); 228 // 229 // 230 // NewOrExistingSourceInfo noesiTwo = new NewOrExistingSourceInfo(); 231 // SourceInfo si = new SourceInfo(); 232 // si.setLink(TestBackendConstants._TEST_NEW_SOURCE_LINK); 233 // si.setRef((new SourceIdentifier()).toString()); 234 // si.setVersion(null); 235 // noesiTwo.setSource(si); 236 // 237 // final Map<NewOrExistingSourceInfo, NewOrExistingSourceInfo> map = new HashMap<NewOrExistingSourceInfo, NewOrExistingSourceInfo>(); 238 // map.put(noesi, noesiTwo); 239 // 240 // 241 // mockery.checking(new Expectations() { 242 // { 243 // oneOf(sourceDao).addTargetSources(with(aNonNull(Number.class)), with(aNonNull(List.class))); 244 // will(returnValue(map)); 245 // } 246 // }); 247 248 249 /** 250 * testing public List<Number> getAnnotationIDsForSources(List<Number> sourceIDs); 244 /** 245 * testing public List<Number> retrieveAnnotationList(List<Number> sourceIDs); 251 246 252 247 **/ 253 248 @Test 254 public void test GetAnnotationIDsForSources() {255 System.out.println("test getAnnotationIDs for sources");249 public void testRetrieveAnnotationList() { 250 System.out.println("test retrieveAnnotationlist"); 256 251 List<Number> sources = new ArrayList<Number>(); 257 252 sources.add(1); … … 263 258 } 264 259 260 ////////////////////////////////// 261 262 265 263 @Test 266 264 public void testGetExternalID() { … … 320 318 Timestamp after_1 = new Timestamp(System.currentTimeMillis()); 321 319 List<Number> result_5 = jdbcAnnotationDao.getFilteredAnnotationIDs(annotationIDs, "some html", null, null, 1, after_1, null); 322 assertEquals(0, result_5.size()); 323 324 325 } 326 327 /** 328 * Test of contructNewOrExistingSourceInfo method, of class JdbcSourceDao. 329 */ 330 @Test 331 public void testContructNewOrExistingSourceInfo() { 332 System.out.println("contructNewOrExistingSourceInfo"); 333 334 List<SourceInfo> sourceInfoList = new ArrayList<SourceInfo>(); 335 336 SourceInfo sourceInfoOne = new SourceInfo(); 337 sourceInfoOne.setLink(TestBackendConstants._TEST_SOURCE_1_LINK); 338 sourceInfoOne.setRef(TestBackendConstants._TEST_SOURCE_1_EXT_ID); 339 sourceInfoOne.setRef(TestBackendConstants._TEST_VERSION_1_EXT_ID); 340 341 SourceInfo sourceInfoTwo = new SourceInfo(); 342 sourceInfoTwo.setLink(TestBackendConstants._TEST_SOURCE_2_LINK); 343 sourceInfoTwo.setRef(TestBackendConstants._TEST_SOURCE_2_EXT_ID); 344 sourceInfoTwo.setRef(TestBackendConstants._TEST_VERSION_3_EXT_ID); 345 346 sourceInfoList.add(sourceInfoOne); 347 sourceInfoList.add(sourceInfoTwo); 348 349 // NewOrExistingSourceInfos result = jdbcSourceDao.contructNewOrExistingSourceInfo(sourceInfoList); 350 // assertEquals(2, result.getTarget().size()); 351 // assertEquals(sourceInfoOne, result.getTarget().get(0).getSource()); 352 // assertEquals(sourceInfoTwo, result.getTarget().get(1).getSource()); 353 354 } 355 356 // /** 357 // * Test of addTargetSources method, of class JdbcSourceDao. public 358 // * Map<NewOrExistingSourceInfo, NewOrExistingSourceInfo> 359 // * addTargetSources(Number annotationID, List<NewOrExistingSourceInfo> 360 // * sources) 361 // */ 362 // @Test 363 // public void testAddTargetSourcesOnExistingSource() { 364 // System.out.println("addTargetSources : adding the old source"); 365 // 366 // NewOrExistingSourceInfo noesi = new NewOrExistingSourceInfo(); 367 // SourceInfo si = new SourceInfo(); 368 // si.setLink(TestBackendConstants._TEST_SOURCE_1_LINK); 369 // si.setRef(TestBackendConstants._TEST_SOURCE_1_EXT_ID); 370 // si.setVersion(TestBackendConstants._TEST_VERSION_1_EXT_ID); 371 // noesi.setSource(si); 372 // 373 // List<NewOrExistingSourceInfo> listnoesi = new ArrayList<NewOrExistingSourceInfo>(); 374 // listnoesi.add(noesi); 375 // 376 // try { 377 // Map<String, String> result = jdbcSourceDao.addTargetSources(5, listnoesi); 378 // assertEquals(0, result.size()); // no new peristsent source IDs are produced 379 // } catch (SQLException e) { 380 // System.out.println(e); 381 // } 382 // } 383 // 384 // /** 385 // * Test of addTargetSources method, of class JdbcSourceDao. public 386 // * Map<NewOrExistingSourceInfo, NewOrExistingSourceInfo> 387 // * addTargetSources(Number annotationID, List<NewOrExistingSourceInfo> 388 // * sources) 389 // */ 390 // @Test 391 // public void testAddTargetSourcesOnNewSource() { 392 // System.out.println("addTargetSources : adding the new source"); 393 // 394 // NewOrExistingSourceInfo noesi = new NewOrExistingSourceInfo(); 395 // NewSourceInfo nsi = new NewSourceInfo(); 396 // nsi.setLink(TestBackendConstants._TEST_NEW_SOURCE_LINK); 397 // nsi.setId(TestBackendConstants._TEST_TEMP_SOURCE_ID); 398 // nsi.setVersion(TestBackendConstants._TEST_VERSION_1_EXT_ID); 399 // noesi.setNewSource(nsi); 400 // 401 // List<NewOrExistingSourceInfo> listnoesiTwo = new ArrayList<NewOrExistingSourceInfo>(); 402 // listnoesiTwo.add(noesi); 403 // 404 // mockery.checking(new Expectations() { 405 // { 406 // oneOf(versionDao).getInternalID(new VersionIdentifier(TestBackendConstants._TEST_VERSION_1_EXT_ID)); 407 // will(returnValue(1)); 408 // } 409 // }); 410 // 411 // try { 412 // Map<String, String> result = jdbcSourceDao.addTargetSources(5, listnoesiTwo); 413 // assertEquals(1, result.size());// a new identifier must be produced 414 // SourceIdentifier sourceIdentifier = new SourceIdentifier(result.get(TestBackendConstants._TEST_TEMP_SOURCE_ID)); 415 // assertFalse(null == sourceIdentifier.getUUID()); // check if a proper uuid has been assigned 416 // } catch (SQLException e) { 417 // System.out.print(e); 418 // } 419 // 420 // } 421 // 320 assertEquals(1, result_5.size()); 321 322 323 } 324 325 ////////////////////////////////// 326 @Test 327 public void testUpdateBody() throws SQLException{ 328 System.out.println("test UpdateAnnotationBody"); 329 String serializedNewBody = "new body"; 330 int result = jdbcAnnotationDao.updateBody(2, serializedNewBody); 331 assertEquals(1, result); 332 Annotation updatedAnnotation= jdbcAnnotationDao.getAnnotationWithoutSources(2); 333 assertEquals(serializedNewBody, Helpers.serializeBody(updatedAnnotation.getBody())); 334 } 335 336 337 // public List<Map<Number, String>> retrievePermissions(Number annotationId) 338 339 @Test 340 public void testRetrievePermissions (){ 341 // VALUES (2, 3, 'owner'); 342 //VALUES (2, 4, 'writer'); 343 //VALUES (2, 5, 'reader'); 344 System.out.println("test Permissions"); 345 List<Map<Number, String>> result = jdbcAnnotationDao.retrievePermissions(2); 346 assertEquals(2, result.size()); 347 assertEquals("owner", result.get(0).get(3)); 348 assertEquals("writer", result.get(0).get(4)); 349 assertEquals("reader", result.get(0).get(5)); 350 351 352 } 422 353 } -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/test/java/eu/dasish/annotation/backend/dao/impl/JdbcCachedRepresentationDaoTest.java
r3407 r3408 80 80 public void testGetCachedRepresentationInfo() { 81 81 System.out.println("getCachedRepresentationInfo"); 82 Number internalID = 1;83 82 84 CachedRepresentationInfo expResult = new CachedRepresentationInfo(); 85 expResult.setMimeType(TestBackendConstants._TEST_CACHED_REPRESENTATION_1_MIME_TYPE_); 86 expResult.setRef(TestBackendConstants._TEST_CACHED_REPRESENTATION_1_EXT_ID_); 87 expResult.setTool(TestBackendConstants._TEST_CACHED_REPRESENTATION_1_TOOL_); 88 expResult.setType(TestBackendConstants._TEST_CACHED_REPRESENTATION_1_TYPE_); 89 90 CachedRepresentationInfo result = jdbcCachedRepresentationDao.getCachedRepresentationInfo(internalID); 91 assertEquals(expResult.getMimeType(), result.getMimeType()); 92 assertEquals(expResult.getType(), result.getType()); 93 assertEquals(expResult.getTool(), result.getTool()); 94 assertEquals(expResult.getRef(), result.getRef()); 83 CachedRepresentationInfo result = jdbcCachedRepresentationDao.getCachedRepresentationInfo(1); 84 assertEquals(TestBackendConstants._TEST_CACHED_REPRESENTATION_1_MIME_TYPE_, result.getMimeType()); 85 assertEquals(TestBackendConstants._TEST_CACHED_REPRESENTATION_1_EXT_ID_, result.getType()); 86 assertEquals(TestBackendConstants._TEST_CACHED_REPRESENTATION_1_TOOL_, result.getTool()); 87 assertEquals(TestBackendConstants._TEST_CACHED_REPRESENTATION_1_TYPE_, result.getRef()); 95 88 } 96 89 … … 131 124 Number result = jdbcCachedRepresentationDao.addCachedRepresentationInfo(cached); 132 125 CachedRepresentationInfo addedCached = jdbcCachedRepresentationDao.getCachedRepresentationInfo(result); 126 assertEquals(8, result.intValue()); 133 127 assertEquals("text/plain", addedCached.getMimeType()); 134 128 assertEquals("vi", addedCached.getTool()); -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/test/java/eu/dasish/annotation/backend/dao/impl/JdbcSourceDaoTest.java
r3407 r3408 19 19 20 20 import eu.dasish.annotation.backend.TestBackendConstants; 21 import eu.dasish.annotation.backend.dao.VersionDao;22 21 import eu.dasish.annotation.backend.identifiers.SourceIdentifier; 23 22 import eu.dasish.annotation.backend.identifiers.VersionIdentifier; … … 27 26 import java.util.ArrayList; 28 27 import java.util.List; 29 import org.jmock.Expectations;30 import org.jmock.Mockery;31 28 import org.junit.Test; 32 29 import static org.junit.Assert.*; … … 75 72 */ 76 73 @Test 77 @Ignore78 74 public void testGetSource() { 79 75 System.out.println("getSource"); 80 76 Number internalID = 1; 81 final Number internalVersionID = 1;82 final VersionIdentifier externalVersionID = new VersionIdentifier(TestBackendConstants._TEST_VERSION_1_EXT_ID);83 84 // mockery.checking(new Expectations() {85 // {86 // oneOf(versionDao).getExternalID(internalVersionID);87 // will(returnValue(externalVersionID));88 // }89 // });90 91 77 Source result = jdbcSourceDao.getSource(internalID); 92 78 assertEquals(TestBackendConstants._TEST_SOURCE_1_EXT_ID, result.getURI()); … … 102 88 public void testDeleteSource() { 103 89 System.out.println("deleteSource"); 90 91 // remove the rows from the joint table to keep integrity 92 jdbcSourceDao.deleteAllSourceVersion(1); 104 93 105 94 // test 1 106 int[] result = jdbcSourceDao.deleteSource(1); //the source is in use, should not be deleted 107 assertEquals(0, result[0]); // 108 assertEquals(0, result[1]); 95 int result = jdbcSourceDao.deleteSource(1); //the source is in use, should not be deleted 96 assertEquals(0, result); 109 97 110 98 // test 2 111 final int[] versionDeleted = new int[3]; 112 versionDeleted[0] = 0; // versions_cahced_representations 113 versionDeleted[1] = 1; // version deleted 114 versionDeleted[2] = 0; // deleted cached representations; version 7 does not have them 115 // mockery.checking(new Expectations() { 116 // { 117 // oneOf(versionDao).deleteVersion(7); 118 // will(returnValue(versionDeleted)); // no other sources refer to this version # 5 119 // } 120 // }); 99 int resultTwo = jdbcSourceDao.deleteSource(5);// the source will be deleted because it is not referred by any annotation 100 assertEquals(1, resultTwo); 101 } 102 103 /** 104 * Test of deleteAllSourceVersion method, of class JdbcSourceDao. 105 */ 106 @Test 107 public void testDeleteAllSourceVersion() { 108 System.out.println("test deleteAllSourceVersion"); 109 assertEquals(2, jdbcSourceDao.deleteAllSourceVersion(1)); 121 110 122 int[] resultTwo = jdbcSourceDao.deleteSource(5);// the source will be deleted because it is not referred by any annotation123 assertEquals(1, resultTwo[0]); // row (5,7) in "sorces_versions" is deleted124 assertEquals(1, resultTwo[1]); //source 5 is deleted from "source" table125 111 } 126 112 113 /** 114 * Test of addSourceVersion method, of class JdbcSourceDao. 115 */ 116 @Test 117 public void testAddSourceVersion() throws SQLException{ 118 System.out.println("test addSourceVersion"); 119 assertEquals(1, jdbcSourceDao.addSourceVersion(1,3)); 120 121 } 122 127 123 /** 128 124 * Test of addSource method, of class JdbcSourceDao. 129 125 */ 130 126 @Test 131 @Ignore132 127 public void testAddSource() throws SQLException { 133 128 System.out.println("addSource"); 134 129 135 130 String link = "http://www.sagradafamilia.cat/"; 136 137 131 // test 1: existing version 138 132 Source freshSource = new Source(); … … 141 135 freshSource.setURI(null); 142 136 freshSource.setTimeSatmp(null); 143 144 // mockery.checking(new Expectations() { 145 // { 146 // oneOf(versionDao).getInternalID(new VersionIdentifier(TestBackendConstants._TEST_VERSION_1_EXT_ID)); 147 // will(returnValue(1)); 148 // } 149 // }); 150 137 151 138 Number result = jdbcSourceDao.addSource(freshSource); 152 139 assertEquals(6, result); 153 154 // mockery.checking(new Expectations() {155 // {156 // oneOf(versionDao).getExternalID(1); // used in getSource157 // will(returnValue(new VersionIdentifier(TestBackendConstants._TEST_VERSION_1_EXT_ID)));158 //159 //160 // }161 // });162 140 Source addedSource = jdbcSourceDao.getSource(result); 163 141 assertEquals(link, addedSource.getLink()); … … 167 145 ////////// test 2 non-existing version 168 146 freshSource.setVersion(TestBackendConstants._TEST_VERSION_NONEXIST_EXT_ID); 169 // mockery.checking(new Expectations() {170 // {171 // oneOf(versionDao).getInternalID(new VersionIdentifier(TestBackendConstants._TEST_VERSION_NONEXIST_EXT_ID));172 // will(returnValue(null));173 // }174 // });175 176 177 147 Number resultTwo = jdbcSourceDao.addSource(freshSource); 178 148 assertEquals(-1, resultTwo); // addversion (preferably with cached representation … … 189 159 test.add(1); 190 160 test.add(2); 191 192 // mockery.checking(new Expectations() {193 // {194 // oneOf(versionDao).getExternalID(1);195 // will(returnValue(new VersionIdentifier(TestBackendConstants._TEST_VERSION_1_EXT_ID)));196 //197 // oneOf(versionDao).getExternalID(3);198 // will(returnValue(new VersionIdentifier(TestBackendConstants._TEST_VERSION_3_EXT_ID)));199 // }200 // });201 202 161 List<SourceInfo> result = jdbcSourceDao.getSourceInfos(test); 203 162 assertEquals(2, result.size()); -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/test/java/eu/dasish/annotation/backend/dao/impl/JdbcVersionDaoTest.java
r3407 r3408 86 86 */ 87 87 @Test 88 @Ignore89 88 public void testDeleteVersion() { 90 89 System.out.println("deleteVersion"); 91 // mockery.checking(new Expectations() { 92 // { 93 // oneOf(cachedRepresentationDao).deleteCachedRepresentationInfo(5); 94 // will(returnValue(0)); 95 // 96 // } 97 // }); 98 int[] result = jdbcVersionDao.deleteVersion(6); 99 assertEquals(1, result[0]); //versions-cached 100 assertEquals(1, result[1]); // version 101 assertEquals(0, result[2]);//cached 5 is in use 102 103 104 int[] resultTwo = jdbcVersionDao.deleteVersion(5); // version is in use by the source 4 105 assertEquals(0, resultTwo[0]); 106 assertEquals(0, resultTwo[1]); 107 assertEquals(0, resultTwo[2]); 90 91 // remove the rows from the joint table to keep integrity 92 jdbcVersionDao.deleteAllVersionCachedRepresentation(6); 93 int result = jdbcVersionDao.deleteVersion(6); 94 assertEquals(1, result); 95 assertEquals(0, jdbcVersionDao.deleteVersion(6)); // delete the same version: nothing happen 96 97 int resultTwo = jdbcVersionDao.deleteVersion(5); // version is in use by the source 4 98 assertEquals(0, resultTwo); 108 99 109 100 } … … 117 108 118 109 Version freshVersion = new Version(); 119 120 110 Number result = jdbcVersionDao.addVersion(freshVersion); 121 111 assertEquals(8, result); 122 112 Version addedVersion = jdbcVersionDao.getVersion(result); 123 assertFalse(null == addedVersion.getVersion()); 113 assertFalse(null == addedVersion.getVersion()); // extend once "version" information is fixed, and becomes different from externalID 124 114 } 125 115 … … 145 135 assertEquals(expResult, result); 146 136 } 137 //////////////////////////////////////////////////////// 138 @Test 139 public void deleteVersionCachedRepresentation(){ 140 System.out.println("test deleteVersionCachedRepresentation"); 141 assertEquals(1, jdbcVersionDao.deleteVersionCachedRepresentation(1, 1)); 142 assertEquals(0, jdbcVersionDao.deleteVersionCachedRepresentation(1, 2)); 143 144 } 145 146 //////////////////////////////////////////////////////// 147 @Test 148 public void deleteAllVersionCachedRepresentation(){ 149 System.out.println("test deleteAllVersionCachedRepresentation"); 150 assertEquals(2, jdbcVersionDao.deleteAllVersionCachedRepresentation(1)); 151 } 152 153 //////////////////////////////////////////////////////// 154 @Test 155 public void addVersionCachedRepresentation(){ 156 System.out.println("test addVersionCachedRepresentation"); 157 assertEquals(1, jdbcVersionDao.addVersionCachedRepresentation(1, 7)); 158 } 147 159 } -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/test/java/eu/dasish/annotation/backend/dao/integration/DaoDispatcherTest.java
r3407 r3408 18 18 package eu.dasish.annotation.backend.dao.integration; 19 19 20 import eu.dasish.annotation.backend.TestBackendConstants; 21 import eu.dasish.annotation.backend.dao.AnnotationDao; 22 import eu.dasish.annotation.backend.dao.CachedRepresentationDao; 23 import eu.dasish.annotation.backend.dao.NotebookDao; 24 import eu.dasish.annotation.backend.dao.SourceDao; 25 import eu.dasish.annotation.backend.dao.UserDao; 26 import eu.dasish.annotation.backend.dao.VersionDao; 20 27 import eu.dasish.annotation.backend.identifiers.AnnotationIdentifier; 28 import eu.dasish.annotation.backend.identifiers.CachedRepresentationIdentifier; 21 29 import eu.dasish.annotation.backend.identifiers.UserIdentifier; 22 30 import eu.dasish.annotation.schema.Annotation; … … 24 32 import eu.dasish.annotation.schema.NewOrExistingSourceInfo; 25 33 import eu.dasish.annotation.schema.NewSourceInfo; 34 import eu.dasish.annotation.schema.SourceInfo; 35 import java.sql.SQLException; 26 36 import java.sql.Timestamp; 37 import java.util.ArrayList; 27 38 import java.util.List; 28 39 import java.util.Map; 29 import org.junit.After; 30 import org.junit.AfterClass; 31 import org.junit.Before; 32 import org.junit.BeforeClass; 40 import org.jmock.Expectations; 41 import org.jmock.Mockery; 33 42 import org.junit.Test; 34 43 import static org.junit.Assert.*; 35 44 import org.junit.runner.RunWith; 45 import org.springframework.beans.factory.annotation.Autowired; 36 46 import org.springframework.test.context.ContextConfiguration; 37 47 import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; … … 43 53 @RunWith(SpringJUnit4ClassRunner.class) 44 54 @ContextConfiguration({"/spring-test-config/dataSource.xml", "/spring-test-config/mockery.xml", "/spring-test-config/mockAnnotationDao.xml", 45 "/spring-test-config/mockUserDao.xml", "/spring-test-config/mockPermissionsDao.xml", "/spring-test-config/mockNotebookDao.xml", 46 "/spring-test-config/mockSourceDao.xml", "/spring-test-config/mockVersionDao.xml", "/spring-config/cachedRepresentationDao.xml"}) 47 public class DaoRequestorTest { 48 49 public DaoRequestorTest() { 50 } 51 52 53 /** 54 * Test of getAnnotationInternalIdentifier method, of class DaoRequestor. 55 "/spring-test-config/mockUserDao.xml", "/spring-test-config/mockNotebookDao.xml", 56 "/spring-test-config/mockSourceDao.xml", "/spring-test-config/mockVersionDao.xml", "/spring-test-config/cachedRepresentationDao.xml"}) 57 public class DaoDispatcherTest { 58 59 private DaoDispatcher daoDispatcher; 60 private Mockery mockery; 61 @Autowired 62 UserDao userDao; 63 @Autowired 64 CachedRepresentationDao cachedRepresentationDao; 65 @Autowired 66 VersionDao versionDao; 67 @Autowired 68 SourceDao sourceDao; 69 @Autowired 70 AnnotationDao annotationDao; 71 @Autowired 72 NotebookDao notebookDao; 73 74 public DaoDispatcherTest() { 75 } 76 77 /** 78 * Test of getAnnotationInternalIdentifier method, of class DaoDispatcher. 55 79 */ 56 80 @Test 57 81 public void testGetAnnotationInternalIdentifier() { 58 82 System.out.println("getAnnotationInternalIdentifier"); 59 AnnotationIdentifier annotationIdentifier = null; 60 DaoRequestor instance = new DaoRequestor(); 61 Number expResult = null; 62 Number result = instance.getAnnotationInternalIdentifier(annotationIdentifier); 63 assertEquals(expResult, result); 64 // TODO review the generated test code and remove the default call to fail. 65 fail("The test case is a prototype."); 66 } 67 68 /** 69 * Test of getAnnotationExternalIdentifier method, of class DaoRequestor. 83 final AnnotationIdentifier annotationIdentifier = new AnnotationIdentifier(TestBackendConstants._TEST_ANNOT_2_EXT); 84 85 mockery.checking(new Expectations() { 86 { 87 oneOf(annotationDao).getInternalID(annotationIdentifier); 88 will(returnValue(2)); 89 } 90 }); 91 assertEquals(2, daoDispatcher.getAnnotationInternalIdentifier(annotationIdentifier)); 92 } 93 94 /** 95 * Test of getAnnotationExternalIdentifier method, of class DaoDispatcher. 70 96 */ 71 97 @Test 72 98 public void testGetAnnotationExternalIdentifier() { 73 99 System.out.println("getAnnotationExternalIdentifier"); 74 Number annotationID = null; 75 DaoRequestor instance = new DaoRequestor(); 76 AnnotationIdentifier expResult = null; 77 AnnotationIdentifier result = instance.getAnnotationExternalIdentifier(annotationID); 78 assertEquals(expResult, result); 79 // TODO review the generated test code and remove the default call to fail. 80 fail("The test case is a prototype."); 81 } 82 83 /** 84 * Test of getUserInternalIdentifier method, of class DaoRequestor. 100 final AnnotationIdentifier annotationIdentifier = new AnnotationIdentifier(TestBackendConstants._TEST_ANNOT_2_EXT); 101 102 mockery.checking(new Expectations() { 103 { 104 oneOf(annotationDao).getExternalID(2); 105 will(returnValue(annotationIdentifier)); 106 } 107 }); 108 assertEquals(TestBackendConstants._TEST_ANNOT_2_EXT, daoDispatcher.getAnnotationExternalIdentifier(2).toString()); 109 } 110 111 /** 112 * Test of getUserInternalIdentifier method, of class DaoDispatcher. 85 113 */ 86 114 @Test 87 115 public void testGetUserInternalIdentifier() { 88 116 System.out.println("getUserInternalIdentifier"); 89 UserIdentifier userIdentifier = null; 90 DaoRequestor instance = new DaoRequestor(); 91 Number expResult = null; 92 Number result = instance.getUserInternalIdentifier(userIdentifier); 93 assertEquals(expResult, result); 94 // TODO review the generated test code and remove the default call to fail. 95 fail("The test case is a prototype."); 96 } 97 98 /** 99 * Test of getUserExternalIdentifier method, of class DaoRequestor. 117 118 final UserIdentifier userIdentifier = new UserIdentifier(TestBackendConstants._TEST_USER_5_EXT_ID); 119 120 mockery.checking(new Expectations() { 121 { 122 oneOf(annotationDao).getInternalID(userIdentifier); 123 will(returnValue(5)); 124 } 125 }); 126 assertEquals(5, daoDispatcher.getUserInternalIdentifier(userIdentifier)); 127 } 128 129 /** 130 * Test of getUserExternalIdentifier method, of class DaoDispatcher. 100 131 */ 101 132 @Test 102 133 public void testGetUserExternalIdentifier() { 103 134 System.out.println("getUserExternalIdentifier"); 104 Number userID = null; 105 DaoRequestor instance = new DaoRequestor(); 106 UserIdentifier expResult = null; 107 UserIdentifier result = instance.getUserExternalIdentifier(userID); 108 assertEquals(expResult, result); 109 // TODO review the generated test code and remove the default call to fail. 110 fail("The test case is a prototype."); 111 } 112 113 /** 114 * Test of deleteCachedForVersion method, of class DaoRequestor. 135 final UserIdentifier userIdentifier = new UserIdentifier(TestBackendConstants._TEST_USER_5_EXT_ID); 136 137 mockery.checking(new Expectations() { 138 { 139 oneOf(annotationDao).getExternalID(5); 140 will(returnValue(userIdentifier)); 141 } 142 }); 143 assertEquals(TestBackendConstants._TEST_USER_5_EXT_ID, daoDispatcher.getUserExternalIdentifier(5)); 144 } 145 146 /** 147 * Test of deleteCachedForVersion method, of class DaoDispatcher. 115 148 */ 116 149 @Test 117 150 public void testDeleteCachedForVersion() { 118 151 System.out.println("deleteCachedForVersion"); 119 Number versionID = null; 120 Number cachedID = null; 121 DaoRequestor instance = new DaoRequestor(); 122 int[] expResult = null; 123 int[] result = instance.deleteCachedForVersion(versionID, cachedID); 124 assertArrayEquals(expResult, result); 125 // TODO review the generated test code and remove the default call to fail. 126 fail("The test case is a prototype."); 127 } 128 129 /** 130 * Test of addCachedForVersion method, of class DaoRequestor. 152 mockery.checking(new Expectations() { 153 { 154 oneOf(versionDao).deleteVersionCachedRepresentation(6, 5); 155 will(returnValue(1)); 156 157 oneOf(cachedRepresentationDao).deleteCachedRepresentationInfo(5); 158 will(returnValue(0)); // cached is used by another version 159 160 } 161 }); 162 163 int[] result = daoDispatcher.deleteCachedForVersion(6, 5); 164 assertEquals(2, result.length); 165 assertEquals(1, result[0]); 166 assertEquals(0, result[1]); 167 } 168 169 /** 170 * Test of addCachedForVersion method, of class DaoDispatcher. 131 171 */ 132 172 @Test 133 173 public void testAddCachedForVersion() { 134 174 System.out.println("addCachedForVersion"); 135 Number versionID = null; 136 CachedRepresentationInfo cached = null; 137 DaoRequestor instance = new DaoRequestor(); 138 Number[] expResult = null; 139 Number[] result = instance.addCachedForVersion(versionID, cached); 140 assertArrayEquals(expResult, result); 141 // TODO review the generated test code and remove the default call to fail. 142 fail("The test case is a prototype."); 143 } 144 145 146 147 /** 175 String mime = "text/html"; 176 String type = "text"; 177 String tool = "latex"; 178 final CachedRepresentationInfo newCached = new CachedRepresentationInfo(); 179 newCached.setMimeType(mime); 180 newCached.setType(type); 181 newCached.setTool(tool); 182 final Number newID = 8; 183 final Number versionID = 1; 184 mockery.checking(new Expectations() { 185 { 186 oneOf(cachedRepresentationDao).getInternalID(new CachedRepresentationIdentifier(newCached.getRef())); 187 will(returnValue(null)); 188 189 oneOf(cachedRepresentationDao).addCachedRepresentationInfo(newCached); 190 will(returnValue(newID)); 191 192 one(versionDao).addVersionCachedRepresentation(versionID, newID); 193 will(returnValue(1)); 194 195 } 196 }); 197 198 199 Number[] result = daoDispatcher.addCachedForVersion(6, newCached); 200 assertEquals(2, result.length); 201 assertEquals(newID, result[0]); 202 assertEquals(1, result[1]); 203 } 204 205 ///////////////////////////////////////////// 206 public void testDeleteVersionWithCachedRepresentations() { 207 System.out.println("deleteVersion"); 208 final List<Number> cachedList = new ArrayList<Number>(); 209 cachedList.add(5); 210 211 mockery.checking(new Expectations() { 212 { 213 oneOf(versionDao).versionIsInUse(6); 214 will(returnValue(false)); 215 216 oneOf(versionDao).retrieveCachedRepresentationList(6); 217 will(returnValue(cachedList)); 218 219 oneOf(versionDao).deleteAllVersionCachedRepresentation(6); 220 will(returnValue(1)); 221 222 oneOf(versionDao).deleteVersion(6); 223 will(returnValue(1)); 224 225 oneOf(cachedRepresentationDao).deleteCachedRepresentationInfo(5); 226 will(returnValue(0)); // cached is used by another version 227 228 229 230 } 231 }); 232 233 int[] result = daoDispatcher.deleteVersionWithCachedRepresentations(6); 234 assertEquals(1, result[0]); //version 235 assertEquals(1, result[1]); // versions-cached 236 assertEquals(0, result[2]);//cached 5 is in use 237 238 //Another test 239 240 mockery.checking(new Expectations() { 241 { 242 oneOf(versionDao).versionIsInUse(5); 243 will(returnValue(true)); 244 } 245 }); 246 247 248 int[] resultTwo = daoDispatcher.deleteVersionWithCachedRepresentations(5); // version is in use by the source 4 249 assertEquals(0, resultTwo[0]); 250 assertEquals(0, resultTwo[1]); 251 assertEquals(0, resultTwo[2]); 252 253 } 254 255 @Test 256 public void testDeleteSource() throws SQLException { 257 258 // test 1 259 int[] result = daoDispatcher.deleteSourceWithVersions(1); //the source is in use, should not be deleted 260 assertEquals(0, result[0]); // 261 assertEquals(0, result[1]); 262 263 // test 2 264 final int[] versionDeleted = new int[3]; 265 versionDeleted[0] = 0; // versions_cahced_representations 266 versionDeleted[1] = 1; // version deleted 267 versionDeleted[2] = 0; // deleted cached representations; version 7 does not have them 268 // mockery.checking(new Expectations() { 269 // { 270 // oneOf(versionDao).deleteVersion(7); 271 // will(returnValue(versionDeleted)); // no other sources refer to this version # 5 272 // } 273 // }); 274 275 int[] resultTwo = daoDispatcher.deleteSourceWithVersions(5);// the source will be deleted because it is not referred by any annotation 276 assertEquals(1, resultTwo[0]); // row (5,7) in "sorces_versions" is deleted 277 assertEquals(1, resultTwo[1]); 278 } 279 280 /** 148 281 * Test of addVersion method, of class JdbcVersionDao. 149 282 */ … … 162 295 // assertEquals(1, result[1].intValue()); 163 296 // } 164 165 /** 297 /** 166 298 * 167 299 */ … … 183 315 // 184 316 // /** 185 // * Test of deleteVersionWithCachedRepresentations method, of class Dao Requestor.317 // * Test of deleteVersionWithCachedRepresentations method, of class DaoDispatcher. 186 318 // */ 187 319 // @Test … … 189 321 // System.out.println("deleteVersionWithCachedRepresentations"); 190 322 // Number versionID = null; 191 // Dao Requestor instance = new DaoRequestor();323 // DaoDispatcher instance = new DaoDispatcher(); 192 324 // int[] expResult = null; 193 325 // int[] result = instance.deleteVersionWithCachedRepresentations(versionID); … … 196 328 // fail("The test case is a prototype."); 197 329 // } 198 199 /** 200 * Test of deleteSourceWithVersions method, of class DaoRequestor. 201 */ 202 @Test 203 public void testDeleteSourceWithVersions() { 330 /** 331 * Test of deleteSourceWithVersions method, of class DaoDispatcher. 332 */ 333 @Test 334 public void testDeleteSourceWithVersions() throws SQLException { 204 335 System.out.println("deleteSourceWithVersions"); 205 336 Number sourceID = null; 206 Dao Requestor instance = new DaoRequestor();337 DaoDispatcher instance = new DaoDispatcher(); 207 338 int[] expResult = null; 208 339 int[] result = instance.deleteSourceWithVersions(sourceID); … … 213 344 214 345 /** 215 * Test of addSourceAndPairSourceVersion method, of class Dao Requestor.346 * Test of addSourceAndPairSourceVersion method, of class DaoDispatcher. 216 347 */ 217 348 @Test … … 219 350 System.out.println("addSourceAndPairSourceVersion"); 220 351 NewSourceInfo newSource = null; 221 Dao Requestor instance = new DaoRequestor();352 DaoDispatcher instance = new DaoDispatcher(); 222 353 Number expResult = null; 223 354 Number result = instance.addSourceAndPairSourceVersion(newSource); … … 228 359 229 360 /** 230 * Test of addTargetSourcesToAnnotation method, of class Dao Requestor.361 * Test of addTargetSourcesToAnnotation method, of class DaoDispatcher. 231 362 */ 232 363 @Test 233 364 public void testAddTargetSourcesToAnnotation() throws Exception { 234 365 System.out.println("addTargetSourcesToAnnotation"); 366 367 368 // NewOrExistingSourceInfo noesi = new NewOrExistingSourceInfo(); 369 // NewSourceInfo nsi = new NewSourceInfo(); 370 // nsi.setLink(TestBackendConstants._TEST_NEW_SOURCE_LINK); 371 // nsi.setId(TestBackendConstants._TEST_TEMP_SOURCE_ID); 372 // nsi.setVersion(null); 373 // noesi.setNewSource(nsi); 374 // 375 // 376 // NewOrExistingSourceInfo noesiTwo = new NewOrExistingSourceInfo(); 377 // SourceInfo si = new SourceInfo(); 378 // si.setLink(TestBackendConstants._TEST_NEW_SOURCE_LINK); 379 // si.setRef((new SourceIdentifier()).toString()); 380 // si.setVersion(null); 381 // noesiTwo.setSource(si); 382 // 383 // final Map<NewOrExistingSourceInfo, NewOrExistingSourceInfo> map = new HashMap<NewOrExistingSourceInfo, NewOrExistingSourceInfo>(); 384 // map.put(noesi, noesiTwo); 385 // 386 // 387 // mockery.checking(new Expectations() { 388 // { 389 // oneOf(sourceDao).addTargetSources(with(aNonNull(Number.class)), with(aNonNull(List.class))); 390 // will(returnValue(map)); 391 // } 392 // }); 393 394 235 395 Number annotationID = null; 236 396 List<NewOrExistingSourceInfo> sources = null; 237 Dao Requestor instance = new DaoRequestor();397 DaoDispatcher instance = new DaoDispatcher(); 238 398 Map expResult = null; 239 399 Map result = instance.addTargetSourcesToAnnotation(annotationID, sources); … … 244 404 245 405 /** 246 * Test of getFilteredAnnotationIDs method, of class Dao Requestor.406 * Test of getFilteredAnnotationIDs method, of class DaoDispatcher. 247 407 */ 248 408 @Test … … 256 416 Timestamp after = null; 257 417 Timestamp before = null; 258 Dao Requestor instance = new DaoRequestor();418 DaoDispatcher instance = new DaoDispatcher(); 259 419 List expResult = null; 260 420 List result = instance.getFilteredAnnotationIDs(link, text, access, namespace, owner, after, before); … … 265 425 266 426 /** 267 * Test of deleteAnnotationWithSources method, of class Dao Requestor.427 * Test of deleteAnnotationWithSources method, of class DaoDispatcher. 268 428 */ 269 429 @Test … … 271 431 System.out.println("deleteAnnotationWithSources"); 272 432 Number annotationID = null; 273 Dao Requestor instance = new DaoRequestor();433 DaoDispatcher instance = new DaoDispatcher(); 274 434 int[] expResult = null; 275 int[] result = instance.deleteAnnotationWithSources (annotationID);435 int[] result = instance.deleteAnnotationWithSourcesAndPermissions(annotationID); 276 436 assertArrayEquals(expResult, result); 277 437 // TODO review the generated test code and remove the default call to fail. … … 280 440 281 441 /** 282 * Test of getAnnotation method, of class Dao Requestor.442 * Test of getAnnotation method, of class DaoDispatcher. 283 443 */ 284 444 @Test … … 286 446 System.out.println("getAnnotation"); 287 447 Number annotationID = null; 288 Dao Requestor instance = new DaoRequestor();448 DaoDispatcher instance = new DaoDispatcher(); 289 449 Annotation expResult = null; 290 450 Annotation result = instance.getAnnotation(annotationID); … … 295 455 296 456 /** 297 * Test of addAnnotationWithTargetSources method, of class DaoRequestor. 298 */ 299 @Test 300 public void testAddAnnotationWithTargetSources() throws Exception { 301 System.out.println("addAnnotationWithTargetSources"); 302 Annotation annotation = null; 303 Number userID = null; 304 DaoRequestor instance = new DaoRequestor(); 305 Annotation expResult = null; 306 Annotation result = instance.addAnnotationWithTargetSources(annotation, userID); 307 assertEquals(expResult, result); 308 // TODO review the generated test code and remove the default call to fail. 309 fail("The test case is a prototype."); 310 } 457 * 458 * @param annotationId 459 * @return result[0] = # removed "annotations_principals_permissions" rows 460 * result[1] = # removed "annotations_target_sources" rows result[2] = # 461 * removed annotation rows (should be 1) 462 */ 463 @Test 464 public void testDeleteAnnotationWithSourcesAndPermissions() throws SQLException { 465 System.out.println("test deleteAnnotationWithSourcesAndPermissions"); 466 // result[0] = # removed "annotations_principals_perissions" rows 467 // result[1] = # removed "annotatiobs_target_sources" rows 468 // result[2] = # removed annotation rows (should be 1) 469 470 int[] result = daoDispatcher.deleteAnnotationWithSourcesAndPermissions(5); 471 assertEquals(3, result[0]); 472 assertEquals(2, result[1]); 473 assertEquals(1, result[2]); 474 475 // now, try to delete the same annotation one more time 476 // if it has been already deleted then the method under testing should return 0 477 478 result = daoDispatcher.deleteAnnotationWithSourcesAndPermissions(5); 479 assertEquals(0, result[0]); 480 assertEquals(0, result[1]); 481 assertEquals(0, result[2]); 482 } 483 484 /** 485 * Test of contructNewOrExistingSourceInfo method, of class JdbcSourceDao. 486 */ 487 @Test 488 public void testContructNewOrExistingSourceInfo() { 489 System.out.println("contructNewOrExistingSourceInfo"); 490 491 List<SourceInfo> sourceInfoList = new ArrayList<SourceInfo>(); 492 493 SourceInfo sourceInfoOne = new SourceInfo(); 494 sourceInfoOne.setLink(TestBackendConstants._TEST_SOURCE_1_LINK); 495 sourceInfoOne.setRef(TestBackendConstants._TEST_SOURCE_1_EXT_ID); 496 sourceInfoOne.setRef(TestBackendConstants._TEST_VERSION_1_EXT_ID); 497 498 SourceInfo sourceInfoTwo = new SourceInfo(); 499 sourceInfoTwo.setLink(TestBackendConstants._TEST_SOURCE_2_LINK); 500 sourceInfoTwo.setRef(TestBackendConstants._TEST_SOURCE_2_EXT_ID); 501 sourceInfoTwo.setRef(TestBackendConstants._TEST_VERSION_3_EXT_ID); 502 503 sourceInfoList.add(sourceInfoOne); 504 sourceInfoList.add(sourceInfoTwo); 505 506 // NewOrExistingSourceInfos result = jdbcSourceDao.contructNewOrExistingSourceInfo(sourceInfoList); 507 // assertEquals(2, result.getTarget().size()); 508 // assertEquals(sourceInfoOne, result.getTarget().get(0).getSource()); 509 // assertEquals(sourceInfoTwo, result.getTarget().get(1).getSource()); 510 511 } 512 // /** 513 // * Test of addTargetSources method, of class JdbcSourceDao. public 514 // * Map<NewOrExistingSourceInfo, NewOrExistingSourceInfo> 515 // * addTargetSources(Number annotationID, List<NewOrExistingSourceInfo> 516 // * sources) 517 // */ 518 // @Test 519 // public void testAddTargetSourcesOnExistingSource() { 520 // System.out.println("addTargetSources : adding the old source"); 521 // 522 // NewOrExistingSourceInfo noesi = new NewOrExistingSourceInfo(); 523 // SourceInfo si = new SourceInfo(); 524 // si.setLink(TestBackendConstants._TEST_SOURCE_1_LINK); 525 // si.setRef(TestBackendConstants._TEST_SOURCE_1_EXT_ID); 526 // si.setVersion(TestBackendConstants._TEST_VERSION_1_EXT_ID); 527 // noesi.setSource(si); 528 // 529 // List<NewOrExistingSourceInfo> listnoesi = new ArrayList<NewOrExistingSourceInfo>(); 530 // listnoesi.add(noesi); 531 // 532 // try { 533 // Map<String, String> result = jdbcSourceDao.addTargetSources(5, listnoesi); 534 // assertEquals(0, result.size()); // no new peristsent source IDs are produced 535 // } catch (SQLException e) { 536 // System.out.println(e); 537 // } 538 // } 539 // 540 // /** 541 // * Test of addTargetSources method, of class JdbcSourceDao. public 542 // * Map<NewOrExistingSourceInfo, NewOrExistingSourceInfo> 543 // * addTargetSources(Number annotationID, List<NewOrExistingSourceInfo> 544 // * sources) 545 // */ 546 // @Test 547 // public void testAddTargetSourcesOnNewSource() { 548 // System.out.println("addTargetSources : adding the new source"); 549 // 550 // NewOrExistingSourceInfo noesi = new NewOrExistingSourceInfo(); 551 // NewSourceInfo nsi = new NewSourceInfo(); 552 // nsi.setLink(TestBackendConstants._TEST_NEW_SOURCE_LINK); 553 // nsi.setId(TestBackendConstants._TEST_TEMP_SOURCE_ID); 554 // nsi.setVersion(TestBackendConstants._TEST_VERSION_1_EXT_ID); 555 // noesi.setNewSource(nsi); 556 // 557 // List<NewOrExistingSourceInfo> listnoesiTwo = new ArrayList<NewOrExistingSourceInfo>(); 558 // listnoesiTwo.add(noesi); 559 // 560 // mockery.checking(new Expectations() { 561 // { 562 // oneOf(versionDao).getInternalID(new VersionIdentifier(TestBackendConstants._TEST_VERSION_1_EXT_ID)); 563 // will(returnValue(1)); 564 // } 565 // }); 566 // 567 // try { 568 // Map<String, String> result = jdbcSourceDao.addTargetSources(5, listnoesiTwo); 569 // assertEquals(1, result.size());// a new identifier must be produced 570 // SourceIdentifier sourceIdentifier = new SourceIdentifier(result.get(TestBackendConstants._TEST_TEMP_SOURCE_ID)); 571 // assertFalse(null == sourceIdentifier.getUUID()); // check if a proper uuid has been assigned 572 // } catch (SQLException e) { 573 // System.out.print(e); 574 // } 575 // 576 // } 577 // 311 578 } -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/test/java/eu/dasish/annotation/backend/rest/AnnotationResourceTest.java
r3407 r3408 23 23 import eu.dasish.annotation.backend.dao.AnnotationDao; 24 24 import eu.dasish.annotation.backend.dao.NotebookDao; 25 import eu.dasish.annotation.backend.dao.PermissionsDao;26 25 import eu.dasish.annotation.backend.dao.SourceDao; 27 26 import eu.dasish.annotation.backend.dao.UserDao; … … 52 51 @ContextConfiguration(locations = {"/spring-test-config/dataSource.xml", "/spring-test-config/mockAnnotationDao.xml", 53 52 "/spring-test-config/mockSourceDao.xml", 54 "/spring-test-config/mockUserDao.xml", "/spring-test-config/mock PermissionsDao.xml", "/spring-test-config/mockNotebookDao.xml", "/spring-test-config/mockery.xml"})53 "/spring-test-config/mockUserDao.xml", "/spring-test-config/mockNotebookDao.xml", "/spring-test-config/mockery.xml"}) 55 54 public class AnnotationResourceTest { 56 55 … … 61 60 @Autowired 62 61 private UserDao userDao; 63 @Autowired64 private PermissionsDao permissionsDao;65 62 @Autowired 66 63 private NotebookDao notebookDao; -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/test/java/eu/dasish/annotation/backend/rest/AnnotationsTest.java
r3407 r3408 23 23 import eu.dasish.annotation.backend.dao.AnnotationDao; 24 24 import eu.dasish.annotation.backend.dao.NotebookDao; 25 import eu.dasish.annotation.backend.dao.PermissionsDao;26 25 import eu.dasish.annotation.backend.identifiers.AnnotationIdentifier; 27 26 import eu.dasish.annotation.backend.identifiers.UserIdentifier; … … 43 42 44 43 private AnnotationDao annotationDao; 45 private PermissionsDao permissionsDao;46 44 private NotebookDao notebookDao; 47 45 … … 49 47 super(AnnotationResource.class.getPackage().getName()); 50 48 annotationDao = webAppContext.getBean(AnnotationDao.class); 51 permissionsDao = webAppContext.getBean(PermissionsDao.class);52 49 notebookDao = webAppContext.getBean(NotebookDao.class); 53 50 } -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/test/java/eu/dasish/annotation/backend/rest/NotebookResourceTest.java
r3380 r3408 19 19 20 20 import eu.dasish.annotation.backend.TestBackendConstants; 21 import eu.dasish.annotation.backend.dao.AnnotationDao;22 21 import eu.dasish.annotation.backend.dao.NotebookDao; 23 22 import eu.dasish.annotation.backend.identifiers.AnnotationIdentifier; … … 48 47 @RunWith(value = SpringJUnit4ClassRunner.class) 49 48 @ContextConfiguration(locations = {"/spring-test-config/dataSource.xml", "/spring-test-config/mockAnnotationDao.xml", "/spring-test-config/mockUserDao.xml", 50 "/spring-test-config/mockSourceDao.xml", "/spring-test-config/mockNotebookDao.xml", "/spring-test-config/mock PermissionsDao.xml", "/spring-test-config/mockery.xml"})49 "/spring-test-config/mockSourceDao.xml", "/spring-test-config/mockNotebookDao.xml", "/spring-test-config/mockery.xml"}) 51 50 public class NotebookResourceTest { 52 51
Note: See TracChangeset
for help on using the changeset viewer.