Changeset 3189
- Timestamp:
- 07/24/13 16:32:22 (11 years ago)
- Location:
- DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src
- Files:
-
- 11 edited
Legend:
- Unmodified
- Added
- Removed
-
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/AnnotationDao.java
r3188 r3189 76 76 public AnnotationIdentifier addAnnotation(Annotation annotation); 77 77 78 78 /** 79 * 80 * @param internalId 81 * @return the external identifier for the annotation with internalId 82 */ 83 public AnnotationIdentifier getExternalID(Number internalId); 79 84 } -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/NotebookDao.java
r3188 r3189 76 76 */ 77 77 Number getNotebookID(NotebookIdentifier externalId); 78 79 /** 80 * @param notebookId 81 * @return returns the externalIds of the annotations contained in the notebookId 82 */ 83 List<AnnotationIdentifier> getAnnotationExternalIDs(NotebookIdentifier notebookId); 78 84 } -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/impl/JdbcAnnotationDao.java
r3180 r3189 264 264 265 265 266 ////////////////////////////////////////////////// 267 @Override 268 public AnnotationIdentifier getExternalID(Number internalID) { 269 if (internalID == null) { 270 return null; 271 } 272 273 String sql = "SELECT "+annotationExternal_id+" FROM "+annotationTableName+" WHERE "+annotationAnnotation_id+" = ?"; 274 List<AnnotationIdentifier> result= getSimpleJdbcTemplate().query(sql, externalIDRowMapper, internalID.toString()); 275 if (result == null) { 276 return null; 277 } 278 if (result.isEmpty()) { 279 return null; 280 } 281 return result.get(0); 282 } 283 284 private final RowMapper<AnnotationIdentifier> externalIDRowMapper = new RowMapper<AnnotationIdentifier>() { 285 @Override 286 public AnnotationIdentifier mapRow(ResultSet rs, int rowNumber) throws SQLException { 287 AnnotationIdentifier result = new AnnotationIdentifier(rs.getString(external_id)); 288 return result; 289 } 290 }; 291 266 292 267 293 //////////// helpers /////////////////////// -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/impl/JdbcNotebookDao.java
r3188 r3189 29 29 import java.sql.ResultSet; 30 30 import java.sql.SQLException; 31 import java.util.ArrayList; 31 32 import java.util.GregorianCalendar; 32 33 import java.util.HashMap; … … 228 229 229 230 /////////////////////////////////////////////////// 230 // RE SUSES notebookInfoRowMapper231 // REUSES notebookInfoRowMapper 231 232 @Override 232 233 public NotebookInfo getNotebookInfo(Number notebookID) { … … 271 272 } 272 273 }; 274 275 276 ////////////////////////////////////////////////////////////////// 277 @Override 278 public List<AnnotationIdentifier> getAnnotationExternalIDs(NotebookIdentifier notebookId){ 279 List<Number> internalIds = getAnnotationIDs(getNotebookID(notebookId)); 280 if (internalIds == null) { 281 return null; 282 } 283 List<AnnotationIdentifier> annotationIds = new ArrayList<AnnotationIdentifier>(); 284 for (Number internalId : internalIds) { 285 annotationIds.add(jdbcAnnotationDao.getExternalID(internalId)); 286 } 287 return annotationIds; 288 } 273 289 } -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/identifiers/AnnotationIdentifier.java
r3137 r3189 20 20 import eu.dasish.annotation.backend.BackendConstants; 21 21 import java.util.UUID; 22 import javax.xml.bind.annotation.XmlRootElement; 22 23 23 24 /** … … 26 27 * @author Peter Withers <peter.withers@mpi.nl> 27 28 */ 29 @XmlRootElement (name = "AnnotationIdentifier") 28 30 public class AnnotationIdentifier extends DasishIdentifier { 29 31 -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/identifiers/DasishIdentifier.java
r3137 r3189 18 18 package eu.dasish.annotation.backend.identifiers; 19 19 import java.util.UUID; 20 import javax.xml.bind.annotation.XmlElement; 20 21 21 22 /** … … 25 26 public class DasishIdentifier { 26 27 28 @XmlElement(required = true) 27 29 final private UUID _identifier; 30 28 31 29 32 private int _hashParameterOne; -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/rest/NotebookResource.java
r3188 r3189 19 19 20 20 import eu.dasish.annotation.backend.BackendConstants; 21 import eu.dasish.annotation.backend.dao.AnnotationDao; 21 22 import eu.dasish.annotation.backend.identifiers.UserIdentifier; 22 23 import eu.dasish.annotation.backend.dao.NotebookDao; 24 import eu.dasish.annotation.backend.identifiers.AnnotationIdentifier; 23 25 import eu.dasish.annotation.backend.identifiers.NotebookIdentifier; 24 26 import eu.dasish.annotation.schema.Notebook; … … 28 30 import java.net.URI; 29 31 import java.net.URISyntaxException; 32 import java.util.ArrayList; 30 33 import java.util.List; 31 34 import javax.servlet.http.HttpServletRequest; … … 57 60 @Autowired 58 61 private NotebookDao notebookDao; 62 @Autowired 63 private AnnotationDao annotationDao; 59 64 60 65 @GET … … 115 120 116 121 @GET 117 @Path("{notebookid: [a-zA-Z0-9_]*}")122 @Path("{notebookid: "+BackendConstants.regExpIdentifier+"}") 118 123 /* 119 124 * Get the list of all annotations _aid_-s contained within a Notebook with related metadata. … … 124 129 * optional orderingMode specifies if the results should be sorted using a descending order desc=1 or an ascending order desc=0 (default: 0 ). 125 130 * */ 126 @Produces( "text/html")127 public StringgetAllAnnotations(@PathParam("notebookid") String notebookId, @DefaultValue("-1") @QueryParam(value = "maximumAnnotations") final int maximumAnnotations,131 @Produces(MediaType.TEXT_XML) 132 public List<AnnotationIdentifier> getAllAnnotations(@PathParam("notebookid") String notebookId, @DefaultValue("-1") @QueryParam(value = "maximumAnnotations") final int maximumAnnotations, 128 133 @DefaultValue("-1") @QueryParam(value = "startAnnotation") final int startAnnotation, 129 134 @DefaultValue("dc:created") @QueryParam(value = "orderby") final String orderby, 130 @DefaultValue("0") @QueryParam(value = "orderingMode") final int orderingMode) { 131 return "all annotations for " + notebookId + " : " + maximumAnnotations + " : " + startAnnotation + " : " + orderby + " : " + orderingMode; 135 @DefaultValue("0") @QueryParam(value = "orderingMode") final int orderingMode) { 136 List<AnnotationIdentifier> annotationIds = notebookDao.getAnnotationExternalIDs(new NotebookIdentifier(notebookId)); 137 return annotationIds; 138 // TODO implement optional parameters!! 132 139 } 133 140 -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/test/java/eu/dasish/annotation/backend/dao/impl/JdbcAnnotationDaoTest.java
r3180 r3189 195 195 196 196 } 197 198 @Test 199 public void testGetExternalID(){ 200 System.out.println("getAnnotationID"); 201 202 final AnnotationIdentifier externalId = jdbcAnnotationDao.getExternalID(TestBackendConstants._TEST_ANNOT_1_INT); 203 assertEquals(new AnnotationIdentifier(TestBackendConstants._TEST_ANNOT_1_EXT), externalId); 204 205 final AnnotationIdentifier externalIdTwo = jdbcAnnotationDao.getExternalID(TestBackendConstants._TEST_ANNOT_4_INT_NOT_IN_THE_DB); 206 assertEquals(null, externalIdTwo); 207 208 final AnnotationIdentifier externalIdThree = jdbcAnnotationDao.getExternalID(null); 209 assertEquals(null, externalIdThree); 210 211 } 197 212 } 198 213 -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/test/java/eu/dasish/annotation/backend/dao/impl/JdbcNotebookDaoTest.java
r3188 r3189 20 20 import eu.dasish.annotation.backend.TestBackendConstants; 21 21 import eu.dasish.annotation.backend.dao.AnnotationDao; 22 import eu.dasish.annotation.backend.identifiers.AnnotationIdentifier; 22 23 import eu.dasish.annotation.backend.identifiers.NotebookIdentifier; 23 24 import eu.dasish.annotation.backend.identifiers.UserIdentifier; … … 291 292 292 293 294 @Test 295 public void testGetAnnotationExternalIDs() { 296 System.out.println("test getExternalAnnotationIds"); 297 298 // test One 299 mockery.checking(new Expectations() { 300 { 301 oneOf(annotationDao).getExternalID(TestBackendConstants._TEST_ANNOT_1_INT); 302 will(returnValue(new AnnotationIdentifier(TestBackendConstants._TEST_ANNOT_1_EXT))); 303 304 oneOf(annotationDao).getExternalID(TestBackendConstants._TEST_ANNOT_2_INT); 305 will(returnValue(new AnnotationIdentifier(TestBackendConstants._TEST_ANNOT_2_EXT))); 306 } 307 }); 308 309 List<AnnotationIdentifier> resultOne= jdbcNotebookDao.getAnnotationExternalIDs(new NotebookIdentifier(TestBackendConstants._TEST_NOTEBOOK_1_EXT)); 310 assertEquals(TestBackendConstants._TEST_ANNOT_1_EXT, resultOne.get(0).toString()); 311 assertEquals(TestBackendConstants._TEST_ANNOT_2_EXT, resultOne.get(1).toString()); 312 313 314 List<AnnotationIdentifier> resultTwo= jdbcNotebookDao.getAnnotationExternalIDs(new NotebookIdentifier(TestBackendConstants._TEST_ANNOT_4_EXT_NOT_IN_THE_DB)); 315 assertEquals(null, resultTwo); 316 317 // test Two, non-existing notebook 318 List<AnnotationIdentifier> resultThree= jdbcNotebookDao.getAnnotationExternalIDs(null); 319 assertEquals(null, resultThree); 320 321 } 322 323 293 324 //////////////////////////////////////////////////////////////////// 294 325 //////// Setting Mockeries ///////////////////////////////////////// … … 311 342 312 343 private void setMockeryNotebookTwo(){ 313 ResourceREF testRef = new ResourceREF();344 ResourceREF testRef = new ResourceREF(); 314 345 testRef.setRef(String.valueOf(TestBackendConstants._TEST_ANNOT_3_INT)); 315 346 final List<ResourceREF> testResultTwo = Arrays.asList(new ResourceREF[] {testRef}); -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/test/java/eu/dasish/annotation/backend/rest/NotebookResourceTest.java
r3188 r3189 18 18 package eu.dasish.annotation.backend.rest; 19 19 20 import com.sun.jersey.api.client.ClientResponse;21 20 import eu.dasish.annotation.backend.TestBackendConstants; 21 import eu.dasish.annotation.backend.dao.AnnotationDao; 22 22 import eu.dasish.annotation.backend.dao.NotebookDao; 23 import eu.dasish.annotation.backend.identifiers.AnnotationIdentifier; 23 24 import eu.dasish.annotation.backend.identifiers.NotebookIdentifier; 24 25 import eu.dasish.annotation.backend.identifiers.UserIdentifier; … … 30 31 import java.util.List; 31 32 import java.util.UUID; 32 import javax.ws.rs.core.MediaType;33 33 import javax.xml.bind.JAXBElement; 34 34 import org.jmock.Expectations; … … 54 54 @Autowired 55 55 private NotebookDao notebookDao; 56 @Autowired 57 private AnnotationDao annotationDao; 56 58 @Autowired 57 59 private NotebookResource notebookResource; … … 163 165 } 164 166 167 168 @Test 169 public void testAllAnnotations() { 170 System.out.println("test getAllAnnotations"); 171 final String notebookIdentifier= TestBackendConstants._TEST_NOTEBOOK_1_EXT; 172 final AnnotationIdentifier aIdOne= new AnnotationIdentifier(TestBackendConstants._TEST_ANNOT_1_EXT); 173 final AnnotationIdentifier aIdTwo= new AnnotationIdentifier(TestBackendConstants._TEST_ANNOT_2_EXT); 174 final List<AnnotationIdentifier> annotationIds = new ArrayList<AnnotationIdentifier>(); 175 annotationIds.add(aIdOne); 176 annotationIds.add(aIdTwo); 177 178 mockery.checking(new Expectations() { 179 { 180 oneOf(notebookDao).getAnnotationExternalIDs(new NotebookIdentifier(notebookIdentifier)); 181 will(returnValue(annotationIds)); 182 183 } 184 }); 185 186 List<AnnotationIdentifier> result= notebookResource.getAllAnnotations(notebookIdentifier, 0, 0, null, 0); 187 assertFalse(null==result); 188 assertEquals(aIdOne, result.get(0)); 189 assertEquals(aIdTwo, result.get(1)); 190 191 192 } 165 193 } -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/test/java/eu/dasish/annotation/backend/rest/NotebooksTest.java
r3188 r3189 175 175 */ 176 176 @Test 177 @Ignore 177 178 public void testGetAllAnnotations() { 178 179 System.out.println("testGetAllAnnotations"); 179 ClientResponse response = resource().path("notebooks/_nid_") 180 181 System.out.println("test GetMetadata"); 182 183 final String notebookIdentifier= TestBackendConstants._TEST_NOTEBOOK_1_EXT; 184 /*final int notebookID = TestBackendConstants._TEST_NOTEBOOK_1_INT; 185 final NotebookInfo testInfo = new ObjectFactory().createNotebookInfo(); 186 187 mockery.checking(new Expectations() { 188 { 189 oneOf(notebookDao).getNotebookID(new NotebookIdentifier(notebookIdentifier)); 190 will(returnValue(notebookID)); 191 192 oneOf(notebookDao).getNotebookInfo(notebookID); 193 will(returnValue(testInfo)); 194 } 195 });*/ 196 197 final String requestUrl = "notebooks/"+notebookIdentifier; 198 199 200 ClientResponse response = resource().path(requestUrl) 180 201 .queryParam("maximumAnnotations", "123") 181 202 .queryParam("startAnnotation", "456") … … 183 204 .queryParam("orderingMode", "1") 184 205 .get(ClientResponse.class); 185 assertEquals(200, response.getStatus()); 186 assertEquals("all annotations for _nid_ : 123 : 456 : dc:789 : 1", response.getEntity(String.class)); 206 System.out.println("requestUrl: " + requestUrl); 207 208 209 assertEquals(200, response.getStatus()); 210 187 211 } 188 212
Note: See TracChangeset
for help on using the changeset viewer.