source: DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/AnnotationDao.java @ 4429

Last change on this file since 4429 was 4429, checked in by olhsha, 10 years ago

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

File size: 7.5 KB
Line 
1/*
2 * Copyright (C) 2013 DASISH
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version 2
7 * of the License, or (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
17 */
18package eu.dasish.annotation.backend.dao;
19
20import eu.dasish.annotation.schema.Annotation;
21import eu.dasish.annotation.schema.AnnotationBody;
22import eu.dasish.annotation.schema.AnnotationInfo;
23import eu.dasish.annotation.schema.Permission;
24import java.sql.SQLException;
25import java.sql.Timestamp;
26import java.util.List;
27import java.util.Map;
28
29/**
30 * Created on : Jun 27, 2013, 10:34:13 AM
31 *
32 * @author Peter Withers <peter.withers@mpi.nl>
33 */
34
35
36public interface AnnotationDao extends ResourceDao{
37   
38   
39    /**
40     * GETTERS
41     */
42   
43    /**
44     *
45     * @param annotationID
46     * @return the pair (annotation, owner_id) with empty list of Targets.
47     *
48     * (Constructing a complete Annotation object using  "getAnnotationWithoutTargets" and "retrieveTargetIDs" is done in "DaoDispatchter".)
49     *
50     */
51    public Annotation getAnnotationWithoutTargetsAndPermissions(Number annotationID);
52   
53   
54     /**
55     *
56     * @param annotationIDs: the list of annotationID-s from which the resulting annotations are to be selected.
57     * @param text: the text which the resulting annotations' bodies must contain.* @param namespace TODO: do not know what to do with it
58     * @param ownerID: the resulting annotations are owned by the owner "ownerID".
59     * @param after: the resulting annotations must have timestamp later than "after".
60     * @param before: the resulting annotations must have timestamp earlier than "before".
61     * @return the sub-list of internal annotation identifiers from the list "internalIDs" for annotations
62     * -- bodies of which contain the "text",
63     * -- to which inlogged user has "access",
64     * -- owned by "owner",
65     * -- added to the database between "before" and "after" time-dates.
66     *
67     */
68    public List<Number> getFilteredAnnotationIDs(List<Number> annotationIDs, Number ownerID, String text, String namespace, String after, String before);
69     
70    public List<Number> getAllAnnotationIDs();
71   
72       /**
73     * unit test is missing
74     * @param annotationIDs
75     * @return annotationInfo  for the annotation with the internal annotationID.
76     *
77     */
78    public AnnotationInfo getAnnotationInfoWithoutTargets(Number annotationID);   
79   
80    /**
81     *
82     * @param annotationIDs
83     * @return list of reTarget references where an i-th reference is constructed from the external identifier of the annotation with the i-th internal identifier from the list.
84     */
85    public List<String> getAnnotationREFs(List<Number> annotationIDs); 
86   
87    /**
88     *
89     * @param TargetIDs
90     * @return the list of annotationdIDs of the annotations which target Targets are from "TargetIDs" list.
91     */
92    public List<Number> retrieveAnnotationList(List<Number> TargetIDs);
93   
94   
95       /**
96     *
97     * @param annotationID
98     * @return the list of the internal IDs of all the target Targets of "annotationID".
99     */
100    public List<Number> retrieveTargetIDs(Number annotationID);   
101   
102   
103       /**
104     *
105     * @param annotationID
106     * @return all the pairs (user-permission) for "annotationId" from the table annotations_principals permissions.
107     */
108    public List<Map<Number, String>>  getPermissions(Number annotationID);
109   
110    public Number  getOwner(Number annotationID);
111   
112    /**
113     *
114     * @param annotationID
115     * @param userID
116     * @return permission of the userID w.r.t. annotationID, or null if the permission is not given
117     */ 
118    public Permission  getPermission(Number annotationID, Number userID);
119   
120    public List<Number> getAnnotationIDsForUserWithPermission(Number userID, String[] permissionStrings);
121   
122   
123    /**
124     *
125     * @param annotationID
126     * @return true if "annotationID" is mentioned in at least one of the joint tables:
127     * "annotations_targets", "annotations_principals_permissions", "notebook_annotations".
128     * Otherwise return "false".
129     */
130    public boolean annotationIsInUse(Number annotationID);
131   
132    /**
133     * ADDERS
134     */
135   
136    /**
137     *
138     * @param annotationID
139     * @param targetID
140     * @return # updated rows in the joint table "annotations_target_Targets".
141     * @throws SQLException
142     * Connects the annotation to its target Target by adding the pair (annotationID, TargetID) to the joint table.
143     */ 
144    public int addAnnotationTarget(Number annotationID, Number targetID);
145   
146   
147    /**
148     *
149     * @param annotationID
150     * @param userID
151     * @param permission
152     * @return # rows added to the table "annotations_principals_permissions"
153     * Sets the "permission" for the "userID" w.r.t. the annotation with "annotationID".
154     */
155    public int addAnnotationPrincipalPermission(Number annotationID, Number userID, Permission permission);
156   
157   
158 
159     /**
160     *
161     * @param annotation: the object to be added to the table "annotation".
162     * @return  the internal ID of the added annotation, if it is added, or null otherwise.
163     **/
164   
165    public Number addAnnotation(Annotation annotation, Number newOwnerID);
166 
167     
168    /////// UPDATERS //////////////////
169   
170   
171    public int updateAnnotationBody(Number annotationID, String text, String mimeType, Boolean isXml);
172   
173   
174   
175    /**
176     *
177     * @param annotation
178     * @return # of updated rows in "annotation" table after updating the annotation. Should return 1 if update  happens
179     * @throws SQLException
180     */
181    public int updateAnnotation(Annotation annotation, Number ownerID);
182   
183   
184     /**
185     *
186     * @param annotationID
187     * @param userID
188     * @param permission
189     * @return # rows updated to the table "annotations_principals_permissions"
190     * Sets the "permission" for the "userID" w.r.t. the annotation with "annotationID".
191     */
192    public int updateAnnotationPrincipalPermission(Number annotationID, Number userID, Permission permission);
193   
194   
195   
196   
197   /**
198    * DELETERS
199    */
200   
201    /**
202     *
203     * @param annotationId
204     * @return # rows in the table "annotation". It should be "1" if the annotation with "annotationID" is successfully deleted, and "0" otherwise.
205     */
206   
207   
208   
209    public int deleteAnnotation(Number annotationId);
210   
211    /**
212     *
213     * @param annotationId
214     * @return # removed rows in the table "annotations_target_Targets".
215     */
216   
217    public int deleteAllAnnotationTarget(Number annotationID);
218   
219   
220   /**
221    *
222    * @param annotationID
223    * @return # removed rows in the table "annotations_principals_permissions".
224    * @throws SQLException
225    */
226    public int deleteAnnotationPrincipalPermissions(Number annotationID);
227   
228    public int deleteAnnotationPrincipalPermission(Number annotationID, Number userID);
229   
230    /*
231     * HELPERS
232     */
233   
234    public String[] retrieveBodyComponents(AnnotationBody annotationBody);
235
236}
Note: See TracBrowser for help on using the repository browser.