Changeset 3411
- Timestamp:
- 08/18/13 20:14:50 (11 years ago)
- Location:
- DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src
- Files:
-
- 2 deleted
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/SourceDao.java
r3408 r3411 90 90 91 91 92 public boolean sourceIsInUse(Number sourceID); 92 93 } -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/impl/JdbcSourceDao.java
r3408 r3411 175 175 176 176 177 //////////// helpers /////////////////////// 178 ///////////////////////////////////////////////// 179 180 ////////////////////////////// 181 private boolean sourceIsInUse(Number sourceID) { 177 @Override 178 public boolean sourceIsInUse(Number sourceID) { 182 179 String sql = "SELECT " + annotation_id + " FROM " + annotationsSourcesTableName + " WHERE " + source_id + "= ? LIMIT 1"; 183 180 List<Number> result = getSimpleJdbcTemplate().query(sql, annotationIDRowMapper, sourceID); … … 195 192 }; 196 193 197 194 /////////// HELPERS //////////////// 198 195 199 196 -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/rest/DaoDispatcher.java
r3409 r3411 64 64 @Autowired 65 65 NotebookDao notebookDao; 66 67 68 66 69 67 public Number getAnnotationInternalIdentifier(AnnotationIdentifier annotationIdentifier) { … … 157 155 public int[] deleteSourceWithVersions(Number sourceID) throws SQLException { 158 156 int[] result = new int[3]; 159 List<Number> versions = sourceDao.retrieveVersionList(sourceID); 160 result[1] = sourceDao.deleteAllSourceVersion(sourceID); 161 result[0] = sourceDao.deleteSource(sourceID); 162 result[3] = 0; 163 for (Number versionID : versions) { 164 int[] deleteVersion = deleteVersionWithCachedRepresentations(versionID); 165 result[3] = result[3] + deleteVersion[1]; 157 if (!sourceDao.sourceIsInUse(sourceID)) { 158 List<Number> versions = sourceDao.retrieveVersionList(sourceID); 159 result[1] = sourceDao.deleteAllSourceVersion(sourceID); 160 result[0] = sourceDao.deleteSource(sourceID); 161 result[3] = 0; 162 for (Number versionID : versions) { 163 int[] deleteVersion = deleteVersionWithCachedRepresentations(versionID); 164 result[3] = result[3] + deleteVersion[1]; 165 } 166 } else { 167 result[0] = 0; 168 result[1] = 0; 169 result[2] = 0; 166 170 } 167 171 return result; … … 202 206 * @return the mapping temporarySourceID -> peristenExternalSOurceId adds a 203 207 * source from "sources" to the DB if it is not there, to the table 204 * "target_source" adds the wro (annotationID, sourceID) to the joint table 205 * "annotations_sources" 208 * "target_source" adds (annotationID, sourceID) to the joint table "annotations_sources" 206 209 * @throws SQLException 207 210 */ -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/test/java/eu/dasish/annotation/backend/rest/DaoDispatcherTest.java
r3410 r3411 18 18 package eu.dasish.annotation.backend.rest; 19 19 20 import eu.dasish.annotation.backend.rest.DaoDispatcher;21 20 import eu.dasish.annotation.backend.TestBackendConstants; 22 21 import eu.dasish.annotation.backend.dao.AnnotationDao; … … 28 27 import eu.dasish.annotation.backend.identifiers.AnnotationIdentifier; 29 28 import eu.dasish.annotation.backend.identifiers.CachedRepresentationIdentifier; 29 import eu.dasish.annotation.backend.identifiers.SourceIdentifier; 30 30 import eu.dasish.annotation.backend.identifiers.UserIdentifier; 31 import eu.dasish.annotation.backend.identifiers.VersionIdentifier; 31 32 import eu.dasish.annotation.schema.Annotation; 32 33 import eu.dasish.annotation.schema.CachedRepresentationInfo; 33 34 import eu.dasish.annotation.schema.NewOrExistingSourceInfo; 34 35 import eu.dasish.annotation.schema.NewSourceInfo; 36 import eu.dasish.annotation.schema.Source; 35 37 import eu.dasish.annotation.schema.SourceInfo; 36 38 import java.sql.SQLException; 37 39 import java.sql.Timestamp; 38 40 import java.util.ArrayList; 41 import java.util.HashMap; 39 42 import java.util.List; 40 43 import java.util.Map; … … 245 248 //Another test 246 249 250 247 251 mockery.checking(new Expectations() { 248 252 { … … 261 265 262 266 @Test 263 public void testDeleteSource() throws SQLException { 264 267 public void testDeleteSourceSourceWithVersions() throws SQLException { 265 268 // test 1 269 mockery.checking(new Expectations() { 270 { 271 oneOf(sourceDao).sourceIsInUse(5); 272 will(returnValue(true)); 273 } 274 }); 275 266 276 int[] result = daoDispatcher.deleteSourceWithVersions(1); //the source is in use, should not be deleted 267 277 assertEquals(0, result[0]); // … … 269 279 270 280 // test 2 271 final int[] versionDeleted = new int[3]; 272 versionDeleted[0] = 0; // versions_cahced_representations 273 versionDeleted[1] = 1; // version deleted 274 versionDeleted[2] = 0; // deleted cached representations; version 7 does not have them 281 282 final List<Number> versionList = new ArrayList<Number>(); 283 versionList.add(7); 284 mockery.checking(new Expectations() { 285 { 286 oneOf(sourceDao).sourceIsInUse(5); 287 will(returnValue(false)); 288 289 oneOf(sourceDao).retrieveVersionList(5); 290 will(returnValue(versionList)); 291 292 oneOf(sourceDao).deleteAllSourceVersion(5); 293 will(returnValue(1)); 294 295 oneOf(sourceDao).deleteSource(5); 296 will(returnValue(1)); 297 298 oneOf(versionDao).versionIsInUse(7); 299 will(returnValue(false)); 300 } 301 }); 302 303 304 int[] resultTwo = daoDispatcher.deleteSourceWithVersions(5);// the source will be deleted because it is not referred by any annotation 305 assertEquals(3, resultTwo.length); 306 assertEquals(1, resultTwo[0]); // source 7 is deleted 307 assertEquals(1, resultTwo[1]); // row (5,7) in "sorces_versions" is deleted 308 assertEquals(0, resultTwo[2]); // version 7 is not foub=nd, not in use 309 } 310 311 312 313 314 /** 315 * Test of addSourceAndPairSourceVersion method, of class DaoDispatcher. 316 */ 317 @Test 318 public void testAddSourceAndPairSourceVersion() throws Exception { 319 System.out.println("addSourceAndPairSourceVersion"); 320 final NewSourceInfo newSource = new NewSourceInfo(); 321 newSource.setLink(TestBackendConstants._TEST_NEW_SOURCE_LINK); 322 newSource.setVersion(TestBackendConstants._TEST_VERSION_3_EXT_ID);// already added version, existing 323 324 mockery.checking(new Expectations() { 325 { 326 oneOf(versionDao).getInternalID(new VersionIdentifier(TestBackendConstants._TEST_VERSION_3_EXT_ID)); 327 will(returnValue(3)); 328 329 oneOf(sourceDao).addSource(with(aNonNull(Source.class))); 330 will(returnValue(6)); 331 332 oneOf(sourceDao).addSourceVersion(6, 3); 333 will(returnValue(1)); 334 335 } 336 }); 337 338 Number result = daoDispatcher.addSourceAndPairSourceVersion(newSource); 339 assertEquals(6, result.intValue()); 340 341 // Another test 342 343 final NewSourceInfo newSourceTwo = new NewSourceInfo(); 344 newSourceTwo.setLink(TestBackendConstants._TEST_NEW_SOURCE_LINK); 345 newSourceTwo.setVersion(TestBackendConstants._TEST_VERSION_NONEXIST_EXT_ID); 346 mockery.checking(new Expectations() { 347 { 348 oneOf(versionDao).getInternalID(new VersionIdentifier(TestBackendConstants._TEST_VERSION_NONEXIST_EXT_ID)); 349 will(returnValue(null)); 350 351 } 352 }); 353 Number resultTwo = daoDispatcher.addSourceAndPairSourceVersion(newSourceTwo); 354 assertEquals(-1, resultTwo.intValue()); 355 356 357 } 358 359 /** 360 * Test of addTargetSourcesToAnnotation method, of class DaoDispatcher. 361 */ 362 @Test 363 public void testAddTargetSourcesToAnnotation() throws Exception { 364 System.out.println("addTargetSourcesToAnnotation"); 365 366 NewOrExistingSourceInfo noesi = new NewOrExistingSourceInfo(); 367 NewSourceInfo nsi = new NewSourceInfo(); 368 nsi.setLink(TestBackendConstants._TEST_NEW_SOURCE_LINK); 369 nsi.setId(TestBackendConstants._TEST_TEMP_SOURCE_ID); 370 nsi.setVersion(null); 371 noesi.setNewSource(nsi); 372 373 374 NewOrExistingSourceInfo noesiTwo = new NewOrExistingSourceInfo(); 375 SourceInfo si = new SourceInfo(); 376 si.setLink(TestBackendConstants._TEST_NEW_SOURCE_LINK); 377 final SourceIdentifier sourceIdentifier = new SourceIdentifier(); 378 si.setRef(sourceIdentifier.toString()); 379 si.setVersion(null); 380 noesiTwo.setSource(si); 381 382 final Map<NewOrExistingSourceInfo, NewOrExistingSourceInfo> map = new HashMap<NewOrExistingSourceInfo, NewOrExistingSourceInfo>(); 383 map.put(noesi, noesiTwo); 384 385 386 // 275 387 // mockery.checking(new Expectations() { 276 388 // { 277 // oneOf(versionDao).deleteVersion(7); 278 // will(returnValue(versionDeleted)); // no other sources refer to this version # 5 279 // } 280 // }); 281 282 int[] resultTwo = daoDispatcher.deleteSourceWithVersions(5);// the source will be deleted because it is not referred by any annotation 283 assertEquals(1, resultTwo[0]); // row (5,7) in "sorces_versions" is deleted 284 assertEquals(1, resultTwo[1]); 285 } 286 287 /** 288 * Test of addVersion method, of class JdbcVersionDao. 289 */ 290 // @Test 291 // public void testAddCachedForVersion() { 292 // System.out.println("test addCachedForVersion"); 293 // 294 // final CachedRepresentationInfo cached = new CachedRepresentationInfo(); 295 // cached.setMimeType("text/plain"); 296 // cached.setTool("vi"); 297 // cached.setType("text"); 298 // cached.setRef(null); 299 // 300 // Number[] result = jdbcCachedRepresentationDao.addCachedForVersion(6, cached); 301 // assertEquals(8, result[0].intValue()); 302 // assertEquals(1, result[1].intValue()); 303 // } 304 /** 305 * 306 */ 307 // @Test 308 // public void tesDeleteCachedForVersion() { 309 // System.out.println("test delete CachedRepresentationForVersion"); 310 // System.out.println("deleteVersion"); 311 // 312 // int[] result = jdbcCachedRepresentationDao.deleteCachedForVersion(6, 5); 313 // assertEquals(1, result[0]); //versions-cached 314 // assertEquals(0, result[1]);//cached 5 is in use 315 // 316 // int[] resultTwo = jdbcCachedRepresentationDao.deleteCachedForVersion(6, 4); // no such pair 317 // assertEquals(0, resultTwo[0]); 318 // assertEquals(0, resultTwo[1]); 319 // 320 // 321 // } 322 // 323 // /** 324 // * Test of deleteVersionWithCachedRepresentations method, of class DaoDispatcher. 325 // */ 326 // @Test 327 // public void testDeleteVersionWithCachedRepresentations() { 328 // System.out.println("deleteVersionWithCachedRepresentations"); 329 // Number versionID = null; 330 // DaoDispatcher instance = new DaoDispatcher(); 331 // int[] expResult = null; 332 // int[] result = instance.deleteVersionWithCachedRepresentations(versionID); 333 // assertArrayEquals(expResult, result); 334 // // TODO review the generated test code and remove the default call to fail. 335 // fail("The test case is a prototype."); 336 // } 337 /** 338 * Test of deleteSourceWithVersions method, of class DaoDispatcher. 339 */ 340 @Test 341 public void testDeleteSourceWithVersions() throws SQLException { 342 System.out.println("deleteSourceWithVersions"); 343 Number sourceID = null; 344 DaoDispatcher instance = new DaoDispatcher(); 345 int[] expResult = null; 346 int[] result = instance.deleteSourceWithVersions(sourceID); 347 assertArrayEquals(expResult, result); 348 // TODO review the generated test code and remove the default call to fail. 349 fail("The test case is a prototype."); 350 } 351 352 /** 353 * Test of addSourceAndPairSourceVersion method, of class DaoDispatcher. 354 */ 355 @Test 356 public void testAddSourceAndPairSourceVersion() throws Exception { 357 System.out.println("addSourceAndPairSourceVersion"); 358 NewSourceInfo newSource = null; 359 DaoDispatcher instance = new DaoDispatcher(); 360 Number expResult = null; 361 Number result = instance.addSourceAndPairSourceVersion(newSource); 362 assertEquals(expResult, result); 363 // TODO review the generated test code and remove the default call to fail. 364 fail("The test case is a prototype."); 365 } 366 367 /** 368 * Test of addTargetSourcesToAnnotation method, of class DaoDispatcher. 369 */ 370 @Test 371 public void testAddTargetSourcesToAnnotation() throws Exception { 372 System.out.println("addTargetSourcesToAnnotation"); 373 374 375 // NewOrExistingSourceInfo noesi = new NewOrExistingSourceInfo(); 376 // NewSourceInfo nsi = new NewSourceInfo(); 377 // nsi.setLink(TestBackendConstants._TEST_NEW_SOURCE_LINK); 378 // nsi.setId(TestBackendConstants._TEST_TEMP_SOURCE_ID); 379 // nsi.setVersion(null); 380 // noesi.setNewSource(nsi); 381 // 382 // 383 // NewOrExistingSourceInfo noesiTwo = new NewOrExistingSourceInfo(); 384 // SourceInfo si = new SourceInfo(); 385 // si.setLink(TestBackendConstants._TEST_NEW_SOURCE_LINK); 386 // si.setRef((new SourceIdentifier()).toString()); 387 // si.setVersion(null); 388 // noesiTwo.setSource(si); 389 // 390 // final Map<NewOrExistingSourceInfo, NewOrExistingSourceInfo> map = new HashMap<NewOrExistingSourceInfo, NewOrExistingSourceInfo>(); 391 // map.put(noesi, noesiTwo); 392 // 393 // 394 // mockery.checking(new Expectations() { 395 // { 389 // oneOf(sourceDao.getInternalID(sourceIdentifier)); 390 // will(returnValue()); 391 // 392 // oneOf(annotationDao).addAnnotationSourcePair(with(aNonNull(Number.class)), with(aNonNull(Number.class))); 393 // will(returnValue(1)); 394 // 396 395 // oneOf(sourceDao).addTargetSources(with(aNonNull(Number.class)), with(aNonNull(List.class))); 397 396 // will(returnValue(map)); … … 400 399 401 400 402 Number annotationID = null; 403 List<NewOrExistingSourceInfo> sources = null; 404 DaoDispatcher instance = new DaoDispatcher(); 405 Map expResult = null; 406 Map result = instance.addTargetSourcesToAnnotation(annotationID, sources); 407 assertEquals(expResult, result); 408 // TODO review the generated test code and remove the default call to fail. 409 fail("The test case is a prototype."); 401 410 402 } 411 403
Note: See TracChangeset
for help on using the changeset viewer.