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 | */ |
---|
18 | package eu.dasish.annotation.backend.dao; |
---|
19 | |
---|
20 | import eu.dasish.annotation.schema.Annotation; |
---|
21 | import eu.dasish.annotation.schema.AnnotationBody; |
---|
22 | import eu.dasish.annotation.schema.AnnotationInfo; |
---|
23 | import eu.dasish.annotation.schema.Permission; |
---|
24 | import java.sql.SQLException; |
---|
25 | import java.sql.Timestamp; |
---|
26 | import java.util.List; |
---|
27 | import 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 | |
---|
36 | public 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 Map<Annotation, Number> 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, String text, String namespace, Number ownerID, Timestamp after, Timestamp before); |
---|
69 | |
---|
70 | /** |
---|
71 | * unit test is missing |
---|
72 | * @param annotationIDs |
---|
73 | * @return pair <annotationInfo, owner_id> for the annotation with the internal annotationID. |
---|
74 | * |
---|
75 | */ |
---|
76 | public Map<AnnotationInfo, Number> getAnnotationInfoWithoutTargets(Number annotationID); |
---|
77 | |
---|
78 | /** |
---|
79 | * |
---|
80 | * @param annotationIDs |
---|
81 | * @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. |
---|
82 | */ |
---|
83 | public List<String> getAnnotationREFs(List<Number> annotationIDs); |
---|
84 | |
---|
85 | /** |
---|
86 | * |
---|
87 | * @param TargetIDs |
---|
88 | * @return the list of annotationdIDs of the annotations which target Targets are from "TargetIDs" list. |
---|
89 | */ |
---|
90 | public List<Number> retrieveAnnotationList(List<Number> TargetIDs); |
---|
91 | |
---|
92 | |
---|
93 | /** |
---|
94 | * |
---|
95 | * @param annotationID |
---|
96 | * @return the list of the internal IDs of all the target Targets of "annotationID". |
---|
97 | */ |
---|
98 | public List<Number> retrieveTargetIDs(Number annotationID); |
---|
99 | |
---|
100 | |
---|
101 | /** |
---|
102 | * |
---|
103 | * @param annotationID |
---|
104 | * @return all the pairs (user-permission) for "annotationId" from the table annotations_principals permissions. |
---|
105 | */ |
---|
106 | public List<Map<Number, String>> getPermissions(Number annotationID); |
---|
107 | |
---|
108 | /** |
---|
109 | * |
---|
110 | * @param annotationID |
---|
111 | * @param userID |
---|
112 | * @return permission of the userID w.r.t. annotationID, or null if the permission is not given |
---|
113 | */ |
---|
114 | public Permission getPermission(Number annotationID, Number userID); |
---|
115 | |
---|
116 | public List<Number> getAnnotationIDsForUserWithPermission(Number userID, String[] permissionStrings); |
---|
117 | |
---|
118 | |
---|
119 | /** |
---|
120 | * |
---|
121 | * @param annotationID |
---|
122 | * @return true if "annotationID" is mentioned in at least one of the joint tables: |
---|
123 | * "annotations_targets", "annotations_principals_permissions", "notebook_annotations". |
---|
124 | * Otherwise return "false". |
---|
125 | */ |
---|
126 | public boolean annotationIsInUse(Number annotationID); |
---|
127 | |
---|
128 | /** |
---|
129 | * ADDERS |
---|
130 | */ |
---|
131 | |
---|
132 | /** |
---|
133 | * |
---|
134 | * @param annotationID |
---|
135 | * @param targetID |
---|
136 | * @return # updated rows in the joint table "annotations_target_Targets". |
---|
137 | * @throws SQLException |
---|
138 | * Connects the annotation to its target Target by adding the pair (annotationID, TargetID) to the joint table. |
---|
139 | */ |
---|
140 | public int addAnnotationTarget(Number annotationID, Number targetID); |
---|
141 | |
---|
142 | |
---|
143 | /** |
---|
144 | * |
---|
145 | * @param annotationID |
---|
146 | * @param userID |
---|
147 | * @param permission |
---|
148 | * @return # rows added to the table "annotations_principals_permissions" |
---|
149 | * Sets the "permission" for the "userID" w.r.t. the annotation with "annotationID". |
---|
150 | */ |
---|
151 | public int addAnnotationPrincipalPermission(Number annotationID, Number userID, Permission permission); |
---|
152 | |
---|
153 | |
---|
154 | |
---|
155 | /** |
---|
156 | * |
---|
157 | * @param annotation: the object to be added to the table "annotation". |
---|
158 | * @return the internal ID of the added annotation, if it is added, or null otherwise. |
---|
159 | **/ |
---|
160 | |
---|
161 | public Number addAnnotation(Annotation annotation, Number ownerID); |
---|
162 | |
---|
163 | |
---|
164 | /////// UPDATERS ////////////////// |
---|
165 | |
---|
166 | |
---|
167 | public int updateAnnotationBody(Number annotationID, String text, String mimeType, Boolean isXml); |
---|
168 | |
---|
169 | |
---|
170 | |
---|
171 | /** |
---|
172 | * |
---|
173 | * @param annotation |
---|
174 | * @param ownerID |
---|
175 | * @return # of updated rows in "annotation" table after updating the annotation. Should return 1 if update happens |
---|
176 | * @throws SQLException |
---|
177 | */ |
---|
178 | public int updateAnnotation(Annotation annotation, Number ownerID); |
---|
179 | |
---|
180 | |
---|
181 | /** |
---|
182 | * |
---|
183 | * @param annotationID |
---|
184 | * @param userID |
---|
185 | * @param permission |
---|
186 | * @return # rows updated to the table "annotations_principals_permissions" |
---|
187 | * Sets the "permission" for the "userID" w.r.t. the annotation with "annotationID". |
---|
188 | */ |
---|
189 | public int updateAnnotationPrincipalPermission(Number annotationID, Number userID, Permission permission); |
---|
190 | |
---|
191 | |
---|
192 | |
---|
193 | |
---|
194 | /** |
---|
195 | * DELETERS |
---|
196 | */ |
---|
197 | |
---|
198 | /** |
---|
199 | * |
---|
200 | * @param annotationId |
---|
201 | * @return # rows in the table "annotation". It should be "1" if the annotation with "annotationID" is successfully deleted, and "0" otherwise. |
---|
202 | */ |
---|
203 | |
---|
204 | |
---|
205 | |
---|
206 | public int deleteAnnotation(Number annotationId); |
---|
207 | |
---|
208 | /** |
---|
209 | * |
---|
210 | * @param annotationId |
---|
211 | * @return # removed rows in the table "annotations_target_Targets". |
---|
212 | */ |
---|
213 | |
---|
214 | public int deleteAllAnnotationTarget(Number annotationID); |
---|
215 | |
---|
216 | |
---|
217 | /** |
---|
218 | * |
---|
219 | * @param annotationID |
---|
220 | * @return # removed rows in the table "annotations_principals_permissions". |
---|
221 | * @throws SQLException |
---|
222 | */ |
---|
223 | public int deleteAnnotationPrincipalPermissions(Number annotationID); |
---|
224 | |
---|
225 | /* |
---|
226 | * HELPERS |
---|
227 | */ |
---|
228 | |
---|
229 | public String[] retrieveBodyComponents(AnnotationBody annotationBody); |
---|
230 | |
---|
231 | } |
---|