Changeset 3303
- Timestamp:
- 08/08/13 08:26:22 (11 years ago)
- Location:
- DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/AnnotationDao.java
r3218 r3303 51 51 Annotation getAnnotation(Number annotationID) throws SQLException; 52 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; 60 53 61 54 /** 62 55 * -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/impl/JdbcAnnotationDao.java
r3272 r3303 195 195 196 196 197 ////////////////////////////////////////////////// 198 @Override 199 public Number getAnnotationID(AnnotationIdentifier externalID) throws SQLException{ 200 if (externalID == null) { 201 return null; 202 } 203 204 String sql = "SELECT "+annotationAnnotation_id+" FROM "+annotationTableName+" WHERE "+annotationExternal_id+" = ?"; 205 List<Number> result= getSimpleJdbcTemplate().query(sql, annotationIDRowMapper, externalID.toString()); 206 if (result == null) { 207 return null; 208 } 209 if (result.isEmpty()) { 210 return null; 211 } 212 213 if (result.size()>1) { 214 throw new SQLException("There are "+result.size()+" annotations with"+ external_id +" "+externalID); 215 } 216 return result.get(0); 217 } 218 219 private final RowMapper<Number> annotationIDRowMapper = new RowMapper<Number>() { 220 @Override 221 public Number mapRow(ResultSet rs, int rowNumber) throws SQLException { 222 Number result = rs.getInt(annotation_id); 223 return result; 224 } 225 }; 197 226 198 227 199 @Override … … 299 271 @Override 300 272 public AnnotationIdentifier getExternalID(Number internalID) { 301 if (internalID == null) { 302 return null; 303 } 304 305 String sql = "SELECT "+annotationExternal_id+" FROM "+annotationTableName+" WHERE "+annotationAnnotation_id+" = ?"; 306 List<AnnotationIdentifier> result= getSimpleJdbcTemplate().query(sql, externalIDRowMapper, internalID.toString()); 307 if (result == null) { 308 return null; 309 } 310 if (result.isEmpty()) { 311 return null; 312 } 313 return result.get(0); 273 return new AnnotationIdentifier(super.getExternalIdentifier(internalID)); 314 274 } 315 275 316 private final RowMapper<AnnotationIdentifier> externalIDRowMapper = new RowMapper<AnnotationIdentifier>() { 317 @Override 318 public AnnotationIdentifier mapRow(ResultSet rs, int rowNumber) throws SQLException { 319 AnnotationIdentifier result = new AnnotationIdentifier(rs.getString(external_id)); 320 return result; 321 } 322 }; 323 276 324 277 325 278 //////////// helpers /////////////////////// -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/impl/JdbcPermissionsDao.java
r3218 r3303 75 75 public int addAnnotationPrincipalPermission(AnnotationIdentifier annotationIdenitifier, UserIdentifier userIdentifier, Permission permission) throws SQLException { 76 76 Map<String, Object> paramsPermissions = new HashMap<String, Object>(); 77 paramsPermissions.put("annotationId", jdbcAnnotationDao.get AnnotationID(annotationIdenitifier));77 paramsPermissions.put("annotationId", jdbcAnnotationDao.getInternalID(annotationIdenitifier)); 78 78 paramsPermissions.put("principalId", jdbcUserDao.getInternalID(userIdentifier)); 79 79 paramsPermissions.put("status", permission.value()); -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/rest/AnnotationResource.java
r3218 r3303 77 77 @Path("{annotationid: " + BackendConstants.regExpIdentifier + "}") 78 78 public JAXBElement<Annotation> getAnnotation(@PathParam("annotationid") String annotationIdentifier) throws SQLException { 79 final Annotation annotation = annotationDao.getAnnotation(annotationDao.get AnnotationID(new AnnotationIdentifier(annotationIdentifier)));79 final Annotation annotation = annotationDao.getAnnotation(annotationDao.getInternalID(new AnnotationIdentifier(annotationIdentifier))); 80 80 return new ObjectFactory().createAnnotation(annotation); 81 81 } … … 87 87 */ 88 88 public String deleteAnnotation(@PathParam("annotationid") String annotationIdentifier) throws SQLException { 89 Number annotationID = annotationDao.get AnnotationID(new AnnotationIdentifier(annotationIdentifier));89 Number annotationID = annotationDao.getInternalID(new AnnotationIdentifier(annotationIdentifier)); 90 90 String result = Integer.toString(annotationDao.deleteAnnotation(annotationID)); 91 91 return result; -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/test/java/eu/dasish/annotation/backend/dao/impl/JdbcAnnotationDaoTest.java
r3220 r3303 142 142 System.out.println("getAnnotationID"); 143 143 144 final Number annotaionId = jdbcAnnotationDao.get AnnotationID(new AnnotationIdentifier(TestBackendConstants._TEST_ANNOT_2_EXT));144 final Number annotaionId = jdbcAnnotationDao.getInternalID(new AnnotationIdentifier(TestBackendConstants._TEST_ANNOT_2_EXT)); 145 145 assertEquals(2, annotaionId.intValue()); 146 146 147 final Number annotaionIdNE = jdbcAnnotationDao.get AnnotationID(new AnnotationIdentifier(TestBackendConstants._TEST_ANNOT_7_EXT_NOT_IN_DB));147 final Number annotaionIdNE = jdbcAnnotationDao.getInternalID(new AnnotationIdentifier(TestBackendConstants._TEST_ANNOT_7_EXT_NOT_IN_DB)); 148 148 assertEquals(null, annotaionIdNE); 149 149 150 final Number annotaionIdNull = jdbcAnnotationDao.get AnnotationID(null);150 final Number annotaionIdNull = jdbcAnnotationDao.getInternalID(null); 151 151 assertEquals(null, annotaionIdNull); 152 152 } … … 274 274 275 275 AnnotationIdentifier generatedAnnotationExternalID = new AnnotationIdentifier(result.getURI()); 276 Annotation addedAnnotation = jdbcAnnotationDao.getAnnotation(jdbcAnnotationDao.get AnnotationID(generatedAnnotationExternalID));276 Annotation addedAnnotation = jdbcAnnotationDao.getAnnotation(jdbcAnnotationDao.getInternalID(generatedAnnotationExternalID)); 277 277 assertEquals(annotationToAdd.getBody().getAny().get(0), addedAnnotation.getBody().getAny().get(0)); 278 278 assertEquals(annotationToAdd.getHeadline(), addedAnnotation.getHeadline()); … … 299 299 300 300 final AnnotationIdentifier externalIdThree = jdbcAnnotationDao.getExternalID(null); 301 assertEquals(null, externalIdThree );301 assertEquals(null, externalIdThree.getUUID()); 302 302 303 303 } -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/test/java/eu/dasish/annotation/backend/rest/AnnotationResourceTest.java
r3218 r3303 82 82 mockery.checking(new Expectations() { 83 83 { 84 oneOf(annotationDao).get AnnotationID(new AnnotationIdentifier(annotationIdentifier));84 oneOf(annotationDao).getInternalID(new AnnotationIdentifier(annotationIdentifier)); 85 85 will(returnValue(annotationID)); 86 86 … … 103 103 mockery.checking(new Expectations() { 104 104 { 105 oneOf(annotationDao).get AnnotationID(new AnnotationIdentifier(TestBackendConstants._TEST_ANNOT_5_EXT));105 oneOf(annotationDao).getInternalID(new AnnotationIdentifier(TestBackendConstants._TEST_ANNOT_5_EXT)); 106 106 will(returnValue(5)); 107 107 … … 118 118 mockery.checking(new Expectations() { 119 119 { 120 oneOf(annotationDao).get AnnotationID(new AnnotationIdentifier(TestBackendConstants._TEST_ANNOT_5_EXT));120 oneOf(annotationDao).getInternalID(new AnnotationIdentifier(TestBackendConstants._TEST_ANNOT_5_EXT)); 121 121 will(returnValue(5)); 122 122 -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/test/java/eu/dasish/annotation/backend/rest/AnnotationsTest.java
r3218 r3303 67 67 mockery.checking(new Expectations() { 68 68 { 69 oneOf(annotationDao).get AnnotationID(new AnnotationIdentifier(annotationIdentifier));69 oneOf(annotationDao).getInternalID(new AnnotationIdentifier(annotationIdentifier)); 70 70 will(returnValue(annotationID)); 71 71 … … 99 99 mockery.checking(new Expectations() { 100 100 { 101 oneOf(annotationDao).get AnnotationID(new AnnotationIdentifier(TestBackendConstants._TEST_ANNOT_5_EXT));101 oneOf(annotationDao).getInternalID(new AnnotationIdentifier(TestBackendConstants._TEST_ANNOT_5_EXT)); 102 102 will(returnValue(5)); 103 103 … … 118 118 mockery.checking(new Expectations() { 119 119 { 120 oneOf(annotationDao).get AnnotationID(new AnnotationIdentifier(TestBackendConstants._TEST_ANNOT_5_EXT));120 oneOf(annotationDao).getInternalID(new AnnotationIdentifier(TestBackendConstants._TEST_ANNOT_5_EXT)); 121 121 will(returnValue(5)); 122 122
Note: See TracChangeset
for help on using the changeset viewer.