Changeset 4546


Ignore:
Timestamp:
02/21/14 18:24:38 (10 years ago)
Author:
olhsha
Message:

refactored.Redundar row mappers are some other methods are thrown away

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

Legend:

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

    r4539 r4546  
    9191     * @return the list of the internal IDs of all the target Targets of "annotationID".
    9292     */
    93     public List<Number> retrieveTargetIDs(Number annotationID);   
     93    //public List<Number> retrieveTargetIDs(Number annotationID);   
    9494   
    9595   
     
    105105   
    106106   
     107   
     108    public List<Number> getAnnotations(Number notebookID);
     109   
     110   
     111    public boolean targetIsInUse(Number targetID);
    107112    /**
    108113     *
     
    112117     * Otherwise return "false".
    113118     */
    114     public boolean annotationIsInUse(Number annotationID);
     119    //public boolean annotationIsInUse(Number annotationID);
    115120   
    116121    /**
     
    212217    public int deleteAnnotationPrincipalPermission(Number annotationID, Number userID);
    213218   
     219    public int deleteAnnotationFromAllNotebooks(Number annotationID);
     220   
    214221    /*
    215222     * HELPERS
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/CachedRepresentationDao.java

    r3916 r4546  
    2020import eu.dasish.annotation.schema.CachedRepresentationInfo;
    2121import java.io.InputStream;
     22import java.util.List;
    2223
    2324/**
     
    4647     */
    4748    public InputStream getCachedRepresentationBlob(Number internalID);
     49   
     50   
     51     /*
     52     * @param targetID
     53     * @return the list of the cached representation's ID-s for the target the internal ID "targetID".
     54     */
     55    public List<Number> getCachedRepresentationsForTarget(Number targetID);
    4856 
    4957    /**
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/DBIntegrityService.java

    r4539 r4546  
    4747
    4848    void setServiceURI(String serviceURI);
    49    
    5049
    5150    /**
    5251     * GETTERS
    5352     */
    54    
    5553    Number getResourceInternalIdentifier(UUID externalID, Resource resource);
    56    
    57     Number getResourceInternalIdentifierFromURI(String uri, Resource resource);   
    58    
     54
     55    Number getResourceInternalIdentifierFromURI(String uri, Resource resource);
     56
    5957    UUID getResourceExternalIdentifier(Number resourceID, Resource resource);
    60    
     58
    6159    String getResourceURI(Number resourceID, Resource resource);
    62    
     60
    6361    UserWithPermissionList getPermissions(Number resourceID, Resource resource);
    64 
    6562
    6663    /**
     
    9996    AnnotationInfoList getFilteredAnnotationInfos(UUID ownerId, String word, String text, Number inloggedUserID, String access, String namespace, String after, String before);
    10097
    101    
    102 
    10398    /**
    10499     *
     
    140135    List<String> getUsersWithNoInfo(Number annotationID);
    141136
    142    
    143137    /**
    144138     *
     
    192186
    193187    /// notebooks ///
    194    
    195    
    196188    NotebookInfoList getNotebooks(Number prinipalID, String permission);
    197    
    198     boolean hasAccess(Number notebookID, Number principalID, Permission permission);   
    199    
     189
     190    boolean hasAccess(Number notebookID, Number principalID, Permission permission);
     191
    200192    ReferenceList getNotebooksOwnedBy(Number principalID);
    201193
     
    203195
    204196    Notebook getNotebook(Number notebookID);
    205    
     197
    206198    Number getNotebookOwner(Number notebookID);
    207199
     
    333325    int deleteUserSafe(Number userID);
    334326
     327    int deleteCachedRepresentation(Number internalID);
     328
    335329    /**
    336330     *
     
    354348    int[] deleteAllCachedRepresentationsOfTarget(Number versionID);
    355349
     350    int deleteTarget(Number internalID);
     351
    356352    /**
    357353     *
     
    365361     */
    366362    int[] deleteAnnotation(Number annotationID);
    367    
     363
    368364    /// notebooks ///
    369365    boolean deleteNotebook(Number notebookID);
    370    
    371    
     366
    372367    //////// HELPERS for resources /////
    373     ResponseBody makeAnnotationResponseEnvelope(Number annotationID);
    374    
    375     ResponseBody makeNotebookResponseEnvelope(Number notebookID);
    376    
    377     ResponseBody makePermissionResponseEnvelope(Number resourceID, Resource resource);
    378 
    379    
     368    ResponseBody makeAnnotationResponseEnvelope(Number annotationID);
     369
     370    ResponseBody makeNotebookResponseEnvelope(Number notebookID);
     371
     372    ResponseBody makePermissionResponseEnvelope(Number resourceID, Resource resource);
    380373}
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/NotebookDao.java

    r4529 r4546  
    5151    List<Number> getNotebookIDsOwnedBy(Number principaID);
    5252   
    53     public List<Number> getPrincipalIDsWithPermission(Number notebookID, Permission permission);
    54    
    55    
    56    
     53   
    5754   
    5855    /**
     
    7269   
    7370   
    74     List<Number> getAnnotations(Number notebookID);
     71   
    7572   
    7673    /**
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/TargetDao.java

    r4281 r4546  
    2828 * @author olhsha
    2929 */
    30 public interface TargetDao extends ResourceDao{
    31    
    32  
    33     /**
     30public interface TargetDao extends ResourceDao {
     31
     32    /**
    3433     * GETTERS
    35      **/
    36    
     34     *
     35     */
    3736    /**
    38      * 
     37     *
    3938     * @param inernalID
    4039     * @return the Target with the intrenal Id "internalID".
    4140     */
    4241    public Target getTarget(Number internalID);
    43    
     42
    4443    /**
    45      * 
     44     *
    4645     * @param targets
    47      * @return the list of TargetInfo objects corresponding to the Targets with the internalIds from the list "Targets".
     46     * @return the list of TargetInfo objects corresponding to the Targets with
     47     * the internalIds from the list "Targets".
    4848     */
    4949    public List<TargetInfo> getTargetInfos(List<Number> targets);
    50    
    51    
     50
    5251    /**
    53      * 
     52     *
    5453     * @param targetID
    55      * @return the list of the cached representation's ID-s for the target Target with the internal ID "TargetID".
    56      */
    57     public List<Number> getCachedRepresentations(Number targetID);
    58    
    59     /**
    60      *
    61      * @param targetID
    62      * @return the list of pairs (cached_representation_id, fragment_descriptor) for the target with the internal ID "targetID".
     54     * @return the list of pairs (cached_representation_id, fragment_descriptor)
     55     * for the target with the internal ID "targetID".
    6356     */
    6457    public Map<Number, String> getCachedRepresentationFragmentPairs(Number targetID);
    65    
     58
    6659    /**
    67      * 
     60     *
    6861     * @param subword
    69      * @return the list of Target ID's which link-fields contain "subword" as a substring.
    70      */
     62     * @return the list of Target ID's which link-fields contain "subword" as a
     63     * substring.
     64     */
    7165    public List<Number> getTargetsReferringTo(String subword);
    72    
    73    /**
    74     *
    75     * @param targetID
    76     * @return The link (uri) to the source to which the target refers
    77     */
     66
     67    /**
     68     *
     69     * @param targetID
     70     * @return The link (uri) to the source to which the target refers
     71     */
    7872    public String getLink(Number targetID);
    79    
    80    /**
    81      * 
     73
     74    /**
     75     *
    8276     * @param link
    8377     * @return the list of Target ID's which link-fields is exactly "link"
    84      */ 
     78     */
    8579    public List<Number> getTargetsForLink(String link);
    86    
     80
     81    boolean cachedIsInUse(Number cachedID);
     82
     83    public List<Number> retrieveTargetIDs(Number annotationID);
     84
    8785    /**
    88      *
    89      * @param targetID
    90      * @return true if "TargetID" occurs in at least one of the joint tables "annotations_target_Targets" and "Targets_versions".
     86     * ADDERS
     87     *
    9188     */
    92     public boolean targetIsInUse(Number targetID);
    93  
    94     /**
    95      * ADDERS
    96      **/
    97    
    98      /**
    99      *
    100      * @param target: the Target-object of the Target to be added to "Target" table.
    101      * @return the internal ID of the just added Target or null if it has not been added.
     89    /**
     90     *
     91     * @param target: the Target-object of the Target to be added to "Target"
     92     * table.
     93     * @return the internal ID of the just added Target or null if it has not
     94     * been added.
    10295     */
    103     public Number addTarget(Target target);   
    104    
     96    public Number addTarget(Target target);
     97
    10598    /**
    106      * 
     99     *
    107100     * @param TargetID
    108101     * @param cachedID
    109      * @return # added rows to the table "Targets_cached_representations". Should be "1" if the pair (TargetID, cachedID) has been added.
    110      * @throws SQLException
     102     * @return # added rows to the table "Targets_cached_representations".
     103     * Should be "1" if the pair (TargetID, cachedID) has been added.
     104     * @throws SQLException
    111105     */
    112     public int addTargetCachedRepresentation(Number TargetID, Number cachedID, String fragmentDescription);
    113    
    114    
    115    
    116    
    117     /**
     106    public int addTargetCachedRepresentation(Number TargetID, Number cachedID, String fragmentDescription);
     107
     108    /**
    118109     * DELETERS
    119      **/
    120    
     110     *
     111     */
    121112    /**
    122      * 
     113     *
    123114     * @param internalId
    124      * @return # deleted rows in "Target" table. Should be "1" if the Target has been deleted.
     115     * @return # deleted rows in "Target" table. Should be "1" if the Target has
     116     * been deleted.
    125117     */
    126118    public int deleteTarget(Number internalID);
    127    
    128    
     119
    129120    /**
    130      * 
     121     *
    131122     * @param TargetID
    132      * @return # deleted rows in the table "Targets_cached_representation" when deleting the pair (TargetID, chachedID)
    133      * @throws SQLException
     123     * @return # deleted rows in the table "Targets_cached_representation" when
     124     * deleting the pair (TargetID, chachedID)
     125     * @throws SQLException
    134126     */
    135     public int deleteTargetCachedRepresentation(Number TargetID, Number chachedID); 
    136    
     127    public int deleteTargetCachedRepresentation(Number TargetID, Number chachedID);
    137128}
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/UserDao.java

    r4276 r4546  
    1818package eu.dasish.annotation.backend.dao;
    1919
     20import eu.dasish.annotation.schema.Permission;
    2021import eu.dasish.annotation.schema.User;
     22import java.util.List;
    2123import java.util.UUID;
    2224
     
    4547     public Number getUserInternalIDFromRemoteID(String remoteID);
    4648     
     49     public List<Number> getPrincipalIDsWithPermissionForNotebook(Number notebookID, Permission permission);
     50     
    4751     public boolean updateAccount(UUID externalID, String account);
    4852     
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/impl/DBIntegrityServiceImlp.java

    r4539 r4546  
    8080    NotebookDao notebookDao;
    8181    final static protected String admin = "admin";
    82     private static final Logger logger = LoggerFactory.getLogger(AnnotationResource.class);
     82    private static final Logger logger = LoggerFactory.getLogger(DBIntegrityServiceImlp.class);
    8383
    8484    //////////////////////////////////
     
    135135            Annotation result = annotationDao.getAnnotationWithoutTargetsAndPermissions(annotationID);
    136136            result.setOwnerRef(userDao.getURIFromInternalID(annotationDao.getOwner(annotationID)));
    137             List<Number> targetIDs = annotationDao.retrieveTargetIDs(annotationID);
     137            List<Number> targetIDs = targetDao.retrieveTargetIDs(annotationID);
    138138            TargetInfoList sis = new TargetInfoList();
    139139            for (Number targetID : targetIDs) {
     
    235235    public ReferenceList getAnnotationTargets(Number annotationID) {
    236236        ReferenceList result = new ReferenceList();
    237         List<Number> targetIDs = annotationDao.retrieveTargetIDs(annotationID);
     237        List<Number> targetIDs = targetDao.retrieveTargetIDs(annotationID);
    238238        for (Number targetID : targetIDs) {
    239239            result.getRef().add(targetDao.getURIFromInternalID(targetID));
     
    248248        }
    249249        List<String> result = new ArrayList<String>();
    250         List<Number> targetIDs = annotationDao.retrieveTargetIDs(annotationID);
     250        List<Number> targetIDs = targetDao.retrieveTargetIDs(annotationID);
    251251        for (Number targetID : targetIDs) {
    252             List<Number> versions = targetDao.getCachedRepresentations(targetID);
     252            List<Number> versions = cachedRepresentationDao.getCachedRepresentationsForTarget(targetID);
    253253            if (versions == null) {
    254254                result.add(targetDao.getURIFromInternalID(targetID));
     
    293293                annotationInfo.setOwnerRef(userDao.getURIFromInternalID(annotationDao.getOwner(annotationID)));
    294294                result.getAnnotationInfo().add(annotationInfo);
    295 
    296295            }
    297296
     
    421420        }
    422421    }
     422   
     423    ////// noetbooks ///////
    423424
    424425    @Override
     
    472473    public ReferenceList getPrincipals(Number notebookID, String permission) {
    473474        ReferenceList result = new ReferenceList();
    474         List<Number> principalIDs = notebookDao.getPrincipalIDsWithPermission(notebookID, Permission.fromValue(permission));
     475        List<Number> principalIDs = userDao.getPrincipalIDsWithPermissionForNotebook(notebookID, Permission.fromValue(permission));
    475476        for (Number principalID : principalIDs) {
    476477            String reference = userDao.getURIFromInternalID(principalID);
     
    487488
    488489        ReferenceList annotations = new ReferenceList();
    489         List<Number> annotationIDs = notebookDao.getAnnotations(notebookID);
     490        List<Number> annotationIDs = annotationDao.getAnnotations(notebookID);
    490491        for (Number annotationID : annotationIDs) {
    491492            annotations.getRef().add(annotationDao.getURIFromInternalID(annotationID));
     
    498499        permissions.add(Permission.WRITER);
    499500        for (Permission permission : permissions) {
    500             List<Number> users = notebookDao.getPrincipalIDsWithPermission(notebookID, permission);
     501            List<Number> users = userDao.getPrincipalIDsWithPermissionForNotebook(notebookID, permission);
    501502            if (users != null) {
    502503                for (Number user : users) {
     
    520521    @Override
    521522    public ReferenceList getAnnotationsForNotebook(Number notebookID, int startAnnotation, int maximumAnnotations, String orderedBy, boolean desc) {
    522         List<Number> annotationIDs = notebookDao.getAnnotations(notebookID);
     523        List<Number> annotationIDs = annotationDao.getAnnotations(notebookID);
    523524
    524525        if (startAnnotation < -1) {
     
    697698
    698699    ////////////// DELETERS //////////////////
     700   
     701   
     702   
     703   
    699704    @Override
    700705    public int deleteUser(Number userID) {
     
    702707    }
    703708
    704     ////////////// DELETERS //////////////////
     709   
    705710    @Override
    706711    public int deleteUserSafe(Number userID) {
     
    708713    }
    709714
     715    @Override
     716    public int deleteCachedRepresentation(Number internalID) {
     717       
     718        if (internalID == null) {
     719            logger.debug("Cached's internalID is null");
     720            return 0;
     721        }
     722       
     723        if (targetDao.cachedIsInUse(internalID)) {
     724            logger.debug("Cached Repr. is in use, and cannot be deleted.");
     725            return 0;
     726        }
     727
     728        return cachedRepresentationDao.deleteCachedRepresentation(internalID);
     729    };
     730   
     731   
    710732    @Override
    711733    public int[] deleteCachedRepresentationOfTarget(Number versionID, Number cachedID) {
     
    722744
    723745    @Override
    724     public int[] deleteAllCachedRepresentationsOfTarget(Number TargetID) {
     746    public int[] deleteAllCachedRepresentationsOfTarget(Number targetID) {
    725747        int[] result = new int[2];
    726748        result[0] = 0;
    727749        result[1] = 0;
    728         List<Number> cachedIDs = targetDao.getCachedRepresentations(TargetID);
     750        List<Number> cachedIDs = cachedRepresentationDao.getCachedRepresentationsForTarget(targetID);
    729751        for (Number cachedID : cachedIDs) {
    730             int[] currentResult = this.deleteCachedRepresentationOfTarget(TargetID, cachedID);
     752            int[] currentResult = this.deleteCachedRepresentationOfTarget(targetID, cachedID);
    731753            result[0] = result[0] + currentResult[0];
    732754            result[1] = result[1] + currentResult[1];
     
    737759    @Override
    738760    public int[] deleteAnnotation(Number annotationID) {
    739         int[] result = new int[4];
     761        int[] result = new int[5];
    740762        result[1] = annotationDao.deleteAnnotationPrincipalPermissions(annotationID);
    741         List<Number> targetIDs = annotationDao.retrieveTargetIDs(annotationID);
     763        List<Number> targetIDs = targetDao.retrieveTargetIDs(annotationID);
    742764        result[2] = annotationDao.deleteAllAnnotationTarget(annotationID);
    743         result[0] = annotationDao.deleteAnnotation(annotationID);
    744765        result[3] = 0;
    745766        if (targetIDs != null) {
    746767            for (Number targetID : targetIDs) {
    747768                this.deleteAllCachedRepresentationsOfTarget(targetID);
    748                 result[3] = result[3] + targetDao.deleteTarget(targetID);
    749 
    750             }
    751         }
    752         return result;
     769                result[3] = result[3] + this.deleteTarget(targetID);
     770
     771            }
     772        }
     773       
     774        result[4] = annotationDao.deleteAnnotationFromAllNotebooks(annotationID);
     775       
     776        result[0] = annotationDao.deleteAnnotation(annotationID);
     777        return result;
     778    }
     779   
     780    ////////////////////// DELETERS ////////////////////////
     781    @Override
     782    public int deleteTarget(Number internalID) {
     783        if (internalID == null) {
     784            logger.debug("internalID of the target is null.");
     785            return 0;
     786        }
     787       
     788        if (annotationDao.targetIsInUse(internalID)) {
     789            logger.debug("The target is in use, and cannot be deleted.");
     790            return 0;
     791        }
     792       
     793        return targetDao.deleteTarget(internalID);
     794
    753795    }
    754796
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/impl/JdbcAnnotationDao.java

    r4539 r4546  
    2626import eu.dasish.annotation.schema.AnnotationInfo;
    2727import eu.dasish.annotation.schema.Permission;
    28 import eu.dasish.annotation.schema.UserWithPermission;
    29 import eu.dasish.annotation.schema.UserWithPermissionList;
    3028import java.lang.String;
    3129import java.sql.ResultSet;
     
    6462
    6563    ///////////// GETTERS /////////////
    66     @Override
    67     public List<Number> retrieveTargetIDs(Number annotationID) {
    68         if (annotationID != null) {
    69             StringBuilder sql = new StringBuilder("SELECT DISTINCT ");
    70             sql.append(target_id).append(" FROM ").append(annotationsTargetsTableName).append(" WHERE ").append(annotation_id).append("= ?");
    71             return getSimpleJdbcTemplate().query(sql.toString(), targetIDRowMapper, annotationID);
    72         } else {
    73             loggerAnnotationDao.debug(nullArgument);
    74             return null;
    75         }
    76     }
     64   
    7765
    7866    ///////////////////////////////////////////////////////////////////
     
    341329
    342330    /////////////////////////////
    343     @Override
    344     public boolean annotationIsInUse(Number annotationID) {
    345         StringBuilder sqlNotebooks = new StringBuilder("SELECT ");
    346         sqlNotebooks.append(notebook_id).append(" FROM ").append(notebooksAnnotationsTableName).append(" WHERE ").append(annotation_id).append("= ? LIMIT 1");
    347         List<Number> resultNotebooks = getSimpleJdbcTemplate().query(sqlNotebooks.toString(), notebookIDRowMapper, annotationID);
    348         if (resultNotebooks.size() > 0) {
    349             return true;
    350         }
    351 
    352         StringBuilder sqlTargets = new StringBuilder("SELECT ");
    353         sqlTargets.append(target_id).append(" FROM ").append(annotationsTargetsTableName).append(" WHERE ").append(annotation_id).append("= ? LIMIT 1");
    354         List<Number> resultTargets = getSimpleJdbcTemplate().query(sqlTargets.toString(), targetIDRowMapper, annotationID);
    355         if (resultTargets.size() > 0) {
    356             return true;
    357         }
    358 
    359         StringBuilder sqlPermissions = new StringBuilder("SELECT ");
    360         sqlPermissions.append(principal_id).append(" FROM ").append(permissionsTableName).append(" WHERE ").append(annotation_id).append("= ? LIMIT 1");
    361         List<Number> resultPermissions = getSimpleJdbcTemplate().query(sqlPermissions.toString(), principalIDRowMapper, annotationID);
    362         return (resultPermissions.size() > 0);
    363     }
     331//    @Override
     332//    public boolean annotationIsInUse(Number annotationID) {
     333//        StringBuilder sqlNotebooks = new StringBuilder("SELECT ");
     334//        sqlNotebooks.append(notebook_id).append(" FROM ").append(notebooksAnnotationsTableName).append(" WHERE ").append(annotation_id).append("= ? LIMIT 1");
     335//        List<Number> resultNotebooks = getSimpleJdbcTemplate().query(sqlNotebooks.toString(), notebookIDRowMapper, annotationID);
     336//        if (resultNotebooks.size() > 0) {
     337//            return true;
     338//        }
     339//
     340//        StringBuilder sqlTargets = new StringBuilder("SELECT ");
     341//        sqlTargets.append(target_id).append(" FROM ").append(annotationsTargetsTableName).append(" WHERE ").append(annotation_id).append("= ? LIMIT 1");
     342//        List<Number> resultTargets = getSimpleJdbcTemplate().query(sqlTargets.toString(), targetIDRowMapper, annotationID);
     343//        if (resultTargets.size() > 0) {
     344//            return true;
     345//        }
     346//
     347//        StringBuilder sqlPermissions = new StringBuilder("SELECT ");
     348//        sqlPermissions.append(principal_id).append(" FROM ").append(permissionsTableName).append(" WHERE ").append(annotation_id).append("= ? LIMIT 1");
     349//        List<Number> resultPermissions = getSimpleJdbcTemplate().query(sqlPermissions.toString(), principalIDRowMapper, annotationID);
     350//        return (resultPermissions.size() > 0);
     351//    }
     352   
     353     @Override
     354    public List<Number> getAnnotations(Number notebookID) {
     355
     356        if (notebookID == null) {
     357            loggerAnnotationDao.debug("notebookID: " + nullArgument);
     358            return null;
     359        }
     360
     361        StringBuilder sql = new StringBuilder("SELECT ");
     362        sql.append(annotation_id).
     363                append(" FROM ").append(notebooksAnnotationsTableName).append(" WHERE ").
     364                append(notebook_id).append(" = :notebookID");
     365        return getSimpleJdbcTemplate().query(sql.toString(), internalIDRowMapper, notebookID);
     366
     367    }
     368     
     369       /////////////////////////////////////////////////
     370    @Override
     371    public boolean targetIsInUse(Number targetID) {
     372        if (targetID == null) {
     373            loggerAnnotationDao.debug("targetID: " + nullArgument);
     374            return false;
     375        }
     376
     377
     378        StringBuilder sqlAnnotations = new StringBuilder("SELECT ");
     379        sqlAnnotations.append(annotation_id).append(" FROM ").append(annotationsTargetsTableName).append(" WHERE ").append(target_id).append(" = ? LIMIT 1");
     380        List<Number> resultAnnotations = getSimpleJdbcTemplate().query(sqlAnnotations.toString(), internalIDRowMapper, targetID);
     381        if (resultAnnotations == null) {
     382            return false;
     383        }
     384        return (resultAnnotations.size() > 0);
     385    }
     386   
     387
    364388
    365389    //////////// UPDATERS /////////////
     
    542566    public int deleteAnnotation(Number annotationID) {
    543567        if (annotationID != null) {
    544             if (annotationIsInUse(annotationID)) {
    545                 return 0;
    546             }
    547568            StringBuilder sqlAnnotation = new StringBuilder("DELETE FROM ");
    548569            sqlAnnotation.append(annotationTableName).append(" where ").append(annotation_id).append(" = ?");
     
    578599        }
    579600
     601    }
     602   
     603    ////////////////////////////////////////
     604    @Override
     605    public int deleteAnnotationFromAllNotebooks(Number annotationID){
     606        if (annotationID != null) {
     607            StringBuilder sql = new StringBuilder("DELETE FROM ");
     608            sql.append(notebooksAnnotationsTableName).append(" WHERE ").append(annotation_id).append(" = ?");
     609            return getSimpleJdbcTemplate().update(sql.toString(), annotationID); // removed "notebook-annotation" rows
     610        } else {
     611            loggerAnnotationDao.debug("annotationID: " + nullArgument);
     612            return 0;
     613        }
    580614    }
    581615
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/impl/JdbcCachedRepresentationDao.java

    r4495 r4546  
    109109    };
    110110
    111     //////////////////////////////////////
    112     private boolean cachedIsInUse(Number cachedID) {
    113        
    114         if (cachedID == null) {
    115             loggerCachedDao.debug("cachedID: " + nullArgument);
    116             return false;
     111   
     112   
     113       /////////////////////////////////////////
     114    @Override
     115    public List<Number> getCachedRepresentationsForTarget(Number targetID) {
     116
     117        if (targetID == null) {
     118            loggerCachedDao.debug("targetID: " + nullArgument);
     119            return null;
    117120        }
    118        
    119         StringBuilder sql = new StringBuilder("SELECT ");
    120         sql.append(target_id).append(" FROM ").append(targetsCachedRepresentationsTableName).append(" WHERE ").append(cached_representation_id).append("= ? LIMIT 1");
    121         List<Number> result = getSimpleJdbcTemplate().query(sql.toString(), targetIDRowMapper, cachedID);
    122         if (result != null) {
    123             return (!result.isEmpty());
    124         } else {
    125             return false;
    126         }
     121
     122        String sql = "SELECT " + cached_representation_id + " FROM " + targetsCachedRepresentationsTableName + " WHERE " + target_id + " = ?";
     123        return getSimpleJdbcTemplate().query(sql, internalIDRowMapper, targetID);
    127124    }
     125
    128126
    129127    //////////////////////// ADDERS ///////////////////////////////
     
    158156            return 0;
    159157        }
    160        
    161         if (cachedIsInUse(internalID)) {
    162             loggerCachedDao.debug("Cached Repr. is in use, and cannot be deleted.");
    163             return 0;
    164         }
    165 
     158               
    166159        StringBuilder sql = new StringBuilder("DELETE FROM ");
    167160        sql.append(cachedRepresentationTableName).append(" WHERE ").append(cached_representation_id).append(" = ?");
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/impl/JdbcNotebookDao.java

    r4539 r4546  
    120120    }
    121121
    122     @Override
    123     public List<Number> getPrincipalIDsWithPermission(Number notebookID, Permission permission) {
    124         if (notebookID == null) {
    125             loggerNotebookDao.debug("notebookID: " + nullArgument);
    126             return null;
    127         }
    128 
    129         if (permission == null) {
    130             loggerNotebookDao.debug("permission: " + nullArgument);
    131             return null;
    132         }
    133         Map<String, Object> params = new HashMap<String, Object>();
    134         params.put("notebookID", notebookID);
    135         params.put("accessMode", permission.value());
    136 
    137         StringBuilder sql = new StringBuilder("SELECT ");
    138         sql.append(principal_id).append(" FROM ").append(notebookPermissionsTableName).append(" WHERE ").
    139                 append(notebook_id).append(" = :notebookID AND ").append(this.permission).append(" = :accessMode");
    140 
    141         return getSimpleJdbcTemplate().query(sql.toString(), principalIDRowMapper, params);
    142 
    143     }
     122   
    144123
    145124    @Override
     
    191170    };
    192171
    193     @Override
    194     public List<Number> getAnnotations(Number notebookID) {
    195 
    196         if (notebookID == null) {
    197             loggerNotebookDao.debug("notebookID: " + nullArgument);
    198             return null;
    199         }
    200 
    201         StringBuilder sql = new StringBuilder("SELECT ");
    202         sql.append(annotation_id).
    203                 append(" FROM ").append(notebooksAnnotationsTableName).append(" WHERE ").
    204                 append(notebook_id).append(" = :notebookID");
    205         return getSimpleJdbcTemplate().query(sql.toString(), annotationIDRowMapper, notebookID);
    206 
    207     }
    208 
     172   
    209173    /**
    210174     *
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/impl/JdbcResourceDao.java

    r4539 r4546  
    178178    };
    179179////////////////// ROW MAPPERS ///////////////////
     180   
     181 
    180182    protected final RowMapper<Number> internalIDRowMapper = new RowMapper<Number>() {
    181183        @Override
     
    192194        }
    193195    };
    194     protected final RowMapper<Number> cachedIDRowMapper = new RowMapper<Number>() {
    195         @Override
    196         public Number mapRow(ResultSet rs, int rowNumber) throws SQLException {
    197             return rs.getInt(cached_representation_id);
    198         }
    199     };
    200     protected final RowMapper<Number> targetIDRowMapper = new RowMapper<Number>() {
    201         @Override
    202         public Number mapRow(ResultSet rs, int rowNumber) throws SQLException {
    203             return rs.getInt(target_id);
    204         }
    205     };
    206     protected final RowMapper<Number> annotationIDRowMapper = new RowMapper<Number>() {
    207         @Override
    208         public Number mapRow(ResultSet rs, int rowNumber) throws SQLException {
    209             return rs.getInt(annotation_id);
    210         }
    211     };
    212     protected final RowMapper<Number> notebookIDRowMapper = new RowMapper<Number>() {
    213         @Override
    214         public Number mapRow(ResultSet rs, int rowNumber) throws SQLException {
    215             return rs.getInt(notebook_id);
    216         }
    217     };
    218     protected final RowMapper<Number> principalIDRowMapper = new RowMapper<Number>() {
    219         @Override
    220         public Number mapRow(ResultSet rs, int rowNumber) throws SQLException {
    221             return rs.getInt(principal_id);
    222         }
    223     };
     196   
     197
     198//    protected final RowMapper<Number> principalIDRowMapper = new RowMapper<Number>() {
     199//        @Override
     200//        public Number mapRow(ResultSet rs, int rowNumber) throws SQLException {
     201//            return rs.getInt(principal_id);
     202//        }
     203//    };
    224204    protected final RowMapper<Number> ownerIDRowMapper = new RowMapper<Number>() {
    225205        @Override
     
    239219   
    240220    ////// END ROW MAPPERS /////
     221   
     222   
    241223    @Override
    242224    public String externalIDtoURI(String externalID) {
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/impl/JdbcTargetDao.java

    r4506 r4546  
    9898    };
    9999
    100     /////////////////////////////////////////
    101     @Override
    102     public List<Number> getCachedRepresentations(Number targetID) {
    103 
    104         if (targetID == null) {
    105             loggerTargetDao.debug("targetID: " + nullArgument);
    106             return null;
    107         }
    108 
    109         String sql = "SELECT " + cached_representation_id + " FROM " + targetsCachedRepresentationsTableName + " WHERE " + target_id + " = ?";
    110         return getSimpleJdbcTemplate().query(sql, cachedIDRowMapper, targetID);
    111     }
    112 
     100 
    113101    @Override
    114102    public Map<Number, String> getCachedRepresentationFragmentPairs(Number targetID) {
     
    187175    }
    188176
    189     /////////////////////////////////////////////////
    190     @Override
    191     public boolean targetIsInUse(Number targetID) {
    192         if (targetID == null) {
    193             loggerTargetDao.debug("targetID: " + nullArgument);
     177 
     178   
     179   
     180     //////////////////////////////////////
     181    @Override
     182    public boolean cachedIsInUse(Number cachedID) {
     183       
     184        if (cachedID == null) {
     185            logger.debug("Cached's Id is null");
    194186            return false;
    195187        }
    196 
    197 
    198         StringBuilder sqlAnnotations = new StringBuilder("SELECT ");
    199         sqlAnnotations.append(annotation_id).append(" FROM ").append(annotationsTargetsTableName).append(" WHERE ").append(target_id).append(" = ? LIMIT 1");
    200         List<Number> resultAnnotations = getSimpleJdbcTemplate().query(sqlAnnotations.toString(), annotationIDRowMapper, targetID);
    201         if (resultAnnotations == null) {
     188       
     189        StringBuilder sql = new StringBuilder("SELECT ");
     190        sql.append(target_id).append(" FROM ").append(targetsCachedRepresentationsTableName).append(" WHERE ").append(cached_representation_id).append("= ? LIMIT 1");
     191        List<Number> result = getSimpleJdbcTemplate().query(sql.toString(), internalIDRowMapper, cachedID);
     192        if (result != null) {
     193            return (!result.isEmpty());
     194        } else {
    202195            return false;
    203196        }
    204         return (resultAnnotations.size() > 0);
     197    }
     198   
     199   
     200    @Override
     201    public List<Number> retrieveTargetIDs(Number annotationID) {
     202        if (annotationID != null) {
     203            StringBuilder sql = new StringBuilder("SELECT DISTINCT ");
     204            sql.append(target_id).append(" FROM ").append(annotationsTargetsTableName).append(" WHERE ").append(annotation_id).append("= ?");
     205            return getSimpleJdbcTemplate().query(sql.toString(), internalIDRowMapper, annotationID);
     206        } else {
     207            loggerTargetDao.debug(nullArgument);
     208            return null;
     209        }
    205210    }
    206211
     
    249254    }
    250255
    251    
    252 
    253 ////////////////////// DELETERS ////////////////////////
    254     @Override
     256  ///////////////////////////////////
     257   @Override
    255258    public int deleteTarget(Number internalID) {
    256259        if (internalID == null) {
    257             loggerTargetDao.debug("internalID: " + nullArgument);
    258             return 0;
    259         }
    260        
    261         if (targetIsInUse(internalID)) {
    262             loggerTargetDao.debug("The target is in use, and cannot be deleted.");
    263             return 0;
    264         }
     260            logger.debug("internalID of the target is null.");
     261            return 0;
     262        }
     263       
     264     
    265265        StringBuilder sqlTargetsVersions = new StringBuilder("DELETE FROM ");
    266266        sqlTargetsVersions.append(targetTableName).append(" WHERE ").append(target_id).append(" = ? ");
     
    268268
    269269    }
     270
    270271
    271272    ///////////////////////////////////////////////////////////////////
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/impl/JdbcUserDao.java

    r4495 r4546  
    1919
    2020import eu.dasish.annotation.backend.dao.UserDao;
     21import eu.dasish.annotation.schema.Permission;
    2122import eu.dasish.annotation.schema.User;
    2223import java.sql.ResultSet;
     
    9394        StringBuilder sqlPermissions = new StringBuilder("SELECT ");
    9495        sqlPermissions.append(principal_id).append(" FROM ").append(permissionsTableName).append(" WHERE ").append(principal_id).append("= ? LIMIT 1");
    95         List<Number> resultTargets = getSimpleJdbcTemplate().query(sqlPermissions.toString(), principalIDRowMapper, userID);
     96        List<Number> resultTargets = getSimpleJdbcTemplate().query(sqlPermissions.toString(), internalIDRowMapper, userID);
    9697        if (resultTargets.size() > 0) {
    9798            return true;
     
    117118        StringBuilder sqlTargets = new StringBuilder("SELECT ");
    118119        sqlTargets.append(principal_id).append(" FROM ").append(principalTableName).append(" WHERE ").append("LOWER(").append(e_mail).append(")= ? LIMIT 1");
    119         List<Number> resultTargets = getSimpleJdbcTemplate().query(sqlTargets.toString(), principalIDRowMapper, emailCriterion);
     120        List<Number> resultTargets = getSimpleJdbcTemplate().query(sqlTargets.toString(), internalIDRowMapper, emailCriterion);
    120121        if (resultTargets.size() > 0) {
    121122            return true;
     
    178179        }
    179180    };
     181   
     182   
     183    @Override
     184    public List<Number> getPrincipalIDsWithPermissionForNotebook(Number notebookID, Permission permission) {
     185        if (notebookID == null) {
     186            loggerUserDao.debug("notebookID: " + nullArgument);
     187            return null;
     188        }
     189
     190        if (permission == null) {
     191            loggerUserDao.debug("permission: " + nullArgument);
     192            return null;
     193        }
     194        Map<String, Object> params = new HashMap<String, Object>();
     195        params.put("notebookID", notebookID);
     196        params.put("accessMode", permission.value());
     197
     198        StringBuilder sql = new StringBuilder("SELECT ");
     199        sql.append(principal_id).append(" FROM ").append(notebookPermissionsTableName).append(" WHERE ").
     200                append(notebook_id).append(" = :notebookID AND ").append(this.permission).append(" = :accessMode");
     201
     202        return getSimpleJdbcTemplate().query(sql.toString(), internalIDRowMapper, params);
     203
     204    }
    180205
    181206    ///////////////////// ADDERS ////////////////////////////
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/test/java/eu/dasish/annotation/backend/dao/impl/DBIntegrityServiceTest.java

    r4539 r4546  
    228228                will(returnValue(uri1));
    229229
    230                 oneOf(annotationDao).retrieveTargetIDs(1);
     230                oneOf(targetDao).retrieveTargetIDs(1);
    231231                will(returnValue(mockTargetIDs));
    232232
     
    330330        mockeryDao.checking(new Expectations() {
    331331            {
    332                 oneOf(annotationDao).retrieveTargetIDs(1);
     332                oneOf(targetDao).retrieveTargetIDs(1);
    333333                will(returnValue(TargetIDs));
    334334
     
    422422
    423423                ////
    424                 oneOf(annotationDao).retrieveTargetIDs(1);
     424                oneOf(targetDao).retrieveTargetIDs(1);
    425425                will(returnValue(targetIDs));
    426426
     
    464464        mockeryDao.checking(new Expectations() {
    465465            {
    466                 oneOf(annotationDao).retrieveTargetIDs(3);
     466                oneOf(targetDao).retrieveTargetIDs(3);
    467467                will(returnValue(targetIDs));
    468468
    469                 oneOf(targetDao).getCachedRepresentations(5);
     469                oneOf(cachedRepresentationDao).getCachedRepresentationsForTarget(5);
    470470                will(returnValue(cachedIDs5));
    471471
    472                 oneOf(targetDao).getCachedRepresentations(7);
     472                oneOf(cachedRepresentationDao).getCachedRepresentationsForTarget(7);
    473473                will(returnValue(cachedIDs7));
    474474
     
    724724        mockeryDao.checking(new Expectations() {
    725725            {
    726                 oneOf(targetDao).getCachedRepresentations(1);
     726                oneOf(cachedRepresentationDao).getCachedRepresentationsForTarget(1);
    727727                will(returnValue(cachedList));
    728728
     
    767767                will(returnValue(2));
    768768
    769                 oneOf(annotationDao).retrieveTargetIDs(2);
     769                oneOf(targetDao).retrieveTargetIDs(2);
    770770                will(returnValue(mockTargetIDs));
    771771
     
    776776                will(returnValue(1));
    777777
    778                 oneOf(targetDao).getCachedRepresentations(2);
     778                oneOf(cachedRepresentationDao).getCachedRepresentationsForTarget(2);
    779779                will(returnValue(mockCachedIDs));
    780780
     
    784784                oneOf(cachedRepresentationDao).deleteCachedRepresentation(3);
    785785                will(returnValue(1));
     786               
     787                oneOf(annotationDao).targetIsInUse(2);
     788                will(returnValue(true));
    786789
    787790                oneOf(targetDao).deleteTarget(2);
    788                 will(returnValue(1));
    789 
    790 
     791                will(returnValue(0));
     792
     793                oneOf(annotationDao).deleteAnnotationFromAllNotebooks(2);
     794                will(returnValue(1));
     795               
     796               
    791797            }
    792798        });
    793799        int[] result = dbIntegrityService.deleteAnnotation(2);// the Target will be deleted because it is not referred by any annotation
    794         assertEquals(4, result.length);
     800        assertEquals(5, result.length);
    795801        assertEquals(1, result[0]); // annotation 3 is deleted
    796802        assertEquals(2, result[1]); // 2 rows in "annotation principal permissions are deleted"
    797803        assertEquals(1, result[2]);  // row (3,2) in "annotations_Targets" is deleted
    798         assertEquals(1, result[3]); //  Target 3 is deleted
    799     }
    800 //    @Test
    801 //    public void testCreateTarget(){ 
    802 //        NewTargetInfo newTargetInfo = new NewTargetInfo();
    803 //        newTargetInfo.setLink(TestBackendConstants._TEST_NEW_Target_LINK);
    804 //        newTargetInfo.setVersion(null);
    805 //       
    806 //        Target result = dbIntegrityService.createTarget(newTargetInfo);
    807 //        assertEquals(TestBackendConstants._TEST_NEW_Target_LINK, result.getLink());
    808 //        assertFalse(null == result.getURI());
    809 //       
    810 //    }
    811 //   
    812 //    @Test
    813 //    public void testCreateVersion(){ 
    814 //        NewTargetInfo newTargetInfo = new NewTargetInfo();
    815 //        newTargetInfo.setLink(TestBackendConstants._TEST_NEW_Target_LINK);
    816 //        newTargetInfo.setVersion(null);
    817 //       
    818 //        Version result = dbIntegrityService.createVersion(newTargetInfo);
    819 //        assertFalse(null == result.getVersion()); // will be chnaged once the schema for version is fixed: ID is added
    820 //       
    821 //    }
     804        assertEquals(0, result[3]); //  target 2 is not deleted deleted since it is used by annotation 1
     805        assertEquals(1, result[4]); // deleted from 1 notebook
     806    }
     807
    822808
    823809    /**
     
    10381024        mockeryDao.checking(new Expectations() {
    10391025            {
    1040                 oneOf(notebookDao).getPrincipalIDsWithPermission(1, Permission.WRITER);
     1026                oneOf(userDao).getPrincipalIDsWithPermissionForNotebook(1, Permission.WRITER);
    10411027                will(returnValue(mockPrincipalIDs));
    10421028
     
    11191105                will(returnValue("serviceURI/users/00000000-0000-0000-0000-000000000112"));
    11201106
    1121                 oneOf(notebookDao).getAnnotations(2);
     1107                oneOf(annotationDao).getAnnotations(2);
    11221108                will(returnValue(mockAnnotations));
    11231109               
     
    11251111                will(returnValue("serviceURI/annotations/00000000-0000-0000-0000-000000000023"));
    11261112               
    1127                 oneOf(notebookDao).getPrincipalIDsWithPermission(2, Permission.READER);
     1113                oneOf(userDao).getPrincipalIDsWithPermissionForNotebook(2, Permission.READER);
    11281114                will(returnValue(mockReaders));
    11291115               
     
    11311117                will(returnValue("serviceURI/users/00000000-0000-0000-0000-000000000111"));
    11321118               
    1133                 oneOf(notebookDao).getPrincipalIDsWithPermission(2, Permission.WRITER);
     1119                oneOf(userDao).getPrincipalIDsWithPermissionForNotebook(2, Permission.WRITER);
    11341120                will(returnValue(mockWriters));
    11351121               
     
    11571143    }
    11581144
    1159 //    public List<UUID> getAnnotationsForNotebook(Number notebookID, int startAnnotation, int maximumAnnotations, String orderedBy, boolean desc) {
    1160 //        List<Number> annotationIDs = notebookDao.getAnnotations(notebookID);
    1161 //
    1162 //        if (startAnnotation < -1) {
    1163 //            logger.info("Variable's startAnnotation value " + startAnnotation + " is invalid. I will return null.");
    1164 //            return null;
    1165 //        }
    1166 //
    1167 //        if (maximumAnnotations < -1) {
    1168 //            logger.info("Variable's maximumAnnotations value " + maximumAnnotations + " is invalid. I will return null.");
    1169 //            return null;
    1170 //        }
    1171 //
    1172 //        int offset = (startAnnotation > 0) ? startAnnotation - 1 : 0;
    1173 //        String direction = desc ? " DESC " : " ASC ";
    1174 //        List<Number> selectedAnnotIDs = annotationDao.sublistOrderedAnnotationIDs(annotationIDs, offset, maximumAnnotations, orderedBy, direction);
    1175 //        List<UUID> annotationUUIDs = new ArrayList<UUID>();
    1176 //        for (Number annotationID : selectedAnnotIDs) {
    1177 //            annotationUUIDs.add(annotationDao.getExternalID(annotationID));
    1178 //        }
    1179 //        return annotationUUIDs;
    1180 //    }
    11811145    @Test
    11821146    public void testAnnotationsForNotebook() {
     
    11871151        mockeryDao.checking(new Expectations() {
    11881152            {
    1189                 oneOf(notebookDao).getAnnotations(1);
     1153                oneOf(annotationDao).getAnnotations(1);
    11901154                will(returnValue(mockAnnotationIDs));
    11911155
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/test/java/eu/dasish/annotation/backend/dao/impl/JdbcAnnotationDaoTest.java

    r4491 r4546  
    8181     * Test of retrieveTargetIDs method, of class JdbcAnnotationDao.
    8282     */
    83     @Test
    84     public void testRetrieveTargetIDs() {
    85         System.out.println("retrieveTargetIDs");
    86         Number annotationID = 1;
    87         List<Number> result = jdbcAnnotationDao.retrieveTargetIDs(annotationID);
    88         assertEquals(2, result.size());
    89         assertEquals(1, result.get(0));
    90         assertEquals(2, result.get(1));
    91     }
     83 
     84   
     85     /**
     86     * Test of getAnnotations method, of class JdbcNotebookDao.
     87     */
     88    @Test
     89    public void testGetAnnotations() {
     90        System.out.println("test getAnnotations");
     91        List<Number> expResult = new ArrayList<Number>();
     92        expResult.add(1);
     93        expResult.add(2);
     94        List<Number> result = jdbcAnnotationDao.getAnnotations(1);
     95        assertEquals(expResult, result);
     96    }
     97
    9298   
    9399    ///////////////////////////////////////////
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/test/java/eu/dasish/annotation/backend/dao/impl/JdbcCachedRepresentationDaoTest.java

    r4461 r4546  
    2323import java.sql.Blob;
    2424import java.sql.SQLException;
     25import java.util.List;
    2526import java.util.UUID;
    2627import javax.sql.rowset.serial.SerialBlob;
     
    135136    }
    136137
    137     /**
    138      * Test of getCachedRepresentationBlob method, of class
    139      * JdbcCachedRepresentationDao. public CachedRepresentationInfo
    140      * getCachedRepresentationInfo(Number internalID);
    141      */
    142 //    @Test
    143 //    public void testGetCachedRepresentationBlob() throws SQLException, UnsupportedEncodingException {
    144 //        System.out.println("getCachedRepresentationBlob ");
    145 //        Blob result = jdbcCachedRepresentationDao.getCachedRepresentationBlob(1);
    146 //        int lengthBlob = 2;
    147 //        byte[] resultBytes = result.getBytes(1, lengthBlob);
    148 //        assertEquals(TestBackendConstants._TEST_CACHED_REPRESENTATION_1_BLOB_BYTE_1, resultBytes[0]);
    149 //        assertEquals(TestBackendConstants._TEST_CACHED_REPRESENTATION_1_BLOB_BYTE_2, resultBytes[1]);
    150 //    }
     138 
     139   
     140    /* Test of getCachedRepresentationsForTarget method, of class JdbcTargetDao.
     141     */
     142    @Test
     143    public void testGetCachedRepresentations() {
     144        System.out.println("test getCachedRepresentationsForTarget");
     145        Number TargetID = 1;
     146        List<Number> result = jdbcCachedRepresentationDao.getCachedRepresentationsForTarget(TargetID);
     147        assertEquals(1, result.get(0));
     148        assertEquals(2, result.get(1));
     149    }
    151150
    152151    /**
     
    156155     */
    157156    @Test
    158     public void testDeleteCachedRepresentationInfo() {
     157    public void testDeleteCachedRepresentation() {
    159158        System.out.println("deleteCachedRepresentationInfo");
    160159        Number internalID = 6; /// deleted because no version refers to it
     
    162161        assertEquals(1, result);
    163162
    164         int resultTwo = jdbcCachedRepresentationDao.deleteCachedRepresentation(internalID);
    165         assertEquals(0, resultTwo);
    166 
    167         Number internalIDDoNotDelete = 5;
    168         int resultThree = jdbcCachedRepresentationDao.deleteCachedRepresentation(internalIDDoNotDelete);
    169         assertEquals(0, resultThree);
    170163    }
    171164
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/test/java/eu/dasish/annotation/backend/dao/impl/JdbcNotebookDaoTest.java

    r4506 r4546  
    7979    }
    8080
    81     /**
    82      * Test of getPrincipalIDsWithPermission method, of class JdbcNotebookDao.
    83      */
    84     @Test
    85     public void testGetPrincipalIDsWithPermission() {
    86         System.out.println("gtest getPrincipalIDsWithPermission");
    87         List<Number> expResult = new ArrayList<Number>();
    88         expResult.add(2);
    89         expResult.add(4);
    90         List result = jdbcNotebookDao.getPrincipalIDsWithPermission(1, Permission.WRITER);
    91         assertEquals(expResult, result);
    92     }
    93 
     81 
    9482    /**
    9583     * Test of getNotebookInfoWithoutOwner method, of class JdbcNotebookDao.
     
    117105    }
    118106
    119     /**
    120      * Test of getAnnotations method, of class JdbcNotebookDao.
    121      */
    122     @Test
    123     public void testGetAnnotations() {
    124         System.out.println("test getAnnotations");
    125         List<Number> expResult = new ArrayList<Number>();
    126         expResult.add(1);
    127         expResult.add(2);
    128         List<Number> result = jdbcNotebookDao.getAnnotations(1);
    129         assertEquals(expResult, result);
    130     }
    131 
     107   
    132108    /**
    133109     * Test of updateNotebookMetadata method, of class JdbcNotebookDao.
     
    161137        boolean result = jdbcNotebookDao.updateUserPermissionForNotebook(1, 2, Permission.READER);
    162138        assertTrue(result);
    163         assertTrue(jdbcNotebookDao.getPrincipalIDsWithPermission(1, Permission.READER).contains(2));
    164139
    165140        // in the next test the update should fail
     
    193168        boolean result = jdbcNotebookDao.addAnnotationToNotebook(2, 4);
    194169        assertTrue(result);
    195         assertTrue(jdbcNotebookDao.getAnnotations(2).contains(4));
    196170    }
    197171
     
    204178        boolean result = jdbcNotebookDao.addPermissionToNotebook(2, 4, Permission.WRITER);
    205179        assertTrue(result);
    206         assertTrue(jdbcNotebookDao.getPrincipalIDsWithPermission(2, Permission.WRITER).contains(4));
    207180    }
    208181
     
    215188        boolean result = jdbcNotebookDao.deleteAnnotationFromNotebook(1, 2);
    216189        assertTrue(result);
    217         assertFalse(jdbcNotebookDao.getAnnotations(1).contains(2));
    218190    }
    219191
     
    227199        boolean result = jdbcNotebookDao.deleteNotebookPrincipalPermission(1, 2);
    228200        assertTrue(result);
    229         assertFalse(jdbcNotebookDao.getPrincipalIDsWithPermission(1, Permission.READER).contains(2));
    230         assertFalse(jdbcNotebookDao.getPrincipalIDsWithPermission(1, Permission.WRITER).contains(2));
    231201    }
    232202
     
    240210        boolean result = jdbcNotebookDao.deleteAllAnnotationsFromNotebook(1);
    241211        assertTrue(result);
    242         assertTrue(jdbcNotebookDao.getAnnotations(1).isEmpty());
    243212    }
    244213
     
    251220        boolean result = jdbcNotebookDao.deleteAllPermissionsForNotebook(1);
    252221        assertTrue(result);
    253         assertTrue(jdbcNotebookDao.getPrincipalIDsWithPermission(1, Permission.READER).isEmpty());
    254         assertTrue(jdbcNotebookDao.getPrincipalIDsWithPermission(1, Permission.WRITER).isEmpty());
    255222    }
    256223
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/test/java/eu/dasish/annotation/backend/dao/impl/JdbcTargetDaoTest.java

    r4461 r4546  
    4444    @Autowired
    4545    JdbcTargetDao jdbcTargetDao;
    46    
    47      /**
    48      * Test of stringURItoExternalID method
    49      * public String stringURItoExternalID(String uri);
     46
     47    /**
     48     * Test of stringURItoExternalID method public String
     49     * stringURItoExternalID(String uri);
    5050     */
    5151    @Test
     
    5858        assertEquals(randomUUID, externalID);
    5959    }
    60    
    61     /**
    62      * Test of externalIDtoURI method
    63      * public String externalIDtoURI(String externalID);
     60
     61    /**
     62     * Test of externalIDtoURI method public String externalIDtoURI(String
     63     * externalID);
    6464     */
    6565    @Test
     
    6868        jdbcTargetDao.setServiceURI(TestBackendConstants._TEST_SERVLET_URI_Targets);
    6969        String randomUUID = UUID.randomUUID().toString();
    70         String uri = TestBackendConstants._TEST_SERVLET_URI_Targets+randomUUID;
     70        String uri = TestBackendConstants._TEST_SERVLET_URI_Targets + randomUUID;
    7171        String uriResult = jdbcTargetDao.externalIDtoURI(randomUUID);
    7272        assertEquals(uri, uriResult);
     
    9595        assertEquals(expResult, result);
    9696    }
    97    
    98     /**
    99      * Test of getInternalIDFromURI method,
    100      * public Number getInternalIDFromURI(UUID externalID);
     97
     98    /**
     99     * Test of getInternalIDFromURI method, public Number
     100     * getInternalIDFromURI(UUID externalID);
    101101     */
    102102    @Test
     
    104104        System.out.println("test getInternalIDFromURI");
    105105        jdbcTargetDao.setServiceURI(TestBackendConstants._TEST_SERVLET_URI_Targets);
    106         String uri = TestBackendConstants._TEST_SERVLET_URI_Targets+"00000000-0000-0000-0000-000000000031";
     106        String uri = TestBackendConstants._TEST_SERVLET_URI_Targets + "00000000-0000-0000-0000-000000000031";
    107107        Number result = jdbcTargetDao.getInternalIDFromURI(uri);
    108108        assertEquals(1, result.intValue());
    109109    }
    110    
    111110
    112111    /**
     
    118117        jdbcTargetDao.setServiceURI(TestBackendConstants._TEST_SERVLET_URI_Targets);
    119118        Target result = jdbcTargetDao.getTarget(1);
    120         assertEquals(TestBackendConstants._TEST_SERVLET_URI_Targets+"00000000-0000-0000-0000-000000000031", result.getURI());
    121         assertEquals("http://nl.wikipedia.org/wiki/Sagrada_Fam%C3%ADlia"+"#"+"de_Opdracht", result.getLink());
     119        assertEquals(TestBackendConstants._TEST_SERVLET_URI_Targets + "00000000-0000-0000-0000-000000000031", result.getURI());
     120        assertEquals("http://nl.wikipedia.org/wiki/Sagrada_Fam%C3%ADlia" + "#" + "de_Opdracht", result.getLink());
    122121        assertEquals("version 1.0", result.getVersion());
    123122        // TODO :add time stamp test
    124        
     123
    125124    }
    126125
     
    133132        // test 1
    134133        // remove the rows from the joint table to keep integrity
    135         int result = jdbcTargetDao.deleteTarget(1); //the Target is in use, should not be deleted
    136         assertEquals(0, result);
    137 
    138         // test 2
    139         int resultTwo = jdbcTargetDao.deleteTarget(6);// the Target will be deleted because it is not referred by any annotation
    140         assertEquals(1, resultTwo);
    141     }
    142    
    143  
     134        int result = jdbcTargetDao.deleteTarget(6); //the Target is in use, should not be deleted
     135        assertEquals(1, result);
     136    }
    144137
    145138    /**
     
    147140     */
    148141    @Test
    149     public void testAddTargetCachedRepresentation() throws SQLException{
    150        System.out.println("test addTargetCachedRepresentation");
    151        assertEquals(1, jdbcTargetDao.addTargetCachedRepresentation(6, 7, "#firstrow"));
    152        // content test
    153        Map<Number, String> pairs = jdbcTargetDao.getCachedRepresentationFragmentPairs(6) ;
    154        assertEquals(1, pairs.size());
    155        assertEquals("#firstrow", pairs.get(7));
    156     }
    157    
     142    public void testAddTargetCachedRepresentation() throws SQLException {
     143        System.out.println("test addTargetCachedRepresentation");
     144        assertEquals(1, jdbcTargetDao.addTargetCachedRepresentation(6, 7, "#firstrow"));
     145        // content test
     146        Map<Number, String> pairs = jdbcTargetDao.getCachedRepresentationFragmentPairs(6);
     147        assertEquals(1, pairs.size());
     148        assertEquals("#firstrow", pairs.get(7));
     149    }
     150
    158151    /**
    159152     * Test of addTarget method, of class JdbcTargetDao.
     
    164157
    165158        Target freshTarget = new Target();
    166         freshTarget.setLink("http://nl.wikipedia.org/wiki/Sagrada_Fam%C3%ADlia"+"#Het_ontwerp");
     159        freshTarget.setLink("http://nl.wikipedia.org/wiki/Sagrada_Fam%C3%ADlia" + "#Het_ontwerp");
    167160        freshTarget.setVersion("version 1.0");
    168161        freshTarget.setLastModified(null);
    169        
     162
    170163        Number result = jdbcTargetDao.addTarget(freshTarget);
    171164        assertEquals(8, result);
    172165        // detailed checking
    173166        Target addedTarget = jdbcTargetDao.getTarget(result);
    174         assertEquals("http://nl.wikipedia.org/wiki/Sagrada_Fam%C3%ADlia"+"#Het_ontwerp", addedTarget.getLink());
     167        assertEquals("http://nl.wikipedia.org/wiki/Sagrada_Fam%C3%ADlia" + "#Het_ontwerp", addedTarget.getLink());
    175168        assertEquals("version 1.0", addedTarget.getVersion());
    176169        assertTrue(addedTarget.getURI().startsWith(TestBackendConstants._TEST_SERVLET_URI_Targets));
     
    182175    @Test
    183176    public void testGetTargetInfos() {
    184         System.out.println("getTargetInfos");       
     177        System.out.println("getTargetInfos");
    185178        jdbcTargetDao.setServiceURI(TestBackendConstants._TEST_SERVLET_URI_Targets);
    186179        List<Number> test = new ArrayList<Number>();
     
    189182        List<TargetInfo> result = jdbcTargetDao.getTargetInfos(test);
    190183        assertEquals(2, result.size());
    191         assertEquals(TestBackendConstants._TEST_SERVLET_URI_Targets+"00000000-0000-0000-0000-000000000031", result.get(0).getRef());
    192         assertEquals(TestBackendConstants._TEST_SERVLET_URI_Targets+"00000000-0000-0000-0000-000000000032", result.get(1).getRef());
     184        assertEquals(TestBackendConstants._TEST_SERVLET_URI_Targets + "00000000-0000-0000-0000-000000000031", result.get(0).getRef());
     185        assertEquals(TestBackendConstants._TEST_SERVLET_URI_Targets + "00000000-0000-0000-0000-000000000032", result.get(1).getRef());
    193186        assertEquals("version 1.0", result.get(0).getVersion());
    194187        assertEquals("version 1.1", result.get(1).getVersion());
    195         assertEquals("http://nl.wikipedia.org/wiki/Sagrada_Fam%C3%ADlia"+"#"+"de_Opdracht", result.get(0).getLink());
    196         assertEquals("http://nl.wikipedia.org/wiki/Antoni_Gaud%C3%AD"+"#Vroege_werk", result.get(1).getLink());
     188        assertEquals("http://nl.wikipedia.org/wiki/Sagrada_Fam%C3%ADlia" + "#" + "de_Opdracht", result.get(0).getLink());
     189        assertEquals("http://nl.wikipedia.org/wiki/Antoni_Gaud%C3%AD" + "#Vroege_werk", result.get(1).getLink());
    197190
    198191    }
     
    214207    }
    215208
    216     /* Test of getCachedRepresentations method, of class JdbcTargetDao.
    217      */
    218     @Test
    219     public void testGetCachedRepresentations() {
    220         System.out.println("test getCachedRepresentations");
    221         Number TargetID = 1;
    222         List<Number> result = jdbcTargetDao.getCachedRepresentations(TargetID);
     209    @Test
     210    public void testRetrieveTargetIDs() {
     211        System.out.println("retrieveTargetIDs");
     212        Number annotationID = 1;
     213        List<Number> result = jdbcTargetDao.retrieveTargetIDs(annotationID);
     214        assertEquals(2, result.size());
    223215        assertEquals(1, result.get(0));
    224216        assertEquals(2, result.get(1));
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/test/java/eu/dasish/annotation/backend/dao/impl/JdbcUserDaoTest.java

    r4461 r4546  
    2020import eu.dasish.annotation.backend.TestBackendConstants;
    2121import eu.dasish.annotation.backend.TestInstances;
     22import eu.dasish.annotation.schema.Permission;
    2223import eu.dasish.annotation.schema.User;
     24import java.util.ArrayList;
     25import java.util.List;
    2326import java.util.UUID;
    2427import org.junit.Test;
     
    157160        user.setEMail("Olha.Shakaravska@mpi.nl");
    158161        assertTrue(jdbcUserDao.userExists(user));
     162    }
     163   
     164      /**
     165     * Test of getPrincipalIDsWithPermission method, of class JdbcNotebookDao.
     166     */
     167    @Test
     168    public void testGetPrincipalIDsWithPermission() {
     169        System.out.println("gtest getPrincipalIDsWithPermission");
     170        List<Number> expResult = new ArrayList<Number>();
     171        expResult.add(2);
     172        expResult.add(4);
     173        List result = jdbcUserDao.getPrincipalIDsWithPermissionForNotebook(1, Permission.WRITER);
     174        assertEquals(expResult, result);
     175    }
    159176
    160     }
    161177}
Note: See TracChangeset for help on using the changeset viewer.