Changeset 3142


Ignore:
Timestamp:
07/16/13 15:37:12 (11 years ago)
Author:
olhsha
Message:

testing dao get-methods for annotations (given a notebook) have been implemented.

Location:
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src
Files:
1 added
4 edited

Legend:

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

    r3138 r3142  
    2828 * @author Peter Withers <peter.withers@mpi.nl>
    2929 */
     30
     31// TODO: Getting Target Sources from Body and testing must be added!!!
     32
     33
    3034public interface AnnotationDao {
    3135   
     
    3438   
    3539     // Returns the list of annotation info-s  for the notebook id.
    36     List<AnnotationInfo> getAnnotationInfos(Number notebookID);
     40    List<AnnotationInfo> getAnnotationInfos(List<Number> annotationIDs);   
     41     
     42     // Returns the list of annotation info-s  for the notebook id.
     43    List<AnnotationInfo> getAnnotationInfosOfNotebook(Number notebookID);
     44   
    3745   
    3846     // Returns the list of annotations Id-s  for the notebook id.
    39     List<ResourceREF> getAnnotationREFs(Number notebookID);
     47    List<ResourceREF> getAnnotationREFs(List<Number> annotationIDs);   
     48   
     49     // Returns the list of annotations Id-s  for the notebook id.
     50    List<ResourceREF> getAnnotationREFsOfNotebook(Number notebookID);
    4051   
    4152    // Returns the annotations object for the notebook id.
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/impl/JdbcAnnotationDao.java

    r3138 r3142  
    1919
    2020import eu.dasish.annotation.backend.dao.AnnotationDao;
    21 import eu.dasish.annotation.schema.Annotation;
    2221import eu.dasish.annotation.schema.AnnotationInfo;
    2322import eu.dasish.annotation.schema.Annotations;
     
    2625import java.sql.ResultSet;
    2726import java.sql.SQLException;
     27import java.util.ArrayList;
    2828import java.util.List;
    2929import javax.sql.DataSource;
     
    3737 */
    3838
    39 /*
    40  *  annotation (
    41     annotation_id SERIAL UNIQUE NOT NULL,
    42     external_id UUID UNIQUE NOT NULL,
    43     time_stamp timestamp with time zone default now(),
    44     owner_id integer,
    45     headline tCRext,
    46     body_xml xml
    47 );
    48  *
    49  *
    50  */
     39
    5140
    5241
     
    5847   
    5948    ////////////////////////////////////////////////////////////////////////
     49    /**
     50     *
     51     * @param notebookID
     52     * @return the list of annotation-ids belonging to the notebook with notebookId
     53     * returns null if notebookId is null
     54     * returns empty list if notebookId is not in the DB: getSimpleJdbcTemplate().query is implemented in this way
     55     * TODO: do we need to return null here? using an additional check.
     56     */
    6057     @Override           
    6158    public List<Number> getAnnotationIDs(Number notebookID) {
     59       if (notebookID == null) {
     60           return null;
     61       }
    6262       String sql = "SELECT notebooks_annotations.annotation_id  FROM notebooks_annotations where notebook_id = ?";
    6363       return getSimpleJdbcTemplate().query(sql, annotationIDRowMapper, notebookID.toString());
     
    7474    ////////////////////////////////////////////////////////////////////////////
    7575
    76     @Override
    77     public List<AnnotationInfo> getAnnotationInfos(Number notebookID) {       
    78         String sql = "SELECT annotation.* FROM annotation WHERE annotation.annotation_id  IN ?";
    79         return getSimpleJdbcTemplate().query(sql, annotationInfoRowMapper, getAnnotationIDs(notebookID));
     76   /**
     77    *
     78    * @param annotationIDs is a list of internal annotation identifiers
     79    * @return the list of the corresponding annotation-infos for the annotation identifiers from the list;
     80    * if the input list is null or empty (zero elements) returns an empty list
     81    */
     82   
     83    @Override
     84    public List<AnnotationInfo> getAnnotationInfos(List<Number> annotationIDs) {
     85       
     86        if (annotationIDs == null) {
     87            return null;
     88        }
     89       
     90        if (annotationIDs.isEmpty()) {
     91            return (new ArrayList<AnnotationInfo>());
     92        }
     93               
     94        String values = makeListOfValues(annotationIDs);
     95        String sql = "SELECT annotation.* FROM annotation WHERE annotation.annotation_id  IN "+values;
     96        return getSimpleJdbcTemplate().query(sql, annotationInfoRowMapper);
    8097    }
    8198   
     
    92109   
    93110   
     111    //////////////////////////////////////////////////
     112   
     113    /**
     114     *
     115     * @param notebookID
     116     * @return the list of annotation-infos of the annotations from notebookID;
     117     * if the notebook contains no annotations returns an empty list
     118     */
     119   
     120    @Override
     121    public List<AnnotationInfo> getAnnotationInfosOfNotebook(Number notebookID) {   
     122        return getAnnotationInfos(getAnnotationIDs(notebookID));
     123    }
     124   
    94125    /////////////////////////////////////////////////
    95126   
    96     @Override
    97     public List<ResourceREF> getAnnotationREFs(Number notebookID) {       
    98         String sql = "SELECT annotation.annotation_id FROM annotation WHERE annotation.annotation_id  IN ?";
    99         return getSimpleJdbcTemplate().query(sql, annotationREFRowMapper, getAnnotationIDs(notebookID));
     127    /**
     128     *
     129     * @param annotationIDs
     130     * @return list of annotation references corresponding to the annotation-ids from the input list
     131     * if the input list is null or empty (zero elements) returns an empty list
     132     */
     133   
     134    @Override
     135    public List<ResourceREF> getAnnotationREFs(List<Number> annotationIDs) {
     136       
     137        if (annotationIDs == null) {
     138            return null;
     139        }
     140       
     141        if (annotationIDs.isEmpty()) {
     142            return (new ArrayList<ResourceREF>());
     143        }
     144       
     145        String values = makeListOfValues(annotationIDs);
     146        String sql = "SELECT annotation.annotation_id FROM annotation WHERE annotation.annotation_id  IN "+values;
     147        return getSimpleJdbcTemplate().query(sql, annotationREFRowMapper);
    100148    }
    101149   
     
    109157    };
    110158   
     159    //////////////////////////////////////////////
     160    /**
     161     *
     162     * @param notebookID
     163     * @return the list of annotation References from the notebookID
     164     * returns null if notebookID == null
     165     */
     166   
     167    @Override
     168    public List<ResourceREF> getAnnotationREFsOfNotebook(Number notebookID) {   
     169        return getAnnotationREFs(getAnnotationIDs(notebookID));
     170    }
     171   
     172   
     173     
     174    ////////////////////////////////////////////////////////////////////////////
     175    /**
     176     *
     177     * @param notebookID
     178     * @return the Annotations (as a list of references) from the notebookID     *
     179     * returns null if notebookID == null
     180     */
     181
     182    @Override
     183    public Annotations getAnnotations(Number notebookID) {
     184       
     185        if (notebookID == null) {
     186            return null;
     187        }
     188       
     189        Annotations result =  new Annotations();
     190        List<ResourceREF> annotREFs = result.getAnnotation(); 
     191        // TODO: what of annotREFS is null???? how to allocated emprey for it???
     192        boolean test = annotREFs.addAll(getAnnotationREFsOfNotebook(notebookID));
     193        return (test ? result : null);       
     194    }
     195   
     196   
    111197    /////////////////////////////////////////////////
    112198    private ResourceREF getResourceREF(String resourceID){
     
    118204    //TODO implement when xml-body stucture is discussed!
    119205    //BTW do we have to get source REF, not the whole sources here??
    120     private Sources getSources(String some_xml) {
     206    private Sources getSources(String someXml) {
    121207        Sources result = new Sources();
    122208        return result;
    123209    }
    124210   
    125    
    126    
    127     ////////////////////////////////////////////////////////////////////////////
    128 
    129     @Override
    130     public Annotations getAnnotations(Number notebookID) {       
    131         String sql = "SELECT annotation.* FROM annotation WHERE annotation.annotation_id  IN ?";
    132         return null; // not omplemented yet
    133        
    134     }
     211    private <T> String makeListOfValues(List<T> vals) {
     212       
     213        if (vals == null) {
     214            return "()";
     215        }
     216       
     217        if (vals.isEmpty()) {           
     218            return "()";
     219        }
     220       
     221        String result = "(";
     222        int length = vals.size();
     223        for (int i=0; i<length-1; i++){
     224            result = result + vals.get(i).toString() +", ";
     225        }
     226        result = result +vals.get(length-1).toString()+")";
     227        return result;
     228    }
     229   
    135230   
    136231}
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/test/java/eu/dasish/annotation/backend/TestBackendConstants.java

    r3137 r3142  
    3131    public static final String _TEST_AID_1_ =  "00000000-0000-0000-0000-000000000005";
    3232    public static final String _TEST_NULL_UUID_ = "00000000-0000-0000-0000-000000000006";
    33 
     33   
     34    // testing jdbcAnnotationDao
     35    public static final String _TEST_NOTEBOOK_1_EXT = "00000000-0000-0000-0000-000000000011";
     36    public static final String _TEST_NOTEBOOK_2_EXT = "00000000-0000-0000-0000-000000000012";
     37    public static final String _TEST_NOTEBOOK_3_EXT = "00000000-0000-0000-0000-000000000013";
     38   
     39    public static final int _TEST_NOTEBOOK_1_INT = 11;
     40    public static final int _TEST_NOTEBOOK_2_INT = 12;
     41    public static final int _TEST_NOTEBOOK_3_INT = 13;
     42   
     43    public static final String _TEST_ANNOT_1_EXT = "00000000-0000-0000-0000-000000000021";
     44    public static final String _TEST_ANNOT_2_EXT = "00000000-0000-0000-0000-000000000022";
     45    public static final String _TEST_ANNOT_3_EXT = "00000000-0000-0000-0000-000000000023";
     46   
     47    public static final int _TEST_ANNOT_1_INT = 21;
     48    public static final int _TEST_ANNOT_2_INT = 22;
     49    public static final int _TEST_ANNOT_3_INT = 23;
     50    public static final int _TEST_ANNOT_4_INT_NOT_IN_THE_DB = 24;
     51   
     52    public static final String _TEST_ANNOT_1_HEADLINE = "Sagrada Famiglia";
     53    public static final String _TEST_ANNOT_2_HEADLINE = "Gaudi";
     54    public static final String _TEST_ANNOT_3_HEADLINE = "Art Nuveau";
     55   
     56    public static final int _TEST_ANNOT_1_OWNER = 111;
     57    public static final int _TEST_ANNOT_2_OWNER = 112;
     58    public static final int _TEST_ANNOT_3_OWNER = 113;
     59   
    3460}
    3561
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/test/resources/test-data/InsertTestData.sql

    r3137 r3142  
    2828INSERT INTO notebooks_annotations (notebook_id,annotation_id) VALUES (1,1);
    2929INSERT INTO notebooks_annotations (notebook_id,annotation_id) VALUES (2,1);
     30
     31
     32-- Test data for jdbcAnnotationDao --
     33
     34INSERT INTO notebook (notebook_id, title, owner_id, external_id) VALUES (11, 'Notebook 11', 111, '00000000-0000-0000-0000-000000000011');
     35INSERT INTO notebook (notebook_id, title, owner_id, external_id) VALUES (12, 'Notebook 12', 112, '00000000-0000-0000-0000-000000000012');
     36INSERT INTO notebook (notebook_id, title, owner_id, external_id) VALUES (13, 'Notebook 13', 113, '00000000-0000-0000-0000-000000000013');
     37
     38INSERT INTO annotation (annotation_id, owner_id,headline,body_xml, external_id) VALUES (21, 111, 'Sagrada Famiglia','<html><body>some html</body></html>', '00000000-0000-0000-0000-000000000021');
     39INSERT INTO annotation (annotation_id, owner_id,headline,body_xml, external_id) VALUES (22, 112, 'Gaudi','<html><body>some html</body></html>', '00000000-0000-0000-0000-000000000022');
     40INSERT INTO annotation (annotation_id, owner_id,headline,body_xml, external_id) VALUES (23, 113, 'Art Nuveau','<html><body>some html</body></html>', '00000000-0000-0000-0000-000000000023');
     41
     42INSERT INTO notebooks_annotations (notebook_id,annotation_id) VALUES (11,21);
     43INSERT INTO notebooks_annotations (notebook_id,annotation_id) VALUES (11,22);
     44INSERT INTO notebooks_annotations (notebook_id,annotation_id) VALUES (12,23);
     45
     46
Note: See TracChangeset for help on using the changeset viewer.