Changeset 4429


Ignore:
Timestamp:
02/04/14 16:25:45 (10 years ago)
Author:
olhsha
Message:

ownership is unique for the annotations and notebooks. Owner is removed from the permissions tables and added to the annotations and notebooks tables. The code is modified and unit-tested.

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

Legend:

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

    r4406 r4429  
    6666     *
    6767     */
    68     public List<Number> getFilteredAnnotationIDs(List<Number> annotationIDs, String text, String namespace, String after, String before);
     68    public List<Number> getFilteredAnnotationIDs(List<Number> annotationIDs, Number ownerID, String text, String namespace, String after, String before);
    6969     
    7070    public List<Number> getAllAnnotationIDs();
     
    163163     **/
    164164   
    165     public Number addAnnotation(Annotation annotation);
     165    public Number addAnnotation(Annotation annotation, Number newOwnerID);
    166166 
    167167     
     
    179179     * @throws SQLException
    180180     */
    181     public int updateAnnotation(Annotation annotation);
     181    public int updateAnnotation(Annotation annotation, Number ownerID);
    182182   
    183183   
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/DBIntegrityService.java

    r4406 r4429  
    8787    * -- created after time-samp "after and before time-stamp "before".
    8888    */
    89     List<Number> getFilteredAnnotationIDs(String link, String text, Number inloggedUserID, String[] accessModes, String namespace, String after, String before);
     89    List<Number> getFilteredAnnotationIDs(UUID ownerId, String link, String text, Number inloggedUserID, String[] accessModes, String namespace, String after, String before);
    9090   
    9191    AnnotationInfoList getAllAnnotationInfos();
     
    108108    * -- created after time-samp "after and before time-stamp "before".
    109109     */
    110     AnnotationInfoList getFilteredAnnotationInfos(String word, String text, Number inloggedUserID, String[] accessModes, String namespace, UUID
    111             ownerID, String after, String before);
     110    AnnotationInfoList getFilteredAnnotationInfos(UUID ownerId, String word, String text, Number inloggedUserID, String[] accessModes, String namespace, String after, String before);
    112111
    113112    /**
     
    162161    Annotation getAnnotation(Number annotationID);
    163162   
     163    Number getAnnotationOwner(Number annotationID);
     164   
    164165     /**
    165166     *
     
    170171    ReferenceList getAnnotationTargets(Number annotationID);
    171172   
     173   
    172174   
    173175    /**
     
    244246    /**
    245247     *
    246      * @param userID
    247248     * @param annotation
    248249     * @return 1 of the annotation if it is updated
    249250     */
    250     int updateUsersAnnotation(Number userID, Annotation annotation);
     251    int updateAnnotation(Annotation annotation);
    251252   
    252253     
     
    313314     * @throws SQLException
    314315     */
    315     Number addUsersAnnotation(Number userID, Annotation annotation);
     316    Number addUsersAnnotation(Number ownerID, Annotation annotation);
    316317   
    317318    /**
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/NotebookDao.java

    r3781 r4429  
    1919
    2020
     21import eu.dasish.annotation.schema.Permission;
    2122import eu.dasish.annotation.schema.ReferenceList;
    2223import eu.dasish.annotation.schema.Notebook;
     
    4142     *
    4243     */
    43     // Returns a list of notebook-info for the notebooks accessible to the current user.
    44     List<NotebookInfo> getNotebookInfos(UUID userID);
     44    // Returns a list of notebook Ids for the notebooks for which the given user "userID' has "permission" access.
     45    List<Number> getNotebookIDs(Number userID, Permission acessMode);
     46   
     47    // Returns a list of notebook Ids for the notebooks for which the given user "userID" is the owner.
     48    List<Number> getOwnerNotebookIDs(Number userID);
     49   
     50    /**
     51     *
     52     * @param notebookID
     53     * @return the notebook info for the notebook with notebookID
     54     */
     55    NotebookInfo getNotebookInfo(Number notebookID);
     56   
     57    /**
     58     *
     59     * @param notebookID
     60     * @return notebook metadata for the notebook with notebookID
     61     */
     62    Notebook getNotebookWithoutAnnotationsAndPermissions(Number notebookID);
     63   
    4564
    4665    // Returns the list of all notebooks owned by the current logged user.
    47     List<Notebook> getUsersNotebooks(UUID userID);
     66    //List<Notebook> getUsersNotebooks(UUID userID);
    4867
    4968   
    5069      // Returns the list of annotation Id-s  for the notebook id.
    51     public List<Number> getAnnotationIDs(Number notebookID);
     70    //public List<Number> getAnnotationIDs(Number notebookID);
    5271   
    5372      /*Returns the list of annotation info-s  for the notebook id.
     
    5574   
    5675      // Returns the list of annotations Id-s  for the notebook id.
    57     public List<String> getAnnotationREFsOfNotebook(Number notebookID);
     76    //public List<String> getAnnotationREFsOfNotebook(Number notebookID);
    5877   
    5978    // Returns the Annotations object for the notebook id.
    60     public ReferenceList getAnnotations(Number notebookID);
     79    //public ReferenceList getAnnotations(Number notebookID);
    6180   
    6281    /**
     
    6685     * user in getting the metadata of a notebook
    6786     */
    68     NotebookInfo getNotebookInfo(Number notebookID);
     87    //NotebookInfo getNotebookInfo(Number notebookID);
    6988   
    7089 
     
    7493     * @return returns the externalIds of the annotations contained in the notebookId
    7594     */
    76     List<UUID> getAnnotationExternalIDs(UUID notebookId);
     95    //List<UUID> getAnnotationExternalIDs(UUID notebookId);
    7796   
    7897   
     
    83102   
    84103    // Creates a new notebook and returns the _nid_ of the created Notebook
    85     UUID addNotebook(UUID userID, String title);
     104    //UUID addNotebook(UUID userID, String title);
    86105
    87106      // Adds an annotation _aid_ to the list of annotations of _nid_.
    88     public int addAnnotation(UUID notebookId, UUID annotationId);
     107    //public int addAnnotation(UUID notebookId, UUID annotationId);
    89108   
    90109   
     
    98117    // Delete _nid_. Annotations stay, they just lose connection to _nid_.<br>
    99118    // returns the number of records deleted
    100     public int deleteNotebook(UUID notebookId);
     119    //public int deleteNotebook(UUID notebookId);
    101120    /**
    102121     *
     
    104123     * @return removes the rows with annotationID from notebooks_annotations table
    105124     */
    106     int removeAnnotation(Number annotationID);
     125    //int removeAnnotation(Number annotationID);
    107126}
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/impl/DBIntegrityServiceImlp.java

    r4406 r4429  
    4040import eu.dasish.annotation.schema.User;
    4141import eu.dasish.annotation.schema.UserWithPermission;
    42 import java.io.IOException;
    4342import java.io.InputStream;
    4443import java.lang.Number;
    45 import java.sql.SQLException;
    46 import java.sql.Timestamp;
    4744import java.util.ArrayList;
    4845import java.util.HashMap;
     
    5047import java.util.Map;
    5148import java.util.UUID;
    52 import javax.xml.parsers.ParserConfigurationException;
    5349import org.springframework.beans.factory.annotation.Autowired;
    5450import org.slf4j.Logger;
    5551import org.slf4j.LoggerFactory;
    56 import org.springframework.transaction.annotation.Transactional;
    5752
    5853/**
     
    151146            result.setTargets(sis);
    152147
    153             result.setPermissions(getPermissionsForAnnotation(annotationID));
     148            result.setPermissions(this.getPermissionsForAnnotation(annotationID));
    154149            return result;
    155150        } else {
    156151            return null;
    157152        }
     153    }
     154   
     155    @Override
     156    public Number getAnnotationOwner(Number annotationID) {
     157        return annotationDao.getOwner(annotationID);
    158158    }
    159159
     
    186186    ////////////////////////////////////////////////////////////////////////
    187187    @Override
    188     public List<Number> getFilteredAnnotationIDs(String link, String text, Number inloggedUserID, String[] accessModes, String namespace, String after, String before) {
     188    public List<Number> getFilteredAnnotationIDs(UUID ownerId, String link, String text, Number inloggedUserID, String[] accessModes, String namespace, String after, String before) {
    189189
    190190        if (accessModes == null) {
     
    200200        }
    201201
    202         return annotationDao.getFilteredAnnotationIDs(annotationIDs, text, namespace, after, before);
     202        Number ownerID = (ownerId != null) ? userDao.getInternalID(ownerId) : null;
     203        return annotationDao.getFilteredAnnotationIDs(annotationIDs, ownerID, text, namespace, after, before);
    203204    }
    204205
     
    255256
    256257    @Override
    257     public AnnotationInfoList getFilteredAnnotationInfos(String word, String text, Number inloggedUserID, String[] accessModes, String namespace, UUID owner, String after, String before) {
    258         List<Number> annotationIDs = getFilteredAnnotationIDs(word, text, inloggedUserID, accessModes, namespace, after, before);
    259         Number givenOwnerID = (owner != null) ? userDao.getInternalID(owner) : null;
     258    public AnnotationInfoList getFilteredAnnotationInfos(UUID ownerId, String word, String text, Number inloggedUserID, String[] accessModes, String namespace, String after, String before) {
     259        List<Number> annotationIDs = this.getFilteredAnnotationIDs(ownerId, word, text, inloggedUserID, accessModes, namespace, after, before);
    260260        if (annotationIDs != null) {
    261261            AnnotationInfoList result = new AnnotationInfoList();
    262262            for (Number annotationID : annotationIDs) {
    263                 Number ownerID = annotationDao.getOwner(annotationID);
    264                 if ((owner == null) || ownerID.equals(givenOwnerID)) {
    265                     ReferenceList targets = getAnnotationTargets(annotationID);
    266                     AnnotationInfo annotationInfo = annotationDao.getAnnotationInfoWithoutTargets(annotationID);
    267                     annotationInfo.setTargets(targets);
    268                     annotationInfo.setOwnerRef(userDao.getURIFromInternalID(ownerID));
    269                     result.getAnnotationInfo().add(annotationInfo);
    270                 }
     263                AnnotationInfo annotationInfo = annotationDao.getAnnotationInfoWithoutTargets(annotationID);
     264                annotationInfo.setTargets(this.getAnnotationTargets(annotationID));
     265                annotationInfo.setOwnerRef(userDao.getURIFromInternalID(annotationDao.getOwner(annotationID)));
     266                result.getAnnotationInfo().add(annotationInfo);
     267
    271268            }
    272269
     
    379376    public int updateAnnotationPrincipalPermission(Number annotationID, Number userID, Permission permission) {
    380377        if (permission != null) {
    381         return annotationDao.updateAnnotationPrincipalPermission(annotationID, userID, permission);
    382         }
    383         else {
     378            return annotationDao.updateAnnotationPrincipalPermission(annotationID, userID, permission);
     379        } else {
    384380            return annotationDao.deleteAnnotationPrincipalPermission(annotationID, userID);
    385381        }
     
    412408    // TODO: unit test
    413409    @Override
    414     public int updateUsersAnnotation(Number userID, Annotation annotation) {
    415         int updatedAnnotations = annotationDao.updateAnnotation(annotation);
     410    public int updateAnnotation(Annotation annotation) {
     411        int updatedAnnotations = annotationDao.updateAnnotation(annotation, userDao.getInternalIDFromURI(annotation.getOwnerRef()));
    416412        Number annotationID = annotationDao.getInternalIDFromURI(annotation.getURI());
    417413        int deletedTargets = annotationDao.deleteAllAnnotationTarget(annotationID);
     
    463459
    464460    @Override
    465     public Number addUsersAnnotation(Number userID, Annotation annotation) {
    466         Number annotationID = annotationDao.addAnnotation(annotation);
     461    public Number addUsersAnnotation(Number ownerID, Annotation annotation) {
     462        Number annotationID = annotationDao.addAnnotation(annotation, ownerID);
    467463        int affectedAnnotRows = addTargets(annotation, annotationID);
    468464        if (annotation.getPermissions() != null) {
    469465            if (annotation.getPermissions().getUserWithPermission() != null) {
    470                 int addedPrincipalsPermissions = addPrincipalsPermissions(annotation.getPermissions().getUserWithPermission(), annotationID);
    471             }
    472         }
    473         int affectedPermissions = annotationDao.addAnnotationPrincipalPermission(annotationID, userID, Permission.OWNER);
     466                int addedPrincipalsPermissions = this.addPrincipalsPermissions(annotation.getPermissions().getUserWithPermission(), annotationID);
     467            }
     468        }
    474469        return annotationID;
    475470    }
     
    526521        List<Number> cachedIDs = targetDao.getCachedRepresentations(TargetID);
    527522        for (Number cachedID : cachedIDs) {
    528             int[] currentResult = deleteCachedRepresentationOfTarget(TargetID, cachedID);
     523            int[] currentResult = this.deleteCachedRepresentationOfTarget(TargetID, cachedID);
    529524            result[0] = result[0] + currentResult[0];
    530525            result[1] = result[1] + currentResult[1];
     
    543538        if (targetIDs != null) {
    544539            for (Number targetID : targetIDs) {
    545                 deleteAllCachedRepresentationsOfTarget(targetID);
     540                this.deleteAllCachedRepresentationsOfTarget(targetID);
    546541                result[3] = result[3] + targetDao.deleteTarget(targetID);
    547542
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/impl/JdbcAnnotationDao.java

    r4406 r4429  
    142142        StringBuilder sql = new StringBuilder("SELECT ");
    143143        sql.append(annotation_id).append(" FROM ").append(permissionsTableName).append(" WHERE ").
    144                 append(principal_id).append("  = ").append(userID.toString()).append(" AND ").
     144                append(principal_id).append("  = ?").append(" AND ").
    145145                append(permission).append("  IN ").append(values);
    146         return getSimpleJdbcTemplate().query(sql.toString(), internalIDRowMapper);
     146        return getSimpleJdbcTemplate().query(sql.toString(), internalIDRowMapper, userID);
    147147    }
    148148
     
    166166    ////////////////////////////////////////////////////////////////////////
    167167    @Override
    168     public List<Number> getFilteredAnnotationIDs(List<Number> annotationIDs, String text, String namespace, String after, String before) {
     168    public List<Number> getFilteredAnnotationIDs(List<Number> annotationIDs, Number ownerID, String text, String namespace, String after, String before) {
    169169
    170170        StringBuilder sql = new StringBuilder("SELECT DISTINCT ");
     
    184184        sql.append(" AND ").append(annotation_id).append(" IN ").append(values);
    185185
    186 
     186        if (ownerID != null) {
     187            sql.append(" AND ").append(owner_id).append("  = :ownerId");
     188            params.put("ownerId", ownerID);
     189        }
     190       
    187191        if (after != null) {
    188192            sql.append(" AND ").append(last_modified).append("  > :afterTimestamp");
     
    334338        }
    335339        StringBuilder sql = new StringBuilder("SELECT ");
    336         sql.append(principal_id).append(" FROM ").append(permissionsTableName).append(" WHERE ").
    337                 append(permission).append("= 'owner' AND ").
     340        sql.append(owner_id).append(" FROM ").append(annotationTableName).append(" WHERE ").
    338341                append(annotation_id).append("= ? LIMIT  1");
    339         List<Number> respond = getSimpleJdbcTemplate().query(sql.toString(), principalIDRowMapper, annotationID);
     342        List<Number> respond = getSimpleJdbcTemplate().query(sql.toString(), ownerIDRowMapper, annotationID);
    340343        return (respond.isEmpty() ? null : respond.get(0));
    341344    }
     345   
     346   
    342347
    343348    /////////////////////////////
     
    386391    // TODO Unit test
    387392    @Override
    388     public int updateAnnotation(Annotation annotation) {
     393    public int updateAnnotation(Annotation annotation, Number newOwnerID) {
    389394
    390395        String[] body = retrieveBodyComponents(annotation.getBody());
    391396        String externalID = stringURItoExternalID(annotation.getURI());
    392397        Map<String, Object> params = new HashMap<String, Object>();
     398        params.put("owner", newOwnerID);
    393399        params.put("bodyText", body[0]);
    394400        params.put("bodyMimeType", body[1]);
     
    400406        StringBuilder sql = new StringBuilder("UPDATE ");
    401407        sql.append(annotationTableName).append(" SET ").
     408                append(owner_id).append("=  :owner ,").
    402409                append(body_text).append("=  :bodyText ,").
    403410                append(body_mimetype).append("= :bodyMimeType ,").
     
    452459    //////////// ADDERS ////////////////////////
    453460    @Override
    454     public Number addAnnotation(Annotation annotation) {
     461    public Number addAnnotation(Annotation annotation, Number ownerID) {
    455462
    456463        String[] body = retrieveBodyComponents(annotation.getBody());
     
    465472        Map<String, Object> params = new HashMap<String, Object>();
    466473        params.put("externalId", externalID.toString());
     474        params.put("owner", ownerID);
    467475        params.put("headline", annotation.getHeadline());
    468476        params.put("bodyText", body[0]);
     
    471479
    472480        StringBuilder sql = new StringBuilder("INSERT INTO ");
    473         sql.append(annotationTableName).append("(").append(external_id);
     481        sql.append(annotationTableName).append("(").append(external_id).append(",").append(owner_id);
    474482        sql.append(",").append(headline).append(",").append(body_text).append(",").append(body_mimetype).append(",").append(is_xml).
    475                 append(" ) VALUES (:externalId, :headline, :bodyText, :bodyMimeType, :isXml)");
     483                append(" ) VALUES (:externalId, :owner, :headline, :bodyText, :bodyMimeType, :isXml)");
    476484        int affectedRows = getSimpleJdbcTemplate().update(sql.toString(), params);
    477485        return ((affectedRows > 0) ? getInternalID(externalID) : null);
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/impl/JdbcNotebookDao.java

    r4262 r4429  
    1919
    2020import eu.dasish.annotation.backend.dao.NotebookDao;
    21 import eu.dasish.annotation.schema.ReferenceList;
    2221import eu.dasish.annotation.schema.Notebook;
    2322import eu.dasish.annotation.schema.NotebookInfo;
     23import eu.dasish.annotation.schema.Permission;
    2424import java.sql.ResultSet;
    2525import java.sql.SQLException;
    26 import java.util.ArrayList;
    2726import java.util.GregorianCalendar;
    2827import java.util.HashMap;
    2928import java.util.List;
    3029import java.util.Map;
    31 import java.util.UUID;
    3230import javax.sql.DataSource;
    3331import org.springframework.jdbc.core.RowMapper;
     
    3533import javax.xml.datatype.DatatypeFactory;
    3634import javax.xml.datatype.XMLGregorianCalendar;
    37 import org.springframework.dao.DataAccessException;
    38 import org.springframework.jdbc.core.simple.SimpleJdbcInsert;
    3935
    4036/**
     
    5753    }
    5854
     55    /// GETTERS /////////
     56   
    5957    ////////////////////////////////////////////////
    6058    @Override
    61     public List<NotebookInfo> getNotebookInfos(UUID  userID) {
    62         String sql = "SELECT " + notebookTitle + ", " + notebookExternal_id + " FROM " + notebookTableName + ", " + principalTableName + " where " + principalPrincipal_id + " = " + notebookOwner_id + " and " + principalExternal_id + " = ?";
    63         return getSimpleJdbcTemplate().query(sql, notebookInfoRowMapper, userID.toString());
     59    public List<Number> getNotebookIDs(Number  userID, Permission acessMode) {
     60        Map<String, Object> params = new HashMap<String, Object>();
     61        params.put("principalID", userID);
     62        params.put("accessMode", acessMode.value());
     63        String sql = "SELECT " + notebook_id + " FROM " + notebookPermissionsTableName +" WHERE " + principalPrincipal_id + " = :principalID" + " AND " + permission + " = :accessMode";
     64        return getSimpleJdbcTemplate().query(sql, internalIDRowMapper, params);
     65    }
     66   
     67     ////////////////////////////////////////////////
     68    @Override
     69    public List<Number> getOwnerNotebookIDs(Number  userID) {
     70        String sql = "SELECT " + notebook_id + " FROM " + notebookTableName +" WHERE " + owner_id + " = ?";
     71        return getSimpleJdbcTemplate().query(sql, internalIDRowMapper, userID);
     72    }
     73   
     74   
     75   
     76    @Override
     77    public NotebookInfo getNotebookInfo(Number notebookID) {
     78        if (notebookID == null) {
     79            return null;
     80        }
     81        String sql = "SELECT  " + notebookExternal_id + "," + notebookTitle + " FROM " + notebookTableName + " where " + notebook_id + " = ? LIMIT 1";
     82        List<NotebookInfo> result = getSimpleJdbcTemplate().query(sql, notebookInfoRowMapper, notebookID.toString());
     83        return (!result.isEmpty() ? result.get(0) : null);
    6484    }
    6585   
     
    7494    };
    7595   
    76     ////////////////////////////////////////////////
    77 
    78     @Override
    79     public List<Notebook> getUsersNotebooks(UUID userID) {
    80         String sql = "SELECT " + notebookStar + " FROM " + notebookTableName + ", " + principalTableName + " where " + principal_id + " = " + notebookOwner_id + " and " + principalExternal_id + " = ?";
    81         return getSimpleJdbcTemplate().query(sql, notebookRowMapper, userID.toString());
    82     }
     96   
     97    @Override
     98    public Notebook getNotebookWithoutAnnotationsAndPermissions(Number notebookID) {
     99        if (notebookID == null) {
     100            return null;
     101        }
     102        String sql = "SELECT  " + notebookExternal_id + "," + notebookTitle + "," + last_modified +" FROM " + notebookTableName + " where " + notebook_id + " = ? LIMIT 1";
     103        List<Notebook> result = getSimpleJdbcTemplate().query(sql, notebookRowMapper, notebookID);
     104        return (!result.isEmpty() ? result.get(0) : null);
     105    }
     106   
     107   
    83108   
    84109       private final RowMapper<Notebook> notebookRowMapper = new RowMapper<Notebook>() {
     
    86111        public Notebook mapRow(ResultSet rs, int rowNumber) throws SQLException {
    87112            Notebook notebook = new Notebook();
    88 //          notebook.setId(rs.getInt("notebook_id"));
    89113            notebook.setTitle(rs.getString(title));
    90114            GregorianCalendar calendar = new GregorianCalendar();
     
    96120                throw new SQLException(exception);
    97121            }
    98             notebook.setURI(externalIDtoURI(rs.getString("external_id")));
    99             notebook.setAnnotations(getAnnotations(rs.getInt(notebook_id)));
     122            notebook.setURI(externalIDtoURI(rs.getString(external_id)));
    100123            return notebook;
    101124        }
    102125    };
    103126
    104     @Override
    105     public UUID addNotebook(UUID userID, String title) {
    106         try {
    107             final UUID externalIdentifier = UUID.randomUUID();
    108             String sql = "INSERT INTO " + notebookTableName + " (" + external_id + ", " + this.title + "," + notebookOwner_id + ") VALUES (:notebookId, :title, (SELECT " + principal_id + " FROM " + principalTableName + " WHERE " + principalExternal_id + " = :userID))";
    109             Map<String, Object> params = new HashMap<String, Object>();
    110             params.put("notebookId", externalIdentifier.toString());
    111             params.put("userID", userID.toString());
    112             params.put("title", title);
    113             final int updatedRowCount = getSimpleJdbcTemplate().update(sql, params);
    114             return externalIdentifier;
    115         } catch (DataAccessException exception) {
    116             throw exception;
    117         }
    118     }
     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//    }
    119142   
    120143 
    121144
    122145    // returns the number of affected annotations
    123     @Override
    124     public int deleteNotebook(UUID notebookId) {
    125         String sql1 = "DELETE FROM " + notebooksAnnotationsTableName + " where " + notebook_id + "= (SELECT " + notebook_id + " FROM " + notebookTableName + " WHERE " + external_id + " = ?)";
    126         String sql2 = "DELETE FROM notebook where external_id = ?";
    127         int affectedAnnotations = getSimpleJdbcTemplate().update(sql1, notebookId.toString());
    128         int affectedNotebooks = getSimpleJdbcTemplate().update(sql2, notebookId.toString());
    129         return affectedAnnotations;
    130     }
    131 
    132     @Override
    133     public int addAnnotation(UUID notebookId, UUID annotationId) {
    134         try {
    135             SimpleJdbcInsert notebookInsert = new SimpleJdbcInsert(getDataSource()).withTableName(notebooksAnnotationsTableName);
    136             Map<String, Object> params = new HashMap<String, Object>();
    137             params.put(notebook_id, notebookId);
    138             params.put(annotation_id, annotationId);
    139             int rowsAffected = notebookInsert.execute(params);
    140             return rowsAffected;
    141         } catch (DataAccessException exception) {
    142             throw exception;
    143         }
    144     }
     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//    }
    145168
    146169    ////////////////////////////////////////////////////////////////////////
     
    152175     * do we need to return null here? using an additional check.
    153176     */
    154     @Override
    155     public List<Number> getAnnotationIDs(Number notebookID) {
    156         StringBuilder sql = new StringBuilder("SELECT DISTINCT ");
    157         sql.append(notebooksAnnotationsTableNameAnnotation_id).append("  FROM ").append(notebooksAnnotationsTableName).append(" where ").append(notebook_id).append(" = ?");
    158         return getSimpleJdbcTemplate().query(sql.toString(), annotationIDRowMapper, notebookID);
    159     }
     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//    }
    160183 
    161184    //////////////////////////////////////////////////
     
    179202     * null if notebookID == null or it does not exists in the DB
    180203     */
    181     @Override
    182     public List<String> getAnnotationREFsOfNotebook(Number notebookID) {
    183         return null; //jdbcAnnotationDao.getAnnotationREFs(getAnnotationIDs(notebookID));
    184     }
     204//    @Override
     205//    public List<String> getAnnotationREFsOfNotebook(Number notebookID) {
     206//        return null; //jdbcAnnotationDao.getAnnotationREFs(getAnnotationIDs(notebookID));
     207//    }
    185208
    186209    ////////////////////////////////////////////////////////////////////////////
     
    196219     *
    197220     */
    198     @Override
    199     public ReferenceList getAnnotations(Number notebookID) {
    200         if (notebookID == null) {
    201             return null;
    202         }
    203         ReferenceList result = new ReferenceList();
    204         result.getRef().addAll(getAnnotationREFsOfNotebook(notebookID));
    205         return result;
    206 
    207     }
     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//    }
    208231
    209232    ///////////////////////////////////////////////////
    210     // REUSES notebookInfoRowMapper
    211     @Override
    212     public NotebookInfo getNotebookInfo(Number notebookID) {
    213         if (notebookID == null) {
    214             return null;
    215         }
    216         String sql = "SELECT  " + notebookExternal_id + "," + notebookTitle + " FROM " + notebookTableName + " where " + notebook_id + " = ? LIMIT 1";
    217         List<NotebookInfo> result = getSimpleJdbcTemplate().query(sql, notebookInfoRowMapper, notebookID.toString());
    218         return (!result.isEmpty() ? result.get(0) : null);
    219     }
    220 
     233   
     234   
    221235   
    222236    //////////////////////////////////////////////////////////////////
    223     @Override
    224     public List<UUID> getAnnotationExternalIDs(UUID notebookId) {
    225         List<Number> internalIds = getAnnotationIDs(getInternalID(notebookId));
    226         if (internalIds == null) {
    227             return null;
    228         }
    229         List<UUID> annotationIds = new ArrayList<UUID>();
    230 //        for (Number internalId : internalIds) {
    231 //            annotationIds.add(jdbcAnnotationDao.getExternalID(internalId));
    232 //        }
    233         return annotationIds;
    234     }
     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//    }
    235249
    236250    ////////////////////////////////////////////////////////////
    237     @Override
    238     public int removeAnnotation(Number annotationID) {
    239         String sqlNotebooks = "DELETE FROM " + notebooksAnnotationsTableName + " where " + annotation_id + " = ?";
    240         int affectedNotebooks = getSimpleJdbcTemplate().update(sqlNotebooks, annotationID);
    241         return affectedNotebooks;
    242     }
     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//    }
    243257}
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/impl/JdbcResourceDao.java

    r4396 r4429  
    4747    final static protected String notebooksAnnotationsTableName = "notebooks_annotations";
    4848    final static protected String permissionsTableName = "annotations_principals_permissions";
     49    final static protected String notebookPermissionsTableName = "notebooks_principals_permissions";
    4950    final static protected String annotationsTargetsTableName = "annotations_targets";
    5051    final static protected String targetsCachedRepresentationsTableName = "targets_cached_representations";
     
    5859    final static protected String target_id = "target_id";
    5960    final static protected String external_id = "external_id";
     61    final static protected String owner_id = "owner_id";
    6062    final static protected String headline = "headline";
    6163    final static protected String body_text = "body_text";
     
    220222        }
    221223    };
     224   
     225    protected final RowMapper<Number> ownerIDRowMapper = new RowMapper<Number>() {
     226        @Override
     227        public Number mapRow(ResultSet rs, int rowNumber) throws SQLException {
     228            return rs.getInt(owner_id);
     229        }
     230    };
     231   
    222232    protected final RowMapper<Number> notebookOwnerIDRowMapper = new RowMapper<Number>() {
    223233        @Override
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/rest/AnnotationResource.java

    r4406 r4429  
    210210                UUID ownerExternalUUID = (ownerExternalId != null) ? UUID.fromString(ownerExternalId) : null;
    211211                String access = (permission != null) ? permission : default_permission;
    212                 final AnnotationInfoList annotationInfoList = dbIntegrityService.getFilteredAnnotationInfos(link, text, userID, makeAccessModeChain(access), namespace, ownerExternalUUID, after, before);
    213                 logger.info("getFilteredAnnotations method: OK");
     212                final AnnotationInfoList annotationInfoList = dbIntegrityService.getFilteredAnnotationInfos(ownerExternalUUID, link, text, userID, this.makeAccessModeChain(access), namespace, after, before);
    214213                return new ObjectFactory().createAnnotationInfoList(annotationInfoList);
    215214            } catch (IllegalArgumentException e) {
     
    277276            if (userID != null) {
    278277                if (annotationID != null) {
    279                     if (isOwner(userID, annotationID)) {
     278                    if (userID.equals(dbIntegrityService.getAnnotationOwner(annotationID))) {
    280279                        int[] resultDelete = dbIntegrityService.deleteAnnotation(annotationID);
    281280                        String result = Integer.toString(resultDelete[0]);
     
    342341        }
    343342
    344         List<UserWithPermission> permissions = annotation.getPermissions().getUserWithPermission();
    345         String ownerURI = annotation.getOwnerRef();
    346         if (!ownerIsListed(ownerURI, permissions)) {
    347             loggerServer.debug(httpServletResponse.SC_CONFLICT + "Wrong request body: the  owner URI's is not listed in the list of permissions as 'owner'. Correct the request and resend.");
    348             httpServletResponse.sendError(HttpServletResponse.SC_CONFLICT, "Wrong request body: the  owner URI's is not listed in the list of permissions as 'owner'. Correct the request and resend.");
    349             return null;
    350         }
    351343
    352344        try {
     
    356348                Number userID = dbIntegrityService.getUserInternalIDFromRemoteID(remoteUser);
    357349                if (userID != null) {
    358                     if (isOwner(userID, annotationID)) {
    359                         int updatedRows = dbIntegrityService.updateUsersAnnotation(userID, annotation);
     350                    if (userID.equals(dbIntegrityService.getAnnotationOwner(annotationID))) {
     351                        int updatedRows = dbIntegrityService.updateAnnotation(annotation);
    360352                        return new ObjectFactory().createResponseBody(makeAnnotationResponseEnvelope(annotationID));
    361353
     
    436428                        final Number annotationID = dbIntegrityService.getAnnotationInternalIdentifier(UUID.fromString(annotationExternalId));
    437429                        if (annotationID != null) {
    438                             if (isOwner(remoteUserID, annotationID)) {
     430                            if (userID.equals(dbIntegrityService.getAnnotationOwner(annotationID))) {
    439431                                int result = (dbIntegrityService.getPermission(annotationID, userID) != null)
    440432                                        ? dbIntegrityService.updateAnnotationPrincipalPermission(annotationID, userID, permission)
     
    488480            if (remoteUserID != null) {
    489481                if (annotationID != null) {
    490                     if (isOwner(remoteUserID, annotationID)) {
     482                    if (remoteUserID.equals(dbIntegrityService.getAnnotationOwner(annotationID))) {
    491483                        int updatedRows = dbIntegrityService.updatePermissions(annotationID, permissions);
    492484                        return new ObjectFactory().createResponseBody(makePermissionResponseEnvelope(annotationID));
     
    512504        }
    513505    }
    514    
     506
    515507    @DELETE
    516508    @Produces(MediaType.TEXT_PLAIN)
     
    525517            if (remoteUserID != null) {
    526518                if (annotationID != null) {
    527                     if (isOwner(remoteUserID, annotationID)) {
     519                    if (remoteUserID.equals(dbIntegrityService.getAnnotationOwner(annotationID))) {
    528520                        Number userID = dbIntegrityService.getUserInternalIdentifier(UUID.fromString(userId));
    529521                        if (userID != null) {
     
    605597
    606598    private boolean canRead(Number userID, Number annotationID) {
     599        if (userID.equals(dbIntegrityService.getAnnotationOwner(annotationID))) {
     600            return true;
     601        }
     602
    607603        final Permission permission = dbIntegrityService.getPermission(annotationID, userID);
    608604        if (permission != null) {
    609             return (permission.value().equals(Permission.OWNER.value()) || permission.value().equals(Permission.WRITER.value()) || permission.value().equals(Permission.READER.value()));
     605            return (permission.value().equals(Permission.WRITER.value()) || permission.value().equals(Permission.READER.value()));
    610606        } else {
    611607            return false;
     
    614610
    615611    private boolean canWrite(Number userID, Number annotationID) {
     612        if (userID.equals(dbIntegrityService.getAnnotationOwner(annotationID))) {
     613            return true;
     614        }
    616615        final Permission permission = dbIntegrityService.getPermission(annotationID, userID);
    617616        if (permission != null) {
    618             return (permission.value().equals(Permission.OWNER.value()) || permission.value().equals(Permission.WRITER.value()));
     617            return (permission.value().equals(Permission.WRITER.value()));
    619618        } else {
    620619            return false;
     
    622621    }
    623622
    624     private boolean isOwner(Number userID, Number annotationID) {
    625         final Permission permission = dbIntegrityService.getPermission(annotationID, userID);
    626         if (permission != null) {
    627             return (permission.value().equals(Permission.OWNER.value()));
    628         } else {
    629             return false;
    630         }
    631     }
    632 
    633623    private String[] makeAccessModeChain(String accessMode) {
    634624        if (accessMode != null) {
    635             if (accessMode.contains(Permission.OWNER.value())) {
     625            if (accessMode.equals(Permission.READER.value())) {
    636626                String[] result = new String[1];
    637                 result[0] = accessMode;
     627                result[0] = Permission.READER.value();
    638628                return result;
    639629            } else {
    640630                if (accessMode.equals(Permission.WRITER.value())) {
    641631                    String[] result = new String[2];
    642                     result[0] = Permission.WRITER.value();
    643                     result[1] = Permission.OWNER.value();
     632                    result[0] = Permission.READER.value();
     633                    result[1] = Permission.WRITER.value();
    644634                    return result;
    645635                } else {
    646                     if (accessMode.equals(Permission.READER.value())) {
    647                         String[] result = new String[3];
    648                         result[0] = Permission.READER.value();
    649                         result[1] = Permission.WRITER.value();
    650                         result[2] = Permission.OWNER.value();
    651                         return result;
    652                     } else {
    653                         logger.error("Invalide access " + accessMode);
    654                         return null;
    655                     }
    656 
    657                 }
     636                    logger.error("Invalide access " + accessMode);
     637                    return null;
     638                }
     639
    658640            }
    659641
     
    662644        }
    663645    }
    664 
    665     private boolean ownerIsListed(String uri, List<UserWithPermission> permissions) {
    666         for (UserWithPermission permissionPair : permissions) {
    667             if (permissionPair.getRef().equals(uri) && permissionPair.getPermission().equals(Permission.OWNER)) {
    668                 return true;
    669             }
    670         }
    671         return false;
    672     }
    673646}
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/sql/DashishAnnotatorCreate.sql

    r4276 r4429  
    5151    notebook_id SERIAL UNIQUE NOT NULL,
    5252    external_id text UNIQUE NOT NULL,
     53    owner_id integer REFERENCES principal(principal_id),
    5354    last_modified timestamp default current_timestamp AT TIME ZONE 'UTC',
    54     title text,
    55     owner_id integer NOT NULL
     55    title text
    5656);
    5757
     
    6060    annotation_id SERIAL UNIQUE NOT NULL,
    6161    external_id text UNIQUE NOT NULL,
     62    owner_id integer REFERENCES principal(principal_id),
    6263    last_modified timestamp default current_timestamp AT TIME ZONE 'UTC',
    6364    headline text,
     
    119120
    120121
    121 
    122122CREATE TABLE annotations_principals_permissions (
    123123annotation_id integer REFERENCES annotation(annotation_id),
     
    127127);
    128128
     129CREATE TABLE notebooks_principals_permissions (
     130notebook_id integer REFERENCES notebook(notebook_id),
     131principal_id integer REFERENCES principal(principal_id),
     132permission_  text REFERENCES permission_(permission_mode),
     133unique(notebook_id, principal_id)
     134);
     135
    129136
    130137---------------------------------------------------------------------------------------------
    131 ALTER TABLE ONLY annotation
    132     ADD CONSTRAINT annotation_primary_key PRIMARY KEY (annotation_id);
     138-- ALTER TABLE ONLY annotation
     139    -- ADD CONSTRAINT annotation_primary_key PRIMARY KEY (annotation_id);
    133140
    134 ALTER TABLE ONLY notebooks_annotations
    135    ADD CONSTRAINT pk_notebooks_annotations PRIMARY KEY (notebook_id, annotation_id);
     141-- ALTER TABLE ONLY notebooks_annotations
     142   -- ADD CONSTRAINT pk_notebooks_annotations PRIMARY KEY (notebook_id, annotation_id);
    136143
    137144
    138 CREATE INDEX fki_annotation_owner_principal_id ON annotation USING btree (owner_id);
     145-- ALTER TABLE ONLY annotation
     146 -- ADD CONSTRAINT fk_annotation_owner_principal_id FOREIGN KEY (owner_id) REFERENCES principal(principal_id);
    139147
    140 CREATE INDEX fki_owner_id_principal_id ON notebook USING btree (owner_id);
    141 
    142 ALTER TABLE ONLY annotation
    143  ADD CONSTRAINT fk_annotation_owner_principal_id FOREIGN KEY (owner_id) REFERENCES principal(principal_id);
    144 
    145 ALTER TABLE ONLY notebook
    146    ADD CONSTRAINT fk_notebook_owner_id_principal_id FOREIGN KEY (owner_id) REFERENCES principal(principal_id);
     148-- ALTER TABLE ONLY notebook
     149   -- ADD CONSTRAINT fk_notebook_owner_id_principal_id FOREIGN KEY (owner_id) REFERENCES principal(principal_id);
    147150
    148151 --ALTER TABLE ONLY notebooks_annotations
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/webapp/META-INF/context.xml

    r4324 r4429  
    2020-->
    2121<Context antiJARLocking="true" path="/annotator-backend">
    22   <Resource auth="Container" driverClassName="org.postgresql.Driver" logAbandoned="true" maxActive="10" maxIdle="5" maxWait="4000" name="jdbc/DASISHAnnotator" password="dasish" removeAbandoned="false" removeAbandonedTimeout="10" type="javax.sql.DataSource" url="jdbc:postgresql:annotator" username="dasish"/>
     22  <Resource auth="Container"
     23            driverClassName="org.postgresql.Driver"
     24            logAbandoned="true" maxActive="10" maxIdle="5" maxWait="4000"
     25            name="jdbc/DASISHAnnotator"
     26            password="dasish"
     27            removeAbandoned="false"
     28            removeAbandonedTimeout="10"
     29            type="javax.sql.DataSource"
     30            url="jdbc:postgresql:annotator"
     31            username="dasish"/>
    2332</Context>
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/test/java/eu/dasish/annotation/backend/dao/impl/DBIntegrityServiceTest.java

    r4406 r4429  
    319319
    320320               
    321                 oneOf(annotationDao).getFilteredAnnotationIDs(mockAnnotationIDs1, "some html", null, after, before);
     321                oneOf(annotationDao).getFilteredAnnotationIDs(mockAnnotationIDs1, null, "some html", null, after, before);
    322322                will(returnValue(mockRetval));
    323323
     
    326326
    327327
    328         List result = dbIntegrityService.getFilteredAnnotationIDs(word, "some html", 3, accessModes, null, after, before);
     328        List result = dbIntegrityService.getFilteredAnnotationIDs(null, word, "some html", 3, accessModes, null, after, before);
    329329        assertEquals(1, result.size());
    330330        assertEquals(3, result.get(0));
     
    430430               
    431431               
    432                 oneOf(annotationDao).getFilteredAnnotationIDs(mockAnnotationIDs1, text, null, after, before);
     432                oneOf(annotationDao).getFilteredAnnotationIDs(mockAnnotationIDs1, 4, text, null, after, before);
    433433                will(returnValue(mockAnnotIDs));
    434434               
     
    458458       
    459459     
    460         AnnotationInfoList result = dbIntegrityService.getFilteredAnnotationInfos(word, text, 3, accessModes, null, ownerUUID, after, before);
     460        AnnotationInfoList result = dbIntegrityService.getFilteredAnnotationInfos(ownerUUID, word, text, 3, accessModes, null, after, before);
    461461        assertEquals(1, result.getAnnotationInfo().size());
    462462        AnnotationInfo resultAnnotInfo = result.getAnnotationInfo().get(0);
     
    674674        mockeryDao.checking(new Expectations() {
    675675            {
    676                 oneOf(annotationDao).addAnnotation(testAnnotation);
     676                oneOf(annotationDao).addAnnotation(testAnnotation, 5);
    677677                will(returnValue(6)); // the next free number is 6
    678678
     
    689689                will(returnValue(1)); // the DB update will be called at perform anyway, even if the body is not changed (can be optimized)
    690690
    691                 oneOf(annotationDao).addAnnotationPrincipalPermission(6, 5, Permission.OWNER);
    692                 will(returnValue(1));
     691               
    693692            }
    694693        });
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/test/java/eu/dasish/annotation/backend/dao/impl/JdbcAnnotationDaoTest.java

    r4406 r4429  
    104104        System.out.println("test deleteAllAnnotationTargets");
    105105        int result = jdbcAnnotationDao.deleteAnnotationPrincipalPermissions(2);
    106         assertEquals(3, result);
     106        assertEquals(2, result);
    107107        assertEquals(0, jdbcAnnotationDao.deleteAnnotationPrincipalPermissions(2));
    108108    }
     
    272272        assertEquals(null, annotationToAdd.getLastModified());
    273273       
    274         Number newAnnotationID = jdbcAnnotationDao.addAnnotation(annotationToAdd);
     274        Number newAnnotationID = jdbcAnnotationDao.addAnnotation(annotationToAdd, 5);
    275275        assertEquals(6, newAnnotationID);
    276276       
     
    335335        annotationIDs.add(3);
    336336       
    337         List<Number> result_1 = jdbcAnnotationDao.getFilteredAnnotationIDs(annotationIDs, null, null, null, null);       
     337        List<Number> result_1 = jdbcAnnotationDao.getFilteredAnnotationIDs(annotationIDs, null, null, null, null, null);       
    338338        assertEquals(2, result_1.size());
    339339        assertEquals(2, result_1.get(0));
     
    341341       
    342342       
    343         List<Number> result_2 = jdbcAnnotationDao.getFilteredAnnotationIDs(annotationIDs, "some html", null, null, null);       
     343        List<Number> result_2 = jdbcAnnotationDao.getFilteredAnnotationIDs(annotationIDs, null, "some html", null, null, null);       
    344344        assertEquals(2, result_2.size());
    345345        assertEquals(2, result_2.get(0));
     
    351351        final String before = (new Timestamp(System.currentTimeMillis())).toString();
    352352 
    353         List<Number> result_4 = jdbcAnnotationDao.getFilteredAnnotationIDs(annotationIDs, "some html", null, after, before);       
    354         assertEquals(2, result_4.size());
    355         assertEquals(2, result_4.get(0));
    356         assertEquals(3, result_2.get(1));
     353        List<Number> result_4 = jdbcAnnotationDao.getFilteredAnnotationIDs(annotationIDs, 4, "some html", null, after, before);       
     354        assertEquals(1, result_4.size());
     355        assertEquals(3, result_4.get(0));
    357356       
    358357        final String after_1 = (new Timestamp(System.currentTimeMillis())).toString();// no annotations added after "now"       
    359         List<Number> result_5 = jdbcAnnotationDao.getFilteredAnnotationIDs(annotationIDs, "some html", null, after_1, null);       
     358        List<Number> result_5 = jdbcAnnotationDao.getFilteredAnnotationIDs(annotationIDs, 4, "some html", null, after_1, null);       
    360359        assertEquals(0, result_5.size());
    361360       
     
    373372        System.out.println("test Permissions");
    374373        List<Map<Number, String>> result = jdbcAnnotationDao.getPermissions(2);
    375         assertEquals(3, result.size());
    376         assertEquals("owner", result.get(0).get(3));
    377         assertEquals("writer", result.get(1).get(4));
    378         assertEquals("reader", result.get(2).get(5));
     374        assertEquals(2, result.size());
     375        assertEquals("writer", result.get(0).get(4));
     376        assertEquals("reader", result.get(1).get(5));
    379377       
    380378       
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/test/java/eu/dasish/annotation/backend/rest/AnnotationResourceTest.java

    r4281 r4429  
    116116                will(returnValue("developer"));
    117117               
    118                 oneOf(mockDbIntegrityService).getPermission(2, 3);
    119                 will(returnValue(Permission.OWNER)); 
     118                oneOf(mockDbIntegrityService).getAnnotationOwner(2);
     119                will(returnValue(3)); 
    120120               
    121121                oneOf(mockDbIntegrityService).getAnnotation(2);               
     
    152152             
    153153                oneOf(mockDbIntegrityService).getUserInternalIDFromRemoteID("twan");
    154                 will(returnValue(3));
     154                will(returnValue(5));
    155155               
    156156                oneOf(mockDbIntegrityService).setServiceURI(with(any(String.class)));
     
    161161               
    162162               
    163                 oneOf(mockDbIntegrityService).getPermission(5, 3);
    164                 will(returnValue(Permission.OWNER)); 
     163                oneOf(mockDbIntegrityService).getAnnotationOwner(5);
     164                will(returnValue(5)); 
    165165               
    166166                oneOf(mockDbIntegrityService).deleteAnnotation(5);
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/test/java/eu/dasish/annotation/backend/rest/AnnotationsTest.java

    r4276 r4429  
    161161        assertEquals(testAnnotation.getHeadline(), entity.getHeadline());
    162162        assertEquals(testAnnotation.getOwnerRef(), entity.getOwnerRef());
    163         assertEquals(3, entity.getPermissions().getUserWithPermission().size());
    164         assertEquals("owner", entity.getPermissions().getUserWithPermission().get(0).getPermission().value());       
    165         assertEquals(resource().getURI()+"users/"+TestBackendConstants._TEST_USER_3_EXT_ID, entity.getPermissions().getUserWithPermission().get(0).getRef());
    166         assertEquals("writer", entity.getPermissions().getUserWithPermission().get(1).getPermission().value());
    167         assertEquals(resource().getURI()+"users/"+TestBackendConstants._TEST_USER_4_EXT_ID, entity.getPermissions().getUserWithPermission().get(1).getRef());
    168         assertEquals("reader", entity.getPermissions().getUserWithPermission().get(2).getPermission().value());
    169         assertEquals(resource().getURI()+"users/"+TestBackendConstants._TEST_USER_5_EXT_ID, entity.getPermissions().getUserWithPermission().get(2).getRef());
     163        assertEquals(2, entity.getPermissions().getUserWithPermission().size());
     164        assertEquals("writer", entity.getPermissions().getUserWithPermission().get(0).getPermission().value());
     165        assertEquals(resource().getURI()+"users/"+TestBackendConstants._TEST_USER_4_EXT_ID, entity.getPermissions().getUserWithPermission().get(0).getRef());
     166        assertEquals("reader", entity.getPermissions().getUserWithPermission().get(1).getPermission().value());
     167        assertEquals(resource().getURI()+"users/"+TestBackendConstants._TEST_USER_5_EXT_ID, entity.getPermissions().getUserWithPermission().get(1).getRef());
    170168        assertEquals(2, entity.getTargets().getTargetInfo().size());
    171169        assertEquals(resource().getURI().toString()+"targets/"+TestBackendConstants._TEST_Target_1_EXT_ID, entity.getTargets().getTargetInfo().get(0).getRef());
     
    233231        assertEquals(annotationToAdd.getBody().getTextBody().getMimeType(), entityA.getBody().getTextBody().getMimeType());
    234232        assertEquals(annotationToAdd.getHeadline(), entityA.getHeadline());
    235         assertEquals(1, entityA.getPermissions().getUserWithPermission().size());
    236         assertEquals("owner", entityA.getPermissions().getUserWithPermission().get(0).getPermission().value());
    237         assertEquals(annotationToAdd.getOwnerRef(), entityA.getPermissions().getUserWithPermission().get(0).getRef());
     233        assertEquals(0, entityA.getPermissions().getUserWithPermission().size());
     234        assertEquals(annotationToAdd.getOwnerRef(), entityA.getOwnerRef());
    238235        assertEquals(annotationToAdd.getTargets().getTargetInfo().get(0).getLink(), entityA.getTargets().getTargetInfo().get(0).getLink());
    239236        // new ref is generated
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/test/resources/test-data/InsertTestData.sql

    r4276 r4429  
    2727-- INSERT INTO notebook (title, owner_id, external_id) VALUES ('a notebook', 1, 1);
    2828
    29 INSERT INTO annotation (headline, body_text, body_mimetype, external_id, is_xml) VALUES ('a headline', '<html><body>some html</body></html>', 'text/html' , '00000000-0000-0000-0000-000000000005', false); --1
     29INSERT INTO annotation (owner_id, headline, body_text, body_mimetype, external_id, is_xml) VALUES (1, 'a headline', '<html><body>some html</body></html>', 'text/html' , '00000000-0000-0000-0000-000000000005', false); --1
    3030
    3131INSERT INTO notebook (title, owner_id, external_id) VALUES ('a second notebook', 2, '00000000-0000-0000-0000-000000000002'); --2
     
    4848INSERT INTO notebook (title, owner_id, external_id) VALUES ('Notebook 6', 5, '00000000-0000-0000-0000-000000000014'); --6
    4949
    50 INSERT INTO annotation (headline,body_text, body_mimetype, external_id, last_modified, is_xml) VALUES ('Sagrada Famiglia','<html><body>some html 1</body></html>', 'text/html' , '00000000-0000-0000-0000-000000000021', '2013-08-12 09:25:00.383', false); --2
    51 INSERT INTO annotation (headline,body_text, body_mimetype, external_id, is_xml) VALUES ('Gaudi','<html><body>some html 2</body></html>', 'text/html' , '00000000-0000-0000-0000-000000000022',false); --3
    52 INSERT INTO annotation (headline,body_text, body_mimetype, external_id, is_xml) VALUES ('Art Nuveau','some plain text', 'text/plain' , '00000000-0000-0000-0000-000000000023', false); --4
    53 INSERT INTO annotation (headline,body_text, body_mimetype, external_id, is_xml) VALUES ('Annotation to delete','<html><body>some html 4</body></html>', 'text/html' , '00000000-0000-0000-0000-000000000024',false); --5
     50INSERT INTO annotation (owner_id, headline,body_text, body_mimetype, external_id, last_modified, is_xml) VALUES (3, 'Sagrada Famiglia','<html><body>some html 1</body></html>', 'text/html' , '00000000-0000-0000-0000-000000000021', '2013-08-12 09:25:00.383', false); --2
     51INSERT INTO annotation (owner_id, headline,body_text, body_mimetype, external_id, is_xml) VALUES (4, 'Gaudi','<html><body>some html 2</body></html>', 'text/html' , '00000000-0000-0000-0000-000000000022',false); --3
     52INSERT INTO annotation (owner_id, headline,body_text, body_mimetype, external_id, is_xml) VALUES (5, 'Art Nuveau','some plain text', 'text/plain' , '00000000-0000-0000-0000-000000000023', false); --4
     53INSERT INTO annotation (owner_id, headline,body_text, body_mimetype, external_id, is_xml) VALUES (5, 'Annotation to delete','<html><body>some html 4</body></html>', 'text/html' , '00000000-0000-0000-0000-000000000024',false); --5
    5454
    5555
     
    104104---- PERMISSIONS --------------------------------------------------------------------------------------------
    105105
    106 INSERT INTO permission_(permission_mode) VALUES ('owner');
     106
    107107INSERT INTO permission_(permission_mode) VALUES ('writer');
    108108INSERT INTO permission_(permission_mode) VALUES ('reader');
    109109
    110 INSERT INTO annotations_principals_permissions (annotation_id, principal_id, permission_) VALUES (2, 3, 'owner');
    111110INSERT INTO annotations_principals_permissions (annotation_id, principal_id, permission_) VALUES (2, 4, 'writer');
    112111INSERT INTO annotations_principals_permissions (annotation_id, principal_id, permission_) VALUES (2, 5, 'reader');
    113112
    114 INSERT INTO annotations_principals_permissions (annotation_id, principal_id, permission_) VALUES (3, 4, 'owner');
    115113INSERT INTO annotations_principals_permissions (annotation_id, principal_id, permission_) VALUES (3, 3, 'reader');
    116114INSERT INTO annotations_principals_permissions (annotation_id, principal_id, permission_) VALUES (3, 5, 'writer');
    117115
    118 INSERT INTO annotations_principals_permissions (annotation_id, principal_id, permission_) VALUES (4, 5, 'owner');
    119116INSERT INTO annotations_principals_permissions (annotation_id, principal_id, permission_) VALUES (4, 3, 'reader');
    120117INSERT INTO annotations_principals_permissions (annotation_id, principal_id, permission_) VALUES (4, 4, 'reader');
    121118
    122 INSERT INTO annotations_principals_permissions (annotation_id, principal_id, permission_) VALUES (5, 5, 'owner');
    123119INSERT INTO annotations_principals_permissions (annotation_id, principal_id, permission_) VALUES (5, 4, 'writer');
    124120INSERT INTO annotations_principals_permissions (annotation_id, principal_id, permission_) VALUES (5, 3, 'writer');
Note: See TracChangeset for help on using the changeset viewer.