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 | |
---|
21 | import eu.dasish.annotation.schema.Annotation; |
---|
22 | import eu.dasish.annotation.schema.AnnotationBody; |
---|
23 | import eu.dasish.annotation.schema.AnnotationInfoList; |
---|
24 | import eu.dasish.annotation.schema.CachedRepresentationInfo; |
---|
25 | import eu.dasish.annotation.schema.Permission; |
---|
26 | import eu.dasish.annotation.schema.UserWithPermissionList; |
---|
27 | import eu.dasish.annotation.schema.ReferenceList; |
---|
28 | import eu.dasish.annotation.schema.Target; |
---|
29 | import eu.dasish.annotation.schema.TargetInfo; |
---|
30 | import eu.dasish.annotation.schema.User; |
---|
31 | import java.io.InputStream; |
---|
32 | import java.sql.SQLException; |
---|
33 | import java.sql.Timestamp; |
---|
34 | import java.util.List; |
---|
35 | import java.util.Map; |
---|
36 | import java.util.UUID; |
---|
37 | |
---|
38 | /** |
---|
39 | * |
---|
40 | * @author olhsha |
---|
41 | **/ |
---|
42 | |
---|
43 | |
---|
44 | |
---|
45 | |
---|
46 | public interface DBIntegrityService{ |
---|
47 | |
---|
48 | public void setServiceURI(String serviceURI); |
---|
49 | |
---|
50 | |
---|
51 | /** |
---|
52 | * GETTERS |
---|
53 | */ |
---|
54 | |
---|
55 | /** |
---|
56 | * |
---|
57 | * @param UUID |
---|
58 | * @return the internal identifier of the annotations with "externalID", or null if no such annotation. |
---|
59 | */ |
---|
60 | 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. |
---|
66 | */ |
---|
67 | UUID getAnnotationExternalIdentifier(Number annotationID); |
---|
68 | |
---|
69 | |
---|
70 | Number getAnnotationInternalIdentifierFromURI(String uri); |
---|
71 | |
---|
72 | |
---|
73 | /** |
---|
74 | * |
---|
75 | * @param word |
---|
76 | * @param text |
---|
77 | * @param access |
---|
78 | * @param namespace |
---|
79 | * @param owner |
---|
80 | * @param after |
---|
81 | * @param before |
---|
82 | * @return the list of internal id-s of the annotations such that: |
---|
83 | * -- Targets' links of which contain "link" (as a substring), |
---|
84 | * -- serialized bodies of which contain "text", |
---|
85 | * -- current user has "access" (owner, reader, writer) to them, |
---|
86 | * -- namespace ???, |
---|
87 | * -- owned by "owner", |
---|
88 | * -- created after time-samp "after and before time-stamp "before". |
---|
89 | */ |
---|
90 | List<Number> getFilteredAnnotationIDs(String link, String text, Number inloggedUserID, String access, String namespace, UUID |
---|
91 | owner, Timestamp after, Timestamp before); |
---|
92 | |
---|
93 | |
---|
94 | |
---|
95 | /** |
---|
96 | * |
---|
97 | @param word |
---|
98 | * @param text |
---|
99 | * @param access |
---|
100 | * @param namespace |
---|
101 | * @param owner |
---|
102 | * @param after |
---|
103 | * @param before |
---|
104 | * @return the list of the annotationInfos of the annotations such that: |
---|
105 | * -- Targets' links of which contain "link" (as a substring), |
---|
106 | * -- serialized bodies of which contain "text", |
---|
107 | * -- current user has "access" (owner, reader, writer) to them, |
---|
108 | * -- namespace ???, |
---|
109 | * -- owned by "owner", |
---|
110 | * -- created after time-samp "after and before time-stamp "before". |
---|
111 | */ |
---|
112 | AnnotationInfoList getFilteredAnnotationInfos(String word, String text, Number inloggedUserID, String access, String namespace, UUID |
---|
113 | ownerID, Timestamp after, Timestamp before); |
---|
114 | |
---|
115 | /** |
---|
116 | * |
---|
117 | * @param userID |
---|
118 | * @return the external identifier of the user "userID", or null if no such user. |
---|
119 | */ |
---|
120 | UUID getUserExternalIdentifier(Number userID); |
---|
121 | |
---|
122 | /** |
---|
123 | * |
---|
124 | * @param externalID |
---|
125 | * @return the internal identifier of the user with "externalID", or null if there is no such user. |
---|
126 | */ |
---|
127 | Number getUserInternalIdentifier(UUID externalID); |
---|
128 | |
---|
129 | /** |
---|
130 | * |
---|
131 | * @param cachedID |
---|
132 | * @return the external identifier of the cached representation "cachedID", or null if no such one. |
---|
133 | */ |
---|
134 | UUID getCachedRepresentationExternalIdentifier(Number cachedID); |
---|
135 | |
---|
136 | /** |
---|
137 | * |
---|
138 | * @param externalID |
---|
139 | * @return the internal identifier of the cachedRepresentation with "externalID", or null if there is no such one. |
---|
140 | */ |
---|
141 | Number getCachedRepresentationInternalIdentifier(UUID externalID); |
---|
142 | |
---|
143 | Number getTargetInternalIdentifier(UUID externalID); |
---|
144 | |
---|
145 | String getTargetURI(Number targetID); |
---|
146 | |
---|
147 | UUID getTargetExternalIdentifier(Number targetID); |
---|
148 | |
---|
149 | String getUserURI(Number userID); |
---|
150 | |
---|
151 | /** |
---|
152 | * |
---|
153 | * @param internalID |
---|
154 | * @return CachedRepresentationInfo (i.e. "metadata") for cached representation with the internal id "intenalID" |
---|
155 | */ |
---|
156 | CachedRepresentationInfo getCachedRepresentationInfo(Number internalID); |
---|
157 | |
---|
158 | /** |
---|
159 | * |
---|
160 | * @param annotationID |
---|
161 | * @return the object Annotation generated from the tables "annotation", "annotations_target_Targets", "Target", "annotations_principals_permissions". |
---|
162 | * @throws SQLException |
---|
163 | */ |
---|
164 | Annotation getAnnotation(Number annotationID); |
---|
165 | |
---|
166 | /** |
---|
167 | * |
---|
168 | * @param annotationID |
---|
169 | * @return the object TargetList containing all target Targets of the annotationID |
---|
170 | * @throws SQLException |
---|
171 | */ |
---|
172 | ReferenceList getAnnotationTargets(Number annotationID); |
---|
173 | |
---|
174 | |
---|
175 | /** |
---|
176 | * |
---|
177 | * @param annotationID |
---|
178 | * @return the list of targetURI's for which there is no cached representation |
---|
179 | */ |
---|
180 | List<String> getTargetsWithNoCachedRepresentation(Number annotationID); |
---|
181 | |
---|
182 | 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 |
---|
188 | */ |
---|
189 | public UserWithPermissionList getPermissionsForAnnotation(Number annotationID); |
---|
190 | |
---|
191 | /** |
---|
192 | * |
---|
193 | * @param TargetID |
---|
194 | * @return the list of the external version ID-s that refers to the same source (link) as targetID |
---|
195 | */ |
---|
196 | public ReferenceList getTargetsForTheSameLinkAs(Number targetID); |
---|
197 | |
---|
198 | /** |
---|
199 | * |
---|
200 | * @param cachedID |
---|
201 | * @return BLOB of the cachedID |
---|
202 | */ |
---|
203 | public InputStream getCachedRepresentationBlob(Number cachedID) ; |
---|
204 | |
---|
205 | |
---|
206 | |
---|
207 | public Target getTarget(Number internalID); |
---|
208 | |
---|
209 | /** |
---|
210 | * |
---|
211 | * @param userID |
---|
212 | * @return user with "userID" |
---|
213 | */ |
---|
214 | public User getUser(Number userID); |
---|
215 | |
---|
216 | /** |
---|
217 | * |
---|
218 | * @param eMail |
---|
219 | * @return user with e-mail "eMail" |
---|
220 | */ |
---|
221 | public User getUserByInfo(String eMail); |
---|
222 | |
---|
223 | |
---|
224 | public String getUserRemoteID(Number internalID); |
---|
225 | |
---|
226 | 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 | |
---|
237 | |
---|
238 | |
---|
239 | /** |
---|
240 | * UPDATERS |
---|
241 | */ |
---|
242 | |
---|
243 | |
---|
244 | |
---|
245 | /** |
---|
246 | * |
---|
247 | * @param userID |
---|
248 | * @param annotation |
---|
249 | * @return 1 of the annotation if it is updated |
---|
250 | */ |
---|
251 | int updateUsersAnnotation(Number userID, Annotation annotation); |
---|
252 | |
---|
253 | |
---|
254 | |
---|
255 | /** |
---|
256 | * |
---|
257 | * @param userID |
---|
258 | * @param annotationBody |
---|
259 | * @return 1 of the annotation if it is updated |
---|
260 | */ |
---|
261 | int updateAnnotationBody(Number internalID, AnnotationBody annotationBody); |
---|
262 | |
---|
263 | |
---|
264 | |
---|
265 | /** |
---|
266 | * |
---|
267 | * @param annotationID |
---|
268 | * @param userID |
---|
269 | * @param permission |
---|
270 | * @return # rows updated to the table "annotations_principals_permissions" |
---|
271 | * Sets the "permission" for the "userID" w.r.t. the annotation with "annotationID". |
---|
272 | */ |
---|
273 | public int updateAnnotationPrincipalPermission(Number annotationID, Number userID, Permission permission); |
---|
274 | |
---|
275 | /** |
---|
276 | * |
---|
277 | * @param annotationID |
---|
278 | * @param permissionList |
---|
279 | * @return # of rows updated or added in the table annotations_principals_permissions |
---|
280 | */ |
---|
281 | public int updatePermissions(Number annotationID, UserWithPermissionList permissionList); |
---|
282 | |
---|
283 | public Number updateUser(User user); |
---|
284 | |
---|
285 | /** |
---|
286 | * ADDERS |
---|
287 | */ |
---|
288 | /** |
---|
289 | * |
---|
290 | * @param targetID |
---|
291 | * @param cachedInfo |
---|
292 | * @param cachedBlob |
---|
293 | * @return result[0] = # updated rows in the table "Targets_cached_representations" (must be 1 or 0). |
---|
294 | * result[1] = the internal ID of the added cached (a new one if "cached" was new for the Data Base). |
---|
295 | */ |
---|
296 | Number[] addCachedForTarget(Number targetID, String fragmentDescriptor, CachedRepresentationInfo cachedInfo, InputStream cachedBlob); |
---|
297 | |
---|
298 | |
---|
299 | /** |
---|
300 | * |
---|
301 | * @param annotationID |
---|
302 | * @param targets |
---|
303 | * @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. |
---|
304 | * @throws SQLException |
---|
305 | */ |
---|
306 | Map<String, String> addTargetsForAnnotation(Number annotationID, List<TargetInfo> targets); |
---|
307 | |
---|
308 | /** |
---|
309 | * |
---|
310 | * @param userID |
---|
311 | * @param annotation |
---|
312 | * @return the internalId of the just added "annotation" (or null if it is not added) by the owner "userID". |
---|
313 | * calls "addTargetsForAnnotation" |
---|
314 | * @throws SQLException |
---|
315 | */ |
---|
316 | Number addUsersAnnotation(Number userID, Annotation annotation); |
---|
317 | |
---|
318 | /** |
---|
319 | * |
---|
320 | * @param user |
---|
321 | * @param remoteID is got from the server |
---|
322 | * @return the internal Id of the just added "user", or null if it was not added for some reason (already exists) |
---|
323 | * @throws SQLException |
---|
324 | */ |
---|
325 | Number addUser(User user, String remoteID); |
---|
326 | |
---|
327 | int addAnnotationPrincipalPermission(Number annotationID, Number userID, Permission permission); |
---|
328 | |
---|
329 | /** |
---|
330 | * DELETERS |
---|
331 | */ |
---|
332 | |
---|
333 | /** |
---|
334 | * |
---|
335 | * @param userID |
---|
336 | * @return # of affected rows in the table "principal". |
---|
337 | * It is 1 if the userId is found and deleted; |
---|
338 | * it is 0 if it is not found or not deleted, e.g. because it is in use in the table "annotationsPreincipalsPermissions" |
---|
339 | */ |
---|
340 | public int deleteUser(Number userID); |
---|
341 | |
---|
342 | /** |
---|
343 | * |
---|
344 | * @param TargetID |
---|
345 | * @param cachedID |
---|
346 | * @return result[0] = # deleted rows in the table "Targets_cached_representations" (1, or 0). |
---|
347 | * result[1] = # deleted rows in the table "cached_representation" (should be 0 if the cached representation is in use by some other Target???). |
---|
348 | */ |
---|
349 | int[] deleteCachedRepresentationOfTarget(Number TargetID, Number cachedID) ; |
---|
350 | |
---|
351 | |
---|
352 | |
---|
353 | |
---|
354 | |
---|
355 | /** |
---|
356 | * |
---|
357 | * @param targetID |
---|
358 | * @return |
---|
359 | * result[0] = # deleted rows in the table "targets_cached_representations". |
---|
360 | * result[1] = # deleted rows in the table "cached_representation". |
---|
361 | **/ |
---|
362 | |
---|
363 | int[] deleteAllCachedRepresentationsOfTarget(Number versionID); |
---|
364 | |
---|
365 | |
---|
366 | |
---|
367 | /** |
---|
368 | * |
---|
369 | * @param annotationID |
---|
370 | * @return result[0] = # deleted rows in the table "annotation" (1 or 0). |
---|
371 | * result[1] = # deleted rows in the table "annotations_principals_permissions". |
---|
372 | * result[2] = # deleted rows in the table "annotations_target_Targets". |
---|
373 | * result[3] = # deleted rows in the table "Target". |
---|
374 | * @throws SQLException |
---|
375 | */ |
---|
376 | int[] deleteAnnotation(Number annotationID); |
---|
377 | |
---|
378 | |
---|
379 | |
---|
380 | } |
---|