Changeset 3188


Ignore:
Timestamp:
07/24/13 13:37:29 (11 years ago)
Author:
olhsha
Message:

GET notebooks/nid/metadata full chain is implemented (probably NotebookInfo? will be extended in the future, though)

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  
    1919
    2020import eu.dasish.annotation.backend.identifiers.AnnotationIdentifier;
    21 import eu.dasish.annotation.backend.identifiers.NotebookIdentifier;
    22 import eu.dasish.annotation.backend.identifiers.UserIdentifier;
    2321import eu.dasish.annotation.schema.Annotation;
    2422import 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  
    6262    Annotations getAnnotations(Number notebookID);
    6363   
    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);
    6571   
     72    /**
     73     *
     74     * @param externalId
     75     * @return the notebook's internal ID, given its extrnalId
     76     */
     77    Number getNotebookID(NotebookIdentifier externalId);
    6678}
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/ResourceDao.java

    r3146 r3188  
    1818package eu.dasish.annotation.backend.dao;
    1919
     20import java.util.UUID;
     21
    2022/**
    2123 *
     
    3133    public boolean isNotebookInTheDataBase(Number notebookID);
    3234   
     35   
    3336}
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/impl/JdbcNotebookDao.java

    r3167 r3188  
    8888        public NotebookInfo mapRow(ResultSet rs, int rowNumber) throws SQLException {
    8989            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"
    9191            notebookInfo.setTitle(rs.getString(title));
    9292//            notebookInfo.setRef(rs.getString("URI"));
     
    226226
    227227    }
     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    };
    228273}
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/impl/JdbcResourceDao.java

    r3167 r3188  
    2222import java.sql.SQLException;
    2323import java.util.List;
     24import java.util.UUID;
    2425import org.springframework.jdbc.core.RowMapper;
    2526import org.springframework.jdbc.core.simple.SimpleJdbcDaoSupport;
     
    6364    final static protected String notebookOwner_id = notebookTableName+"."+owner_id;
    6465   
    65     final static protected String notebooksAnnotationsTableNameAnnotation_id = "notebooks_annotations.annotation_id";
     66   
     67    final static protected String notebooksAnnotationsTableNameAnnotation_id = notebooksAnnotationsTableName+"."+annotation_id;
     68   
    6669   
    6770    final static protected String principalPrincipal_id = principalTableName+"."+principal_id;
     
    100103    };
    101104   
     105     
    102106}
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/rest/NotebookResource.java

    r3111 r3188  
    1818package eu.dasish.annotation.backend.rest;
    1919
     20import eu.dasish.annotation.backend.BackendConstants;
    2021import eu.dasish.annotation.backend.identifiers.UserIdentifier;
    2122import eu.dasish.annotation.backend.dao.NotebookDao;
    2223import eu.dasish.annotation.backend.identifiers.NotebookIdentifier;
    2324import eu.dasish.annotation.schema.Notebook;
     25import eu.dasish.annotation.schema.NotebookInfo;
    2426import eu.dasish.annotation.schema.NotebookInfos;
    2527import eu.dasish.annotation.schema.ObjectFactory;
     
    102104
    103105    @GET
    104     @Produces("text/html")
    105     @Path("{notebookid: [a-zA-Z0-9_]*}/metadata")
     106    @Produces(MediaType.TEXT_XML)
     107    @Path("{notebookid: "+BackendConstants.regExpIdentifier+"}/metadata")
    106108    // 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       
    109114    }
    110115
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/test/java/eu/dasish/annotation/backend/TestBackendConstants.java

    r3180 r3188  
    3737    public static final String _TEST_NOTEBOOK_3_EXT = "00000000-0000-0000-0000-000000000013";
    3838   
     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   
    3943    public static final int _TEST_NOTEBOOK_1_INT = 11;
    4044    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  
    2222import eu.dasish.annotation.backend.identifiers.NotebookIdentifier;
    2323import eu.dasish.annotation.backend.identifiers.UserIdentifier;
    24 import eu.dasish.annotation.schema.AnnotationInfo;
    2524import eu.dasish.annotation.schema.Annotations;
    2625import eu.dasish.annotation.schema.Notebook;
     
    172171    }
    173172   
    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   
    225174   
    226175    /**
     
    262211
    263212    /**
    264      * Test of getAnnotations method, of class JdbcAnnotationDao.
     213     * Test of getAnnotations method, of class JdbcNotebookDao.
    265214     * Annotations getAnnotations(Number notebookID)
    266215     */
     
    300249    }
    301250   
     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   
    302292   
    303293    ////////////////////////////////////////////////////////////////////
     
    351341     }
    352342       
     343     
    353344}
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/test/java/eu/dasish/annotation/backend/rest/AnnotationResourceTest.java

    r3186 r3188  
    7777        });
    7878         
    79         JAXBElement result = annotationResource.getAnnotation(annotationIdentifier);
     79        JAXBElement<Annotation> result = annotationResource.getAnnotation(annotationIdentifier);
    8080        assertEquals(expectedAnnotation, result.getValue());
    8181    }
     
    133133       
    134134       
    135         JAXBElement result = annotationResource.createAnnotation(annotationToAdd);
     135        JAXBElement<Annotation> result = annotationResource.createAnnotation(annotationToAdd);
    136136        assertTrue(annotationToAdd.equals(result.getValue()));
    137137    }
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/test/java/eu/dasish/annotation/backend/rest/NotebookResourceTest.java

    r3154 r3188  
    1818package eu.dasish.annotation.backend.rest;
    1919
     20import com.sun.jersey.api.client.ClientResponse;
    2021import eu.dasish.annotation.backend.TestBackendConstants;
    2122import eu.dasish.annotation.backend.dao.NotebookDao;
     
    2526import eu.dasish.annotation.schema.NotebookInfo;
    2627import eu.dasish.annotation.schema.NotebookInfos;
     28import eu.dasish.annotation.schema.ObjectFactory;
    2729import java.util.ArrayList;
    2830import java.util.List;
    2931import java.util.UUID;
     32import javax.ws.rs.core.MediaType;
    3033import javax.xml.bind.JAXBElement;
    3134import org.jmock.Expectations;
     
    130133        assertEquals(expResult, result);
    131134    }
     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
    132165}
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/test/java/eu/dasish/annotation/backend/rest/NotebooksTest.java

    r3184 r3188  
    2121import com.sun.jersey.api.client.GenericType;
    2222import com.sun.jersey.api.client.filter.HTTPBasicAuthFilter;
     23import eu.dasish.annotation.backend.TestBackendConstants;
    2324import eu.dasish.annotation.backend.dao.NotebookDao;
     25import eu.dasish.annotation.backend.identifiers.AnnotationIdentifier;
    2426import eu.dasish.annotation.backend.identifiers.NotebookIdentifier;
    2527import eu.dasish.annotation.backend.identifiers.UserIdentifier;
     28import eu.dasish.annotation.schema.Annotation;
    2629import eu.dasish.annotation.schema.Notebook;
    2730import eu.dasish.annotation.schema.NotebookInfo;
    2831import eu.dasish.annotation.schema.NotebookInfos;
     32import eu.dasish.annotation.schema.ObjectFactory;
    2933import java.net.URI;
    3034import java.net.URISyntaxException;
     
    132136    @Test
    133137    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());
    138161    }
    139162
Note: See TracChangeset for help on using the changeset viewer.