Changeset 3142
- Timestamp:
- 07/16/13 15:37:12 (11 years ago)
- Location:
- DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src
- Files:
-
- 1 added
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/AnnotationDao.java
r3138 r3142 28 28 * @author Peter Withers <peter.withers@mpi.nl> 29 29 */ 30 31 // TODO: Getting Target Sources from Body and testing must be added!!! 32 33 30 34 public interface AnnotationDao { 31 35 … … 34 38 35 39 // Returns the list of annotation info-s for the notebook id. 36 List<AnnotationInfo> getAnnotationInfos(Number notebookID); 40 List<AnnotationInfo> getAnnotationInfos(List<Number> annotationIDs); 41 42 // Returns the list of annotation info-s for the notebook id. 43 List<AnnotationInfo> getAnnotationInfosOfNotebook(Number notebookID); 44 37 45 38 46 // Returns the list of annotations Id-s for the notebook id. 39 List<ResourceREF> getAnnotationREFs(Number notebookID); 47 List<ResourceREF> getAnnotationREFs(List<Number> annotationIDs); 48 49 // Returns the list of annotations Id-s for the notebook id. 50 List<ResourceREF> getAnnotationREFsOfNotebook(Number notebookID); 40 51 41 52 // Returns the annotations object for the notebook id. -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/impl/JdbcAnnotationDao.java
r3138 r3142 19 19 20 20 import eu.dasish.annotation.backend.dao.AnnotationDao; 21 import eu.dasish.annotation.schema.Annotation;22 21 import eu.dasish.annotation.schema.AnnotationInfo; 23 22 import eu.dasish.annotation.schema.Annotations; … … 26 25 import java.sql.ResultSet; 27 26 import java.sql.SQLException; 27 import java.util.ArrayList; 28 28 import java.util.List; 29 29 import javax.sql.DataSource; … … 37 37 */ 38 38 39 /* 40 * annotation ( 41 annotation_id SERIAL UNIQUE NOT NULL, 42 external_id UUID UNIQUE NOT NULL, 43 time_stamp timestamp with time zone default now(), 44 owner_id integer, 45 headline tCRext, 46 body_xml xml 47 ); 48 * 49 * 50 */ 39 51 40 52 41 … … 58 47 59 48 //////////////////////////////////////////////////////////////////////// 49 /** 50 * 51 * @param notebookID 52 * @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 55 * TODO: do we need to return null here? using an additional check. 56 */ 60 57 @Override 61 58 public List<Number> getAnnotationIDs(Number notebookID) { 59 if (notebookID == null) { 60 return null; 61 } 62 62 String sql = "SELECT notebooks_annotations.annotation_id FROM notebooks_annotations where notebook_id = ?"; 63 63 return getSimpleJdbcTemplate().query(sql, annotationIDRowMapper, notebookID.toString()); … … 74 74 //////////////////////////////////////////////////////////////////////////// 75 75 76 @Override 77 public List<AnnotationInfo> getAnnotationInfos(Number notebookID) { 78 String sql = "SELECT annotation.* FROM annotation WHERE annotation.annotation_id IN ?"; 79 return getSimpleJdbcTemplate().query(sql, annotationInfoRowMapper, getAnnotationIDs(notebookID)); 76 /** 77 * 78 * @param annotationIDs is a list of internal annotation identifiers 79 * @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 81 */ 82 83 @Override 84 public List<AnnotationInfo> getAnnotationInfos(List<Number> annotationIDs) { 85 86 if (annotationIDs == null) { 87 return null; 88 } 89 90 if (annotationIDs.isEmpty()) { 91 return (new ArrayList<AnnotationInfo>()); 92 } 93 94 String values = makeListOfValues(annotationIDs); 95 String sql = "SELECT annotation.* FROM annotation WHERE annotation.annotation_id IN "+values; 96 return getSimpleJdbcTemplate().query(sql, annotationInfoRowMapper); 80 97 } 81 98 … … 92 109 93 110 111 ////////////////////////////////////////////////// 112 113 /** 114 * 115 * @param notebookID 116 * @return the list of annotation-infos of the annotations from notebookID; 117 * if the notebook contains no annotations returns an empty list 118 */ 119 120 @Override 121 public List<AnnotationInfo> getAnnotationInfosOfNotebook(Number notebookID) { 122 return getAnnotationInfos(getAnnotationIDs(notebookID)); 123 } 124 94 125 ///////////////////////////////////////////////// 95 126 96 @Override 97 public List<ResourceREF> getAnnotationREFs(Number notebookID) { 98 String sql = "SELECT annotation.annotation_id FROM annotation WHERE annotation.annotation_id IN ?"; 99 return getSimpleJdbcTemplate().query(sql, annotationREFRowMapper, getAnnotationIDs(notebookID)); 127 /** 128 * 129 * @param annotationIDs 130 * @return list of annotation references corresponding to the annotation-ids from the input list 131 * if the input list is null or empty (zero elements) returns an empty list 132 */ 133 134 @Override 135 public List<ResourceREF> getAnnotationREFs(List<Number> annotationIDs) { 136 137 if (annotationIDs == null) { 138 return null; 139 } 140 141 if (annotationIDs.isEmpty()) { 142 return (new ArrayList<ResourceREF>()); 143 } 144 145 String values = makeListOfValues(annotationIDs); 146 String sql = "SELECT annotation.annotation_id FROM annotation WHERE annotation.annotation_id IN "+values; 147 return getSimpleJdbcTemplate().query(sql, annotationREFRowMapper); 100 148 } 101 149 … … 109 157 }; 110 158 159 ////////////////////////////////////////////// 160 /** 161 * 162 * @param notebookID 163 * @return the list of annotation References from the notebookID 164 * returns null if notebookID == null 165 */ 166 167 @Override 168 public List<ResourceREF> getAnnotationREFsOfNotebook(Number notebookID) { 169 return getAnnotationREFs(getAnnotationIDs(notebookID)); 170 } 171 172 173 174 //////////////////////////////////////////////////////////////////////////// 175 /** 176 * 177 * @param notebookID 178 * @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 185 if (notebookID == null) { 186 return null; 187 } 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); 194 } 195 196 111 197 ///////////////////////////////////////////////// 112 198 private ResourceREF getResourceREF(String resourceID){ … … 118 204 //TODO implement when xml-body stucture is discussed! 119 205 //BTW do we have to get source REF, not the whole sources here?? 120 private Sources getSources(String some _xml) {206 private Sources getSources(String someXml) { 121 207 Sources result = new Sources(); 122 208 return result; 123 209 } 124 210 125 126 127 //////////////////////////////////////////////////////////////////////////// 128 129 @Override 130 public Annotations getAnnotations(Number notebookID) { 131 String sql = "SELECT annotation.* FROM annotation WHERE annotation.annotation_id IN ?"; 132 return null; // not omplemented yet 133 134 } 211 private <T> String makeListOfValues(List<T> vals) { 212 213 if (vals == null) { 214 return "()"; 215 } 216 217 if (vals.isEmpty()) { 218 return "()"; 219 } 220 221 String result = "("; 222 int length = vals.size(); 223 for (int i=0; i<length-1; i++){ 224 result = result + vals.get(i).toString() +", "; 225 } 226 result = result +vals.get(length-1).toString()+")"; 227 return result; 228 } 229 135 230 136 231 } -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/test/java/eu/dasish/annotation/backend/TestBackendConstants.java
r3137 r3142 31 31 public static final String _TEST_AID_1_ = "00000000-0000-0000-0000-000000000005"; 32 32 public static final String _TEST_NULL_UUID_ = "00000000-0000-0000-0000-000000000006"; 33 33 34 // testing jdbcAnnotationDao 35 public static final String _TEST_NOTEBOOK_1_EXT = "00000000-0000-0000-0000-000000000011"; 36 public static final String _TEST_NOTEBOOK_2_EXT = "00000000-0000-0000-0000-000000000012"; 37 public static final String _TEST_NOTEBOOK_3_EXT = "00000000-0000-0000-0000-000000000013"; 38 39 public static final int _TEST_NOTEBOOK_1_INT = 11; 40 public static final int _TEST_NOTEBOOK_2_INT = 12; 41 public static final int _TEST_NOTEBOOK_3_INT = 13; 42 43 public static final String _TEST_ANNOT_1_EXT = "00000000-0000-0000-0000-000000000021"; 44 public static final String _TEST_ANNOT_2_EXT = "00000000-0000-0000-0000-000000000022"; 45 public static final String _TEST_ANNOT_3_EXT = "00000000-0000-0000-0000-000000000023"; 46 47 public static final int _TEST_ANNOT_1_INT = 21; 48 public static final int _TEST_ANNOT_2_INT = 22; 49 public static final int _TEST_ANNOT_3_INT = 23; 50 public static final int _TEST_ANNOT_4_INT_NOT_IN_THE_DB = 24; 51 52 public static final String _TEST_ANNOT_1_HEADLINE = "Sagrada Famiglia"; 53 public static final String _TEST_ANNOT_2_HEADLINE = "Gaudi"; 54 public static final String _TEST_ANNOT_3_HEADLINE = "Art Nuveau"; 55 56 public static final int _TEST_ANNOT_1_OWNER = 111; 57 public static final int _TEST_ANNOT_2_OWNER = 112; 58 public static final int _TEST_ANNOT_3_OWNER = 113; 59 34 60 } 35 61 -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/test/resources/test-data/InsertTestData.sql
r3137 r3142 28 28 INSERT INTO notebooks_annotations (notebook_id,annotation_id) VALUES (1,1); 29 29 INSERT INTO notebooks_annotations (notebook_id,annotation_id) VALUES (2,1); 30 31 32 -- Test data for jdbcAnnotationDao -- 33 34 INSERT INTO notebook (notebook_id, title, owner_id, external_id) VALUES (11, 'Notebook 11', 111, '00000000-0000-0000-0000-000000000011'); 35 INSERT INTO notebook (notebook_id, title, owner_id, external_id) VALUES (12, 'Notebook 12', 112, '00000000-0000-0000-0000-000000000012'); 36 INSERT INTO notebook (notebook_id, title, owner_id, external_id) VALUES (13, 'Notebook 13', 113, '00000000-0000-0000-0000-000000000013'); 37 38 INSERT INTO annotation (annotation_id, owner_id,headline,body_xml, external_id) VALUES (21, 111, 'Sagrada Famiglia','<html><body>some html</body></html>', '00000000-0000-0000-0000-000000000021'); 39 INSERT INTO annotation (annotation_id, owner_id,headline,body_xml, external_id) VALUES (22, 112, 'Gaudi','<html><body>some html</body></html>', '00000000-0000-0000-0000-000000000022'); 40 INSERT INTO annotation (annotation_id, owner_id,headline,body_xml, external_id) VALUES (23, 113, 'Art Nuveau','<html><body>some html</body></html>', '00000000-0000-0000-0000-000000000023'); 41 42 INSERT INTO notebooks_annotations (notebook_id,annotation_id) VALUES (11,21); 43 INSERT INTO notebooks_annotations (notebook_id,annotation_id) VALUES (11,22); 44 INSERT INTO notebooks_annotations (notebook_id,annotation_id) VALUES (12,23); 45 46
Note: See TracChangeset
for help on using the changeset viewer.