Changeset 4539
- Timestamp:
- 02/20/14 15:52:16 (10 years ago)
- Location:
- DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src
- Files:
-
- 1 added
- 15 edited
Legend:
- Unmodified
- Added
- Removed
-
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/AnnotationDao.java
r4495 r4539 93 93 public List<Number> retrieveTargetIDs(Number annotationID); 94 94 95 96 /**97 *98 * @param annotationID99 * @return all the pairs (user-permission) for "annotationId" from the table annotations_principals permissions.100 */101 public List<Map<Number, String>> getPermissions(Number annotationID);102 95 103 96 public Number getOwner(Number annotationID); -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/DBIntegrityService.java
r4529 r4539 18 18 package eu.dasish.annotation.backend.dao; 19 19 20 import eu.dasish.annotation.backend.Resource; 20 21 import eu.dasish.annotation.schema.Annotation; 21 22 import eu.dasish.annotation.schema.AnnotationBody; … … 28 29 import eu.dasish.annotation.schema.UserWithPermissionList; 29 30 import eu.dasish.annotation.schema.ReferenceList; 31 import eu.dasish.annotation.schema.ResponseBody; 30 32 import eu.dasish.annotation.schema.Target; 31 33 import eu.dasish.annotation.schema.TargetInfo; … … 44 46 public interface DBIntegrityService { 45 47 46 public void setServiceURI(String serviceURI); 48 void setServiceURI(String serviceURI); 49 47 50 48 51 /** 49 52 * GETTERS 50 53 */ 51 /** 52 * 53 * @param UUID 54 * @return the internal identifier of the annotations with "externalID", or 55 * null if no such annotation. 56 */ 57 Number getAnnotationInternalIdentifier(UUID externalID); 58 59 /** 60 * 61 * @param annotationID 62 * @return the externalID of the annotation with "internalID" or null if 63 * there is no such annotation. 64 */ 65 UUID getAnnotationExternalIdentifier(Number annotationID); 66 67 Number getAnnotationInternalIdentifierFromURI(String uri); 54 55 Number getResourceInternalIdentifier(UUID externalID, Resource resource); 56 57 Number getResourceInternalIdentifierFromURI(String uri, Resource resource); 58 59 UUID getResourceExternalIdentifier(Number resourceID, Resource resource); 60 61 String getResourceURI(Number resourceID, Resource resource); 62 63 UserWithPermissionList getPermissions(Number resourceID, Resource resource); 64 68 65 69 66 /** … … 102 99 AnnotationInfoList getFilteredAnnotationInfos(UUID ownerId, String word, String text, Number inloggedUserID, String access, String namespace, String after, String before); 103 100 104 /** 105 * 106 * @param userID 107 * @return the external identifier of the user "userID", or null if no such 108 * user. 109 */ 110 UUID getUserExternalIdentifier(Number userID); 111 112 /** 113 * 114 * @param externalID 115 * @return the internal identifier of the user with "externalID", or null if 116 * there is no such user. 117 */ 118 Number getUserInternalIdentifier(UUID externalID); 119 120 /** 121 * 122 * @param cachedID 123 * @return the external identifier of the cached representation "cachedID", 124 * or null if no such one. 125 */ 126 UUID getCachedRepresentationExternalIdentifier(Number cachedID); 127 128 /** 129 * 130 * @param externalID 131 * @return the internal identifier of the cachedRepresentation with 132 * "externalID", or null if there is no such one. 133 */ 134 Number getCachedRepresentationInternalIdentifier(UUID externalID); 135 136 Number getTargetInternalIdentifier(UUID externalID); 137 138 String getTargetURI(Number targetID); 139 140 UUID getTargetExternalIdentifier(Number targetID); 141 142 String getUserURI(Number userID); 101 143 102 144 103 /** … … 181 140 List<String> getUsersWithNoInfo(Number annotationID); 182 141 183 /** 184 * 185 * @param annotationID 186 * @return the list of TargetID's for which there is no cached 187 * representation 188 */ 189 public UserWithPermissionList getPermissionsForAnnotation(Number annotationID); 190 191 /** 192 * 193 * @param TargetID 142 143 /** 144 * 145 * @param targetID 194 146 * @return the list of the external version ID-s that refers to the same 195 147 * source (link) as targetID 196 148 */ 197 publicReferenceList getTargetsForTheSameLinkAs(Number targetID);149 ReferenceList getTargetsForTheSameLinkAs(Number targetID); 198 150 199 151 /** … … 202 154 * @return BLOB of the cachedID 203 155 */ 204 publicInputStream getCachedRepresentationBlob(Number cachedID);205 206 publicTarget getTarget(Number internalID);156 InputStream getCachedRepresentationBlob(Number cachedID); 157 158 Target getTarget(Number internalID); 207 159 208 160 /** … … 211 163 * @return user with "userID" 212 164 */ 213 publicUser getUser(Number userID);165 User getUser(Number userID); 214 166 215 167 /** … … 218 170 * @return user with e-mail "eMail" 219 171 */ 220 publicUser getUserByInfo(String eMail);221 222 publicString getUserRemoteID(Number internalID);223 224 publicNumber getUserInternalIDFromRemoteID(String remoteID);172 User getUserByInfo(String eMail); 173 174 String getUserRemoteID(Number internalID); 175 176 Number getUserInternalIDFromRemoteID(String remoteID); 225 177 226 178 /** … … 231 183 * permission is not given 232 184 */ 233 publicPermission getPermission(Number annotationID, Number userID);234 235 publicString getTypeOfUserAccount(Number userID);236 237 publicboolean canRead(Number userID, Number annotationID);238 239 publicboolean canWrite(Number userID, Number annotationID);185 Permission getPermission(Number annotationID, Number userID); 186 187 String getTypeOfUserAccount(Number userID); 188 189 boolean canRead(Number userID, Number annotationID); 190 191 boolean canWrite(Number userID, Number annotationID); 240 192 241 193 /// notebooks /// 242 194 243 public Number getNotebookInternalIdentifier(UUID externalIdentifier); 244 245 public NotebookInfoList getNotebooks(Number prinipalID, String permission); 195 196 NotebookInfoList getNotebooks(Number prinipalID, String permission); 246 197 247 198 boolean hasAccess(Number notebookID, Number principalID, Permission permission); 248 199 249 public ReferenceList getNotebooksOwnedBy(Number principalID); 250 251 public ReferenceList getPrincipals(Number notebookID, String permission); 252 253 public Notebook getNotebook(Number notebookID); 200 ReferenceList getNotebooksOwnedBy(Number principalID); 201 202 ReferenceList getPrincipals(Number notebookID, String permission); 203 204 Notebook getNotebook(Number notebookID); 205 206 Number getNotebookOwner(Number notebookID); 254 207 255 208 ReferenceList getAnnotationsForNotebook(Number notebookID, int startAnnotation, int maximumAnnotations, String orderedBy, boolean desc); … … 258 211 * UPDATERS 259 212 */ 260 publicboolean updateAccount(UUID userExternalID, String account);213 boolean updateAccount(UUID userExternalID, String account); 261 214 262 215 /** … … 284 237 * "annotationID". 285 238 */ 286 publicint updateAnnotationPrincipalPermission(Number annotationID, Number userID, Permission permission);239 int updateAnnotationPrincipalPermission(Number annotationID, Number userID, Permission permission); 287 240 288 241 /** … … 293 246 * annotations_principals_permissions 294 247 */ 295 publicint updatePermissions(Number annotationID, UserWithPermissionList permissionList);296 297 publicNumber updateUser(User user);248 int updatePermissions(Number annotationID, UserWithPermissionList permissionList); 249 250 Number updateUser(User user); 298 251 299 252 /// notebooks /// 300 publicboolean updateNotebookMetadata(Number notebookID, NotebookInfo upToDateNotebookInfo);301 302 publicboolean addAnnotationToNotebook(Number notebookID, Number annotationID);253 boolean updateNotebookMetadata(Number notebookID, NotebookInfo upToDateNotebookInfo); 254 255 boolean addAnnotationToNotebook(Number notebookID, Number annotationID); 303 256 304 257 /** … … 368 321 * "annotationsPreincipalsPermissions" 369 322 */ 370 publicint deleteUser(Number userID);323 int deleteUser(Number userID); 371 324 372 325 /** … … 378 331 * "annotationsPreincipalsPermissions" 379 332 */ 380 publicint deleteUserSafe(Number userID);333 int deleteUserSafe(Number userID); 381 334 382 335 /** … … 416 369 boolean deleteNotebook(Number notebookID); 417 370 371 372 //////// HELPERS for resources ///// 373 ResponseBody makeAnnotationResponseEnvelope(Number annotationID); 374 375 ResponseBody makeNotebookResponseEnvelope(Number notebookID); 376 377 ResponseBody makePermissionResponseEnvelope(Number resourceID, Resource resource); 378 379 418 380 } -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/ResourceDao.java
r3865 r4539 18 18 package eu.dasish.annotation.backend.dao; 19 19 20 21 import java.util.List; 22 import java.util.Map; 20 23 import java.util.UUID; 21 24 … … 29 32 public void setServiceURI(String serviceURI); 30 33 31 /** 32 * 33 * @param externalID 34 * @return internal identifier of the reTarget with externalID, or null if there is no reTarget with this identifier 35 */ 34 36 35 public Number getInternalID(UUID externalId); 37 36 38 39 /** 40 * 41 * @param uri 42 * @return internal identifier of the reTarget with uri, or null if there is no reTarget with this uri 43 */ 37 44 38 public Number getInternalIDFromURI(String uri); 45 39 46 /** 47 * 48 * @param internalId 49 * @return the UUID (external ID) of the reTarget with the "internalID". 50 */ 40 51 41 public UUID getExternalID(Number internalId); 52 42 53 /** 54 * 55 * @param externalID 56 * @return returns the URI which is a concatenation of the serviceURI and externalID 57 */ 43 58 44 public String externalIDtoURI(String externalID); 59 45 … … 71 57 */ 72 58 public String getURIFromInternalID(Number internalID); 59 60 public List<Map<Number, String>> getPermissions(Number resourceID); 73 61 } -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/impl/DBIntegrityServiceImlp.java
r4529 r4539 18 18 package eu.dasish.annotation.backend.dao.impl; 19 19 20 import eu.dasish.annotation.backend.Resource; 20 21 import eu.dasish.annotation.backend.Helpers; 21 22 import eu.dasish.annotation.backend.dao.AnnotationDao; … … 23 24 import eu.dasish.annotation.backend.dao.DBIntegrityService; 24 25 import eu.dasish.annotation.backend.dao.NotebookDao; 26 import eu.dasish.annotation.backend.dao.ResourceDao; 25 27 import eu.dasish.annotation.backend.dao.TargetDao; 26 28 import eu.dasish.annotation.backend.dao.UserDao; 27 29 import eu.dasish.annotation.backend.rest.AnnotationResource; 30 import eu.dasish.annotation.schema.Action; 31 import eu.dasish.annotation.schema.ActionList; 28 32 import eu.dasish.annotation.schema.Annotation; 33 import eu.dasish.annotation.schema.AnnotationActionName; 29 34 import eu.dasish.annotation.schema.AnnotationBody; 30 35 import eu.dasish.annotation.schema.AnnotationInfo; … … 38 43 import eu.dasish.annotation.schema.TargetInfoList; 39 44 import eu.dasish.annotation.schema.Permission; 45 import eu.dasish.annotation.schema.PermissionActionName; 40 46 import eu.dasish.annotation.schema.UserWithPermissionList; 41 47 import eu.dasish.annotation.schema.ReferenceList; 48 import eu.dasish.annotation.schema.ResponseBody; 42 49 import eu.dasish.annotation.schema.Target; 43 50 import eu.dasish.annotation.schema.TargetInfo; … … 51 58 import java.util.Map; 52 59 import java.util.UUID; 60 import java.lang.reflect.Field; 53 61 import org.springframework.beans.factory.annotation.Autowired; 54 62 import org.slf4j.Logger; … … 73 81 final static protected String admin = "admin"; 74 82 private static final Logger logger = LoggerFactory.getLogger(AnnotationResource.class); 83 75 84 ////////////////////////////////// 85 private ResourceDao getDao(Resource resource) { 86 switch (resource) { 87 case PRINCIPAL: 88 return userDao; 89 case ANNOTATION: 90 return annotationDao; 91 case TARGET: 92 return targetDao; 93 case CACHED_REPRESENTATION: 94 return cachedRepresentationDao; 95 case NOTEBOOK: 96 return notebookDao; 97 default: 98 return null; 99 } 100 } 76 101 77 102 @Override … … 81 106 targetDao.setServiceURI(serviceURI + "targets/"); 82 107 annotationDao.setServiceURI(serviceURI + "annotations/"); 83 //notebookDao.setServiceURI(serviceURI+"notebooks/");108 notebookDao.setServiceURI(serviceURI + "notebooks/"); 84 109 } 85 110 86 111 ///////////// GETTERS ////////////////////////// 87 112 @Override 88 public Number getAnnotationInternalIdentifier(UUID externalID) { 89 return annotationDao.getInternalID(externalID); 90 } 91 92 @Override 93 public Number getAnnotationInternalIdentifierFromURI(String uri) { 94 return annotationDao.getInternalIDFromURI(uri); 95 } 96 97 @Override 98 public UUID getAnnotationExternalIdentifier(Number annotationID) { 99 return annotationDao.getExternalID(annotationID); 100 } 101 102 @Override 103 public Number getTargetInternalIdentifier(UUID externalID) { 104 return targetDao.getInternalID(externalID); 105 } 106 107 @Override 108 public UUID getTargetExternalIdentifier(Number targetID) { 109 return targetDao.getExternalID(targetID); 110 } 111 112 @Override 113 public String getTargetURI(Number targetID) { 114 return targetDao.getURIFromInternalID(targetID); 115 } 116 117 @Override 118 public String getUserURI(Number userID) { 119 return userDao.getURIFromInternalID(userID); 120 } 121 122 @Override 123 public Number getUserInternalIdentifier(UUID externalID) { 124 return userDao.getInternalID(externalID); 125 } 126 127 @Override 128 public UUID getUserExternalIdentifier(Number userID) { 129 return userDao.getExternalID(userID); 130 } 131 132 @Override 133 public Number getCachedRepresentationInternalIdentifier(UUID externalID) { 134 return cachedRepresentationDao.getInternalID(externalID); 135 } 136 137 @Override 138 public UUID getCachedRepresentationExternalIdentifier(Number cachedID) { 139 return cachedRepresentationDao.getExternalID(cachedID); 113 public Number getResourceInternalIdentifier(UUID externalID, Resource resource) { 114 return this.getDao(resource).getInternalID(externalID); 115 } 116 117 @Override 118 public Number getResourceInternalIdentifierFromURI(String uri, Resource resource) { 119 return this.getDao(resource).getInternalIDFromURI(uri); 120 } 121 122 @Override 123 public UUID getResourceExternalIdentifier(Number resourceID, Resource resource) { 124 return this.getDao(resource).getExternalID(resourceID); 125 } 126 127 @Override 128 public String getResourceURI(Number resourceID, Resource resource) { 129 return this.getDao(resource).getURIFromInternalID(resourceID); 140 130 } 141 131 … … 153 143 result.setTargets(sis); 154 144 155 result.setPermissions(this.getPermissions ForAnnotation(annotationID));145 result.setPermissions(this.getPermissions(annotationID, Resource.ANNOTATION)); 156 146 return result; 157 147 } else { … … 168 158 // TODO UNIT tests 169 159 @Override 170 public UserWithPermissionList getPermissions ForAnnotation(Number annotationID) {171 if ( annotationID != null) {172 List<Map<Number, String>> principalsPermissions = annotationDao.getPermissions(annotationID);160 public UserWithPermissionList getPermissions(Number resourceID, Resource resource) { 161 if (resourceID != null) { 162 List<Map<Number, String>> principalsPermissions = this.getDao(resource).getPermissions(resourceID); 173 163 UserWithPermissionList result = new UserWithPermissionList(); 174 164 List<UserWithPermission> list = result.getUserWithPermission(); 175 165 for (Map<Number, String> principalPermission : principalsPermissions) { 176 177 166 Number[] principal = new Number[1]; 178 167 principalPermission.keySet().toArray(principal); 179 180 168 UserWithPermission userWithPermission = new UserWithPermission(); 181 169 userWithPermission.setRef(userDao.getURIFromInternalID(principal[0])); 182 170 userWithPermission.setPermission(Permission.fromValue(principalPermission.get(principal[0]))); 183 184 171 list.add(userWithPermission); 185 172 } 186 173 return result; 187 } else { 188 return null; 189 } 190 191 } 192 193 //////////////////////////////////////////////////////////////////////// 174 175 } 176 return null; 177 } 178 179 //////////////////////////////////////////////////////////////////////// 194 180 @Override 195 181 public List<Number> getFilteredAnnotationIDs(UUID ownerId, String link, String text, Number inloggedUserID, String access, String namespace, String after, String before) { … … 436 422 } 437 423 438 /// notebooks ///439 @Override440 public Number getNotebookInternalIdentifier(UUID externalIdentifier){441 return notebookDao.getInternalID(externalIdentifier);442 }443 444 445 424 @Override 446 425 public NotebookInfoList getNotebooks(Number principalID, String permission) { … … 471 450 472 451 @Override 473 public boolean hasAccess(Number notebookID, Number principalID, Permission permission) {452 public boolean hasAccess(Number notebookID, Number principalID, Permission permission) { 474 453 List<Number> notebookIDs = notebookDao.getNotebookIDs(principalID, permission); 475 454 if (notebookIDs == null) { 476 455 return false; 477 } 456 } 478 457 return notebookIDs.contains(notebookID); 479 458 } 480 481 459 482 460 @Override 483 461 public ReferenceList getNotebooksOwnedBy(Number principalID) { … … 530 508 } 531 509 } 532 533 510 result.setPermissions(ups); 534 511 return result; 512 } 513 514 @Override 515 public Number getNotebookOwner(Number notebookID) { 516 return notebookDao.getOwner(notebookID); 535 517 } 536 518 … … 781 763 782 764 ////////////// HELPERS //////////////////// 765 //////////////////////////////////////// 766 @Override 767 public ResponseBody makeAnnotationResponseEnvelope(Number annotationID) { 768 ResponseBody result = new ResponseBody(); 769 Annotation annotation = this.getAnnotation(annotationID); 770 result.setAnnotation(annotation); 771 List<String> targetsNoCached = this.getTargetsWithNoCachedRepresentation(annotationID); 772 ActionList actionList = new ActionList(); 773 result.setActionList(actionList); 774 actionList.getAction().addAll(makeActionList(targetsNoCached, AnnotationActionName.CREATE_CACHED_REPRESENTATION.value())); 775 return result; 776 } 777 778 @Override 779 public ResponseBody makeNotebookResponseEnvelope(Number notebookID) { 780 ResponseBody result = new ResponseBody(); 781 result.setPermissions(null); 782 Notebook notebook = this.getNotebook(notebookID); 783 result.setNotebook(notebook); 784 return result; 785 } 786 787 @Override 788 public ResponseBody makePermissionResponseEnvelope(Number resourceID, Resource resource) { 789 ResponseBody result = new ResponseBody(); 790 UserWithPermissionList permissions = this.getPermissions(resourceID, resource); 791 result.setPermissions(permissions); 792 List<String> usersWithNoInfo = this.getUsersWithNoInfo(resourceID); 793 ActionList actionList = new ActionList(); 794 result.setActionList(actionList); 795 actionList.getAction().addAll(makeActionList(usersWithNoInfo, PermissionActionName.PROVIDE_USER_INFO.value())); 796 return result; 797 } 798 799 private List<Action> makeActionList(List<String> resourceURIs, String message) { 800 if (resourceURIs != null) { 801 if (resourceURIs.isEmpty()) { 802 return (new ArrayList<Action>()); 803 } else { 804 List<Action> result = new ArrayList<Action>(); 805 for (String resourceURI : resourceURIs) { 806 Action action = new Action(); 807 result.add(action); 808 action.setMessage(message); 809 action.setObject(resourceURI); 810 } 811 return result; 812 } 813 } else { 814 return null; 815 } 816 } 817 818 //// priveee /// 783 819 private Target createFreshTarget(TargetInfo targetInfo) { 784 820 Target target = new Target(); -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/impl/JdbcAnnotationDao.java
r4521 r4539 26 26 import eu.dasish.annotation.schema.AnnotationInfo; 27 27 import eu.dasish.annotation.schema.Permission; 28 import eu.dasish.annotation.schema.UserWithPermission; 29 import eu.dasish.annotation.schema.UserWithPermissionList; 28 30 import java.lang.String; 29 31 import java.sql.ResultSet; … … 76 78 /////////////////////////////////////////////////////////////////// 77 79 @Override 78 public List<Map<Number, String>> getPermissions(Number annotationID) {80 public List<Map<Number, String>> getPermissions(Number annotationID) { 79 81 if (annotationID == null) { 80 82 loggerAnnotationDao.debug(nullArgument); … … 85 87 return getSimpleJdbcTemplate().query(sql.toString(), principalsPermissionsRowMapper, annotationID); 86 88 } 87 private final RowMapper<Map<Number, String>> principalsPermissionsRowMapper = new RowMapper<Map<Number, String>>() { 88 @Override 89 public Map<Number, String> mapRow(ResultSet rs, int rowNumber) throws SQLException { 90 Map<Number, String> result = new HashMap<Number, String>(); 91 result.put(rs.getInt(principal_id), rs.getString(permission)); 92 return result; 93 } 94 }; 95 89 90 96 91 @Override 97 92 public Permission getPermission(Number annotationID, Number userID) { -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/impl/JdbcNotebookDao.java
r4529 r4539 69 69 } 70 70 71 71 ////////////////////////////////////////////////// 72 @Override 73 public List<Map<Number, String>> getPermissions(Number notebookID) { 74 if (notebookID == null) { 75 loggerNotebookDao.debug(nullArgument); 76 return null; 77 } 78 StringBuilder sql = new StringBuilder("SELECT "); 79 sql.append(principal_id).append(",").append(permission).append(" FROM ").append(notebookPermissionsTableName).append(" WHERE ").append(notebook_id).append(" = ?"); 80 return getSimpleJdbcTemplate().query(sql.toString(), principalsPermissionsRowMapper, notebookID); 81 } 82 83 ///////////// 72 84 73 85 @Override -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/impl/JdbcResourceDao.java
r4506 r4539 21 21 import java.sql.ResultSet; 22 22 import java.sql.SQLException; 23 import java.util.ArrayList; 24 import java.util.HashMap; 23 25 import java.util.List; 26 import java.util.Map; 24 27 import java.util.UUID; 25 28 import javax.xml.datatype.DatatypeConfigurationException; … … 151 154 return externalIDtoURI(getExternalID(internalID).toString()); 152 155 } 156 157 // override for notebooks and annotations 158 @Override 159 public List<Map<Number, String>> getPermissions(Number resourceID) { 160 return (new ArrayList<Map<Number, String>>()); 161 } 153 162 154 163 ///////////////////////////////////////////////////// … … 220 229 }; 221 230 231 protected final RowMapper<Map<Number, String>> principalsPermissionsRowMapper = new RowMapper<Map<Number, String>>() { 232 @Override 233 public Map<Number, String> mapRow(ResultSet rs, int rowNumber) throws SQLException { 234 Map<Number, String> result = new HashMap<Number, String>(); 235 result.put(rs.getInt(principal_id), rs.getString(permission)); 236 return result; 237 } 238 }; 239 240 ////// END ROW MAPPERS ///// 222 241 @Override 223 242 public String externalIDtoURI(String externalID) { … … 270 289 271 290 } 291 292 272 293 } -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/rest/AnnotationResource.java
r4532 r4539 19 19 20 20 import eu.dasish.annotation.backend.BackendConstants; 21 import eu.dasish.annotation.backend.Resource; 21 22 import eu.dasish.annotation.backend.dao.DBIntegrityService; 22 23 import eu.dasish.annotation.schema.Annotation; 23 import eu.dasish.annotation.schema.Annotation ActionName;24 import eu.dasish.annotation.schema.AnnotationBody; 24 25 import eu.dasish.annotation.schema.AnnotationInfoList; 25 import eu.dasish.annotation.schema.Action;26 import eu.dasish.annotation.schema.ActionList;27 import eu.dasish.annotation.schema.AnnotationBody;28 26 import eu.dasish.annotation.schema.ObjectFactory; 29 27 import eu.dasish.annotation.schema.Permission; 30 import eu.dasish.annotation.schema.PermissionActionName;31 28 import eu.dasish.annotation.schema.UserWithPermissionList; 32 29 import eu.dasish.annotation.schema.ReferenceList; 33 30 import eu.dasish.annotation.schema.ResponseBody; 34 import eu.dasish.annotation.schema.UserWithPermission;35 31 import java.io.IOException; 36 import java.net.URI;37 import java.sql.Timestamp;38 import java.util.ArrayList;39 import java.util.List;40 32 import java.util.UUID; 41 33 import javax.servlet.ServletContext; … … 113 105 dbIntegrityService.setServiceURI(uriInfo.getBaseUri().toString()); 114 106 try { 115 final Number annotationID = dbIntegrityService.get AnnotationInternalIdentifier(UUID.fromString(externalIdentifier));107 final Number annotationID = dbIntegrityService.getResourceInternalIdentifier(UUID.fromString(externalIdentifier), Resource.ANNOTATION); 116 108 if (annotationID != null) { 117 109 String remoteUser = httpServletRequest.getRemoteUser(); … … 144 136 dbIntegrityService.setServiceURI(uriInfo.getBaseUri().toString()); 145 137 try { 146 final Number annotationID = dbIntegrityService.get AnnotationInternalIdentifier(UUID.fromString(externalIdentifier));138 final Number annotationID = dbIntegrityService.getResourceInternalIdentifier(UUID.fromString(externalIdentifier), Resource.ANNOTATION); 147 139 if (annotationID != null) { 148 140 String remoteUser = httpServletRequest.getRemoteUser(); … … 157 149 } else { 158 150 verboseOutput.REMOTE_PRINCIPAL_NOT_FOUND(remoteUser); 159 160 151 } 161 152 } else { … … 209 200 dbIntegrityService.setServiceURI(uriInfo.getBaseUri().toString()); 210 201 try { 211 final Number annotationID = dbIntegrityService.get AnnotationInternalIdentifier(UUID.fromString(externalIdentifier));202 final Number annotationID = dbIntegrityService.getResourceInternalIdentifier(UUID.fromString(externalIdentifier), Resource.ANNOTATION); 212 203 String remoteUser = httpServletRequest.getRemoteUser(); 213 204 Number userID = dbIntegrityService.getUserInternalIDFromRemoteID(remoteUser); … … 215 206 if (annotationID != null) { 216 207 if (dbIntegrityService.canRead(userID, annotationID)) { 217 final UserWithPermissionList permissionList = dbIntegrityService.getPermissions ForAnnotation(annotationID);208 final UserWithPermissionList permissionList = dbIntegrityService.getPermissions(annotationID, Resource.ANNOTATION); 218 209 return new ObjectFactory().createPermissionList(permissionList); 219 210 } else { … … 240 231 dbIntegrityService.setServiceURI(uriInfo.getBaseUri().toString()); 241 232 try { 242 final Number annotationID = dbIntegrityService.get AnnotationInternalIdentifier(UUID.fromString(externalIdentifier));233 final Number annotationID = dbIntegrityService.getResourceInternalIdentifier(UUID.fromString(externalIdentifier), Resource.ANNOTATION); 243 234 String remoteUser = httpServletRequest.getRemoteUser(); 244 235 Number userID = dbIntegrityService.getUserInternalIDFromRemoteID(remoteUser); … … 280 271 if (userID != null) { 281 272 Number annotationID = dbIntegrityService.addUsersAnnotation(userID, annotation); 282 return new ObjectFactory().createResponseBody( makeAnnotationResponseEnvelope(annotationID));273 return new ObjectFactory().createResponseBody(dbIntegrityService.makeAnnotationResponseEnvelope(annotationID)); 283 274 } else { 284 275 verboseOutput.REMOTE_PRINCIPAL_NOT_FOUND(remoteUser); … … 306 297 307 298 try { 308 final Number annotationID = dbIntegrityService.get AnnotationInternalIdentifier(UUID.fromString(externalIdentifier));299 final Number annotationID = dbIntegrityService.getResourceInternalIdentifier(UUID.fromString(externalIdentifier), Resource.ANNOTATION); 309 300 if (annotationID != null) { 310 301 String remoteUser = httpServletRequest.getRemoteUser(); … … 313 304 if (userID.equals(dbIntegrityService.getAnnotationOwner(annotationID)) || dbIntegrityService.getTypeOfUserAccount(userID).equals(admin)) { 314 305 int updatedRows = dbIntegrityService.updateAnnotation(annotation); 315 return new ObjectFactory().createResponseBody( makeAnnotationResponseEnvelope(annotationID));306 return new ObjectFactory().createResponseBody(dbIntegrityService.makeAnnotationResponseEnvelope(annotationID)); 316 307 } else { 317 308 verboseOutput.FORBIDDEN_PERMISSION_CHANGING(externalIdentifier); … … 338 329 dbIntegrityService.setServiceURI(path); 339 330 try { 340 final Number annotationID = dbIntegrityService.get AnnotationInternalIdentifier(UUID.fromString(externalIdentifier));331 final Number annotationID = dbIntegrityService.getResourceInternalIdentifier(UUID.fromString(externalIdentifier), Resource.ANNOTATION); 341 332 String remoteUser = httpServletRequest.getRemoteUser(); 342 333 Number userID = dbIntegrityService.getUserInternalIDFromRemoteID(remoteUser); … … 345 336 if (dbIntegrityService.canWrite(userID, annotationID)) { 346 337 int updatedRows = dbIntegrityService.updateAnnotationBody(annotationID, annotationBody); 347 return new ObjectFactory().createResponseBody( makeAnnotationResponseEnvelope(annotationID));338 return new ObjectFactory().createResponseBody(dbIntegrityService.makeAnnotationResponseEnvelope(annotationID)); 348 339 } else { 349 340 verboseOutput.FORBIDDEN_ANNOTATION_WRITING(externalIdentifier); … … 373 364 if (remoteUserID != null) { 374 365 try { 375 final Number userID = dbIntegrityService.get UserInternalIdentifier(UUID.fromString(userExternalId));366 final Number userID = dbIntegrityService.getResourceInternalIdentifier(UUID.fromString(userExternalId), Resource.PRINCIPAL); 376 367 if (userID != null) { 377 368 try { 378 final Number annotationID = dbIntegrityService.get AnnotationInternalIdentifier(UUID.fromString(annotationExternalId));369 final Number annotationID = dbIntegrityService.getResourceInternalIdentifier(UUID.fromString(annotationExternalId), Resource.ANNOTATION); 379 370 if (annotationID != null) { 380 371 if (remoteUserID.equals(dbIntegrityService.getAnnotationOwner(annotationID)) || dbIntegrityService.getTypeOfUserAccount(remoteUserID).equals(admin)) { … … 414 405 dbIntegrityService.setServiceURI(uriInfo.getBaseUri().toString()); 415 406 try { 416 final Number annotationID = dbIntegrityService.get AnnotationInternalIdentifier(UUID.fromString(annotationExternalId));407 final Number annotationID = dbIntegrityService.getResourceInternalIdentifier(UUID.fromString(annotationExternalId), Resource.ANNOTATION); 417 408 String remoteUser = httpServletRequest.getRemoteUser(); 418 409 Number remoteUserID = dbIntegrityService.getUserInternalIDFromRemoteID(remoteUser); … … 421 412 if (remoteUserID.equals(dbIntegrityService.getAnnotationOwner(annotationID)) || dbIntegrityService.getTypeOfUserAccount(remoteUserID).equals(admin)) { 422 413 int updatedRows = dbIntegrityService.updatePermissions(annotationID, permissions); 423 return new ObjectFactory().createResponseBody( makePermissionResponseEnvelope(annotationID));414 return new ObjectFactory().createResponseBody(dbIntegrityService.makePermissionResponseEnvelope(annotationID, Resource.ANNOTATION)); 424 415 } else { 425 416 verboseOutput.FORBIDDEN_PERMISSION_CHANGING(annotationExternalId); … … 448 439 int deletedRows = 0; 449 440 try { 450 final Number annotationID = dbIntegrityService.get AnnotationInternalIdentifier(UUID.fromString(annotationId));441 final Number annotationID = dbIntegrityService.getResourceInternalIdentifier(UUID.fromString(annotationId), Resource.ANNOTATION); 451 442 String remoteUser = httpServletRequest.getRemoteUser(); 452 443 Number remoteUserID = dbIntegrityService.getUserInternalIDFromRemoteID(remoteUser); … … 454 445 if (annotationID != null) { 455 446 if (remoteUserID.equals(dbIntegrityService.getAnnotationOwner(annotationID)) || dbIntegrityService.getTypeOfUserAccount(remoteUserID).equals(admin)) { 456 Number userID = dbIntegrityService.get UserInternalIdentifier(UUID.fromString(userId));447 Number userID = dbIntegrityService.getResourceInternalIdentifier(UUID.fromString(userId), Resource.PRINCIPAL); 457 448 if (userID != null) { 458 449 deletedRows = dbIntegrityService.updateAnnotationPrincipalPermission(annotationID, userID, null); … … 477 468 return (deletedRows + " is deleted."); 478 469 } 479 ///////////////////////////////////////// 480 481 private ResponseBody makeAnnotationResponseEnvelope(Number annotationID) { 482 ResponseBody result = new ResponseBody(); 483 result.setPermissions(null); 484 Annotation annotation = dbIntegrityService.getAnnotation(annotationID); 485 result.setAnnotation(annotation); 486 List<String> targetsNoCached = dbIntegrityService.getTargetsWithNoCachedRepresentation(annotationID); 487 ActionList actionList = new ActionList(); 488 result.setActionList(actionList); 489 actionList.getAction().addAll(makeActionList(targetsNoCached, AnnotationActionName.CREATE_CACHED_REPRESENTATION.value())); 490 return result; 491 } 492 493 ///////////////////////////////////////// 494 private ResponseBody makePermissionResponseEnvelope(Number annotationID) { 495 ResponseBody result = new ResponseBody(); 496 result.setAnnotation(null); 497 UserWithPermissionList permissions = dbIntegrityService.getPermissionsForAnnotation(annotationID); 498 result.setPermissions(permissions); 499 List<String> usersWithNoInfo = dbIntegrityService.getUsersWithNoInfo(annotationID); 500 ActionList actionList = new ActionList(); 501 result.setActionList(actionList); 502 actionList.getAction().addAll(makeActionList(usersWithNoInfo, PermissionActionName.PROVIDE_USER_INFO.value())); 503 return result; 504 } 505 506 // REFACTOR : move to the integrity service all te methods below 507 private List<Action> makeActionList(List<String> resourceURIs, String message) { 508 if (resourceURIs != null) { 509 if (resourceURIs.isEmpty()) { 510 return (new ArrayList<Action>()); 511 } else { 512 List<Action> result = new ArrayList<Action>(); 513 for (String resourceURI : resourceURIs) { 514 Action action = new Action(); 515 result.add(action); 516 action.setMessage(message); 517 action.setObject(resourceURI); 518 } 519 return result; 520 } 521 } else { 522 return null; 523 } 524 } 470 525 471 } -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/rest/CachedRepresentationResource.java
r4532 r4539 19 19 20 20 import eu.dasish.annotation.backend.BackendConstants; 21 import eu.dasish.annotation.backend.Resource; 21 22 import eu.dasish.annotation.backend.dao.DBIntegrityService; 22 23 import eu.dasish.annotation.schema.CachedRepresentationInfo; … … 83 84 dbIntegrityService.setServiceURI(uriInfo.getBaseUri().toString()); 84 85 try { 85 final Number cachedID = dbIntegrityService.get CachedRepresentationInternalIdentifier(UUID.fromString(externalId));86 final Number cachedID = dbIntegrityService.getResourceInternalIdentifier(UUID.fromString(externalId), Resource.CACHED_REPRESENTATION); 86 87 if (cachedID != null) { 87 88 final CachedRepresentationInfo cachedInfo = dbIntegrityService.getCachedRepresentationInfo(cachedID); … … 110 111 dbIntegrityService.setServiceURI(uriInfo.getBaseUri().toString()); 111 112 try { 112 final Number cachedID = dbIntegrityService.get CachedRepresentationInternalIdentifier(UUID.fromString(externalId));113 final Number cachedID = dbIntegrityService.getResourceInternalIdentifier(UUID.fromString(externalId), Resource.CACHED_REPRESENTATION); 113 114 if (cachedID != null) { 114 115 InputStream dbRespond = dbIntegrityService.getCachedRepresentationBlob(cachedID); -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/rest/NotebookResource.java
r4532 r4539 19 19 20 20 import eu.dasish.annotation.backend.BackendConstants; 21 import eu.dasish.annotation.backend.Resource; 21 22 import eu.dasish.annotation.backend.dao.DBIntegrityService; 22 23 import eu.dasish.annotation.schema.Notebook; 24 import eu.dasish.annotation.schema.NotebookInfo; 23 25 import eu.dasish.annotation.schema.NotebookInfoList; 24 26 import eu.dasish.annotation.schema.ObjectFactory; 25 27 import eu.dasish.annotation.schema.Permission; 26 28 import eu.dasish.annotation.schema.ReferenceList; 29 import eu.dasish.annotation.schema.ResponseBody; 27 30 import java.io.IOException; 28 import java.net.URI;29 31 import java.sql.SQLException; 30 32 import java.util.UUID; 31 33 import javax.servlet.http.HttpServletRequest; 32 34 import javax.servlet.http.HttpServletResponse; 35 import javax.ws.rs.Consumes; 33 36 import javax.ws.rs.GET; 37 import javax.ws.rs.PUT; 34 38 import javax.ws.rs.Path; 35 39 import javax.ws.rs.PathParam; … … 70 74 private final Logger loggerServer = LoggerFactory.getLogger(HttpServletResponse.class); 71 75 private final VerboseOutput verboseOutput = new VerboseOutput(httpServletResponse, loggerServer); 76 private final String admin = "admin"; 72 77 73 78 public NotebookResource() { … … 126 131 final Number principalID = dbIntegrityService.getUserInternalIDFromRemoteID(remoteUser); 127 132 if (principalID != null) { 128 Number notebookID = dbIntegrityService.get NotebookInternalIdentifier(UUID.fromString(externalIdentifier));133 Number notebookID = dbIntegrityService.getResourceInternalIdentifier(UUID.fromString(externalIdentifier), Resource.NOTEBOOK); 129 134 if (notebookID != null) { 130 135 if (dbIntegrityService.hasAccess(notebookID, principalID, Permission.fromValue("reader"))) { … … 158 163 final Number principalID = dbIntegrityService.getUserInternalIDFromRemoteID(remoteUser); 159 164 if (principalID != null) { 160 Number notebookID = dbIntegrityService.get NotebookInternalIdentifier(UUID.fromString(externalIdentifier));165 Number notebookID = dbIntegrityService.getResourceInternalIdentifier(UUID.fromString(externalIdentifier), Resource.NOTEBOOK); 161 166 if (notebookID != null) { 162 167 if (dbIntegrityService.hasAccess(notebookID, principalID, Permission.fromValue("reader"))) { … … 190 195 final Number principalID = dbIntegrityService.getUserInternalIDFromRemoteID(remoteUser); 191 196 if (principalID != null) { 192 Number notebookID = dbIntegrityService.get NotebookInternalIdentifier(UUID.fromString(externalIdentifier));197 Number notebookID = dbIntegrityService.getResourceInternalIdentifier(UUID.fromString(externalIdentifier), Resource.NOTEBOOK); 193 198 if (notebookID != null) { 194 199 if (dbIntegrityService.hasAccess(notebookID, principalID, Permission.fromValue("reader"))) { … … 206 211 return new ObjectFactory().createReferenceList(new ReferenceList()); 207 212 } 213 214 @PUT 215 @Consumes(MediaType.APPLICATION_XML) 216 @Produces(MediaType.APPLICATION_XML) 217 @Path("{notebookid: " + BackendConstants.regExpIdentifier + "}") 218 public JAXBElement<ResponseBody> updateNotebookInfo(@PathParam("notebookid") String externalIdentifier, NotebookInfo notebookInfo) throws IOException { 219 String path = uriInfo.getBaseUri().toString(); 220 dbIntegrityService.setServiceURI(path); 221 String notebookURI = notebookInfo.getRef(); 222 223 if (!(path + "notebook/" + externalIdentifier).equals(notebookURI)) { 224 verboseOutput.IDENTIFIER_MISMATCH(externalIdentifier); 225 return new ObjectFactory().createResponseBody(new ResponseBody()); 226 } 227 228 try { 229 final Number notebookID = dbIntegrityService.getResourceInternalIdentifier(UUID.fromString(externalIdentifier), Resource.NOTEBOOK); 230 if (notebookID != null) { 231 String remoteUser = httpServletRequest.getRemoteUser(); 232 Number userID = dbIntegrityService.getUserInternalIDFromRemoteID(remoteUser); 233 if (userID != null) { 234 if (userID.equals(dbIntegrityService.getNotebookOwner(notebookID)) || dbIntegrityService.getTypeOfUserAccount(userID).equals(admin)) { 235 boolean success = dbIntegrityService.updateNotebookMetadata(notebookID, notebookInfo); 236 if (success) { 237 return new ObjectFactory().createResponseBody(dbIntegrityService.makeNotebookResponseEnvelope(notebookID)); 238 } 239 } else { 240 verboseOutput.FORBIDDEN_PERMISSION_CHANGING(externalIdentifier); 241 loggerServer.debug(" Ownership changing is the part of the full update of the notebook metadadata."); 242 } 243 } else { 244 verboseOutput.REMOTE_PRINCIPAL_NOT_FOUND(remoteUser); 245 } 246 } else { 247 verboseOutput.NOTEBOOK_NOT_FOUND(externalIdentifier); 248 } 249 } catch (IllegalArgumentException e) { 250 verboseOutput.ILLEGAL_UUID(externalIdentifier); 251 } 252 return new ObjectFactory().createResponseBody(new ResponseBody()); 253 } 254 255 256 208 257 } -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/rest/TargetResource.java
r4532 r4539 21 21 import com.sun.jersey.multipart.MultiPart; 22 22 import eu.dasish.annotation.backend.BackendConstants; 23 import eu.dasish.annotation.backend.Resource; 23 24 import eu.dasish.annotation.backend.dao.DBIntegrityService; 24 25 import eu.dasish.annotation.schema.CachedRepresentationInfo; … … 91 92 dbIntegrityService.setServiceURI(uriInfo.getBaseUri().toString()); 92 93 try { 93 final Number targetID = dbIntegrityService.get TargetInternalIdentifier(UUID.fromString(externalIdentifier));94 final Number targetID = dbIntegrityService.getResourceInternalIdentifier(UUID.fromString(externalIdentifier), Resource.TARGET); 94 95 if (targetID != null) { 95 96 final Target target = dbIntegrityService.getTarget(targetID); … … 118 119 dbIntegrityService.setServiceURI(uriInfo.getBaseUri().toString()); 119 120 try { 120 final Number targetID = dbIntegrityService.get TargetInternalIdentifier(UUID.fromString(externalIdentifier));121 final Number targetID = dbIntegrityService.getResourceInternalIdentifier(UUID.fromString(externalIdentifier), Resource.TARGET); 121 122 if (targetID != null) { 122 123 final ReferenceList siblings = dbIntegrityService.getTargetsForTheSameLinkAs(targetID); … … 148 149 dbIntegrityService.setServiceURI(uriInfo.getBaseUri().toString()); 149 150 try { 150 final Number targetID = dbIntegrityService.get TargetInternalIdentifier(UUID.fromString(targetIdentifier));151 final Number targetID = dbIntegrityService.getResourceInternalIdentifier(UUID.fromString(targetIdentifier), Resource.TARGET); 151 152 if (targetID != null) { 152 153 CachedRepresentationInfo metadata = multiPart.getBodyParts().get(0).getEntityAs(CachedRepresentationInfo.class); … … 177 178 dbIntegrityService.setServiceURI(uriInfo.getBaseUri().toString()); 178 179 try { 179 final Number targetID = dbIntegrityService.get TargetInternalIdentifier(UUID.fromString(targetExternalIdentifier));180 if (targetID != null) { 181 final Number cachedID = dbIntegrityService.get CachedRepresentationInternalIdentifier(UUID.fromString(cachedExternalIdentifier));180 final Number targetID = dbIntegrityService.getResourceInternalIdentifier(UUID.fromString(targetExternalIdentifier), Resource.TARGET); 181 if (targetID != null) { 182 final Number cachedID = dbIntegrityService.getResourceInternalIdentifier(UUID.fromString(cachedExternalIdentifier), Resource.CACHED_REPRESENTATION); 182 183 if (cachedID != null) { 183 184 int[] resultDelete = dbIntegrityService.deleteCachedRepresentationOfTarget(targetID, cachedID); -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/rest/UserResource.java
r4532 r4539 19 19 20 20 import eu.dasish.annotation.backend.BackendConstants; 21 import eu.dasish.annotation.backend.Resource; 21 22 import eu.dasish.annotation.backend.dao.DBIntegrityService; 22 23 import eu.dasish.annotation.schema.CurrentUserInfo; … … 87 88 dbIntegrityService.setServiceURI(uriInfo.getBaseUri().toString()); 88 89 try { 89 final Number userID = dbIntegrityService.get UserInternalIdentifier(UUID.fromString(externalIdentifier));90 final Number userID = dbIntegrityService.getResourceInternalIdentifier(UUID.fromString(externalIdentifier), Resource.PRINCIPAL); 90 91 if (userID != null) { 91 92 final User user = dbIntegrityService.getUser(userID); … … 134 135 dbIntegrityService.setServiceURI(uriInfo.getBaseUri().toString()); 135 136 try { 136 final Number userID = dbIntegrityService.get UserInternalIdentifier(UUID.fromString(externalIdentifier));137 final Number userID = dbIntegrityService.getResourceInternalIdentifier(UUID.fromString(externalIdentifier), Resource.PRINCIPAL); 137 138 if (userID != null) { 138 139 final CurrentUserInfo userInfo = new CurrentUserInfo(); 139 userInfo.setRef(dbIntegrityService.get UserURI(userID));140 userInfo.setRef(dbIntegrityService.getResourceURI(userID, Resource.PRINCIPAL)); 140 141 userInfo.setCurrentUser(ifLoggedIn(userID)); 141 142 return new ObjectFactory().createCurrentUserInfo(userInfo); … … 217 218 final boolean updated = dbIntegrityService.updateAccount(UUID.fromString(externalId), accountType); 218 219 if (updated) { 219 return "The account was updated to "+dbIntegrityService.getTypeOfUserAccount(dbIntegrityService.get UserInternalIdentifier(UUID.fromString(externalId)));220 return "The account was updated to "+dbIntegrityService.getTypeOfUserAccount(dbIntegrityService.getResourceInternalIdentifier(UUID.fromString(externalId), Resource.PRINCIPAL)); 220 221 } else { 221 222 verboseOutput.ACCOUNT_IS_NOT_UPDATED(); … … 239 240 if (dbIntegrityService.getTypeOfUserAccount(remoteUserID).equals(admin)) { 240 241 dbIntegrityService.setServiceURI(uriInfo.getBaseUri().toString()); 241 final Number userID = dbIntegrityService.get UserInternalIdentifier(UUID.fromString(externalIdentifier));242 final Number userID = dbIntegrityService.getResourceInternalIdentifier(UUID.fromString(externalIdentifier), Resource.PRINCIPAL); 242 243 if (userID != null) { 243 244 final Integer result = dbIntegrityService.deleteUser(userID); … … 264 265 if (dbIntegrityService.getTypeOfUserAccount(remoteUserID).equals(admin)) { 265 266 dbIntegrityService.setServiceURI(uriInfo.getBaseUri().toString()); 266 final Number userID = dbIntegrityService.get UserInternalIdentifier(UUID.fromString(externalIdentifier));267 final Number userID = dbIntegrityService.getResourceInternalIdentifier(UUID.fromString(externalIdentifier), Resource.PRINCIPAL); 267 268 if (userID != null) { 268 269 final Integer result = dbIntegrityService.deleteUserSafe(userID); -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/rest/VerboseOutput.java
r4532 r4539 106 106 107 107 private MessageStatus _IDENTIFIER_MISMATCH(String identifier){ 108 return new MessageStatus("Wrong request: the annotation identifier " + identifier + " and the annotationID from the request body do not match.", HttpServletResponse.SC_BAD_REQUEST);108 return new MessageStatus("Wrong request: the annotation (notebook) identifier " + identifier + " and the annotation (notebook) ID from the request body do not match.", HttpServletResponse.SC_BAD_REQUEST); 109 109 } 110 110 -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/test/java/eu/dasish/annotation/backend/dao/impl/DBIntegrityServiceTest.java
r4529 r4539 18 18 package eu.dasish.annotation.backend.dao.impl; 19 19 20 import eu.dasish.annotation.backend.Resource; 20 21 import eu.dasish.annotation.backend.TestBackendConstants; 21 22 import eu.dasish.annotation.backend.TestInstances; … … 100 101 public void testGetAnnotationInternalIdentifier() { 101 102 System.out.println("getAnnotationInternalIdentifier"); 102 final UUID externalID = UUID.fromString("00000000-0000-0000-0000-000000000021"); 103 103 final UUID externalID = UUID.fromString("00000000-0000-0000-0000-000000000021"); 104 //dbIntegrityService.setResourceList(); 104 105 mockeryDao.checking(new Expectations() { 105 106 { … … 108 109 } 109 110 }); 110 assertEquals(1, dbIntegrityService.get AnnotationInternalIdentifier(externalID));111 assertEquals(1, dbIntegrityService.getResourceInternalIdentifier(externalID, Resource.ANNOTATION)); 111 112 } 112 113 … … 126 127 } 127 128 }); 128 assertEquals("00000000-0000-0000-0000-000000000021", dbIntegrityService.get AnnotationExternalIdentifier(1).toString());129 assertEquals("00000000-0000-0000-0000-000000000021", dbIntegrityService.getResourceExternalIdentifier(1, Resource.ANNOTATION).toString()); 129 130 } 130 131 … … 145 146 } 146 147 }); 147 assertEquals(1, dbIntegrityService.get UserInternalIdentifier(externalID));148 assertEquals(1, dbIntegrityService.getResourceInternalIdentifier(externalID, Resource.PRINCIPAL)); 148 149 } 149 150 … … 163 164 } 164 165 }); 165 assertEquals("00000000-0000-0000-0000-000000000111", dbIntegrityService.get UserExternalIdentifier(1).toString());166 assertEquals("00000000-0000-0000-0000-000000000111", dbIntegrityService.getResourceExternalIdentifier(1, Resource.PRINCIPAL).toString()); 166 167 } 167 168 … … 843 844 }); 844 845 845 assertEquals(1, dbIntegrityService.get NotebookInternalIdentifier(mockUUID));846 assertEquals(1, dbIntegrityService.getResourceInternalIdentifier(mockUUID, Resource.NOTEBOOK)); 846 847 847 848 } -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/test/java/eu/dasish/annotation/backend/rest/AnnotationResourceTest.java
r4529 r4539 18 18 package eu.dasish.annotation.backend.rest; 19 19 20 import eu.dasish.annotation.backend.Resource; 20 21 import eu.dasish.annotation.backend.dao.DBIntegrityService; 21 import eu.dasish.annotation.backend.MockObjectsFactoryRest;22 22 import eu.dasish.annotation.backend.TestBackendConstants; 23 23 import eu.dasish.annotation.backend.TestInstances; 24 import eu.dasish.annotation.schema.Action; 25 import eu.dasish.annotation.schema.ActionList; 24 26 import eu.dasish.annotation.schema.AnnotationBody; 25 27 import eu.dasish.annotation.schema.AnnotationBody.TextBody; … … 30 32 import eu.dasish.annotation.schema.ResponseBody; 31 33 import eu.dasish.annotation.schema.AnnotationActionName; 32 import eu.dasish.annotation.schema.Permission;33 34 import java.io.IOException; 34 35 import java.sql.SQLException; … … 87 88 * Test of getAnnotation method, of class AnnotationResource. 88 89 */ 90 91 /* 92 93 * public JAXBElement<Annotation> getAnnotation(@PathParam("annotationid") String externalIdentifier) throws IOException { 94 dbIntegrityService.setServiceURI(uriInfo.getBaseUri().toString()); 95 try { 96 final Number annotationID = dbIntegrityService.getResourceInternalIdentifier(UUID.fromString(externalIdentifier), Resource.ANNOTATION); 97 if (annotationID != null) { 98 String remoteUser = httpServletRequest.getRemoteUser(); 99 final Number userID = dbIntegrityService.getUserInternalIDFromRemoteID(remoteUser); 100 if (userID != null) { 101 if (dbIntegrityService.canRead(userID, annotationID)) { 102 final Annotation annotation = dbIntegrityService.getAnnotation(annotationID); 103 return new ObjectFactory().createAnnotation(annotation); 104 } else { 105 verboseOutput.FORBIDDEN_ANNOTATION_READING(externalIdentifier); 106 } 107 } else { 108 verboseOutput.REMOTE_PRINCIPAL_NOT_FOUND(remoteUser); 109 } 110 } else { 111 verboseOutput.ANNOTATION_NOT_FOUND(externalIdentifier); 112 } 113 } catch (IllegalArgumentException e) { 114 verboseOutput.ILLEGAL_UUID(externalIdentifier); 115 } 116 return new ObjectFactory().createAnnotation(new Annotation()); 117 } 118 * 119 */ 120 89 121 @Test 90 122 public void testGetAnnotation() throws SQLException, JAXBException, Exception { … … 103 135 104 136 105 oneOf(mockDbIntegrityService).setServiceURI( with(any(String.class)));137 oneOf(mockDbIntegrityService).setServiceURI("http://localhost:8080/annotator-backend/api/"); 106 138 will(doAll()); 139 140 oneOf(mockDbIntegrityService).getResourceInternalIdentifier(with(aNonNull(UUID.class)), with(aNonNull((Resource.class)))); 141 will(returnValue(2)); 107 142 108 143 oneOf(mockDbIntegrityService).getUserInternalIDFromRemoteID("olhsha@mpi.nl"); … … 110 145 111 146 oneOf(mockDbIntegrityService).canRead(3, 2); 112 will(returnValue(true)); 113 114 oneOf(mockDbIntegrityService).getAnnotationInternalIdentifier(with(any(UUID.class))); 115 will(returnValue(2)); 147 will(returnValue(true)); 116 148 117 149 oneOf(mockDbIntegrityService).getAnnotation(2); … … 144 176 { 145 177 oneOf(mockUriInfo).getBaseUri(); 146 will(returnValue(URI.create("http://localhost:8080/annotator-backend/api/"))); 147 178 will(returnValue(URI.create("http://localhost:8080/annotator-backend/api/"))); 148 179 149 180 oneOf(mockDbIntegrityService).getUserInternalIDFromRemoteID("olhsha@mpi.nl"); … … 153 184 will(doAll()); 154 185 155 oneOf(mockDbIntegrityService).get AnnotationInternalIdentifier(with(aNonNull(UUID.class)));186 oneOf(mockDbIntegrityService).getResourceInternalIdentifier(with(aNonNull(UUID.class)), with(aNonNull((Resource.class)))); 156 187 will(returnValue(4)); 157 188 … … 207 238 addedAnnotation.setOwnerRef("http://localhost:8080/annotator-backend/api/users/"+"00000000-0000-0000-0000-000000000111"); 208 239 240 final ResponseBody mockEnvelope = new ResponseBody(); 241 final Action action = new Action(); 242 final ActionList actionList = new ActionList(); 243 mockEnvelope.setAnnotation(addedAnnotation); 244 mockEnvelope.setActionList(actionList); 245 actionList.getAction().add(action); 246 action.setMessage(AnnotationActionName.CREATE_CACHED_REPRESENTATION.value()); 247 action.setObject("http://localhost:8080/annotator-backend/api/targets/00000000-0000-0000-0000-000000000036"); 248 209 249 annotationResource.setHttpServletRequest(mockRequest); 210 250 annotationResource.setUriInfo(mockUriInfo); … … 221 261 oneOf(mockDbIntegrityService).getUserInternalIDFromRemoteID("olhsha@mpi.nl"); 222 262 will(returnValue(3)); 223 224 263 225 264 oneOf(mockDbIntegrityService).addUsersAnnotation(3, annotationToAdd); 226 265 will(returnValue(newAnnotationID)); … … 231 270 oneOf(mockDbIntegrityService).getTargetsWithNoCachedRepresentation(newAnnotationID); 232 271 will(returnValue(targets)); 272 273 oneOf(mockDbIntegrityService).makeAnnotationResponseEnvelope(newAnnotationID); 274 will(returnValue(mockEnvelope)); 233 275 234 276 }
Note: See TracChangeset
for help on using the changeset viewer.