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

Last change on this file since 5836 was 5836, checked in by olhsha@mpi.nl, 10 years ago

refactoring. Adding ALL as an access mode.

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