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.AnnotationInfo; |
---|
22 | import eu.dasish.annotation.schema.Permission; |
---|
23 | import eu.dasish.annotation.schema.ResourceREF; |
---|
24 | import java.sql.SQLException; |
---|
25 | import java.sql.Timestamp; |
---|
26 | import java.util.List; |
---|
27 | import java.util.Map; |
---|
28 | |
---|
29 | /** |
---|
30 | * Created on : Jun 27, 2013, 10:34:13 AM |
---|
31 | * |
---|
32 | * @author Peter Withers <peter.withers@mpi.nl> |
---|
33 | */ |
---|
34 | |
---|
35 | |
---|
36 | public interface AnnotationDao extends ResourceDao{ |
---|
37 | |
---|
38 | |
---|
39 | ////////////// GETTERS ////////////////////////// |
---|
40 | |
---|
41 | /** |
---|
42 | * |
---|
43 | * @param annotationID |
---|
44 | * @return the Annotation object with empty list of sources. |
---|
45 | * |
---|
46 | * (Constructing a complete Annotation object using "getAnnotationWithoutSources" and "retrieveSourceIDs" is done in "DaoDispatchter" |
---|
47 | * |
---|
48 | */ |
---|
49 | public Annotation getAnnotationWithoutSources(Number annotationID) throws SQLException; |
---|
50 | |
---|
51 | |
---|
52 | /** |
---|
53 | * |
---|
54 | * @param annotationIDs: the list of annotationID-s from which the resulting annotations are to be selected. |
---|
55 | * @param text: the text which the resulting annotations' bodies must contain. |
---|
56 | * @param access: the resulting annotations must have permission "access" (owner, or writer, or reader) for the currently inlogged user. |
---|
57 | * @param namespace TODO: do not know what to do with it |
---|
58 | * @param ownerID: the resulting annotations are owned by the owner "ownerID". |
---|
59 | * @param after: the resulting annotations must have timestamp later than "after". |
---|
60 | * @param before: the resulting annotations must have timestamp earlier than "before". |
---|
61 | * @return the sub-list of internal annotation identifiers from the list "internalIDs" for annotations |
---|
62 | * -- bodies of which contain the "text", |
---|
63 | * -- to which inlogged user has "access", |
---|
64 | * -- owned by "owner", |
---|
65 | * -- added to the database between "before" and "after" time-dates. |
---|
66 | * |
---|
67 | */ |
---|
68 | public List<Number> getFilteredAnnotationIDs(List<Number> annotationIDs, String text, String access, String namespace, Number ownerID, Timestamp after, Timestamp before); |
---|
69 | |
---|
70 | /** |
---|
71 | * |
---|
72 | * @param annotationIDs |
---|
73 | * @return the list of annotationInfos (owner, headline, target sources, external_id) for the annotations with the internal IDs from the input list. |
---|
74 | * |
---|
75 | */ |
---|
76 | public List<AnnotationInfo> getAnnotationInfos(List<Number> annotationIDs); |
---|
77 | |
---|
78 | |
---|
79 | /** |
---|
80 | * |
---|
81 | * @param annotationIDs |
---|
82 | * @return list of resource references where an i-th reference is constructed from the external identifier of the annotation with the i-th internal identifier from the list. |
---|
83 | */ |
---|
84 | public List<ResourceREF> getAnnotationREFs(List<Number> annotationIDs); |
---|
85 | |
---|
86 | /** |
---|
87 | * |
---|
88 | * @param sourceIDs |
---|
89 | * @return the list of annotationdIDs of the annotations which target sources are from "sourceIDs" list. |
---|
90 | */ |
---|
91 | public List<Number> retrieveAnnotationList(List<Number> sourceIDs); |
---|
92 | |
---|
93 | |
---|
94 | /** |
---|
95 | * |
---|
96 | * @param annotationID |
---|
97 | * @return the list of the internal IDs of all the target sources of "annotationID". |
---|
98 | */ |
---|
99 | public List<Number> retrieveSourceIDs(Number annotationID); |
---|
100 | |
---|
101 | |
---|
102 | /** |
---|
103 | * |
---|
104 | * @param annotationId |
---|
105 | * @return all the pairs (user-permission) for "annotationId" from the table annotations_principals permissions. |
---|
106 | */ |
---|
107 | public List<Map<Number, String>> retrievePermissions(Number annotationId); |
---|
108 | |
---|
109 | |
---|
110 | /** |
---|
111 | * |
---|
112 | * @param sourceID |
---|
113 | * @return true if "annotationID" is mentioned in at least one of the joint tables: |
---|
114 | * "annotations_target_sources", "annotations_principals_permissions", "notebook_annotations". |
---|
115 | * Otherwise return "false". |
---|
116 | */ |
---|
117 | public boolean annotationIsInUse(Number annotationID); |
---|
118 | |
---|
119 | ///////////// ADDERS ///////////////////// |
---|
120 | |
---|
121 | /** |
---|
122 | * |
---|
123 | * @param annotationID |
---|
124 | * @param sourceID |
---|
125 | * @return # updated rows in the joint table "annotations_target_sources". |
---|
126 | * @throws SQLException |
---|
127 | * Connects the annotation to its target source by adding the pair (annotationID, sourceID) to the joint table. |
---|
128 | */ |
---|
129 | public int addAnnotationSourcePair(Number annotationID, Number sourceID) throws SQLException; |
---|
130 | |
---|
131 | |
---|
132 | /** |
---|
133 | * |
---|
134 | * @param annotationID |
---|
135 | * @param userID |
---|
136 | * @param permission |
---|
137 | * @return # rows added to the table "annotations_principals_permissions" |
---|
138 | * Sets the "permission" for the "userID" w.r.t. the annotation with "annotationID". |
---|
139 | */ |
---|
140 | public int addAnnotationPrincipalPermission(Number annotationID, Number userID, Permission permission) throws SQLException; |
---|
141 | |
---|
142 | |
---|
143 | |
---|
144 | /** |
---|
145 | * |
---|
146 | * @param annotation: the object to be added to the table "annotation". |
---|
147 | * @return the internal ID of the added annotation, if it is added, or null otherwise. |
---|
148 | **/ |
---|
149 | |
---|
150 | public Number addAnnotation(Annotation annotation, Number ownerID) throws SQLException; |
---|
151 | |
---|
152 | |
---|
153 | /////// UPDATERS ////////////////// |
---|
154 | /** |
---|
155 | * |
---|
156 | * @param annotationID |
---|
157 | * @param serializedNewBody |
---|
158 | * @return # of updated rows in "annotation" table after updating the annotation's body with "serializedNewBody". Should return 1. |
---|
159 | */ |
---|
160 | public int updateBody(Number annotationID, String serializedNewBody); |
---|
161 | |
---|
162 | |
---|
163 | //////////// DELETERS /////////////////////// |
---|
164 | |
---|
165 | /** |
---|
166 | * |
---|
167 | * @param annotationId |
---|
168 | * @return # rows in the table "annotation". It should be "1" if the annotation with "annotationID" is successfully deleted, and "0" otherwise. |
---|
169 | */ |
---|
170 | |
---|
171 | |
---|
172 | |
---|
173 | public int deleteAnnotation(Number annotationId) throws SQLException; |
---|
174 | |
---|
175 | /** |
---|
176 | * |
---|
177 | * @param annotationId |
---|
178 | * @return # removed rows in the table "annotations_target_sources". |
---|
179 | */ |
---|
180 | |
---|
181 | public int deleteAllAnnotationSource(Number annotationID) throws SQLException; |
---|
182 | |
---|
183 | |
---|
184 | /** |
---|
185 | * |
---|
186 | * @param annotationID |
---|
187 | * @return # removed rows in the table "annotations_principals_permissions". |
---|
188 | * @throws SQLException |
---|
189 | */ |
---|
190 | public int deleteAnnotationPrincipalPermissions(Number annotationID) throws SQLException ; |
---|
191 | |
---|
192 | |
---|
193 | |
---|
194 | |
---|
195 | } |
---|