Changeset 3348


Ignore:
Timestamp:
08/09/13 16:00:34 (11 years ago)
Author:
olhsha
Message:

add source: now adds time stamp to the return value (new source)

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/SourceDao.java

    r3347 r3348  
    6868     * @return the copy of freshSource with the assigned external identifier
    6969     */
    70     public Source addSource(Source freshSource);
     70    public Source addSource(Source freshSource) throws SQLException;
    7171   
    7272    //////////////////////////////////////////////
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/impl/JdbcAnnotationDao.java

    r3347 r3348  
    285285    }
    286286
    287     private XMLGregorianCalendar retrieveTimeStamp(Number internalID) {
    288         String sqlTime = "SELECT " + time_stamp + " FROM " + annotationTableName + " WHERE " + annotation_id + "= ?";
    289         List<XMLGregorianCalendar> timeStamp = getSimpleJdbcTemplate().query(sqlTime, timeStampRowMapper, internalID);
    290         if (timeStamp.isEmpty()) {
    291             return null;
    292         }
    293         return timeStamp.get(0);
    294     }
    295     private final RowMapper<XMLGregorianCalendar> timeStampRowMapper = new RowMapper<XMLGregorianCalendar>() {
    296         @Override
    297         public XMLGregorianCalendar mapRow(ResultSet rs, int rowNumber) throws SQLException {
    298             try {
    299                 XMLGregorianCalendar result = Helpers.setXMLGregorianCalendar(rs.getDate(time_stamp));
    300                 return result;
    301             } catch (DatatypeConfigurationException e) {
    302                 System.out.println(e);
    303                 return null;
    304             }
    305         }
    306     };
     287   
    307288
    308289    ///////////////////////////////////////////////////////////
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/impl/JdbcResourceDao.java

    r3299 r3348  
    1818package eu.dasish.annotation.backend.dao.impl;
    1919
     20import eu.dasish.annotation.backend.Helpers;
    2021import eu.dasish.annotation.backend.dao.ResourceDao;
    2122import eu.dasish.annotation.backend.identifiers.DasishIdentifier;
     
    2324import java.sql.SQLException;
    2425import java.util.List;
     26import javax.xml.datatype.DatatypeConfigurationException;
     27import javax.xml.datatype.XMLGregorianCalendar;
    2528import org.springframework.jdbc.core.RowMapper;
    2629import org.springframework.jdbc.core.simple.SimpleJdbcDaoSupport;
     
    156159   
    157160   
     161   
     162    /////////////////////////////////////////////////////
     163   protected XMLGregorianCalendar retrieveTimeStamp(Number internalID) {
     164        String sqlTime = "SELECT " + time_stamp + " FROM " + resourceTableName + " WHERE " + internalIdName + "= ?";
     165        List<XMLGregorianCalendar> timeStamp = getSimpleJdbcTemplate().query(sqlTime, timeStampRowMapper, internalID);
     166        if (timeStamp.isEmpty()) {
     167            return null;
     168        }
     169        return timeStamp.get(0);
     170    }
     171    protected final RowMapper<XMLGregorianCalendar> timeStampRowMapper = new RowMapper<XMLGregorianCalendar>() {
     172        @Override
     173        public XMLGregorianCalendar mapRow(ResultSet rs, int rowNumber) throws SQLException {
     174            try {
     175                XMLGregorianCalendar result = Helpers.setXMLGregorianCalendar(rs.getDate(time_stamp));
     176                return result;
     177            } catch (DatatypeConfigurationException e) {
     178                System.out.println(e);
     179                return null;
     180            }
     181        }
     182    };
     183   
    158184    //////////////////////////////////////////
    159185    /**
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/impl/JdbcSourceDao.java

    r3347 r3348  
    147147    ///////////////////////////////////////////////////////////////////
    148148    @Override
    149     public Source addSource(Source freshSource) {
     149    public Source addSource(Source freshSource) throws SQLException{
    150150
    151151        SourceIdentifier externalIdentifier = new SourceIdentifier();
     
    167167            Source result = makeFreshCopy(freshSource);
    168168            result.setURI(externalIdentifier.toString());
     169           
     170            //retrieve taime stamp for the just added annotation
     171            XMLGregorianCalendar timeStamp =this.retrieveTimeStamp(getInternalID(new SourceIdentifier(externalIdentifier.toString())));
     172            result.setTimeSatmp(timeStamp);
     173           
    169174            return result;
    170175        } else {
    171             return null;
     176            throw new SQLException("Cannot add the source");
    172177        }
    173178         
     
    313318    }
    314319
     320    // TODO: make deep copy for source, otherwise testing will be unfair!!
    315321    private Source makeFreshCopy(Source source) {
    316322        Source result = new Source();
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/test/java/eu/dasish/annotation/backend/dao/impl/JdbcSourceDaoTest.java

    r3347 r3348  
    5050    "/spring-config/sourceDao.xml"})
    5151public class JdbcSourceDaoTest extends JdbcResourceDaoTest {
    52    
     52
    5353    @Autowired
    5454    JdbcSourceDao jdbcSourceDao;
     
    103103        final Number internalVersionID = 1;
    104104        final VersionIdentifier externalVersionID = new VersionIdentifier(TestBackendConstants._TEST_VERSION_1_EXT_ID);
    105        
     105
    106106        mockery.checking(new Expectations() {
    107107            {
     
    110110            }
    111111        });
    112        
     112
    113113        Source result = jdbcSourceDao.getSource(internalID);
    114114        assertEquals(TestBackendConstants._TEST_SOURCE_1_EXT_ID, result.getURI());
     
    127127        int result = jdbcSourceDao.deleteSourceVersionRows(internalID);
    128128        assertEquals(1, result);
    129        
     129
    130130        Number internalIDNoExist = 5;
    131131        int resultTwo = jdbcSourceDao.deleteSourceVersionRows(internalIDNoExist);
     
    150150                oneOf(versionDao).retrieveVersionList(internalIDToBeDeleted);
    151151                will(returnValue(versions));
    152                
     152
    153153                oneOf(versionDao).deleteVersion(5);
    154154                will(returnValue(1)); // no other sources refer to this version # 5
    155155            }
    156156        });
    157        
     157
    158158        int resultTwo = jdbcSourceDao.deleteSource(internalIDToBeDeleted);
    159159        assertEquals(1, resultTwo); // the source will be deleted because it is not referred by any annotation
     
    166166    public void testAddSource() {
    167167        System.out.println("addSource");
    168        
     168
    169169        String link = "http://www.sagradafamilia.cat/";
    170170        String version = null;
    171        
     171        String timeStamp = null;
     172
    172173        Source freshSource = new Source();
    173174        freshSource.setLink(link);
    174175        freshSource.setVersion(version);
    175        
    176         Source result = jdbcSourceDao.addSource(freshSource);
    177         assertEquals(link, result.getLink());
    178         assertEquals(version, result.getVersion());
    179         assertEquals(5, jdbcSourceDao.getInternalID(new SourceIdentifier(result.getURI())));
    180         // TODO time stamp is not checked       
     176        freshSource.setVersion(timeStamp);
     177
     178        try {
     179            Source result = jdbcSourceDao.addSource(freshSource);
     180            assertEquals(link, result.getLink());
     181            assertEquals(version, result.getVersion());
     182            assertEquals(5, jdbcSourceDao.getInternalID(new SourceIdentifier(result.getURI())));
     183
     184            assertFalse(null==result.getTimeSatmp());
     185           
     186        } catch (SQLException e) {
     187            System.out.println(e);
     188        }
    181189    }
    182190
     
    188196        System.out.println("getSourceInfos");
    189197        Number annotationID = 2;
    190        
     198
    191199        mockery.checking(new Expectations() {
    192200            {
    193201                oneOf(versionDao).getExternalID(1);
    194202                will(returnValue(new VersionIdentifier(TestBackendConstants._TEST_VERSION_1_EXT_ID)));
    195                
     203
    196204                oneOf(versionDao).getExternalID(3);
    197205                will(returnValue(new VersionIdentifier(TestBackendConstants._TEST_VERSION_3_EXT_ID)));
    198206            }
    199207        });
    200        
     208
    201209        List<SourceInfo> result = jdbcSourceDao.getSourceInfos(annotationID);
    202210        assertEquals(2, result.size());
     
    207215        assertEquals(TestBackendConstants._TEST_SOURCE_1_LINK, result.get(0).getLink());
    208216        assertEquals(TestBackendConstants._TEST_SOURCE_2_LINK, result.get(1).getLink());
    209        
     217
    210218    }
    211219
     
    216224    public void testContructNewOrExistingSourceInfo() {
    217225        System.out.println("contructNewOrExistingSourceInfo");
    218        
     226
    219227        List<SourceInfo> sourceInfoList = new ArrayList<SourceInfo>();
    220        
     228
    221229        SourceInfo sourceInfoOne = new SourceInfo();
    222230        sourceInfoOne.setLink(TestBackendConstants._TEST_SOURCE_1_LINK);
    223231        sourceInfoOne.setRef(TestBackendConstants._TEST_SOURCE_1_EXT_ID);
    224232        sourceInfoOne.setRef(TestBackendConstants._TEST_VERSION_1_EXT_ID);
    225        
     233
    226234        SourceInfo sourceInfoTwo = new SourceInfo();
    227235        sourceInfoTwo.setLink(TestBackendConstants._TEST_SOURCE_2_LINK);
    228236        sourceInfoTwo.setRef(TestBackendConstants._TEST_SOURCE_2_EXT_ID);
    229237        sourceInfoTwo.setRef(TestBackendConstants._TEST_VERSION_3_EXT_ID);
    230        
     238
    231239        sourceInfoList.add(sourceInfoOne);
    232240        sourceInfoList.add(sourceInfoTwo);
    233        
     241
    234242        NewOrExistingSourceInfos result = jdbcSourceDao.contructNewOrExistingSourceInfo(sourceInfoList);
    235243        assertEquals(2, result.getTarget().size());
    236244        assertEquals(sourceInfoOne, result.getTarget().get(0).getSource());
    237245        assertEquals(sourceInfoTwo, result.getTarget().get(1).getSource());
    238        
     246
    239247    }
    240248
     
    248256    public void testAddTargetSourcesOnExistingSource() {
    249257        System.out.println("addTargetSources : adding the old source");
    250        
     258
    251259        NewOrExistingSourceInfo noesi = new NewOrExistingSourceInfo();
    252260        SourceInfo si = new SourceInfo();
     
    255263        si.setVersion(TestBackendConstants._TEST_VERSION_1_EXT_ID);
    256264        noesi.setSource(si);
    257        
     265
    258266        List<NewOrExistingSourceInfo> listnoesi = new ArrayList<NewOrExistingSourceInfo>();
    259267        listnoesi.add(noesi);
    260        
     268
    261269        try {
    262270            Map<NewOrExistingSourceInfo, NewOrExistingSourceInfo> result = jdbcSourceDao.addTargetSources(5, listnoesi);
     
    277285    public void testAddTargetSourcesOnNewSource() {
    278286        System.out.println("addTargetSources : adding the new source");
    279        
     287
    280288        NewOrExistingSourceInfo noesi = new NewOrExistingSourceInfo();
    281289        NewSourceInfo nsi = new NewSourceInfo();
     
    284292        nsi.setVersion(null);
    285293        noesi.setNewSource(nsi);
    286        
     294
    287295        List<NewOrExistingSourceInfo> listnoesiTwo = new ArrayList<NewOrExistingSourceInfo>();
    288296        listnoesiTwo.add(noesi);
    289        
     297
    290298        try {
    291299            Map<NewOrExistingSourceInfo, NewOrExistingSourceInfo> result = jdbcSourceDao.addTargetSources(5, listnoesiTwo);
     
    293301            assertEquals(noesi.getNewSource().getLink(), result.get(noesi).getSource().getLink());
    294302            assertEquals(noesi.getNewSource().getVersion(), result.get(noesi).getSource().getVersion());
    295            
     303
    296304            SourceIdentifier sourceIdentifier = new SourceIdentifier(result.get(noesi).getSource().getRef());
    297305            assertFalse(null == sourceIdentifier.getUUID()); // check if a proper uuid has been assigned
     
    299307            System.out.print(e);
    300308        }
    301        
     309
    302310    }
    303311}
Note: See TracChangeset for help on using the changeset viewer.