Changeset 4491


Ignore:
Timestamp:
02/10/14 15:26:08 (10 years ago)
Author:
olhsha
Message:

POST/PUT/DELETE methods are tested, debugged, refactored and tested

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

Legend:

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

    r4429 r4491  
    5151    public Annotation getAnnotationWithoutTargetsAndPermissions(Number annotationID);
    5252   
    53    
    54      /**
    55      *
    56      * @param annotationIDs: the list of annotationID-s from which the resulting annotations are to be selected.
    57      * @param text: the text which the resulting annotations' bodies must contain.* @param namespace TODO: do not know what to do with it
    58      * @param ownerID: the resulting annotations are owned by the owner "ownerID".
    59      * @param after: the resulting annotations must have timestamp later than "after".
    60      * @param before: the resulting annotations must have timestamp earlier than "before".
    61      * @return the sub-list of internal annotation identifiers from the list "internalIDs" for annotations
    62      * -- bodies of which contain the "text",
    63      * -- to which inlogged user has "access",
    64      * -- owned by "owner",
    65      * -- added to the database between "before" and "after" time-dates.
    66      *
    67      */
    68     public List<Number> getFilteredAnnotationIDs(List<Number> annotationIDs, Number ownerID, String text, String namespace, String after, String before);
     53     
     54    public List<Number> getFilteredAnnotationIDs(Number ownerID, String text, String namespace, String after, String before);
    6955     
     56 
     57    public List<Number> getAnnotationIDsForUserWithPermission(Number userID, String acess);
     58   
     59   
     60    public List<Number> getAnnotationIDsForTargets(List<Number> TargetIDs);   
     61   
     62    /*
     63     * Use inly in the debugging mode to acces all the existing annotations.
     64     */
    7065    public List<Number> getAllAnnotationIDs();
    7166   
     
    8580    public List<String> getAnnotationREFs(List<Number> annotationIDs);
    8681   
    87     /**
    88      *
    89      * @param TargetIDs
    90      * @return the list of annotationdIDs of the annotations which target Targets are from "TargetIDs" list.
    91      */
    92     public List<Number> retrieveAnnotationList(List<Number> TargetIDs);
    93    
     82   
     83   
     84   
    9485   
    9586       /**
     
    117108     */
    118109    public Permission  getPermission(Number annotationID, Number userID);
    119    
    120     public List<Number> getAnnotationIDsForUserWithPermission(Number userID, String[] permissionStrings);
    121110   
    122111   
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/DBIntegrityService.java

    r4429 r4491  
    8787    * -- created after time-samp "after and before time-stamp "before".
    8888    */
    89     List<Number> getFilteredAnnotationIDs(UUID ownerId, 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 access, 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(UUID ownerId, String word, String text, Number inloggedUserID, String[] accessModes, String namespace, String after, String before);
     110    AnnotationInfoList getFilteredAnnotationInfos(UUID ownerId, String word, String text, Number inloggedUserID,  String access, String namespace, String after, String before);
    111111
    112112    /**
     
    237237    public String getTypeOfUserAccount(Number userID);
    238238   
     239    public boolean canRead(Number userID, Number annotationID);
     240           
     241    public boolean canWrite(Number userID, Number annotationID);       
     242   
    239243    /**
    240244     * UPDATERS
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/impl/DBIntegrityServiceImlp.java

    r4429 r4491  
    6565    @Autowired
    6666    AnnotationDao annotationDao;
     67   
     68    final static protected String admin = "admin";
    6769    private static final Logger logger = LoggerFactory.getLogger(AnnotationResource.class);
    6870    //////////////////////////////////
     
    152154        }
    153155    }
    154    
     156
    155157    @Override
    156158    public Number getAnnotationOwner(Number annotationID) {
     
    186188    ////////////////////////////////////////////////////////////////////////
    187189    @Override
    188     public List<Number> getFilteredAnnotationIDs(UUID ownerId, String link, String text, Number inloggedUserID, String[] accessModes, String namespace, String after, String before) {
    189 
    190         if (accessModes == null) {
    191             return null;
    192         }
    193 
    194         List<Number> annotationIDs = annotationDao.getAnnotationIDsForUserWithPermission(inloggedUserID, accessModes);
    195 
     190    public List<Number> getFilteredAnnotationIDs(UUID ownerId, String link, String text, Number inloggedUserID, String access, String namespace, String after, String before) {
     191
     192        Number ownerID = (ownerId != null) ? userDao.getInternalID(ownerId) : null;
     193        if (ownerID != null) {
     194            if ("owner".equals(access) && !inloggedUserID.equals(ownerID)) {
     195                logger.info("The inlogged user cannot be the owner of the annotations owned by " + ownerId.toString());
     196                return null;
     197            }
     198        }
     199
     200        //filtering on tables "target" and "annotations_targets"
     201        List<Number> annotationIDsForTargets = null;
    196202        if (link != null) {
    197203            List<Number> targetIDs = targetDao.getTargetsReferringTo(link);
    198             List<Number> annotationIDsForTargets = annotationDao.retrieveAnnotationList(targetIDs);
    199             annotationIDs.retainAll(annotationIDsForTargets);
    200         }
    201 
    202         Number ownerID = (ownerId != null) ? userDao.getInternalID(ownerId) : null;
    203         return annotationDao.getFilteredAnnotationIDs(annotationIDs, ownerID, text, namespace, after, before);
     204            annotationIDsForTargets = annotationDao.getAnnotationIDsForTargets(targetIDs);
     205            if (annotationIDsForTargets == null) {
     206                logger.info("There are no annotations for the targets referring to " + link + ".");
     207                return null;
     208            }
     209        }
     210
     211        // filtering in the table "annotation"
     212        if (ownerID == null && "owner".equals(access)) {
     213            ownerID = inloggedUserID;
     214        }
     215        List<Number> annotationIDs = annotationDao.getFilteredAnnotationIDs(ownerID, text, namespace, after, before);
     216        if (annotationIDs != null) {
     217            if (annotationIDsForTargets != null) {
     218                annotationIDs.retainAll(annotationIDsForTargets);
     219            } else {
     220                // nothing to filter on link == null
     221            }
     222        } else {
     223            logger.info("There are no annotations for the given filters on the annotation table.");
     224            return null;
     225        }
     226
     227        // filtering on table "annotations_principals_permissions"
     228        if ("reader".equals(access) || "writer".equals(access)) {
     229            // owner != inloggedUser
     230            List<Number> annotationIDsPermission = annotationDao.getAnnotationIDsForUserWithPermission(inloggedUserID, access);
     231            if (annotationIDsPermission != null) {
     232                annotationIDs.retainAll(annotationIDsPermission);
     233            } else {
     234                logger.info("There are no annotations for which the inlogged user has access " + access);
     235                return null;
     236            }
     237        } else {
     238            // inloggedUser == owner
     239        }
     240        return annotationIDs;
    204241    }
    205242
     
    256293
    257294    @Override
    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);
     295    public AnnotationInfoList getFilteredAnnotationInfos(UUID ownerId, String word, String text, Number inloggedUserID, String access, String namespace, String after, String before) {
     296        List<Number> annotationIDs = this.getFilteredAnnotationIDs(ownerId, word, text, inloggedUserID, access, namespace, after, before);
    260297        if (annotationIDs != null) {
    261298            AnnotationInfoList result = new AnnotationInfoList();
     
    366403        return userDao.getTypeOfUserAccount(userID);
    367404    }
     405   
     406    @Override
     407    public boolean canRead(Number userID, Number annotationID) {
     408        if (userID.equals(annotationDao.getOwner(annotationID)) || userDao.getTypeOfUserAccount(userID).equals(admin)) {
     409            return true;
     410        }
     411
     412        final Permission permission = annotationDao.getPermission(annotationID, userID);
     413        if (permission != null) {
     414            return (permission.value().equals(Permission.WRITER.value()) || permission.value().equals(Permission.READER.value()));
     415        } else {
     416            return false;
     417        }
     418    }
     419
     420    @Override
     421    public boolean canWrite(Number userID, Number annotationID) {
     422        if (userID.equals(annotationDao.getOwner(annotationID)) || userDao.getTypeOfUserAccount(userID).equals(admin)) {
     423            return true;
     424        }
     425        final Permission permission = annotationDao.getPermission(annotationID, userID);
     426        if (permission != null) {
     427            return (permission.value().equals(Permission.WRITER.value()));
     428        } else {
     429            return false;
     430        }
     431    }
    368432
    369433    ///// UPDATERS /////////////////
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/impl/JdbcAnnotationDao.java

    r4429 r4491  
    9494    };
    9595
     96   
     97   
    9698    @Override
    9799    public Permission getPermission(Number annotationID, Number userID) {
     
    126128    };
    127129
    128     @Override
    129     public List<Number> getAnnotationIDsForUserWithPermission(Number userID, String[] permissionStrings) {
    130         if (permissionStrings == null) {
    131             loggerAnnotationDao.debug("premissionStrings: " + nullArgument);
    132             return null;
    133         }
    134 
    135         if (userID == null) {
    136             loggerAnnotationDao.debug("userID: " + nullArgument);
    137             return null;
    138         }
    139 
    140         String values = stringsToValuesString(permissionStrings);
    141 
    142         StringBuilder sql = new StringBuilder("SELECT ");
    143         sql.append(annotation_id).append(" FROM ").append(permissionsTableName).append(" WHERE ").
    144                 append(principal_id).append("  = ?").append(" AND ").
    145                 append(permission).append("  IN ").append(values);
    146         return getSimpleJdbcTemplate().query(sql.toString(), internalIDRowMapper, userID);
    147     }
    148 
    149     private String stringsToValuesString(String[] strings) {
    150         if (strings == null) {
    151             return null;
    152         }
    153 
    154         int length = strings.length;
    155         if (length == 0) {
    156             return null;
    157         }
    158         String result = "(";
    159         for (int i = 0; i < length - 1; i++) {
    160             result = result + "'" + strings[i] + "', ";
    161         }
    162         result = result + "'" + strings[length - 1] + "')";
    163         return result;
    164     }
    165 
     130   
     131   
     132   
    166133    ////////////////////////////////////////////////////////////////////////
    167134    @Override
    168     public List<Number> getFilteredAnnotationIDs(List<Number> annotationIDs, Number ownerID, String text, String namespace, String after, String before) {
     135    public List<Number> getFilteredAnnotationIDs(Number ownerID, String text, String namespace, String after, String before) {
    169136
    170137        StringBuilder sql = new StringBuilder("SELECT DISTINCT ");
    171138        sql.append(annotation_id).append(" FROM ").append(annotationTableName).append(" WHERE TRUE ");
    172139        Map<String, Object> params = new HashMap<String, Object>();
    173 
    174         if (annotationIDs == null) {
    175             loggerAnnotationDao.debug("annotationIDs: " + nullArgument);
    176             return null;
    177         } else {
    178             if (annotationIDs.isEmpty()) {
    179                 return new ArrayList<Number>();
    180             }
    181         }
    182 
    183         String values = makeListOfValues(annotationIDs);
    184         sql.append(" AND ").append(annotation_id).append(" IN ").append(values);
    185140
    186141        if (ownerID != null) {
     
    206161    }
    207162
    208     /////////////////////////////////////////
    209     @Override
    210     public List<Number> getAllAnnotationIDs() {
     163     ///////////////////////////////////////////////////////////////////////////////////
     164    @Override
     165    public List<Number> getAnnotationIDsForUserWithPermission(Number userID, String access) {
     166       
     167        if (userID == null) {
     168            loggerAnnotationDao.debug("userID: " + nullArgument);
     169            return null;
     170        }
     171       
     172        if (access == null) {
     173            logger.info("The access argument is null. I assign it a default value 'reader'.");
     174            access = "reader";
     175        }
     176
     177       
    211178        StringBuilder sql = new StringBuilder("SELECT ");
    212         sql.append(annotation_id).append(" , ").append(last_modified).append(" FROM ").append(annotationTableName).append(" ORDER BY ").append(last_modified).append(" DESC");
    213         return getSimpleJdbcTemplate().query(sql.toString(), internalIDRowMapper);
    214     }
     179        sql.append(annotation_id).append(" FROM ").append(permissionsTableName).append(" WHERE ").
     180                append(principal_id).append("  = ?").append(" AND ").
     181                append(permission).append("  = ").append(access);
     182        return getSimpleJdbcTemplate().query(sql.toString(), internalIDRowMapper, userID);
     183    }
     184
     185   
     186 
     187   
    215188
    216189    //////////////////////////////
    217190    @Override
    218     public List<Number> retrieveAnnotationList(List<Number> targetIDs) {
     191    public List<Number> getAnnotationIDsForTargets(List<Number> targetIDs) {
    219192        if (targetIDs == null) {
    220193            loggerAnnotationDao.debug("targetIDs: " + nullArgument);
     
    229202        query.append(values);
    230203        return getSimpleJdbcTemplate().query(query.toString(), internalIDRowMapper);
     204    }
     205   
     206   
     207   
     208   
     209    /////////////////////////////////////////
     210    @Override
     211    public List<Number> getAllAnnotationIDs() {
     212        StringBuilder sql = new StringBuilder("SELECT ");
     213        sql.append(annotation_id).append(" , ").append(last_modified).append(" FROM ").append(annotationTableName).append(" ORDER BY ").append(last_modified).append(" DESC");
     214        return getSimpleJdbcTemplate().query(sql.toString(), internalIDRowMapper);
    231215    }
    232216
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/impl/JdbcResourceDao.java

    r4429 r4491  
    9696    final static protected String targetStar = targetTableName + ".*";
    9797    final static protected String principalStar = principalTableName + ".*";
     98   
     99    ////////////////////////////////
     100   
     101   
    98102    ///////////////////////////////////////////////////
    99103    protected String internalIdName = null;
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/impl/JdbcUserDao.java

    r4461 r4491  
    7878    public User getUserByInfo(String eMail) {
    7979        StringBuilder sql = new StringBuilder("SELECT ");
    80         sql.append(principalStar).append(" FROM ").append(principalTableName).append(" WHERE ").append(e_mail).append("= ? LIMIT 1");
     80        sql.append(principalStar).append(" FROM ").append(principalTableName).append(" WHERE ").append("LOWER(").append(e_mail).append(")").append("= ? LIMIT 1");
    8181        List<User> result = getSimpleJdbcTemplate().query(sql.toString(), userRowMapper, eMail.toLowerCase());
    8282        return (!result.isEmpty() ? result.get(0) : null);
     
    198198        params.put("externalId", newExternalIdentifier);
    199199        params.put("principalName", user.getDisplayName());
    200         params.put("email", user.getEMail().toLowerCase());
     200        params.put("email", user.getEMail());
    201201        params.put("remoteID", remoteID);
    202202        params.put("accountType", this.user);
     
    261261        StringBuilder sql = new StringBuilder("UPDATE ");
    262262        sql.append(principalTableName).append(" SET ").
    263                 append(e_mail).append("= '").append(user.getEMail().toLowerCase()).append("',").
     263                append(e_mail).append("= '").append(user.getEMail()).append("',").
    264264                append(principal_name).append("= '").append(user.getDisplayName()).append("' ").
    265265                append(" WHERE ").append(principal_id).append("= ?");
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/rest/AnnotationResource.java

    r4429 r4491  
    8383    @Context
    8484    private ServletContext context;
    85     final String default_permission = "reader";
     85   
    8686    private final Logger logger = LoggerFactory.getLogger(AnnotationResource.class);
    8787    public static final Logger loggerServer = LoggerFactory.getLogger(HttpServletResponse.class);
     
    123123                final Number userID = dbIntegrityService.getUserInternalIDFromRemoteID(remoteUser);
    124124                if (userID != null) {
    125                     if (dbIntegrityService.getTypeOfUserAccount(userID).equals(admin) || canRead(userID, annotationID)) {
     125                    if (dbIntegrityService.canRead(userID, annotationID)) {
    126126                        final Annotation annotation = dbIntegrityService.getAnnotation(annotationID);
    127127                        JAXBElement<Annotation> rootElement = new ObjectFactory().createAnnotation(annotation);
     
    164164                final Number userID = dbIntegrityService.getUserInternalIDFromRemoteID(remoteUser);
    165165                if (userID != null) {
    166                     if (dbIntegrityService.getTypeOfUserAccount(userID).equals(admin) || canRead(userID, annotationID)) {
     166                    if (dbIntegrityService.canRead(userID, annotationID)) {
    167167                        final ReferenceList TargetList = dbIntegrityService.getAnnotationTargets(annotationID);
    168168                        logger.info("getAnnotationTargets method: OK");
     
    197197    public JAXBElement<AnnotationInfoList> getFilteredAnnotations(@QueryParam("link") String link,
    198198            @QueryParam("text") String text,
    199             @QueryParam("access") String permission,
     199            @QueryParam("access") String access,
    200200            @QueryParam("namespace") String namespace,
    201201            @QueryParam("owner") String ownerExternalId,
     
    209209            try {
    210210                UUID ownerExternalUUID = (ownerExternalId != null) ? UUID.fromString(ownerExternalId) : null;
    211                 String access = (permission != null) ? permission : default_permission;
    212                 final AnnotationInfoList annotationInfoList = dbIntegrityService.getFilteredAnnotationInfos(ownerExternalUUID, link, text, userID, this.makeAccessModeChain(access), namespace, after, before);
     211               
     212                final AnnotationInfoList annotationInfoList = dbIntegrityService.getFilteredAnnotationInfos(ownerExternalUUID, link, text, userID, access, namespace, after, before);
    213213                return new ObjectFactory().createAnnotationInfoList(annotationInfoList);
    214214            } catch (IllegalArgumentException e) {
     
    238238            if (userID != null) {
    239239                if (annotationID != null) {
    240                     if (dbIntegrityService.getTypeOfUserAccount(userID).equals(admin) || canRead(userID, annotationID)) {
     240                    if (dbIntegrityService.canRead(userID, annotationID)) {
    241241                        final UserWithPermissionList permissionList = dbIntegrityService.getPermissionsForAnnotation(annotationID);
    242242                        logger.debug("getAnnotationPermissions method: OK");
     
    276276            if (userID != null) {
    277277                if (annotationID != null) {
    278                     if (userID.equals(dbIntegrityService.getAnnotationOwner(annotationID))) {
     278                    if (userID.equals(dbIntegrityService.getAnnotationOwner(annotationID)) || dbIntegrityService.getTypeOfUserAccount(userID).equals(admin)) {
    279279                        int[] resultDelete = dbIntegrityService.deleteAnnotation(annotationID);
    280280                        String result = Integer.toString(resultDelete[0]);
     
    348348                Number userID = dbIntegrityService.getUserInternalIDFromRemoteID(remoteUser);
    349349                if (userID != null) {
    350                     if (userID.equals(dbIntegrityService.getAnnotationOwner(annotationID))) {
     350                    if (userID.equals(dbIntegrityService.getAnnotationOwner(annotationID)) || dbIntegrityService.getTypeOfUserAccount(userID).equals(admin)) {
    351351                        int updatedRows = dbIntegrityService.updateAnnotation(annotation);
    352352                        return new ObjectFactory().createResponseBody(makeAnnotationResponseEnvelope(annotationID));
     
    387387            if (userID != null) {
    388388                if (annotationID != null) {
    389                     if (canWrite(userID, annotationID)) {
     389                    if (dbIntegrityService.canWrite(userID, annotationID)) {
    390390                        int updatedRows = dbIntegrityService.updateAnnotationBody(annotationID, annotationBody);
    391391                        return new ObjectFactory().createResponseBody(makeAnnotationResponseEnvelope(annotationID));
     
    428428                        final Number annotationID = dbIntegrityService.getAnnotationInternalIdentifier(UUID.fromString(annotationExternalId));
    429429                        if (annotationID != null) {
    430                             if (userID.equals(dbIntegrityService.getAnnotationOwner(annotationID))) {
     430                            if (remoteUserID.equals(dbIntegrityService.getAnnotationOwner(annotationID)) || dbIntegrityService.getTypeOfUserAccount(remoteUserID).equals(admin)) {
    431431                                int result = (dbIntegrityService.getPermission(annotationID, userID) != null)
    432432                                        ? dbIntegrityService.updateAnnotationPrincipalPermission(annotationID, userID, permission)
     
    480480            if (remoteUserID != null) {
    481481                if (annotationID != null) {
    482                     if (remoteUserID.equals(dbIntegrityService.getAnnotationOwner(annotationID))) {
     482                    if (remoteUserID.equals(dbIntegrityService.getAnnotationOwner(annotationID)) || dbIntegrityService.getTypeOfUserAccount(remoteUserID).equals(admin)) {
    483483                        int updatedRows = dbIntegrityService.updatePermissions(annotationID, permissions);
    484484                        return new ObjectFactory().createResponseBody(makePermissionResponseEnvelope(annotationID));
     
    517517            if (remoteUserID != null) {
    518518                if (annotationID != null) {
    519                     if (remoteUserID.equals(dbIntegrityService.getAnnotationOwner(annotationID))) {
     519                    if (remoteUserID.equals(dbIntegrityService.getAnnotationOwner(annotationID)) || dbIntegrityService.getTypeOfUserAccount(remoteUserID).equals(admin)) {
    520520                        Number userID = dbIntegrityService.getUserInternalIdentifier(UUID.fromString(userId));
    521521                        if (userID != null) {
     
    596596    }
    597597
    598     private boolean canRead(Number userID, Number annotationID) {
    599         if (userID.equals(dbIntegrityService.getAnnotationOwner(annotationID))) {
    600             return true;
    601         }
    602 
    603         final Permission permission = dbIntegrityService.getPermission(annotationID, userID);
    604         if (permission != null) {
    605             return (permission.value().equals(Permission.WRITER.value()) || permission.value().equals(Permission.READER.value()));
    606         } else {
    607             return false;
    608         }
    609     }
    610 
    611     private boolean canWrite(Number userID, Number annotationID) {
    612         if (userID.equals(dbIntegrityService.getAnnotationOwner(annotationID))) {
    613             return true;
    614         }
    615         final Permission permission = dbIntegrityService.getPermission(annotationID, userID);
    616         if (permission != null) {
    617             return (permission.value().equals(Permission.WRITER.value()));
    618         } else {
    619             return false;
    620         }
    621     }
    622 
    623     private String[] makeAccessModeChain(String accessMode) {
    624         if (accessMode != null) {
    625             if (accessMode.equals(Permission.READER.value())) {
    626                 String[] result = new String[1];
    627                 result[0] = Permission.READER.value();
    628                 return result;
    629             } else {
    630                 if (accessMode.equals(Permission.WRITER.value())) {
    631                     String[] result = new String[2];
    632                     result[0] = Permission.READER.value();
    633                     result[1] = Permission.WRITER.value();
    634                     return result;
    635                 } else {
    636                     logger.error("Invalide access " + accessMode);
    637                     return null;
    638                 }
    639 
    640             }
    641 
    642         } else {
    643             return null;
    644         }
    645     }
    646598}
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/webapp/index.jsp

    r4407 r4491  
    4949        GET <a href="api/users/00000000-0000-0000-0000-0000000000112">api/users/00000000-0000-0000-0000-0000000000112</a> <br>
    5050        GET <a href="api/users/00000000-0000-0000-0000-0000000000112/current">api/users/00000000-0000-0000-0000-0000000000112/current</a>  !Problem: how to ask the servlet if the given user is logged in, may be by some other running somewhere client<br>
    51         GET <a href="api/users/info?email=twagoo@mpi.nl">api/users/info?email=twagoo@mpi.nl</a>  <br>
     51        GET <a href="api/users/info?email=Twan.Goosen@mpi.nl">api/users/info?email=Twan.Goosen@mpi.nl</a>  <br>
    5252        GET <a href="api/annotations?link=Sagrada">api/annotations/info?link=Sagrada</a>  <br>
    5353        GET <a href="api/annotations?link=Gaud">api/annotations/info?link=Gaud</a>  <br>
    54         GET <a href="api/annotations?after=2014-01-28 15:57:58.046908&before=2014-01-30 10:08:16.213186">api/annotations?after=2014-01-28 15:57:58.046908&before=2014-01-30 10:08:16.213186</a> <br>
     54        GET <a href="api/annotations?after=2014-02-04 15:57:58.046908&before=2014-02-06 10:08:16.213186">api/annotations?after=2014-02-04 15:57:58.046908&before=2014-02-06 10:08:16.213186</a> <br>
    5555        !Comment: What is "namespace" query parameter? Must be implemented and tested <br>
    5656        GET <a href="api/annotations/00000000-0000-0000-0000-000000000021">api/annotations/00000000-0000-0000-0000-000000000021</a>  </br>
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/test/java/eu/dasish/annotation/backend/dao/impl/DBIntegrityServiceTest.java

    r4464 r4491  
    278278        final List<Number> mockAnnotationIDs1 = new ArrayList<Number>();
    279279        mockAnnotationIDs1.add(1);
    280         mockAnnotationIDs1.add(2);
    281280       
    282281        final List<Number> mockAnnotationIDs2 = new ArrayList<Number>();
     
    290289        mockRetval.add(1);
    291290       
    292         final String[] accessModes = new String[2];
    293         accessModes[0] = "reader";
    294         accessModes[1] = "writer";
    295 
     291       
    296292        mockeryDao.checking(new Expectations() {
    297293            {
    298294                oneOf(targetDao).getTargetsReferringTo("nl.wikipedia.org");
    299295                will(returnValue(mockTargetIDs));
    300 
    301                 oneOf(annotationDao).getAnnotationIDsForUserWithPermission(3, accessModes);
     296               
     297                oneOf(annotationDao).getAnnotationIDsForTargets(mockTargetIDs);
     298                will(returnValue(mockAnnotationIDs2));               
     299               
     300                oneOf(annotationDao).getFilteredAnnotationIDs(null, "some html 1", null, after, before);
    302301                will(returnValue(mockAnnotationIDs1));
    303302
    304                
    305                 oneOf(annotationDao).retrieveAnnotationList(mockTargetIDs);
    306                 will(returnValue(mockAnnotationIDs2));
    307 
    308                
    309                 oneOf(annotationDao).getFilteredAnnotationIDs(mockAnnotationIDs1, null, "some html 1", null, after, before);
    310                 will(returnValue(mockRetval));
    311 
    312             }
    313         });
    314 
    315 
    316         List result = dbIntegrityService.getFilteredAnnotationIDs(null, "nl.wikipedia.org", "some html 1", 3, accessModes, null, after, before);
     303                oneOf(annotationDao).getAnnotationIDsForUserWithPermission(3, "reader");
     304                will(returnValue(mockAnnotationIDs1));
     305
     306               
     307
     308            }
     309        });
     310
     311
     312        List result = dbIntegrityService.getFilteredAnnotationIDs(null, "nl.wikipedia.org", "some html 1", 3, "reader", null, after, before);
    317313        assertEquals(1, result.size());
    318314        assertEquals(1, result.get(0));
     
    368364        final List<Number> mockAnnotationIDs1 = new ArrayList<Number>();
    369365        mockAnnotationIDs1.add(1);
    370         mockAnnotationIDs1.add(2);
    371366       
    372367        final List<Number> mockAnnotationIDs2 = new ArrayList<Number>();
     
    391386        targetIDs.add(2);
    392387       
    393         final String[] accessModes = new String[2];
    394         accessModes[0] = "reader";
    395         accessModes[1] = "writer";
    396        
    397         mockeryDao.checking(new Expectations() {
    398             {
    399                 oneOf(userDao).getInternalID(ownerUUID);
    400                 will(returnValue(1));
    401                
    402                 oneOf(annotationDao).getAnnotationIDsForUserWithPermission(3, accessModes);
    403                 will(returnValue(mockAnnotationIDs1));
    404              
    405                 // getFilteredAnnotationIds
     388       
     389       
     390        mockeryDao.checking(new Expectations() {
     391            {
     392                oneOf(userDao).getInternalID(ownerUUID);
     393                will(returnValue(1));
     394               
    406395                oneOf(targetDao).getTargetsReferringTo("nl.wikipedia.org");
    407396                will(returnValue(mockTargetIDs));
    408397               
    409                 oneOf(annotationDao).retrieveAnnotationList(mockTargetIDs);
    410                 will(returnValue(mockAnnotationIDs2));
     398                oneOf(annotationDao).getAnnotationIDsForTargets(mockTargetIDs);
     399                will(returnValue(mockAnnotationIDs2));               
    411400               
     401                oneOf(annotationDao).getFilteredAnnotationIDs(1, "some html 1", null, after, before);
     402                will(returnValue(mockAnnotationIDs1));
     403
     404                oneOf(annotationDao).getAnnotationIDsForUserWithPermission(3, "reader");
     405                will(returnValue(mockAnnotationIDs1));
     406
    412407               
    413                 oneOf(annotationDao).getFilteredAnnotationIDs(mockAnnotationIDs1, 1, "some html 1", null, after, before);
    414                 will(returnValue(mockAnnotIDs));
    415                
    416                
    417408//                ///////////////////////////////////
    418409//               
     
    442433       
    443434     
    444         AnnotationInfoList result = dbIntegrityService.getFilteredAnnotationInfos(ownerUUID, "nl.wikipedia.org", "some html 1", 3, accessModes, null, after, before);
     435        AnnotationInfoList result = dbIntegrityService.getFilteredAnnotationInfos(ownerUUID, "nl.wikipedia.org", "some html 1", 3, "reader", null, after, before);
    445436        assertEquals(1, result.getAnnotationInfo().size());
    446437        AnnotationInfo resultAnnotInfo = result.getAnnotationInfo().get(0);
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/test/java/eu/dasish/annotation/backend/dao/impl/JdbcAnnotationDaoTest.java

    r4461 r4491  
    297297        targets.add(1);
    298298        targets.add(2);
    299         List<Number> result = jdbcAnnotationDao.retrieveAnnotationList(targets);
     299        List<Number> result = jdbcAnnotationDao.getAnnotationIDsForTargets(targets);
    300300        assertEquals (2, result.size());
    301301        assertEquals(1, result.get(0));
     
    326326    public void testGetFilteredAnnotationIDs(){
    327327        System.out.println(" test getFilteredAnnotationIDs");
    328        
    329        
    330         //////////////////////////////////////////
    331         // TEST 1
    332         //final String link = "nl.wikipedia.org";
    333         final List<Number> annotationIDs = new ArrayList<Number>();
    334         annotationIDs.add(1);
    335         annotationIDs.add(2);
    336        
    337         List<Number> result_1 = jdbcAnnotationDao.getFilteredAnnotationIDs(annotationIDs, null, null, null, null, null);       
    338         assertEquals(2, result_1.size());
     328       
     329        List<Number> result_1 = jdbcAnnotationDao.getFilteredAnnotationIDs(null, "some html", null, null, null);       
     330        assertEquals(3, result_1.size());
    339331        assertEquals(1, result_1.get(0));
    340332        assertEquals(2, result_1.get(1));
    341        
    342        
    343         List<Number> result_2 = jdbcAnnotationDao.getFilteredAnnotationIDs(annotationIDs, null, "some html", null, null, null);       
    344         assertEquals(2, result_2.size());
    345         assertEquals(1, result_2.get(0));
    346         assertEquals(2, result_2.get(1));
    347        
     333        assertEquals(4, result_1.get(2));
    348334       
    349335             
     
    351337        final String before = (new Timestamp(System.currentTimeMillis())).toString();
    352338 
    353         List<Number> result_4 = jdbcAnnotationDao.getFilteredAnnotationIDs(annotationIDs, 1, "some html", null, after, before);       
    354         assertEquals(1, result_4.size());
    355         assertEquals(1, result_4.get(0));
     339        List<Number> result_2 = jdbcAnnotationDao.getFilteredAnnotationIDs(1, "some html", null, after, before);       
     340        assertEquals(1, result_2.size());
     341        assertEquals(1, result_2.get(0));
    356342       
    357343        final String after_1 = (new Timestamp(System.currentTimeMillis())).toString();// no annotations added after "now"       
    358         List<Number> result_5 = jdbcAnnotationDao.getFilteredAnnotationIDs(annotationIDs, 4, "some html", null, after_1, null);       
    359         assertEquals(0, result_5.size());
     344        List<Number> result_3 = jdbcAnnotationDao.getFilteredAnnotationIDs(4, "some html", null, after_1, null);       
     345        assertEquals(0, result_3.size());
    360346       
    361347       
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/test/java/eu/dasish/annotation/backend/rest/AnnotationResourceTest.java

    r4461 r4491  
    110110                will(returnValue(3));
    111111               
     112                oneOf(mockDbIntegrityService).canRead(3, 2);
     113                will(returnValue(true));
     114               
    112115                oneOf(mockDbIntegrityService).getAnnotationInternalIdentifier(with(any(UUID.class)));               
    113116                will(returnValue(2));
    114                
    115                 oneOf(mockDbIntegrityService).getTypeOfUserAccount(3);
    116                 will(returnValue("developer"));
    117                
    118                 oneOf(mockDbIntegrityService).getAnnotationOwner(2);
    119                 will(returnValue(3)); 
    120117               
    121118                oneOf(mockDbIntegrityService).getAnnotation(2);               
Note: See TracChangeset for help on using the changeset viewer.