Changeset 3365


Ignore:
Timestamp:
08/12/13 16:25:10 (11 years ago)
Author:
olhsha
Message:

getting the list of annotation IDs, where annotations are filtered by link, text, etc. So far body is considered as a text (got from xmls list of elements, vis get(0)). NOT TESTED yet!

Location:
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend
Files:
5 edited

Legend:

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

    r3221 r3365  
    3131    public static final int USER_HASH_PARAM_1 =  5;
    3232    public static final int USER_HASH_PARAM_2 =  19;
    33    
    3433    // peter, is it okay?
    3534    public static final int SOURCE_HASH_PARAM_1 =  7;
     
    4140   
    4241    public static final String regExpIdentifier = "[a-zA-Z0-9_-]*";
     42   
    4343}
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/AnnotationDao.java

    r3345 r3365  
    1919
    2020import eu.dasish.annotation.backend.identifiers.AnnotationIdentifier;
    21 import eu.dasish.annotation.backend.identifiers.SourceIdentifier;
     21import eu.dasish.annotation.backend.identifiers.UserIdentifier;
    2222import eu.dasish.annotation.schema.Annotation;
    2323import eu.dasish.annotation.schema.AnnotationInfo;
    24 import eu.dasish.annotation.schema.NewOrExistingSourceInfo;
    2524import eu.dasish.annotation.schema.ResourceREF;
    2625import java.sql.SQLException;
     26import java.sql.Timestamp;
    2727import java.util.List;
    2828
     
    7373    public Annotation addAnnotation(Annotation annotation, Number ownerID) throws SQLException;
    7474 
     75     
     76    /**
     77     *
     78     * @param link optional
     79     * @param text optional
     80     * @param access optional
     81     * @param namespace optional TODO: do not know what to do with it
     82     * @param owner optional
     83     * @param after optional
     84     * @param before optional
     85     * @return the list of internal annotation identifiers for annotations
     86     * -- referring to the "link",
     87     * -- bodies of which contain the "text",
     88     * -- to which inlogged user has "access",
     89     * -- owned by "owner",
     90     * -- added to the database between "before" and "after" time-dates.
     91     */
     92    public List<Number> getFilteredAnnotationIDs(String link, String text, String access, String namespace, UserIdentifier owner, Timestamp after, Timestamp before);
     93   
    7594   
    76    
    77    
     95    /**
     96     *
     97     * @param annotationIDs
     98     * @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>
     100     */
    78101    public List<AnnotationInfo> getAnnotationInfos(List<Number> annotationIDs);   
    79102     
    80103   
    81104   
    82     public List<ResourceREF> getAnnotationREFs(List<Number> annotationIDs);   
     105    public List<ResourceREF> getAnnotationREFs(List<Number> annotationIDs);
     106   
     107   
     108   
    83109   
    84110}
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/SourceDao.java

    r3348 r3365  
    108108    public Map<NewOrExistingSourceInfo, NewOrExistingSourceInfo> addTargetSources(Number annotationID, List<NewOrExistingSourceInfo> sources) throws SQLException;       
    109109   
    110        
     110    /**
     111     *
     112     * @param link
     113     * @return the list source ID's which link-fields contain "link" as a substring
     114     */
     115    public List<Number> getSourcesForLink(String link);
    111116}
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/impl/JdbcAnnotationDao.java

    r3364 r3365  
    2525import eu.dasish.annotation.backend.dao.UserDao;
    2626import eu.dasish.annotation.backend.identifiers.AnnotationIdentifier;
     27import eu.dasish.annotation.backend.identifiers.UserIdentifier;
    2728import eu.dasish.annotation.schema.Annotation;
    2829import eu.dasish.annotation.schema.AnnotationBody;
     
    3536import java.sql.ResultSet;
    3637import java.sql.SQLException;
     38import java.sql.Timestamp;
    3739import java.util.ArrayList;
    3840import java.util.HashMap;
     
    6769    }
    6870
    69     ////////////////////////////////////////////////////////////////////////////
    70     /**
    71      *
    72      * @param annotationIDs is a list of internal annotation identifiers
    73      * @return the list of the corresponding annotation-infos for the annotation
    74      * identifiers from the list; if the input list is null return null if the
    75      * input list is empty (zero elements) returns an empty list
    76      */
     71    @Override
     72    public List<Number> getFilteredAnnotationIDs(String link, String text, String access, String namespace, UserIdentifier owner, Timestamp after, Timestamp before) {
     73
     74        String sql = "SELECT " + annotation_id + " FROM " + annotationTableName;
     75        boolean firstClauseIsBuild = false;
     76        //TODO: optimize List<Object> params = new ArrayList<Object>();
     77        //TODO: optimizie String builder
     78
     79
     80
     81        if (owner != null) {
     82            sql = sql + " WHERE " + principal_id + "=:owner" + jdbcUserDao.getInternalID(owner);
     83            firstClauseIsBuild = true;
     84        }
     85
     86
     87
     88        if (after != null) {
     89            if (firstClauseIsBuild) {
     90                sql = sql + " AND " + time_stamp + "  > " + after.toString();
     91            } else {
     92                sql = sql + " WHERE " + time_stamp + "  > " + after.toString();
     93                firstClauseIsBuild = true;
     94            }
     95        }
     96
     97        if (before != null) {
     98            if (firstClauseIsBuild) {
     99                sql = sql + " AND " + time_stamp + "  < " + before.toString();
     100            } else {
     101                sql = sql + " WHERE " + time_stamp + "  < " + before.toString();
     102                firstClauseIsBuild = true;
     103            }
     104        }
     105
     106        if (text != null) {
     107            if (firstClauseIsBuild) {
     108                sql = sql + " AND " + body_xml + "  LIKE '%" + text + "%'";
     109            } else {
     110                sql = sql + " WHERE " + body_xml + "  LIKE '%" + text + "%'";
     111                firstClauseIsBuild = true;
     112            }
     113        }
     114
     115        if (link != null) {
     116            List<Number> sourceIDs = jdbcSourceDao.getSourcesForLink(link);
     117            if (!sourceIDs.isEmpty()) {
     118                String values = makeListOfValues(sourceIDs);
     119                if (firstClauseIsBuild) {
     120                    sql = sql + " AND " + source_id + " IN " + values;
     121                }
     122                 else {
     123                    sql = sql + " WHERE " + source_id + " IN " + values;
     124                    firstClauseIsBuild = true;
     125                }
     126            }
     127        }
     128
     129
     130        List<Number> result = getSimpleJdbcTemplate().query(sql, internalIDRowMapper);
     131        return result;
     132    }
     133
    77134    @Override
    78135    public List<AnnotationInfo> getAnnotationInfos(List<Number> annotationIDs) {
     
    197254        int affectedNotebooks = getSimpleJdbcTemplate().update(sqlNotebooks, annotationId);
    198255
    199          String sqlPermissions = "DELETE FROM " + permissionsTableName + " where " + annotation_id + " = ?";
     256        String sqlPermissions = "DELETE FROM " + permissionsTableName + " where " + annotation_id + " = ?";
    200257        int affectedPermissions = getSimpleJdbcTemplate().update(sqlPermissions, annotationId);
    201        
     258
    202259        // safe removing sources
    203260        List<Number> sourceIDs = jdbcSourceDao.retrieveSourceIDs(annotationId);
     
    205262        int affectedAnnotationsSources = getSimpleJdbcTemplate().update(sqlTargetSources, annotationId);
    206263        int affectedSources;
    207         for (Number sourceID : sourceIDs) {           
    208          // call  the method in sources DAO that handles removal of a source which is not refered by other annotations
     264        for (Number sourceID : sourceIDs) {
     265            // call  the method in sources DAO that handles removal of a source which is not refered by other annotations
    209266            affectedSources = jdbcSourceDao.deleteSource(sourceID);
    210267        }
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/impl/JdbcSourceDao.java

    r3364 r3365  
    223223   
    224224   
    225 
     225   
    226226   
    227227   
     
    258258    }
    259259
    260    
    261    
     260    @Override
     261    public List<Number> getSourcesForLink(String link){
     262      String sql = "SELECT "+source_id+" FROM "+sourceTableName+ "WHERE "+link_uri+" LIKE '%"+link+"%'";
     263      List<Number> result = getSimpleJdbcTemplate().query(sql, internalIDRowMapper);
     264      return result;
     265    }
    262266
    263267    //////// HELPERS //////////////////////
Note: See TracChangeset for help on using the changeset viewer.