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

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

Integrity service is adjusted and retested. Some REST methods fornotebooks are added (not tested)

File size: 12.8 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.AnnotationInfoList;
23import eu.dasish.annotation.schema.CachedRepresentationInfo;
24import eu.dasish.annotation.schema.Notebook;
25import eu.dasish.annotation.schema.NotebookInfo;
26import eu.dasish.annotation.schema.NotebookInfoList;
27import eu.dasish.annotation.schema.Permission;
28import eu.dasish.annotation.schema.UserWithPermissionList;
29import eu.dasish.annotation.schema.ReferenceList;
30import eu.dasish.annotation.schema.Target;
31import eu.dasish.annotation.schema.TargetInfo;
32import eu.dasish.annotation.schema.User;
33import java.io.InputStream;
34import java.sql.SQLException;
35import java.util.List;
36import java.util.Map;
37import java.util.UUID;
38
39/**
40 *
41 * @author olhsha
42 *
43 */
44public 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    public ReferenceList getNotebooksOwnedBy(Number principalID);
248
249    public ReferenceList getPrincipals(Number notebookID, String permission);
250
251    public Notebook getNotebook(Number notebookID);
252
253    ReferenceList getAnnotationsForNotebook(Number notebookID, int startAnnotation, int maximumAnnotations, String orderedBy, boolean desc);
254
255    /**
256     * UPDATERS
257     */
258    public boolean updateAccount(UUID userExternalID, String account);
259
260    /**
261     *
262     * @param annotation
263     * @return 1 of the annotation if it is updated
264     */
265    int updateAnnotation(Annotation annotation);
266
267    /**
268     *
269     * @param userID
270     * @param annotationBody
271     * @return 1 of the annotation if it is updated
272     */
273    int updateAnnotationBody(Number internalID, AnnotationBody annotationBody);
274
275    /**
276     *
277     * @param annotationID
278     * @param userID
279     * @param permission
280     * @return # rows updated to the table "annotations_principals_permissions"
281     * Sets the "permission" for the "userID" w.r.t. the annotation with
282     * "annotationID".
283     */
284    public int updateAnnotationPrincipalPermission(Number annotationID, Number userID, Permission permission);
285
286    /**
287     *
288     * @param annotationID
289     * @param permissionList
290     * @return # of rows updated or added in the table
291     * annotations_principals_permissions
292     */
293    public int updatePermissions(Number annotationID, UserWithPermissionList permissionList);
294
295    public Number updateUser(User user);
296
297    /// notebooks ///
298    public boolean updateNotebookMetadata(Number notebookID, NotebookInfo upToDateNotebookInfo);
299
300    public boolean addAnnotationToNotebook(Number notebookID, Number annotationID);
301
302    /**
303     * ADDERS
304     */
305    /**
306     *
307     * @param targetID
308     * @param cachedInfo
309     * @param cachedBlob
310     * @return result[0] = # updated rows in the table
311     * "Targets_cached_representations" (must be 1 or 0). result[1] = the
312     * internal ID of the added cached (a new one if "cached" was new for the
313     * Data Base).
314     */
315    Number[] addCachedForTarget(Number targetID, String fragmentDescriptor, CachedRepresentationInfo cachedInfo, InputStream cachedBlob);
316
317    /**
318     *
319     * @param annotationID
320     * @param targets
321     * @return map temporaryTargetID |--> TargetExternalID. Its domain is the
322     * temporary IDs of all the new Targets. While adding a new Target a new
323     * external ID is generated for it and it becomes the value of the map. The
324     * TargetIDs which are already present in the DB are not in the domain. If
325     * all Targets are old, then the map is empty.
326     * @throws SQLException
327     */
328    Map<String, String> addTargetsForAnnotation(Number annotationID, List<TargetInfo> targets);
329
330    /**
331     *
332     * @param userID
333     * @param annotation
334     * @return the internalId of the just added "annotation" (or null if it is
335     * not added) by the owner "userID". calls "addTargetsForAnnotation"
336     * @throws SQLException
337     */
338    Number addUsersAnnotation(Number ownerID, Annotation annotation);
339
340    /**
341     *
342     * @param user
343     * @param remoteID is got from the server
344     * @return the internal Id of the just added "user", or null if it was not
345     * added for some reason (already exists)
346     * @throws SQLException
347     */
348    Number addUser(User user, String remoteID);
349
350    int addAnnotationPrincipalPermission(Number annotationID, Number userID, Permission permission);
351
352    /// notebooks ////
353    Number createNotebook(Notebook notebook, Number ownerID);
354
355    boolean createAnnotationInNotebook(Number notebookID, Annotation annotation, Number ownerID);
356
357    /**
358     * DELETERS
359     */
360    /**
361     *
362     * @param userID
363     * @return # of affected rows in the table "principal". It is 1 if the
364     * userId is found and deleted; it is 0 if it is not found or not deleted,
365     * e.g. because it is in use in the table
366     * "annotationsPreincipalsPermissions"
367     */
368    public int deleteUser(Number userID);
369
370    /**
371     *
372     * @param userID
373     * @return # of affected rows in the table "principal". It is 1 if the
374     * userId is found and deleted; it is 0 if it is not found or not deleted,
375     * e.g. because it is in use in the table
376     * "annotationsPreincipalsPermissions"
377     */
378    public int deleteUserSafe(Number userID);
379
380    /**
381     *
382     * @param TargetID
383     * @param cachedID
384     * @return result[0] = # deleted rows in the table
385     * "Targets_cached_representations" (1, or 0). result[1] = # deleted rows in
386     * the table "cached_representation" (should be 0 if the cached
387     * representation is in use by some other Target???).
388     */
389    int[] deleteCachedRepresentationOfTarget(Number TargetID, Number cachedID);
390
391    /**
392     *
393     * @param targetID
394     * @return result[0] = # deleted rows in the table
395     * "targets_cached_representations". result[1] = # deleted rows in the table
396     * "cached_representation".
397     *
398     */
399    int[] deleteAllCachedRepresentationsOfTarget(Number versionID);
400
401    /**
402     *
403     * @param annotationID
404     * @return result[0] = # deleted rows in the table "annotation" (1 or 0).
405     * result[1] = # deleted rows in the table
406     * "annotations_principals_permissions". result[2] = # deleted rows in the
407     * table "annotations_target_Targets". result[3] = # deleted rows in the
408     * table "Target".
409     * @throws SQLException
410     */
411    int[] deleteAnnotation(Number annotationID);
412   
413    /// notebooks ///
414    boolean deleteNotebook(Number notebookID);
415   
416}
Note: See TracBrowser for help on using the repository browser.