Changeset 3364
- Timestamp:
- 08/12/13 12:57:16 (11 years ago)
- Location:
- DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/Helpers.java
r3361 r3364 19 19 20 20 import java.sql.Timestamp; 21 import java.text.ParseException;22 import java.text.SimpleDateFormat;23 import java.util.Date;24 21 import java.util.GregorianCalendar; 25 import java.util.Locale;26 22 import javax.xml.datatype.DatatypeConfigurationException; 27 23 import javax.xml.datatype.DatatypeFactory; -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/impl/JdbcAnnotationDao.java
r3361 r3364 194 194 public int deleteAnnotation(Number annotationId) throws SQLException { 195 195 196 //TODO: why does it not work via calling notebook and permissions "remove" methods??197 198 196 String sqlNotebooks = "DELETE FROM " + notebooksAnnotationsTableName + " where " + annotation_id + " = ?"; 199 197 int affectedNotebooks = getSimpleJdbcTemplate().update(sqlNotebooks, annotationId); 200 198 201 String sqlPermissions = "DELETE FROM " + permissionsTableName + " where " + annotation_id + " = ?";199 String sqlPermissions = "DELETE FROM " + permissionsTableName + " where " + annotation_id + " = ?"; 202 200 int affectedPermissions = getSimpleJdbcTemplate().update(sqlPermissions, annotationId); 203 204 // TODO make a separate methods in sources DAO so that it handles removal of sources which are not referered by annotations 201 202 // safe removing sources 203 List<Number> sourceIDs = jdbcSourceDao.retrieveSourceIDs(annotationId); 205 204 String sqlTargetSources = "DELETE FROM " + annotationsSourcesTableName + " where " + annotation_id + " = ?"; 206 int affectedSources = getSimpleJdbcTemplate().update(sqlTargetSources, annotationId); 205 int affectedAnnotationsSources = getSimpleJdbcTemplate().update(sqlTargetSources, annotationId); 206 int affectedSources; 207 for (Number sourceID : sourceIDs) { 208 // call the method in sources DAO that handles removal of a source which is not refered by other annotations 209 affectedSources = jdbcSourceDao.deleteSource(sourceID); 210 } 207 211 208 212 String sqlAnnotation = "DELETE FROM " + annotationTableName + " where " + annotation_id + " = ?"; -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/impl/JdbcSourceDao.java
r3361 r3364 64 64 public List<Number> retrieveSourceIDs(Number annotationID) { 65 65 String sql = "SELECT " + source_id + " FROM " + annotationsSourcesTableName + " WHERE " + annotation_id + "= ?"; 66 List<Number> result = getSimpleJdbcTemplate().query(sql, annotationSourceRowMapper, annotationID); 67 68 if (result == null) { 69 return null; 70 } 71 if (result.isEmpty()) { 72 return null; 73 } 66 List<Number> result = getSimpleJdbcTemplate().query(sql, annotationSourceRowMapper, annotationID); 74 67 return result; 75 68 } -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/test/java/eu/dasish/annotation/backend/dao/impl/JdbcAnnotationDaoTest.java
r3361 r3364 18 18 package eu.dasish.annotation.backend.dao.impl; 19 19 20 import eu.dasish.annotation.backend.Helpers;21 20 import eu.dasish.annotation.backend.TestBackendConstants; 22 21 import eu.dasish.annotation.backend.TestInstances; … … 38 37 import java.util.List; 39 38 import java.util.Map; 40 import javax.xml.datatype.DatatypeConfigurationException;41 39 import org.jmock.Expectations; 42 40 import org.jmock.Mockery; 43 41 import static org.junit.Assert.*; 42 import org.junit.Ignore; 44 43 import org.junit.Test; 45 44 import org.junit.runner.RunWith; … … 229 228 public void testDeleteAnnotation() throws SQLException { 230 229 System.out.println("deleteAnnotation"); 231 232 mockery.checking(new Expectations() { 233 { 234 oneOf(permissionsDao).removeAnnotation(5); 230 final List<Number> sourceIDs = new ArrayList<Number>(); 231 sourceIDs.add(3); 232 sourceIDs.add(4); 233 234 mockery.checking(new Expectations() { 235 { 236 oneOf(sourceDao).retrieveSourceIDs(5); 237 will(returnValue(sourceIDs)); 238 239 oneOf(sourceDao).deleteSource(sourceIDs.get(0)); 240 will(returnValue(0)); 241 242 oneOf(sourceDao).deleteSource(sourceIDs.get(1)); 235 243 will(returnValue(1)); 236 237 oneOf(notebookDao).removeAnnotation(5);238 will(returnValue(3));239 244 } 240 245 }); … … 244 249 // now, try to delete the same annotation one more time 245 250 // if it has been already deleted then the method under testing should return 0 251 252 mockery.checking(new Expectations() { 253 { 254 oneOf(sourceDao).retrieveSourceIDs(5); 255 will(returnValue(new ArrayList<Number>())); 256 } 257 }); 246 258 result = jdbcAnnotationDao.deleteAnnotation(5); 247 259 assertEquals(0, result); … … 352 364 353 365 @Test 366 @Ignore 354 367 public void testGetExternalID() { 355 368 System.out.println("getAnnotationID");
Note: See TracChangeset
for help on using the changeset viewer.