Changeset 3380


Ignore:
Timestamp:
08/14/13 16:34:29 (11 years ago)
Author:
olhsha
Message:

"put updated body" is implemented and tested. Big refactring: simplifying DAO's and pushing their composition to rest methods. add-methods in DAO return now not the classes but internalID-s of the added resources. Still 2 test errors and 2 test failures.

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

Legend:

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

    r3369 r3380  
    2121import eu.dasish.annotation.backend.identifiers.UserIdentifier;
    2222import eu.dasish.annotation.schema.Annotation;
     23import eu.dasish.annotation.schema.AnnotationBody;
    2324import eu.dasish.annotation.schema.AnnotationInfo;
     25import eu.dasish.annotation.schema.NewOrExistingSourceInfo;
    2426import eu.dasish.annotation.schema.ResourceREF;
    2527import java.sql.SQLException;
    2628import java.sql.Timestamp;
    2729import java.util.List;
     30import java.util.Map;
    2831
    2932/**
     
    5457    Annotation getAnnotation(Number annotationID) throws SQLException;
    5558   
    56        
     59   
    5760    /**
    5861     *
    5962     * @param annotationId
    60      * @return the amount of deleted sources; removes _aid_ from the DB, together with its tagrget sources to
    61      * which no other annotations refers.
     63     * @return
     64     * result[0] = # removed notebooks_annotations rows
     65     * result[1] = # removed "annotations_principals_perissions" rows
     66     * result[2] = # removed "annotatiobs_target_sources" rows
     67     * result[3] = # SAFELY removed "target_sources" rows (only unused)
     68     * result[4] = # removed annotation rows (should be 1)
    6269     */
    6370   
    64     public int deleteAnnotation(Number annotationId) throws SQLException;
     71    public int[] deleteAnnotation(Number annotationId) throws SQLException;
    6572   
    6673   
     
    6976     *
    7077     * @param annotation added to the table with annotations
    71      * @return annotationIdentifier of the newly added annotation; returns null if something went wrong and annotation was not added or more than one row in the annotation table was affected
    72      */
    73     public Annotation addAnnotation(Annotation annotation, Number ownerID) throws SQLException;
     78     * @return  internal Id of the added annotation
     79     **/
     80   
     81    public Number addAnnotation(Annotation annotation, Number ownerID) throws SQLException;
    7482 
    7583     
     
    8997     * -- owned by "owner",
    9098     * -- added to the database between "before" and "after" time-dates.
     99     *
     100     *
     101     * The first step for GET api/annotations?<filters>
    91102     */
    92103    public List<Number> getFilteredAnnotationIDs(String link, String text, String access, String namespace, UserIdentifier owner, Timestamp after, Timestamp before);
     
    97108     * @param annotationIDs
    98109     * @return the list of annotationInfos (owner, headline, target sources, external_id) for the internal Ids from the  input list
    99      * used on the second step for for GET api/annotations?<filters>
     110     * used on the second step for GET api/annotations?<filters>
    100111     */
    101112    public List<AnnotationInfo> getAnnotationInfos(List<Number> annotationIDs);   
     
    113124   
    114125   
     126    // NOT TESTED
     127    public int updateBody(Number annotationID, String serializedNewBody);
     128   
     129     /**
     130     *
     131     * @param annotationID
     132     * @return the list of the source's internal IDs of all the target sources of annotationID
     133     */
     134    public List<Number> retrieveSourceIDs(Number annotationID);
     135   
     136    /**
     137     *
     138     * @param body
     139     * @return serialized body
     140     */
     141    //NOT TESTED, will be changed after serialization is fixed
     142    public String serializeBody(AnnotationBody body);
     143   
     144    /**
     145     *
     146     * @param bodyXml
     147     * @return deserialized body
     148     */
     149    // NOT TESTED will be chnaged after serializaion is fixed
     150    public AnnotationBody deserializeBody(String bodyXml);
     151   
     152    /**
     153     *
     154     * @param serializedBody
     155     * @param sourcePairs
     156     * @return replaces temporary source IDs with persistent ones (after they are added)
     157     */   
     158   
     159    //NOT TESTED
     160    public String updateTargetRefsInBody(String serializedBody, Map<String, String> sourceIDPairs);
    115161}
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/CachedRepresentationDao.java

    r3372 r3380  
    6161     *
    6262     * @param cached
    63      * @return copy of "cached" after "cached" is added to the DB; the internal id is set in the return copy
     63     * @return the internal Id of the just added "cached"
    6464     */
    65     public CachedRepresentationInfo addCachedRepresentationInfo(CachedRepresentationInfo cached);
     65    public Number addCachedRepresentationInfo(CachedRepresentationInfo cached);
    6666   
    6767   
    68    
    6968 
    7069}
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/ResourceDao.java

    r3373 r3380  
    3333    public <T extends DasishIdentifier> Number getInternalID(T externalId);
    3434   
    35    
    36      /**   
    37      * @param notebookID
    38      * @return false if notebookID == null or the notebook with notebookID is not in the DB;
    39      * @return true if the notebook with notebookID in the DB
    40      */
    41    
    4235   
    4336}
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/SourceDao.java

    r3365 r3380  
    4040    public SourceIdentifier getExternalID(Number internalID);
    4141   
    42     /**
    43      *
    44      * @param annotationID
    45      * @return the list of the source's internal IDs of all the target sources of annotationID
    46      */
    47     public List<Number> retrieveSourceIDs(Number annotationID);
     42   
    4843   
    4944    /**
     
    5348     */
    5449    public Source getSource(Number internalID);
     50   
     51    /**
     52     *
     53     * @param internalID
     54     * @return the  map "colum name" --> vale for the source form the DB
     55     */
     56    public Map<String, Object> getRawSource(Number internalID);
    5557   
    5658    /**
     
    6668     * @param freshSource
    6769     * adds freshSource to the DB and assigns the fresh external Identifier to it
    68      * @return the copy of freshSource with the assigned external identifier
     70     * @return the internal ID of the just added source
     71     * return -1 id the source cannot be added because its version is not in the DB
    6972     */
    70     public Source addSource(Source freshSource) throws SQLException;
     73    public Number addSource(Source freshSource) throws SQLException;
    7174   
    7275    //////////////////////////////////////////////
     
    7780     * @return the Information about the target sources to which annotationId refers
    7881     */
    79     public List<SourceInfo> getSourceInfos(Number annotationID);
     82    public List<SourceInfo> getSourceInfos(List<Number> sources);
    8083   
    8184   /**
     
    101104     * @param annotationID
    102105     * @param sources
    103      * @return the mapping of a (possible new, freshly added) source onto the corresponding same source in the DB.
    104      * The difference between the argument/key source and the value source is just their internal and external identifiers.
    105      * The already existing source is mapped onto itself.
     106     * @return the mapping of a (temporary source ID  onto the corresponding same source persisten ID  in the DB.
    106107     * The side-effect: the joint table "annotations_target_sources" is extended by the pairs (annotationID, addedSoiurceID).
     108     * Also: calls "addSource" if the source is not yet in the DB.
    107109     */
    108     public Map<NewOrExistingSourceInfo, NewOrExistingSourceInfo> addTargetSources(Number annotationID, List<NewOrExistingSourceInfo> sources) throws SQLException;       
     110    public Map<String, String> addTargetSources(Number annotationID, List<NewOrExistingSourceInfo> sources) throws SQLException;       
    109111   
    110112    /**
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/VersionDao.java

    r3372 r3380  
    6363     *
    6464     * @param version
    65      * @return the copy of "version" with the new external Id set in "version" text field  (for now)
     65     * @return the internal Id of the just added version
    6666     *
    6767     */
    68     public Version addVersion(Version version);
     68    public Number addVersion(Version version);
    6969   
    7070    /**
     
    8989     */
    9090    public  int[] deleteCachedRepresentationForSource(Number sourceID, Number cachedRepresentationID);
     91   
     92    public Number getInternalID(VersionIdentifier externalID);
    9193}
    9294   
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/impl/JdbcAnnotationDao.java

    r3370 r3380  
    7070
    7171    @Override
     72    public List<Number> retrieveSourceIDs(Number annotationID) {
     73        String sql = "SELECT " + source_id + " FROM " + annotationsSourcesTableName + " WHERE " + annotation_id + "= ?";
     74        List<Number> result = getSimpleJdbcTemplate().query(sql, annotationSourceRowMapper, annotationID);
     75        return result;
     76    }
     77    private final RowMapper<Number> annotationSourceRowMapper = new RowMapper<Number>() {
     78        @Override
     79        public Number mapRow(ResultSet rs, int rowNumber) throws SQLException {
     80            Number result = rs.getInt(source_id);
     81            return result;
     82        }
     83    };
     84
     85    @Override
    7286    public List<Number> getFilteredAnnotationIDs(String link, String text, String access, String namespace, UserIdentifier owner, Timestamp after, Timestamp before) {
    73        
     87
    7488        StringBuilder sql = new StringBuilder("SELECT DISTINCT ");
    75         sql.append(annotation_id).append(" FROM ").append(annotationTableName).append(" WHERE TRUE ");       
     89        sql.append(annotation_id).append(" FROM ").append(annotationTableName).append(" WHERE TRUE ");
    7690        Map<String, Object> params = new HashMap<String, Object>();
    77        
    78          if (link != null) {
     91
     92        if (link != null) {
    7993            List<Number> sourceIDs = jdbcSourceDao.getSourcesForLink(link);
    8094            List<Number> annotationIDs = getAnnotationIDsForSources(sourceIDs);
     
    8296                String values = makeListOfValues(annotationIDs);
    8397                sql.append(" AND ").append(annotation_id).append(" IN ").append(values);
    84             }
    85             else{
     98            } else {
    8699                return new ArrayList<Number>();
    87100            }
    88101        }
    89          
     102
    90103
    91104        if (owner != null) {
     
    101114
    102115        if (before != null) {
    103             sql.append(" AND ").append(time_stamp).append("  < :before");           
     116            sql.append(" AND ").append(time_stamp).append("  < :before");
    104117            params.put("before", before);
    105118        }
     
    108121            sql.append(" AND ").append(body_xml).append("  LIKE '%").append(text).append("%'");
    109122        }
    110        
    111        
     123
     124
    112125        List<Number> result = getSimpleJdbcTemplate().query(sql.toString(), internalIDRowMapper, params);
    113126        return result;
    114127    }
    115    
     128
    116129    //////////////////////////////
    117    
    118     @Override
    119     public List<Number> getAnnotationIDsForSources(List<Number> sourceIDs){       
     130    @Override
     131    public List<Number> getAnnotationIDsForSources(List<Number> sourceIDs) {
    120132        if (sourceIDs == null) {
    121133            return null;
    122         }       
     134        }
    123135        if (sourceIDs.isEmpty()) {
    124            return new ArrayList<Number>();
    125         }       
     136            return new ArrayList<Number>();
     137        }
    126138        String values = makeListOfValues(sourceIDs);
    127139        StringBuilder query = new StringBuilder("SELECT DISTINCT ");
     
    131143        return result;
    132144    }
    133            
    134    
    135145
    136146    @Override
     
    146156
    147157        String values = makeListOfValues(annotationIDs);
    148         String sql = "SELECT " + annotationStar + " FROM " + annotationTableName + " WHERE " + annotationAnnotation_id + "  IN " + values;
     158        String sql = "SELECT DISTINCT " + annotationStar + " FROM " + annotationTableName + " WHERE " + annotationAnnotation_id + "  IN " + values;
    149159        return getSimpleJdbcTemplate().query(sql, annotationInfoRowMapper);
    150160    }
     
    165175     * @return list of annotation references corresponding to the annotation-ids
    166176     * from the input list if the input list is null or empty (zero elements)
    167      * returns an empty list
    168      * there may be annotationIDs which are not in the DB (so that's why we need this method).
     177     * returns an empty list there may be annotationIDs which are not in the DB
     178     * (so that's why we need this method).
    169179     */
    170    
    171180    @Override
    172181    public List<ResourceREF> getAnnotationREFs(List<Number> annotationIDs) {
     
    181190
    182191        String values = makeListOfValues(annotationIDs);
    183         String sql = "SELECT " + annotationAnnotation_id + " FROM " + annotationTableName + " WHERE " + annotationAnnotation_id + "  IN " + values;
     192        String sql = "SELECT DISTINCT " + annotationAnnotation_id + " FROM " + annotationTableName + " WHERE " + annotationAnnotation_id + "  IN " + values;
    184193        return getSimpleJdbcTemplate().query(sql, annotationREFRowMapper);
    185194    }
     
    199208            return null;
    200209        }
    201         String sql = "SELECT " + annotationStar + " FROM " + annotationTableName + " WHERE " + annotationAnnotation_id + "= ?";
     210        String sql = "SELECT " + annotationStar + " FROM " + annotationTableName + " WHERE " + annotationAnnotation_id + "= ? LIMIT  1";
    202211        List<Annotation> result = getSimpleJdbcTemplate().query(sql, annotationRowMapper, annotationID);
    203212
     
    221230            result.setHeadline(rs.getString(headline));
    222231
    223             result.setBody(convertToAnnotationBody(rs.getString(body_xml)));
    224 
    225             List<SourceInfo> sourceInfoList = jdbcSourceDao.getSourceInfos(rs.getInt(annotation_id));
     232            result.setBody(deserializeBody(rs.getString(body_xml)));
     233
     234            List<SourceInfo> sourceInfoList = jdbcSourceDao.getSourceInfos(retrieveSourceIDs(rs.getInt(annotation_id)));
    226235            NewOrExistingSourceInfos noeSourceInfos = jdbcSourceDao.contructNewOrExistingSourceInfo(sourceInfoList);
    227236            result.setTargetSources(noeSourceInfos);
     
    241250    };
    242251
    243     private AnnotationBody convertToAnnotationBody(String input) {
    244         if (input == null) {
    245             return null;
    246         }
    247 
    248         AnnotationBody result = new AnnotationBody();
    249         List<Object> element = result.getAny();
    250         element.add(input);
    251         return result;
    252     }
    253 
    254     @Override
    255     public int deleteAnnotation(Number annotationId) throws SQLException {
     252    @Override
     253    public int[] deleteAnnotation(Number annotationId) throws SQLException {
     254
     255        int[] result = new int[5];
    256256
    257257        String sqlNotebooks = "DELETE FROM " + notebooksAnnotationsTableName + " where " + annotation_id + " = ?";
    258         int affectedNotebooks = getSimpleJdbcTemplate().update(sqlNotebooks, annotationId);
     258        result[0] = getSimpleJdbcTemplate().update(sqlNotebooks, annotationId);// removed "notebooks_annotations" rows
    259259
    260260        String sqlPermissions = "DELETE FROM " + permissionsTableName + " where " + annotation_id + " = ?";
    261         int affectedPermissions = getSimpleJdbcTemplate().update(sqlPermissions, annotationId);
     261        result[1] = getSimpleJdbcTemplate().update(sqlPermissions, annotationId); // removed "permission" rows
    262262
    263263        // safe removing sources
    264         List<Number> sourceIDs = jdbcSourceDao.retrieveSourceIDs(annotationId);
     264        List<Number> sourceIDs = retrieveSourceIDs(annotationId);
    265265        String sqlTargetSources = "DELETE FROM " + annotationsSourcesTableName + " where " + annotation_id + " = ?";
    266         int affectedAnnotationsSources = getSimpleJdbcTemplate().update(sqlTargetSources, annotationId);
    267         int affectedSources;
     266        result[2] = getSimpleJdbcTemplate().update(sqlTargetSources, annotationId); // removed "annotations_target_sources" rows
     267        result[3] = 0; //removed "target_source" rows
    268268        for (Number sourceID : sourceIDs) {
    269             // call  the method in sources DAO that handles removal of a source which is not refered by other annotations
    270             affectedSources = jdbcSourceDao.deleteSource(sourceID);
     269            result[3] = result[3] + jdbcSourceDao.deleteSource(sourceID);
    271270        }
    272271
    273272        String sqlAnnotation = "DELETE FROM " + annotationTableName + " where " + annotation_id + " = ?";
    274         int affectedAnnotations = getSimpleJdbcTemplate().update(sqlAnnotation, annotationId);
    275         if (affectedAnnotations > 1) {
    276             throw new SQLException("There was more than one annotation (" + affectedAnnotations + ") with the same ID " + annotationId);
    277         }
    278         return affectedAnnotations;
    279         //TODO implement deleting sources (see the specification document and the interfaces' javadoc
     273        result[4] = getSimpleJdbcTemplate().update(sqlAnnotation, annotationId); // removed annotations rows
     274
     275        return result;
    280276    }
    281277
     
    283279    // Change it when the decision is taken!!!
    284280    @Override
    285     public Annotation addAnnotation(Annotation annotation, Number ownerID) throws SQLException {
    286 
    287         Annotation result = makeDeepCopy(annotation);
    288 
    289         ResourceREF ownerRef = new ResourceREF();
    290         ownerRef.setRef(String.valueOf(ownerID));
    291         result.setOwner(ownerRef);
     281    public Number addAnnotation(Annotation annotation, Number ownerID) throws SQLException {
    292282
    293283        // generate a new annotation ID
    294284        AnnotationIdentifier annotationIdentifier = new AnnotationIdentifier();
    295         result.setURI(annotationIdentifier.toString());
    296 
    297285        Map<String, Object> params = new HashMap<String, Object>();
    298286        params.put("externalId", annotationIdentifier.toString());
    299         //params.put("timeStamp", annotation.getTimeStamp()); is generated while adding the annotation in the DB as "now"
    300287        params.put("ownerId", ownerID);
    301288        params.put("headline", annotation.getHeadline());
    302289        params.put("bodyXml", annotation.getBody().getAny().get(0).toString());
    303290
    304         try {
    305 
    306             String sql = "INSERT INTO " + annotationTableName + "(" + external_id + "," + owner_id + "," + headline + "," + body_xml + " ) VALUES (:externalId, :ownerId, :headline, :bodyXml)";
    307             final int affectedRows = getSimpleJdbcTemplate().update(sql, params);
    308 
    309             if (affectedRows != 1) {
    310                 throw (new SQLException("Cannot add the annotation properly"));
    311             }
    312 
    313             Number internalID = getInternalID(annotationIdentifier);
    314 
    315             //retrieve taime stamp for the just added annotation
    316             result.setTimeStamp(retrieveTimeStamp(internalID));
    317 
    318             // place new target sources in the DB, when necessary, update the corresponding target source info for the result
    319             // the joint annotations_target_sources" tabel is updated.
    320             List<NewOrExistingSourceInfo> sources = result.getTargetSources().getTarget();
    321             Map<NewOrExistingSourceInfo, NewOrExistingSourceInfo> sourcePairs = jdbcSourceDao.addTargetSources(internalID, sources);
    322             sources.clear();
    323             sources.addAll(sourcePairs.values());
    324 
    325             //replace the temporary sourceId-references in the body with the persistent externalId
    326             String body = annotation.getBody().getAny().get(0).toString();
    327             String newBody = updateTargetRefsInBody(body, sourcePairs);
    328             List<Object> bodyXML = result.getBody().getAny();
    329             bodyXML.clear();
    330             bodyXML.add(newBody);
    331             String sqlUpdate = "UPDATE " + annotationTableName + " SET " + body_xml + "= ? WHERE " + annotation_id + "= " + internalID;
    332             int affectedRowsBodyUpd = getSimpleJdbcTemplate().update(sqlUpdate, newBody);
    333             if (affectedRows != 1) {
    334                 throw (new SQLException("Cannot update the body with persistent reference ID"));
    335             }
    336 
    337             return result;
    338         } catch (DataAccessException exception) {
    339             throw exception;
    340         }
     291        StringBuilder sql = new StringBuilder("INSERT INTO ");
     292        sql.append(annotationTableName).append("(").append(external_id).append(",").append(owner_id);
     293        sql.append(",").append(headline).append(",").append(body_xml).append(" ) VALUES (:externalId, :ownerId, :headline, :bodyXml)");
     294        int affectedRows = getSimpleJdbcTemplate().update(sql.toString(), params);
     295        if (affectedRows == 1) {
     296            return getInternalID(annotationIdentifier);
     297        } else {
     298            return null;
     299        }
     300
    341301    }
    342302
     
    347307    }
    348308
     309    ///////////////////////////////////////////////////////////////////////
     310    @Override
     311    public int updateBody(Number annotationID, String serializedNewBody) {
     312        StringBuilder sql = new StringBuilder("UPDATE ");
     313        sql.append(annotationTableName).append(" SET ").append(body_xml).append("= ").append(serializedNewBody).append(" WHERE ").append(annotation_id).append("= ?");
     314        return getSimpleJdbcTemplate().update(sql.toString(), annotationID);
     315    }
     316
    349317    //////////// helpers ///////////////////////
    350318    /////////////////////////////////////////////////
    351     private String updateTargetRefsInBody(String body, Map<NewOrExistingSourceInfo, NewOrExistingSourceInfo> sourcePairs) {
    352         String result = body;
    353         for (NewOrExistingSourceInfo tempSource : sourcePairs.keySet()) {
    354             NewSourceInfo newSource = tempSource.getNewSource();
    355             if (newSource != null) {
    356                 result = result.replaceAll(newSource.getId(), sourcePairs.get(tempSource).getSource().getRef());
    357             }
     319    // TODO: change when serialization mechanism for bodies is fixed
     320    @Override
     321    public String serializeBody(AnnotationBody body) {
     322        return body.getAny().get(0).toString();
     323    }
     324
     325    // TODO: change when serialization mechanism for bodies is fixed
     326    @Override
     327    public AnnotationBody deserializeBody(String bodyXml) {
     328        AnnotationBody result = new AnnotationBody();
     329        result.getAny().add(bodyXml);
     330        return result;
     331    }
     332
     333    ///////////////////////////////////////
     334    @Override
     335    public String updateTargetRefsInBody(String serializedBody, Map<String, String> sourceIDPairs) {
     336        String result = (new StringBuilder(serializedBody)).toString();
     337        for (String tempSource : sourceIDPairs.keySet()) {
     338            result = result.replaceAll(tempSource, sourceIDPairs.get(tempSource));
    358339        }
    359340        return result;
     
    367348    }
    368349
    369     ////////////////////////////////////////// 
    370     private Annotation makeDeepCopy(Annotation annotation) {
    371 
    372         if (annotation == null) {
    373             return null;
    374         }
    375 
    376         Annotation result = new Annotation();
    377 
    378         AnnotationBody body = new AnnotationBody();
    379         String bodyString = annotation.getBody().getAny().get(0).toString();
    380         body.getAny().add(bodyString);
    381         result.setBody(body);
    382 
    383         result.setHeadline(annotation.getHeadline());
    384 
    385         ResourceREF owner = new ResourceREF();
    386         owner.setRef(annotation.getOwner().getRef());
    387         result.setOwner(owner);
    388 
    389 //        ResourceREF permissions = new ResourceREF();
    390 //        permissions.setRef(annotation.getPermissions().getRef());
    391 //        result.setPermissions(permissions);
    392 
    393         result.setPermissions(null); //we do not have permissions there
    394 
    395         NewOrExistingSourceInfos noesi = new NewOrExistingSourceInfos();
    396         noesi.getTarget().addAll(annotation.getTargetSources().getTarget());
    397         result.setTargetSources(noesi);
    398 
    399         result.setTimeStamp(annotation.getTimeStamp());
    400         result.setURI(annotation.getURI());
    401 
    402         return result;
    403     }
     350    /**
     351     *
     352     * @param annotationID
     353     * @return mapping of the column names of the DB to the corresponding values
     354     * used for testing
     355     */
     356    //NOT TESTED
     357    public Map<String, Object> getRawAnnotation(Number annotationID) throws SQLException {
     358
     359
     360        if (annotationID == null) {
     361            return null;
     362        }
     363        String sql = "SELECT " + annotationStar + " FROM " + annotationTableName + " WHERE " + annotationAnnotation_id + "= ? LIMIT  1";
     364        List<Map<String, Object>> result = getSimpleJdbcTemplate().query(sql, rawAnnotationRowMapper, annotationID);
     365
     366        if (result == null) {
     367            return null;
     368        }
     369        if (result.isEmpty()) {
     370            return null;
     371        }
     372
     373        return result.get(0);
     374    }
     375    private final RowMapper<Map<String, Object>> rawAnnotationRowMapper = new RowMapper<Map<String, Object>>() {
     376        @Override
     377        public Map<String, Object> mapRow(ResultSet rs, int rowNumber) throws SQLException {
     378            Map<String, Object> result = new HashMap<String, Object>();
     379            result.put(owner_id, rs.getInt(owner_id));
     380            result.put(headline, rs.getString(headline));
     381            result.put(body_xml, rs.getString(body_xml));
     382            result.put(external_id, rs.getString(external_id));
     383            result.put(time_stamp, rs.getTimestamp(time_stamp));
     384            return result;
     385        }
     386    };
    404387}
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/impl/JdbcCachedRepresentationDao.java

    r3372 r3380  
    7070            result.setTool(rs.getString(tool));
    7171            result.setType(rs.getString(type_));
    72             // TODO add where is the file when the schem is updated!!!!s
     72            // TODO add "where is the file when the schema" is updated!!!!s
    7373            return result;
    7474        }
     
    9393     
    9494      ////////////////////////////////////////////////////////////////////////////
    95       @Override
    96     public CachedRepresentationInfo addCachedRepresentationInfo(CachedRepresentationInfo cached) {
     95    @Override
     96    public Number addCachedRepresentationInfo(CachedRepresentationInfo cached) {
    9797
    9898        CachedRepresentationIdentifier externalIdentifier = new CachedRepresentationIdentifier();
     
    105105        String sql = "INSERT INTO " + cachedRepresentationTableName + "(" + external_id + "," + mime_type + "," + tool + "," + type_ + " ) VALUES (:externalId, :mime_type,  :tool, :type)";
    106106        final int affectedRows = getSimpleJdbcTemplate().update(sql, params);
    107 
    108         if (affectedRows == 1) {
    109             CachedRepresentationInfo cachedNew = makeFreshCopy(cached);
    110             cachedNew.setRef(externalIdentifier.toString());
    111             return cachedNew;
    112         } else {
    113             return null;
    114         }
     107        return getInternalID(externalIdentifier);
    115108    }
    116109
     
    139132    };
    140133
    141     ////////// Helpers ///////////////////
    142     private CachedRepresentationInfo makeFreshCopy(CachedRepresentationInfo cached) {
    143         CachedRepresentationInfo result = new CachedRepresentationInfo();
    144         result.setMimeType(cached.getMimeType());
    145         result.setRef(cached.getRef());
    146         result.setTool(cached.getTool());
    147         result.setType(cached.getType());
    148         return result;
    149     }
    150    
    151134}
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/impl/JdbcPermissionsDao.java

    r3303 r3380  
    8989        return affectedPermissions;
    9090    }
    91    /////////////////////////////////////////////////////////////////////////////////
    92     //TODO replace name "user" in the scheme beacuse it is misleading. E.g. replace it with
    93     // getUser actual gives you the list of PAIRS (user, permission) that are refferred from an annotation
    94 //   @Override
    95 //   public PermissionList makeFreshPermissionList(UserIdentifier owner) {
    96 //       PermissionList result = new PermissionList();
    97 //       
    98 //       result.setURI((new PermissionListIdentifier()).toString());
    99 //       
    100 //       UserWithPermission idOwner = new UserWithPermission();
    101 //       idOwner.setPermission(Permission.fromValue("owner"));
    102 //       idOwner.setRef(owner.toString());
    103 //       
    104 //       result.getUser().add(idOwner);
    105 //       return result;
    106 //   }
    107    
    10891}
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/impl/JdbcResourceDao.java

    r3373 r3380  
    2323import java.sql.ResultSet;
    2424import java.sql.SQLException;
     25import java.util.ArrayList;
    2526import java.util.List;
    2627import javax.xml.datatype.DatatypeConfigurationException;
     
    3334 * @author olhsha
    3435 */
    35 public class JdbcResourceDao extends SimpleJdbcDaoSupport implements ResourceDao{
    36    
     36public class JdbcResourceDao extends SimpleJdbcDaoSupport implements ResourceDao {
     37
    3738    // base string constants: resource table Names
    3839    final static protected String notebookTableName = "notebook";
    3940    final static protected String annotationTableName = "annotation";
    40     final static protected String sourceTableName = "target_source"; 
     41    final static protected String sourceTableName = "target_source";
    4142    final static protected String cachedRepresentationTableName = "cached_representation_info";
    4243    final static protected String versionTableName = "version";
    4344    final static protected String principalTableName = "principal";
    4445    // joint tablenames
    45    
    4646    final static protected String notebooksAnnotationsTableName = "notebooks_annotations";
    4747    final static protected String permissionsTableName = "annotations_principals_permissions";
     
    4949    final static protected String versionsCachedRepresentationsTableName = "versions_cached_representations";
    5050    final static protected String sourcesVersionsTableName = "sources_versions";
    51    
    5251    // base string constants: field Names
    5352    final static protected String annotation_id = "annotation_id";
     
    5857    final static protected String headline = "headline";
    5958    final static protected String body_xml = "body_xml";
    60     final static protected String title="title";
     59    final static protected String title = "title";
    6160    final static protected String principal_id = "principal_id";
    6261    final static protected String time_stamp = "time_stamp";
     
    7069    final static protected String type_ = "type_";
    7170    final static protected String where_is_the_file = "where_is_the_file";
    72    
    7371    // derived string constants: table+field names
    74    
    75     final static protected String annotationStar = annotationTableName+".*";
    76     final static protected String annotationAnnotation_id = annotationTableName+"."+annotation_id;
    77     final static protected String annotationExternal_id = annotationTableName+"."+external_id;
    78    
    79     final static protected String notebookStar = notebookTableName+".*";
    80     final static protected String notebookNotebook_id = notebookTableName+"."+notebook_id;
    81     final static protected String notebookTitle=notebookTableName+"."+title;
    82     final static protected String notebookExternal_id = notebookTableName+"."+external_id;
    83     final static protected String notebookOwner_id = notebookTableName+"."+owner_id;
    84    
    85    
    86     final static protected String notebooksAnnotationsTableNameAnnotation_id = notebooksAnnotationsTableName+"."+annotation_id;
    87    
    88    
    89     final static protected String principalPrincipal_id = principalTableName+"."+principal_id;
    90     final static protected String principalExternal_id = principalTableName+"."+external_id;
    91    
    92    
    93     final static protected String cachedRepresentationStar = cachedRepresentationTableName+".*";   
    94     final static protected String versionStar = versionTableName+".*";
    95     final static protected String sourceStar = sourceTableName+".*";
    96    
     72    final static protected String annotationStar = annotationTableName + ".*";
     73    final static protected String annotationAnnotation_id = annotationTableName + "." + annotation_id;
     74    final static protected String annotationExternal_id = annotationTableName + "." + external_id;
     75    final static protected String notebookStar = notebookTableName + ".*";
     76    final static protected String notebookNotebook_id = notebookTableName + "." + notebook_id;
     77    final static protected String notebookTitle = notebookTableName + "." + title;
     78    final static protected String notebookExternal_id = notebookTableName + "." + external_id;
     79    final static protected String notebookOwner_id = notebookTableName + "." + owner_id;
     80    final static protected String notebooksAnnotationsTableNameAnnotation_id = notebooksAnnotationsTableName + "." + annotation_id;
     81    final static protected String principalPrincipal_id = principalTableName + "." + principal_id;
     82    final static protected String principalExternal_id = principalTableName + "." + external_id;
     83    final static protected String cachedRepresentationStar = cachedRepresentationTableName + ".*";
     84    final static protected String versionStar = versionTableName + ".*";
     85    final static protected String sourceStar = sourceTableName + ".*";
    9786    ///////////////////////////////////////////////////
    98    
    99     protected String internalIdName=null;
    100     protected String resourceTableName=null;
    101    
     87    protected String internalIdName = null;
     88    protected String resourceTableName = null;
     89
    10290    //////////////////////////////////////////////////////////////////////////////////
    10391    @Override
    104     public <T extends DasishIdentifier> Number getInternalID(T externalId){
    105        if (externalId == null) {
     92    public <T extends DasishIdentifier> Number getInternalID(T externalId) {
     93        if (externalId == null) {
    10694            return null;
    10795        }
    108        String sql = "SELECT "+internalIdName+" FROM "+resourceTableName+" WHERE "+external_id  +"= ? LIMIT 1";
    109        List<Number> sqlResult= getSimpleJdbcTemplate().query(sql, internalIDRowMapper, externalId.toString());
    110        
    111        if (sqlResult == null) {
    112            return null;
    113        }
    114        if (sqlResult.isEmpty()) {
    115            return null;
    116        }
    117        
    118         Number result  = sqlResult.get(0);
     96        String sql = "SELECT " + internalIdName + " FROM " + resourceTableName + " WHERE " + external_id + "= ? LIMIT 1";
     97        List<Number> sqlResult = getSimpleJdbcTemplate().query(sql, internalIDRowMapper, externalId.toString());
     98
     99        if (sqlResult == null) {
     100            return null;
     101        }
     102        if (sqlResult.isEmpty()) {
     103            return null;
     104        }
     105
     106        Number result = sqlResult.get(0);
    119107        return result;
    120     } 
    121      
    122      protected final RowMapper<Number> internalIDRowMapper = new RowMapper<Number>() {       
     108    }
     109    protected final RowMapper<Number> internalIDRowMapper = new RowMapper<Number>() {
    123110        @Override
    124111        public Number mapRow(ResultSet rs, int rowNumber) throws SQLException {
    125             int result = rs.getInt(internalIdName); 
    126             Number resultNumber =  result;
     112            int result = rs.getInt(internalIdName);
     113            Number resultNumber = result;
    127114            return resultNumber;
    128115        }
    129      };
    130      
    131      
    132      /////////////////////////////////////////////
    133      
    134    
    135     protected String getExternalIdentifier(Number internalId){
    136       if (internalId == null) {
     116    };
     117
     118   
     119    /////////////////////////////////////////////
     120    protected String getExternalIdentifier(Number internalId) {
     121        if (internalId == null) {
    137122            return null;
    138123        }
     
    149134        return (sqlResult.get(0));
    150135    }
    151    
    152136    protected final RowMapper<String> externalIDRowMapper = new RowMapper<String>() {
    153137        @Override
     
    156140        }
    157141    };
    158    
    159    
    160    
    161    
     142
    162143    /////////////////////////////////////////////////////
    163    protected XMLGregorianCalendar retrieveTimeStamp(Number internalID) {
     144    protected XMLGregorianCalendar retrieveTimeStamp(Number internalID) {
    164145        String sqlTime = "SELECT " + time_stamp + " FROM " + resourceTableName + " WHERE " + internalIdName + "= ? LIMIT 1";
    165146        List<XMLGregorianCalendar> timeStamp = getSimpleJdbcTemplate().query(sqlTime, timeStampRowMapper, internalID);
     
    181162        }
    182163    };
    183    
    184    
    185    
    186    
     164
    187165    protected <T> String makeListOfValues(List<T> vals) {
    188        
     166
    189167        if (vals == null) {
    190168            return null;
    191169        }
    192        
    193         if (vals.isEmpty()) {           
     170
     171        if (vals.isEmpty()) {
    194172            return null;
    195173        }
    196        
     174
    197175        String result = "(";
    198176        int length = vals.size();
    199         for (int i=0; i<length-1; i++){
    200             result = result + vals.get(i).toString() +", ";
     177        for (int i = 0; i < length - 1; i++) {
     178            result = result + vals.get(i).toString() + ", ";
    201179        }
    202         result = result +vals.get(length-1).toString()+")";
     180        result = result + vals.get(length - 1).toString() + ")";
    203181        return result;
    204182    }
    205    
    206183}
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/impl/JdbcSourceDao.java

    r3372 r3380  
    6161    }
    6262
    63     @Override
    64     public List<Number> retrieveSourceIDs(Number annotationID) {
    65         String sql = "SELECT " + source_id + " FROM " + annotationsSourcesTableName + " WHERE " + annotation_id + "= ?";
    66         List<Number> result = getSimpleJdbcTemplate().query(sql, annotationSourceRowMapper, annotationID);       
    67         return result;
    68     }
    69     private final RowMapper<Number> annotationSourceRowMapper = new RowMapper<Number>() {
    70         @Override
    71         public Number mapRow(ResultSet rs, int rowNumber) throws SQLException {
    72             Number result = rs.getInt(source_id);
    73             return result;
    74         }
    75     };
    76 
    77     ///////////////////////////////////////////////////////////////////////////////
     63        ///////////////////////////////////////////////////////////////////////////////
    7864    @Override
    7965    public Source getSource(Number internalID) {
    8066        String sql = "SELECT " + sourceStar + "FROM " + sourceTableName + " WHERE " + source_id + " = ?";
    81         List<Source> result = getSimpleJdbcTemplate().query(sql, SourceRowMapper, internalID);
     67        List<Source> result = getSimpleJdbcTemplate().query(sql, sourceRowMapper, internalID);
    8268        return result.get(0);
    8369    }
    84     private final RowMapper<Source> SourceRowMapper = new RowMapper<Source>() {
     70    private final RowMapper<Source> sourceRowMapper = new RowMapper<Source>() {
    8571        @Override
    8672        public Source mapRow(ResultSet rs, int rowNumber) throws SQLException {
     
    9783        }
    9884    };
     85   
     86        ///////////////////////////////////////////////////////////////////////////////
     87    @Override
     88    public Map<String, Object> getRawSource(Number internalID) {
     89        String sql = "SELECT " + sourceStar + "FROM " + sourceTableName + " WHERE " + source_id + " = ?";
     90        List<Map<String, Object>> result = getSimpleJdbcTemplate().query(sql, rawSourceRowMapper, internalID);
     91        return result.get(0);
     92    }
     93    private final RowMapper<Map<String, Object>> rawSourceRowMapper = new RowMapper<Map<String, Object>>() {
     94        @Override
     95        public Map<String, Object> mapRow(ResultSet rs, int rowNumber) throws SQLException {
     96           Map<String, Object> result = new HashMap<String, Object>();
     97           result.put(external_id, rs.getString(external_id));
     98           result.put(link_uri, rs.getString(link_uri));
     99           result.put(version_id, rs.getInt(version_id));
     100           return result;
     101        }
     102    };
    99103
    100104    ///////////////////////////////////////////////////////////////////
     
    140144    ///////////////////////////////////////////////////////////////////
    141145    @Override
    142     public Source addSource(Source freshSource) throws SQLException{
    143 
     146    public Number addSource(Source freshSource) throws SQLException{
     147     
    144148        SourceIdentifier externalIdentifier = new SourceIdentifier();
     149        Number versionID = versionDao.getInternalID(new VersionIdentifier(freshSource.getVersion()));
     150       
     151        if (versionID == null) {
     152            System.out.println("Cannot add source because there is no version for it, and no cached representation. Create them and try again.");
     153            return -1;
     154        }
    145155
    146156        Map<String, Object> params = new HashMap<String, Object>();
    147157        params.put("externalId", externalIdentifier.toString());
    148158        params.put("linkUri", freshSource.getLink());
    149         params.put("versionId", freshSource.getVersion());
     159        params.put("versionId", versionID);
    150160        String sql = "INSERT INTO " + sourceTableName + "(" + external_id + "," + link_uri + "," + version_id + " ) VALUES (:externalId, :linkUri,  :versionId)";
    151161        final int affectedRows = getSimpleJdbcTemplate().update(sql, params);
    152 
     162       
     163       
    153164        Map<String, Object> paramsJoint = new HashMap<String, Object>();
    154165        paramsJoint.put("sourceId", getInternalID(externalIdentifier));
    155         paramsJoint.put("versionId", freshSource.getVersion());
    156         String sqlSourceVersion = "INSERT INTO " + sourcesVersionsTableName + "(" + source_id + "," + version_id + " ) VALUES (:sourceId, :versionId)";
    157         int affectedRowsJoint = getSimpleJdbcTemplate().update(sqlSourceVersion, paramsJoint);
    158        
    159         if (affectedRows == 1 && affectedRowsJoint == 1) {
    160             Source result = makeFreshCopy(freshSource);
    161             result.setURI(externalIdentifier.toString());
    162            
    163             //retrieve taime stamp for the just added annotation
    164             XMLGregorianCalendar timeStamp =this.retrieveTimeStamp(getInternalID(new SourceIdentifier(externalIdentifier.toString())));
    165             result.setTimeSatmp(timeStamp);
    166            
    167             return result;
    168         } else {
    169             throw new SQLException("Cannot add the source");
    170         }
    171          
     166        paramsJoint.put("versionId", versionID);
     167        String sqlJoint = "INSERT INTO " + sourcesVersionsTableName + "(" + source_id +"," + version_id + " ) VALUES (:sourceId, :versionId)";
     168        final int affectedJointRows = getSimpleJdbcTemplate().update(sqlJoint, paramsJoint);
     169       
     170       
     171        return(getInternalID(externalIdentifier));
    172172    }
    173173
     
    175175    ///////////////////////////////////////////////////////////////////
    176176    @Override
    177     public List<SourceInfo> getSourceInfos(Number annotationID) {
    178         List<Number> sources = retrieveSourceIDs(annotationID);
     177    public List<SourceInfo> getSourceInfos(List<Number> sources) {
    179178        if (sources == null) {
    180179            return null;
     
    228227     ////////////////////////////////////////////////////////////////////////
    229228    @Override
    230     public Map<NewOrExistingSourceInfo, NewOrExistingSourceInfo> addTargetSources(Number annotationID, List<NewOrExistingSourceInfo> sources) throws SQLException {
    231 
    232         Map<NewOrExistingSourceInfo, NewOrExistingSourceInfo> result = new HashMap<NewOrExistingSourceInfo, NewOrExistingSourceInfo>();
     229    public Map<String, String> addTargetSources(Number annotationID, List<NewOrExistingSourceInfo> sources) throws SQLException {
     230
     231        Map<String, String> result = new HashMap<String, String>();
    233232       
    234233        for (NewOrExistingSourceInfo noeSourceInfo : sources) {
    235234            SourceInfo sourceInfo = noeSourceInfo.getSource();
    236235            if (sourceInfo != null) {
    237                 // this is an old source, already exists in the DB
    238                 result.put(noeSourceInfo, noeSourceInfo);               
     236                // this is an old source, already exists in the DB             
    239237                addAnnotationSourcePair(annotationID, getInternalID(new SourceIdentifier(sourceInfo.getRef())));
    240238            } else {
    241239                Source newSource = constructNewSource(noeSourceInfo.getNewSource());
    242                 Source addedSource = addSource(newSource);
    243                 int affectedRows = addAnnotationSourcePair(annotationID, getInternalID(new SourceIdentifier(addedSource.getURI())));
    244                
    245                 //  create updated source info
    246                 SourceInfo updatedSourceInfo = new SourceInfo();
    247                 updatedSourceInfo.setLink(addedSource.getLink());
    248                 updatedSourceInfo.setRef(addedSource.getURI());
    249                 updatedSourceInfo.setVersion(addedSource.getVersion());
    250 
    251                 NewOrExistingSourceInfo updatedInfo = new NewOrExistingSourceInfo();
    252                 updatedInfo.setSource(updatedSourceInfo);
    253                 result.put(noeSourceInfo, updatedInfo);
     240                Number addedSourceID = addSource(newSource);// adding new source
     241                int affectedRows = addAnnotationSourcePair(annotationID, addedSourceID);             
     242                result.put(noeSourceInfo.getNewSource().getId(), getExternalID(addedSourceID).toString());
    254243            }
    255244           
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/impl/JdbcVersionDao.java

    r3372 r3380  
    5151        return new VersionIdentifier(super.getExternalIdentifier(internalID));
    5252    }
     53   
     54      //////////////////////////////////////////////////////////////////////////////////////////////////////   
     55    @Override
     56    public Number getInternalID(VersionIdentifier externalID) {
     57        return (super.getInternalID(externalID));
     58    }
     59   
    5360    ///////////////////////////////////////////////////////////////
    5461
     
    158165    /////////////////////////////////////////////////
    159166    @Override
    160     public Version addVersion(Version freshVersion) {
     167    public Number addVersion(Version freshVersion) {
    161168        VersionIdentifier externalIdentifier = new VersionIdentifier();
    162169        String newExternalIdentifier = externalIdentifier.toString();
     
    168175        String sql = "INSERT INTO " + versionTableName + "(" + external_id + "," + version + " ) VALUES (:externalId, :version)";
    169176        final int affectedRows = getSimpleJdbcTemplate().update(sql, params);
    170 
    171         if (affectedRows == 1) {
    172             Version versionAdded = makeFreshCopy(freshVersion);
    173             // TODO change for external identifier when the schema is fixed
    174             versionAdded.setVersion(newExternalIdentifier);
    175             return versionAdded;
    176         } else {
    177             return null;
    178         }
    179 
    180         // adding the corresponding cached representation is initiated from the separate service POST api/sources/<sid>/cached
    181         // so it is not implemented here
     177        return getInternalID(externalIdentifier);
    182178    }
    183179
     
    213209    }
    214210
    215     ////////////////////// HELPERS ///////////////////////////////
    216     private Version makeFreshCopy(Version version) {
    217         Version result = new Version();
    218         // TOD: add external ID when the schema is corrected
    219         result.setVersion(version.getVersion());
    220         return result;
    221     }
     211   
    222212}
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/rest/AnnotationResource.java

    r3303 r3380  
    2222import eu.dasish.annotation.backend.dao.NotebookDao;
    2323import eu.dasish.annotation.backend.dao.PermissionsDao;
     24import eu.dasish.annotation.backend.dao.SourceDao;
    2425import eu.dasish.annotation.backend.dao.UserDao;
    2526import eu.dasish.annotation.backend.identifiers.AnnotationIdentifier;
    2627import eu.dasish.annotation.backend.identifiers.UserIdentifier;
    2728import eu.dasish.annotation.schema.Annotation;
     29import eu.dasish.annotation.schema.NewOrExistingSourceInfo;
    2830import eu.dasish.annotation.schema.ObjectFactory;
    2931import eu.dasish.annotation.schema.Permission;
    3032import java.sql.SQLException;
     33import java.util.List;
     34import java.util.Map;
    3135import javax.servlet.http.HttpServletRequest;
    3236import javax.ws.rs.Consumes;
     
    5357    @Autowired
    5458    private AnnotationDao annotationDao;
     59    @Autowired
     60    private SourceDao sourceDao;
    5561    @Autowired
    5662    private UserDao userDao;
     
    8793     */
    8894    public String deleteAnnotation(@PathParam("annotationid") String annotationIdentifier) throws SQLException {
    89         Number annotationID = annotationDao.getInternalID(new AnnotationIdentifier(annotationIdentifier));       
    90         String result = Integer.toString(annotationDao.deleteAnnotation(annotationID));
     95        Number annotationID = annotationDao.getInternalID(new AnnotationIdentifier(annotationIdentifier));
     96        int[] resultDelete = annotationDao.deleteAnnotation(annotationID);
     97        String result = Integer.toString(resultDelete[4]);
    9198        return result;
    9299    }
     
    98105    @Path("")
    99106    public JAXBElement<Annotation> createAnnotation(Annotation annotation) throws SQLException {
    100 
    101107        String remoteUser = httpServletRequest.getRemoteUser();
    102108        Number userID;
    103 
    104109        if (remoteUser == null) {
    105110            // happens in client testing
     
    110115        }
    111116
    112         Annotation newAnnotation = annotationDao.addAnnotation(annotation, userID);
    113         if (newAnnotation == null) {
     117        Number annotationID = annotationDao.addAnnotation(annotation, userID);
     118
     119        // adding sources to the DB if necessary and updating the joint table annotations_target_sources
     120        // also, since the source id-s can bementioned in the body, update the body as well
     121        // Note that client provided serialization "NewOrExistingSourceInfo" (of type choice) allows to switch between
     122        // new and existing sources
     123        List<NewOrExistingSourceInfo> sources = annotation.getTargetSources().getTarget();
     124        Map<String, String> sourcePairs = sourceDao.addTargetSources(annotationID, sources);
     125        String body = annotationDao.serializeBody(annotation.getBody());
     126        String newBody = annotationDao.updateTargetRefsInBody(body, sourcePairs);
     127        if (!body.equals(newBody)) {
     128            annotationDao.updateBody(annotationID, newBody);
     129        };
     130
     131        int affectedPermissions = permissionsDao.addAnnotationPrincipalPermission(annotationDao.getExternalID(annotationID), new UserIdentifier(remoteUser), Permission.OWNER);
     132        if (affectedPermissions != 1) {
     133            System.out.println("Cannot update permission table");
    114134            return null;
    115         } else {
    116             int affectedPermissions = permissionsDao.addAnnotationPrincipalPermission(new AnnotationIdentifier(newAnnotation.getURI()), new UserIdentifier(remoteUser), Permission.OWNER);
    117             return (new ObjectFactory().createAnnotation(newAnnotation));
    118135        }
     136        Annotation newAnnotation = annotationDao.getAnnotation(annotationID);
     137        return (new ObjectFactory().createAnnotation(newAnnotation));
    119138    }
    120139}
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/test/java/eu/dasish/annotation/backend/TestBackendConstants.java

    r3361 r3380  
    2222
    2323package eu.dasish.annotation.backend;
    24 
    25 import java.util.UUID;
    2624
    2725public class TestBackendConstants {
     
    9391    public static final String _TEST_VERSION_2_EXT_ID = "00000000-0000-0000-0000-000000000042";
    9492    public static final String _TEST_VERSION_3_EXT_ID = "00000000-0000-0000-0000-000000000043";
    95    
     93    public static final String _TEST_VERSION_NONEXIST_EXT_ID = "00000000-0000-0000-0000-000000000049";
    9694   
    9795    public static final String _TEST_TEMP_SOURCE_ID = "Barcelona-1";
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/test/java/eu/dasish/annotation/backend/dao/impl/JdbcAnnotationDaoTest.java

    r3370 r3380  
    4343import org.jmock.Mockery;
    4444import static org.junit.Assert.*;
     45import org.junit.Ignore;
    4546import org.junit.Test;
    4647import org.junit.runner.RunWith;
     
    7677     * List<AnnotationInfo> getAnnotationInfos(List<Number> annotationIDs)
    7778     */
     79   
     80      /**
     81     * Test of retrieveSourceIDs method, of class JdbcSourceDao.
     82     */
     83    @Test
     84    public void testRetrieveSourceIDs() {
     85        System.out.println("retrieveSourceIDs");
     86        Number annotationID = 2;
     87        List<Number> result = jdbcAnnotationDao.retrieveSourceIDs(annotationID);
     88        assertEquals(2, result.size());
     89        assertEquals(1, result.get(0));
     90        assertEquals(2, result.get(1));
     91    }
     92   
    7893    @Test
    7994    public void testGetAnnotationInfos() {
     
    197212        mockery.checking(new Expectations() {
    198213            {
    199                 oneOf(sourceDao).getSourceInfos(testAnnotationID);
     214                oneOf(sourceDao).getSourceInfos(with(aNonNull(List.class))); // retrieveSourceIDs is tested, so we can put "any" instead of its result
    200215                will(returnValue(sourceInfoList));
    201216
     
    238253        mockery.checking(new Expectations() {
    239254            {
    240                 oneOf(sourceDao).retrieveSourceIDs(5);
    241                 will(returnValue(sourceIDs));
    242                
    243255                oneOf(sourceDao).deleteSource(sourceIDs.get(0));
    244256                will(returnValue(0));
     
    249261        });
    250262
    251         int result = jdbcAnnotationDao.deleteAnnotation(5);
    252         assertEquals(1, result);
     263        int[] result = jdbcAnnotationDao.deleteAnnotation(5);
     264//       result[0] = # removed notebooks_annotations rows
     265//       result[1] = # removed "annotations_principals_perissions" rows
     266//       result[2] = # removed "annotatiobs_target_sources" rows
     267//       result[3] = # SAFELY removed "target_sources" rows (only unused)
     268//       result[4] = # removed annotation rows (should be 1)
     269       
     270        assertEquals(1, result[0]);
     271        assertEquals(3, result[1]);
     272        assertEquals(2, result[2]);
     273        assertEquals(1, result[3]);
     274        assertEquals(1, result[4]);
     275       
     276       
     277       
    253278        // now, try to delete the same annotation one more time
    254279        // if it has been already deleted then the method under testing should return 0
    255        
    256         mockery.checking(new Expectations() {
    257             {
    258                 oneOf(sourceDao).retrieveSourceIDs(5);
    259                 will(returnValue(new ArrayList<Number>()));               
    260             }
    261         });
     280   
    262281        result = jdbcAnnotationDao.deleteAnnotation(5);
    263         assertEquals(0, result);
     282        assertEquals(0, result[0]);
     283        assertEquals(0, result[1]);
     284        assertEquals(0, result[2]);
     285        assertEquals(0, result[3]);
     286        assertEquals(0, result[4]);
    264287    }
    265288
     
    268291     */
    269292    @Test
    270     public void testAddAnnotationExistingSource() throws SQLException {
    271         System.out.println("test_addAnnotation with an existing source");
    272 
    273         Annotation annotationToAdd = testInstances.getAnnotationToAdd();// existing sources
     293    public void testAddAnnotation() throws SQLException {
     294        System.out.println("test_addAnnotation ");
     295
     296        final Annotation annotationToAdd = testInstances.getAnnotationToAdd();// existing sources
    274297        assertEquals(null, annotationToAdd.getURI());
    275298        assertEquals(null, annotationToAdd.getTimeStamp());
    276 
    277         NewOrExistingSourceInfo noesi = new NewOrExistingSourceInfo();
    278         SourceInfo si = new SourceInfo();
    279         si.setLink(TestBackendConstants._TEST_SOURCE_1_LINK);
    280         si.setRef(TestBackendConstants._TEST_SOURCE_1_EXT_ID);
    281         si.setVersion(TestBackendConstants._TEST_VERSION_1_EXT_ID);
    282         noesi.setSource(si);
    283 
    284         final Map<NewOrExistingSourceInfo, NewOrExistingSourceInfo> map = new HashMap<NewOrExistingSourceInfo, NewOrExistingSourceInfo>();
    285         map.put(noesi, noesi);
    286 
    287 
    288         mockery.checking(new Expectations() {
    289             {
    290                 oneOf(sourceDao).addTargetSources(with(aNonNull(Number.class)), with(aNonNull(List.class)));
    291                 will(returnValue(map));
    292             }
    293         });
    294 
    295         Annotation result = jdbcAnnotationDao.addAnnotation(annotationToAdd, 5);
    296         assertFalse(null == result.getURI());
    297         assertFalse(null == result.getTimeStamp());
    298         assertEquals(annotationToAdd.getBody().getAny().get(0), result.getBody().getAny().get(0));
    299         assertEquals(annotationToAdd.getHeadline(), result.getHeadline());
    300         assertEquals(String.valueOf(5), result.getOwner().getRef());
    301         assertEquals(annotationToAdd.getPermissions(), result.getPermissions());
    302 
    303         SourceInfo expectedSi = annotationToAdd.getTargetSources().getTarget().get(0).getSource();
    304         SourceInfo resultSi = result.getTargetSources().getTarget().get(0).getSource();
    305         assertEquals(expectedSi.getLink(), resultSi.getLink());
    306         assertEquals(expectedSi.getRef(), resultSi.getRef());
    307         assertEquals(expectedSi.getVersion(), resultSi.getVersion());
    308     }
    309 
    310     /**
    311      * Test of addAnnotation method, of class JdbcAnnotationDao.
    312      */
    313     @Test
    314     public void testAddAnnotationNewSource() throws SQLException {
    315         System.out.println("test_addAnnotation with a new source");
    316 
    317 
    318         Annotation annotationToAdd = testInstances.getAnnotationToAddNewSource();// existing sources
    319         assertEquals(null, annotationToAdd.getURI());
    320         assertEquals(null, annotationToAdd.getTimeStamp());
    321 
    322 
    323         NewOrExistingSourceInfo noesi = new NewOrExistingSourceInfo();
    324         NewSourceInfo nsi = new NewSourceInfo();
    325         nsi.setLink(TestBackendConstants._TEST_NEW_SOURCE_LINK);
    326         nsi.setId(TestBackendConstants._TEST_TEMP_SOURCE_ID);
    327         nsi.setVersion(null);
    328         noesi.setNewSource(nsi);
    329 
    330 
    331         NewOrExistingSourceInfo noesiTwo = new NewOrExistingSourceInfo();
    332         SourceInfo si = new SourceInfo();
    333         si.setLink(TestBackendConstants._TEST_NEW_SOURCE_LINK);
    334         si.setRef((new SourceIdentifier()).toString());
    335         si.setVersion(null);
    336         noesiTwo.setSource(si);
    337 
    338         final Map<NewOrExistingSourceInfo, NewOrExistingSourceInfo> map = new HashMap<NewOrExistingSourceInfo, NewOrExistingSourceInfo>();
    339         map.put(noesi, noesiTwo);
    340 
    341 
    342         mockery.checking(new Expectations() {
    343             {
    344                 oneOf(sourceDao).addTargetSources(with(aNonNull(Number.class)), with(aNonNull(List.class)));
    345                 will(returnValue(map));
    346             }
    347         });
    348 
    349         Annotation result = jdbcAnnotationDao.addAnnotation(annotationToAdd, 5);
    350         assertFalse(null == result.getURI());
    351         assertFalse(null == result.getTimeStamp());
    352         assertEquals(annotationToAdd.getHeadline(), result.getHeadline());
    353         assertEquals(String.valueOf(5), result.getOwner().getRef());
    354         assertEquals(annotationToAdd.getPermissions(), result.getPermissions());
    355 
    356         NewSourceInfo expectedSi = annotationToAdd.getTargetSources().getTarget().get(0).getNewSource();
    357         SourceInfo resultSi = result.getTargetSources().getTarget().get(0).getSource();
    358         assertEquals(expectedSi.getLink(), resultSi.getLink());
    359         assertEquals(expectedSi.getVersion(), resultSi.getVersion());
    360         //the reference is replaced with the persistent one
    361         assertEquals(si.getRef(), resultSi.getRef());
    362         ///// 
    363 
    364         // checking the bodies: the temporary reference should be replaced
    365         String expBody = annotationToAdd.getBody().getAny().get(0).toString().replaceAll(TestBackendConstants._TEST_TEMP_SOURCE_ID, si.getRef());
    366         assertEquals(expBody, result.getBody().getAny().get(0).toString());
    367     }
    368    
    369    
     299       
     300        Number newAnnotationID = jdbcAnnotationDao.addAnnotation(annotationToAdd, 5);
     301        assertEquals(6, newAnnotationID);
     302       
     303        Map<String, Object> addedAnnotation= jdbcAnnotationDao.getRawAnnotation(6);
     304        assertFalse(null == addedAnnotation.get("external_id"));
     305        assertFalse(null == addedAnnotation.get("time_stamp"));
     306        assertEquals(5, addedAnnotation.get("owner_id"));
     307        assertEquals(annotationToAdd.getBody().getAny().get(0), addedAnnotation.get("body_xml")); // TODO: to be changed after serialization is fixed
     308        assertEquals(annotationToAdd.getHeadline(), addedAnnotation.get("headline"));
     309    }
     310
     311 
     312
     313
     314//        NewOrExistingSourceInfo noesi = new NewOrExistingSourceInfo();
     315//        NewSourceInfo nsi = new NewSourceInfo();
     316//        nsi.setLink(TestBackendConstants._TEST_NEW_SOURCE_LINK);
     317//        nsi.setId(TestBackendConstants._TEST_TEMP_SOURCE_ID);
     318//        nsi.setVersion(null);
     319//        noesi.setNewSource(nsi);
     320//
     321//
     322//        NewOrExistingSourceInfo noesiTwo = new NewOrExistingSourceInfo();
     323//        SourceInfo si = new SourceInfo();
     324//        si.setLink(TestBackendConstants._TEST_NEW_SOURCE_LINK);
     325//        si.setRef((new SourceIdentifier()).toString());
     326//        si.setVersion(null);
     327//        noesiTwo.setSource(si);
     328//
     329//        final Map<NewOrExistingSourceInfo, NewOrExistingSourceInfo> map = new HashMap<NewOrExistingSourceInfo, NewOrExistingSourceInfo>();
     330//        map.put(noesi, noesiTwo);
     331//
     332//
     333//        mockery.checking(new Expectations() {
     334//            {
     335//                oneOf(sourceDao).addTargetSources(with(aNonNull(Number.class)), with(aNonNull(List.class)));
     336//                will(returnValue(map));
     337//            }
     338//        });
     339
     340 
    370341    /**
    371342     * testing public List<Number> getAnnotationIDsForSources(List<Number> sourceIDs);
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/test/java/eu/dasish/annotation/backend/dao/impl/JdbcCachedRepresentationDaoTest.java

    r3298 r3380  
    2525import org.junit.Test;
    2626import static org.junit.Assert.*;
    27 import org.junit.Ignore;
    2827import org.junit.runner.RunWith;
    2928import org.springframework.beans.factory.annotation.Autowired;
     
    3837@RunWith(SpringJUnit4ClassRunner.class)
    3938@ContextConfiguration({"/spring-test-config/dataSource.xml", "/spring-test-config/mockery.xml", "/spring-test-config/mockAnnotationDao.xml",
    40     "/spring-test-config/mockUserDao.xml", "/spring-test-config/mockPermissionsDao.xml", "/spring-test-config/mockNotebookDao.xml", "/spring-config/cachedRepresentationDao.xml"})
     39    "/spring-test-config/mockUserDao.xml", "/spring-test-config/mockPermissionsDao.xml", "/spring-test-config/mockNotebookDao.xml",
     40    "/spring-test-config/mockSourceDao.xml", "/spring-config/cachedRepresentationDao.xml"})
    4141public class JdbcCachedRepresentationDaoTest extends JdbcResourceDaoTest{
    4242   
     
    150150        cached.setTool("vi");
    151151        cached.setType("text");
     152        cached.setRef(null);
    152153       
    153         CachedRepresentationInfo result = jdbcCachedRepresentationDao.addCachedRepresentationInfo(cached);
    154         assertEquals("text/plain", result.getMimeType());
    155         assertEquals("vi", result.getTool());
    156         assertEquals("text", result.getType());
    157         assertFalse(result.getRef() == null); // new non-null external identifier should be assigned
     154        Number result = jdbcCachedRepresentationDao.addCachedRepresentationInfo(cached);
     155        CachedRepresentationInfo addedCached = jdbcCachedRepresentationDao.getCachedRepresentationInfo(result);
     156        assertEquals("text/plain", addedCached.getMimeType());
     157        assertEquals("vi", addedCached.getTool());
     158        assertEquals("text", addedCached.getType());
     159        assertFalse(addedCached.getRef() == null); // new non-null external identifier should be assigned
    158160    }
    159161   
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/test/java/eu/dasish/annotation/backend/dao/impl/JdbcNotebookDaoTest.java

    r3218 r3380  
    4949 */
    5050@RunWith(SpringJUnit4ClassRunner.class)
    51 @ContextConfiguration({"/spring-test-config/mockery.xml", "/spring-test-config/mockAnnotationDao.xml", "/spring-test-config/mockUserDao.xml", "/spring-test-config/mockPermissionsDao.xml",
     51@ContextConfiguration({"/spring-test-config/mockery.xml", "/spring-test-config/mockAnnotationDao.xml", "/spring-test-config/mockSourceDao.xml", "/spring-test-config/mockUserDao.xml", "/spring-test-config/mockPermissionsDao.xml",
    5252    "/spring-test-config/dataSource.xml", "/spring-config/notebookDao.xml"})
    5353public class JdbcNotebookDaoTest extends JdbcResourceDaoTest{
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/test/java/eu/dasish/annotation/backend/dao/impl/JdbcPermissionsDaoTest.java

    r3218 r3380  
    3939
    4040@RunWith(SpringJUnit4ClassRunner.class)
    41 @ContextConfiguration({"/spring-test-config/mockery.xml", "/spring-test-config/dataSource.xml", "/spring-test-config/mockUserDao.xml", "/spring-test-config/mockAnnotationDao.xml", "/spring-test-config/mockNotebookDao.xml", "/spring-config/permissionsDao.xml"})
     41@ContextConfiguration({"/spring-test-config/mockery.xml", "/spring-test-config/dataSource.xml", "/spring-test-config/mockUserDao.xml", "/spring-test-config/mockSourceDao.xml","/spring-test-config/mockAnnotationDao.xml", "/spring-test-config/mockNotebookDao.xml", "/spring-config/permissionsDao.xml"})
    4242public class JdbcPermissionsDaoTest extends JdbcResourceDaoTest{
    4343   
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/test/java/eu/dasish/annotation/backend/dao/impl/JdbcSourceDaoTest.java

    r3367 r3380  
    8181    }
    8282
    83     /**
    84      * Test of retrieveSourceIDs method, of class JdbcSourceDao.
    85      */
    86     @Test
    87     public void testRetrieveSourceIDs() {
    88         System.out.println("retrieveSourceIDs");
    89         Number annotationID = 2;
    90         List<Number> result = jdbcSourceDao.retrieveSourceIDs(annotationID);
    91         assertEquals(2, result.size());
    92         assertEquals(1, result.get(0));
    93         assertEquals(2, result.get(1));
    94     }
     83 
    9584
    9685    /**
     
    169158        System.out.println("addSource");
    170159
    171         String link = "http://www.sagradafamilia.cat/";
    172         String version = null;
    173         String timeStamp = null;
    174 
     160        String link = "http://www.sagradafamilia.cat/";     
     161 
     162        // existing version
    175163        Source freshSource = new Source();
    176164        freshSource.setLink(link);
    177         freshSource.setVersion(version);
    178         freshSource.setVersion(timeStamp);
    179 
     165        freshSource.setVersion(TestBackendConstants._TEST_VERSION_1_EXT_ID);
     166        freshSource.setURI(null);
     167        freshSource.setTimeSatmp(null);
     168       
     169        mockery.checking(new Expectations() {
     170            {
     171                oneOf(versionDao).getInternalID(new VersionIdentifier(TestBackendConstants._TEST_VERSION_1_EXT_ID));
     172                will(returnValue(1));
     173            }
     174        });
     175 
    180176        try {
    181             Source result = jdbcSourceDao.addSource(freshSource);
    182             assertEquals(link, result.getLink());
    183             assertEquals(version, result.getVersion());
    184             assertEquals(6, jdbcSourceDao.getInternalID(new SourceIdentifier(result.getURI())));
    185 
    186             assertFalse(null==result.getTimeSatmp());
    187            
     177            Number result = jdbcSourceDao.addSource(freshSource);           
     178            assertEquals(6, result);
     179            Map<String, Object> addedSource = jdbcSourceDao.getRawSource(result);
     180            assertEquals(link, addedSource.get("link_uri"));
     181            assertEquals(1, addedSource.get("version_id"));
     182            assertFalse(null==addedSource.get("external_id"));
    188183        } catch (SQLException e) {
    189184            System.out.println(e);
    190185        }
     186       
     187        ////////// test 2 non-existing source
     188        freshSource.setVersion(TestBackendConstants._TEST_VERSION_NONEXIST_EXT_ID);
     189         mockery.checking(new Expectations() {
     190            {
     191                oneOf(versionDao).getInternalID(new VersionIdentifier(TestBackendConstants._TEST_VERSION_NONEXIST_EXT_ID));
     192                will(returnValue(null));
     193            }
     194        });
     195 
     196        try {
     197            Number result = jdbcSourceDao.addSource(freshSource);           
     198            assertEquals(-1, result);
     199        } catch (SQLException e) {
     200            System.out.println(e);
     201        }
     202       
    191203    }
    192204
     
    197209    public void testGetSourceInfos() {
    198210        System.out.println("getSourceInfos");
    199         Number annotationID = 2;
     211        List<Number> test = new ArrayList<Number>();
     212        test.add(1);
     213        test.add(2);
    200214
    201215        mockery.checking(new Expectations() {
     
    209223        });
    210224
    211         List<SourceInfo> result = jdbcSourceDao.getSourceInfos(annotationID);
     225        List<SourceInfo> result = jdbcSourceDao.getSourceInfos(test);
    212226        assertEquals(2, result.size());
    213227        assertEquals(TestBackendConstants._TEST_SOURCE_1_EXT_ID, result.get(0).getRef());
     
    270284
    271285        try {
    272             Map<NewOrExistingSourceInfo, NewOrExistingSourceInfo> result = jdbcSourceDao.addTargetSources(5, listnoesi);
    273             assertEquals(1, result.size());
    274             assertEquals(result.get(noesi), noesi);
     286            Map<String, String> result = jdbcSourceDao.addTargetSources(5, listnoesi);
     287            assertEquals(0, result.size()); // no new peristsent source IDs are produced
    275288        } catch (SQLException e) {
    276289            System.out.println(e);
     
    292305        nsi.setLink(TestBackendConstants._TEST_NEW_SOURCE_LINK);
    293306        nsi.setId(TestBackendConstants._TEST_TEMP_SOURCE_ID);
    294         nsi.setVersion(null);
     307        nsi.setVersion(TestBackendConstants._TEST_VERSION_1_EXT_ID);
    295308        noesi.setNewSource(nsi);
    296309
    297310        List<NewOrExistingSourceInfo> listnoesiTwo = new ArrayList<NewOrExistingSourceInfo>();
    298311        listnoesiTwo.add(noesi);
     312       
     313        mockery.checking(new Expectations() {
     314            {
     315                oneOf(versionDao).getInternalID(new VersionIdentifier(TestBackendConstants._TEST_VERSION_1_EXT_ID));
     316                will(returnValue(1));
     317            }
     318        });
    299319
    300320        try {
    301             Map<NewOrExistingSourceInfo, NewOrExistingSourceInfo> result = jdbcSourceDao.addTargetSources(5, listnoesiTwo);
    302             assertEquals(1, result.size());
    303             assertEquals(noesi.getNewSource().getLink(), result.get(noesi).getSource().getLink());
    304             assertEquals(noesi.getNewSource().getVersion(), result.get(noesi).getSource().getVersion());
    305 
    306             SourceIdentifier sourceIdentifier = new SourceIdentifier(result.get(noesi).getSource().getRef());
     321            Map<String, String> result = jdbcSourceDao.addTargetSources(5, listnoesiTwo);
     322            assertEquals(1, result.size());// a new identifier must be produced
     323            SourceIdentifier sourceIdentifier = new SourceIdentifier(result.get(TestBackendConstants._TEST_TEMP_SOURCE_ID));
    307324            assertFalse(null == sourceIdentifier.getUUID()); // check if a proper uuid has been assigned
    308325        } catch (SQLException e) {
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/test/java/eu/dasish/annotation/backend/dao/impl/JdbcVersionDaoTest.java

    r3372 r3380  
    4040@ContextConfiguration({"/spring-test-config/dataSource.xml", "/spring-test-config/mockery.xml", "/spring-test-config/mockAnnotationDao.xml",
    4141    "/spring-test-config/mockUserDao.xml", "/spring-test-config/mockPermissionsDao.xml", "/spring-test-config/mockNotebookDao.xml",
    42     "/spring-test-config/mockCachedRepresentationDao.xml", "/spring-config/versionDao.xml"})
     42    "/spring-test-config/mockSourceDao.xml", "/spring-test-config/mockCachedRepresentationDao.xml", "/spring-config/versionDao.xml"})
    4343
    4444public class JdbcVersionDaoTest extends JdbcResourceDaoTest{
     
    169169        Version freshVersion = new Version();   
    170170       
    171         Version result = jdbcVersionDao.addVersion(freshVersion);
    172         assertFalse(null==result.getVersion());
    173        
    174         // check if it is a good UUID. the program breaks if the string is anot a good UUID
    175         assertEquals(result.getVersion(), (new VersionIdentifier(result.getVersion())).toString());
     171        Number result = jdbcVersionDao.addVersion(freshVersion);
     172        assertEquals(8, result);
     173        Version addedVersion = jdbcVersionDao.getVersion(result);
     174        assertFalse(null==addedVersion.getVersion());
     175       
    176176    }
    177177
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/test/java/eu/dasish/annotation/backend/rest/AnnotationResourceTest.java

    r3303 r3380  
    2424import eu.dasish.annotation.backend.dao.NotebookDao;
    2525import eu.dasish.annotation.backend.dao.PermissionsDao;
     26import eu.dasish.annotation.backend.dao.SourceDao;
    2627import eu.dasish.annotation.backend.dao.UserDao;
    2728import eu.dasish.annotation.backend.identifiers.AnnotationIdentifier;
    2829import eu.dasish.annotation.backend.identifiers.UserIdentifier;
    2930import eu.dasish.annotation.schema.Annotation;
     31import eu.dasish.annotation.schema.NewOrExistingSourceInfo;
    3032import eu.dasish.annotation.schema.Permission;
    3133import eu.dasish.annotation.schema.ResourceREF;
     34import eu.dasish.annotation.schema.SourceInfo;
    3235import java.sql.SQLException;
    3336import javax.xml.bind.JAXBElement;
     
    4144import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
    4245import java.lang.InstantiationException;
     46import java.util.HashMap;
     47import java.util.List;
     48import java.util.Map;
    4349import javax.servlet.ServletException;
    4450import org.springframework.mock.web.MockHttpServletRequest;
     
    4955
    5056@RunWith(value = SpringJUnit4ClassRunner.class)
    51 @ContextConfiguration(locations = {"/spring-test-config/dataSource.xml", "/spring-test-config/mockAnnotationDao.xml", "/spring-test-config/mockUserDao.xml", "/spring-test-config/mockPermissionsDao.xml", "/spring-test-config/mockNotebookDao.xml", "/spring-test-config/mockery.xml"})
     57@ContextConfiguration(locations = {"/spring-test-config/dataSource.xml", "/spring-test-config/mockAnnotationDao.xml",
     58    "/spring-test-config/mockSourceDao.xml",
     59    "/spring-test-config/mockUserDao.xml", "/spring-test-config/mockPermissionsDao.xml", "/spring-test-config/mockNotebookDao.xml", "/spring-test-config/mockery.xml"})
    5260public class AnnotationResourceTest {
    5361   
     
    6169    private PermissionsDao permissionsDao;
    6270    @Autowired
    63     private NotebookDao notebookDao;
     71    private NotebookDao notebookDao; 
     72    @Autowired
     73    private SourceDao sourceDao;
    6474   
    6575    @Autowired
     
    101111        System.out.println("deleteAnnotation");
    102112       
     113       
    103114        mockery.checking(new Expectations() {
    104             {
     115            { 
    105116                oneOf(annotationDao).getInternalID(new AnnotationIdentifier(TestBackendConstants._TEST_ANNOT_5_EXT));               
    106117                will(returnValue(5));     
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/test/java/eu/dasish/annotation/backend/rest/NotebookResourceTest.java

    r3218 r3380  
    4747 */
    4848@RunWith(value = SpringJUnit4ClassRunner.class)
    49 @ContextConfiguration(locations = {"/spring-test-config/dataSource.xml", "/spring-test-config/mockAnnotationDao.xml", "/spring-test-config/mockUserDao.xml", "/spring-test-config/mockNotebookDao.xml", "/spring-test-config/mockPermissionsDao.xml", "/spring-test-config/mockery.xml"})
     49@ContextConfiguration(locations = {"/spring-test-config/dataSource.xml", "/spring-test-config/mockAnnotationDao.xml", "/spring-test-config/mockUserDao.xml",
     50    "/spring-test-config/mockSourceDao.xml", "/spring-test-config/mockNotebookDao.xml", "/spring-test-config/mockPermissionsDao.xml", "/spring-test-config/mockery.xml"})
    5051public class NotebookResourceTest {
    5152
Note: See TracChangeset for help on using the changeset viewer.