- Timestamp:
- 11/18/14 17:52:24 (10 years ago)
- Location:
- DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend
- Files:
-
- 1 deleted
- 16 edited
Legend:
- Unmodified
- Added
- Removed
-
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/CHANGES.txt
r5774 r5836 64 64 sych with the basic authenticated version. 65 65 66 November 7, 2014. This is a package for a basic authenticated annotator, to test a new feature. 67 Namely, a user with "write" access can update annotation as a whole, but if he also sends permission 68 updates they will be ignored. 66 69 70 November 10, 2014. This is a package for a shibboleth authenticated annotator. Now A user with 71 "write" access can update annotation as a whole, but if he also sends permission updates they will 72 be ignored. 67 73 -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/UPDATE.txt
r5774 r5836 1 1 2 Placing tarball: take the tar-ball of the new version 1. 5.4-shibboleth, and follow the2 Placing tarball: take the tar-ball of the new version 1.6-basic, and follow the 3 3 standard MPI deployment procedure. 4 4 5 This is synchronisation of the shibbolized-authenticated version of the backend 6 to the basic-authnticated, so both versions are complyiant with the same schema. 5 A new feature: a user with "write" access can update 6 annotation as a whole, but if he also sends permission updates they will be 7 ignored. 7 8 8 9 -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/pom.xml
r5774 r5836 5 5 <groupId>eu.dasish.annotation</groupId> 6 6 <artifactId>annotator-backend</artifactId> 7 <version>1. 5.4-shibboleth</version>7 <version>1.6-shibboleth</version> 8 8 <packaging>war</packaging> 9 9 <name>annotator-backend Jersey Webapp</name> -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/AnnotationDao.java
r5661 r5836 58 58 59 59 60 public List<Number> getAnnotationIDsForPermission(Number principalID, Access acess); 61 62 public List<Number> getAnnotationIDsForPublicAccess(Access access); 60 public List<Number> getAnnotationIDsPermissionAtLeast(Number principalID, Access acess); 61 62 63 public List<Number> getAnnotationIDsPublicAtLeast(Access access); 63 64 64 65 … … 85 86 public List<String> getAnnotationREFs(List<Number> annotationIDs); 86 87 87 88 89 90 91 /** 92 * 93 * @param annotationID 94 * @return the list of the internal IDs of all the target Targets of "annotationID". 95 */ 96 //public List<Number> retrieveTargetIDs(Number annotationID); 97 88 98 89 99 90 public Number getOwner(Number annotationID); … … 106 97 */ 107 98 public Access getAccess(Number annotationID, Number principalID); 99 100 public boolean hasExplicitAccess(Number annotationID, Number principalID); 108 101 109 102 … … 148 141 * Sets the "access" for the "principalID" w.r.t. the annotation with "annotationID". 149 142 */ 150 public int add AnnotationPrincipalAccess(Number annotationID, Number principalID, Access access);143 public int addPermission(Number annotationID, Number principalID, Access access); 151 144 152 145 … … 187 180 * Sets the "access" for the "principalID" w.r.t. the annotation with "annotationID". 188 181 */ 189 public int update AnnotationPrincipalAccess(Number annotationID, Number principalID, Access access);190 191 192 public int updatePublicA ttribute(Number annotationID, Access access);182 public int updatePermission(Number annotationID, Number principalID, Access access); 183 184 185 public int updatePublicAccess(Number annotationID, Access access); 193 186 194 187 … … 222 215 * @throws SQLException 223 216 */ 224 public int delete AnnotationPermissions(Number annotationID);225 226 public int delete AnnotationPrincipalAccess(Number annotationID, Number principalID);217 public int deletePermissions(Number annotationID); 218 219 public int deletePermission(Number annotationID, Number principalID); 227 220 228 221 public int deleteAnnotationFromAllNotebooks(Number annotationID); -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/DBDispatcher.java
r5774 r5836 23 23 import eu.dasish.annotation.backend.PrincipalExists; 24 24 import eu.dasish.annotation.backend.Resource; 25 import eu.dasish.annotation.backend.ResourceAction;26 25 import eu.dasish.annotation.schema.Annotation; 27 26 import eu.dasish.annotation.schema.AnnotationBody; … … 32 31 import eu.dasish.annotation.schema.NotebookInfoList; 33 32 import eu.dasish.annotation.schema.Access; 33 import eu.dasish.annotation.schema.Action; 34 34 import eu.dasish.annotation.schema.PermissionList; 35 35 import eu.dasish.annotation.schema.ReferenceList; … … 186 186 * access is not given 187 187 */ 188 Access getAccess(Number annotationID, Number principalID) ;188 Access getAccess(Number annotationID, Number principalID) ; 189 189 190 190 Access getPublicAttribute(Number annotationID); … … 194 194 Principal getDataBaseAdmin() ; 195 195 196 boolean canDo( ResourceActionaction, Number principalID, Number resourceID, Resource resource);196 boolean canDo(Access action, Number principalID, Number resourceID, Resource resource); 197 197 198 198 … … 247 247 * "annotationID". 248 248 */ 249 int update AnnotationPrincipalAccess(Number annotationID, Number principalID, Access access);249 int updatePermission(Number annotationID, Number principalID, Access access); 250 250 251 251 /** -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/impl/DBDispatcherImlp.java
r5774 r5836 24 24 import eu.dasish.annotation.backend.PrincipalCannotBeDeleted; 25 25 import eu.dasish.annotation.backend.PrincipalExists; 26 import eu.dasish.annotation.backend.ResourceAction;27 26 import eu.dasish.annotation.backend.dao.AnnotationDao; 28 27 import eu.dasish.annotation.backend.dao.CachedRepresentationDao; … … 121 120 } 122 121 123 124 122 @Override 125 123 public UUID getResourceExternalIdentifier(Number resourceID, Resource resource) { … … 127 125 } 128 126 129 130 127 @Override 131 128 public Annotation getAnnotation(Number annotationID) { … … 174 171 175 172 //////////////////////////////////////////////////////////////////////// 176 @Override 173 @Override 177 174 public List<Number> getFilteredAnnotationIDs(UUID ownerId, String link, MatchMode matchMode, String text, Number inloggedPrincipalID, String accessMode, String namespace, String after, String before) throws NotInDataBaseException { 178 175 … … 209 206 if (!accessMode.equals("owner")) { 210 207 Access access = Access.fromValue(accessMode); 211 List<Number> annotationIDsAccess = annotationDao.getAnnotationIDsForPermission(inloggedPrincipalID, access); 212 List<Number> annotationIDsPublic = annotationDao.getAnnotationIDsForPublicAccess(access); 213 List<Number> annotationIDsOwned = annotationDao.getFilteredAnnotationIDs(inloggedPrincipalID, text, namespace, after, before); 214 int check1 = this.addAllNoRepetitions(annotationIDsAccess, annotationIDsPublic); 215 int check2 = this.addAllNoRepetitions(annotationIDsAccess, annotationIDsOwned); 216 annotationIDs.retainAll(annotationIDsAccess);// intersection 208 if (access.equals(Access.NONE)) { 209 List<Number> annotationIDsfiletered = new ArrayList<Number>(); 210 Access accessCurrent; 211 for (Number annotationID : annotationIDs) { 212 accessCurrent = annotationDao.getAccess(inloggedPrincipalID, annotationID); 213 if (accessCurrent.equals(Access.NONE)) { 214 annotationIDsfiletered.add(annotationID); 215 } 216 } 217 annotationIDs = annotationIDsfiletered; // yeaahhh I'm relying on garbage collector here 218 } else { 219 List<Number> annotationIDsAccess = annotationDao.getAnnotationIDsPermissionAtLeast(inloggedPrincipalID, access); 220 List<Number> annotationIDsPublic = annotationDao.getAnnotationIDsPublicAtLeast(access); 221 List<Number> annotationIDsOwned = annotationDao.getFilteredAnnotationIDs(inloggedPrincipalID, text, namespace, after, before); 222 int check1 = this.addAllNoRepetitions(annotationIDsAccess, annotationIDsPublic); 223 int check2 = this.addAllNoRepetitions(annotationIDsAccess, annotationIDsOwned); 224 annotationIDs.retainAll(annotationIDsAccess);// intersection 225 } 217 226 } 218 227 } … … 263 272 return annotationIDs; 264 273 } 265 266 private boolean matchCriterium(String currentString, String pattern, MatchMode matchMode) {274 275 private boolean matchCriterium(String currentString, String pattern, MatchMode matchMode) { 267 276 switch (matchMode) { 268 case EXACT: return currentString.equals(pattern); 269 case STARTS_WITH: return currentString.startsWith(pattern); 270 case ENDS_WITH: return currentString.endsWith(pattern); 271 case CONTAINS: return currentString.contains(pattern); 272 default: return false; 277 case EXACT: 278 return currentString.equals(pattern); 279 case STARTS_WITH: 280 return currentString.startsWith(pattern); 281 case ENDS_WITH: 282 return currentString.endsWith(pattern); 283 case CONTAINS: 284 return currentString.contains(pattern); 285 default: 286 return false; 273 287 } 274 288 } … … 413 427 for (Number siblingID : targetIDs) { 414 428 if (!siblingID.equals(targetID)) { 415 referenceList.getHref().add(targetDao.getHrefFromInternalID(siblingID));429 referenceList.getHref().add(targetDao.getHrefFromInternalID(siblingID)); 416 430 } 417 431 } … … 438 452 Access publicAttribute = annotationDao.getPublicAttribute(annotationID); 439 453 Access access = annotationDao.getAccess(annotationID, principalID); 440 if (access != null) { 441 if (publicAttribute.equals(Access.NONE)) { 442 return access; 454 if (publicAttribute.equals(Access.NONE)) { 455 return access; 456 } else { 457 if (publicAttribute.equals(Access.READ)) { 458 if (access.equals(Access.NONE)) { 459 return Access.READ; 460 } else { 461 return access; 462 } 443 463 } else { 444 if (publicAttribute.equals(Access. READ)) {445 if (access.equals(Access.NONE) ) {446 return Access. READ;464 if (publicAttribute.equals(Access.WRITE)) { 465 if (access.equals(Access.NONE) || access.equals(Access.READ)) { 466 return Access.WRITE; 447 467 } else { 448 468 return access; 449 469 } 450 470 } else { 451 return Access.WRITE; 471 if (publicAttribute.equals(Access.ALL)) { 472 return Access.ALL; 473 } else { 474 logger.error("Database problem: the value of public attribute is not a proper Access value: " + publicAttribute.value()); 475 return access; 476 } 452 477 } 453 478 } 454 } else {455 return publicAttribute;456 479 } 457 480 } … … 466 489 return principalDao.getPrincipalInternalIDFromRemoteID(remoteID); 467 490 } 468 491 469 492 @Override 470 493 public UUID getPrincipalExternalIDFromRemoteID(String remoteID) throws NotInDataBaseException { … … 484 507 // !!!so far implemented only for annotations!!! 485 508 @Override 486 public boolean canDo( ResourceActionaction, Number principalID, Number resourceID, Resource resource) {509 public boolean canDo(Access action, Number principalID, Number resourceID, Resource resource) { 487 510 488 511 switch (resource) { … … 509 532 } 510 533 511 private boolean greaterOrEqual(Access access, ResourceAction action) { 512 if (access.equals(Access.WRITE) && (action.equals(ResourceAction.READ) || action.equals(ResourceAction.WRITE))) { 534 private boolean greaterOrEqual(Access access, Access action) { 535 536 if (access.equals(Access.ALL)) { 513 537 return true; 514 538 } 515 if (access.equals(Access.READ) && action.equals(ResourceAction.READ)) { 539 540 if (access.equals(Access.WRITE) && (action.equals(Access.READ) || action.equals(Access.WRITE))) { 541 return true; 542 } 543 if (access.equals(Access.READ) && action.equals(Access.READ)) { 516 544 return true; 517 545 } … … 524 552 public NotebookInfoList getNotebooks(Number principalID, Access access) { 525 553 NotebookInfoList result = new NotebookInfoList(); 526 if (access.equals(Access.READ) || access.equals(Access.WRITE) ) {554 if (access.equals(Access.READ) || access.equals(Access.WRITE) || access.equals(Access.ALL)) { 527 555 List<Number> notebookIDs = notebookDao.getNotebookIDs(principalID, access); 528 556 for (Number notebookID : notebookIDs) { … … 581 609 accesss.add(Access.READ); 582 610 accesss.add(Access.WRITE); 611 accesss.add(Access.ALL); 583 612 for (Access access : accesss) { 584 613 List<Number> principals = principalDao.getPrincipalIDsWithAccessForNotebook(notebookID, access); … … 642 671 default: 643 672 return false; 644 } 645 } 646 673 } 674 } 675 647 676 @Override 648 677 public boolean updateAccount(UUID principalExternalID, String account) throws NotInDataBaseException { … … 651 680 652 681 @Override 653 public int update AnnotationPrincipalAccess(Number annotationID, Number principalID, Access access) {682 public int updatePermission(Number annotationID, Number principalID, Access access) { 654 683 int result; 655 684 if (access != null) { 656 Access currentAccess = annotationDao.getAccess(annotationID, principalID);657 if (c urrentAccess != null) {658 result = annotationDao.update AnnotationPrincipalAccess(annotationID, principalID, access);685 Boolean checkAccess = annotationDao.hasExplicitAccess(annotationID, principalID); 686 if (checkAccess) { 687 result = annotationDao.updatePermission(annotationID, principalID, access); 659 688 } else { 660 result = annotationDao.add AnnotationPrincipalAccess(annotationID, principalID, access);689 result = annotationDao.addPermission(annotationID, principalID, access); 661 690 } 662 691 } else { 663 result = annotationDao.delete AnnotationPrincipalAccess(annotationID, principalID);692 result = annotationDao.deletePermission(annotationID, principalID); 664 693 } 665 694 return result; … … 668 697 @Override 669 698 public int updatePublicAttribute(Number annotationID, Access publicAttribute) { 670 return annotationDao.updatePublicA ttribute(annotationID, publicAttribute);699 return annotationDao.updatePublicAccess(annotationID, publicAttribute); 671 700 } 672 701 673 702 @Override 674 703 public int updatePermissions(Number annotationID, PermissionList permissionList) throws NotInDataBaseException { 675 annotationDao.updatePublicA ttribute(annotationID, permissionList.getPublic());704 annotationDao.updatePublicAccess(annotationID, permissionList.getPublic()); 676 705 List<Permission> permissions = permissionList.getPermission(); 677 706 int result = 0; … … 679 708 Number principalID = principalDao.getInternalIDFromHref(permission.getPrincipalHref()); 680 709 Access access = permission.getLevel(); 681 Access currentAccess = annotationDao.getAccess(annotationID, principalID); 682 if (currentAccess != null) { 683 if (!access.equals(currentAccess)) { 684 result = result + annotationDao.updateAnnotationPrincipalAccess(annotationID, principalID, access); 685 } else { 686 result = 0; 687 } 710 Boolean checkAccess = annotationDao.hasExplicitAccess(annotationID, principalID); 711 if (checkAccess) { 712 result = result + annotationDao.updatePermission(annotationID, principalID, access); 688 713 } else { 689 result = result + annotationDao.addAnnotationPrincipalAccess(annotationID, principalID, access); 690 } 691 714 result = result + annotationDao.addPermission(annotationID, principalID, access); 715 } 692 716 } 693 717 return result; … … 703 727 int deletedTargets = annotationDao.deleteAllAnnotationTarget(annotationID); 704 728 int addedTargets = this.addTargets(annotation, annotationID); 705 729 706 730 Number remoteUserID = principalDao.getPrincipalInternalIDFromRemoteID(remoteUser); 707 708 if (ownerID.equals(remoteUserID) ) {709 int deletedPrinsipalsAccesss = annotationDao.delete AnnotationPermissions(annotationID);731 732 if (ownerID.equals(remoteUserID) || (annotationDao.getAccess(annotationID, remoteUserID).equals(Access.ALL))) { 733 int deletedPrinsipalsAccesss = annotationDao.deletePermissions(annotationID); 710 734 int addedPrincipalsAccesss = this.addPermissions(annotation.getPermissions().getPermission(), annotationID); 711 int updatedPublicAttribute = annotationDao.updatePublicAttribute(annotationID, annotation.getPermissions().getPublic());735 //int updatedPublicAttribute = annotationDao.updatePublicAccess(annotationID, annotation.getPermissions().getPublic()); 712 736 }; 713 737 return updatedAnnotations; … … 722 746 723 747 @Override 724 public int updateAnnotationHeadline(Number internalID, String newHeader) {748 public int updateAnnotationHeadline(Number internalID, String newHeader) { 725 749 return annotationDao.updateAnnotationHeadline(internalID, newHeader); 726 750 } … … 775 799 } 776 800 777 778 801 @Override 779 802 public Map<String, String> addTargetsForAnnotation(Number annotationID, List<TargetInfo> targets) throws NotInDataBaseException { … … 799 822 int affectedAnnotRows = this.addTargets(annotation, annotationID); 800 823 int addedPrincipalsAccesss = this.addPermissions(annotation.getPermissions().getPermission(), annotationID); 801 int updatedPublic = annotationDao.updatePublicAttribute(annotationID, annotation.getPermissions().getPublic());824 //int updatedPublic = annotationDao.updatePublicAccess(annotationID, annotation.getPermissions().getPublic()); 802 825 return annotationID; 803 826 } … … 886 909 public int[] deleteAnnotation(Number annotationID) { 887 910 int[] result = new int[5]; 888 result[1] = annotationDao.delete AnnotationPermissions(annotationID);911 result[1] = annotationDao.deletePermissions(annotationID); 889 912 List<Number> targetIDs = targetDao.getTargetIDs(annotationID); 890 913 result[2] = annotationDao.deleteAllAnnotationTarget(annotationID); … … 925 948 @Override 926 949 public int deleteAnnotationPrincipalAccess(Number annotationID, Number principalID) { 927 return annotationDao.delete AnnotationPrincipalAccess(annotationID, principalID);950 return annotationDao.deletePermission(annotationID, principalID); 928 951 } 929 952 ////////////// HELPERS //////////////////// … … 981 1004 } 982 1005 } 983 984 @Override 985 public UUID getPrincipalExternalIdFromName(String fullName) throws NotInDataBaseException {986 return principalDao.getExternalIdFromName(fullName);987 } 988 989 @Override 990 public List<UUID> getAnnotationExternalIdsFromHeadline(String headline) {1006 1007 @Override 1008 public UUID getPrincipalExternalIdFromName(String fullName) throws NotInDataBaseException { 1009 return principalDao.getExternalIdFromName(fullName); 1010 } 1011 1012 @Override 1013 public List<UUID> getAnnotationExternalIdsFromHeadline(String headline) { 991 1014 return annotationDao.getExternalIdFromHeadline(headline); 992 1015 } 993 994 @Override 995 public List<Number> getAnnotationInternalIDsFromHeadline(String headline) {1016 1017 @Override 1018 public List<Number> getAnnotationInternalIDsFromHeadline(String headline) { 996 1019 return annotationDao.getInternalIDsFromHeadline(headline); 997 1020 } … … 1032 1055 int addedPermissions = 0; 1033 1056 for (Permission permission : permissions) { 1034 addedPermissions = addedPermissions + annotationDao.add AnnotationPrincipalAccess(annotationID, principalDao.getInternalIDFromHref(permission.getPrincipalHref()), permission.getLevel());1057 addedPermissions = addedPermissions + annotationDao.addPermission(annotationID, principalDao.getInternalIDFromHref(permission.getPrincipalHref()), permission.getLevel()); 1035 1058 } 1036 1059 return addedPermissions; -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/impl/JdbcAnnotationDao.java
r5661 r5836 57 57 internalIdName = annotation_id; 58 58 resourceTableName = annotationTableName; 59 60 59 } 61 60 … … 71 70 StringBuilder sql = new StringBuilder("SELECT "); 72 71 sql.append(principal_id).append(",").append(access).append(" FROM ").append(permissionsTableName).append(" WHERE ").append(annotation_id).append(" = ?"); 73 logger.debug("Parameter " + annotation_id + " := " + annotationID.intValue());74 72 return this.loggedQuery(sql.toString(), principalsAccesssRowMapper, annotationID); 75 73 } 76 77 @Override 78 public Access getAccess(Number annotationID, Number principalID) { 79 74 75 private List<Access> getAccessHelper(Number annotationID, Number principalID){ 80 76 Map<String, Number> params = new HashMap<String, Number>(); 81 77 params.put("annotationId", annotationID); … … 86 82 append(annotation_id).append(" = :annotationId ").append(" AND "). 87 83 append(principal_id).append(" = :principalId").append(" LIMIT 1"); 88 List<Access> result = this.loggedQuery(sql.toString(), accessRowMapper, params); 89 if (result.isEmpty()) { 90 return null; 84 return this.loggedQuery(sql.toString(), accessRowMapper, params); 85 } 86 87 @Override 88 public boolean hasExplicitAccess(Number annotationID, Number principalID) { 89 List<Access> result = this.getAccessHelper(annotationID, principalID); 90 if (result == null || result.isEmpty()) { 91 return false; 92 } else { 93 return true; 94 } 95 } 96 97 @Override 98 public Access getAccess(Number annotationID, Number principalID) { 99 List<Access> result = this.getAccessHelper(annotationID, principalID); 100 if (result == null || result.isEmpty()) { 101 return Access.NONE; 91 102 } else { 92 103 return result.get(0); 93 104 } 94 105 } 95 private final RowMapper<Access> accessRowMapper = new RowMapper<Access>() { 96 @Override 97 public Access mapRow(ResultSet rs, int rowNumber) throws SQLException { 98 return Access.fromValue(rs.getString(access)); 99 } 100 }; 101 102 106 103 107 104 108 ///////////////////////////////////////////////////////////////////// … … 109 113 append(annotation_id).append(" = ? ").append(" LIMIT 1"); 110 114 List<Access> result = this.loggedQuery(sql.toString(), public_RowMapper, annotationID); 111 return result.get(0); 112 } 113 114 115 @Override 116 public List<UUID> getExternalIdFromHeadline(String headline){ 115 if (result == null || result.isEmpty()) { 116 return Access.NONE; 117 } else { 118 return result.get(0); 119 } 120 121 } 122 123 @Override 124 public List<UUID> getExternalIdFromHeadline(String headline) { 117 125 StringBuilder requestDB = new StringBuilder("SELECT "); 118 126 requestDB.append(external_id).append(" FROM ").append(annotationTableName).append(" WHERE ").append("'").append(headline).append("'").append("= ?"); 119 return this.loggedQuery(requestDB.toString(), externalIDRowMapper, headline); 120 } 121 122 @Override 123 public List<Number> getInternalIDsFromHeadline(String headline) {127 return this.loggedQuery(requestDB.toString(), externalIDRowMapper, headline); 128 } 129 130 @Override 131 public List<Number> getInternalIDsFromHeadline(String headline) { 124 132 StringBuilder requestDB = new StringBuilder("SELECT "); 125 133 requestDB.append(annotation_id).append(" FROM ").append(annotationTableName).append(" WHERE ").append("'").append(headline).append("'").append("= ?"); 126 return this.loggedQuery(requestDB.toString(), internalIDRowMapper, headline); 134 return this.loggedQuery(requestDB.toString(), internalIDRowMapper, headline); 127 135 } 128 136 … … 157 165 } 158 166 167 159 168 /////////////////////////////////////////////////////////////////////////////////// 160 @Override 161 public List<Number> getAnnotationIDsForPermission(Number principalID, Access access) { 162 169 //this method does not include all the annotations which are NOT in the pair with principal in this table 170 // they have all default NONE access 171 @Override 172 public List<Number> getAnnotationIDsPermissionAtLeast(Number principalID, Access access) { 163 173 StringBuilder sql = new StringBuilder("SELECT "); 164 174 sql.append(annotation_id).append(" FROM ").append(permissionsTableName).append(" WHERE "). … … 170 180 /// helper /// 171 181 private String sqlAccessConstraint(String column, Access access) { 172 173 182 StringBuilder accessConstraint = new StringBuilder(); 174 183 if (access.equals(Access.READ)) { 175 184 accessConstraint.append("(").append(column).append(" = '").append(Access.READ.value()).append("'"); 176 accessConstraint.append(" OR ").append(column).append(" = '").append(Access.WRITE.value()).append("')"); 185 accessConstraint.append(" OR ").append(column).append(" = '").append(Access.WRITE.value()).append("'"); 186 accessConstraint.append(" OR ").append(column).append(" = '").append(Access.ALL.value()).append("')"); 177 187 } else { 178 accessConstraint.append(column).append(" = '").append(access.value()).append("'"); 179 } 180 188 if (access.equals(Access.WRITE)) { 189 accessConstraint.append("(").append(column).append(" = '").append(Access.WRITE.value()).append("'"); 190 accessConstraint.append(" OR ").append(column).append(" = '").append(Access.ALL.value()).append("')"); 191 } else if (access.equals(Access.ALL)) { 192 accessConstraint.append("(").append(column).append(" = '").append(Access.ALL.value()).append("')"); 193 } else { 194 accessConstraint.append("(").append(column).append(" = '").append(Access.NONE.value()).append("')"); 195 } 196 } 181 197 return accessConstraint.toString(); 182 198 } … … 184 200 ///////////// 185 201 @Override 186 public List<Number> getAnnotationIDs ForPublicAccess(Access access) {202 public List<Number> getAnnotationIDsPublicAtLeast(Access access) { 187 203 StringBuilder sql = new StringBuilder("SELECT "); 188 204 sql.append(annotation_id).append(" FROM ").append(annotationTableName).append(" WHERE "). … … 190 206 return this.loggedQuery(sql.toString(), internalIDRowMapper); 191 207 } 192 193 194 208 195 209 ///////////////////////////////////////// … … 317 331 annotation.setTargets(null); 318 332 String externalId = rs.getString(external_id); 319 annotation.setId(externalId); 333 annotation.setId(externalId); 320 334 annotation.setHref(externalIDtoHref(externalId)); 321 335 annotation.setLastModified(timeStampToXMLGregorianCalendar(rs.getString(last_modified))); … … 335 349 } 336 350 337 ///////////////////////////// 338 // @Override 339 // public boolean annotationIsInUse(Number annotationID) { 340 // StringBuilder sqlNotebooks = new StringBuilder("SELECT "); 341 // sqlNotebooks.append(notebook_id).append(" FROM ").append(notebooksAnnotationsTableName).append(" WHERE ").append(annotation_id).append("= ? LIMIT 1"); 342 // List<Number> resultNotebooks = this.loggedQuery(sqlNotebooks.toString(), notebookIDRowMapper, annotationID); 343 // if (resultNotebooks.size() > 0) { 344 // return true; 345 // } 346 // 347 // StringBuilder sqlTargets = new StringBuilder("SELECT "); 348 // sqlTargets.append(target_id).append(" FROM ").append(annotationsTargetsTableName).append(" WHERE ").append(annotation_id).append("= ? LIMIT 1"); 349 // List<Number> resultTargets = this.loggedQuery(sqlTargets.toString(), targetIDRowMapper, annotationID); 350 // if (resultTargets.size() > 0) { 351 // return true; 352 // } 353 // 354 // StringBuilder sqlAccesss = new StringBuilder("SELECT "); 355 // sqlAccesss.append(principal_id).append(" FROM ").append(permissionsTableName).append(" WHERE ").append(annotation_id).append("= ? LIMIT 1"); 356 // List<Number> resultAccesss = this.loggedQuery(sqlAccesss.toString(), principalIDRowMapper, annotationID); 357 // return (resultAccesss.size() > 0); 358 // } 351 359 352 @Override 360 353 public List<Number> getAnnotations(Number notebookID) { … … 395 388 return affectedRows; 396 389 } 397 398 390 391 @Override 399 392 public int updateAnnotationHeadline(Number annotationID, String header) { 400 393 Map<String, Object> params = new HashMap<String, Object>(); … … 416 409 417 410 String[] body = retrieveBodyComponents(annotation.getBody()); 418 411 419 412 Map<String, Object> params = new HashMap<String, Object>(); 420 413 params.put("owner", newOwnerID); … … 423 416 params.put("headline", annotation.getHeadline()); 424 417 params.put("isXml", annotation.getBody().getXmlBody() != null); 425 params.put("externalId", annotation.getId()); 418 params.put("externalId", annotation.getId()); 419 params.put("publicAccess", annotation.getPermissions().getPublic().value()); 426 420 params.put("annotationId", annotationID); 427 421 … … 434 428 append(last_modified).append("= default,"). 435 429 append(is_xml).append("= :isXml, "). 436 append(external_id).append("= :externalId"). 437 append(" WHERE ").append(annotation_id).append("= :annotationId"); 430 append(external_id).append("= :externalId, "). 431 append(public_).append("= :publicAccess"). 432 append(" WHERE ").append(annotation_id).append("= :annotationId"); 438 433 int affectedRows = this.loggedUpdate(sql.toString(), params); 439 434 440 435 return affectedRows; 441 436 } 442 437 443 438 @Override 444 public int update AnnotationPrincipalAccess(Number annotationID, Number principalID, Access access) {439 public int updatePermission(Number annotationID, Number principalID, Access access) { 445 440 446 441 Map<String, Object> params = new HashMap<String, Object>(); … … 460 455 461 456 @Override 462 public int updatePublicA ttribute(Number annotationID, Access access) {457 public int updatePublicAccess(Number annotationID, Access access) { 463 458 464 459 Map<String, Object> params = new HashMap<String, Object>(); … … 486 481 params.put("bodyText", body[0]); 487 482 params.put("bodyMimeType", body[1]); 488 params.put("isXml", annotation.getBody().getXmlBody() != null); 483 params.put("isXml", annotation.getBody().getXmlBody() != null); 484 params.put("publicAccess", annotation.getPermissions().getPublic().value()); 489 485 490 486 StringBuilder sql = new StringBuilder("INSERT INTO "); 491 487 sql.append(annotationTableName).append("(").append(external_id).append(",").append(owner_id); 492 sql.append(",").append(headline).append(",").append(body_text).append(",").append(body_mimetype).append(",").append(is_xml). 493 append(" ) VALUES (:externalId, :owner, :headline, :bodyText, :bodyMimeType, :isXml )");488 sql.append(",").append(headline).append(",").append(body_text).append(",").append(body_mimetype).append(",").append(is_xml).append(",").append(public_). 489 append(" ) VALUES (:externalId, :owner, :headline, :bodyText, :bodyMimeType, :isXml, :publicAccess)"); 494 490 int affectedRows = this.loggedUpdate(sql.toString(), params); 495 491 return getInternalID(externalID); … … 509 505 ///////////////////////////////////////////////////////////////////////////////////////// 510 506 @Override 511 public int add AnnotationPrincipalAccess(Number annotationID, Number principalID, Access access) {507 public int addPermission(Number annotationID, Number principalID, Access access) { 512 508 513 509 Map<String, Object> paramsAccesss = new HashMap<String, Object>(); … … 541 537 ////////////////////////////////////////////////////// 542 538 @Override 543 public int delete AnnotationPermissions(Number annotationID) {539 public int deletePermissions(Number annotationID) { 544 540 StringBuilder sqlAccesss = new StringBuilder("DELETE FROM "); 545 541 sqlAccesss.append(permissionsTableName).append(" WHERE ").append(annotation_id).append(" = ?"); 546 542 return this.loggedUpdate(sqlAccesss.toString(), annotationID); // removed "access" rows 547 543 } 548 549 //////////////////////////////////////// 550 @Override 551 public int deleteAnnotationFromAllNotebooks(Number annotationID) { 552 StringBuilder sql = new StringBuilder("DELETE FROM "); 553 sql.append(notebooksAnnotationsTableName).append(" WHERE ").append(annotation_id).append(" = ?"); 554 return this.loggedUpdate(sql.toString(), annotationID); // removed "notebook-annotation" rows 555 556 } 557 544 558 545 ////////////////////////////////////////////////////// 559 546 @Override 560 public int delete AnnotationPrincipalAccess(Number annotationID, Number principalID) {547 public int deletePermission(Number annotationID, Number principalID) { 561 548 Map<String, Number> params = new HashMap(); 562 549 params.put("annotationId", annotationID); … … 568 555 569 556 } 557 558 //////////////////////////////////////// 559 @Override 560 public int deleteAnnotationFromAllNotebooks(Number annotationID) { 561 StringBuilder sql = new StringBuilder("DELETE FROM "); 562 sql.append(notebooksAnnotationsTableName).append(" WHERE ").append(annotation_id).append(" = ?"); 563 return this.loggedUpdate(sql.toString(), annotationID); // removed "notebook-annotation" rows 564 565 } 566 567 570 568 /////////////// helpers ////////////////// 571 569 -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/impl/JdbcResourceDao.java
r5468 r5836 264 264 } 265 265 }; 266 protected final RowMapper<Access> accessRowMapper = new RowMapper<Access>() { 267 @Override 268 public Access mapRow(ResultSet rs, int rowNumber) throws SQLException { 269 Access result =Access.fromValue(rs.getString(access)); 270 return result; 271 } 272 }; 266 273 protected final RowMapper<Access> public_RowMapper = new RowMapper<Access>() { 267 274 @Override -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/rest/AnnotationResource.java
r5774 r5836 23 23 import eu.dasish.annotation.backend.NotInDataBaseException; 24 24 import eu.dasish.annotation.backend.Resource; 25 import eu.dasish.annotation.backend.ResourceAction;26 25 import eu.dasish.annotation.backend.dao.ILambda; 27 26 import eu.dasish.annotation.schema.Annotation; … … 94 93 Map params = new HashMap(); 95 94 try { 96 Annotation result = (Annotation) (new RequestWrappers(this)).wrapRequestResource(params, new GetAnnotation(), Resource.ANNOTATION, ResourceAction.READ, externalIdentifier);95 Annotation result = (Annotation) (new RequestWrappers(this)).wrapRequestResource(params, new GetAnnotation(), Resource.ANNOTATION, Access.READ, externalIdentifier); 97 96 if (result != null) { 98 97 return (new ObjectFactory()).createAnnotation(result); … … 125 124 Map params = new HashMap(); 126 125 try { 127 ReferenceList result = (ReferenceList) (new RequestWrappers(this)).wrapRequestResource(params, new GetTargetList(), Resource.ANNOTATION, ResourceAction.READ, externalIdentifier);126 ReferenceList result = (ReferenceList) (new RequestWrappers(this)).wrapRequestResource(params, new GetTargetList(), Resource.ANNOTATION, Access.READ, externalIdentifier); 128 127 if (result != null) { 129 128 return (new ObjectFactory()).createTargetList(result); … … 244 243 Map params = new HashMap(); 245 244 try { 246 PermissionList result = (PermissionList) (new RequestWrappers(this)).wrapRequestResource(params, new GetPermissionList(), Resource.ANNOTATION, ResourceAction.READ, externalIdentifier);245 PermissionList result = (PermissionList) (new RequestWrappers(this)).wrapRequestResource(params, new GetPermissionList(), Resource.ANNOTATION, Access.READ, externalIdentifier); 247 246 if (result != null) { 248 247 return (new ObjectFactory()).createPermissionList(result); … … 273 272 Map params = new HashMap(); 274 273 try { 275 int[] result = (int[]) (new RequestWrappers(this)).wrapRequestResource(params, new DeleteAnnotation(), Resource.ANNOTATION, ResourceAction.DELETE, externalIdentifier);274 int[] result = (int[]) (new RequestWrappers(this)).wrapRequestResource(params, new DeleteAnnotation(), Resource.ANNOTATION, Access.ALL, externalIdentifier); 276 275 if (result != null) { 277 276 return result[0] + " annotation(s) is(are) deleted."; … … 344 343 } 345 344 try { 346 Map params = new HashMap(); 347 345 Map params = new HashMap(); 348 346 params.put("annotation", annotation); 349 347 params.put("remoteUser",httpServletRequest.getRemoteUser()); 350 ResponseBody result = (ResponseBody) (new RequestWrappers(this)).wrapRequestResource(params, new UpdateAnnotation(), Resource.ANNOTATION, ResourceAction.WRITE, externalId);348 ResponseBody result = (ResponseBody) (new RequestWrappers(this)).wrapRequestResource(params, new UpdateAnnotation(), Resource.ANNOTATION, Access.WRITE, externalId); 351 349 if (result != null) { 352 350 return (new ObjectFactory()).createResponseBody(result); … … 386 384 params.put("annotationBody", annotationBody); 387 385 try { 388 ResponseBody result = (ResponseBody) (new RequestWrappers(this)).wrapRequestResource(params, new UpdateAnnotationBody(), Resource.ANNOTATION, ResourceAction.WRITE, externalIdentifier);386 ResponseBody result = (ResponseBody) (new RequestWrappers(this)).wrapRequestResource(params, new UpdateAnnotationBody(), Resource.ANNOTATION, Access.WRITE, externalIdentifier); 389 387 if (result != null) { 390 388 return (new ObjectFactory()).createResponseBody(result); … … 422 420 params.put("headline", newHeadline); 423 421 try { 424 ResponseBody result = (ResponseBody) (new RequestWrappers(this)).wrapRequestResource(params, new UpdateAnnotationHeadline(), Resource.ANNOTATION, ResourceAction.WRITE, externalIdentifier);422 ResponseBody result = (ResponseBody) (new RequestWrappers(this)).wrapRequestResource(params, new UpdateAnnotationHeadline(), Resource.ANNOTATION, Access.WRITE, externalIdentifier); 425 423 if (result != null) { 426 424 return (new ObjectFactory()).createResponseBody(result); … … 479 477 Map params = new HashMap(); 480 478 params.put("access", accessTyped); 481 Integer result = (Integer) (new RequestWrappers(this)).wrapRequestResource(params, new UpdatePublicAccess(), Resource.ANNOTATION, ResourceAction.WRITE_W_METAINFO, annotationId.toString());479 Integer result = (Integer) (new RequestWrappers(this)).wrapRequestResource(params, new UpdatePublicAccess(), Resource.ANNOTATION, Access.ALL, annotationId.toString()); 482 480 updatedAnnotations = (result != null) ? updatedAnnotations + result.intValue() : updatedAnnotations; 483 481 } … … 486 484 Map params = new HashMap(); 487 485 params.put("access", accessTyped); 488 Integer result = (Integer) (new RequestWrappers(this)).wrapRequestResource(params, new UpdatePublicAccess(), Resource.ANNOTATION, ResourceAction.WRITE_W_METAINFO, annotationDatabaseId);486 Integer result = (Integer) (new RequestWrappers(this)).wrapRequestResource(params, new UpdatePublicAccess(), Resource.ANNOTATION, Access.ALL, annotationDatabaseId); 489 487 if (result != null) { 490 488 return result + " row(s) is(are) updated."; … … 517 515 @Produces(MediaType.APPLICATION_XML) 518 516 @Path("{annotationid: " + BackendConstants.regExpIdentifier + "}/permissions/{principalid: " + BackendConstants.regExpIdentifier + "}") 519 public String update Access(@PathParam("annotationid") String annotationExternalId,517 public String updatePermission(@PathParam("annotationid") String annotationExternalId, 520 518 @PathParam("principalid") String principalExternalId, Access access) throws IOException { 521 519 try { 522 return this.genericUpdateDelete Access(annotationExternalId, principalExternalId, access);520 return this.genericUpdateDeletePermission(annotationExternalId, principalExternalId, access); 523 521 } catch (NotInDataBaseException e1) { 524 522 httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, e1.getMessage()); … … 569 567 String tmp = null; 570 568 for (UUID annotationId : annotationIds) { 571 tmp = this.genericUpdateDelete Access(annotationId.toString(), principalDatabaseId, Access.fromValue(access));569 tmp = this.genericUpdateDeletePermission(annotationId.toString(), principalDatabaseId, Access.fromValue(access)); 572 570 if (!tmp.startsWith("0")) { 573 571 count++; … … 576 574 return (count + " row(s) are updated"); 577 575 } else { 578 return this.genericUpdateDelete Access(annotationDatabaseId, principalDatabaseId, Access.fromValue(access));576 return this.genericUpdateDeletePermission(annotationDatabaseId, principalDatabaseId, Access.fromValue(access)); 579 577 } 580 578 … … 589 587 590 588 //////////////////////////////////////////// 591 private String genericUpdateDelete Access(String annotationId, String principalId, Access access) throws IOException, NotInDataBaseException, ForbiddenException {589 private String genericUpdateDeletePermission(String annotationId, String principalId, Access access) throws IOException, NotInDataBaseException, ForbiddenException { 592 590 Map params = new HashMap(); 593 591 params.put("access", access); 594 592 final Number inputPrincipalID = dbDispatcher.getResourceInternalIdentifier(UUID.fromString(principalId), Resource.PRINCIPAL); 595 593 params.put("inputPrincipalID", inputPrincipalID); 596 Integer result = (Integer) (new RequestWrappers(this)).wrapRequestResource(params, new UpdateP rincipalAccess(), Resource.ANNOTATION, ResourceAction.WRITE_W_METAINFO, annotationId);594 Integer result = (Integer) (new RequestWrappers(this)).wrapRequestResource(params, new UpdatePermissionHelper(), Resource.ANNOTATION, Access.ALL, annotationId); 597 595 if (result != null) { 598 596 return result + " row(s) is(are) updated."; … … 602 600 } 603 601 604 private class UpdateP rincipalAccessimplements ILambda<Map, Integer> {602 private class UpdatePermissionHelper implements ILambda<Map, Integer> { 605 603 606 604 @Override … … 609 607 Number principalID = (Number) params.get("inputPrincipalID"); 610 608 Access access = (Access) params.get("access"); 611 return dbDispatcher.update AnnotationPrincipalAccess(annotationID, principalID, access);609 return dbDispatcher.updatePermission(annotationID, principalID, access); 612 610 } 613 611 } … … 623 621 params.put("permissions", permissions); 624 622 try { 625 ResponseBody result = (ResponseBody) (new RequestWrappers(this)).wrapRequestResource(params, new UpdatePermissions(), Resource.ANNOTATION, ResourceAction.WRITE_W_METAINFO, annotationExternalId);623 ResponseBody result = (ResponseBody) (new RequestWrappers(this)).wrapRequestResource(params, new UpdatePermissions(), Resource.ANNOTATION, Access.ALL, annotationExternalId); 626 624 if (result != null) { 627 625 return new ObjectFactory().createResponseBody(result); … … 655 653 @Produces(MediaType.TEXT_PLAIN) 656 654 @Path("{annotationId: " + BackendConstants.regExpIdentifier + "}/principal/{principalId}/delete") 657 public String deleteP rincipalsAccess(@PathParam("annotationId") String annotationId,655 public String deletePermission(@PathParam("annotationId") String annotationId, 658 656 @PathParam("principalId") String principalId) throws IOException { 659 657 try { 660 return this.genericUpdateDelete Access(annotationId, principalId, null);658 return this.genericUpdateDeletePermission(annotationId, principalId, null); 661 659 } catch (NotInDataBaseException e1) { 662 660 httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, e1.getMessage()); -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/rest/CachedRepresentationResource.java
r5693 r5836 24 24 import eu.dasish.annotation.backend.NotInDataBaseException; 25 25 import eu.dasish.annotation.backend.Resource; 26 import eu.dasish.annotation.backend.ResourceAction;27 26 import eu.dasish.annotation.backend.dao.ILambda; 27 import eu.dasish.annotation.schema.Access; 28 28 import eu.dasish.annotation.schema.CachedRepresentationInfo; 29 29 import eu.dasish.annotation.schema.ObjectFactory; … … 71 71 Map params = new HashMap(); 72 72 try { 73 CachedRepresentationInfo result = (CachedRepresentationInfo) (new RequestWrappers(this)).wrapRequestResource(params, new GetCachedRepresentationInfo(), Resource.CACHED_REPRESENTATION, ResourceAction.READ, externalId);73 CachedRepresentationInfo result = (CachedRepresentationInfo) (new RequestWrappers(this)).wrapRequestResource(params, new GetCachedRepresentationInfo(), Resource.CACHED_REPRESENTATION, Access.READ, externalId); 74 74 if (result != null) { 75 75 return (new ObjectFactory()).createCachedRepresentationInfo(result); … … 103 103 Map params = new HashMap(); 104 104 try { 105 InputStream result = (InputStream) (new RequestWrappers(this)).wrapRequestResource(params, new GetCachedRepresentationInputStream(), Resource.CACHED_REPRESENTATION, ResourceAction.READ, externalId);105 InputStream result = (InputStream) (new RequestWrappers(this)).wrapRequestResource(params, new GetCachedRepresentationInputStream(), Resource.CACHED_REPRESENTATION, Access.READ, externalId); 106 106 if (result != null) { 107 107 ImageIO.setUseCache(false); … … 135 135 Map params = new HashMap(); 136 136 try { 137 return (InputStream) (new RequestWrappers(this)).wrapRequestResource(params, new GetCachedRepresentationInputStream(), Resource.CACHED_REPRESENTATION, ResourceAction.READ, externalId);137 return (InputStream) (new RequestWrappers(this)).wrapRequestResource(params, new GetCachedRepresentationInputStream(), Resource.CACHED_REPRESENTATION, Access.READ, externalId); 138 138 } catch (NotInDataBaseException e1) { 139 139 httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, e1.getMessage()); … … 165 165 params.put("stream", bpe.getInputStream()); 166 166 try { 167 Integer result = (Integer) (new RequestWrappers(this)).wrapRequestResource(params, new UpdateCachedBlob(), Resource.CACHED_REPRESENTATION, ResourceAction.WRITE, cachedIdentifier);167 Integer result = (Integer) (new RequestWrappers(this)).wrapRequestResource(params, new UpdateCachedBlob(), Resource.CACHED_REPRESENTATION, Access.WRITE, cachedIdentifier); 168 168 if (result != null) { 169 169 return result + "rows are updated"; … … 199 199 params.put("stream", input); 200 200 try { 201 Integer result = (Integer) (new RequestWrappers(this)).wrapRequestResource(params, new UpdateCachedBlob(), Resource.CACHED_REPRESENTATION, ResourceAction.WRITE, cachedIdentifier);201 Integer result = (Integer) (new RequestWrappers(this)).wrapRequestResource(params, new UpdateCachedBlob(), Resource.CACHED_REPRESENTATION, Access.WRITE, cachedIdentifier); 202 202 input.close(); 203 203 if (result != null) { … … 240 240 params.put("info", cachedInfo); 241 241 try { 242 Integer result = (Integer) (new RequestWrappers(this)).wrapRequestResource(params, new UpdateCachedMetadata(), Resource.CACHED_REPRESENTATION, ResourceAction.WRITE_W_METAINFO, cachedInfo.getId());242 Integer result = (Integer) (new RequestWrappers(this)).wrapRequestResource(params, new UpdateCachedMetadata(), Resource.CACHED_REPRESENTATION, Access.ALL, cachedInfo.getId()); 243 243 if (result != null) { 244 244 return result + "rows are updated"; -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/rest/RequestWrappers.java
r5684 r5836 22 22 import eu.dasish.annotation.backend.PrincipalExists; 23 23 import eu.dasish.annotation.backend.Resource; 24 import eu.dasish.annotation.backend.ResourceAction;25 24 import eu.dasish.annotation.backend.dao.ILambda; 26 25 import eu.dasish.annotation.backend.dao.ILambdaPrincipal; 26 import eu.dasish.annotation.schema.Access; 27 27 import eu.dasish.annotation.schema.ObjectFactory; 28 28 import eu.dasish.annotation.schema.Principal; … … 30 30 import java.util.Map; 31 31 import java.util.UUID; 32 import javax.servlet.http.HttpServletResponse;33 32 import javax.xml.bind.JAXBElement; 34 33 … … 62 61 } 63 62 64 public T wrapRequestResource(Map params, ILambda<Map, T> dbRequestor, Resource resource, ResourceActionaction, String externalId) throws IOException, ForbiddenException, NotInDataBaseException {63 public T wrapRequestResource(Map params, ILambda<Map, T> dbRequestor, Resource resource, Access action, String externalId) throws IOException, ForbiddenException, NotInDataBaseException { 65 64 Number principalID = resourceResource.getPrincipalID(); 66 65 if (principalID == null) { -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/rest/TargetResource.java
r5693 r5836 24 24 import eu.dasish.annotation.backend.NotInDataBaseException; 25 25 import eu.dasish.annotation.backend.Resource; 26 import eu.dasish.annotation.backend.ResourceAction;27 26 import eu.dasish.annotation.backend.dao.ILambda; 27 import eu.dasish.annotation.schema.Access; 28 28 import eu.dasish.annotation.schema.CachedRepresentationInfo; 29 29 import eu.dasish.annotation.schema.ObjectFactory; 30 30 import eu.dasish.annotation.schema.ReferenceList; 31 import eu.dasish.annotation.schema.ResponseBody;32 31 import eu.dasish.annotation.schema.Target; 33 32 import java.io.IOException; … … 82 81 Map params = new HashMap(); 83 82 try { 84 Target result = (Target) (new RequestWrappers(this)).wrapRequestResource(params, new GetTarget(), Resource.TARGET, ResourceAction.READ, externalIdentifier);83 Target result = (Target) (new RequestWrappers(this)).wrapRequestResource(params, new GetTarget(), Resource.TARGET, Access.READ, externalIdentifier); 85 84 if (result != null) { 86 85 return new ObjectFactory().createTarget(result); … … 114 113 Map params = new HashMap(); 115 114 try { 116 ReferenceList result = (ReferenceList) (new RequestWrappers(this)).wrapRequestResource(params, new GetSiblingTargets(), Resource.TARGET, ResourceAction.READ, externalIdentifier);115 ReferenceList result = (ReferenceList) (new RequestWrappers(this)).wrapRequestResource(params, new GetSiblingTargets(), Resource.TARGET, Access.READ, externalIdentifier); 117 116 if (result != null) { 118 117 return new ObjectFactory().createReferenceList(result); … … 153 152 params.put("fragmentDescriptor", fragmentDescriptor); 154 153 try { 155 CachedRepresentationInfo result = (CachedRepresentationInfo) (new RequestWrappers(this)).wrapRequestResource(params, new PostCached(), Resource.TARGET, ResourceAction.WRITE_W_METAINFO, targetIdentifier);154 CachedRepresentationInfo result = (CachedRepresentationInfo) (new RequestWrappers(this)).wrapRequestResource(params, new PostCached(), Resource.TARGET, Access.ALL, targetIdentifier); 156 155 if (result != null) { 157 156 return new ObjectFactory().createCachedRepresentationInfo(result); -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/webapp/SCHEMA/DASISH-schema.xsd
r5755 r5836 136 136 <xs:enumeration value="write"/> 137 137 <xs:enumeration value="none"/> 138 <xs:enumeration value="all"/> 138 139 </xs:restriction> 139 140 </xs:simpleType> … … 153 154 <xs:attribute name="public" type="dasish:Access" use="required"/> 154 155 </xs:extension> 156 </xs:complexContent> 157 </xs:complexType> 158 159 <xs:complexType name="HistoryRecord"> 160 <xs:sequence> 161 <xs:element name="modifiedByHref" type="xs:anyURI" minOccurs="1" maxOccurs="1"/> 162 <xs:element name="modifiedOn" type="xs:dateTime" minOccurs="1" maxOccurs="1"/> 163 <xs:element name="mdifiedBody" type="dasish:AnnotationBody" minOccurs="1" maxOccurs="1"/> 164 <xs:element name="modifiedHeadline" type="xs:string" minOccurs="1" maxOccurs="1"/> 165 </xs:sequence> 166 </xs:complexType> 167 168 <xs:complexType name="HistoryRecordList"> 169 <xs:complexContent> 170 <xs:extension base="dasish:List"> 171 <xs:sequence> 172 <xs:element name="historyRecord" type="dasish:HistoryRecord" minOccurs="0" 173 maxOccurs="unbounded"/> 174 </xs:sequence> 175 </xs:extension> 155 176 </xs:complexContent> 156 177 </xs:complexType> … … 166 187 <xs:element name="permissions" type="dasish:PermissionList" minOccurs="1" 167 188 maxOccurs="1"/> 189 <xs:element name="historyRecords" type="dasish:HistoryRecordList" minOccurs="0" maxOccurs="1"/> 168 190 </xs:sequence> 169 191 <xs:attribute name="href" type="xs:anyURI" use="required"/> … … 348 370 349 371 <xs:element name="targetInfo" type="dasish:TargetInfo"/> 350 351 <xs:element name="targetInfoList" type="dasish:TargetInfoList"/> 372 373 <xs:element name="historyRecord" type="dasish:HistoryRecord"/> 374 375 <xs:element name="historyRecordList" type="dasish:HistoryRecordList"/> 352 376 353 377 <xs:element name="targetList" type="dasish:ReferenceList"/> -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/test/java/eu/dasish/annotation/backend/dao/impl/DBDispatcherTest.java
r5774 r5836 344 344 will(returnValue(mockAnnotationIDs1)); 345 345 346 oneOf(annotationDao).getAnnotationIDs ForPermission(loggedIn, Access.READ);346 oneOf(annotationDao).getAnnotationIDsPermissionAtLeast(loggedIn, Access.READ); 347 347 will(returnValue(mockAnnotationIDsRead)); 348 348 349 oneOf(annotationDao).getAnnotationIDs ForPublicAccess(Access.READ);349 oneOf(annotationDao).getAnnotationIDsPublicAtLeast(Access.READ); 350 350 will(returnValue(mockAnnotationIDsPublicRead)); 351 351 … … 418 418 will(returnValue(mockAnnotationIDs1)); 419 419 420 oneOf(annotationDao).getAnnotationIDs ForPermission(loggedIn, Access.READ);420 oneOf(annotationDao).getAnnotationIDsPermissionAtLeast(loggedIn, Access.READ); 421 421 will(returnValue(mockAnnotationIDsRead)); 422 422 423 oneOf(annotationDao).getAnnotationIDs ForPublicAccess(Access.READ);423 oneOf(annotationDao).getAnnotationIDsPublicAtLeast(Access.READ); 424 424 will(returnValue(mockAnnotationIDsPublicRead)); 425 425 … … 491 491 will(returnValue(mockAnnotationIDs1)); 492 492 493 oneOf(annotationDao).getAnnotationIDs ForPermission(loggedIn, Access.READ);493 oneOf(annotationDao).getAnnotationIDsPermissionAtLeast(loggedIn, Access.READ); 494 494 will(returnValue(mockAnnotationIDsRead)); 495 495 496 oneOf(annotationDao).getAnnotationIDs ForPublicAccess(Access.READ);496 oneOf(annotationDao).getAnnotationIDsPublicAtLeast(Access.READ); 497 497 will(returnValue(mockAnnotationIDsPublicRead)); 498 498 … … 565 565 will(returnValue(mockAnnotationIDs1)); 566 566 567 oneOf(annotationDao).getAnnotationIDs ForPermission(loggedIn, Access.READ);567 oneOf(annotationDao).getAnnotationIDsPermissionAtLeast(loggedIn, Access.READ); 568 568 will(returnValue(mockAnnotationIDsRead)); 569 569 570 oneOf(annotationDao).getAnnotationIDs ForPublicAccess(Access.READ);570 oneOf(annotationDao).getAnnotationIDsPublicAtLeast(Access.READ); 571 571 will(returnValue(mockAnnotationIDsPublicRead)); 572 572 … … 631 631 will(returnValue(mockAnnotationIDs1)); 632 632 633 oneOf(annotationDao).getAnnotationIDs ForPermission(loggedIn, Access.WRITE);633 oneOf(annotationDao).getAnnotationIDsPermissionAtLeast(loggedIn, Access.WRITE); 634 634 will(returnValue(mockAnnotationIDsWrite)); 635 635 636 oneOf(annotationDao).getAnnotationIDs ForPublicAccess(Access.WRITE);636 oneOf(annotationDao).getAnnotationIDsPublicAtLeast(Access.WRITE); 637 637 will(returnValue(mockAnnotationIDsPublicWrite)); 638 638 … … 695 695 will(returnValue(mockAnnotationIDs1)); 696 696 697 oneOf(annotationDao).getAnnotationIDs ForPermission(loggedIn, Access.WRITE);697 oneOf(annotationDao).getAnnotationIDsPermissionAtLeast(loggedIn, Access.WRITE); 698 698 will(returnValue(mockAnnotationIDsWrite)); 699 699 700 oneOf(annotationDao).getAnnotationIDs ForPublicAccess(Access.WRITE);700 oneOf(annotationDao).getAnnotationIDsPublicAtLeast(Access.WRITE); 701 701 will(returnValue(mockAnnotationIDsPublicWrite)); 702 702 … … 761 761 will(returnValue(mockAnnotationIDs1)); 762 762 763 oneOf(annotationDao).getAnnotationIDs ForPermission(loggedIn, Access.WRITE);763 oneOf(annotationDao).getAnnotationIDsPermissionAtLeast(loggedIn, Access.WRITE); 764 764 will(returnValue(mockAnnotationIDsWrite)); 765 765 766 oneOf(annotationDao).getAnnotationIDs ForPublicAccess(Access.WRITE);766 oneOf(annotationDao).getAnnotationIDsPublicAtLeast(Access.WRITE); 767 767 will(returnValue(mockAnnotationIDsPublicWrite)); 768 768 … … 826 826 will(returnValue(mockAnnotationIDs1)); 827 827 828 oneOf(annotationDao).getAnnotationIDs ForPermission(loggedIn, Access.WRITE);828 oneOf(annotationDao).getAnnotationIDsPermissionAtLeast(loggedIn, Access.WRITE); 829 829 will(returnValue(mockAnnotationIDsWrite)); 830 830 831 oneOf(annotationDao).getAnnotationIDs ForPublicAccess(Access.WRITE);831 oneOf(annotationDao).getAnnotationIDsPublicAtLeast(Access.WRITE); 832 832 will(returnValue(mockAnnotationIDsPublicWrite)); 833 833 … … 1021 1021 will(returnValue(mockAnnotationIDs1)); 1022 1022 1023 oneOf(annotationDao).getAnnotationIDs ForPermission(loggedIn, Access.READ);1023 oneOf(annotationDao).getAnnotationIDsPermissionAtLeast(loggedIn, Access.READ); 1024 1024 will(returnValue(mockAnnotationIDsRead)); 1025 1025 1026 oneOf(annotationDao).getAnnotationIDs ForPublicAccess(Access.READ);1026 oneOf(annotationDao).getAnnotationIDsPublicAtLeast(Access.READ); 1027 1027 will(returnValue(mockAnnotationIDsPublicRead)); 1028 1028 … … 1258 1258 will(returnValue(1)); // the DB update will be called at perform anyway, even if the body is not changed (can be optimized) 1259 1259 1260 oneOf(annotationDao).updatePublicA ttribute(5, Access.WRITE);1260 oneOf(annotationDao).updatePublicAccess(5, Access.WRITE); 1261 1261 will(returnValue(1)); 1262 1262 } … … 1414 1414 mockeryDao.checking(new Expectations() { 1415 1415 { 1416 oneOf(annotationDao).delete AnnotationPermissions(2);1416 oneOf(annotationDao).deletePermissions(2); 1417 1417 will(returnValue(2)); 1418 1418 … … 1767 1767 will(returnValue("/api/principals/00000000-0000-0000-0000-000000000113")); 1768 1768 1769 1769 oneOf(principalDao).getPrincipalIDsWithAccessForNotebook(2, Access.ALL); 1770 will(returnValue(new ArrayList<Number>())); 1770 1771 1771 1772 } … … 1952 1953 will(returnValue(1)); // the DB update will be called at perform anyway, even if the body is not changed (can be optimized) 1953 1954 1954 oneOf(annotationDao).updatePublicA ttribute(5, Access.WRITE);1955 oneOf(annotationDao).updatePublicAccess(5, Access.WRITE); 1955 1956 will(returnValue(1)); 1956 1957 … … 2110 2111 will(returnValue(1)); 2111 2112 2112 oneOf(annotationDao).delete AnnotationPermissions(1);2113 oneOf(annotationDao).deletePermissions(1); 2113 2114 will(returnValue(3)); 2114 2115 … … 2144 2145 will(returnValue(2)); 2145 2146 2146 oneOf(annotationDao).add AnnotationPrincipalAccess(1, 2, Access.WRITE);2147 oneOf(annotationDao).addPermission(1, 2, Access.WRITE); 2147 2148 will(returnValue(1)); 2148 2149 … … 2150 2151 will(returnValue(3)); 2151 2152 2152 oneOf(annotationDao).add AnnotationPrincipalAccess(1, 3, Access.READ);2153 oneOf(annotationDao).addPermission(1, 3, Access.READ); 2153 2154 will(returnValue(1)); 2154 2155 … … 2161 2162 /// 2162 2163 2163 oneOf(annotationDao).updatePublicA ttribute(1, permissions.getPublic());2164 oneOf(annotationDao).updatePublicAccess(1, permissions.getPublic()); 2164 2165 will(returnValue(1)); 2165 2166 … … 2200 2201 // } 2201 2202 @Test 2202 public void testUpdate AnnotationPrinciaplAccess() {2203 public void testUpdatePermission() { 2203 2204 System.out.println("test updateAnnotationPrincipalAccess"); 2204 2205 mockeryDao.checking(new Expectations() { 2205 2206 { 2206 oneOf(annotationDao). getAccess(1, 2);2207 will(returnValue( Access.WRITE));2208 2209 oneOf(annotationDao).update AnnotationPrincipalAccess(1, 2, Access.READ);2210 will(returnValue(1)); 2211 2212 oneOf(annotationDao). getAccess(1, 4);2213 will(returnValue( null));2214 2215 oneOf(annotationDao).add AnnotationPrincipalAccess(1, 4, Access.WRITE);2216 will(returnValue(1)); 2217 2218 } 2219 }); 2220 2221 assertEquals(1, dbDispatcher.update AnnotationPrincipalAccess(1, 2, Access.READ));2222 assertEquals(1, dbDispatcher.update AnnotationPrincipalAccess(1, 4, Access.WRITE));2207 oneOf(annotationDao).hasExplicitAccess(1, 2); 2208 will(returnValue(true)); 2209 2210 oneOf(annotationDao).updatePermission(1, 2, Access.READ); 2211 will(returnValue(1)); 2212 2213 oneOf(annotationDao).hasExplicitAccess(1, 4); 2214 will(returnValue(false)); 2215 2216 oneOf(annotationDao).addPermission(1, 4, Access.WRITE); 2217 will(returnValue(1)); 2218 2219 } 2220 }); 2221 2222 assertEquals(1, dbDispatcher.updatePermission(1, 2, Access.READ)); 2223 assertEquals(1, dbDispatcher.updatePermission(1, 4, Access.WRITE)); 2223 2224 } 2224 2225 … … 2249 2250 { 2250 2251 ///// 2251 oneOf(annotationDao).updatePublicA ttribute(1, permissions.getPublic());2252 oneOf(annotationDao).updatePublicAccess(1, permissions.getPublic()); 2252 2253 will(returnValue(1)); 2253 2254 … … 2255 2256 will(returnValue(2)); 2256 2257 2257 oneOf(annotationDao). getAccess(1, 2);2258 will(returnValue( Access.WRITE));2258 oneOf(annotationDao).hasExplicitAccess(1, 2); 2259 will(returnValue(true)); 2259 2260 2260 2261 oneOf(principalDao).getInternalIDFromHref(permissions.getPermission().get(1).getPrincipalHref()); 2261 2262 will(returnValue(3)); 2262 2263 2263 oneOf(annotationDao). getAccess(1, 3);2264 will(returnValue( Access.WRITE));2264 oneOf(annotationDao).hasExplicitAccess(1, 3); 2265 will(returnValue(true)); 2265 2266 2266 2267 oneOf(principalDao).getInternalIDFromHref(permissions.getPermission().get(2).getPrincipalHref()); 2267 2268 will(returnValue(4)); 2268 2269 2269 oneOf(annotationDao).getAccess(1, 4); 2270 will(returnValue(null)); 2271 2272 oneOf(annotationDao).updateAnnotationPrincipalAccess(1, 3, Access.READ); 2273 will(returnValue(1)); 2274 2275 oneOf(annotationDao).addAnnotationPrincipalAccess(1, 4, Access.READ); 2276 will(returnValue(1)); 2277 2278 } 2279 }); 2280 2281 assertEquals(2, dbDispatcher.updatePermissions(1, permissions)); 2270 oneOf(annotationDao).hasExplicitAccess(1, 4); 2271 will(returnValue(false)); 2272 2273 oneOf(annotationDao).updatePermission(1, 2, Access.WRITE); 2274 will(returnValue(1)); 2275 2276 oneOf(annotationDao).updatePermission(1, 3, Access.READ); 2277 will(returnValue(1)); 2278 2279 oneOf(annotationDao).addPermission(1, 4, Access.READ); 2280 will(returnValue(1)); 2281 2282 } 2283 }); 2284 2285 assertEquals(3, dbDispatcher.updatePermissions(1, permissions)); 2282 2286 2283 2287 } … … 2293 2297 { 2294 2298 ///// 2295 oneOf(annotationDao).updatePublicA ttribute(1, Access.NONE);2299 oneOf(annotationDao).updatePublicAccess(1, Access.NONE); 2296 2300 will(returnValue(1)); 2297 2301 -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/test/java/eu/dasish/annotation/backend/dao/impl/JdbcAnnotationDaoTest.java
r5468 r5836 114 114 public void testDeleteAnnotationPrinciplePermissions() { 115 115 System.out.println("test deleteAllAnnotationTargets"); 116 int result = jdbcAnnotationDao.delete AnnotationPermissions(1);116 int result = jdbcAnnotationDao.deletePermissions(1); 117 117 assertEquals(3, result); 118 assertEquals(0, jdbcAnnotationDao.delete AnnotationPermissions(1));118 assertEquals(0, jdbcAnnotationDao.deletePermissions(1)); 119 119 } 120 120 … … 123 123 public void testAddAnnotationPrincipalAccess() { 124 124 System.out.println("test addAnnotationTargets"); 125 int result = jdbcAnnotationDao.add AnnotationPrincipalAccess(1, 1, Access.READ);125 int result = jdbcAnnotationDao.addPermission(1, 1, Access.READ); 126 126 assertEquals(1, result); 127 127 } … … 226 226 // to provide integrity, first delete rows in the joint tables 227 227 jdbcAnnotationDao.deleteAllAnnotationTarget(4); 228 jdbcAnnotationDao.delete AnnotationPermissions(4);228 jdbcAnnotationDao.deletePermissions(4); 229 229 230 230 assertEquals(1, jdbcAnnotationDao.deleteAnnotation(4)); … … 313 313 public void testAnnotationIDsForPermission() { 314 314 System.out.println("test getAnnotationIDsForPermission"); 315 List<Number> result = jdbcAnnotationDao.getAnnotationIDs ForPermission(1, Access.READ);315 List<Number> result = jdbcAnnotationDao.getAnnotationIDsPermissionAtLeast(1, Access.READ); 316 316 assertEquals(3, result.size()); 317 317 assertEquals(2, result.get(0)); … … 319 319 assertEquals(4, result.get(2)); 320 320 321 List<Number> resultTwo = jdbcAnnotationDao.getAnnotationIDs ForPermission(1, Access.WRITE);321 List<Number> resultTwo = jdbcAnnotationDao.getAnnotationIDsPermissionAtLeast(1, Access.WRITE); 322 322 assertEquals(1, resultTwo.size()); 323 323 assertEquals(4, resultTwo.get(0)); 324 324 325 List<Number> resultThree = jdbcAnnotationDao.getAnnotationIDs ForPermission(1, Access.NONE);325 List<Number> resultThree = jdbcAnnotationDao.getAnnotationIDsPermissionAtLeast(1, Access.NONE); 326 326 assertEquals(0, resultThree.size()); 327 327 … … 332 332 public void testAnnotationIDsForPublicAccess() { 333 333 System.out.println("test getAnnotationIDsForPublicAccess"); 334 List<Number> result = jdbcAnnotationDao.getAnnotationIDs ForPublicAccess(Access.READ);334 List<Number> result = jdbcAnnotationDao.getAnnotationIDsPublicAtLeast(Access.READ); 335 335 assertEquals(2, result.size()); 336 336 assertTrue(result.contains(1)); 337 337 assertTrue(result.contains(2)); 338 338 339 List<Number> resultTwo = jdbcAnnotationDao.getAnnotationIDs ForPublicAccess(Access.WRITE);339 List<Number> resultTwo = jdbcAnnotationDao.getAnnotationIDsPublicAtLeast(Access.WRITE); 340 340 assertEquals(1, resultTwo.size()); 341 341 assertEquals(1, resultTwo.get(0)); 342 342 343 343 344 List<Number> resultThree = jdbcAnnotationDao.getAnnotationIDs ForPublicAccess(Access.NONE);344 List<Number> resultThree = jdbcAnnotationDao.getAnnotationIDsPublicAtLeast(Access.NONE); 345 345 assertEquals(2, resultThree.size()); 346 346 assertTrue(resultThree.contains(3)); … … 362 362 assertEquals(Access.READ, jdbcAnnotationDao.getAccess(1, 3)); 363 363 assertEquals(Access.WRITE, jdbcAnnotationDao.getAccess(2, 3)); 364 assertEquals( null, jdbcAnnotationDao.getAccess(3, 3));364 assertEquals(Access.NONE, jdbcAnnotationDao.getAccess(3, 3)); 365 365 } 366 366 … … 449 449 System.out.println("test updateAnntationPrincipalAccess "); 450 450 451 int result = jdbcAnnotationDao.update AnnotationPrincipalAccess(1, 2, Access.NONE);451 int result = jdbcAnnotationDao.updatePermission(1, 2, Access.NONE); 452 452 assertEquals(1, result); 453 453 assertEquals(Access.NONE, jdbcAnnotationDao.getAccess(1, 2)); … … 458 458 System.out.println("test updatePublicAtribute "); 459 459 460 int result = jdbcAnnotationDao.updatePublicA ttribute(1, Access.NONE);460 int result = jdbcAnnotationDao.updatePublicAccess(1, Access.NONE); 461 461 assertEquals(1, result); 462 462 assertEquals(Access.NONE, jdbcAnnotationDao.getPublicAttribute(1)); -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/test/java/eu/dasish/annotation/backend/rest/AnnotationResourceTest.java
r5774 r5836 21 21 import eu.dasish.annotation.backend.NotInDataBaseException; 22 22 import eu.dasish.annotation.backend.Resource; 23 import eu.dasish.annotation.backend.ResourceAction;24 23 import eu.dasish.annotation.backend.dao.DBDispatcher; 25 24 import eu.dasish.annotation.backend.TestInstances; … … 107 106 108 107 109 oneOf(mockDbDispatcher).canDo( ResourceAction.READ, 3, 1, Resource.ANNOTATION);108 oneOf(mockDbDispatcher).canDo(Access.READ, 3, 1, Resource.ANNOTATION); 110 109 will(returnValue(true)); 111 110 … … 152 151 will(returnValue(3)); 153 152 154 oneOf(mockDbDispatcher).canDo( ResourceAction.DELETE, 3, 4, Resource.ANNOTATION);153 oneOf(mockDbDispatcher).canDo(Access.ALL, 3, 4, Resource.ANNOTATION); 155 154 will(returnValue(true)); 156 155 … … 276 275 will(returnValue(1)); 277 276 278 oneOf(mockDbDispatcher).canDo( ResourceAction.WRITE, 1, 1, Resource.ANNOTATION);277 oneOf(mockDbDispatcher).canDo(Access.WRITE, 1, 1, Resource.ANNOTATION); 279 278 will(returnValue(true)); 280 279 … … 344 343 will(returnValue(1)); 345 344 346 oneOf(mockDbDispatcher).canDo( ResourceAction.WRITE, 1, 1, Resource.ANNOTATION);345 oneOf(mockDbDispatcher).canDo(Access.WRITE, 1, 1, Resource.ANNOTATION); 347 346 will(returnValue(true)); 348 347 … … 397 396 will(returnValue(1)); 398 397 399 oneOf(mockDbDispatcher).canDo( ResourceAction.WRITE, 1, 1, Resource.ANNOTATION);398 oneOf(mockDbDispatcher).canDo(Access.WRITE, 1, 1, Resource.ANNOTATION); 400 399 will(returnValue(true)); 401 400
Note: See TracChangeset
for help on using the changeset viewer.