Changeset 3188
- Timestamp:
- 07/24/13 13:37:29 (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
r3180 r3188 19 19 20 20 import eu.dasish.annotation.backend.identifiers.AnnotationIdentifier; 21 import eu.dasish.annotation.backend.identifiers.NotebookIdentifier;22 import eu.dasish.annotation.backend.identifiers.UserIdentifier;23 21 import eu.dasish.annotation.schema.Annotation; 24 22 import eu.dasish.annotation.schema.AnnotationInfo; -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/NotebookDao.java
r3167 r3188 62 62 Annotations getAnnotations(Number notebookID); 63 63 64 64 /** 65 * 66 * @param notebookID 67 * @return the Notebook information (title, owner (?), time_stamp(?), amount of annotations(?), their headlines (?) // TODO: discuss changing in the schema 68 * user in getting the metadata of a notebook 69 */ 70 NotebookInfo getNotebookInfo(Number notebookID); 65 71 72 /** 73 * 74 * @param externalId 75 * @return the notebook's internal ID, given its extrnalId 76 */ 77 Number getNotebookID(NotebookIdentifier externalId); 66 78 } -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/ResourceDao.java
r3146 r3188 18 18 package eu.dasish.annotation.backend.dao; 19 19 20 import java.util.UUID; 21 20 22 /** 21 23 * … … 31 33 public boolean isNotebookInTheDataBase(Number notebookID); 32 34 35 33 36 } -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/impl/JdbcNotebookDao.java
r3167 r3188 88 88 public NotebookInfo mapRow(ResultSet rs, int rowNumber) throws SQLException { 89 89 NotebookInfo notebookInfo = new NotebookInfo(); 90 notebookInfo.setRef(rs.getString(external_id)); // todo: what is ref? should it be the external id? 90 notebookInfo.setRef(rs.getString(external_id)); // todo: what is ref? should it be the external id? Olha: "yes" 91 91 notebookInfo.setTitle(rs.getString(title)); 92 92 // notebookInfo.setRef(rs.getString("URI")); … … 226 226 227 227 } 228 229 /////////////////////////////////////////////////// 230 // RESUSES notebookInfoRowMapper 231 @Override 232 public NotebookInfo getNotebookInfo(Number notebookID) { 233 if (notebookID == null) { 234 return null; 235 } 236 String sql = "SELECT "+notebookExternal_id+","+ notebookTitle + " FROM " + notebookTableName + " where " + notebook_id + " = ?"; 237 List<NotebookInfo> result = getSimpleJdbcTemplate().query(sql, notebookInfoRowMapper, notebookID.toString()); 238 if (result == null) { 239 return null; 240 } 241 if (result.isEmpty()) { 242 return null; 243 } 244 return result.get(0); 245 } 246 247 ////////////////////////////////////////////////// 248 @Override 249 public Number getNotebookID(NotebookIdentifier externalId) { 250 if (externalId == null) { 251 return null; 252 } 253 254 String sql = "SELECT "+notebookNotebook_id+" FROM "+notebookTableName+" WHERE "+notebookExternal_id+" = ?"; 255 List<Number> result= getSimpleJdbcTemplate().query(sql, notebookIdRowMapper, externalId.toString()); 256 if (result == null) { 257 return null; 258 } 259 if (result.isEmpty()) { 260 return null; 261 } 262 263 return result.get(0); 264 } 265 266 private final RowMapper<Number> notebookIdRowMapper = new RowMapper<Number>() { 267 @Override 268 public Number mapRow(ResultSet rs, int rowNumber) throws SQLException { 269 Number result = rs.getInt(notebook_id); 270 return result; 271 } 272 }; 228 273 } -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/impl/JdbcResourceDao.java
r3167 r3188 22 22 import java.sql.SQLException; 23 23 import java.util.List; 24 import java.util.UUID; 24 25 import org.springframework.jdbc.core.RowMapper; 25 26 import org.springframework.jdbc.core.simple.SimpleJdbcDaoSupport; … … 63 64 final static protected String notebookOwner_id = notebookTableName+"."+owner_id; 64 65 65 final static protected String notebooksAnnotationsTableNameAnnotation_id = "notebooks_annotations.annotation_id"; 66 67 final static protected String notebooksAnnotationsTableNameAnnotation_id = notebooksAnnotationsTableName+"."+annotation_id; 68 66 69 67 70 final static protected String principalPrincipal_id = principalTableName+"."+principal_id; … … 100 103 }; 101 104 105 102 106 } -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/rest/NotebookResource.java
r3111 r3188 18 18 package eu.dasish.annotation.backend.rest; 19 19 20 import eu.dasish.annotation.backend.BackendConstants; 20 21 import eu.dasish.annotation.backend.identifiers.UserIdentifier; 21 22 import eu.dasish.annotation.backend.dao.NotebookDao; 22 23 import eu.dasish.annotation.backend.identifiers.NotebookIdentifier; 23 24 import eu.dasish.annotation.schema.Notebook; 25 import eu.dasish.annotation.schema.NotebookInfo; 24 26 import eu.dasish.annotation.schema.NotebookInfos; 25 27 import eu.dasish.annotation.schema.ObjectFactory; … … 102 104 103 105 @GET 104 @Produces( "text/html")105 @Path("{notebookid: [a-zA-Z0-9_]*}/metadata")106 @Produces(MediaType.TEXT_XML) 107 @Path("{notebookid: "+BackendConstants.regExpIdentifier+"}/metadata") 106 108 // Get all metadata about a specified notebook _nid_, including the information if it is private or not. 107 public String getMetadata(@PathParam("notebookid") String notebookId) { 108 return "metadata for " + notebookId; 109 public JAXBElement<NotebookInfo> getMetadata(@PathParam("notebookid") String notebookId) { 110 NotebookInfo result = notebookDao.getNotebookInfo(notebookDao.getNotebookID(new NotebookIdentifier(notebookId))); 111 // TODO change the name of the create method to createNotebookInfo! 112 return new ObjectFactory().createNotebook(result); 113 109 114 } 110 115 -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/test/java/eu/dasish/annotation/backend/TestBackendConstants.java
r3180 r3188 37 37 public static final String _TEST_NOTEBOOK_3_EXT = "00000000-0000-0000-0000-000000000013"; 38 38 39 public static final String _TEST_NOTEBOOK_1_TITLE = "Notebook 11"; 40 public static final String _TEST_NOTEBOOK_2_TITLE = "Notebook 12"; 41 public static final String _TEST_NOTEBOOK_3_TITLE = "Notebook 13"; 42 39 43 public static final int _TEST_NOTEBOOK_1_INT = 11; 40 44 public static final int _TEST_NOTEBOOK_2_INT = 12; -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/test/java/eu/dasish/annotation/backend/dao/impl/JdbcNotebookDaoTest.java
r3151 r3188 22 22 import eu.dasish.annotation.backend.identifiers.NotebookIdentifier; 23 23 import eu.dasish.annotation.backend.identifiers.UserIdentifier; 24 import eu.dasish.annotation.schema.AnnotationInfo;25 24 import eu.dasish.annotation.schema.Annotations; 26 25 import eu.dasish.annotation.schema.Notebook; … … 172 171 } 173 172 174 /** 175 * Test of getAnnotationInfosOfNotebook method, of class JdbcAnnotationDao. 176 * List<AnnotationInfo> getAnnotationInfosOfNotebook(Number notebookID) 177 178 @Test 179 public void testGetAnnotationInfosOfNotebook() { 180 System.out.println("getAnnotationInfosOfNotebook"); 181 182 mockery.checking(new Expectations() { 183 { 184 exactly(2).of(annotationDao).getAnnotationInfos(Arrays.asList(new Number[] {21, 22}));// exactly 2 notebooks (their id-s 1 and 2) contains the annotation 1 185 will(returnValue(testResult)); 186 } 187 }); 188 189 //test One 190 final List<AnnotationInfo> annotationInfos = jdbcNotebookDao.getAnnotationInfosOfNotebook(TestBackendConstants._TEST_NOTEBOOK_1_INT); 191 assertEquals(2, annotationInfos.size()); 192 193 assertEquals(TestBackendConstants._TEST_ANNOT_1_HEADLINE, annotationInfos.get(0).getHeadline()); 194 assertEquals(String.valueOf(TestBackendConstants._TEST_ANNOT_1_OWNER), annotationInfos.get(0).getOwner().getRef()); 195 //assertEquals(TestBackendConstants._TEST_ANNOT_1_TARGETS, annotationInfos.get(0).getTargetSources()); 196 197 assertEquals(TestBackendConstants._TEST_ANNOT_2_HEADLINE, annotationInfos.get(1).getHeadline()); 198 assertEquals(String.valueOf(TestBackendConstants._TEST_ANNOT_2_OWNER), annotationInfos.get(1).getOwner().getRef()); 199 //assertEquals(TestBackendConstants._TEST_ANNOT_2_TARGETS, annotationInfos.get(1).getTargetSources()); 200 201 202 //test Two 203 final List<AnnotationInfo> annotationInfosTwo = jdbcNotebookDao.getAnnotationInfosOfNotebook(TestBackendConstants._TEST_NOTEBOOK_2_INT); 204 assertEquals(1, annotationInfosTwo.size()); 205 206 assertEquals(TestBackendConstants._TEST_ANNOT_3_HEADLINE, annotationInfosTwo.get(0).getHeadline()); 207 assertEquals(String.valueOf(TestBackendConstants._TEST_ANNOT_3_OWNER), annotationInfosTwo.get(0).getOwner().getRef()); 208 //assertEquals(TestBackendConstants._TEST_ANNOT_3_TARGETS, annotationInfosTwo.get(0).getTargetSources()); 209 210 //test notebook with no annotations 211 final List<AnnotationInfo> annotationInfosThree = jdbcNotebookDao.getAnnotationInfosOfNotebook(TestBackendConstants._TEST_NOTEBOOK_3_INT); 212 assertEquals(0, annotationInfosThree.size()); 213 214 //non-existing notebook 215 final List<AnnotationInfo> annotationInfosFour = jdbcNotebookDao.getAnnotationInfosOfNotebook(TestBackendConstants._TEST_ANNOT_4_INT_NOT_IN_THE_DB); 216 assertEquals(null, annotationInfosFour); 217 218 219 //null notebook 220 final List<AnnotationInfo> annotationInfosFive = jdbcNotebookDao.getAnnotationInfosOfNotebook(null); 221 assertEquals(null, annotationInfosFive); 222 223 } 224 * */ 173 225 174 226 175 /** … … 262 211 263 212 /** 264 * Test of getAnnotations method, of class Jdbc AnnotationDao.213 * Test of getAnnotations method, of class JdbcNotebookDao. 265 214 * Annotations getAnnotations(Number notebookID) 266 215 */ … … 300 249 } 301 250 251 /** Test of getNotebookInfo method, of class JdbcNotebookDao. 252 * 253 */ 254 @Test 255 public void testGetNotebookInfo() { 256 System.out.println("test getNotebookInfo"); 257 258 // test One 259 NotebookInfo info = jdbcNotebookDao.getNotebookInfo(TestBackendConstants._TEST_NOTEBOOK_1_INT); 260 assertEquals(String.valueOf(TestBackendConstants._TEST_NOTEBOOK_1_EXT), info.getRef()); 261 assertEquals(String.valueOf(TestBackendConstants._TEST_NOTEBOOK_1_TITLE), info.getTitle()); 262 263 // test Two, non-existing notebook 264 NotebookInfo infoTwo = jdbcNotebookDao.getNotebookInfo(TestBackendConstants._TEST_ANNOT_4_INT_NOT_IN_THE_DB); 265 assertEquals(null, infoTwo); 266 267 // test Three Null-notebook 268 NotebookInfo infoThree = jdbcNotebookDao.getNotebookInfo(null); 269 assertEquals(null, infoThree); 270 } 271 272 /** Test of getNotebookID method, of class JdbcNotebookDao. 273 * 274 */ 275 @Test 276 public void testGetNotebookID() { 277 System.out.println("test getNotebookID"); 278 279 // test One 280 Number resultOne= jdbcNotebookDao.getNotebookID(new NotebookIdentifier(TestBackendConstants._TEST_NOTEBOOK_1_EXT)); 281 assertEquals(TestBackendConstants._TEST_NOTEBOOK_1_INT, resultOne.intValue()); 282 283 // test Two, non-existing notebook 284 Number resultTwo= jdbcNotebookDao.getNotebookID(new NotebookIdentifier(TestBackendConstants._TEST_ANNOT_4_EXT_NOT_IN_THE_DB)); 285 assertEquals(null, resultTwo); 286 287 // test Three Null-notebook 288 Number resultThree= jdbcNotebookDao.getNotebookID(null); 289 assertEquals(null, resultThree); 290 } 291 302 292 303 293 //////////////////////////////////////////////////////////////////// … … 351 341 } 352 342 343 353 344 } -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/test/java/eu/dasish/annotation/backend/rest/AnnotationResourceTest.java
r3186 r3188 77 77 }); 78 78 79 JAXBElement result = annotationResource.getAnnotation(annotationIdentifier);79 JAXBElement<Annotation> result = annotationResource.getAnnotation(annotationIdentifier); 80 80 assertEquals(expectedAnnotation, result.getValue()); 81 81 } … … 133 133 134 134 135 JAXBElement result = annotationResource.createAnnotation(annotationToAdd);135 JAXBElement<Annotation> result = annotationResource.createAnnotation(annotationToAdd); 136 136 assertTrue(annotationToAdd.equals(result.getValue())); 137 137 } -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/test/java/eu/dasish/annotation/backend/rest/NotebookResourceTest.java
r3154 r3188 18 18 package eu.dasish.annotation.backend.rest; 19 19 20 import com.sun.jersey.api.client.ClientResponse; 20 21 import eu.dasish.annotation.backend.TestBackendConstants; 21 22 import eu.dasish.annotation.backend.dao.NotebookDao; … … 25 26 import eu.dasish.annotation.schema.NotebookInfo; 26 27 import eu.dasish.annotation.schema.NotebookInfos; 28 import eu.dasish.annotation.schema.ObjectFactory; 27 29 import java.util.ArrayList; 28 30 import java.util.List; 29 31 import java.util.UUID; 32 import javax.ws.rs.core.MediaType; 30 33 import javax.xml.bind.JAXBElement; 31 34 import org.jmock.Expectations; … … 130 133 assertEquals(expResult, result); 131 134 } 135 136 /** 137 * Test of getMetadata method, of class NotebookResource. Get all metadata 138 * about a specified notebook <nid>, including the information if it is 139 * private or not. GET api/notebooks/<nid>/metadata 140 */ 141 @Test 142 public void testGetMetadata() { 143 System.out.println("test GetMetadata"); 144 145 final String notebookIdentifier= TestBackendConstants._TEST_NOTEBOOK_1_EXT; 146 final int notebookID = TestBackendConstants._TEST_NOTEBOOK_1_INT; 147 final NotebookInfo testInfo = new ObjectFactory().createNotebookInfo(); 148 149 mockery.checking(new Expectations() { 150 { 151 oneOf(notebookDao).getNotebookID(new NotebookIdentifier(notebookIdentifier)); 152 will(returnValue(notebookID)); 153 154 oneOf(notebookDao).getNotebookInfo(notebookID); 155 will(returnValue(testInfo)); 156 } 157 }); 158 159 JAXBElement<NotebookInfo> result = notebookResource.getMetadata(notebookIdentifier); 160 NotebookInfo entity = result.getValue(); 161 assertEquals(testInfo.getRef(), entity.getRef()); 162 assertEquals(testInfo.getTitle(), entity.getTitle()); 163 } 164 132 165 } -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/test/java/eu/dasish/annotation/backend/rest/NotebooksTest.java
r3184 r3188 21 21 import com.sun.jersey.api.client.GenericType; 22 22 import com.sun.jersey.api.client.filter.HTTPBasicAuthFilter; 23 import eu.dasish.annotation.backend.TestBackendConstants; 23 24 import eu.dasish.annotation.backend.dao.NotebookDao; 25 import eu.dasish.annotation.backend.identifiers.AnnotationIdentifier; 24 26 import eu.dasish.annotation.backend.identifiers.NotebookIdentifier; 25 27 import eu.dasish.annotation.backend.identifiers.UserIdentifier; 28 import eu.dasish.annotation.schema.Annotation; 26 29 import eu.dasish.annotation.schema.Notebook; 27 30 import eu.dasish.annotation.schema.NotebookInfo; 28 31 import eu.dasish.annotation.schema.NotebookInfos; 32 import eu.dasish.annotation.schema.ObjectFactory; 29 33 import java.net.URI; 30 34 import java.net.URISyntaxException; … … 132 136 @Test 133 137 public void testGetMetadata() { 134 System.out.println("testGetMetadata"); 135 ClientResponse response = resource().path("notebooks/_nid_/metadata").get(ClientResponse.class); 136 assertEquals(200, response.getStatus()); 137 assertEquals("metadata for _nid_", response.getEntity(String.class)); 138 System.out.println("test GetMetadata"); 139 140 final String notebookIdentifier= TestBackendConstants._TEST_NOTEBOOK_1_EXT; 141 final int notebookID = TestBackendConstants._TEST_NOTEBOOK_1_INT; 142 final NotebookInfo testInfo = new ObjectFactory().createNotebookInfo(); 143 144 mockery.checking(new Expectations() { 145 { 146 oneOf(notebookDao).getNotebookID(new NotebookIdentifier(notebookIdentifier)); 147 will(returnValue(notebookID)); 148 149 oneOf(notebookDao).getNotebookInfo(notebookID); 150 will(returnValue(testInfo)); 151 } 152 }); 153 154 final String requestUrl = "notebooks/" + notebookIdentifier+"/metadata"; 155 System.out.println("requestUrl: " + requestUrl); 156 ClientResponse response = resource().path(requestUrl).type(MediaType.TEXT_XML).get(ClientResponse.class); 157 assertEquals(200, response.getStatus()); 158 NotebookInfo entity = response.getEntity(NotebookInfo.class); 159 assertEquals(testInfo.getRef(), entity.getRef()); 160 assertEquals(testInfo.getTitle(), entity.getTitle()); 138 161 } 139 162
Note: See TracChangeset
for help on using the changeset viewer.