Changeset 4495


Ignore:
Timestamp:
02/11/14 18:01:34 (10 years ago)
Author:
olhsha
Message:

NotebookDao? finished, not 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

    r4491 r4495  
    6565    public List<Number> getAllAnnotationIDs();
    6666   
     67    public List<Number> sublistOrderedAnnotationIDs(List<Number> annotationIDs, int offset, int limit, String orderedBy, String desc);
     68   
    6769       /**
    6870     * unit test is missing
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/DBIntegrityService.java

    r4491 r4495  
    1818package eu.dasish.annotation.backend.dao;
    1919
    20 
    2120import eu.dasish.annotation.schema.Annotation;
    2221import eu.dasish.annotation.schema.AnnotationBody;
    2322import eu.dasish.annotation.schema.AnnotationInfoList;
    2423import eu.dasish.annotation.schema.CachedRepresentationInfo;
     24import eu.dasish.annotation.schema.Notebook;
     25import eu.dasish.annotation.schema.NotebookInfo;
     26import eu.dasish.annotation.schema.NotebookInfoList;
    2527import eu.dasish.annotation.schema.Permission;
    2628import eu.dasish.annotation.schema.UserWithPermissionList;
     
    3133import java.io.InputStream;
    3234import java.sql.SQLException;
    33 import java.sql.Timestamp;
    3435import java.util.List;
    3536import java.util.Map;
     
    3940 *
    4041 * @author olhsha
    41  **/
    42 
    43 
    44 
    45 
    46 public interface DBIntegrityService{
    47    
     42 *
     43 */
     44public interface DBIntegrityService {
     45
    4846    public void setServiceURI(String serviceURI);
    49    
    50    
     47
    5148    /**
    5249     * GETTERS
    5350     */
    54    
    55     /**
    56      *
     51    /**
     52     *
    5753     * @param UUID
    58      * @return the internal identifier of the annotations with "externalID", or null if no such annotation.
     54     * @return the internal identifier of the annotations with "externalID", or
     55     * null if no such annotation.
    5956     */
    6057    Number getAnnotationInternalIdentifier(UUID externalID);
    61    
    62     /**
    63      *
    64      * @param annotationID
    65      * @return the externalID of the annotation with "internalID" or null if there is no such annotation.
     58
     59    /**
     60     *
     61     * @param annotationID
     62     * @return the externalID of the annotation with "internalID" or null if
     63     * there is no such annotation.
    6664     */
    6765    UUID getAnnotationExternalIdentifier(Number annotationID);
    68    
    6966
    7067    Number getAnnotationInternalIdentifierFromURI(String uri);
    71    
    72 
    73    /**
    74     *
    75     * @param word
    76     * @param text
    77     * @param access
    78     * @param namespace
    79     * @param after
    80     * @param before
    81     * @return the list of internal id-s of the annotations such that:
    82     * -- Targets' links of which contain "link" (as a substring),
    83     * -- serialized bodies of which contain "text",
    84     * -- current user has "access" (owner, reader, writer)  to them,
    85     * -- namespace ???,
    86     * -- owned by "owner",
    87     * -- created after time-samp "after and before time-stamp "before".
    88     */
     68
     69    /**
     70     *
     71     * @param word
     72     * @param text
     73     * @param access
     74     * @param namespace
     75     * @param after
     76     * @param before
     77     * @return the list of internal id-s of the annotations such that: --
     78     * Targets' links of which contain "link" (as a substring), -- serialized
     79     * bodies of which contain "text", -- current user has "access" (owner,
     80     * reader, writer) to them, -- namespace ???, -- owned by "owner", --
     81     * created after time-samp "after and before time-stamp "before".
     82     */
    8983    List<Number> getFilteredAnnotationIDs(UUID ownerId, String link, String text, Number inloggedUserID, String access, String namespace, String after, String before);
    90    
     84
    9185    AnnotationInfoList getAllAnnotationInfos();
    92    
    93     /**
    94      *
    95      @param word
    96     * @param text
    97     * @param access
    98     * @param namespace
    99     * @param owner
    100     * @param after
    101     * @param before
    102      * @return the list of the annotationInfos of the annotations such that:
    103     * -- Targets' links of which contain "link" (as a substring),
    104     * -- serialized bodies of which contain "text",
    105     * -- current user has "access" (owner, reader, writer)  to them,
    106     * -- namespace ???,
    107     * -- owned by "owner",
    108     * -- created after time-samp "after and before time-stamp "before".
    109      */
    110     AnnotationInfoList getFilteredAnnotationInfos(UUID ownerId, String word, String text, Number inloggedUserID,  String access, String namespace, String after, String before);
    111 
    112     /**
    113      *
    114      * @param userID
    115      * @return the external identifier of the user "userID", or null if no such user.
     86
     87    /**
     88     *
     89     * @param word
     90     * @param text
     91     * @param access
     92     * @param namespace
     93     * @param owner
     94     * @param after
     95     * @param before
     96     * @return the list of the annotationInfos of the annotations such that: --
     97     * Targets' links of which contain "link" (as a substring), -- serialized
     98     * bodies of which contain "text", -- current user has "access" (owner,
     99     * reader, writer) to them, -- namespace ???, -- owned by "owner", --
     100     * created after time-samp "after and before time-stamp "before".
     101     */
     102    AnnotationInfoList getFilteredAnnotationInfos(UUID ownerId, String word, String text, Number inloggedUserID, String access, String namespace, String after, String before);
     103
     104    /**
     105     *
     106     * @param userID
     107     * @return the external identifier of the user "userID", or null if no such
     108     * user.
    116109     */
    117110    UUID getUserExternalIdentifier(Number userID);
    118111
    119112    /**
    120      * 
     113     *
    121114     * @param externalID
    122      * @return the internal identifier of the user with "externalID", or null if there is no such user.
     115     * @return the internal identifier of the user with "externalID", or null if
     116     * there is no such user.
    123117     */
    124118    Number getUserInternalIdentifier(UUID externalID);
    125    
    126       /**
    127      * 
     119
     120    /**
     121     *
    128122     * @param cachedID
    129      * @return the external identifier of the cached representation "cachedID", or null if no such one.
     123     * @return the external identifier of the cached representation "cachedID",
     124     * or null if no such one.
    130125     */
    131126    UUID getCachedRepresentationExternalIdentifier(Number cachedID);
    132127
    133128    /**
    134      * 
     129     *
    135130     * @param externalID
    136      * @return the internal identifier of the cachedRepresentation with "externalID", or null if there is no such one.
     131     * @return the internal identifier of the cachedRepresentation with
     132     * "externalID", or null if there is no such one.
    137133     */
    138134    Number getCachedRepresentationInternalIdentifier(UUID externalID);
    139    
    140     Number getTargetInternalIdentifier(UUID externalID); 
     135
     136    Number getTargetInternalIdentifier(UUID externalID);
    141137
    142138    String getTargetURI(Number targetID);
    143    
     139
    144140    UUID getTargetExternalIdentifier(Number targetID);
    145      
    146     String getUserURI(Number userID); 
    147    
    148     /**
    149      * 
     141
     142    String getUserURI(Number userID);
     143
     144    /**
     145     *
    150146     * @param internalID
    151      * @return CachedRepresentationInfo (i.e. "metadata") for cached representation with the internal id "intenalID"
     147     * @return CachedRepresentationInfo (i.e. "metadata") for cached
     148     * representation with the internal id "intenalID"
    152149     */
    153150    CachedRepresentationInfo getCachedRepresentationInfo(Number internalID);
    154    
    155     /**
    156      *
    157      * @param annotationID
    158      * @return the object Annotation generated from the tables "annotation", "annotations_target_Targets", "Target", "annotations_principals_permissions".
    159      * @throws SQLException
     151
     152    /**
     153     *
     154     * @param annotationID
     155     * @return the object Annotation generated from the tables "annotation",
     156     * "annotations_target_Targets", "Target",
     157     * "annotations_principals_permissions".
     158     * @throws SQLException
    160159     */
    161160    Annotation getAnnotation(Number annotationID);
    162    
     161
    163162    Number getAnnotationOwner(Number annotationID);
    164    
    165      /**
    166      *
    167      * @param annotationID
    168      * @return the object TargetList containing all target Targets of the annotationID
    169      * @throws SQLException
     163
     164    /**
     165     *
     166     * @param annotationID
     167     * @return the object TargetList containing all target Targets of the
     168     * annotationID
     169     * @throws SQLException
    170170     */
    171171    ReferenceList getAnnotationTargets(Number annotationID);
    172    
    173    
    174    
    175     /**
    176      *
    177      * @param annotationID
    178      * @return the list of targetURI's for which there is no cached representation
     172
     173    /**
     174     *
     175     * @param annotationID
     176     * @return the list of targetURI's for which there is no cached
     177     * representation
    179178     */
    180179    List<String> getTargetsWithNoCachedRepresentation(Number annotationID);
    181    
     180
    182181    List<String> getUsersWithNoInfo(Number annotationID);
    183    
    184     /**
    185      *
    186      * @param annotationID
    187      * @return the list of TargetID's for which there is no cached representation
     182
     183    /**
     184     *
     185     * @param annotationID
     186     * @return the list of TargetID's for which there is no cached
     187     * representation
    188188     */
    189189    public UserWithPermissionList getPermissionsForAnnotation(Number annotationID);
    190    
    191      /**
    192      * 
     190
     191    /**
     192     *
    193193     * @param TargetID
    194      * @return the list of the external version ID-s that refers to the same source (link) as targetID
     194     * @return the list of the external version ID-s that refers to the same
     195     * source (link) as targetID
    195196     */
    196197    public ReferenceList getTargetsForTheSameLinkAs(Number targetID);
    197    
    198     /**
    199      * 
     198
     199    /**
     200     *
    200201     * @param cachedID
    201202     * @return BLOB of the cachedID
    202203     */
    203     public InputStream getCachedRepresentationBlob(Number cachedID) ;
    204    
    205    
    206    
     204    public InputStream getCachedRepresentationBlob(Number cachedID);
     205
    207206    public Target getTarget(Number internalID);
    208    
    209     /**
    210      * 
     207
     208    /**
     209     *
    211210     * @param userID
    212211     * @return user with "userID"
    213212     */
    214213    public User getUser(Number userID);
    215            
    216     /**
    217      * 
     214
     215    /**
     216     *
    218217     * @param eMail
    219218     * @return user with e-mail "eMail"
    220219     */
    221220    public User getUserByInfo(String eMail);
    222    
    223    
     221
    224222    public String getUserRemoteID(Number internalID);
    225    
     223
    226224    public Number getUserInternalIDFromRemoteID(String remoteID);
    227  
    228     /**
    229      * 
    230      * @param annotationID
    231      * @param userID
    232      * @return permission of the userID w.r.t. annotationID, or null if the permission is not given
    233      */
    234     public Permission  getPermission(Number annotationID, Number userID);
    235    
    236    
     225
     226    /**
     227     *
     228     * @param annotationID
     229     * @param userID
     230     * @return permission of the userID w.r.t. annotationID, or null if the
     231     * permission is not given
     232     */
     233    public Permission getPermission(Number annotationID, Number userID);
     234
    237235    public String getTypeOfUserAccount(Number userID);
    238    
     236
    239237    public boolean canRead(Number userID, Number annotationID);
    240            
    241     public boolean canWrite(Number userID, Number annotationID);       
    242    
     238
     239    public boolean canWrite(Number userID, Number annotationID);
     240
     241    /// notebooks ///
     242    public NotebookInfoList getNotebooks(Number prinipalID, Permission permission);
     243
     244    public NotebookInfoList getNotebooksOwnedBy(Number principalID);
     245
     246    public List<UUID> getPrincipals(Number notebookID, Permission permission);
     247
     248    public NotebookInfo getNotebookInfo(Number notebookID);
     249
     250    List<UUID> getAnnotationsForNotebook(Number notebookID, int startAnnotation, int maximumAnnotations, String orderedBy, boolean desc);
     251
    243252    /**
    244253     * UPDATERS
    245254     */
    246    
    247255    public boolean updateAccount(UUID userExternalID, String account);
    248    
    249    
    250     /**
    251      *
     256
     257    /**
     258     *
    252259     * @param annotation
    253260     * @return 1 of the annotation if it is updated
    254261     */
    255262    int updateAnnotation(Annotation annotation);
    256    
    257      
    258    
    259     /**
    260      *
     263
     264    /**
     265     *
    261266     * @param userID
    262267     * @param annotationBody
     
    264269     */
    265270    int updateAnnotationBody(Number internalID, AnnotationBody annotationBody);
    266    
    267    
    268    
    269        /**
    270      *
     271
     272    /**
     273     *
    271274     * @param annotationID
    272275     * @param userID
    273276     * @param permission
    274277     * @return # rows updated to the table "annotations_principals_permissions"
    275      * Sets the "permission" for the "userID" w.r.t. the annotation with "annotationID".
     278     * Sets the "permission" for the "userID" w.r.t. the annotation with
     279     * "annotationID".
    276280     */
    277281    public int updateAnnotationPrincipalPermission(Number annotationID, Number userID, Permission permission);
    278    
    279    /**
    280      * 
     282
     283    /**
     284     *
    281285     * @param annotationID
    282286     * @param permissionList
    283      * @return # of rows updated or added in the table annotations_principals_permissions
     287     * @return # of rows updated or added in the table
     288     * annotations_principals_permissions
    284289     */
    285290    public int updatePermissions(Number annotationID, UserWithPermissionList permissionList);
    286    
     291
    287292    public Number updateUser(User user);
    288    
    289    /**
    290     * ADDERS
    291     */
    292     /**
    293      *
     293
     294    /// notebooks ///
     295    public boolean updateNotebookMetadata(Number notebookID, NotebookInfo upToDateNotebookInfo);
     296
     297    public boolean addAnnotationToNotebook(Number notebookID, Number annotationID);
     298
     299    /**
     300     * ADDERS
     301     */
     302    /**
     303     *
    294304     * @param targetID
    295305     * @param cachedInfo
    296306     * @param cachedBlob
    297      * @return result[0] = # updated rows in the table "Targets_cached_representations" (must be 1 or 0).
    298      * result[1] = the internal ID of the added cached (a new one if "cached" was new for the Data Base).
     307     * @return result[0] = # updated rows in the table
     308     * "Targets_cached_representations" (must be 1 or 0). result[1] = the
     309     * internal ID of the added cached (a new one if "cached" was new for the
     310     * Data Base).
    299311     */
    300312    Number[] addCachedForTarget(Number targetID, String fragmentDescriptor, CachedRepresentationInfo cachedInfo, InputStream cachedBlob);
    301    
    302  
    303     /**
    304      *
     313
     314    /**
     315     *
    305316     * @param annotationID
    306317     * @param targets
    307      * @return map temporaryTargetID |--> TargetExternalID. Its domain is the temporary IDs of all the new Targets. While adding a new Target a new external ID is generated for it and it becomes the value of the map. The TargetIDs which are already present in the DB are not in the domain. If all Targets are old, then the map is empty.
    308      * @throws SQLException
     318     * @return map temporaryTargetID |--> TargetExternalID. Its domain is the
     319     * temporary IDs of all the new Targets. While adding a new Target a new
     320     * external ID is generated for it and it becomes the value of the map. The
     321     * TargetIDs which are already present in the DB are not in the domain. If
     322     * all Targets are old, then the map is empty.
     323     * @throws SQLException
    309324     */
    310325    Map<String, String> addTargetsForAnnotation(Number annotationID, List<TargetInfo> targets);
    311326
    312327    /**
    313      * 
     328     *
    314329     * @param userID
    315330     * @param annotation
    316      * @return the internalId of the just added "annotation" (or null if it is not added) by the owner "userID".
    317      * calls "addTargetsForAnnotation"
    318      * @throws SQLException 
     331     * @return the internalId of the just added "annotation" (or null if it is
     332     * not added) by the owner "userID". calls "addTargetsForAnnotation"
     333     * @throws SQLException
    319334     */
    320335    Number addUsersAnnotation(Number ownerID, Annotation annotation);
    321    
    322     /**
    323      * 
     336
     337    /**
     338     *
    324339     * @param user
    325340     * @param remoteID is got from the server
    326      * @return the internal Id of the just added "user", or null if it was not added for some reason (already exists)
    327      * @throws SQLException
     341     * @return the internal Id of the just added "user", or null if it was not
     342     * added for some reason (already exists)
     343     * @throws SQLException
    328344     */
    329345    Number addUser(User user, String remoteID);
    330346
    331347    int addAnnotationPrincipalPermission(Number annotationID, Number userID, Permission permission);
    332    
     348
     349    /// notebooks ////
     350    Number createNotebook(Notebook notebook, Number ownerID);
     351
     352    boolean createAnnotationInNotebook(Number notebookID, Annotation annotation, Number ownerID);
     353
    333354    /**
    334355     * DELETERS
    335356     */
    336    
    337     /**
    338      *
    339      * @param userID
    340      * @return # of affected rows in the table "principal".
    341      * It is 1 if the userId is found and deleted;
    342      * it is 0 if it is not found or not deleted, e.g. because it is in use in the table "annotationsPreincipalsPermissions"
     357    /**
     358     *
     359     * @param userID
     360     * @return # of affected rows in the table "principal". It is 1 if the
     361     * userId is found and deleted; it is 0 if it is not found or not deleted,
     362     * e.g. because it is in use in the table
     363     * "annotationsPreincipalsPermissions"
    343364     */
    344365    public int deleteUser(Number userID);
    345    
    346      /**
    347      *
    348      * @param userID
    349      * @return # of affected rows in the table "principal".
    350      * It is 1 if the userId is found and deleted;
    351      * it is 0 if it is not found or not deleted, e.g. because it is in use in the table "annotationsPreincipalsPermissions"
     366
     367    /**
     368     *
     369     * @param userID
     370     * @return # of affected rows in the table "principal". It is 1 if the
     371     * userId is found and deleted; it is 0 if it is not found or not deleted,
     372     * e.g. because it is in use in the table
     373     * "annotationsPreincipalsPermissions"
    352374     */
    353375    public int deleteUserSafe(Number userID);
    354    
    355     /**
    356      * 
     376
     377    /**
     378     *
    357379     * @param TargetID
    358380     * @param cachedID
    359      * @return result[0] = # deleted rows in the table "Targets_cached_representations" (1, or 0).
    360      * result[1] = # deleted rows in the table "cached_representation" (should be 0 if the cached representation is in use by some other Target???).
    361      */
    362     int[] deleteCachedRepresentationOfTarget(Number TargetID, Number cachedID) ;
    363 
     381     * @return result[0] = # deleted rows in the table
     382     * "Targets_cached_representations" (1, or 0). result[1] = # deleted rows in
     383     * the table "cached_representation" (should be 0 if the cached
     384     * representation is in use by some other Target???).
     385     */
     386    int[] deleteCachedRepresentationOfTarget(Number TargetID, Number cachedID);
     387
     388    /**
     389     *
     390     * @param targetID
     391     * @return result[0] = # deleted rows in the table
     392     * "targets_cached_representations". result[1] = # deleted rows in the table
     393     * "cached_representation".
     394     *
     395     */
     396    int[] deleteAllCachedRepresentationsOfTarget(Number versionID);
     397
     398    /**
     399     *
     400     * @param annotationID
     401     * @return result[0] = # deleted rows in the table "annotation" (1 or 0).
     402     * result[1] = # deleted rows in the table
     403     * "annotations_principals_permissions". result[2] = # deleted rows in the
     404     * table "annotations_target_Targets". result[3] = # deleted rows in the
     405     * table "Target".
     406     * @throws SQLException
     407     */
     408    int[] deleteAnnotation(Number annotationID);
    364409   
    365    
    366 
    367    
    368     /**
    369      *
    370      * @param targetID
    371      * @return
    372      * result[0] =  # deleted rows in the table "targets_cached_representations".
    373      * result[1] = # deleted rows in the table "cached_representation".
    374      **/
    375    
    376     int[] deleteAllCachedRepresentationsOfTarget(Number versionID);
    377 
    378      
    379    
    380     /**
    381      *
    382      * @param annotationID
    383      * @return result[0] = # deleted rows in the table "annotation" (1 or 0).
    384      * result[1] = # deleted rows in the table "annotations_principals_permissions".
    385      * result[2] = # deleted rows in the table "annotations_target_Targets".
    386      * result[3] = # deleted rows in the table "Target".
    387      * @throws SQLException
    388      */
    389     int[] deleteAnnotation(Number annotationID);
    390 
    391    
     410    /// notebooks ///
     411    boolean deleteNotebook(Number notebookID);
    392412   
    393413}
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/NotebookDao.java

    r4493 r4495  
    2323import eu.dasish.annotation.schema.NotebookInfo;
    2424import java.util.List;
     25import java.util.UUID;
    2526
    2627/**
     
    3940     * GETTERS
    4041     *
    41      */
    42     // Returns a list of notebook Ids for the notebooks for which the given user "userID' has "permission" access.
    43     List<Number> getNotebookIDs(Number userID, Permission acessMode);
     42  **/
     43   
     44    Number getOwner(Number notebookID);
     45   
     46    List<Number> getNotebookIDs(Number principalID, Permission acessMode);
    4447   
    4548    // Returns a list of notebook Ids for the notebooks for which the given user "userID" is the owner.
    46     List<Number> getOwnerNotebookIDs(Number userID);
     49    List<Number> getNotebookIDsOwnedBy(Number principaID);
    4750   
    4851    public List<Number> getPrincipalIDsWithPermission(Number notebookID, Permission permission);
     52   
    4953   
    5054   
     
    5559     * @return the notebook info for the notebook with notebookID
    5660     */
    57     NotebookInfo getNotebookInfo(Number notebookID);
     61    NotebookInfo getNotebookInfoWithoutOwner(Number notebookID);
    5862   
    5963   
     
    6367     * @return notebook metadata for the notebook with notebookID
    6468     */
    65     Notebook getNotebookWithoutAnnotationsAndPermissions(Number notebookID);
     69    Notebook getNotebookWithoutAnnotationsAndPermissionsAndOwner(Number notebookID);
    6670   
    67     //? Which type shul be orderedby?
    68     /**
    69      *
    70      * @param maximumAnnotations
    71      * @param startannotation
    72      * @param orderedBy
    73      * @param orederingMode if true then descending, if falset hen ascending
    74      * @return
    75      */
    76     List<Number> getAnnotations(int maximumAnnotations, int startannotation, String orderedBy, boolean orderingMode);
     71   
     72    List<Number> getAnnotations(Number notebookID);
    7773   
    7874    /**
     
    9086     * @return true if updated, false otherwise. Logs the reason if the notebook is not updated.
    9187     */
    92     boolean updateNotebookMetadata(Number notebookID);
     88    boolean updateNotebookMetadata(Number notebookID, String title, Number ownerID);
     89   
     90    boolean setOwner(Number notebookID, Number ownerID);
     91   
     92    boolean updateUserPermissionForNotebook(Number notebookID, Number principalID, Permission permission);
    9393   
    9494     /**
     
    9999     */
    100100   
    101     Number createNotebook(Notebook notebook);
     101    public Number createNotebookWithoutPermissionsAndAnnotations(Notebook notebook, Number ownerID);
    102102   
    103     boolean addAnnotationToNotebook(Number noteboookId, Number AnnotationID);
     103    boolean addAnnotationToNotebook(Number notebookID, Number annotationID);
     104   
     105    boolean addPermissionToNotebook(Number notebookID, Number userID, Permission permission);
    104106   
    105107   
     
    107109    /**
    108110     *
    109      * DELETERS (ADDER)
     111     * DELETERS
    110112     *
    111113     *
    112114     */
    113115   
    114     boolean deleteannotationFromNotebook(Number notebookID, Number annotationID);
     116    boolean deleteAnnotationFromNotebook(Number notebookID, Number annotationID);
     117   
     118    boolean deleteAllAnnotationsFromNotebook(Number notebookID);
     119   
     120    boolean deleteNotebookPrincipalPermission(Number notebookID, Number principalID);
     121   
     122    boolean deleteAllPermissionsForNotebook(Number notebookID);
    115123   
    116124    boolean deleteNotebook(Number notebookID);
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/impl/DBIntegrityServiceImlp.java

    r4491 r4495  
    2222import eu.dasish.annotation.backend.dao.CachedRepresentationDao;
    2323import eu.dasish.annotation.backend.dao.DBIntegrityService;
     24import eu.dasish.annotation.backend.dao.NotebookDao;
    2425import eu.dasish.annotation.backend.dao.TargetDao;
    2526import eu.dasish.annotation.backend.dao.UserDao;
     
    3233import eu.dasish.annotation.schema.CachedRepresentationFragmentList;
    3334import eu.dasish.annotation.schema.CachedRepresentationInfo;
     35import eu.dasish.annotation.schema.Notebook;
     36import eu.dasish.annotation.schema.NotebookInfo;
     37import eu.dasish.annotation.schema.NotebookInfoList;
    3438import eu.dasish.annotation.schema.TargetInfoList;
    3539import eu.dasish.annotation.schema.Permission;
     
    6569    @Autowired
    6670    AnnotationDao annotationDao;
    67    
     71    @Autowired
     72    NotebookDao notebookDao;
    6873    final static protected String admin = "admin";
    6974    private static final Logger logger = LoggerFactory.getLogger(AnnotationResource.class);
     
    403408        return userDao.getTypeOfUserAccount(userID);
    404409    }
    405    
     410
    406411    @Override
    407412    public boolean canRead(Number userID, Number annotationID) {
     
    429434            return false;
    430435        }
     436    }
     437
     438    /// notebooks ///
     439    @Override
     440    public NotebookInfoList getNotebooks(Number prinipalID, Permission permission) {
     441        NotebookInfoList result = new NotebookInfoList();
     442        List<Number> notebookIDs = notebookDao.getNotebookIDs(prinipalID, permission);
     443        for (Number notebookID : notebookIDs) {
     444            NotebookInfo notebookInfo = notebookDao.getNotebookInfoWithoutOwner(notebookID);
     445            Number ownerID = notebookDao.getOwner(notebookID);
     446            notebookInfo.setOwnerRef(userDao.getURIFromInternalID(ownerID));
     447            result.getNotebookInfo().add(notebookInfo);
     448        }
     449
     450        return result;
     451    }
     452
     453    @Override
     454    public NotebookInfoList getNotebooksOwnedBy(Number principalID) {
     455        NotebookInfoList result = new NotebookInfoList();
     456        List<Number> notebookIDs = notebookDao.getNotebookIDsOwnedBy(principalID);
     457        String ownerRef = userDao.getURIFromInternalID(principalID);
     458        for (Number notebookID : notebookIDs) {
     459            NotebookInfo notebookInfo = notebookDao.getNotebookInfoWithoutOwner(notebookID);
     460            notebookInfo.setOwnerRef(ownerRef);
     461            result.getNotebookInfo().add(notebookInfo);
     462        }
     463
     464        return result;
     465    }
     466
     467    @Override
     468    public List<UUID> getPrincipals(Number notebookID, Permission permission) {
     469        List<UUID> result = new ArrayList<UUID>();
     470        List<Number> principalIDs = notebookDao.getPrincipalIDsWithPermission(notebookID, permission);
     471        for (Number principalID : principalIDs) {
     472            UUID uuid = userDao.getExternalID(principalID);
     473            result.add(uuid);
     474        }
     475        return result;
     476    }
     477
     478    @Override
     479    public NotebookInfo getNotebookInfo(Number notebookID) {
     480        NotebookInfo result = notebookDao.getNotebookInfoWithoutOwner(notebookID);
     481        result.setOwnerRef(userDao.getURIFromInternalID(notebookDao.getOwner(notebookID)));
     482        return result;
     483    }
     484
     485    /////////////////////////////////////////////////////////////
     486    @Override
     487    public List<UUID> getAnnotationsForNotebook(Number notebookID, int startAnnotation, int maximumAnnotations, String orderedBy, boolean desc) {
     488        List<Number> annotationIDs = notebookDao.getAnnotations(notebookID);
     489
     490        if (startAnnotation < -1) {
     491            logger.info("Variable's startAnnotation value " + startAnnotation + " is invalid. I will return null.");
     492            return null;
     493        }
     494
     495        if (maximumAnnotations < -1) {
     496            logger.info("Variable's maximumAnnotations value " + maximumAnnotations + " is invalid. I will return null.");
     497            return null;
     498        }
     499
     500        int offset = (startAnnotation > 0) ? startAnnotation - 1 : 0;
     501        String direction = desc ? " DESC " : " ASC ";
     502        List<Number> selectedAnnotIDs = annotationDao.sublistOrderedAnnotationIDs(annotationIDs, offset, maximumAnnotations, orderedBy, direction);
     503        List<UUID> annotationUUIDs = new ArrayList<UUID>();
     504        for (Number annotationID : selectedAnnotIDs) {
     505            annotationUUIDs.add(annotationDao.getExternalID(annotationID));
     506        }
     507        return annotationUUIDs;
    431508    }
    432509
     
    489566    }
    490567
     568    @Override
     569    public Number updateUser(User user) {
     570        return userDao.updateUser(user);
     571    }
     572    /// notebooks ///
     573
     574    @Override
     575    public boolean updateNotebookMetadata(Number notebookID, NotebookInfo upToDateNotebookInfo) {
     576        Number ownerID = userDao.getInternalIDFromURI(upToDateNotebookInfo.getOwnerRef());
     577        return notebookDao.updateNotebookMetadata(notebookID, upToDateNotebookInfo.getTitle(), ownerID);
     578    }
     579
     580    @Override
     581    public boolean addAnnotationToNotebook(Number notebookID, Number annotationID) {
     582        return notebookDao.addAnnotationToNotebook(notebookID, annotationID);
     583    }
     584
    491585    /////////////// ADDERS  /////////////////////////////////
    492586    @Override
     
    535629
    536630    @Override
    537     public Number updateUser(User user) {
    538         return userDao.updateUser(user);
    539     }
    540 
    541     @Override
    542631    public Number addUser(User user, String remoteID) {
    543632        if (userDao.userExists(user)) {
     
    551640    public int addAnnotationPrincipalPermission(Number annotationID, Number userID, Permission permission) {
    552641        return annotationDao.addAnnotationPrincipalPermission(annotationID, userID, permission);
     642    }
     643   
     644    //////////// notebooks //////
     645
     646    @Override
     647    public Number createNotebook(Notebook notebook, Number ownerID) {
     648        Number notebookID = notebookDao.createNotebookWithoutPermissionsAndAnnotations(notebook, ownerID);
     649        boolean updateOwner = notebookDao.setOwner(notebookID, ownerID);
     650        List<UserWithPermission> permissions = notebook.getPermissions().getUserWithPermission();
     651        for (UserWithPermission principalPermission : permissions) {
     652            Number principalID = userDao.getInternalIDFromURI(principalPermission.getRef());
     653            Permission permission = principalPermission.getPermission();
     654            boolean updatePermissions = notebookDao.addPermissionToNotebook(notebookID, principalID, permission);
     655        }
     656        return notebookID;
     657    }
     658
     659    @Override
     660    public boolean createAnnotationInNotebook(Number notebookID, Annotation annotation, Number ownerID) {
     661        Number newAnnotationID = this.addUsersAnnotation(ownerID, annotation);
     662        return notebookDao.addAnnotationToNotebook(notebookID, newAnnotationID);
    553663    }
    554664
     
    609719        return result;
    610720    }
     721   
     722    @Override
     723    public boolean deleteNotebook(Number notebookID) {
     724        boolean deletePermissions = notebookDao.deleteAllPermissionsForNotebook(notebookID);
     725        boolean deleteAnnotations = notebookDao.deleteAllAnnotationsFromNotebook(notebookID);
     726        return notebookDao.deleteNotebook(notebookID);
     727    }
    611728
    612729    ////////////// HELPERS ////////////////////
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/impl/JdbcAnnotationDao.java

    r4491 r4495  
    6767            StringBuilder sql = new StringBuilder("SELECT DISTINCT ");
    6868            sql.append(target_id).append(" FROM ").append(annotationsTargetsTableName).append(" WHERE ").append(annotation_id).append("= ?");
    69             return getSimpleJdbcTemplate().query(sql.toString(), TargetIDRowMapper, annotationID);
     69            return getSimpleJdbcTemplate().query(sql.toString(), targetIDRowMapper, annotationID);
    7070        } else {
    7171            loggerAnnotationDao.debug(nullArgument);
     
    9494    };
    9595
    96    
    97    
    9896    @Override
    9997    public Permission getPermission(Number annotationID, Number userID) {
     
    128126    };
    129127
    130    
    131    
    132    
    133128    ////////////////////////////////////////////////////////////////////////
    134129    @Override
     
    143138            params.put("ownerId", ownerID);
    144139        }
    145        
     140
    146141        if (after != null) {
    147142            sql.append(" AND ").append(last_modified).append("  > :afterTimestamp");
     
    161156    }
    162157
    163      ///////////////////////////////////////////////////////////////////////////////////
     158    ///////////////////////////////////////////////////////////////////////////////////
    164159    @Override
    165160    public List<Number> getAnnotationIDsForUserWithPermission(Number userID, String access) {
    166        
     161
    167162        if (userID == null) {
    168163            loggerAnnotationDao.debug("userID: " + nullArgument);
    169164            return null;
    170165        }
    171        
     166
    172167        if (access == null) {
    173168            logger.info("The access argument is null. I assign it a default value 'reader'.");
     
    175170        }
    176171
    177        
     172
    178173        StringBuilder sql = new StringBuilder("SELECT ");
    179174        sql.append(annotation_id).append(" FROM ").append(permissionsTableName).append(" WHERE ").
     
    183178    }
    184179
    185    
    186  
    187    
    188 
    189180    //////////////////////////////
    190181    @Override
     
    203194        return getSimpleJdbcTemplate().query(query.toString(), internalIDRowMapper);
    204195    }
    205    
    206    
    207    
    208    
     196
    209197    /////////////////////////////////////////
    210198    @Override
     
    215203    }
    216204
     205    @Override
     206    public List<Number> sublistOrderedAnnotationIDs(List<Number> annotationIDs, int offset, int limit, String orderedBy, String direction) {
     207        if (annotationIDs == null) {
     208            return null;
     209        }
     210
     211        if (annotationIDs.isEmpty()) {
     212            return annotationIDs;
     213        }
     214
     215       
     216        String values = makeListOfValues(annotationIDs);
     217        Map<String, Object> params = new HashMap<String, Object>();
     218        params.put("offset", offset);
     219        params.put("limit", limit);
     220
     221        StringBuilder query = new StringBuilder("SELECT DISTINCT ");
     222        query.append(annotation_id).append(" FROM ").append(annotationsTargetsTableName).append(" WHERE ").append(annotation_id).append(" IN ");
     223        query.append(values).append(" ORDER BY ").append(orderedBy);
     224
     225        if (limit > -1) {
     226            query.append(direction).append(" LIMIT :limit ");
     227        }
     228
     229        query.append(" OFFSET :offset ");
     230        return getSimpleJdbcTemplate().query(query.toString(), internalIDRowMapper, params);
     231    }
     232
     233    //////////////////////////////////////////////////////////////////////
    217234    @Override
    218235    public AnnotationInfo getAnnotationInfoWithoutTargets(Number annotationID) {
     
    265282        String values = makeListOfValues(annotationIDs);
    266283        StringBuilder sql = new StringBuilder("SELECT DISTINCT ");
    267         sql.append(external_id).append(" FROM ").append(annotationTableName).append(" WHERE ").append(annotationAnnotation_id).append("  IN ").append(values);
     284        sql.append(external_id).append(" FROM ").append(annotationTableName).append(" WHERE ").append(annotation_id).append("  IN ").append(values);
    268285        return getSimpleJdbcTemplate().query(sql.toString(), annotationREFRowMapper);
    269286    }
     
    283300        }
    284301        StringBuilder sql = new StringBuilder("SELECT ");
    285         sql.append(annotationStar).append(" FROM ").append(annotationTableName).append(" WHERE ").append(annotationAnnotation_id).append("= ? LIMIT  1");
     302        sql.append(annotationStar).append(" FROM ").append(annotationTableName).append(" WHERE ").append(annotation_id).append("= ? LIMIT  1");
    286303        List<Annotation> respond = getSimpleJdbcTemplate().query(sql.toString(), annotationRowMapper, annotationID);
    287304        return (respond.isEmpty() ? null : respond.get(0));
     
    327344        return (respond.isEmpty() ? null : respond.get(0));
    328345    }
    329    
    330    
    331346
    332347    /////////////////////////////
     
    342357        StringBuilder sqlTargets = new StringBuilder("SELECT ");
    343358        sqlTargets.append(target_id).append(" FROM ").append(annotationsTargetsTableName).append(" WHERE ").append(annotation_id).append("= ? LIMIT 1");
    344         List<Number> resultTargets = getSimpleJdbcTemplate().query(sqlTargets.toString(), TargetIDRowMapper, annotationID);
     359        List<Number> resultTargets = getSimpleJdbcTemplate().query(sqlTargets.toString(), targetIDRowMapper, annotationID);
    345360        if (resultTargets.size() > 0) {
    346361            return true;
     
    449464        if (annotation == null) {
    450465            loggerAnnotationDao.debug("annotation: " + nullArgument);
    451             return 0;
     466            return null;
     467        }
     468       
     469        if (ownerID == null) {
     470            loggerAnnotationDao.debug("ownerID: " + nullArgument);
     471            return null;
    452472        }
    453473
     
    575595                StringBuilder sqlPermissions = new StringBuilder("DELETE FROM ");
    576596                sqlPermissions.append(permissionsTableName).append(" WHERE ").append(annotation_id).append(" = :annotationId AND ").
    577                 append(principal_id).append(" = :userId");               
    578                 return getSimpleJdbcTemplate().update(sqlPermissions.toString(), params); 
     597                        append(principal_id).append(" = :userId");
     598                return getSimpleJdbcTemplate().update(sqlPermissions.toString(), params);
    579599            } else {
    580600                loggerAnnotationDao.debug("userID: " + nullArgument);
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/impl/JdbcCachedRepresentationDao.java

    r4281 r4495  
    119119        StringBuilder sql = new StringBuilder("SELECT ");
    120120        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);
     121        List<Number> result = getSimpleJdbcTemplate().query(sql.toString(), targetIDRowMapper, cachedID);
    122122        if (result != null) {
    123123            return (!result.isEmpty());
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/impl/JdbcNotebookDao.java

    r4493 r4495  
    2828import java.util.List;
    2929import java.util.Map;
     30import java.util.UUID;
    3031import javax.sql.DataSource;
    3132import org.springframework.jdbc.core.RowMapper;
     
    3334import javax.xml.datatype.DatatypeFactory;
    3435import javax.xml.datatype.XMLGregorianCalendar;
     36import org.slf4j.Logger;
     37import org.slf4j.LoggerFactory;
    3538
    3639/**
     
    4245public class JdbcNotebookDao extends JdbcResourceDao implements NotebookDao {
    4346
    44 //    @Autowired
    45 //    private AnnotationDao jdbcAnnotationDao;
     47    private final Logger loggerNotebookDao = LoggerFactory.getLogger(JdbcNotebookDao.class);
     48
    4649    public JdbcNotebookDao(DataSource dataSource) {
    4750        setDataSource(dataSource);
     
    5255    /// GETTERS /////////
    5356    ////////////////////////////////////////////////
    54     @Override
    55     public List<Number> getNotebookIDs(Number userID, Permission acessMode) {
    56         Map<String, Object> params = new HashMap<String, Object>();
    57         params.put("principalID", userID);
    58         params.put("accessMode", acessMode.value());
    59         String sql = "SELECT " + notebook_id + " FROM " + notebookPermissionsTableName + " WHERE " + principalPrincipal_id + " = :principalID" + " AND " + permission + " = :accessMode";
    60         return getSimpleJdbcTemplate().query(sql, internalIDRowMapper, params);
    61     }
    62 
    6357    ////////////////////////////////////////////////
    6458    @Override
    65     public List<Number> getOwnerNotebookIDs(Number userID) {
    66         String sql = "SELECT " + notebook_id + " FROM " + notebookTableName + " WHERE " + owner_id + " = ?";
    67         return getSimpleJdbcTemplate().query(sql, internalIDRowMapper, userID);
    68     }
    69 
    70  
     59    public Number getOwner(Number notebookID) {
     60        if (notebookID == null) {
     61            loggerNotebookDao.debug("notebookID: " + nullArgument);
     62            return null;
     63        }
     64        StringBuilder sql = new StringBuilder("SELECT ");
     65        sql.append(owner_id).append(" FROM ").append(notebookTableName).append(" WHERE ").
     66                append(notebook_id).append(" = ?");
     67        List<Number> result = getSimpleJdbcTemplate().query(sql.toString(), principalIDRowMapper, notebookID);
     68        if (result.isEmpty()) {
     69            return null;
     70        } else {
     71            return result.get(0);
     72        }
     73    }
     74
     75    @Override
     76    public List<Number> getNotebookIDs(Number principalID, Permission permission) {
     77
     78        if (principalID == null) {
     79            loggerNotebookDao.debug("princiaplID: " + nullArgument);
     80            return null;
     81        }
     82
     83        if (permission == null) {
     84            loggerNotebookDao.debug("permission: " + nullArgument);
     85            return null;
     86        }
     87
     88        Map<String, Object> params = new HashMap<String, Object>();
     89        params.put("principalID", principalID);
     90        params.put("accessMode", permission.value());
     91        StringBuilder sql = new StringBuilder("SELECT ");
     92        sql.append(notebook_id).append(" FROM ").append(notebookPermissionsTableName).append(" WHERE ").
     93                append(principal_id).append(" = :principalID AND ").append(permission).append(" = :accessMode");
     94        return getSimpleJdbcTemplate().query(sql.toString(), internalIDRowMapper, params);
     95    }
     96
     97    ////////////////////////////////////////////////
     98    @Override
     99    public List<Number> getNotebookIDsOwnedBy(Number principalID) {
     100
     101        if (principalID == null) {
     102            loggerNotebookDao.debug("principalID: " + nullArgument);
     103            return null;
     104        }
     105
     106        StringBuilder sql = new StringBuilder("SELECT ");
     107        sql.append(notebook_id).append(" FROM ").append(notebookTableName).append(" WHERE ").
     108                append(owner_id).append(" = ?");
     109        return getSimpleJdbcTemplate().query(sql.toString(), internalIDRowMapper, principalID);
     110    }
    71111
    72112    @Override
    73113    public List<Number> getPrincipalIDsWithPermission(Number notebookID, Permission permission) {
    74          if (notebookID == null) {
    75             return null;
    76         }         
    77         Map<String, Object> params= new HashMap<String, Object>();
     114        if (notebookID == null) {
     115            loggerNotebookDao.debug("notebookID: " + nullArgument);
     116            return null;
     117        }
     118
     119        if (permission == null) {
     120            loggerNotebookDao.debug("permission: " + nullArgument);
     121            return null;
     122        }
     123        Map<String, Object> params = new HashMap<String, Object>();
    78124        params.put("notebookID", notebookID);
    79         params.put("permission", permission.value());
    80        
    81         String sql = "SELECT  " + owner_id + " FROM " + notebookPermissionsTableName + " WHERE " + notebook_id +" = :notebookID AND " +this.permission + " = :permission";
    82         return getSimpleJdbcTemplate().query(sql, principalIDRowMapper, params);
    83        
    84     }
    85 
    86     @Override
    87     public NotebookInfo getNotebookInfo(Number notebookID) {
    88         if (notebookID == null) {
    89             return null;
    90         }
    91         String sql = "SELECT  " + notebookExternal_id + "," + notebookTitle + " FROM " + notebookTableName + " where " + notebook_id + " = ? LIMIT 1";
    92         List<NotebookInfo> result = getSimpleJdbcTemplate().query(sql, notebookInfoRowMapper, notebookID);
     125        params.put("accessMode", permission.value());
     126
     127        StringBuilder sql = new StringBuilder("SELECT ");
     128        sql.append(principal_id).append(" FROM ").append(notebookPermissionsTableName).append(" WHERE ").
     129                append(notebook_id).append(" = :notebookID AND ").append(this.permission).append(" = :accessMode");
     130
     131        return getSimpleJdbcTemplate().query(sql.toString(), principalIDRowMapper, params);
     132
     133    }
     134
     135    @Override
     136    public NotebookInfo getNotebookInfoWithoutOwner(Number notebookID) {
     137        if (notebookID == null) {
     138            loggerNotebookDao.debug("notebookID: " + nullArgument);
     139            return null;
     140        }
     141
     142        StringBuilder sql = new StringBuilder("SELECT ");
     143        sql.append(external_id).append(" , ").append(title).
     144                append(" FROM ").append(notebookTableName).append(" WHERE ").
     145                append(notebook_id).append(" = :notebookID");
     146        List<NotebookInfo> result = getSimpleJdbcTemplate().query(sql.toString(), notebookInfoRowMapper, notebookID);
    93147        return (!result.isEmpty() ? result.get(0) : null);
    94148    }
     
    104158
    105159    @Override
    106     public Notebook getNotebookWithoutAnnotationsAndPermissions(Number notebookID) {
    107         if (notebookID == null) {
    108             return null;
    109         }
    110         String sql = "SELECT  " + notebookExternal_id + "," + notebookTitle + "," + last_modified + " FROM " + notebookTableName + " where " + notebook_id + " = ? LIMIT 1";
    111         List<Notebook> result = getSimpleJdbcTemplate().query(sql, notebookRowMapper, notebookID);
     160    public Notebook getNotebookWithoutAnnotationsAndPermissionsAndOwner(Number notebookID) {
     161        if (notebookID == null) {
     162            loggerNotebookDao.debug("notebookID: " + nullArgument);
     163            return null;
     164        }
     165        StringBuilder sql = new StringBuilder("SELECT ");
     166        sql.append(external_id).append(" , ").append(title).append(" , ").append(last_modified).
     167                append(" FROM ").append(notebookTableName).append(" WHERE ").
     168                append(notebook_id).append(" = :notebookID");
     169        List<Notebook> result = getSimpleJdbcTemplate().query(sql.toString(), notebookRowMapper, notebookID);
    112170        return (!result.isEmpty() ? result.get(0) : null);
    113171    }
     
    129187        }
    130188    };
     189
     190    @Override
     191    public List<Number> getAnnotations(Number notebookID) {
     192
     193        if (notebookID == null) {
     194            loggerNotebookDao.debug("notebookID: " + nullArgument);
     195            return null;
     196        }
     197
     198        StringBuilder sql = new StringBuilder("SELECT ");
     199        sql.append(annotation_id).
     200                append(" FROM ").append(notebooksAnnotationsTableName).append(" WHERE ").
     201                append(notebook_id).append(" = :notebookID");
     202        return getSimpleJdbcTemplate().query(sql.toString(), annotationIDRowMapper, notebookID);
     203
     204    }
     205
     206    /**
     207     *
     208     * UPDATERS
     209     *
     210     *
     211     */
     212    /**
     213     *
     214     * @param notebookID
     215     * @return true if updated, false otherwise. Logs the reason if the notebook
     216     * is not updated.
     217     */
     218    @Override
     219    public boolean updateNotebookMetadata(Number notebookID, String title, Number ownerID) {
     220
     221        if (notebookID == null) {
     222            loggerNotebookDao.debug("notebookID: " + nullArgument);
     223            return false;
     224        }
     225
     226        if (title == null) {
     227            loggerNotebookDao.debug("title: " + nullArgument);
     228            return false;
     229        }
     230
     231        if (ownerID == null) {
     232            loggerNotebookDao.debug("ownerID: " + nullArgument);
     233            return false;
     234        }
     235
     236        Map<String, Object> params = new HashMap<String, Object>();
     237        params.put("notebookID", notebookID);
     238        params.put("title", title);
     239        params.put("owner", ownerID);
     240
     241        StringBuilder sql = new StringBuilder("UPDATE ");
     242        sql.append(notebookTableName).append(" SET ").
     243                append(last_modified).append("=  default,").
     244                append(this.title).append("= :title, ").
     245                append(owner_id).append("= :owner").
     246                append(" WHERE ").append(notebook_id).append("= :notebookID");
     247        int affectedRows = getSimpleJdbcTemplate().update(sql.toString(), params);
     248        if (affectedRows <= 0) {
     249            logger.info("For some reason no rows in the table notebooks were updated. ");
     250            return false;
     251        } else {
     252            if (affectedRows > 1) {
     253                logger.info("For some reason more than 1 row in the table notebooks were updated. that's strange.");
     254                return true;
     255            } else {
     256                return true;
     257            }
     258        }
     259    }
    131260   
    132    
    133     @Override
    134     public List<Number> getAnnotations(int maximumAnnotations, int startannotation, String orderedBy, boolean orderingMode){
    135         return null;
    136     }
    137    
    138    
    139        /**
    140      *
    141      * UPDATERS
    142      *
    143      *
     261    @Override
     262    public boolean setOwner(Number notebookID, Number ownerID) {
     263
     264        if (notebookID == null) {
     265            loggerNotebookDao.debug("notebookID: " + nullArgument);
     266            return false;
     267        }
     268
     269        if (ownerID == null) {
     270            loggerNotebookDao.debug("ownerID: " + nullArgument);
     271            return false;
     272        }
     273
     274        Map<String, Object> params = new HashMap<String, Object>();
     275        params.put("notebookID", notebookID);
     276        params.put("ownerID", ownerID);
     277
     278        StringBuilder sql = new StringBuilder("UPDATE ");
     279        sql.append(notebookTableName).append(" SET ").
     280                append(last_modified).append("=  default,").
     281                append(owner_id).append("= :ownerID").
     282                append(" WHERE ").append(notebook_id).append("= :notebookID");
     283        int affectedRows = getSimpleJdbcTemplate().update(sql.toString(), params);
     284        if (affectedRows <= 0) {
     285            logger.info("For some reason no rows in the table notebooks were updated. ");
     286            return false;
     287        } else {
     288            if (affectedRows > 1) {
     289                logger.info("For some reason more than 1 row in the table notebooks were updated. that's strange.");
     290                return true;
     291            } else {
     292                return true;
     293            }
     294        }
     295    }
     296
     297    @Override
     298    public boolean updateUserPermissionForNotebook(Number notebookID, Number principalID, Permission permission) {
     299
     300        if (notebookID == null) {
     301            loggerNotebookDao.debug("notebookID: " + nullArgument);
     302            return false;
     303        }
     304
     305        if (principalID == null) {
     306            loggerNotebookDao.debug("principalID: " + nullArgument);
     307            return false;
     308        }
     309
     310        if (permission == null) {
     311            loggerNotebookDao.debug("permission: " + nullArgument);
     312            return false;
     313        }
     314
     315
     316        Map<String, Object> params = new HashMap<String, Object>();
     317        params.put("notebookID", notebookID);
     318        params.put("principalID", principalID);
     319        params.put("permission", permission.value());
     320
     321        StringBuilder sql = new StringBuilder("UPDATE ");
     322        sql.append(notebookPermissionsTableName).append(" SET ").
     323                append(notebook_id).append("= :notebookID, ").
     324                append(principal_id).append("= :principalID").
     325                append(this.permission).append("= :permission").
     326                append(" WHERE ").append(notebook_id).append("= :notebookID");
     327        int affectedRows = getSimpleJdbcTemplate().update(sql.toString(), params);
     328        if (affectedRows <= 0) {
     329            logger.info("For some reason no rows in the table notebooks-permissions were updated. ");
     330            return false;
     331        } else {
     332            if (affectedRows > 1) {
     333                logger.info("For some reason more than 1 row in the table notebooks-permissions were updated. that's strange.");
     334                return true;
     335            } else {
     336                return true;
     337            }
     338        }
     339    }
     340
     341    /**
     342     *
     343     * ADDERS
     344     *
     345     *
    144346     */
    145    
    146    
    147    
     347    @Override
     348    public Number createNotebookWithoutPermissionsAndAnnotations(Notebook notebook, Number ownerID) {
     349        if (notebook == null) {
     350            loggerNotebookDao.debug("notebook: " + nullArgument);
     351            return null;
     352        }
     353
     354        if (ownerID == null) {
     355            loggerNotebookDao.debug("ownerID: " + nullArgument);
     356            return null;
     357        }
     358
     359        UUID externalID = UUID.randomUUID();
     360        Map<String, Object> params = new HashMap<String, Object>();
     361        params.put("externalId", externalID.toString());
     362        params.put("owner", ownerID);
     363        params.put("title", notebook.getTitle());
     364
     365        StringBuilder sql = new StringBuilder("INSERT INTO ");
     366        sql.append(notebookTableName).append("(").append(external_id).append(",").append(owner_id);
     367        sql.append(",").append(title).
     368                append(" ) VALUES (:externalId, :owner, :title)");
     369        int affectedRows = getSimpleJdbcTemplate().update(sql.toString(), params);
     370        return ((affectedRows > 0) ? getInternalID(externalID) : null);
     371    }
     372
     373    @Override
     374    public boolean addAnnotationToNotebook(Number notebookID, Number annotationID) {
     375
     376        if (notebookID == null) {
     377            loggerNotebookDao.debug("notebookID: " + nullArgument);
     378            return false;
     379        }
     380
     381        if (annotationID == null) {
     382            loggerNotebookDao.debug("annotationID: " + nullArgument);
     383            return false;
     384        }
     385
     386        Map<String, Object> params = new HashMap<String, Object>();
     387        params.put("notebookID", notebookID);
     388        params.put("annotationID", annotationID);
     389
     390        StringBuilder sql = new StringBuilder("INSERT INTO ");
     391        sql.append(notebooksAnnotationsTableName).append("(").append(notebook_id).append(",").append(annotation_id);
     392        sql.append(",").append(" ) VALUES (:notebookID, :annotationID)");
     393        int affectedRows = getSimpleJdbcTemplate().update(sql.toString(), params);
     394        return (affectedRows > 0);
     395    }
     396
     397    @Override
     398    public boolean addPermissionToNotebook(Number notebookID, Number principalID, Permission permission) {
     399        if (notebookID == null) {
     400            loggerNotebookDao.debug("notebookID: " + nullArgument);
     401            return false;
     402        }
     403
     404        if (principalID == null) {
     405            loggerNotebookDao.debug("principalID: " + nullArgument);
     406            return false;
     407        }
     408
     409        if (permission == null) {
     410            loggerNotebookDao.debug("premission: " + nullArgument);
     411            return false;
     412        }
     413
     414        Map<String, Object> params = new HashMap<String, Object>();
     415        params.put("notebookID", notebookID);
     416        params.put("principalID", principalID);
     417        params.put("permission", permission.value());
     418
     419        StringBuilder sql = new StringBuilder("INSERT INTO ");
     420        sql.append(notebookPermissionsTableName).append("(").append(notebook_id).append(",").append(principal_id);
     421        sql.append(",").append(this.permission).
     422                append(" ) VALUES (:notebookID, :principalID, :permission)");
     423        int affectedRows = getSimpleJdbcTemplate().update(sql.toString(), params);
     424        return (affectedRows > 0);
     425    }
     426
    148427    /**
    149      *
    150      * @param notebookID
    151      * @return true if updated, false otherwise. Logs the reason if the notebook is not updated.
     428     *
     429     * DELETERS
     430     *
     431     *
    152432     */
    153433    @Override
    154     public boolean updateNotebookMetadata(Number notebookID){
    155         return false;
    156     }
    157      /**
    158      *
    159      * ADDERS
    160      *
    161      *
    162      */
    163    
    164     @Override
    165     public Number createNotebook(Notebook notebook){
    166         return null;
    167     }
    168    
    169     @Override
    170     public boolean addAnnotationToNotebook(Number noteboookId, Number AnnotationID){
    171         return false;
    172     }
    173    
    174    
    175     /**
    176      *
    177      * DELETERS (ADDER)
    178      *
    179      *
    180      */
    181    
    182     @Override
    183     public boolean deleteannotationFromNotebook(Number notebookID, Number annotationID){
    184         return false;
    185     }
    186    
    187     @Override
    188     public boolean deleteNotebook(Number notebookID){
    189         return false;
     434    public boolean deleteAnnotationFromNotebook(Number notebookID, Number annotationID) {
     435        if (notebookID != null) {
     436            if (annotationID != null) {
     437                Map<String, Number> params = new HashMap();
     438                params.put("notebookID", notebookID);
     439                params.put("annotationID", annotationID);
     440                StringBuilder sql = new StringBuilder("DELETE FROM ");
     441                sql.append(notebooksAnnotationsTableName).append(" WHERE ").append(notebook_id).append(" = :notebookID AND ").
     442                        append(annotation_id).append(" = :annotationID");
     443                int affectedRows = getSimpleJdbcTemplate().update(sql.toString(), params);
     444                return (affectedRows > 0);
     445            } else {
     446                loggerNotebookDao.debug("annotationID: " + nullArgument);
     447                return false;
     448            }
     449        } else {
     450            loggerNotebookDao.debug("notebookID: " + nullArgument);
     451            return false;
     452        }
     453    }
     454
     455    @Override
     456    public boolean deleteNotebookPrincipalPermission(Number notebookID, Number principalID) {
     457        if (notebookID != null) {
     458            if (principalID != null) {
     459                Map<String, Number> params = new HashMap();
     460                params.put("notebookID", notebookID);
     461                params.put("principalID", principalID);
     462                StringBuilder sqlPermissions = new StringBuilder("DELETE FROM ");
     463                sqlPermissions.append(notebookPermissionsTableName).append(" WHERE ").append(notebook_id).append(" = :notebookID AND ").
     464                        append(principal_id).append(" = :principalID");
     465                int affectedRows = getSimpleJdbcTemplate().update(sqlPermissions.toString(), params);
     466                return (affectedRows > 0);
     467            } else {
     468                loggerNotebookDao.debug("principalID: " + nullArgument);
     469                return false;
     470            }
     471        } else {
     472            loggerNotebookDao.debug("notebookID: " + nullArgument);
     473            return false;
     474        }
     475    }
     476
     477    @Override
     478    public boolean deleteAllAnnotationsFromNotebook(Number notebookID) {
     479        if (notebookID != null) {
     480            StringBuilder sql = new StringBuilder("DELETE FROM ");
     481            sql.append(notebooksAnnotationsTableName).append(" WHERE ").append(notebook_id).append(" = ? ");
     482            int affectedRows = getSimpleJdbcTemplate().update(sql.toString(), notebookID);
     483            return (affectedRows > 0);
     484        } else {
     485            loggerNotebookDao.debug("notebookID: " + nullArgument);
     486            return false;
     487        }
     488    }
     489
     490    @Override
     491    public boolean deleteAllPermissionsForNotebook(Number notebookID) {
     492        if (notebookID != null) {
     493            StringBuilder sqlPermissions = new StringBuilder("DELETE FROM ");
     494            sqlPermissions.append(notebookPermissionsTableName).append(" WHERE ").append(notebook_id).append(" = ? ");
     495            int affectedRows = getSimpleJdbcTemplate().update(sqlPermissions.toString(), notebookID);
     496            return (affectedRows > 0);
     497        } else {
     498            loggerNotebookDao.debug("notebookID: " + nullArgument);
     499            return false;
     500        }
     501    }
     502
     503    @Override
     504    public boolean deleteNotebook(Number notebookID) {
     505        if (notebookID != null) {
     506            StringBuilder sql = new StringBuilder("DELETE FROM ");
     507            sql.append(notebookTableName).append(" WHERE ").append(notebook_id).append(" = ? ");
     508            int affectedRows = getSimpleJdbcTemplate().update(sql.toString(), notebookID);
     509            return (affectedRows > 0);
     510        } else {
     511            loggerNotebookDao.debug("notebookID: " + nullArgument);
     512            return false;
     513        }
    190514    }
    191515}
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/impl/JdbcResourceDao.java

    r4491 r4495  
    8282    final static protected String fragment_descriptor = "fragment_descriptor";
    8383    final static protected String fragment_descriptor_in_cached = "fragment_descriptor_in_cached";
    84     // derived string constants: table+field names
    8584    final static protected String annotationStar = annotationTableName + ".*";
    86     final static protected String annotationAnnotation_id = annotationTableName + "." + annotation_id;
    87     final static protected String annotationExternal_id = annotationTableName + "." + external_id;
    88     final static protected String notebookStar = notebookTableName + ".*";
    89     final static protected String notebookNotebook_id = notebookTableName + "." + notebook_id;
    90     final static protected String notebookTitle = notebookTableName + "." + title;
    91     final static protected String notebookExternal_id = notebookTableName + "." + external_id;
    92     final static protected String notebooksAnnotationsTableNameAnnotation_id = notebooksAnnotationsTableName + "." + annotation_id;
    93     final static protected String principalPrincipal_id = principalTableName + "." + principal_id;
    94     final static protected String principalExternal_id = principalTableName + "." + external_id;
    9585    final static protected String cachedRepresentationStar = cachedRepresentationTableName + ".*";
    9686    final static protected String targetStar = targetTableName + ".*";
     
    202192        }
    203193    };
    204     protected final RowMapper<Number> TargetIDRowMapper = new RowMapper<Number>() {
     194    protected final RowMapper<Number> targetIDRowMapper = new RowMapper<Number>() {
    205195        @Override
    206196        public Number mapRow(ResultSet rs, int rowNumber) throws SQLException {
     
    234224    };
    235225   
    236     protected final RowMapper<Number> notebookOwnerIDRowMapper = new RowMapper<Number>() {
    237         @Override
    238         public Number mapRow(ResultSet rs, int rowNumber) throws SQLException {
    239             return rs.getInt(notebookOwner_id);
    240         }
    241     };
     226
    242227
    243228    @Override
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/impl/JdbcUserDao.java

    r4491 r4495  
    9999
    100100        StringBuilder sqlNotebooks = new StringBuilder("SELECT ");
    101         sqlNotebooks.append(notebookOwner_id).append(" FROM ").append(notebookTableName).append(" WHERE ").append(notebookOwner_id).append("= ? LIMIT 1");
    102         List<Number> resultNotebooks = getSimpleJdbcTemplate().query(sqlNotebooks.toString(), notebookOwnerIDRowMapper, userID);
     101        sqlNotebooks.append(owner_id).append(" FROM ").append(notebookTableName).append(" WHERE ").append(owner_id).append("= ? LIMIT 1");
     102        List<Number> resultNotebooks = getSimpleJdbcTemplate().query(sqlNotebooks.toString(), ownerIDRowMapper, userID);
    103103        if (resultNotebooks.size() > 0) {
    104104            return true;
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/test/java/eu/dasish/annotation/backend/dao/impl/DBIntegrityServiceTest.java

    r4491 r4495  
    2222import eu.dasish.annotation.backend.dao.AnnotationDao;
    2323import eu.dasish.annotation.backend.dao.CachedRepresentationDao;
     24import eu.dasish.annotation.backend.dao.NotebookDao;
    2425import eu.dasish.annotation.backend.dao.TargetDao;
    2526import eu.dasish.annotation.backend.dao.UserDao;
     
    6263@ContextConfiguration({"/spring-test-config/dataSource.xml", "/spring-test-config/mockeryDao.xml", "/spring-test-config/mockAnnotationDao.xml",
    6364    "/spring-test-config/mockUserDao.xml", "/spring-test-config/mockTargetDao.xml", "/spring-test-config/mockCachedRepresentationDao.xml",
     65    "/spring-test-config/mockNotebookDao.xml",
    6466    "/spring-config/dbIntegrityService.xml"})
    6567public class DBIntegrityServiceTest {
     
    7779    @Autowired
    7880    private AnnotationDao annotationDao;
     81    @Autowired
     82    private NotebookDao notebookDao;
     83   
    7984    TestInstances testInstances = new TestInstances(TestBackendConstants._TEST_SERVLET_URI);
    8085
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/test/java/eu/dasish/annotation/backend/rest/AnnotationsTest.java

    r4461 r4495  
    8989        // sorry for the duplication, but JerseyTest is not aware of
    9090        // @ContextConfiguration
    91         return "classpath:spring-config/componentscan.xml, classpath:spring-config/annotationDao.xml, classpath:spring-config/userDao.xml, classpath:spring-config/targetDao.xml, classpath:spring-config/cachedRepresentationDao.xml, classpath:spring-config/dbIntegrityService.xml, classpath:spring-config/jaxbMarshallerFactory.xml, classpath:spring-test-config/dataSource.xml";
     91        return "classpath:spring-config/componentscan.xml, classpath:spring-config/notebookDao.xml, classpath:spring-config/annotationDao.xml, classpath:spring-config/userDao.xml, classpath:spring-config/targetDao.xml, classpath:spring-config/cachedRepresentationDao.xml, classpath:spring-config/dbIntegrityService.xml, classpath:spring-config/jaxbMarshallerFactory.xml, classpath:spring-test-config/dataSource.xml";
    9292    }
    9393   
Note: See TracChangeset for help on using the changeset viewer.