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