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.NotInDataBaseException; |
---|
21 | import eu.dasish.annotation.schema.Annotation; |
---|
22 | import eu.dasish.annotation.schema.AnnotationBody; |
---|
23 | import eu.dasish.annotation.schema.AnnotationInfo; |
---|
24 | import eu.dasish.annotation.schema.Access; |
---|
25 | import java.sql.SQLException; |
---|
26 | import java.util.List; |
---|
27 | import java.util.UUID; |
---|
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 | /** |
---|
40 | * GETTERS |
---|
41 | */ |
---|
42 | |
---|
43 | public List<UUID> getExternalIdFromHeadline(String headline); |
---|
44 | |
---|
45 | public List<Number> getInternalIDsFromHeadline(String headline); |
---|
46 | /** |
---|
47 | * |
---|
48 | * @param annotationID |
---|
49 | * @return the pair (annotation, owner_id) with empty list of Targets. |
---|
50 | * |
---|
51 | * (Constructing a complete Annotation object using "getAnnotationWithoutTargets" and "retrieveTargetIDs" is done in "DaoDispatchter".) |
---|
52 | * |
---|
53 | */ |
---|
54 | public Annotation getAnnotationWithoutTargetsAndPemissionList(Number annotationID); |
---|
55 | |
---|
56 | |
---|
57 | public List<Number> getFilteredAnnotationIDs(Number ownerID, String text, String namespace, String after, String before); |
---|
58 | |
---|
59 | |
---|
60 | public List<Number> getAnnotationIDsPermissionAtLeast(Number principalID, Access acess); |
---|
61 | |
---|
62 | |
---|
63 | public List<Number> getAnnotationIDsPublicAtLeast(Access access); |
---|
64 | |
---|
65 | |
---|
66 | /* |
---|
67 | * Use inly in the debugging mode to acces all the existing annotations. |
---|
68 | */ |
---|
69 | public List<Number> getAllAnnotationIDs(); |
---|
70 | |
---|
71 | public List<Number> sublistOrderedAnnotationIDs(List<Number> annotationIDs, int offset, int limit, String orderedBy, String desc); |
---|
72 | |
---|
73 | /** |
---|
74 | * unit test is missing |
---|
75 | * @param annotationIDs |
---|
76 | * @return annotationInfo for the annotation with the internal annotationID. |
---|
77 | * |
---|
78 | */ |
---|
79 | public AnnotationInfo getAnnotationInfoWithoutTargetsAndOwner(Number annotationID); |
---|
80 | |
---|
81 | /** |
---|
82 | * |
---|
83 | * @param annotationIDs |
---|
84 | * @return list of reTarget references where an i-th reference is constructed from the external identifier of the annotation with the i-th internal identifier from the list. |
---|
85 | */ |
---|
86 | public List<String> getAnnotationREFs(List<Number> annotationIDs); |
---|
87 | |
---|
88 | |
---|
89 | |
---|
90 | public Number getOwner(Number annotationID); |
---|
91 | |
---|
92 | /** |
---|
93 | * |
---|
94 | * @param annotationID |
---|
95 | * @param principalID |
---|
96 | * @return access of the principalID w.r.t. annotationID, or null if the access is not given |
---|
97 | */ |
---|
98 | public Access getAccess(Number annotationID, Number principalID); |
---|
99 | |
---|
100 | public boolean hasExplicitAccess(Number annotationID, Number principalID); |
---|
101 | |
---|
102 | |
---|
103 | public Access getPublicAttribute(Number annotationID); |
---|
104 | |
---|
105 | |
---|
106 | |
---|
107 | public List<Number> getAnnotations(Number notebookID); |
---|
108 | |
---|
109 | |
---|
110 | public boolean targetIsInUse(Number targetID); |
---|
111 | /** |
---|
112 | * |
---|
113 | * @param annotationID |
---|
114 | * @return true if "annotationID" is mentioned in at least one of the joint tables: |
---|
115 | * "annotations_targets", "annotations_principals_accesss", "notebook_annotations". |
---|
116 | * Otherwise return "false". |
---|
117 | */ |
---|
118 | //public boolean annotationIsInUse(Number annotationID); |
---|
119 | |
---|
120 | /** |
---|
121 | * ADDERS |
---|
122 | */ |
---|
123 | |
---|
124 | /** |
---|
125 | * |
---|
126 | * @param annotationID |
---|
127 | * @param targetID |
---|
128 | * @return # updated rows in the joint table "annotations_target_Targets". |
---|
129 | * @throws SQLException |
---|
130 | * Connects the annotation to its target Target by adding the pair (annotationID, TargetID) to the joint table. |
---|
131 | */ |
---|
132 | public int addAnnotationTarget(Number annotationID, Number targetID); |
---|
133 | |
---|
134 | |
---|
135 | /** |
---|
136 | * |
---|
137 | * @param annotationID |
---|
138 | * @param principalID |
---|
139 | * @param access |
---|
140 | * @return # rows added to the table "annotations_principals_accesss" |
---|
141 | * Sets the "access" for the "principalID" w.r.t. the annotation with "annotationID". |
---|
142 | */ |
---|
143 | public int addPermission(Number annotationID, Number principalID, Access access); |
---|
144 | |
---|
145 | |
---|
146 | |
---|
147 | /** |
---|
148 | * |
---|
149 | * @param annotation: the object to be added to the table "annotation". |
---|
150 | * @return the internal ID of the added annotation, if it is added, or null otherwise. |
---|
151 | **/ |
---|
152 | |
---|
153 | public Number addAnnotation(Annotation annotation, Number newOwnerID) throws NotInDataBaseException; |
---|
154 | |
---|
155 | |
---|
156 | /////// UPDATERS ////////////////// |
---|
157 | |
---|
158 | |
---|
159 | public int updateAnnotationBody(Number annotationID, String text, String mimeType, Boolean isXml); |
---|
160 | |
---|
161 | public int updateAnnotationHeadline(Number annotationID, String text); |
---|
162 | |
---|
163 | |
---|
164 | |
---|
165 | /** |
---|
166 | * |
---|
167 | * @param annotation |
---|
168 | * @return # of updated rows in "annotation" table after updating the annotation. Should return 1 if update happens |
---|
169 | * @throws SQLException |
---|
170 | */ |
---|
171 | public int updateAnnotation(Annotation annotation, Number annotationID, Number ownerID); |
---|
172 | |
---|
173 | |
---|
174 | /** |
---|
175 | * |
---|
176 | * @param annotationID |
---|
177 | * @param principalID |
---|
178 | * @param access |
---|
179 | * @return # rows updated to the table "annotations_principals_accesss" |
---|
180 | * Sets the "access" for the "principalID" w.r.t. the annotation with "annotationID". |
---|
181 | */ |
---|
182 | public int updatePermission(Number annotationID, Number principalID, Access access); |
---|
183 | |
---|
184 | |
---|
185 | public int updatePublicAccess(Number annotationID, Access access); |
---|
186 | |
---|
187 | |
---|
188 | /** |
---|
189 | * DELETERS |
---|
190 | */ |
---|
191 | |
---|
192 | /** |
---|
193 | * |
---|
194 | * @param annotationId |
---|
195 | * @return # rows in the table "annotation". It should be "1" if the annotation with "annotationID" is successfully deleted, and "0" otherwise. |
---|
196 | */ |
---|
197 | |
---|
198 | |
---|
199 | |
---|
200 | public int deleteAnnotation(Number annotationId); |
---|
201 | |
---|
202 | /** |
---|
203 | * |
---|
204 | * @param annotationId |
---|
205 | * @return # removed rows in the table "annotations_target_Targets". |
---|
206 | */ |
---|
207 | |
---|
208 | public int deleteAllAnnotationTarget(Number annotationID); |
---|
209 | |
---|
210 | |
---|
211 | /** |
---|
212 | * |
---|
213 | * @param annotationID |
---|
214 | * @return # removed rows in the table "annotations_principals_accesss". |
---|
215 | * @throws SQLException |
---|
216 | */ |
---|
217 | public int deletePermissions(Number annotationID); |
---|
218 | |
---|
219 | public int deletePermission(Number annotationID, Number principalID); |
---|
220 | |
---|
221 | public int deleteAnnotationFromAllNotebooks(Number annotationID); |
---|
222 | |
---|
223 | /* |
---|
224 | * HELPERS |
---|
225 | */ |
---|
226 | |
---|
227 | public String[] retrieveBodyComponents(AnnotationBody annotationBody); |
---|
228 | |
---|
229 | } |
---|