Changeset 4493


Ignore:
Timestamp:
02/10/14 17:25:21 (10 years ago)
Author:
olhsha
Message:

adding notebook DAO, not tested

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

Legend:

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

    r4429 r4493  
    2020
    2121import eu.dasish.annotation.schema.Permission;
    22 import eu.dasish.annotation.schema.ReferenceList;
    2322import eu.dasish.annotation.schema.Notebook;
    2423import eu.dasish.annotation.schema.NotebookInfo;
    2524import java.util.List;
    26 import java.util.UUID;
    2725
    2826/**
     
    4846    List<Number> getOwnerNotebookIDs(Number userID);
    4947   
     48    public List<Number> getPrincipalIDsWithPermission(Number notebookID, Permission permission);
     49   
     50   
     51   
    5052    /**
    5153     *
     
    5557    NotebookInfo getNotebookInfo(Number notebookID);
    5658   
     59   
    5760    /**
    5861     *
     
    6265    Notebook getNotebookWithoutAnnotationsAndPermissions(Number notebookID);
    6366   
    64 
    65     // Returns the list of all notebooks owned by the current logged user.
    66     //List<Notebook> getUsersNotebooks(UUID userID);
    67 
     67    //? Which type shul be orderedby?
     68    /**
     69     *
     70     * @param maximumAnnotations
     71     * @param startannotation
     72     * @param orderedBy
     73     * @param orederingMode if true then descending, if falset hen ascending
     74     * @return
     75     */
     76    List<Number> getAnnotations(int maximumAnnotations, int startannotation, String orderedBy, boolean orderingMode);
    6877   
    69       // Returns the list of annotation Id-s  for the notebook id.
    70     //public List<Number> getAnnotationIDs(Number notebookID);
     78    /**
     79     *
     80     * UPDATERS
     81     *
     82     *
     83     */
    7184   
    72       /*Returns the list of annotation info-s  for the notebook id.
    73     /List<AnnotationInfo> getAnnotationInfosOfNotebook(Number notebookID); */   
    7485   
    75       // Returns the list of annotations Id-s  for the notebook id.
    76     //public List<String> getAnnotationREFsOfNotebook(Number notebookID);
    77    
    78     // Returns the Annotations object for the notebook id.
    79     //public ReferenceList getAnnotations(Number notebookID);
    8086   
    8187    /**
    8288     *
    8389     * @param notebookID
    84      * @return the Notebook information (title, owner (?), time_stamp(?), amount of annotations(?), their headlines (?) // TODO: discuss changing in the schema
    85      * user in getting the metadata of a notebook
     90     * @return true if updated, false otherwise. Logs the reason if the notebook is not updated.
    8691     */
    87     //NotebookInfo getNotebookInfo(Number notebookID);
    88    
    89  
     92    boolean updateNotebookMetadata(Number notebookID);
    9093   
    9194     /**
    92      * @param notebookId
    93      * @return returns the externalIds of the annotations contained in the notebookId
     95     *
     96     * ADDERS
     97     *
     98     *
    9499     */
    95     //List<UUID> getAnnotationExternalIDs(UUID notebookId);
     100   
     101    Number createNotebook(Notebook notebook);
     102   
     103    boolean addAnnotationToNotebook(Number noteboookId, Number AnnotationID);
     104   
    96105   
    97106   
    98107    /**
    99108     *
    100      *  ADDERS
     109     * DELETERS (ADDER)
     110     *
     111     *
    101112     */
    102113   
    103     // Creates a new notebook and returns the _nid_ of the created Notebook
    104     //UUID addNotebook(UUID userID, String title);
    105 
    106       // Adds an annotation _aid_ to the list of annotations of _nid_.
    107     //public int addAnnotation(UUID notebookId, UUID annotationId);
     114    boolean deleteannotationFromNotebook(Number notebookID, Number annotationID);
    108115   
    109    
    110    
    111    /**
    112     *
    113     * DELETE
    114     *
    115     */
    116    
    117     // Delete _nid_. Annotations stay, they just lose connection to _nid_.<br>
    118     // returns the number of records deleted
    119     //public int deleteNotebook(UUID notebookId);
    120     /**
    121      *
    122      * @param annotationID
    123      * @return removes the rows with annotationID from notebooks_annotations table
    124      */
    125     //int removeAnnotation(Number annotationID);
     116    boolean deleteNotebook(Number notebookID);
    126117}
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/impl/JdbcNotebookDao.java

    r4429 r4493  
    3939 * @author Peter Withers <peter.withers@mpi.nl>
    4040 */
    41 
    4241// TODO: not updated fully yet.
    43 
    4442public class JdbcNotebookDao extends JdbcResourceDao implements NotebookDao {
    4543
    4644//    @Autowired
    4745//    private AnnotationDao jdbcAnnotationDao;
    48 
    4946    public JdbcNotebookDao(DataSource dataSource) {
    50         setDataSource(dataSource);       
     47        setDataSource(dataSource);
    5148        internalIdName = notebook_id;
    5249        resourceTableName = notebookTableName;
     
    5451
    5552    /// GETTERS /////////
    56    
    5753    ////////////////////////////////////////////////
    5854    @Override
    59     public List<Number> getNotebookIDs(Number  userID, Permission acessMode) {
     55    public List<Number> getNotebookIDs(Number userID, Permission acessMode) {
    6056        Map<String, Object> params = new HashMap<String, Object>();
    6157        params.put("principalID", userID);
    6258        params.put("accessMode", acessMode.value());
    63         String sql = "SELECT " + notebook_id + " FROM " + notebookPermissionsTableName +" WHERE " + principalPrincipal_id + " = :principalID" + " AND " + permission + " = :accessMode";
     59        String sql = "SELECT " + notebook_id + " FROM " + notebookPermissionsTableName + " WHERE " + principalPrincipal_id + " = :principalID" + " AND " + permission + " = :accessMode";
    6460        return getSimpleJdbcTemplate().query(sql, internalIDRowMapper, params);
    6561    }
    66    
    67      ////////////////////////////////////////////////
     62
     63    ////////////////////////////////////////////////
    6864    @Override
    69     public List<Number> getOwnerNotebookIDs(Number  userID) {
    70         String sql = "SELECT " + notebook_id + " FROM " + notebookTableName +" WHERE " + owner_id + " = ?";
     65    public List<Number> getOwnerNotebookIDs(Number userID) {
     66        String sql = "SELECT " + notebook_id + " FROM " + notebookTableName + " WHERE " + owner_id + " = ?";
    7167        return getSimpleJdbcTemplate().query(sql, internalIDRowMapper, userID);
    7268    }
    73    
    74    
    75    
     69
     70 
     71
     72    @Override
     73    public List<Number> getPrincipalIDsWithPermission(Number notebookID, Permission permission) {
     74         if (notebookID == null) {
     75            return null;
     76        }         
     77        Map<String, Object> params= new HashMap<String, Object>();
     78        params.put("notebookID", notebookID);
     79        params.put("permission", permission.value());
     80       
     81        String sql = "SELECT  " + owner_id + " FROM " + notebookPermissionsTableName + " WHERE " + notebook_id +" = :notebookID AND " +this.permission + " = :permission";
     82        return getSimpleJdbcTemplate().query(sql, principalIDRowMapper, params);
     83       
     84    }
     85
    7686    @Override
    7787    public NotebookInfo getNotebookInfo(Number notebookID) {
     
    8090        }
    8191        String sql = "SELECT  " + notebookExternal_id + "," + notebookTitle + " FROM " + notebookTableName + " where " + notebook_id + " = ? LIMIT 1";
    82         List<NotebookInfo> result = getSimpleJdbcTemplate().query(sql, notebookInfoRowMapper, notebookID.toString());
     92        List<NotebookInfo> result = getSimpleJdbcTemplate().query(sql, notebookInfoRowMapper, notebookID);
    8393        return (!result.isEmpty() ? result.get(0) : null);
    8494    }
    85    
    8695    private final RowMapper<NotebookInfo> notebookInfoRowMapper = new RowMapper<NotebookInfo>() {
    8796        @Override
    8897        public NotebookInfo mapRow(ResultSet rs, int rowNumber) throws SQLException {
    8998            NotebookInfo notebookInfo = new NotebookInfo();
    90             notebookInfo.setRef(externalIDtoURI(rs.getString(external_id))); 
     99            notebookInfo.setRef(externalIDtoURI(rs.getString(external_id)));
    91100            notebookInfo.setTitle(rs.getString(title));
    92101            return notebookInfo;
    93102        }
    94103    };
    95    
    96    
     104
    97105    @Override
    98106    public Notebook getNotebookWithoutAnnotationsAndPermissions(Number notebookID) {
     
    100108            return null;
    101109        }
    102         String sql = "SELECT  " + notebookExternal_id + "," + notebookTitle + "," + last_modified +" FROM " + notebookTableName + " where " + notebook_id + " = ? LIMIT 1";
     110        String sql = "SELECT  " + notebookExternal_id + "," + notebookTitle + "," + last_modified + " FROM " + notebookTableName + " where " + notebook_id + " = ? LIMIT 1";
    103111        List<Notebook> result = getSimpleJdbcTemplate().query(sql, notebookRowMapper, notebookID);
    104112        return (!result.isEmpty() ? result.get(0) : null);
    105113    }
    106    
    107    
    108    
    109        private final RowMapper<Notebook> notebookRowMapper = new RowMapper<Notebook>() {
     114    private final RowMapper<Notebook> notebookRowMapper = new RowMapper<Notebook>() {
    110115        @Override
    111116        public Notebook mapRow(ResultSet rs, int rowNumber) throws SQLException {
     
    124129        }
    125130    };
    126 
    127 //    @Override
    128 //    public UUID addNotebook(UUID userID, String title) {
    129 //        try {
    130 //            final UUID externalIdentifier = UUID.randomUUID();
    131 //            String sql = "INSERT INTO " + notebookTableName + " (" + external_id + ", " + this.title + "," + notebookOwner_id + ") VALUES (:notebookId, :title, (SELECT " + principal_id + " FROM " + principalTableName + " WHERE " + principalExternal_id + " = :userID))";
    132 //            Map<String, Object> params = new HashMap<String, Object>();
    133 //            params.put("notebookId", externalIdentifier.toString());
    134 //            params.put("userID", userID.toString());
    135 //            params.put("title", title);
    136 //            final int updatedRowCount = getSimpleJdbcTemplate().update(sql, params);
    137 //            return externalIdentifier;
    138 //        } catch (DataAccessException exception) {
    139 //            throw exception;
    140 //        }
    141 //    }
    142131   
    143  
    144 
    145     // returns the number of affected annotations
    146 //    @Override
    147 //    public int deleteNotebook(UUID notebookId) {
    148 //        String sql1 = "DELETE FROM " + notebooksAnnotationsTableName + " where " + notebook_id + "= (SELECT " + notebook_id + " FROM " + notebookTableName + " WHERE " + external_id + " = ?)";
    149 //        String sql2 = "DELETE FROM notebook where external_id = ?";
    150 //        int affectedAnnotations = getSimpleJdbcTemplate().update(sql1, notebookId.toString());
    151 //        int affectedNotebooks = getSimpleJdbcTemplate().update(sql2, notebookId.toString());
    152 //        return affectedAnnotations;
    153 //    }
    154 
    155 //    @Override
    156 //    public int addAnnotation(UUID notebookId, UUID annotationId) {
    157 //        try {
    158 //            SimpleJdbcInsert notebookInsert = new SimpleJdbcInsert(getDataSource()).withTableName(notebooksAnnotationsTableName);
    159 //            Map<String, Object> params = new HashMap<String, Object>();
    160 //            params.put(notebook_id, notebookId);
    161 //            params.put(annotation_id, annotationId);
    162 //            int rowsAffected = notebookInsert.execute(params);
    163 //            return rowsAffected;
    164 //        } catch (DataAccessException exception) {
    165 //            throw exception;
    166 //        }
    167 //    }
    168 
    169     ////////////////////////////////////////////////////////////////////////
     132   
     133    @Override
     134    public List<Number> getAnnotations(int maximumAnnotations, int startannotation, String orderedBy, boolean orderingMode){
     135        return null;
     136    }
     137   
     138   
     139       /**
     140     *
     141     * UPDATERS
     142     *
     143     *
     144     */
     145   
     146   
     147   
    170148    /**
    171      *
     149     * 
    172150     * @param notebookID
    173      * @return the list of annotation-ids belonging to the notebook with
    174      * notebookId returns null if notebookId is null or is not in the DB TODO:
    175      * do we need to return null here? using an additional check.
     151     * @return true if updated, false otherwise. Logs the reason if the notebook is not updated.
    176152     */
    177 //    @Override
    178 //    public List<Number> getAnnotationIDs(Number notebookID) {
    179 //        StringBuilder sql = new StringBuilder("SELECT DISTINCT ");
    180 //        sql.append(notebooksAnnotationsTableNameAnnotation_id).append("  FROM ").append(notebooksAnnotationsTableName).append(" where ").append(notebook_id).append(" = ?");
    181 //        return getSimpleJdbcTemplate().query(sql.toString(), annotationIDRowMapper, notebookID);
    182 //    }
    183  
    184     //////////////////////////////////////////////////
     153    @Override
     154    public boolean updateNotebookMetadata(Number notebookID){
     155        return false;
     156    }
     157     /**
     158     *
     159     * ADDERS
     160     *
     161     *
     162     */
     163   
     164    @Override
     165    public Number createNotebook(Notebook notebook){
     166        return null;
     167    }
     168   
     169    @Override
     170    public boolean addAnnotationToNotebook(Number noteboookId, Number AnnotationID){
     171        return false;
     172    }
     173   
     174   
    185175    /**
    186      *
    187      * @param notebookID
    188      * @return the list of annotation-infos of the annotations from notebookID;
    189      * if notebook not in the DB or null returns null if the notebook contains
    190      * no annotations returns an empty list
    191      *
    192      *
    193      * @Override public List<AnnotationInfo> getAnnotationInfosOfNotebook(Number
    194      * notebookID) { return
    195      * jdbcAnnotationDao.getAnnotationInfos(getAnnotationIDs(notebookID)); }
     176     *
     177     * DELETERS (ADDER)
     178     *
     179     *
    196180     */
    197     //////////////////////////////////////////////
    198     /**
    199      *
    200      * @param notebookID
    201      * @return the list of annotation References from the notebookID returns
    202      * null if notebookID == null or it does not exists in the DB
    203      */
    204 //    @Override
    205 //    public List<String> getAnnotationREFsOfNotebook(Number notebookID) {
    206 //        return null; //jdbcAnnotationDao.getAnnotationREFs(getAnnotationIDs(notebookID));
    207 //    }
    208 
    209     ////////////////////////////////////////////////////////////////////////////
    210     /**
    211      *
    212      * @param notebookID
    213      * @return the Annotations (as a list of references) from the notebookID *
    214      * returns null if notebookID == null, or it does not exists in th DB, or
    215      * the list of annotations is empty, or something wrong happened when
    216      * extracting annotations from the notebook (according to dasish.xsd if an
    217      * Annotation is created then its list of annotations must contain at least
    218      * one element!)
    219      *
    220      */
    221 //    @Override
    222 //    public ReferenceList getAnnotations(Number notebookID) {
    223 //        if (notebookID == null) {
    224 //            return null;
    225 //        }
    226 //        ReferenceList result = new ReferenceList();
    227 //        result.getRef().addAll(getAnnotationREFsOfNotebook(notebookID));
    228 //        return result;
    229 //
    230 //    }
    231 
    232     ///////////////////////////////////////////////////
    233    
    234    
    235181   
    236     //////////////////////////////////////////////////////////////////
    237 //    @Override
    238 //    public List<UUID> getAnnotationExternalIDs(UUID notebookId) {
    239 //        List<Number> internalIds = getAnnotationIDs(getInternalID(notebookId));
    240 //        if (internalIds == null) {
    241 //            return null;
    242 //        }
    243 //        List<UUID> annotationIds = new ArrayList<UUID>();
    244 ////        for (Number internalId : internalIds) {
    245 ////            annotationIds.add(jdbcAnnotationDao.getExternalID(internalId));
    246 ////        }
    247 //        return annotationIds;
    248 //    }
    249 
    250     ////////////////////////////////////////////////////////////
    251 //    @Override
    252 //    public int removeAnnotation(Number annotationID) {
    253 //        String sqlNotebooks = "DELETE FROM " + notebooksAnnotationsTableName + " where " + annotation_id + " = ?";
    254 //        int affectedNotebooks = getSimpleJdbcTemplate().update(sqlNotebooks, annotationID);
    255 //        return affectedNotebooks;
    256 //    }
     182    @Override
     183    public boolean deleteannotationFromNotebook(Number notebookID, Number annotationID){
     184        return false;
     185    }
     186   
     187    @Override
     188    public boolean deleteNotebook(Number notebookID){
     189        return false;
     190    }
    257191}
Note: See TracChangeset for help on using the changeset viewer.