Changeset 3189


Ignore:
Timestamp:
07/24/13 16:32:22 (11 years ago)
Author:
olhsha
Message:

getting getAllNotebooks is implemented. HOWEVER: UPDATE the NotebooksTest?.java with the new test for rest interface

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  
    7676    public AnnotationIdentifier addAnnotation(Annotation annotation);
    7777 
    78    
     78    /**
     79     *
     80     * @param internalId
     81     * @return the external identifier for the annotation with internalId
     82     */
     83    public AnnotationIdentifier getExternalID(Number internalId);
    7984}
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/NotebookDao.java

    r3188 r3189  
    7676     */
    7777    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);
    7884}
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/impl/JdbcAnnotationDao.java

    r3180 r3189  
    264264     
    265265   
     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   
    266292   
    267293    //////////// helpers ///////////////////////
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/impl/JdbcNotebookDao.java

    r3188 r3189  
    2929import java.sql.ResultSet;
    3030import java.sql.SQLException;
     31import java.util.ArrayList;
    3132import java.util.GregorianCalendar;
    3233import java.util.HashMap;
     
    228229   
    229230    ///////////////////////////////////////////////////
    230     // RESUSES notebookInfoRowMapper
     231    // REUSES notebookInfoRowMapper
    231232    @Override
    232233    public NotebookInfo getNotebookInfo(Number notebookID) {
     
    271272        }
    272273    };
     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    }
    273289}
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/identifiers/AnnotationIdentifier.java

    r3137 r3189  
    2020import eu.dasish.annotation.backend.BackendConstants;
    2121import java.util.UUID;
     22import javax.xml.bind.annotation.XmlRootElement;
    2223
    2324/**
     
    2627 * @author Peter Withers <peter.withers@mpi.nl>
    2728 */
     29@XmlRootElement (name = "AnnotationIdentifier")
    2830public class AnnotationIdentifier extends DasishIdentifier {   
    2931
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/identifiers/DasishIdentifier.java

    r3137 r3189  
    1818package eu.dasish.annotation.backend.identifiers;
    1919import java.util.UUID;
     20import javax.xml.bind.annotation.XmlElement;
    2021
    2122/**
     
    2526public class DasishIdentifier {
    2627   
     28    @XmlElement(required = true)
    2729    final private UUID _identifier;
     30   
    2831   
    2932    private int _hashParameterOne;
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/rest/NotebookResource.java

    r3188 r3189  
    1919
    2020import eu.dasish.annotation.backend.BackendConstants;
     21import eu.dasish.annotation.backend.dao.AnnotationDao;
    2122import eu.dasish.annotation.backend.identifiers.UserIdentifier;
    2223import eu.dasish.annotation.backend.dao.NotebookDao;
     24import eu.dasish.annotation.backend.identifiers.AnnotationIdentifier;
    2325import eu.dasish.annotation.backend.identifiers.NotebookIdentifier;
    2426import eu.dasish.annotation.schema.Notebook;
     
    2830import java.net.URI;
    2931import java.net.URISyntaxException;
     32import java.util.ArrayList;
    3033import java.util.List;
    3134import javax.servlet.http.HttpServletRequest;
     
    5760    @Autowired
    5861    private NotebookDao notebookDao;
     62    @Autowired
     63    private AnnotationDao annotationDao;
    5964
    6065    @GET
     
    115120
    116121    @GET
    117     @Path("{notebookid: [a-zA-Z0-9_]*}")
     122    @Path("{notebookid: "+BackendConstants.regExpIdentifier+"}")
    118123    /*
    119124     * Get the list of all annotations _aid_-s contained within a Notebook with related metadata.
     
    124129     * optional orderingMode specifies if the results should be sorted using a descending order desc=1 or an ascending order desc=0 (default: 0 ).
    125130     * */
    126     @Produces("text/html")
    127     public String getAllAnnotations(@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,
    128133            @DefaultValue("-1") @QueryParam(value = "startAnnotation") final int startAnnotation,
    129134            @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!!
    132139    }
    133140
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/test/java/eu/dasish/annotation/backend/dao/impl/JdbcAnnotationDaoTest.java

    r3180 r3189  
    195195       
    196196    }
     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    }
    197212}
    198213
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/test/java/eu/dasish/annotation/backend/dao/impl/JdbcNotebookDaoTest.java

    r3188 r3189  
    2020import eu.dasish.annotation.backend.TestBackendConstants;
    2121import eu.dasish.annotation.backend.dao.AnnotationDao;
     22import eu.dasish.annotation.backend.identifiers.AnnotationIdentifier;
    2223import eu.dasish.annotation.backend.identifiers.NotebookIdentifier;
    2324import eu.dasish.annotation.backend.identifiers.UserIdentifier;
     
    291292   
    292293   
     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   
    293324    ////////////////////////////////////////////////////////////////////
    294325    //////// Setting Mockeries /////////////////////////////////////////
     
    311342
    312343     private void setMockeryNotebookTwo(){
    313       ResourceREF testRef = new ResourceREF();
     344        ResourceREF testRef = new ResourceREF();
    314345        testRef.setRef(String.valueOf(TestBackendConstants._TEST_ANNOT_3_INT));
    315346        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  
    1818package eu.dasish.annotation.backend.rest;
    1919
    20 import com.sun.jersey.api.client.ClientResponse;
    2120import eu.dasish.annotation.backend.TestBackendConstants;
     21import eu.dasish.annotation.backend.dao.AnnotationDao;
    2222import eu.dasish.annotation.backend.dao.NotebookDao;
     23import eu.dasish.annotation.backend.identifiers.AnnotationIdentifier;
    2324import eu.dasish.annotation.backend.identifiers.NotebookIdentifier;
    2425import eu.dasish.annotation.backend.identifiers.UserIdentifier;
     
    3031import java.util.List;
    3132import java.util.UUID;
    32 import javax.ws.rs.core.MediaType;
    3333import javax.xml.bind.JAXBElement;
    3434import org.jmock.Expectations;
     
    5454    @Autowired
    5555    private NotebookDao notebookDao;
     56    @Autowired
     57    private AnnotationDao annotationDao;   
    5658    @Autowired
    5759    private NotebookResource notebookResource;
     
    163165    }
    164166
     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    }
    165193}
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/test/java/eu/dasish/annotation/backend/rest/NotebooksTest.java

    r3188 r3189  
    175175     */
    176176    @Test
     177    @Ignore
    177178    public void testGetAllAnnotations() {
    178179        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)
    180201                .queryParam("maximumAnnotations", "123")
    181202                .queryParam("startAnnotation", "456")
     
    183204                .queryParam("orderingMode", "1")
    184205                .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       
    187211    }
    188212
Note: See TracChangeset for help on using the changeset viewer.