Changeset 3348
- Timestamp:
- 08/09/13 16:00:34 (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/SourceDao.java
r3347 r3348 68 68 * @return the copy of freshSource with the assigned external identifier 69 69 */ 70 public Source addSource(Source freshSource) ;70 public Source addSource(Source freshSource) throws SQLException; 71 71 72 72 ////////////////////////////////////////////// -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/impl/JdbcAnnotationDao.java
r3347 r3348 285 285 } 286 286 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 307 288 308 289 /////////////////////////////////////////////////////////// -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/impl/JdbcResourceDao.java
r3299 r3348 18 18 package eu.dasish.annotation.backend.dao.impl; 19 19 20 import eu.dasish.annotation.backend.Helpers; 20 21 import eu.dasish.annotation.backend.dao.ResourceDao; 21 22 import eu.dasish.annotation.backend.identifiers.DasishIdentifier; … … 23 24 import java.sql.SQLException; 24 25 import java.util.List; 26 import javax.xml.datatype.DatatypeConfigurationException; 27 import javax.xml.datatype.XMLGregorianCalendar; 25 28 import org.springframework.jdbc.core.RowMapper; 26 29 import org.springframework.jdbc.core.simple.SimpleJdbcDaoSupport; … … 156 159 157 160 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 158 184 ////////////////////////////////////////// 159 185 /** -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/impl/JdbcSourceDao.java
r3347 r3348 147 147 /////////////////////////////////////////////////////////////////// 148 148 @Override 149 public Source addSource(Source freshSource) {149 public Source addSource(Source freshSource) throws SQLException{ 150 150 151 151 SourceIdentifier externalIdentifier = new SourceIdentifier(); … … 167 167 Source result = makeFreshCopy(freshSource); 168 168 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 169 174 return result; 170 175 } else { 171 return null;176 throw new SQLException("Cannot add the source"); 172 177 } 173 178 … … 313 318 } 314 319 320 // TODO: make deep copy for source, otherwise testing will be unfair!! 315 321 private Source makeFreshCopy(Source source) { 316 322 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 50 50 "/spring-config/sourceDao.xml"}) 51 51 public class JdbcSourceDaoTest extends JdbcResourceDaoTest { 52 52 53 53 @Autowired 54 54 JdbcSourceDao jdbcSourceDao; … … 103 103 final Number internalVersionID = 1; 104 104 final VersionIdentifier externalVersionID = new VersionIdentifier(TestBackendConstants._TEST_VERSION_1_EXT_ID); 105 105 106 106 mockery.checking(new Expectations() { 107 107 { … … 110 110 } 111 111 }); 112 112 113 113 Source result = jdbcSourceDao.getSource(internalID); 114 114 assertEquals(TestBackendConstants._TEST_SOURCE_1_EXT_ID, result.getURI()); … … 127 127 int result = jdbcSourceDao.deleteSourceVersionRows(internalID); 128 128 assertEquals(1, result); 129 129 130 130 Number internalIDNoExist = 5; 131 131 int resultTwo = jdbcSourceDao.deleteSourceVersionRows(internalIDNoExist); … … 150 150 oneOf(versionDao).retrieveVersionList(internalIDToBeDeleted); 151 151 will(returnValue(versions)); 152 152 153 153 oneOf(versionDao).deleteVersion(5); 154 154 will(returnValue(1)); // no other sources refer to this version # 5 155 155 } 156 156 }); 157 157 158 158 int resultTwo = jdbcSourceDao.deleteSource(internalIDToBeDeleted); 159 159 assertEquals(1, resultTwo); // the source will be deleted because it is not referred by any annotation … … 166 166 public void testAddSource() { 167 167 System.out.println("addSource"); 168 168 169 169 String link = "http://www.sagradafamilia.cat/"; 170 170 String version = null; 171 171 String timeStamp = null; 172 172 173 Source freshSource = new Source(); 173 174 freshSource.setLink(link); 174 175 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 } 181 189 } 182 190 … … 188 196 System.out.println("getSourceInfos"); 189 197 Number annotationID = 2; 190 198 191 199 mockery.checking(new Expectations() { 192 200 { 193 201 oneOf(versionDao).getExternalID(1); 194 202 will(returnValue(new VersionIdentifier(TestBackendConstants._TEST_VERSION_1_EXT_ID))); 195 203 196 204 oneOf(versionDao).getExternalID(3); 197 205 will(returnValue(new VersionIdentifier(TestBackendConstants._TEST_VERSION_3_EXT_ID))); 198 206 } 199 207 }); 200 208 201 209 List<SourceInfo> result = jdbcSourceDao.getSourceInfos(annotationID); 202 210 assertEquals(2, result.size()); … … 207 215 assertEquals(TestBackendConstants._TEST_SOURCE_1_LINK, result.get(0).getLink()); 208 216 assertEquals(TestBackendConstants._TEST_SOURCE_2_LINK, result.get(1).getLink()); 209 217 210 218 } 211 219 … … 216 224 public void testContructNewOrExistingSourceInfo() { 217 225 System.out.println("contructNewOrExistingSourceInfo"); 218 226 219 227 List<SourceInfo> sourceInfoList = new ArrayList<SourceInfo>(); 220 228 221 229 SourceInfo sourceInfoOne = new SourceInfo(); 222 230 sourceInfoOne.setLink(TestBackendConstants._TEST_SOURCE_1_LINK); 223 231 sourceInfoOne.setRef(TestBackendConstants._TEST_SOURCE_1_EXT_ID); 224 232 sourceInfoOne.setRef(TestBackendConstants._TEST_VERSION_1_EXT_ID); 225 233 226 234 SourceInfo sourceInfoTwo = new SourceInfo(); 227 235 sourceInfoTwo.setLink(TestBackendConstants._TEST_SOURCE_2_LINK); 228 236 sourceInfoTwo.setRef(TestBackendConstants._TEST_SOURCE_2_EXT_ID); 229 237 sourceInfoTwo.setRef(TestBackendConstants._TEST_VERSION_3_EXT_ID); 230 238 231 239 sourceInfoList.add(sourceInfoOne); 232 240 sourceInfoList.add(sourceInfoTwo); 233 241 234 242 NewOrExistingSourceInfos result = jdbcSourceDao.contructNewOrExistingSourceInfo(sourceInfoList); 235 243 assertEquals(2, result.getTarget().size()); 236 244 assertEquals(sourceInfoOne, result.getTarget().get(0).getSource()); 237 245 assertEquals(sourceInfoTwo, result.getTarget().get(1).getSource()); 238 246 239 247 } 240 248 … … 248 256 public void testAddTargetSourcesOnExistingSource() { 249 257 System.out.println("addTargetSources : adding the old source"); 250 258 251 259 NewOrExistingSourceInfo noesi = new NewOrExistingSourceInfo(); 252 260 SourceInfo si = new SourceInfo(); … … 255 263 si.setVersion(TestBackendConstants._TEST_VERSION_1_EXT_ID); 256 264 noesi.setSource(si); 257 265 258 266 List<NewOrExistingSourceInfo> listnoesi = new ArrayList<NewOrExistingSourceInfo>(); 259 267 listnoesi.add(noesi); 260 268 261 269 try { 262 270 Map<NewOrExistingSourceInfo, NewOrExistingSourceInfo> result = jdbcSourceDao.addTargetSources(5, listnoesi); … … 277 285 public void testAddTargetSourcesOnNewSource() { 278 286 System.out.println("addTargetSources : adding the new source"); 279 287 280 288 NewOrExistingSourceInfo noesi = new NewOrExistingSourceInfo(); 281 289 NewSourceInfo nsi = new NewSourceInfo(); … … 284 292 nsi.setVersion(null); 285 293 noesi.setNewSource(nsi); 286 294 287 295 List<NewOrExistingSourceInfo> listnoesiTwo = new ArrayList<NewOrExistingSourceInfo>(); 288 296 listnoesiTwo.add(noesi); 289 297 290 298 try { 291 299 Map<NewOrExistingSourceInfo, NewOrExistingSourceInfo> result = jdbcSourceDao.addTargetSources(5, listnoesiTwo); … … 293 301 assertEquals(noesi.getNewSource().getLink(), result.get(noesi).getSource().getLink()); 294 302 assertEquals(noesi.getNewSource().getVersion(), result.get(noesi).getSource().getVersion()); 295 303 296 304 SourceIdentifier sourceIdentifier = new SourceIdentifier(result.get(noesi).getSource().getRef()); 297 305 assertFalse(null == sourceIdentifier.getUUID()); // check if a proper uuid has been assigned … … 299 307 System.out.print(e); 300 308 } 301 309 302 310 } 303 311 }
Note: See TracChangeset
for help on using the changeset viewer.