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

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

adding two html forms and two services for updating user-annotation access and public access of an annotation

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