Changeset 3144
- Timestamp:
- 07/17/13 09:07:22 (11 years ago)
- Location:
- DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/impl/JdbcAnnotationDao.java
r3142 r3144 46 46 } 47 47 48 ////////////////////////////////////////// 49 /** 50 * 51 * @param notebookID 52 * @return false if notebookID == null or the notebook with notebookID is not in the DB; 53 * @return true if the notebook with notebookID in the DB 54 */ 55 public boolean isNotebookInTheDataBase(Number notebookID){ 56 57 if (notebookID == null) { 58 return false; 59 } 60 String sql = "SELECT notebook.notebook_id FROM notebook where notebook_id = ?"; 61 List<Number> result=getSimpleJdbcTemplate().query(sql, isNotebookInTheDataBaseRowMapper, notebookID.toString()); 62 if (result == null) { 63 return false; 64 } 65 if (result.isEmpty()) { 66 return false; 67 } 68 return true; 69 } 70 71 private final RowMapper<Number> isNotebookInTheDataBaseRowMapper = new RowMapper<Number>() { 72 @Override 73 public Integer mapRow(ResultSet rs, int rowNumber) throws SQLException { 74 Integer notebookId = rs.getInt("notebook_id"); 75 return notebookId; 76 } 77 }; 78 48 79 //////////////////////////////////////////////////////////////////////// 49 80 /** … … 51 82 * @param notebookID 52 83 * @return the list of annotation-ids belonging to the notebook with notebookId 53 * returns null if notebookId is null 54 * returns empty list if notebookId is not in the DB: getSimpleJdbcTemplate().query is implemented in this way 84 * returns null if notebookId is null or is not in the DB 55 85 * TODO: do we need to return null here? using an additional check. 56 86 */ 57 87 @Override 58 88 public List<Number> getAnnotationIDs(Number notebookID) { 59 if (notebookID == null) { 60 return null; 61 } 62 String sql = "SELECT notebooks_annotations.annotation_id FROM notebooks_annotations where notebook_id = ?"; 63 return getSimpleJdbcTemplate().query(sql, annotationIDRowMapper, notebookID.toString()); 89 if (notebookID == null) { 90 return null; 91 } 92 93 if (isNotebookInTheDataBase(notebookID)) { 94 String sql = "SELECT notebooks_annotations.annotation_id FROM notebooks_annotations where notebook_id = ?"; 95 return getSimpleJdbcTemplate().query(sql, annotationIDRowMapper, notebookID.toString()); 96 } else { 97 return null; 98 } 64 99 } 65 100 … … 78 113 * @param annotationIDs is a list of internal annotation identifiers 79 114 * @return the list of the corresponding annotation-infos for the annotation identifiers from the list; 80 * if the input list is null or empty (zero elements) returns an empty list 115 * if the input list is null return null 116 * if the input list is empty (zero elements) returns an empty list 81 117 */ 82 118 … … 115 151 * @param notebookID 116 152 * @return the list of annotation-infos of the annotations from notebookID; 153 * if notebook not in the DB or null returns null 117 154 * if the notebook contains no annotations returns an empty list 118 155 */ … … 162 199 * @param notebookID 163 200 * @return the list of annotation References from the notebookID 164 * returns null if notebookID == null 201 * returns null if notebookID == null or it does not exists in the DB 165 202 */ 166 203 … … 177 214 * @param notebookID 178 215 * @return the Annotations (as a list of references) from the notebookID * 179 * returns null if notebookID == null 180 */ 181 182 @Override 183 public Annotations getAnnotations(Number notebookID) { 184 216 * returns null if notebookID == null, or it does not exists in th DB, or the list of annotations is empty, 217 * or something wrong happened when extracting annotations from the notebook 218 * (according to dasish.xsd if an Annotation is created then its list of annotations must contain at least one element!) 219 * 220 */ 221 222 @Override 223 public Annotations getAnnotations(Number notebookID) { 224 185 225 if (notebookID == null) { 186 226 return null; 187 227 } 188 189 Annotations result = new Annotations(); 190 List<ResourceREF> annotREFs = result.getAnnotation(); 191 // TODO: what of annotREFS is null???? how to allocated emprey for it??? 192 boolean test = annotREFs.addAll(getAnnotationREFsOfNotebook(notebookID)); 193 return (test ? result : null); 228 229 if (isNotebookInTheDataBase(notebookID)) { 230 Annotations result = new Annotations(); 231 List<ResourceREF> annotREFs = result.getAnnotation(); 232 // TODO: what of annotREFS is null???? 233 boolean test = annotREFs.addAll(getAnnotationREFsOfNotebook(notebookID)); 234 return (test ? result : null); 235 } else { 236 return null; 237 } 238 194 239 } 195 240 … … 230 275 231 276 } 277 -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/test/java/eu/dasish/annotation/backend/dao/impl/JdbcAnnotationDaoTest.java
r3142 r3144 100 100 public void tearDown() { 101 101 } 102 103 104 /** 105 * Test of getAnnotationIDs method, of class JdbcAnnotationDao. 106 * boolean isNotebookInTheDataBase(Number notebookID) 107 */ 108 @Test 109 public void testIsNotebookInTheDataBase() { 110 System.out.println("isNotebookInTheDataBase"); 111 112 final boolean testOne = jdbcAnnotationDao.isNotebookInTheDataBase(TestBackendConstants._TEST_NOTEBOOK_1_INT); 113 assertEquals(true, testOne); 114 115 final boolean testTwo = jdbcAnnotationDao.isNotebookInTheDataBase(TestBackendConstants._TEST_NOTEBOOK_2_INT); 116 assertEquals(true, testTwo); 117 118 final boolean testThree = jdbcAnnotationDao.isNotebookInTheDataBase(TestBackendConstants._TEST_NOTEBOOK_3_INT); 119 assertEquals(true, testThree); 120 121 final boolean testFour = jdbcAnnotationDao.isNotebookInTheDataBase(TestBackendConstants._TEST_ANNOT_4_INT_NOT_IN_THE_DB); 122 assertEquals(false, testFour); 123 124 final boolean testFive = jdbcAnnotationDao.isNotebookInTheDataBase(null); 125 assertEquals(false, testFive); 126 } 102 127 103 128 /** … … 130 155 //test five, the notebook not in the DB 131 156 final List<Number> annotationIDsFive = jdbcAnnotationDao.getAnnotationIDs(TestBackendConstants._TEST_ANNOT_4_INT_NOT_IN_THE_DB); 132 assertEquals(n ew ArrayList<Number>(), annotationIDsFive);157 assertEquals(null, annotationIDsFive); 133 158 134 159 } … … 138 163 * List<AnnotationInfo> getAnnotationInfos(List<Number> annotationIDs) 139 164 */ 140 @Test 141 165 @Test 142 166 public void testGetAnnotationInfos() { 143 167 System.out.println("getAnnotationInfos"); … … 206 230 //non-existing notebook 207 231 final List<AnnotationInfo> annotationInfosFour = jdbcAnnotationDao.getAnnotationInfosOfNotebook(TestBackendConstants._TEST_ANNOT_4_INT_NOT_IN_THE_DB); 208 assertEquals( 0, annotationInfosFour.size());232 assertEquals(null, annotationInfosFour); 209 233 210 234 … … 266 290 assertEquals(0, testListThree.size()); 267 291 268 // test F ive, non-existing notebook292 // test Four, non-existing notebook 269 293 List<ResourceREF> testListFour = jdbcAnnotationDao.getAnnotationREFsOfNotebook(TestBackendConstants._TEST_ANNOT_4_INT_NOT_IN_THE_DB); 270 assertEquals( 0, testListFour.size());294 assertEquals(null, testListFour); 271 295 272 296 // test Five Null-notebook … … 277 301 /** 278 302 * Test of getAnnotations method, of class JdbcAnnotationDao. 279 * /280 @Test281 @ Ignore303 * Annotations getAnnotations(Number notebookID) 304 */ 305 @Test 282 306 public void testGetAnnotations() { 283 307 System.out.println("getAnnotations"); 284 Number notebookID = null; 285 JdbcAnnotationDao instance = null; 286 Annotations expResult = null; 287 Annotations result = instance.getAnnotations(notebookID); 288 assertEquals(expResult, result); 289 // TODO review the generated test code and remove the default call to fail. 290 fail("The test case is a prototype."); 308 309 // test One 310 Annotations annotations = jdbcAnnotationDao.getAnnotations(TestBackendConstants._TEST_NOTEBOOK_1_INT); 311 assertEquals(2, annotations.getAnnotation().size()); 312 assertEquals(String.valueOf(TestBackendConstants._TEST_ANNOT_1_INT), annotations.getAnnotation().get(0).getRef()); 313 assertEquals(String.valueOf(TestBackendConstants._TEST_ANNOT_2_INT), annotations.getAnnotation().get(1).getRef()); 314 315 // test One 316 Annotations annotationsTwo = jdbcAnnotationDao.getAnnotations(TestBackendConstants._TEST_NOTEBOOK_2_INT); 317 assertEquals(1, annotationsTwo.getAnnotation().size()); 318 assertEquals(String.valueOf(TestBackendConstants._TEST_ANNOT_3_INT), annotationsTwo.getAnnotation().get(0).getRef()); 319 320 // test Three "empty" list of annotations 321 // according to dasish.xsd if an Annotation is created then its list of annotations must contain at least one element! 322 // therefore: no annotations in the notebook ==> Annotations-pbject must be null :( 323 Annotations annotationsThree = jdbcAnnotationDao.getAnnotations(TestBackendConstants._TEST_NOTEBOOK_3_INT); 324 assertEquals(null, annotationsThree); 325 326 // test Five, non-existing notebook 327 Annotations annotationsFour = jdbcAnnotationDao.getAnnotations(TestBackendConstants._TEST_ANNOT_4_INT_NOT_IN_THE_DB); 328 assertEquals(null, annotationsFour); 329 330 // test Five Null-notebook 331 Annotations annotationsFive = jdbcAnnotationDao.getAnnotations(null); 332 assertEquals(null, annotationsFive); 291 333 } 292 334 }
Note: See TracChangeset
for help on using the changeset viewer.