Changeset 3364


Ignore:
Timestamp:
08/12/13 12:57:16 (11 years ago)
Author:
olhsha
Message:

safe removing sources (if not other annotation refers) is incorporated into remove annotation

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  
    1919
    2020import java.sql.Timestamp;
    21 import java.text.ParseException;
    22 import java.text.SimpleDateFormat;
    23 import java.util.Date;
    2421import java.util.GregorianCalendar;
    25 import java.util.Locale;
    2622import javax.xml.datatype.DatatypeConfigurationException;
    2723import 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  
    194194    public int deleteAnnotation(Number annotationId) throws SQLException {
    195195
    196         //TODO: why  does it not work via calling notebook and permissions "remove" methods??
    197 
    198196        String sqlNotebooks = "DELETE FROM " + notebooksAnnotationsTableName + " where " + annotation_id + " = ?";
    199197        int affectedNotebooks = getSimpleJdbcTemplate().update(sqlNotebooks, annotationId);
    200198
    201         String sqlPermissions = "DELETE FROM " + permissionsTableName + " where " + annotation_id + " = ?";
     199         String sqlPermissions = "DELETE FROM " + permissionsTableName + " where " + annotation_id + " = ?";
    202200        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);
    205204        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        }
    207211
    208212        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  
    6464    public List<Number> retrieveSourceIDs(Number annotationID) {
    6565        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);       
    7467        return result;
    7568    }
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/test/java/eu/dasish/annotation/backend/dao/impl/JdbcAnnotationDaoTest.java

    r3361 r3364  
    1818package eu.dasish.annotation.backend.dao.impl;
    1919
    20 import eu.dasish.annotation.backend.Helpers;
    2120import eu.dasish.annotation.backend.TestBackendConstants;
    2221import eu.dasish.annotation.backend.TestInstances;
     
    3837import java.util.List;
    3938import java.util.Map;
    40 import javax.xml.datatype.DatatypeConfigurationException;
    4139import org.jmock.Expectations;
    4240import org.jmock.Mockery;
    4341import static org.junit.Assert.*;
     42import org.junit.Ignore;
    4443import org.junit.Test;
    4544import org.junit.runner.RunWith;
     
    229228    public void testDeleteAnnotation() throws SQLException {
    230229        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));
    235243                will(returnValue(1));
    236 
    237                 oneOf(notebookDao).removeAnnotation(5);
    238                 will(returnValue(3));
    239244            }
    240245        });
     
    244249        // now, try to delete the same annotation one more time
    245250        // 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        });
    246258        result = jdbcAnnotationDao.deleteAnnotation(5);
    247259        assertEquals(0, result);
     
    352364
    353365    @Test
     366    @Ignore
    354367    public void testGetExternalID() {
    355368        System.out.println("getAnnotationID");
Note: See TracChangeset for help on using the changeset viewer.