Changeset 3152
- Timestamp:
- 07/17/13 16:01:11 (11 years ago)
- Location:
- DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/AnnotationDao.java
r3151 r3152 18 18 package eu.dasish.annotation.backend.dao; 19 19 20 import eu.dasish.annotation.backend.identifiers.AnnotationIdentifier; 21 import eu.dasish.annotation.schema.Annotation; 20 22 import eu.dasish.annotation.schema.AnnotationInfo; 21 import eu.dasish.annotation.schema.Annotations;22 23 import eu.dasish.annotation.schema.ResourceREF; 24 import java.sql.SQLException; 23 25 import java.util.List; 24 26 … … 41 43 List<ResourceREF> getAnnotationREFs(List<Number> annotationIDs); 42 44 43 45 /** 46 * 47 * @param annotationID 48 * @return annotation which has an annotation ID "annotationID" 49 * if externalID is null or such annotation does not exist in the DB returns null; 50 */ 51 Annotation getAnnotation(Number annotationID) throws SQLException; 52 53 /** 54 * 55 * @param externalID 56 * @return the internal annotationId for the annotation with the external Id "extrnalID" 57 * if annotationID is null or such annotation does not exist in the DB returns null; 58 */ 59 Number getAnnotationID(AnnotationIdentifier externalID) throws SQLException; 44 60 } -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/impl/JdbcAnnotationDao.java
r3151 r3152 19 19 20 20 import eu.dasish.annotation.backend.dao.AnnotationDao; 21 import eu.dasish.annotation.backend.identifiers.AnnotationIdentifier; 22 import eu.dasish.annotation.schema.Annotation; 23 import eu.dasish.annotation.schema.AnnotationBody; 21 24 import eu.dasish.annotation.schema.AnnotationInfo; 22 import eu.dasish.annotation.schema.Annotations;23 25 import eu.dasish.annotation.schema.ResourceREF; 24 26 import eu.dasish.annotation.schema.Sources; … … 29 31 import javax.sql.DataSource; 30 32 import org.springframework.jdbc.core.RowMapper; 31 import org.springframework.jdbc.core.simple.SimpleJdbcDaoSupport;32 33 33 34 /** … … 121 122 }; 122 123 123 124 125 126 124 ////////////////////////////////////////////// 125 /* CREATE TABLE annotation ( 126 annotation_id SERIAL UNIQUE NOT NULL, 127 external_id UUID UNIQUE NOT NULL, 128 time_stamp timestamp with time zone default now(), 129 owner_id integer, 130 headline text, 131 body_xml xml */ 132 133 @Override 134 public Annotation getAnnotation(Number annotationID) throws SQLException{ 135 if (annotationID == null) { 136 return null; 137 } 138 String sql = "SELECT * FROM annotation WHERE annotation.annotation_id = ?"; 139 List<Annotation> result= getSimpleJdbcTemplate().query(sql, annotationRowMapper, annotationID); 140 141 if (result == null) { 142 return null; 143 } 144 if (result.isEmpty()) { 145 return null; 146 } 147 148 if (result.size()>1) { 149 throw new SQLException("There are "+result.size()+" annotations with annotation_id "+annotationID); 150 } 151 return result.get(0); 152 } 153 154 private final RowMapper<Annotation> annotationRowMapper = new RowMapper<Annotation>() { 155 @Override 156 public Annotation mapRow(ResultSet rs, int rowNumber) throws SQLException { 157 Annotation result = new Annotation(); 158 result.setHeadline(rs.getString("headline")); 159 160 ResourceREF ownerREF = new ResourceREF(); 161 ownerREF.setRef(String.valueOf(rs.getInt("owner_id"))); 162 result.setOwner(ownerREF); 163 164 /*TODO 165 * Add permissions also to the database 166 * ResourceREF permissionsREF = new ResourceREF(); 167 permissionsREF.setRef(String.valueOf(rs.getInt("permissions"))); 168 result.setPermissions(permissionsREF);*/ 169 170 171 // TODO: add source, also to the database 172 173 result.setBody(convertToAnnotationBody(rs.getString("body_xml"))); 174 return result; 175 } 176 }; 177 178 // TODO: fill in the stub, when the annotation body is elaborated 179 private AnnotationBody convertToAnnotationBody(String input){ 180 if (input == null) { 181 return null; 182 } 183 184 AnnotationBody result = new AnnotationBody(); 185 List<Object> element =result.getAny(); 186 element.add(input); 187 return result; 188 } 189 190 191 ////////////////////////////////////////////////// 192 @Override 193 public Number getAnnotationID(AnnotationIdentifier externalID) throws SQLException{ 194 if (externalID == null) { 195 return null; 196 } 197 198 String sql = "SELECT annotation.annotation_id FROM annotation WHERE annotation.external_id = ?"; 199 List<Number> result= getSimpleJdbcTemplate().query(sql, annotationIDRowMapper, externalID.toString()); 200 if (result == null) { 201 return null; 202 } 203 if (result.isEmpty()) { 204 return null; 205 } 206 207 if (result.size()>1) { 208 throw new SQLException("There are "+result.size()+" annotations with external_id "+externalID); 209 } 210 return result.get(0); 211 } 212 213 private final RowMapper<Number> annotationIDRowMapper = new RowMapper<Number>() { 214 @Override 215 public Number mapRow(ResultSet rs, int rowNumber) throws SQLException { 216 Number result = rs.getInt("annotation_id"); 217 return result; 218 } 219 }; 220 221 222 //////////// helpers /////////////////////// 127 223 128 224 ///////////////////////////////////////////////// -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/test/java/eu/dasish/annotation/backend/TestBackendConstants.java
r3142 r3152 44 44 public static final String _TEST_ANNOT_2_EXT = "00000000-0000-0000-0000-000000000022"; 45 45 public static final String _TEST_ANNOT_3_EXT = "00000000-0000-0000-0000-000000000023"; 46 public static final String _TEST_ANNOT_4_EXT_NOT_IN_THE_DB = "00000000-0000-0000-0000-000000000024"; 46 47 47 48 public static final int _TEST_ANNOT_1_INT = 21; … … 58 59 public static final int _TEST_ANNOT_3_OWNER = 113; 59 60 61 public static final String _TEST_ANNOT_1_BODY = "<html><body>some html 1</body></html>"; 62 60 63 } 61 64 -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/test/java/eu/dasish/annotation/backend/dao/impl/JdbcAnnotationDaoTest.java
r3151 r3152 19 19 20 20 import eu.dasish.annotation.backend.TestBackendConstants; 21 import eu.dasish.annotation.backend.identifiers.AnnotationIdentifier; 22 import eu.dasish.annotation.schema.Annotation; 21 23 import eu.dasish.annotation.schema.AnnotationInfo; 22 24 import eu.dasish.annotation.schema.ResourceREF; 25 import java.sql.SQLException; 23 26 import java.util.ArrayList; 24 27 import java.util.List; … … 112 115 113 116 } 114 117 /** 118 * 119 * Test of getAnnotationID method, of class JdbcAnnotationDao. 120 * Integer getAnnotationID(AnnotationIdentifier externalID) 121 */ 122 @Test 123 public void getAnnotationID() throws SQLException{ 124 System.out.println("getAnnotationID"); 125 126 final Number annotaionId = jdbcAnnotationDao.getAnnotationID(new AnnotationIdentifier(TestBackendConstants._TEST_ANNOT_1_EXT)); 127 assertEquals(TestBackendConstants._TEST_ANNOT_1_INT, annotaionId.intValue()); 128 129 final Number annotaionIdNE = jdbcAnnotationDao.getAnnotationID(new AnnotationIdentifier(TestBackendConstants._TEST_ANNOT_4_EXT_NOT_IN_THE_DB)); 130 assertEquals(null, annotaionIdNE); 131 132 final Number annotaionIdNull = jdbcAnnotationDao.getAnnotationID(null); 133 assertEquals(null, annotaionIdNull); 134 } 135 136 /** 137 * 138 * Test of getAnnotation method, of class JdbcAnnotationDao. 139 * Annotation getAnnotation(Number annotationlID) 140 */ 141 @Test 142 public void getAnnotation() throws SQLException{ 143 System.out.println("getAnnotation"); 144 145 final Annotation annotaion = jdbcAnnotationDao.getAnnotation(TestBackendConstants._TEST_ANNOT_1_INT); 146 assertEquals(TestBackendConstants._TEST_ANNOT_1_HEADLINE, annotaion.getHeadline()); 147 assertEquals(String.valueOf(TestBackendConstants._TEST_ANNOT_1_OWNER), annotaion.getOwner().getRef()); 148 assertEquals(TestBackendConstants._TEST_ANNOT_1_BODY, annotaion.getBody().getAny().get(0)); // when the body is elaborated it will be changed 149 150 final Annotation annotaionNE = jdbcAnnotationDao.getAnnotation(TestBackendConstants._TEST_ANNOT_4_INT_NOT_IN_THE_DB); 151 assertEquals(null, annotaionNE); 152 153 final Annotation annotaionNull = jdbcAnnotationDao.getAnnotation(null); 154 assertEquals(null, annotaionNull); 155 } 115 156 116 157 } -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/test/resources/test-data/InsertTestData.sql
r3142 r3152 36 36 INSERT INTO notebook (notebook_id, title, owner_id, external_id) VALUES (13, 'Notebook 13', 113, '00000000-0000-0000-0000-000000000013'); 37 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');38 INSERT INTO annotation (annotation_id, owner_id,headline,body_xml, external_id) VALUES (21, 111, 'Sagrada Famiglia','<html><body>some html 1</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 2 </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 3</body></html>', '00000000-0000-0000-0000-000000000023'); 41 41 42 42 INSERT INTO notebooks_annotations (notebook_id,annotation_id) VALUES (11,21);
Note: See TracChangeset
for help on using the changeset viewer.