Changeset 3303


Ignore:
Timestamp:
08/08/13 08:26:22 (11 years ago)
Author:
olhsha
Message:

updating getInternalID and getExternalID for dao-annotations

Location:
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/AnnotationDao.java

    r3218 r3303  
    5151    Annotation getAnnotation(Number annotationID) throws SQLException;
    5252   
    53     /**
    54      *
    55      * @param externalID
    56      * @return the internal annotationId for the annotation with the external Id "extrnalID"
    57      * if annotationID is null or such annotation does not exist in the DB returns null;
    58      */
    59     Number getAnnotationID(AnnotationIdentifier externalID) throws SQLException;
    60    
     53       
    6154    /**
    6255     *
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/impl/JdbcAnnotationDao.java

    r3272 r3303  
    195195     
    196196     
    197    //////////////////////////////////////////////////
    198      @Override
    199     public Number getAnnotationID(AnnotationIdentifier externalID) throws SQLException{
    200         if (externalID == null) {
    201             return null;
    202         }
    203        
    204        String sql = "SELECT "+annotationAnnotation_id+" FROM "+annotationTableName+" WHERE "+annotationExternal_id+"  = ?";
    205        List<Number> result= getSimpleJdbcTemplate().query(sql, annotationIDRowMapper, externalID.toString());
    206        if (result == null) {
    207            return null;
    208        }
    209        if (result.isEmpty()) {
    210            return null;
    211        }
    212        
    213        if (result.size()>1) {
    214            throw new SQLException("There are "+result.size()+" annotations with"+ external_id +" "+externalID);
    215        }
    216        return result.get(0);
    217    }
    218      
    219       private final RowMapper<Number> annotationIDRowMapper = new RowMapper<Number>() {       
    220         @Override
    221         public Number mapRow(ResultSet rs, int rowNumber) throws SQLException {
    222            Number result = rs.getInt(annotation_id);
    223            return result;
    224         }
    225     };
     197   
    226198     
    227199   @Override   
     
    299271    @Override
    300272    public AnnotationIdentifier getExternalID(Number internalID) {
    301         if (internalID == null) {
    302             return null;
    303         }
    304        
    305        String sql = "SELECT "+annotationExternal_id+" FROM "+annotationTableName+" WHERE "+annotationAnnotation_id+"  = ?";
    306        List<AnnotationIdentifier> result= getSimpleJdbcTemplate().query(sql, externalIDRowMapper, internalID.toString());
    307        if (result == null) {
    308            return null;
    309        }
    310        if (result.isEmpty()) {
    311            return null;
    312        }
    313        return result.get(0);
     273        return new AnnotationIdentifier(super.getExternalIdentifier(internalID));
    314274   }
    315275     
    316       private final RowMapper<AnnotationIdentifier> externalIDRowMapper = new RowMapper<AnnotationIdentifier>() {       
    317         @Override
    318         public AnnotationIdentifier mapRow(ResultSet rs, int rowNumber) throws SQLException {
    319            AnnotationIdentifier result = new AnnotationIdentifier(rs.getString(external_id));
    320            return result;
    321         }
    322     };
    323    
     276   
    324277   
    325278    //////////// helpers ///////////////////////
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/impl/JdbcPermissionsDao.java

    r3218 r3303  
    7575    public int addAnnotationPrincipalPermission(AnnotationIdentifier annotationIdenitifier, UserIdentifier userIdentifier, Permission permission) throws SQLException {
    7676        Map<String, Object> paramsPermissions = new HashMap<String, Object>();
    77         paramsPermissions.put("annotationId", jdbcAnnotationDao.getAnnotationID(annotationIdenitifier));
     77        paramsPermissions.put("annotationId", jdbcAnnotationDao.getInternalID(annotationIdenitifier));
    7878        paramsPermissions.put("principalId", jdbcUserDao.getInternalID(userIdentifier));
    7979        paramsPermissions.put("status", permission.value());
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/rest/AnnotationResource.java

    r3218 r3303  
    7777    @Path("{annotationid: " + BackendConstants.regExpIdentifier + "}")
    7878    public JAXBElement<Annotation> getAnnotation(@PathParam("annotationid") String annotationIdentifier) throws SQLException {
    79         final Annotation annotation = annotationDao.getAnnotation(annotationDao.getAnnotationID(new AnnotationIdentifier(annotationIdentifier)));
     79        final Annotation annotation = annotationDao.getAnnotation(annotationDao.getInternalID(new AnnotationIdentifier(annotationIdentifier)));
    8080        return new ObjectFactory().createAnnotation(annotation);
    8181    }
     
    8787     */
    8888    public String deleteAnnotation(@PathParam("annotationid") String annotationIdentifier) throws SQLException {
    89         Number annotationID = annotationDao.getAnnotationID(new AnnotationIdentifier(annotationIdentifier));       
     89        Number annotationID = annotationDao.getInternalID(new AnnotationIdentifier(annotationIdentifier));       
    9090        String result = Integer.toString(annotationDao.deleteAnnotation(annotationID));
    9191        return result;
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/test/java/eu/dasish/annotation/backend/dao/impl/JdbcAnnotationDaoTest.java

    r3220 r3303  
    142142       System.out.println("getAnnotationID");
    143143       
    144        final Number annotaionId = jdbcAnnotationDao.getAnnotationID(new AnnotationIdentifier(TestBackendConstants._TEST_ANNOT_2_EXT));
     144       final Number annotaionId = jdbcAnnotationDao.getInternalID(new AnnotationIdentifier(TestBackendConstants._TEST_ANNOT_2_EXT));
    145145       assertEquals(2, annotaionId.intValue());
    146146       
    147        final Number annotaionIdNE = jdbcAnnotationDao.getAnnotationID(new AnnotationIdentifier(TestBackendConstants._TEST_ANNOT_7_EXT_NOT_IN_DB));
     147       final Number annotaionIdNE = jdbcAnnotationDao.getInternalID(new AnnotationIdentifier(TestBackendConstants._TEST_ANNOT_7_EXT_NOT_IN_DB));
    148148       assertEquals(null, annotaionIdNE);   
    149149     
    150        final Number annotaionIdNull = jdbcAnnotationDao.getAnnotationID(null);
     150       final Number annotaionIdNull = jdbcAnnotationDao.getInternalID(null);
    151151       assertEquals(null, annotaionIdNull);
    152152    }
     
    274274       
    275275        AnnotationIdentifier generatedAnnotationExternalID  = new AnnotationIdentifier(result.getURI());
    276         Annotation addedAnnotation = jdbcAnnotationDao.getAnnotation(jdbcAnnotationDao.getAnnotationID(generatedAnnotationExternalID));       
     276        Annotation addedAnnotation = jdbcAnnotationDao.getAnnotation(jdbcAnnotationDao.getInternalID(generatedAnnotationExternalID));       
    277277        assertEquals(annotationToAdd.getBody().getAny().get(0), addedAnnotation.getBody().getAny().get(0));
    278278        assertEquals(annotationToAdd.getHeadline(), addedAnnotation.getHeadline());
     
    299299       
    300300       final AnnotationIdentifier externalIdThree = jdbcAnnotationDao.getExternalID(null);
    301        assertEquals(null, externalIdThree);
     301       assertEquals(null, externalIdThree.getUUID());
    302302       
    303303    }
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/test/java/eu/dasish/annotation/backend/rest/AnnotationResourceTest.java

    r3218 r3303  
    8282        mockery.checking(new Expectations() {
    8383            {
    84                 oneOf(annotationDao).getAnnotationID(new AnnotationIdentifier(annotationIdentifier));               
     84                oneOf(annotationDao).getInternalID(new AnnotationIdentifier(annotationIdentifier));               
    8585                will(returnValue(annotationID));               
    8686               
     
    103103        mockery.checking(new Expectations() {
    104104            {
    105                 oneOf(annotationDao).getAnnotationID(new AnnotationIdentifier(TestBackendConstants._TEST_ANNOT_5_EXT));               
     105                oneOf(annotationDao).getInternalID(new AnnotationIdentifier(TestBackendConstants._TEST_ANNOT_5_EXT));               
    106106                will(returnValue(5));     
    107107               
     
    118118        mockery.checking(new Expectations() {
    119119            {
    120                 oneOf(annotationDao).getAnnotationID(new AnnotationIdentifier(TestBackendConstants._TEST_ANNOT_5_EXT));               
     120                oneOf(annotationDao).getInternalID(new AnnotationIdentifier(TestBackendConstants._TEST_ANNOT_5_EXT));               
    121121                will(returnValue(5));
    122122               
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/test/java/eu/dasish/annotation/backend/rest/AnnotationsTest.java

    r3218 r3303  
    6767        mockery.checking(new Expectations() {
    6868            {
    69                 oneOf(annotationDao).getAnnotationID(new AnnotationIdentifier(annotationIdentifier));               
     69                oneOf(annotationDao).getInternalID(new AnnotationIdentifier(annotationIdentifier));               
    7070                will(returnValue(annotationID));
    7171               
     
    9999        mockery.checking(new Expectations() {
    100100            {
    101                 oneOf(annotationDao).getAnnotationID(new AnnotationIdentifier(TestBackendConstants._TEST_ANNOT_5_EXT));               
     101                oneOf(annotationDao).getInternalID(new AnnotationIdentifier(TestBackendConstants._TEST_ANNOT_5_EXT));               
    102102                will(returnValue(5));
    103103               
     
    118118        mockery.checking(new Expectations() {
    119119            {
    120                 oneOf(annotationDao).getAnnotationID(new AnnotationIdentifier(TestBackendConstants._TEST_ANNOT_5_EXT));               
     120                oneOf(annotationDao).getInternalID(new AnnotationIdentifier(TestBackendConstants._TEST_ANNOT_5_EXT));               
    121121                will(returnValue(5));
    122122               
Note: See TracChangeset for help on using the changeset viewer.