Changeset 4495
- Timestamp:
- 02/11/14 18:01:34 (10 years ago)
- Location:
- DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src
- Files:
-
- 11 edited
Legend:
- Unmodified
- Added
- Removed
-
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/AnnotationDao.java
r4491 r4495 65 65 public List<Number> getAllAnnotationIDs(); 66 66 67 public List<Number> sublistOrderedAnnotationIDs(List<Number> annotationIDs, int offset, int limit, String orderedBy, String desc); 68 67 69 /** 68 70 * unit test is missing -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/DBIntegrityService.java
r4491 r4495 18 18 package eu.dasish.annotation.backend.dao; 19 19 20 21 20 import eu.dasish.annotation.schema.Annotation; 22 21 import eu.dasish.annotation.schema.AnnotationBody; 23 22 import eu.dasish.annotation.schema.AnnotationInfoList; 24 23 import eu.dasish.annotation.schema.CachedRepresentationInfo; 24 import eu.dasish.annotation.schema.Notebook; 25 import eu.dasish.annotation.schema.NotebookInfo; 26 import eu.dasish.annotation.schema.NotebookInfoList; 25 27 import eu.dasish.annotation.schema.Permission; 26 28 import eu.dasish.annotation.schema.UserWithPermissionList; … … 31 33 import java.io.InputStream; 32 34 import java.sql.SQLException; 33 import java.sql.Timestamp;34 35 import java.util.List; 35 36 import java.util.Map; … … 39 40 * 40 41 * @author olhsha 41 **/ 42 43 44 45 46 public interface DBIntegrityService{ 47 42 * 43 */ 44 public interface DBIntegrityService { 45 48 46 public void setServiceURI(String serviceURI); 49 50 47 51 48 /** 52 49 * GETTERS 53 50 */ 54 55 /** 56 * 51 /** 52 * 57 53 * @param UUID 58 * @return the internal identifier of the annotations with "externalID", or null if no such annotation. 54 * @return the internal identifier of the annotations with "externalID", or 55 * null if no such annotation. 59 56 */ 60 57 Number getAnnotationInternalIdentifier(UUID externalID); 61 62 /** 63 * 64 * @param annotationID 65 * @return the externalID of the annotation with "internalID" or null if there is no such annotation. 58 59 /** 60 * 61 * @param annotationID 62 * @return the externalID of the annotation with "internalID" or null if 63 * there is no such annotation. 66 64 */ 67 65 UUID getAnnotationExternalIdentifier(Number annotationID); 68 69 66 70 67 Number getAnnotationInternalIdentifierFromURI(String uri); 71 72 73 /** 74 * 75 * @param word 76 * @param text 77 * @param access 78 * @param namespace 79 * @param after 80 * @param before 81 * @return the list of internal id-s of the annotations such that: 82 * -- Targets' links of which contain "link" (as a substring), 83 * -- serialized bodies of which contain "text", 84 * -- current user has "access" (owner, reader, writer) to them, 85 * -- namespace ???, 86 * -- owned by "owner", 87 * -- created after time-samp "after and before time-stamp "before". 88 */ 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 */ 89 83 List<Number> getFilteredAnnotationIDs(UUID ownerId, String link, String text, Number inloggedUserID, String access, String namespace, String after, String before); 90 84 91 85 AnnotationInfoList getAllAnnotationInfos(); 92 93 /** 94 * 95 @param word 96 * @param text 97 * @param access 98 * @param namespace 99 * @param owner 100 * @param after 101 * @param before 102 * @return the list of the annotationInfos of the annotations such that: 103 * -- Targets' links of which contain "link" (as a substring), 104 * -- serialized bodies of which contain "text", 105 * -- current user has "access" (owner, reader, writer) to them, 106 * -- namespace ???, 107 * -- owned by "owner", 108 * -- created after time-samp "after and before time-stamp "before". 109 */ 110 AnnotationInfoList getFilteredAnnotationInfos(UUID ownerId, String word, String text, Number inloggedUserID, String access, String namespace, String after, String before); 111 112 /** 113 * 114 * @param userID 115 * @return the external identifier of the user "userID", or null if no such user. 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. 116 109 */ 117 110 UUID getUserExternalIdentifier(Number userID); 118 111 119 112 /** 120 * 113 * 121 114 * @param externalID 122 * @return the internal identifier of the user with "externalID", or null if there is no such user. 115 * @return the internal identifier of the user with "externalID", or null if 116 * there is no such user. 123 117 */ 124 118 Number getUserInternalIdentifier(UUID externalID); 125 126 127 * 119 120 /** 121 * 128 122 * @param cachedID 129 * @return the external identifier of the cached representation "cachedID", or null if no such one. 123 * @return the external identifier of the cached representation "cachedID", 124 * or null if no such one. 130 125 */ 131 126 UUID getCachedRepresentationExternalIdentifier(Number cachedID); 132 127 133 128 /** 134 * 129 * 135 130 * @param externalID 136 * @return the internal identifier of the cachedRepresentation with "externalID", or null if there is no such one. 131 * @return the internal identifier of the cachedRepresentation with 132 * "externalID", or null if there is no such one. 137 133 */ 138 134 Number getCachedRepresentationInternalIdentifier(UUID externalID); 139 140 Number getTargetInternalIdentifier(UUID externalID); 135 136 Number getTargetInternalIdentifier(UUID externalID); 141 137 142 138 String getTargetURI(Number targetID); 143 139 144 140 UUID getTargetExternalIdentifier(Number targetID); 145 146 String getUserURI(Number userID); 147 148 /** 149 * 141 142 String getUserURI(Number userID); 143 144 /** 145 * 150 146 * @param internalID 151 * @return CachedRepresentationInfo (i.e. "metadata") for cached representation with the internal id "intenalID" 147 * @return CachedRepresentationInfo (i.e. "metadata") for cached 148 * representation with the internal id "intenalID" 152 149 */ 153 150 CachedRepresentationInfo getCachedRepresentationInfo(Number internalID); 154 155 /** 156 * 157 * @param annotationID 158 * @return the object Annotation generated from the tables "annotation", "annotations_target_Targets", "Target", "annotations_principals_permissions". 159 * @throws SQLException 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 160 159 */ 161 160 Annotation getAnnotation(Number annotationID); 162 161 163 162 Number getAnnotationOwner(Number annotationID); 164 165 /** 166 * 167 * @param annotationID 168 * @return the object TargetList containing all target Targets of the annotationID 169 * @throws SQLException 163 164 /** 165 * 166 * @param annotationID 167 * @return the object TargetList containing all target Targets of the 168 * annotationID 169 * @throws SQLException 170 170 */ 171 171 ReferenceList getAnnotationTargets(Number annotationID); 172 173 174 175 /** 176 * 177 * @param annotationID 178 * @return the list of targetURI's for which there is no cached representation 172 173 /** 174 * 175 * @param annotationID 176 * @return the list of targetURI's for which there is no cached 177 * representation 179 178 */ 180 179 List<String> getTargetsWithNoCachedRepresentation(Number annotationID); 181 180 182 181 List<String> getUsersWithNoInfo(Number annotationID); 183 184 /** 185 * 186 * @param annotationID 187 * @return the list of TargetID's for which there is no cached representation 182 183 /** 184 * 185 * @param annotationID 186 * @return the list of TargetID's for which there is no cached 187 * representation 188 188 */ 189 189 public UserWithPermissionList getPermissionsForAnnotation(Number annotationID); 190 191 192 * 190 191 /** 192 * 193 193 * @param TargetID 194 * @return the list of the external version ID-s that refers to the same source (link) as targetID 194 * @return the list of the external version ID-s that refers to the same 195 * source (link) as targetID 195 196 */ 196 197 public ReferenceList getTargetsForTheSameLinkAs(Number targetID); 197 198 /** 199 * 198 199 /** 200 * 200 201 * @param cachedID 201 202 * @return BLOB of the cachedID 202 203 */ 203 public InputStream getCachedRepresentationBlob(Number cachedID) ; 204 205 206 204 public InputStream getCachedRepresentationBlob(Number cachedID); 205 207 206 public Target getTarget(Number internalID); 208 209 /** 210 * 207 208 /** 209 * 211 210 * @param userID 212 211 * @return user with "userID" 213 212 */ 214 213 public User getUser(Number userID); 215 216 /** 217 * 214 215 /** 216 * 218 217 * @param eMail 219 218 * @return user with e-mail "eMail" 220 219 */ 221 220 public User getUserByInfo(String eMail); 222 223 221 224 222 public String getUserRemoteID(Number internalID); 225 223 226 224 public Number getUserInternalIDFromRemoteID(String remoteID); 227 228 /** 229 * 230 * @param annotationID 231 * @param userID 232 * @return permission of the userID w.r.t. annotationID, or null if the permission is not given233 * /234 public Permission getPermission(Number annotationID, Number userID);235 236 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 237 235 public String getTypeOfUserAccount(Number userID); 238 236 239 237 public boolean canRead(Number userID, Number annotationID); 240 241 public boolean canWrite(Number userID, Number annotationID); 242 238 239 public boolean canWrite(Number userID, Number annotationID); 240 241 /// notebooks /// 242 public NotebookInfoList getNotebooks(Number prinipalID, Permission permission); 243 244 public NotebookInfoList getNotebooksOwnedBy(Number principalID); 245 246 public List<UUID> getPrincipals(Number notebookID, Permission permission); 247 248 public NotebookInfo getNotebookInfo(Number notebookID); 249 250 List<UUID> getAnnotationsForNotebook(Number notebookID, int startAnnotation, int maximumAnnotations, String orderedBy, boolean desc); 251 243 252 /** 244 253 * UPDATERS 245 254 */ 246 247 255 public boolean updateAccount(UUID userExternalID, String account); 248 249 250 /** 251 * 256 257 /** 258 * 252 259 * @param annotation 253 260 * @return 1 of the annotation if it is updated 254 261 */ 255 262 int updateAnnotation(Annotation annotation); 256 257 258 259 /** 260 * 263 264 /** 265 * 261 266 * @param userID 262 267 * @param annotationBody … … 264 269 */ 265 270 int updateAnnotationBody(Number internalID, AnnotationBody annotationBody); 266 267 268 269 /** 270 * 271 272 /** 273 * 271 274 * @param annotationID 272 275 * @param userID 273 276 * @param permission 274 277 * @return # rows updated to the table "annotations_principals_permissions" 275 * Sets the "permission" for the "userID" w.r.t. the annotation with "annotationID". 278 * Sets the "permission" for the "userID" w.r.t. the annotation with 279 * "annotationID". 276 280 */ 277 281 public int updateAnnotationPrincipalPermission(Number annotationID, Number userID, Permission permission); 278 279 /**280 * 282 283 /** 284 * 281 285 * @param annotationID 282 286 * @param permissionList 283 * @return # of rows updated or added in the table annotations_principals_permissions 287 * @return # of rows updated or added in the table 288 * annotations_principals_permissions 284 289 */ 285 290 public int updatePermissions(Number annotationID, UserWithPermissionList permissionList); 286 291 287 292 public Number updateUser(User user); 288 289 /** 290 * ADDERS 291 */ 292 /** 293 * 293 294 /// notebooks /// 295 public boolean updateNotebookMetadata(Number notebookID, NotebookInfo upToDateNotebookInfo); 296 297 public boolean addAnnotationToNotebook(Number notebookID, Number annotationID); 298 299 /** 300 * ADDERS 301 */ 302 /** 303 * 294 304 * @param targetID 295 305 * @param cachedInfo 296 306 * @param cachedBlob 297 * @return result[0] = # updated rows in the table "Targets_cached_representations" (must be 1 or 0). 298 * result[1] = the internal ID of the added cached (a new one if "cached" was new for the Data Base). 307 * @return result[0] = # updated rows in the table 308 * "Targets_cached_representations" (must be 1 or 0). result[1] = the 309 * internal ID of the added cached (a new one if "cached" was new for the 310 * Data Base). 299 311 */ 300 312 Number[] addCachedForTarget(Number targetID, String fragmentDescriptor, CachedRepresentationInfo cachedInfo, InputStream cachedBlob); 301 302 303 /** 304 * 313 314 /** 315 * 305 316 * @param annotationID 306 317 * @param targets 307 * @return map temporaryTargetID |--> TargetExternalID. Its domain is the temporary IDs of all the new Targets. While adding a new Target a new external ID is generated for it and it becomes the value of the map. The TargetIDs which are already present in the DB are not in the domain. If all Targets are old, then the map is empty. 308 * @throws SQLException 318 * @return map temporaryTargetID |--> TargetExternalID. Its domain is the 319 * temporary IDs of all the new Targets. While adding a new Target a new 320 * external ID is generated for it and it becomes the value of the map. The 321 * TargetIDs which are already present in the DB are not in the domain. If 322 * all Targets are old, then the map is empty. 323 * @throws SQLException 309 324 */ 310 325 Map<String, String> addTargetsForAnnotation(Number annotationID, List<TargetInfo> targets); 311 326 312 327 /** 313 * 328 * 314 329 * @param userID 315 330 * @param annotation 316 * @return the internalId of the just added "annotation" (or null if it is not added) by the owner "userID".317 * calls "addTargetsForAnnotation"318 * @throws SQLException 331 * @return the internalId of the just added "annotation" (or null if it is 332 * not added) by the owner "userID". calls "addTargetsForAnnotation" 333 * @throws SQLException 319 334 */ 320 335 Number addUsersAnnotation(Number ownerID, Annotation annotation); 321 322 /** 323 * 336 337 /** 338 * 324 339 * @param user 325 340 * @param remoteID is got from the server 326 * @return the internal Id of the just added "user", or null if it was not added for some reason (already exists) 327 * @throws SQLException 341 * @return the internal Id of the just added "user", or null if it was not 342 * added for some reason (already exists) 343 * @throws SQLException 328 344 */ 329 345 Number addUser(User user, String remoteID); 330 346 331 347 int addAnnotationPrincipalPermission(Number annotationID, Number userID, Permission permission); 332 348 349 /// notebooks //// 350 Number createNotebook(Notebook notebook, Number ownerID); 351 352 boolean createAnnotationInNotebook(Number notebookID, Annotation annotation, Number ownerID); 353 333 354 /** 334 355 * DELETERS 335 356 */ 336 337 /**338 * 339 * @ param userID340 * @return # of affected rows in the table "principal".341 * It is 1 if the userId is found and deleted;342 * it is 0 if it is not found or not deleted, e.g. because it is in use in the table"annotationsPreincipalsPermissions"357 /** 358 * 359 * @param userID 360 * @return # of affected rows in the table "principal". It is 1 if the 361 * userId is found and deleted; it is 0 if it is not found or not deleted, 362 * e.g. because it is in use in the table 363 * "annotationsPreincipalsPermissions" 343 364 */ 344 365 public int deleteUser(Number userID); 345 346 /** 347 * 348 * @param userID 349 * @return # of affected rows in the table "principal". 350 * It is 1 if the userId is found and deleted; 351 * it is 0 if it is not found or not deleted, e.g. because it is in use in the table "annotationsPreincipalsPermissions" 366 367 /** 368 * 369 * @param userID 370 * @return # of affected rows in the table "principal". It is 1 if the 371 * userId is found and deleted; it is 0 if it is not found or not deleted, 372 * e.g. because it is in use in the table 373 * "annotationsPreincipalsPermissions" 352 374 */ 353 375 public int deleteUserSafe(Number userID); 354 355 /** 356 * 376 377 /** 378 * 357 379 * @param TargetID 358 380 * @param cachedID 359 * @return result[0] = # deleted rows in the table "Targets_cached_representations" (1, or 0). 360 * result[1] = # deleted rows in the table "cached_representation" (should be 0 if the cached representation is in use by some other Target???). 361 */ 362 int[] deleteCachedRepresentationOfTarget(Number TargetID, Number cachedID) ; 363 381 * @return result[0] = # deleted rows in the table 382 * "Targets_cached_representations" (1, or 0). result[1] = # deleted rows in 383 * the table "cached_representation" (should be 0 if the cached 384 * representation is in use by some other Target???). 385 */ 386 int[] deleteCachedRepresentationOfTarget(Number TargetID, Number cachedID); 387 388 /** 389 * 390 * @param targetID 391 * @return result[0] = # deleted rows in the table 392 * "targets_cached_representations". result[1] = # deleted rows in the table 393 * "cached_representation". 394 * 395 */ 396 int[] deleteAllCachedRepresentationsOfTarget(Number versionID); 397 398 /** 399 * 400 * @param annotationID 401 * @return result[0] = # deleted rows in the table "annotation" (1 or 0). 402 * result[1] = # deleted rows in the table 403 * "annotations_principals_permissions". result[2] = # deleted rows in the 404 * table "annotations_target_Targets". result[3] = # deleted rows in the 405 * table "Target". 406 * @throws SQLException 407 */ 408 int[] deleteAnnotation(Number annotationID); 364 409 365 366 367 368 /** 369 * 370 * @param targetID 371 * @return 372 * result[0] = # deleted rows in the table "targets_cached_representations". 373 * result[1] = # deleted rows in the table "cached_representation". 374 **/ 375 376 int[] deleteAllCachedRepresentationsOfTarget(Number versionID); 377 378 379 380 /** 381 * 382 * @param annotationID 383 * @return result[0] = # deleted rows in the table "annotation" (1 or 0). 384 * result[1] = # deleted rows in the table "annotations_principals_permissions". 385 * result[2] = # deleted rows in the table "annotations_target_Targets". 386 * result[3] = # deleted rows in the table "Target". 387 * @throws SQLException 388 */ 389 int[] deleteAnnotation(Number annotationID); 390 391 410 /// notebooks /// 411 boolean deleteNotebook(Number notebookID); 392 412 393 413 } -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/NotebookDao.java
r4493 r4495 23 23 import eu.dasish.annotation.schema.NotebookInfo; 24 24 import java.util.List; 25 import java.util.UUID; 25 26 26 27 /** … … 39 40 * GETTERS 40 41 * 41 */ 42 // Returns a list of notebook Ids for the notebooks for which the given user "userID' has "permission" access. 43 List<Number> getNotebookIDs(Number userID, Permission acessMode); 42 **/ 43 44 Number getOwner(Number notebookID); 45 46 List<Number> getNotebookIDs(Number principalID, Permission acessMode); 44 47 45 48 // Returns a list of notebook Ids for the notebooks for which the given user "userID" is the owner. 46 List<Number> get OwnerNotebookIDs(Number userID);49 List<Number> getNotebookIDsOwnedBy(Number principaID); 47 50 48 51 public List<Number> getPrincipalIDsWithPermission(Number notebookID, Permission permission); 52 49 53 50 54 … … 55 59 * @return the notebook info for the notebook with notebookID 56 60 */ 57 NotebookInfo getNotebookInfo (Number notebookID);61 NotebookInfo getNotebookInfoWithoutOwner(Number notebookID); 58 62 59 63 … … 63 67 * @return notebook metadata for the notebook with notebookID 64 68 */ 65 Notebook getNotebookWithoutAnnotationsAndPermissions (Number notebookID);69 Notebook getNotebookWithoutAnnotationsAndPermissionsAndOwner(Number notebookID); 66 70 67 //? Which type shul be orderedby? 68 /** 69 * 70 * @param maximumAnnotations 71 * @param startannotation 72 * @param orderedBy 73 * @param orederingMode if true then descending, if falset hen ascending 74 * @return 75 */ 76 List<Number> getAnnotations(int maximumAnnotations, int startannotation, String orderedBy, boolean orderingMode); 71 72 List<Number> getAnnotations(Number notebookID); 77 73 78 74 /** … … 90 86 * @return true if updated, false otherwise. Logs the reason if the notebook is not updated. 91 87 */ 92 boolean updateNotebookMetadata(Number notebookID); 88 boolean updateNotebookMetadata(Number notebookID, String title, Number ownerID); 89 90 boolean setOwner(Number notebookID, Number ownerID); 91 92 boolean updateUserPermissionForNotebook(Number notebookID, Number principalID, Permission permission); 93 93 94 94 /** … … 99 99 */ 100 100 101 Number createNotebook(Notebook notebook);101 public Number createNotebookWithoutPermissionsAndAnnotations(Notebook notebook, Number ownerID); 102 102 103 boolean addAnnotationToNotebook(Number noteboookId, Number AnnotationID); 103 boolean addAnnotationToNotebook(Number notebookID, Number annotationID); 104 105 boolean addPermissionToNotebook(Number notebookID, Number userID, Permission permission); 104 106 105 107 … … 107 109 /** 108 110 * 109 * DELETERS (ADDER)111 * DELETERS 110 112 * 111 113 * 112 114 */ 113 115 114 boolean deleteannotationFromNotebook(Number notebookID, Number annotationID); 116 boolean deleteAnnotationFromNotebook(Number notebookID, Number annotationID); 117 118 boolean deleteAllAnnotationsFromNotebook(Number notebookID); 119 120 boolean deleteNotebookPrincipalPermission(Number notebookID, Number principalID); 121 122 boolean deleteAllPermissionsForNotebook(Number notebookID); 115 123 116 124 boolean deleteNotebook(Number notebookID); -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/impl/DBIntegrityServiceImlp.java
r4491 r4495 22 22 import eu.dasish.annotation.backend.dao.CachedRepresentationDao; 23 23 import eu.dasish.annotation.backend.dao.DBIntegrityService; 24 import eu.dasish.annotation.backend.dao.NotebookDao; 24 25 import eu.dasish.annotation.backend.dao.TargetDao; 25 26 import eu.dasish.annotation.backend.dao.UserDao; … … 32 33 import eu.dasish.annotation.schema.CachedRepresentationFragmentList; 33 34 import eu.dasish.annotation.schema.CachedRepresentationInfo; 35 import eu.dasish.annotation.schema.Notebook; 36 import eu.dasish.annotation.schema.NotebookInfo; 37 import eu.dasish.annotation.schema.NotebookInfoList; 34 38 import eu.dasish.annotation.schema.TargetInfoList; 35 39 import eu.dasish.annotation.schema.Permission; … … 65 69 @Autowired 66 70 AnnotationDao annotationDao; 67 71 @Autowired 72 NotebookDao notebookDao; 68 73 final static protected String admin = "admin"; 69 74 private static final Logger logger = LoggerFactory.getLogger(AnnotationResource.class); … … 403 408 return userDao.getTypeOfUserAccount(userID); 404 409 } 405 410 406 411 @Override 407 412 public boolean canRead(Number userID, Number annotationID) { … … 429 434 return false; 430 435 } 436 } 437 438 /// notebooks /// 439 @Override 440 public NotebookInfoList getNotebooks(Number prinipalID, Permission permission) { 441 NotebookInfoList result = new NotebookInfoList(); 442 List<Number> notebookIDs = notebookDao.getNotebookIDs(prinipalID, permission); 443 for (Number notebookID : notebookIDs) { 444 NotebookInfo notebookInfo = notebookDao.getNotebookInfoWithoutOwner(notebookID); 445 Number ownerID = notebookDao.getOwner(notebookID); 446 notebookInfo.setOwnerRef(userDao.getURIFromInternalID(ownerID)); 447 result.getNotebookInfo().add(notebookInfo); 448 } 449 450 return result; 451 } 452 453 @Override 454 public NotebookInfoList getNotebooksOwnedBy(Number principalID) { 455 NotebookInfoList result = new NotebookInfoList(); 456 List<Number> notebookIDs = notebookDao.getNotebookIDsOwnedBy(principalID); 457 String ownerRef = userDao.getURIFromInternalID(principalID); 458 for (Number notebookID : notebookIDs) { 459 NotebookInfo notebookInfo = notebookDao.getNotebookInfoWithoutOwner(notebookID); 460 notebookInfo.setOwnerRef(ownerRef); 461 result.getNotebookInfo().add(notebookInfo); 462 } 463 464 return result; 465 } 466 467 @Override 468 public List<UUID> getPrincipals(Number notebookID, Permission permission) { 469 List<UUID> result = new ArrayList<UUID>(); 470 List<Number> principalIDs = notebookDao.getPrincipalIDsWithPermission(notebookID, permission); 471 for (Number principalID : principalIDs) { 472 UUID uuid = userDao.getExternalID(principalID); 473 result.add(uuid); 474 } 475 return result; 476 } 477 478 @Override 479 public NotebookInfo getNotebookInfo(Number notebookID) { 480 NotebookInfo result = notebookDao.getNotebookInfoWithoutOwner(notebookID); 481 result.setOwnerRef(userDao.getURIFromInternalID(notebookDao.getOwner(notebookID))); 482 return result; 483 } 484 485 ///////////////////////////////////////////////////////////// 486 @Override 487 public List<UUID> getAnnotationsForNotebook(Number notebookID, int startAnnotation, int maximumAnnotations, String orderedBy, boolean desc) { 488 List<Number> annotationIDs = notebookDao.getAnnotations(notebookID); 489 490 if (startAnnotation < -1) { 491 logger.info("Variable's startAnnotation value " + startAnnotation + " is invalid. I will return null."); 492 return null; 493 } 494 495 if (maximumAnnotations < -1) { 496 logger.info("Variable's maximumAnnotations value " + maximumAnnotations + " is invalid. I will return null."); 497 return null; 498 } 499 500 int offset = (startAnnotation > 0) ? startAnnotation - 1 : 0; 501 String direction = desc ? " DESC " : " ASC "; 502 List<Number> selectedAnnotIDs = annotationDao.sublistOrderedAnnotationIDs(annotationIDs, offset, maximumAnnotations, orderedBy, direction); 503 List<UUID> annotationUUIDs = new ArrayList<UUID>(); 504 for (Number annotationID : selectedAnnotIDs) { 505 annotationUUIDs.add(annotationDao.getExternalID(annotationID)); 506 } 507 return annotationUUIDs; 431 508 } 432 509 … … 489 566 } 490 567 568 @Override 569 public Number updateUser(User user) { 570 return userDao.updateUser(user); 571 } 572 /// notebooks /// 573 574 @Override 575 public boolean updateNotebookMetadata(Number notebookID, NotebookInfo upToDateNotebookInfo) { 576 Number ownerID = userDao.getInternalIDFromURI(upToDateNotebookInfo.getOwnerRef()); 577 return notebookDao.updateNotebookMetadata(notebookID, upToDateNotebookInfo.getTitle(), ownerID); 578 } 579 580 @Override 581 public boolean addAnnotationToNotebook(Number notebookID, Number annotationID) { 582 return notebookDao.addAnnotationToNotebook(notebookID, annotationID); 583 } 584 491 585 /////////////// ADDERS ///////////////////////////////// 492 586 @Override … … 535 629 536 630 @Override 537 public Number updateUser(User user) {538 return userDao.updateUser(user);539 }540 541 @Override542 631 public Number addUser(User user, String remoteID) { 543 632 if (userDao.userExists(user)) { … … 551 640 public int addAnnotationPrincipalPermission(Number annotationID, Number userID, Permission permission) { 552 641 return annotationDao.addAnnotationPrincipalPermission(annotationID, userID, permission); 642 } 643 644 //////////// notebooks ////// 645 646 @Override 647 public Number createNotebook(Notebook notebook, Number ownerID) { 648 Number notebookID = notebookDao.createNotebookWithoutPermissionsAndAnnotations(notebook, ownerID); 649 boolean updateOwner = notebookDao.setOwner(notebookID, ownerID); 650 List<UserWithPermission> permissions = notebook.getPermissions().getUserWithPermission(); 651 for (UserWithPermission principalPermission : permissions) { 652 Number principalID = userDao.getInternalIDFromURI(principalPermission.getRef()); 653 Permission permission = principalPermission.getPermission(); 654 boolean updatePermissions = notebookDao.addPermissionToNotebook(notebookID, principalID, permission); 655 } 656 return notebookID; 657 } 658 659 @Override 660 public boolean createAnnotationInNotebook(Number notebookID, Annotation annotation, Number ownerID) { 661 Number newAnnotationID = this.addUsersAnnotation(ownerID, annotation); 662 return notebookDao.addAnnotationToNotebook(notebookID, newAnnotationID); 553 663 } 554 664 … … 609 719 return result; 610 720 } 721 722 @Override 723 public boolean deleteNotebook(Number notebookID) { 724 boolean deletePermissions = notebookDao.deleteAllPermissionsForNotebook(notebookID); 725 boolean deleteAnnotations = notebookDao.deleteAllAnnotationsFromNotebook(notebookID); 726 return notebookDao.deleteNotebook(notebookID); 727 } 611 728 612 729 ////////////// HELPERS //////////////////// -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/impl/JdbcAnnotationDao.java
r4491 r4495 67 67 StringBuilder sql = new StringBuilder("SELECT DISTINCT "); 68 68 sql.append(target_id).append(" FROM ").append(annotationsTargetsTableName).append(" WHERE ").append(annotation_id).append("= ?"); 69 return getSimpleJdbcTemplate().query(sql.toString(), TargetIDRowMapper, annotationID);69 return getSimpleJdbcTemplate().query(sql.toString(), targetIDRowMapper, annotationID); 70 70 } else { 71 71 loggerAnnotationDao.debug(nullArgument); … … 94 94 }; 95 95 96 97 98 96 @Override 99 97 public Permission getPermission(Number annotationID, Number userID) { … … 128 126 }; 129 127 130 131 132 133 128 //////////////////////////////////////////////////////////////////////// 134 129 @Override … … 143 138 params.put("ownerId", ownerID); 144 139 } 145 140 146 141 if (after != null) { 147 142 sql.append(" AND ").append(last_modified).append(" > :afterTimestamp"); … … 161 156 } 162 157 163 158 /////////////////////////////////////////////////////////////////////////////////// 164 159 @Override 165 160 public List<Number> getAnnotationIDsForUserWithPermission(Number userID, String access) { 166 161 167 162 if (userID == null) { 168 163 loggerAnnotationDao.debug("userID: " + nullArgument); 169 164 return null; 170 165 } 171 166 172 167 if (access == null) { 173 168 logger.info("The access argument is null. I assign it a default value 'reader'."); … … 175 170 } 176 171 177 172 178 173 StringBuilder sql = new StringBuilder("SELECT "); 179 174 sql.append(annotation_id).append(" FROM ").append(permissionsTableName).append(" WHERE "). … … 183 178 } 184 179 185 186 187 188 189 180 ////////////////////////////// 190 181 @Override … … 203 194 return getSimpleJdbcTemplate().query(query.toString(), internalIDRowMapper); 204 195 } 205 206 207 208 196 209 197 ///////////////////////////////////////// 210 198 @Override … … 215 203 } 216 204 205 @Override 206 public List<Number> sublistOrderedAnnotationIDs(List<Number> annotationIDs, int offset, int limit, String orderedBy, String direction) { 207 if (annotationIDs == null) { 208 return null; 209 } 210 211 if (annotationIDs.isEmpty()) { 212 return annotationIDs; 213 } 214 215 216 String values = makeListOfValues(annotationIDs); 217 Map<String, Object> params = new HashMap<String, Object>(); 218 params.put("offset", offset); 219 params.put("limit", limit); 220 221 StringBuilder query = new StringBuilder("SELECT DISTINCT "); 222 query.append(annotation_id).append(" FROM ").append(annotationsTargetsTableName).append(" WHERE ").append(annotation_id).append(" IN "); 223 query.append(values).append(" ORDER BY ").append(orderedBy); 224 225 if (limit > -1) { 226 query.append(direction).append(" LIMIT :limit "); 227 } 228 229 query.append(" OFFSET :offset "); 230 return getSimpleJdbcTemplate().query(query.toString(), internalIDRowMapper, params); 231 } 232 233 ////////////////////////////////////////////////////////////////////// 217 234 @Override 218 235 public AnnotationInfo getAnnotationInfoWithoutTargets(Number annotationID) { … … 265 282 String values = makeListOfValues(annotationIDs); 266 283 StringBuilder sql = new StringBuilder("SELECT DISTINCT "); 267 sql.append(external_id).append(" FROM ").append(annotationTableName).append(" WHERE ").append(annotation Annotation_id).append(" IN ").append(values);284 sql.append(external_id).append(" FROM ").append(annotationTableName).append(" WHERE ").append(annotation_id).append(" IN ").append(values); 268 285 return getSimpleJdbcTemplate().query(sql.toString(), annotationREFRowMapper); 269 286 } … … 283 300 } 284 301 StringBuilder sql = new StringBuilder("SELECT "); 285 sql.append(annotationStar).append(" FROM ").append(annotationTableName).append(" WHERE ").append(annotation Annotation_id).append("= ? LIMIT 1");302 sql.append(annotationStar).append(" FROM ").append(annotationTableName).append(" WHERE ").append(annotation_id).append("= ? LIMIT 1"); 286 303 List<Annotation> respond = getSimpleJdbcTemplate().query(sql.toString(), annotationRowMapper, annotationID); 287 304 return (respond.isEmpty() ? null : respond.get(0)); … … 327 344 return (respond.isEmpty() ? null : respond.get(0)); 328 345 } 329 330 331 346 332 347 ///////////////////////////// … … 342 357 StringBuilder sqlTargets = new StringBuilder("SELECT "); 343 358 sqlTargets.append(target_id).append(" FROM ").append(annotationsTargetsTableName).append(" WHERE ").append(annotation_id).append("= ? LIMIT 1"); 344 List<Number> resultTargets = getSimpleJdbcTemplate().query(sqlTargets.toString(), TargetIDRowMapper, annotationID);359 List<Number> resultTargets = getSimpleJdbcTemplate().query(sqlTargets.toString(), targetIDRowMapper, annotationID); 345 360 if (resultTargets.size() > 0) { 346 361 return true; … … 449 464 if (annotation == null) { 450 465 loggerAnnotationDao.debug("annotation: " + nullArgument); 451 return 0; 466 return null; 467 } 468 469 if (ownerID == null) { 470 loggerAnnotationDao.debug("ownerID: " + nullArgument); 471 return null; 452 472 } 453 473 … … 575 595 StringBuilder sqlPermissions = new StringBuilder("DELETE FROM "); 576 596 sqlPermissions.append(permissionsTableName).append(" WHERE ").append(annotation_id).append(" = :annotationId AND "). 577 append(principal_id).append(" = :userId");578 return getSimpleJdbcTemplate().update(sqlPermissions.toString(), params); 597 append(principal_id).append(" = :userId"); 598 return getSimpleJdbcTemplate().update(sqlPermissions.toString(), params); 579 599 } else { 580 600 loggerAnnotationDao.debug("userID: " + nullArgument); -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/impl/JdbcCachedRepresentationDao.java
r4281 r4495 119 119 StringBuilder sql = new StringBuilder("SELECT "); 120 120 sql.append(target_id).append(" FROM ").append(targetsCachedRepresentationsTableName).append(" WHERE ").append(cached_representation_id).append("= ? LIMIT 1"); 121 List<Number> result = getSimpleJdbcTemplate().query(sql.toString(), TargetIDRowMapper, cachedID);121 List<Number> result = getSimpleJdbcTemplate().query(sql.toString(), targetIDRowMapper, cachedID); 122 122 if (result != null) { 123 123 return (!result.isEmpty()); -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/impl/JdbcNotebookDao.java
r4493 r4495 28 28 import java.util.List; 29 29 import java.util.Map; 30 import java.util.UUID; 30 31 import javax.sql.DataSource; 31 32 import org.springframework.jdbc.core.RowMapper; … … 33 34 import javax.xml.datatype.DatatypeFactory; 34 35 import javax.xml.datatype.XMLGregorianCalendar; 36 import org.slf4j.Logger; 37 import org.slf4j.LoggerFactory; 35 38 36 39 /** … … 42 45 public class JdbcNotebookDao extends JdbcResourceDao implements NotebookDao { 43 46 44 // @Autowired 45 // private AnnotationDao jdbcAnnotationDao; 47 private final Logger loggerNotebookDao = LoggerFactory.getLogger(JdbcNotebookDao.class); 48 46 49 public JdbcNotebookDao(DataSource dataSource) { 47 50 setDataSource(dataSource); … … 52 55 /// GETTERS ///////// 53 56 //////////////////////////////////////////////// 54 @Override55 public List<Number> getNotebookIDs(Number userID, Permission acessMode) {56 Map<String, Object> params = new HashMap<String, Object>();57 params.put("principalID", userID);58 params.put("accessMode", acessMode.value());59 String sql = "SELECT " + notebook_id + " FROM " + notebookPermissionsTableName + " WHERE " + principalPrincipal_id + " = :principalID" + " AND " + permission + " = :accessMode";60 return getSimpleJdbcTemplate().query(sql, internalIDRowMapper, params);61 }62 63 57 //////////////////////////////////////////////// 64 58 @Override 65 public List<Number> getOwnerNotebookIDs(Number userID) { 66 String sql = "SELECT " + notebook_id + " FROM " + notebookTableName + " WHERE " + owner_id + " = ?"; 67 return getSimpleJdbcTemplate().query(sql, internalIDRowMapper, userID); 68 } 69 70 59 public Number getOwner(Number notebookID) { 60 if (notebookID == null) { 61 loggerNotebookDao.debug("notebookID: " + nullArgument); 62 return null; 63 } 64 StringBuilder sql = new StringBuilder("SELECT "); 65 sql.append(owner_id).append(" FROM ").append(notebookTableName).append(" WHERE "). 66 append(notebook_id).append(" = ?"); 67 List<Number> result = getSimpleJdbcTemplate().query(sql.toString(), principalIDRowMapper, notebookID); 68 if (result.isEmpty()) { 69 return null; 70 } else { 71 return result.get(0); 72 } 73 } 74 75 @Override 76 public List<Number> getNotebookIDs(Number principalID, Permission permission) { 77 78 if (principalID == null) { 79 loggerNotebookDao.debug("princiaplID: " + nullArgument); 80 return null; 81 } 82 83 if (permission == null) { 84 loggerNotebookDao.debug("permission: " + nullArgument); 85 return null; 86 } 87 88 Map<String, Object> params = new HashMap<String, Object>(); 89 params.put("principalID", principalID); 90 params.put("accessMode", permission.value()); 91 StringBuilder sql = new StringBuilder("SELECT "); 92 sql.append(notebook_id).append(" FROM ").append(notebookPermissionsTableName).append(" WHERE "). 93 append(principal_id).append(" = :principalID AND ").append(permission).append(" = :accessMode"); 94 return getSimpleJdbcTemplate().query(sql.toString(), internalIDRowMapper, params); 95 } 96 97 //////////////////////////////////////////////// 98 @Override 99 public List<Number> getNotebookIDsOwnedBy(Number principalID) { 100 101 if (principalID == null) { 102 loggerNotebookDao.debug("principalID: " + nullArgument); 103 return null; 104 } 105 106 StringBuilder sql = new StringBuilder("SELECT "); 107 sql.append(notebook_id).append(" FROM ").append(notebookTableName).append(" WHERE "). 108 append(owner_id).append(" = ?"); 109 return getSimpleJdbcTemplate().query(sql.toString(), internalIDRowMapper, principalID); 110 } 71 111 72 112 @Override 73 113 public List<Number> getPrincipalIDsWithPermission(Number notebookID, Permission permission) { 74 if (notebookID == null) { 75 return null; 76 } 77 Map<String, Object> params= new HashMap<String, Object>(); 114 if (notebookID == null) { 115 loggerNotebookDao.debug("notebookID: " + nullArgument); 116 return null; 117 } 118 119 if (permission == null) { 120 loggerNotebookDao.debug("permission: " + nullArgument); 121 return null; 122 } 123 Map<String, Object> params = new HashMap<String, Object>(); 78 124 params.put("notebookID", notebookID); 79 params.put("permission", permission.value()); 80 81 String sql = "SELECT " + owner_id + " FROM " + notebookPermissionsTableName + " WHERE " + notebook_id +" = :notebookID AND " +this.permission + " = :permission"; 82 return getSimpleJdbcTemplate().query(sql, principalIDRowMapper, params); 83 84 } 85 86 @Override 87 public NotebookInfo getNotebookInfo(Number notebookID) { 88 if (notebookID == null) { 89 return null; 90 } 91 String sql = "SELECT " + notebookExternal_id + "," + notebookTitle + " FROM " + notebookTableName + " where " + notebook_id + " = ? LIMIT 1"; 92 List<NotebookInfo> result = getSimpleJdbcTemplate().query(sql, notebookInfoRowMapper, notebookID); 125 params.put("accessMode", permission.value()); 126 127 StringBuilder sql = new StringBuilder("SELECT "); 128 sql.append(principal_id).append(" FROM ").append(notebookPermissionsTableName).append(" WHERE "). 129 append(notebook_id).append(" = :notebookID AND ").append(this.permission).append(" = :accessMode"); 130 131 return getSimpleJdbcTemplate().query(sql.toString(), principalIDRowMapper, params); 132 133 } 134 135 @Override 136 public NotebookInfo getNotebookInfoWithoutOwner(Number notebookID) { 137 if (notebookID == null) { 138 loggerNotebookDao.debug("notebookID: " + nullArgument); 139 return null; 140 } 141 142 StringBuilder sql = new StringBuilder("SELECT "); 143 sql.append(external_id).append(" , ").append(title). 144 append(" FROM ").append(notebookTableName).append(" WHERE "). 145 append(notebook_id).append(" = :notebookID"); 146 List<NotebookInfo> result = getSimpleJdbcTemplate().query(sql.toString(), notebookInfoRowMapper, notebookID); 93 147 return (!result.isEmpty() ? result.get(0) : null); 94 148 } … … 104 158 105 159 @Override 106 public Notebook getNotebookWithoutAnnotationsAndPermissions(Number notebookID) { 107 if (notebookID == null) { 108 return null; 109 } 110 String sql = "SELECT " + notebookExternal_id + "," + notebookTitle + "," + last_modified + " FROM " + notebookTableName + " where " + notebook_id + " = ? LIMIT 1"; 111 List<Notebook> result = getSimpleJdbcTemplate().query(sql, notebookRowMapper, notebookID); 160 public Notebook getNotebookWithoutAnnotationsAndPermissionsAndOwner(Number notebookID) { 161 if (notebookID == null) { 162 loggerNotebookDao.debug("notebookID: " + nullArgument); 163 return null; 164 } 165 StringBuilder sql = new StringBuilder("SELECT "); 166 sql.append(external_id).append(" , ").append(title).append(" , ").append(last_modified). 167 append(" FROM ").append(notebookTableName).append(" WHERE "). 168 append(notebook_id).append(" = :notebookID"); 169 List<Notebook> result = getSimpleJdbcTemplate().query(sql.toString(), notebookRowMapper, notebookID); 112 170 return (!result.isEmpty() ? result.get(0) : null); 113 171 } … … 129 187 } 130 188 }; 189 190 @Override 191 public List<Number> getAnnotations(Number notebookID) { 192 193 if (notebookID == null) { 194 loggerNotebookDao.debug("notebookID: " + nullArgument); 195 return null; 196 } 197 198 StringBuilder sql = new StringBuilder("SELECT "); 199 sql.append(annotation_id). 200 append(" FROM ").append(notebooksAnnotationsTableName).append(" WHERE "). 201 append(notebook_id).append(" = :notebookID"); 202 return getSimpleJdbcTemplate().query(sql.toString(), annotationIDRowMapper, notebookID); 203 204 } 205 206 /** 207 * 208 * UPDATERS 209 * 210 * 211 */ 212 /** 213 * 214 * @param notebookID 215 * @return true if updated, false otherwise. Logs the reason if the notebook 216 * is not updated. 217 */ 218 @Override 219 public boolean updateNotebookMetadata(Number notebookID, String title, Number ownerID) { 220 221 if (notebookID == null) { 222 loggerNotebookDao.debug("notebookID: " + nullArgument); 223 return false; 224 } 225 226 if (title == null) { 227 loggerNotebookDao.debug("title: " + nullArgument); 228 return false; 229 } 230 231 if (ownerID == null) { 232 loggerNotebookDao.debug("ownerID: " + nullArgument); 233 return false; 234 } 235 236 Map<String, Object> params = new HashMap<String, Object>(); 237 params.put("notebookID", notebookID); 238 params.put("title", title); 239 params.put("owner", ownerID); 240 241 StringBuilder sql = new StringBuilder("UPDATE "); 242 sql.append(notebookTableName).append(" SET "). 243 append(last_modified).append("= default,"). 244 append(this.title).append("= :title, "). 245 append(owner_id).append("= :owner"). 246 append(" WHERE ").append(notebook_id).append("= :notebookID"); 247 int affectedRows = getSimpleJdbcTemplate().update(sql.toString(), params); 248 if (affectedRows <= 0) { 249 logger.info("For some reason no rows in the table notebooks were updated. "); 250 return false; 251 } else { 252 if (affectedRows > 1) { 253 logger.info("For some reason more than 1 row in the table notebooks were updated. that's strange."); 254 return true; 255 } else { 256 return true; 257 } 258 } 259 } 131 260 132 133 @Override 134 public List<Number> getAnnotations(int maximumAnnotations, int startannotation, String orderedBy, boolean orderingMode){ 135 return null; 136 } 137 138 139 /** 140 * 141 * UPDATERS 142 * 143 * 261 @Override 262 public boolean setOwner(Number notebookID, Number ownerID) { 263 264 if (notebookID == null) { 265 loggerNotebookDao.debug("notebookID: " + nullArgument); 266 return false; 267 } 268 269 if (ownerID == null) { 270 loggerNotebookDao.debug("ownerID: " + nullArgument); 271 return false; 272 } 273 274 Map<String, Object> params = new HashMap<String, Object>(); 275 params.put("notebookID", notebookID); 276 params.put("ownerID", ownerID); 277 278 StringBuilder sql = new StringBuilder("UPDATE "); 279 sql.append(notebookTableName).append(" SET "). 280 append(last_modified).append("= default,"). 281 append(owner_id).append("= :ownerID"). 282 append(" WHERE ").append(notebook_id).append("= :notebookID"); 283 int affectedRows = getSimpleJdbcTemplate().update(sql.toString(), params); 284 if (affectedRows <= 0) { 285 logger.info("For some reason no rows in the table notebooks were updated. "); 286 return false; 287 } else { 288 if (affectedRows > 1) { 289 logger.info("For some reason more than 1 row in the table notebooks were updated. that's strange."); 290 return true; 291 } else { 292 return true; 293 } 294 } 295 } 296 297 @Override 298 public boolean updateUserPermissionForNotebook(Number notebookID, Number principalID, Permission permission) { 299 300 if (notebookID == null) { 301 loggerNotebookDao.debug("notebookID: " + nullArgument); 302 return false; 303 } 304 305 if (principalID == null) { 306 loggerNotebookDao.debug("principalID: " + nullArgument); 307 return false; 308 } 309 310 if (permission == null) { 311 loggerNotebookDao.debug("permission: " + nullArgument); 312 return false; 313 } 314 315 316 Map<String, Object> params = new HashMap<String, Object>(); 317 params.put("notebookID", notebookID); 318 params.put("principalID", principalID); 319 params.put("permission", permission.value()); 320 321 StringBuilder sql = new StringBuilder("UPDATE "); 322 sql.append(notebookPermissionsTableName).append(" SET "). 323 append(notebook_id).append("= :notebookID, "). 324 append(principal_id).append("= :principalID"). 325 append(this.permission).append("= :permission"). 326 append(" WHERE ").append(notebook_id).append("= :notebookID"); 327 int affectedRows = getSimpleJdbcTemplate().update(sql.toString(), params); 328 if (affectedRows <= 0) { 329 logger.info("For some reason no rows in the table notebooks-permissions were updated. "); 330 return false; 331 } else { 332 if (affectedRows > 1) { 333 logger.info("For some reason more than 1 row in the table notebooks-permissions were updated. that's strange."); 334 return true; 335 } else { 336 return true; 337 } 338 } 339 } 340 341 /** 342 * 343 * ADDERS 344 * 345 * 144 346 */ 145 146 147 347 @Override 348 public Number createNotebookWithoutPermissionsAndAnnotations(Notebook notebook, Number ownerID) { 349 if (notebook == null) { 350 loggerNotebookDao.debug("notebook: " + nullArgument); 351 return null; 352 } 353 354 if (ownerID == null) { 355 loggerNotebookDao.debug("ownerID: " + nullArgument); 356 return null; 357 } 358 359 UUID externalID = UUID.randomUUID(); 360 Map<String, Object> params = new HashMap<String, Object>(); 361 params.put("externalId", externalID.toString()); 362 params.put("owner", ownerID); 363 params.put("title", notebook.getTitle()); 364 365 StringBuilder sql = new StringBuilder("INSERT INTO "); 366 sql.append(notebookTableName).append("(").append(external_id).append(",").append(owner_id); 367 sql.append(",").append(title). 368 append(" ) VALUES (:externalId, :owner, :title)"); 369 int affectedRows = getSimpleJdbcTemplate().update(sql.toString(), params); 370 return ((affectedRows > 0) ? getInternalID(externalID) : null); 371 } 372 373 @Override 374 public boolean addAnnotationToNotebook(Number notebookID, Number annotationID) { 375 376 if (notebookID == null) { 377 loggerNotebookDao.debug("notebookID: " + nullArgument); 378 return false; 379 } 380 381 if (annotationID == null) { 382 loggerNotebookDao.debug("annotationID: " + nullArgument); 383 return false; 384 } 385 386 Map<String, Object> params = new HashMap<String, Object>(); 387 params.put("notebookID", notebookID); 388 params.put("annotationID", annotationID); 389 390 StringBuilder sql = new StringBuilder("INSERT INTO "); 391 sql.append(notebooksAnnotationsTableName).append("(").append(notebook_id).append(",").append(annotation_id); 392 sql.append(",").append(" ) VALUES (:notebookID, :annotationID)"); 393 int affectedRows = getSimpleJdbcTemplate().update(sql.toString(), params); 394 return (affectedRows > 0); 395 } 396 397 @Override 398 public boolean addPermissionToNotebook(Number notebookID, Number principalID, Permission permission) { 399 if (notebookID == null) { 400 loggerNotebookDao.debug("notebookID: " + nullArgument); 401 return false; 402 } 403 404 if (principalID == null) { 405 loggerNotebookDao.debug("principalID: " + nullArgument); 406 return false; 407 } 408 409 if (permission == null) { 410 loggerNotebookDao.debug("premission: " + nullArgument); 411 return false; 412 } 413 414 Map<String, Object> params = new HashMap<String, Object>(); 415 params.put("notebookID", notebookID); 416 params.put("principalID", principalID); 417 params.put("permission", permission.value()); 418 419 StringBuilder sql = new StringBuilder("INSERT INTO "); 420 sql.append(notebookPermissionsTableName).append("(").append(notebook_id).append(",").append(principal_id); 421 sql.append(",").append(this.permission). 422 append(" ) VALUES (:notebookID, :principalID, :permission)"); 423 int affectedRows = getSimpleJdbcTemplate().update(sql.toString(), params); 424 return (affectedRows > 0); 425 } 426 148 427 /** 149 * 150 * @param notebookID 151 * @return true if updated, false otherwise. Logs the reason if the notebook is not updated. 428 * 429 * DELETERS 430 * 431 * 152 432 */ 153 433 @Override 154 public boolean updateNotebookMetadata(Number notebookID){ 155 return false; 156 } 157 /** 158 * 159 * ADDERS 160 * 161 * 162 */ 163 164 @Override 165 public Number createNotebook(Notebook notebook){ 166 return null; 167 } 168 169 @Override 170 public boolean addAnnotationToNotebook(Number noteboookId, Number AnnotationID){ 171 return false; 172 } 173 174 175 /** 176 * 177 * DELETERS (ADDER) 178 * 179 * 180 */ 181 182 @Override 183 public boolean deleteannotationFromNotebook(Number notebookID, Number annotationID){ 184 return false; 185 } 186 187 @Override 188 public boolean deleteNotebook(Number notebookID){ 189 return false; 434 public boolean deleteAnnotationFromNotebook(Number notebookID, Number annotationID) { 435 if (notebookID != null) { 436 if (annotationID != null) { 437 Map<String, Number> params = new HashMap(); 438 params.put("notebookID", notebookID); 439 params.put("annotationID", annotationID); 440 StringBuilder sql = new StringBuilder("DELETE FROM "); 441 sql.append(notebooksAnnotationsTableName).append(" WHERE ").append(notebook_id).append(" = :notebookID AND "). 442 append(annotation_id).append(" = :annotationID"); 443 int affectedRows = getSimpleJdbcTemplate().update(sql.toString(), params); 444 return (affectedRows > 0); 445 } else { 446 loggerNotebookDao.debug("annotationID: " + nullArgument); 447 return false; 448 } 449 } else { 450 loggerNotebookDao.debug("notebookID: " + nullArgument); 451 return false; 452 } 453 } 454 455 @Override 456 public boolean deleteNotebookPrincipalPermission(Number notebookID, Number principalID) { 457 if (notebookID != null) { 458 if (principalID != null) { 459 Map<String, Number> params = new HashMap(); 460 params.put("notebookID", notebookID); 461 params.put("principalID", principalID); 462 StringBuilder sqlPermissions = new StringBuilder("DELETE FROM "); 463 sqlPermissions.append(notebookPermissionsTableName).append(" WHERE ").append(notebook_id).append(" = :notebookID AND "). 464 append(principal_id).append(" = :principalID"); 465 int affectedRows = getSimpleJdbcTemplate().update(sqlPermissions.toString(), params); 466 return (affectedRows > 0); 467 } else { 468 loggerNotebookDao.debug("principalID: " + nullArgument); 469 return false; 470 } 471 } else { 472 loggerNotebookDao.debug("notebookID: " + nullArgument); 473 return false; 474 } 475 } 476 477 @Override 478 public boolean deleteAllAnnotationsFromNotebook(Number notebookID) { 479 if (notebookID != null) { 480 StringBuilder sql = new StringBuilder("DELETE FROM "); 481 sql.append(notebooksAnnotationsTableName).append(" WHERE ").append(notebook_id).append(" = ? "); 482 int affectedRows = getSimpleJdbcTemplate().update(sql.toString(), notebookID); 483 return (affectedRows > 0); 484 } else { 485 loggerNotebookDao.debug("notebookID: " + nullArgument); 486 return false; 487 } 488 } 489 490 @Override 491 public boolean deleteAllPermissionsForNotebook(Number notebookID) { 492 if (notebookID != null) { 493 StringBuilder sqlPermissions = new StringBuilder("DELETE FROM "); 494 sqlPermissions.append(notebookPermissionsTableName).append(" WHERE ").append(notebook_id).append(" = ? "); 495 int affectedRows = getSimpleJdbcTemplate().update(sqlPermissions.toString(), notebookID); 496 return (affectedRows > 0); 497 } else { 498 loggerNotebookDao.debug("notebookID: " + nullArgument); 499 return false; 500 } 501 } 502 503 @Override 504 public boolean deleteNotebook(Number notebookID) { 505 if (notebookID != null) { 506 StringBuilder sql = new StringBuilder("DELETE FROM "); 507 sql.append(notebookTableName).append(" WHERE ").append(notebook_id).append(" = ? "); 508 int affectedRows = getSimpleJdbcTemplate().update(sql.toString(), notebookID); 509 return (affectedRows > 0); 510 } else { 511 loggerNotebookDao.debug("notebookID: " + nullArgument); 512 return false; 513 } 190 514 } 191 515 } -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/impl/JdbcResourceDao.java
r4491 r4495 82 82 final static protected String fragment_descriptor = "fragment_descriptor"; 83 83 final static protected String fragment_descriptor_in_cached = "fragment_descriptor_in_cached"; 84 // derived string constants: table+field names85 84 final static protected String annotationStar = annotationTableName + ".*"; 86 final static protected String annotationAnnotation_id = annotationTableName + "." + annotation_id;87 final static protected String annotationExternal_id = annotationTableName + "." + external_id;88 final static protected String notebookStar = notebookTableName + ".*";89 final static protected String notebookNotebook_id = notebookTableName + "." + notebook_id;90 final static protected String notebookTitle = notebookTableName + "." + title;91 final static protected String notebookExternal_id = notebookTableName + "." + external_id;92 final static protected String notebooksAnnotationsTableNameAnnotation_id = notebooksAnnotationsTableName + "." + annotation_id;93 final static protected String principalPrincipal_id = principalTableName + "." + principal_id;94 final static protected String principalExternal_id = principalTableName + "." + external_id;95 85 final static protected String cachedRepresentationStar = cachedRepresentationTableName + ".*"; 96 86 final static protected String targetStar = targetTableName + ".*"; … … 202 192 } 203 193 }; 204 protected final RowMapper<Number> TargetIDRowMapper = new RowMapper<Number>() {194 protected final RowMapper<Number> targetIDRowMapper = new RowMapper<Number>() { 205 195 @Override 206 196 public Number mapRow(ResultSet rs, int rowNumber) throws SQLException { … … 234 224 }; 235 225 236 protected final RowMapper<Number> notebookOwnerIDRowMapper = new RowMapper<Number>() { 237 @Override 238 public Number mapRow(ResultSet rs, int rowNumber) throws SQLException { 239 return rs.getInt(notebookOwner_id); 240 } 241 }; 226 242 227 243 228 @Override -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/impl/JdbcUserDao.java
r4491 r4495 99 99 100 100 StringBuilder sqlNotebooks = new StringBuilder("SELECT "); 101 sqlNotebooks.append( notebookOwner_id).append(" FROM ").append(notebookTableName).append(" WHERE ").append(notebookOwner_id).append("= ? LIMIT 1");102 List<Number> resultNotebooks = getSimpleJdbcTemplate().query(sqlNotebooks.toString(), notebookOwnerIDRowMapper, userID);101 sqlNotebooks.append(owner_id).append(" FROM ").append(notebookTableName).append(" WHERE ").append(owner_id).append("= ? LIMIT 1"); 102 List<Number> resultNotebooks = getSimpleJdbcTemplate().query(sqlNotebooks.toString(), ownerIDRowMapper, userID); 103 103 if (resultNotebooks.size() > 0) { 104 104 return true; -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/test/java/eu/dasish/annotation/backend/dao/impl/DBIntegrityServiceTest.java
r4491 r4495 22 22 import eu.dasish.annotation.backend.dao.AnnotationDao; 23 23 import eu.dasish.annotation.backend.dao.CachedRepresentationDao; 24 import eu.dasish.annotation.backend.dao.NotebookDao; 24 25 import eu.dasish.annotation.backend.dao.TargetDao; 25 26 import eu.dasish.annotation.backend.dao.UserDao; … … 62 63 @ContextConfiguration({"/spring-test-config/dataSource.xml", "/spring-test-config/mockeryDao.xml", "/spring-test-config/mockAnnotationDao.xml", 63 64 "/spring-test-config/mockUserDao.xml", "/spring-test-config/mockTargetDao.xml", "/spring-test-config/mockCachedRepresentationDao.xml", 65 "/spring-test-config/mockNotebookDao.xml", 64 66 "/spring-config/dbIntegrityService.xml"}) 65 67 public class DBIntegrityServiceTest { … … 77 79 @Autowired 78 80 private AnnotationDao annotationDao; 81 @Autowired 82 private NotebookDao notebookDao; 83 79 84 TestInstances testInstances = new TestInstances(TestBackendConstants._TEST_SERVLET_URI); 80 85 -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/test/java/eu/dasish/annotation/backend/rest/AnnotationsTest.java
r4461 r4495 89 89 // sorry for the duplication, but JerseyTest is not aware of 90 90 // @ContextConfiguration 91 return "classpath:spring-config/componentscan.xml, classpath:spring-config/ annotationDao.xml, classpath:spring-config/userDao.xml, classpath:spring-config/targetDao.xml, classpath:spring-config/cachedRepresentationDao.xml, classpath:spring-config/dbIntegrityService.xml, classpath:spring-config/jaxbMarshallerFactory.xml, classpath:spring-test-config/dataSource.xml";91 return "classpath:spring-config/componentscan.xml, classpath:spring-config/notebookDao.xml, classpath:spring-config/annotationDao.xml, classpath:spring-config/userDao.xml, classpath:spring-config/targetDao.xml, classpath:spring-config/cachedRepresentationDao.xml, classpath:spring-config/dbIntegrityService.xml, classpath:spring-config/jaxbMarshallerFactory.xml, classpath:spring-test-config/dataSource.xml"; 92 92 } 93 93
Note: See TracChangeset
for help on using the changeset viewer.