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.AnnotationInfoList; |
---|
23 | import eu.dasish.annotation.schema.CachedRepresentationInfo; |
---|
24 | import eu.dasish.annotation.schema.Notebook; |
---|
25 | import eu.dasish.annotation.schema.NotebookInfo; |
---|
26 | import eu.dasish.annotation.schema.NotebookInfoList; |
---|
27 | import eu.dasish.annotation.schema.Permission; |
---|
28 | import eu.dasish.annotation.schema.UserWithPermissionList; |
---|
29 | import eu.dasish.annotation.schema.ReferenceList; |
---|
30 | import eu.dasish.annotation.schema.Target; |
---|
31 | import eu.dasish.annotation.schema.TargetInfo; |
---|
32 | import eu.dasish.annotation.schema.User; |
---|
33 | import java.io.InputStream; |
---|
34 | import java.sql.SQLException; |
---|
35 | import java.util.List; |
---|
36 | import java.util.Map; |
---|
37 | import java.util.UUID; |
---|
38 | |
---|
39 | /** |
---|
40 | * |
---|
41 | * @author olhsha |
---|
42 | * |
---|
43 | */ |
---|
44 | public interface DBIntegrityService { |
---|
45 | |
---|
46 | public void setServiceURI(String serviceURI); |
---|
47 | |
---|
48 | /** |
---|
49 | * GETTERS |
---|
50 | */ |
---|
51 | /** |
---|
52 | * |
---|
53 | * @param UUID |
---|
54 | * @return the internal identifier of the annotations with "externalID", or |
---|
55 | * null if no such annotation. |
---|
56 | */ |
---|
57 | Number getAnnotationInternalIdentifier(UUID externalID); |
---|
58 | |
---|
59 | /** |
---|
60 | * |
---|
61 | * @param annotationID |
---|
62 | * @return the externalID of the annotation with "internalID" or null if |
---|
63 | * there is no such annotation. |
---|
64 | */ |
---|
65 | UUID getAnnotationExternalIdentifier(Number annotationID); |
---|
66 | |
---|
67 | Number getAnnotationInternalIdentifierFromURI(String uri); |
---|
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 | */ |
---|
83 | List<Number> getFilteredAnnotationIDs(UUID ownerId, String link, String text, Number inloggedUserID, String access, String namespace, String after, String before); |
---|
84 | |
---|
85 | AnnotationInfoList getAllAnnotationInfos(); |
---|
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. |
---|
109 | */ |
---|
110 | UUID getUserExternalIdentifier(Number userID); |
---|
111 | |
---|
112 | /** |
---|
113 | * |
---|
114 | * @param externalID |
---|
115 | * @return the internal identifier of the user with "externalID", or null if |
---|
116 | * there is no such user. |
---|
117 | */ |
---|
118 | Number getUserInternalIdentifier(UUID externalID); |
---|
119 | |
---|
120 | /** |
---|
121 | * |
---|
122 | * @param cachedID |
---|
123 | * @return the external identifier of the cached representation "cachedID", |
---|
124 | * or null if no such one. |
---|
125 | */ |
---|
126 | UUID getCachedRepresentationExternalIdentifier(Number cachedID); |
---|
127 | |
---|
128 | /** |
---|
129 | * |
---|
130 | * @param externalID |
---|
131 | * @return the internal identifier of the cachedRepresentation with |
---|
132 | * "externalID", or null if there is no such one. |
---|
133 | */ |
---|
134 | Number getCachedRepresentationInternalIdentifier(UUID externalID); |
---|
135 | |
---|
136 | Number getTargetInternalIdentifier(UUID externalID); |
---|
137 | |
---|
138 | String getTargetURI(Number targetID); |
---|
139 | |
---|
140 | UUID getTargetExternalIdentifier(Number targetID); |
---|
141 | |
---|
142 | String getUserURI(Number userID); |
---|
143 | |
---|
144 | /** |
---|
145 | * |
---|
146 | * @param internalID |
---|
147 | * @return CachedRepresentationInfo (i.e. "metadata") for cached |
---|
148 | * representation with the internal id "intenalID" |
---|
149 | */ |
---|
150 | CachedRepresentationInfo getCachedRepresentationInfo(Number internalID); |
---|
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 |
---|
159 | */ |
---|
160 | Annotation getAnnotation(Number annotationID); |
---|
161 | |
---|
162 | Number getAnnotationOwner(Number annotationID); |
---|
163 | |
---|
164 | /** |
---|
165 | * |
---|
166 | * @param annotationID |
---|
167 | * @return the object TargetList containing all target Targets of the |
---|
168 | * annotationID |
---|
169 | * @throws SQLException |
---|
170 | */ |
---|
171 | ReferenceList getAnnotationTargets(Number annotationID); |
---|
172 | |
---|
173 | /** |
---|
174 | * |
---|
175 | * @param annotationID |
---|
176 | * @return the list of targetURI's for which there is no cached |
---|
177 | * representation |
---|
178 | */ |
---|
179 | List<String> getTargetsWithNoCachedRepresentation(Number annotationID); |
---|
180 | |
---|
181 | List<String> getUsersWithNoInfo(Number annotationID); |
---|
182 | |
---|
183 | /** |
---|
184 | * |
---|
185 | * @param annotationID |
---|
186 | * @return the list of TargetID's for which there is no cached |
---|
187 | * 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 |
---|
195 | * source (link) as targetID |
---|
196 | */ |
---|
197 | public ReferenceList getTargetsForTheSameLinkAs(Number targetID); |
---|
198 | |
---|
199 | /** |
---|
200 | * |
---|
201 | * @param cachedID |
---|
202 | * @return BLOB of the cachedID |
---|
203 | */ |
---|
204 | public InputStream getCachedRepresentationBlob(Number cachedID); |
---|
205 | |
---|
206 | public Target getTarget(Number internalID); |
---|
207 | |
---|
208 | /** |
---|
209 | * |
---|
210 | * @param userID |
---|
211 | * @return user with "userID" |
---|
212 | */ |
---|
213 | public User getUser(Number userID); |
---|
214 | |
---|
215 | /** |
---|
216 | * |
---|
217 | * @param eMail |
---|
218 | * @return user with e-mail "eMail" |
---|
219 | */ |
---|
220 | public User getUserByInfo(String eMail); |
---|
221 | |
---|
222 | public String getUserRemoteID(Number internalID); |
---|
223 | |
---|
224 | public Number getUserInternalIDFromRemoteID(String remoteID); |
---|
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 | |
---|
235 | public String getTypeOfUserAccount(Number userID); |
---|
236 | |
---|
237 | public boolean canRead(Number userID, Number annotationID); |
---|
238 | |
---|
239 | public boolean canWrite(Number userID, Number annotationID); |
---|
240 | |
---|
241 | /// notebooks /// |
---|
242 | |
---|
243 | public Number getNotebookInternalIdentifier(UUID externalIdentifier); |
---|
244 | |
---|
245 | public NotebookInfoList getNotebooks(Number prinipalID, String permission); |
---|
246 | |
---|
247 | boolean hasAccess(Number notebookID, Number principalID, Permission permission); |
---|
248 | |
---|
249 | public ReferenceList getNotebooksOwnedBy(Number principalID); |
---|
250 | |
---|
251 | public ReferenceList getPrincipals(Number notebookID, String permission); |
---|
252 | |
---|
253 | public Notebook getNotebook(Number notebookID); |
---|
254 | |
---|
255 | ReferenceList getAnnotationsForNotebook(Number notebookID, int startAnnotation, int maximumAnnotations, String orderedBy, boolean desc); |
---|
256 | |
---|
257 | /** |
---|
258 | * UPDATERS |
---|
259 | */ |
---|
260 | public boolean updateAccount(UUID userExternalID, String account); |
---|
261 | |
---|
262 | /** |
---|
263 | * |
---|
264 | * @param annotation |
---|
265 | * @return 1 of the annotation if it is updated |
---|
266 | */ |
---|
267 | int updateAnnotation(Annotation annotation); |
---|
268 | |
---|
269 | /** |
---|
270 | * |
---|
271 | * @param userID |
---|
272 | * @param annotationBody |
---|
273 | * @return 1 of the annotation if it is updated |
---|
274 | */ |
---|
275 | int updateAnnotationBody(Number internalID, AnnotationBody annotationBody); |
---|
276 | |
---|
277 | /** |
---|
278 | * |
---|
279 | * @param annotationID |
---|
280 | * @param userID |
---|
281 | * @param permission |
---|
282 | * @return # rows updated to the table "annotations_principals_permissions" |
---|
283 | * Sets the "permission" for the "userID" w.r.t. the annotation with |
---|
284 | * "annotationID". |
---|
285 | */ |
---|
286 | public int updateAnnotationPrincipalPermission(Number annotationID, Number userID, Permission permission); |
---|
287 | |
---|
288 | /** |
---|
289 | * |
---|
290 | * @param annotationID |
---|
291 | * @param permissionList |
---|
292 | * @return # of rows updated or added in the table |
---|
293 | * annotations_principals_permissions |
---|
294 | */ |
---|
295 | public int updatePermissions(Number annotationID, UserWithPermissionList permissionList); |
---|
296 | |
---|
297 | public Number updateUser(User user); |
---|
298 | |
---|
299 | /// notebooks /// |
---|
300 | public boolean updateNotebookMetadata(Number notebookID, NotebookInfo upToDateNotebookInfo); |
---|
301 | |
---|
302 | public boolean addAnnotationToNotebook(Number notebookID, Number annotationID); |
---|
303 | |
---|
304 | /** |
---|
305 | * ADDERS |
---|
306 | */ |
---|
307 | /** |
---|
308 | * |
---|
309 | * @param targetID |
---|
310 | * @param cachedInfo |
---|
311 | * @param cachedBlob |
---|
312 | * @return result[0] = # updated rows in the table |
---|
313 | * "Targets_cached_representations" (must be 1 or 0). result[1] = the |
---|
314 | * internal ID of the added cached (a new one if "cached" was new for the |
---|
315 | * Data Base). |
---|
316 | */ |
---|
317 | Number[] addCachedForTarget(Number targetID, String fragmentDescriptor, CachedRepresentationInfo cachedInfo, InputStream cachedBlob); |
---|
318 | |
---|
319 | /** |
---|
320 | * |
---|
321 | * @param annotationID |
---|
322 | * @param targets |
---|
323 | * @return map temporaryTargetID |--> TargetExternalID. Its domain is the |
---|
324 | * temporary IDs of all the new Targets. While adding a new Target a new |
---|
325 | * external ID is generated for it and it becomes the value of the map. The |
---|
326 | * TargetIDs which are already present in the DB are not in the domain. If |
---|
327 | * all Targets are old, then the map is empty. |
---|
328 | * @throws SQLException |
---|
329 | */ |
---|
330 | Map<String, String> addTargetsForAnnotation(Number annotationID, List<TargetInfo> targets); |
---|
331 | |
---|
332 | /** |
---|
333 | * |
---|
334 | * @param userID |
---|
335 | * @param annotation |
---|
336 | * @return the internalId of the just added "annotation" (or null if it is |
---|
337 | * not added) by the owner "userID". calls "addTargetsForAnnotation" |
---|
338 | * @throws SQLException |
---|
339 | */ |
---|
340 | Number addUsersAnnotation(Number ownerID, Annotation annotation); |
---|
341 | |
---|
342 | /** |
---|
343 | * |
---|
344 | * @param user |
---|
345 | * @param remoteID is got from the server |
---|
346 | * @return the internal Id of the just added "user", or null if it was not |
---|
347 | * added for some reason (already exists) |
---|
348 | * @throws SQLException |
---|
349 | */ |
---|
350 | Number addUser(User user, String remoteID); |
---|
351 | |
---|
352 | int addAnnotationPrincipalPermission(Number annotationID, Number userID, Permission permission); |
---|
353 | |
---|
354 | /// notebooks //// |
---|
355 | Number createNotebook(Notebook notebook, Number ownerID); |
---|
356 | |
---|
357 | boolean createAnnotationInNotebook(Number notebookID, Annotation annotation, Number ownerID); |
---|
358 | |
---|
359 | /** |
---|
360 | * DELETERS |
---|
361 | */ |
---|
362 | /** |
---|
363 | * |
---|
364 | * @param userID |
---|
365 | * @return # of affected rows in the table "principal". It is 1 if the |
---|
366 | * userId is found and deleted; it is 0 if it is not found or not deleted, |
---|
367 | * e.g. because it is in use in the table |
---|
368 | * "annotationsPreincipalsPermissions" |
---|
369 | */ |
---|
370 | public int deleteUser(Number userID); |
---|
371 | |
---|
372 | /** |
---|
373 | * |
---|
374 | * @param userID |
---|
375 | * @return # of affected rows in the table "principal". It is 1 if the |
---|
376 | * userId is found and deleted; it is 0 if it is not found or not deleted, |
---|
377 | * e.g. because it is in use in the table |
---|
378 | * "annotationsPreincipalsPermissions" |
---|
379 | */ |
---|
380 | public int deleteUserSafe(Number userID); |
---|
381 | |
---|
382 | /** |
---|
383 | * |
---|
384 | * @param TargetID |
---|
385 | * @param cachedID |
---|
386 | * @return result[0] = # deleted rows in the table |
---|
387 | * "Targets_cached_representations" (1, or 0). result[1] = # deleted rows in |
---|
388 | * the table "cached_representation" (should be 0 if the cached |
---|
389 | * representation is in use by some other Target???). |
---|
390 | */ |
---|
391 | int[] deleteCachedRepresentationOfTarget(Number TargetID, Number cachedID); |
---|
392 | |
---|
393 | /** |
---|
394 | * |
---|
395 | * @param targetID |
---|
396 | * @return result[0] = # deleted rows in the table |
---|
397 | * "targets_cached_representations". result[1] = # deleted rows in the table |
---|
398 | * "cached_representation". |
---|
399 | * |
---|
400 | */ |
---|
401 | int[] deleteAllCachedRepresentationsOfTarget(Number versionID); |
---|
402 | |
---|
403 | /** |
---|
404 | * |
---|
405 | * @param annotationID |
---|
406 | * @return result[0] = # deleted rows in the table "annotation" (1 or 0). |
---|
407 | * result[1] = # deleted rows in the table |
---|
408 | * "annotations_principals_permissions". result[2] = # deleted rows in the |
---|
409 | * table "annotations_target_Targets". result[3] = # deleted rows in the |
---|
410 | * table "Target". |
---|
411 | * @throws SQLException |
---|
412 | */ |
---|
413 | int[] deleteAnnotation(Number annotationID); |
---|
414 | |
---|
415 | /// notebooks /// |
---|
416 | boolean deleteNotebook(Number notebookID); |
---|
417 | |
---|
418 | } |
---|