Changeset 4252
- Timestamp:
- 01/10/14 17:20:38 (10 years ago)
- Location:
- DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main
- Files:
-
- 12 edited
Legend:
- Unmodified
- Added
- Removed
-
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/BackendConstants.java
r3936 r4252 27 27 public static final String regExpEmail = regExpIdentifier+"@"+regExpIdentifier; 28 28 public static final String fragmentDescriptors = "[a-zA-Z0-9_-(),#%]*"; 29 public static final String regExpRemoteId = regExpIdentifier+"|"+regExpEmail; 29 30 } -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/DBIntegrityService.java
r4207 r4252 235 235 236 236 237 237 public boolean userHasAdminRights(Number userID); 238 238 239 239 /** -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/UserDao.java
r3972 r4252 32 32 public User getUserByInfo(String eMail); 33 33 34 // where is it used? 34 35 public boolean userIsInUse(Number userID); 35 36 37 // where is it used?? 36 38 public boolean userExists(User user); 37 39 40 public boolean hasAdminRights(Number internalID); 41 38 42 public String getRemoteID(Number internalID); 43 39 44 40 45 public Number getUserInternalIDFromRemoteID(String remoteID); -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/impl/DBIntegrityServiceImlp.java
r4207 r4252 348 348 } 349 349 350 @Override 351 public boolean userHasAdminRights(Number userID){ 352 return userDao.hasAdminRights(userID); 353 } 354 350 355 ///// UPDATERS ///////////////// 351 356 @Override -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/impl/JdbcResourceDao.java
r4181 r4252 37 37 public class JdbcResourceDao extends SimpleJdbcDaoSupport implements ResourceDao { 38 38 39 // base string constants: reTargettable Names39 // base string constants: table Names 40 40 final static protected String notebookTableName = "notebook"; 41 41 final static protected String annotationTableName = "annotation"; … … 50 50 final static protected String targetsCachedRepresentationsTableName = "targets_cached_representations"; 51 51 // base string constants: field Names 52 final static protected String admin_rights = "admin_rights"; 52 53 final static protected String annotation_id = "annotation_id"; 53 54 final static protected String notebook_id = "notebook_id"; -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/impl/JdbcUserDao.java
r4146 r4252 131 131 } 132 132 133 @Override 134 public boolean hasAdminRights(Number internalID){ 135 StringBuilder requestDB = new StringBuilder("SELECT "); 136 requestDB.append(admin_rights).append(" FROM ").append(principalTableName).append(" WHERE ").append(principal_id).append("= ? LIMIT 1"); 137 List<Boolean> result = getSimpleJdbcTemplate().query(requestDB.toString(), adminRightsRowMapper, internalID); 138 return (result.size() > 0) ? result.get(0).booleanValue() :false; 139 } 140 private final RowMapper<Boolean> adminRightsRowMapper = new RowMapper<Boolean>() { 141 @Override 142 public Boolean mapRow(ResultSet rs, int rowNumber) throws SQLException { 143 return new Boolean(rs.getBoolean(admin_rights)); 144 } 145 }; 146 133 147 ///////////////////// ADDERS //////////////////////////// 134 148 public Number addUser(User user, String remoteID){ … … 153 167 sql.append(principalTableName).append(" SET "). 154 168 append(e_mail).append("= '").append(user.getEMail()).append("',"). 155 append(principal_name).append("= '").append(user.getDisplayName()).append("' ,").156 append(" 'WHERE ").append(principal_id).append("= ?");169 append(principal_name).append("= '").append(user.getDisplayName()).append("' "). 170 append(" WHERE ").append(principal_id).append("= ?"); 157 171 int affectedRows = getSimpleJdbcTemplate().update(sql.toString(), principalID); 158 172 return principalID; -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/rest/AnnotationResource.java
r4245 r4252 113 113 String remoteUser = httpServletRequest.getRemoteUser(); 114 114 final Number userID = dbIntegrityService.getUserInternalIDFromRemoteID(remoteUser); 115 if (canRead(userID, annotationID)) { 116 final Annotation annotation = dbIntegrityService.getAnnotation(annotationID); 117 JAXBElement<Annotation> rootElement = new ObjectFactory().createAnnotation(annotation); 118 logger.info("getAnnotation method: OK"); 119 return rootElement; 120 } else { 121 httpServletResponse.sendError(HttpServletResponse.SC_FORBIDDEN, "The logged-in user cannot read the annotation."); 122 return null; 123 } 124 } else { 125 httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, "The annotation with the given id is not found in the database"); 115 if (userID != null) { 116 if (canRead(userID, annotationID)) { 117 final Annotation annotation = dbIntegrityService.getAnnotation(annotationID); 118 JAXBElement<Annotation> rootElement = new ObjectFactory().createAnnotation(annotation); 119 logger.info("getAnnotation method: OK"); 120 return rootElement; 121 } else { 122 httpServletResponse.sendError(HttpServletResponse.SC_FORBIDDEN, "The logged-in user cannot read the annotation."); 123 return null; 124 } 125 } else { 126 httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, "The annotation with the given id is not found in the database"); 127 return null; 128 } 129 } else { 130 httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, "The logged in user is not found in the database"); 126 131 return null; 127 132 } … … 139 144 if (annotationID != null) { 140 145 final Number userID = dbIntegrityService.getUserInternalIDFromRemoteID(httpServletRequest.getRemoteUser()); 141 if (canRead(userID, annotationID)) { 142 final ReferenceList TargetList = dbIntegrityService.getAnnotationTargets(annotationID); 143 logger.info("getAnnotationTargets method: OK"); 144 return new ObjectFactory().createTargetList(TargetList); 145 } else { 146 httpServletResponse.sendError(HttpServletResponse.SC_FORBIDDEN, "The logged-in user cannot read the annotation."); 147 return null; 148 } 149 } else { 150 httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, "The annotation with the given id is not found in the database"); 151 return null; 152 } 153 } 154 155 // TODO Unit test 146 if (userID != null) { 147 if (canRead(userID, annotationID)) { 148 final ReferenceList TargetList = dbIntegrityService.getAnnotationTargets(annotationID); 149 logger.info("getAnnotationTargets method: OK"); 150 return new ObjectFactory().createTargetList(TargetList); 151 } else { 152 httpServletResponse.sendError(HttpServletResponse.SC_FORBIDDEN, "The logged-in user cannot read the annotation."); 153 return null; 154 } 155 } else { 156 httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, "The annotation with the given id is not found in the database"); 157 return null; 158 } 159 } else { 160 httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, "The logged in user is not found in the database"); 161 return null; 162 } 163 } 164 // TODO Unit test 165 156 166 @GET 157 167 @Produces(MediaType.TEXT_XML) … … 164 174 @QueryParam("owner") String ownerExternalId, 165 175 @QueryParam("after") Timestamp after, 166 @QueryParam("before") Timestamp before) {176 @QueryParam("before") Timestamp before) throws IOException { 167 177 168 178 dbIntegrityService.setServiceURI(uriInfo.getBaseUri().toString()); 169 179 Number userID = dbIntegrityService.getUserInternalIDFromRemoteID(httpServletRequest.getRemoteUser()); 170 UUID ownerExternalUUID = (ownerExternalId != null) ? UUID.fromString(ownerExternalId) : null; 171 String access = (permission != null) ? permission : default_permission; 172 final AnnotationInfoList annotationInfoList = dbIntegrityService.getFilteredAnnotationInfos(link, text, userID, makeAccessModeChain(access), namespace, ownerExternalUUID, after, before); 173 logger.info("getFilteredAnnotations method: OK"); 174 return new ObjectFactory().createAnnotationInfoList(annotationInfoList); 180 if (userID != null) { 181 UUID ownerExternalUUID = (ownerExternalId != null) ? UUID.fromString(ownerExternalId) : null; 182 String access = (permission != null) ? permission : default_permission; 183 final AnnotationInfoList annotationInfoList = dbIntegrityService.getFilteredAnnotationInfos(link, text, userID, makeAccessModeChain(access), namespace, ownerExternalUUID, after, before); 184 logger.info("getFilteredAnnotations method: OK"); 185 return new ObjectFactory().createAnnotationInfoList(annotationInfoList); 186 } else { 187 httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, "The logged in user is not found in the database"); 188 return null; 189 } 190 175 191 } 176 192 … … 184 200 final Number annotationID = dbIntegrityService.getAnnotationInternalIdentifier(UUID.fromString(ExternalIdentifier)); 185 201 final Number userID = dbIntegrityService.getUserInternalIDFromRemoteID(httpServletRequest.getRemoteUser()); 186 if (annotationID != null) { 187 if (canRead(userID, annotationID)) { 188 final UserWithPermissionList permissionList = dbIntegrityService.getPermissionsForAnnotation(annotationID); 189 logger.info("getAnnotationPermissions method: OK"); 190 return new ObjectFactory().createPermissionList(permissionList); 191 } else { 192 httpServletResponse.sendError(HttpServletResponse.SC_FORBIDDEN, "The logged-in user cannot read the annotation."); 193 return null; 194 } 195 } else { 196 httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, "The annotation with the given id is not found in the database"); 197 return null; 198 } 199 } 200 201 /////////////////////////////////////////////////////// 202 // TODO: how to return the status code? 202 if (userID != null) { 203 if (annotationID != null) { 204 if (canRead(userID, annotationID)) { 205 final UserWithPermissionList permissionList = dbIntegrityService.getPermissionsForAnnotation(annotationID); 206 logger.info("getAnnotationPermissions method: OK"); 207 return new ObjectFactory().createPermissionList(permissionList); 208 } else { 209 httpServletResponse.sendError(HttpServletResponse.SC_FORBIDDEN, "The logged-in user cannot read the annotation."); 210 return null; 211 } 212 } else { 213 httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, "The annotation with the given id is not found in the database"); 214 return null; 215 } 216 } else { 217 httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, "The logged in user is not found in the database"); 218 return null; 219 } 220 } 221 /////////////////////////////////////////////////////// 222 // TODO: how to return the status code? 223 203 224 @DELETE 204 225 @Path("{annotationid: " + BackendConstants.regExpIdentifier + "}") … … 207 228 final Number annotationID = dbIntegrityService.getAnnotationInternalIdentifier(UUID.fromString(externalIdentifier)); 208 229 final Number userID = dbIntegrityService.getUserInternalIDFromRemoteID(httpServletRequest.getRemoteUser()); 209 if (annotationID != null) { 210 if (isOwner(userID, annotationID)) { 211 int[] resultDelete = dbIntegrityService.deleteAnnotation(annotationID); 212 String result = Integer.toString(resultDelete[0]); 213 logger.info("deleteAnnotation method: OK"); 214 return result + " annotation(s) deleted."; 215 } else { 216 httpServletResponse.sendError(HttpServletResponse.SC_FORBIDDEN, "The logged-in user cannot delete the annotation. Only the owner can delete the annotation."); 217 return null; 218 } 219 } else { 220 httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, "The annotation with the given id is not found in the database"); 221 return null; 222 } 223 } 224 225 /////////////////////////////////////////////////////// 230 if (userID != null) { 231 if (annotationID != null) { 232 if (isOwner(userID, annotationID)) { 233 int[] resultDelete = dbIntegrityService.deleteAnnotation(annotationID); 234 String result = Integer.toString(resultDelete[0]); 235 logger.info("deleteAnnotation method: OK"); 236 return result + " annotation(s) deleted."; 237 } else { 238 httpServletResponse.sendError(HttpServletResponse.SC_FORBIDDEN, "The logged-in user cannot delete the annotation. Only the owner can delete the annotation."); 239 return null; 240 } 241 } else { 242 httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, "The annotation with the given id is not found in the database"); 243 return null; 244 } 245 246 } else { 247 httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, "The logged in user is not found in the database"); 248 return null; 249 } 250 } 251 /////////////////////////////////////////////////////// 252 226 253 @POST 227 254 @Consumes(MediaType.APPLICATION_XML) … … 231 258 dbIntegrityService.setServiceURI(uriInfo.getBaseUri().toString()); 232 259 final Number userID = dbIntegrityService.getUserInternalIDFromRemoteID(httpServletRequest.getRemoteUser()); 233 Number annotationID = dbIntegrityService.addUsersAnnotation(userID, annotation); 234 logger.info("createAnnotation method: OK"); 235 return new ObjectFactory().createResponseBody(makeAnnotationResponseEnvelope(annotationID)); 236 } 237 238 /////////////////////////////////////////////////////// 239 // TODO: unit test 260 if (userID != null) { 261 Number annotationID = dbIntegrityService.addUsersAnnotation(userID, annotation); 262 logger.info("createAnnotation method: OK"); 263 return new ObjectFactory().createResponseBody(makeAnnotationResponseEnvelope(annotationID)); 264 } else { 265 httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, "The logged in user is not found in the database"); 266 return null; 267 } 268 } 269 /////////////////////////////////////////////////////// 270 // TODO: unit test 271 240 272 @PUT 241 273 @Consumes(MediaType.APPLICATION_XML) … … 254 286 if (annotationID != null) { 255 287 final Number userID = dbIntegrityService.getUserInternalIDFromRemoteID(httpServletRequest.getRemoteUser()); 256 if (canWrite(userID, annotationID)) { 257 int updatedRows = dbIntegrityService.updateUsersAnnotation(userID, annotation); 258 logger.info("updateAnnotation method: OK"); 259 return new ObjectFactory().createResponseBody(makeAnnotationResponseEnvelope(annotationID)); 260 261 } else { 262 httpServletResponse.sendError(HttpServletResponse.SC_UNAUTHORIZED); 263 return null; 264 } 265 } else { 266 httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, "The annotation with the given id is not found in the database"); 288 if (userID != null) { 289 if (canWrite(userID, annotationID)) { 290 int updatedRows = dbIntegrityService.updateUsersAnnotation(userID, annotation); 291 logger.info("updateAnnotation method: OK"); 292 return new ObjectFactory().createResponseBody(makeAnnotationResponseEnvelope(annotationID)); 293 294 } else { 295 httpServletResponse.sendError(HttpServletResponse.SC_UNAUTHORIZED); 296 return null; 297 } 298 } else { 299 httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, "The annotation with the given id is not found in the database"); 300 return null; 301 } 302 } else { 303 httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, "The logged in user is not found in the database"); 267 304 return null; 268 305 } … … 276 313 String path = uriInfo.getBaseUri().toString(); 277 314 dbIntegrityService.setServiceURI(path); 278 279 315 final Number annotationID = dbIntegrityService.getAnnotationInternalIdentifier(UUID.fromString(externalIdentifier)); 280 316 final Number userID = dbIntegrityService.getUserInternalIDFromRemoteID(httpServletRequest.getRemoteUser()); 281 if (annotationID != null) { 282 if (canWrite(userID, annotationID)) { 283 int updatedRows = dbIntegrityService.updateAnnotationBody(annotationID, annotationBody); 284 logger.info("updateAnnotationBody method: OK"); 285 return new ObjectFactory().createResponseBody(makeAnnotationResponseEnvelope(annotationID)); 286 } else { 287 httpServletResponse.sendError(HttpServletResponse.SC_UNAUTHORIZED); 288 return null; 289 } 290 } else { 291 httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, "The annotation with the given id is not found in the database"); 317 if (userID != null) { 318 if (annotationID != null) { 319 if (canWrite(userID, annotationID)) { 320 int updatedRows = dbIntegrityService.updateAnnotationBody(annotationID, annotationBody); 321 logger.info("updateAnnotationBody method: OK"); 322 return new ObjectFactory().createResponseBody(makeAnnotationResponseEnvelope(annotationID)); 323 } else { 324 httpServletResponse.sendError(HttpServletResponse.SC_UNAUTHORIZED); 325 return null; 326 } 327 } else { 328 httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, "The annotation with the given id is not found in the database"); 329 return null; 330 } 331 } else { 332 httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, "The logged in user is not found in the database"); 292 333 return null; 293 334 } … … 303 344 final Number remoteUserID = dbIntegrityService.getUserInternalIDFromRemoteID(httpServletRequest.getRemoteUser()); 304 345 final Number userID = dbIntegrityService.getUserInternalIdentifier(UUID.fromString(userExternalId)); 305 if (annotationID != null) { 306 if (isOwner(remoteUserID, annotationID)) { 307 int result = (dbIntegrityService.getPermission(annotationID, userID) != null) 308 ? dbIntegrityService.updateAnnotationPrincipalPermission(annotationID, userID, permission) 309 : dbIntegrityService.addAnnotationPrincipalPermission(annotationID, userID, permission); 310 logger.info("updatePermission method: OK"); 311 return result + " rows are updated/added"; 312 313 } else { 314 httpServletResponse.sendError(HttpServletResponse.SC_UNAUTHORIZED); 315 return null; 316 } 317 } else { 318 httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, "The annotation with the given id is not found in the database"); 346 if (remoteUserID != null) { 347 if (annotationID != null) { 348 if (isOwner(remoteUserID, annotationID)) { 349 int result = (dbIntegrityService.getPermission(annotationID, userID) != null) 350 ? dbIntegrityService.updateAnnotationPrincipalPermission(annotationID, userID, permission) 351 : dbIntegrityService.addAnnotationPrincipalPermission(annotationID, userID, permission); 352 logger.info("updatePermission method: OK"); 353 return result + " rows are updated/added"; 354 355 } else { 356 httpServletResponse.sendError(HttpServletResponse.SC_UNAUTHORIZED); 357 return null; 358 } 359 } else { 360 httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, "The annotation with the given id is not found in the database"); 361 return null; 362 } 363 364 } else { 365 httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, "The logged in user is not found in the database"); 319 366 return null; 320 367 } … … 329 376 final Number annotationID = dbIntegrityService.getAnnotationInternalIdentifier(UUID.fromString(annotationExternalId)); 330 377 final Number remoteUserID = dbIntegrityService.getUserInternalIDFromRemoteID(httpServletRequest.getRemoteUser()); 331 if (annotationID != null) { 332 if (isOwner(remoteUserID, annotationID)) { 333 int updatedRows = dbIntegrityService.updatePermissions(annotationID, permissions); 334 logger.info("updatePermissions method: OK"); 335 return new ObjectFactory().createResponseBody(makePermissionResponseEnvelope(annotationID)); 336 } else { 337 httpServletResponse.sendError(HttpServletResponse.SC_UNAUTHORIZED); 338 return null; 339 } 340 } else { 341 httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, "The annotation with the given id is not found in the database"); 342 return null; 343 } 344 } 345 346 ///////////////////////////////////////// 378 if (remoteUserID != null) { 379 if (annotationID != null) { 380 if (isOwner(remoteUserID, annotationID)) { 381 int updatedRows = dbIntegrityService.updatePermissions(annotationID, permissions); 382 logger.info("updatePermissions method: OK"); 383 return new ObjectFactory().createResponseBody(makePermissionResponseEnvelope(annotationID)); 384 } else { 385 httpServletResponse.sendError(HttpServletResponse.SC_UNAUTHORIZED); 386 return null; 387 } 388 } else { 389 httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, "The annotation with the given id is not found in the database"); 390 return null; 391 } 392 } else { 393 httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, "The logged in user is not found in the database"); 394 return null; 395 } 396 } 397 ///////////////////////////////////////// 347 398 private ResponseBody makeAnnotationResponseEnvelope(Number annotationID) { 348 399 ResponseBody result = new ResponseBody(); -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/rest/CachedRepresentationResource.java
r4245 r4252 72 72 @Transactional(readOnly = true) 73 73 public JAXBElement<CachedRepresentationInfo> getCachedRepresentationInfo(@PathParam("cachedid") String externalId) throws SQLException, IOException { 74 dbIntegrityService.setServiceURI(uriInfo.getBaseUri().toString()); 75 final Number cachedID = dbIntegrityService.getCachedRepresentationInternalIdentifier(UUID.fromString(externalId)); 76 if (cachedID != null) { 77 final CachedRepresentationInfo cachedInfo = dbIntegrityService.getCachedRepresentationInfo(cachedID); 78 return new ObjectFactory().createCashedRepresentationInfo(cachedInfo); 74 75 final Number remoteUserID = dbIntegrityService.getUserInternalIDFromRemoteID(httpServletRequest.getRemoteUser()); 76 if (remoteUserID != null) { 77 dbIntegrityService.setServiceURI(uriInfo.getBaseUri().toString()); 78 final Number cachedID = dbIntegrityService.getCachedRepresentationInternalIdentifier(UUID.fromString(externalId)); 79 if (cachedID != null) { 80 final CachedRepresentationInfo cachedInfo = dbIntegrityService.getCachedRepresentationInfo(cachedID); 81 return new ObjectFactory().createCashedRepresentationInfo(cachedInfo); 82 } else { 83 httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, "The cached representation with the given id is not found in the database"); 84 return null; 85 } 79 86 } else { 80 httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, "The cached representation with the given idis not found in the database");87 httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, "The logged in user is not found in the database"); 81 88 return null; 82 89 } … … 88 95 @Transactional(readOnly = true) 89 96 public BufferedImage getCachedRepresentationContent(@PathParam("cachedid") String externalId) throws SQLException, IOException { 90 dbIntegrityService.setServiceURI(uriInfo.getBaseUri().toString()); 91 final Number cachedID = dbIntegrityService.getCachedRepresentationInternalIdentifier(UUID.fromString(externalId)); 92 if (cachedID != null) { 93 InputStream dbRespond = dbIntegrityService.getCachedRepresentationBlob(cachedID); 94 ImageIO.setUseCache(false); 95 BufferedImage result = ImageIO.read(dbRespond); 96 return result; 97 final Number remoteUserID = dbIntegrityService.getUserInternalIDFromRemoteID(httpServletRequest.getRemoteUser()); 98 if (remoteUserID != null) { 99 dbIntegrityService.setServiceURI(uriInfo.getBaseUri().toString()); 100 final Number cachedID = dbIntegrityService.getCachedRepresentationInternalIdentifier(UUID.fromString(externalId)); 101 if (cachedID != null) { 102 InputStream dbRespond = dbIntegrityService.getCachedRepresentationBlob(cachedID); 103 ImageIO.setUseCache(false); 104 BufferedImage result = ImageIO.read(dbRespond); 105 return result; 106 } else { 107 httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, "The cached representation with the given id is not found in the database"); 108 return null; 109 } 97 110 } else { 98 httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, "The cached representation with the given idis not found in the database");111 httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, "The logged in user is not found in the database"); 99 112 return null; 100 113 } -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/rest/TargetResource.java
r4245 r4252 83 83 @Transactional(readOnly = true) 84 84 public JAXBElement<Target> getTarget(@PathParam("targetid") String ExternalIdentifier) throws SQLException, IOException { 85 dbIntegrityService.setServiceURI(uriInfo.getBaseUri().toString()); 86 final Number targetID = dbIntegrityService.getTargetInternalIdentifier(UUID.fromString(ExternalIdentifier)); 87 if (targetID != null) { 88 final Target target = dbIntegrityService.getTarget(targetID); 89 return new ObjectFactory().createTarget(target); 85 final Number remoteUserID = dbIntegrityService.getUserInternalIDFromRemoteID(httpServletRequest.getRemoteUser()); 86 if (remoteUserID != null) { 87 dbIntegrityService.setServiceURI(uriInfo.getBaseUri().toString()); 88 final Number targetID = dbIntegrityService.getTargetInternalIdentifier(UUID.fromString(ExternalIdentifier)); 89 if (targetID != null) { 90 final Target target = dbIntegrityService.getTarget(targetID); 91 return new ObjectFactory().createTarget(target); 92 } else { 93 httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, "The target with the given id is not found in the database"); 94 return null; 95 } 90 96 } else { 91 httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, "The target with the given idis not found in the database");97 httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, "The logged in user is not found in the database"); 92 98 return null; 93 99 } … … 100 106 @Transactional(readOnly = true) 101 107 public JAXBElement<ReferenceList> getSiblingTargets(@PathParam("targetid") String ExternalIdentifier) throws SQLException, IOException { 102 dbIntegrityService.setServiceURI(uriInfo.getBaseUri().toString()); 103 final Number targetID = dbIntegrityService.getTargetInternalIdentifier(UUID.fromString(ExternalIdentifier)); 104 if (targetID != null) { 105 final ReferenceList siblings = dbIntegrityService.getTargetsForTheSameLinkAs(targetID); 106 return new ObjectFactory().createReferenceList(siblings); 108 final Number remoteUserID = dbIntegrityService.getUserInternalIDFromRemoteID(httpServletRequest.getRemoteUser()); 109 if (remoteUserID != null) { 110 dbIntegrityService.setServiceURI(uriInfo.getBaseUri().toString()); 111 final Number targetID = dbIntegrityService.getTargetInternalIdentifier(UUID.fromString(ExternalIdentifier)); 112 if (targetID != null) { 113 final ReferenceList siblings = dbIntegrityService.getTargetsForTheSameLinkAs(targetID); 114 return new ObjectFactory().createReferenceList(siblings); 115 } else { 116 httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, "The target with the given id is not found in the database"); 117 return null; 118 } 107 119 } else { 108 httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, "The target with the given idis not found in the database");120 httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, "The logged in user is not found in the database"); 109 121 return null; 110 122 } … … 132 144 public JAXBElement<CachedRepresentationInfo> postCached(@PathParam("targetid") String targetIdentifier, 133 145 @PathParam("fragmentDescriptor") String fragmentDescriptor, 134 MultiPart multiPart) throws SQLException { 135 dbIntegrityService.setServiceURI(uriInfo.getBaseUri().toString()); 136 final Number targetID = dbIntegrityService.getTargetInternalIdentifier(UUID.fromString(targetIdentifier)); 137 CachedRepresentationInfo metadata = multiPart.getBodyParts().get(0).getEntityAs(CachedRepresentationInfo.class); 138 BodyPartEntity bpe = (BodyPartEntity) multiPart.getBodyParts().get(1).getEntity(); 139 InputStream cachedSource = bpe.getInputStream(); 140 final Number[] respondDB = dbIntegrityService.addCachedForTarget(targetID, fragmentDescriptor, metadata, cachedSource); 141 final CachedRepresentationInfo cachedInfo = dbIntegrityService.getCachedRepresentationInfo(respondDB[1]); 142 return new ObjectFactory() 143 .createCashedRepresentationInfo(cachedInfo); 146 MultiPart multiPart) throws SQLException, IOException { 147 final Number remoteUserID = dbIntegrityService.getUserInternalIDFromRemoteID(httpServletRequest.getRemoteUser()); 148 if (remoteUserID != null) { 149 dbIntegrityService.setServiceURI(uriInfo.getBaseUri().toString()); 150 final Number targetID = dbIntegrityService.getTargetInternalIdentifier(UUID.fromString(targetIdentifier)); 151 CachedRepresentationInfo metadata = multiPart.getBodyParts().get(0).getEntityAs(CachedRepresentationInfo.class); 152 BodyPartEntity bpe = (BodyPartEntity) multiPart.getBodyParts().get(1).getEntity(); 153 InputStream cachedSource = bpe.getInputStream(); 154 final Number[] respondDB = dbIntegrityService.addCachedForTarget(targetID, fragmentDescriptor, metadata, cachedSource); 155 final CachedRepresentationInfo cachedInfo = dbIntegrityService.getCachedRepresentationInfo(respondDB[1]); 156 return new ObjectFactory() 157 .createCashedRepresentationInfo(cachedInfo); 158 } else { 159 httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, "The logged in user is not found in the database"); 160 return null; 161 } 144 162 145 163 } … … 149 167 public String deleteCachedForTarget(@PathParam("targetid") String targetExternalIdentifier, 150 168 @PathParam("cachedid") String cachedExternalIdentifier) throws SQLException, IOException { 151 dbIntegrityService.setServiceURI(uriInfo.getBaseUri().toString()); 152 final Number targetID = dbIntegrityService.getTargetInternalIdentifier(UUID.fromString(targetExternalIdentifier)); 153 if (targetID != null) { 154 final Number cachedID = dbIntegrityService.getCachedRepresentationInternalIdentifier(UUID.fromString(cachedExternalIdentifier)); 155 if (cachedID != null) { 156 int[] resultDelete = dbIntegrityService.deleteCachedRepresentationOfTarget(targetID, cachedID); 157 String result = Integer.toString(resultDelete[0]); 158 return result + " pair(s) target-cached deleted."; 169 final Number remoteUserID = dbIntegrityService.getUserInternalIDFromRemoteID(httpServletRequest.getRemoteUser()); 170 if (remoteUserID != null) { 171 dbIntegrityService.setServiceURI(uriInfo.getBaseUri().toString()); 172 final Number targetID = dbIntegrityService.getTargetInternalIdentifier(UUID.fromString(targetExternalIdentifier)); 173 if (targetID != null) { 174 final Number cachedID = dbIntegrityService.getCachedRepresentationInternalIdentifier(UUID.fromString(cachedExternalIdentifier)); 175 if (cachedID != null) { 176 int[] resultDelete = dbIntegrityService.deleteCachedRepresentationOfTarget(targetID, cachedID); 177 String result = Integer.toString(resultDelete[0]); 178 return result + " pair(s) target-cached deleted."; 179 } else { 180 httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, "The cached representation with the given id is not found in the database"); 181 return null; 182 } 159 183 } else { 160 httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, "The cached representationwith the given id is not found in the database");184 httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, "The target with the given id is not found in the database"); 161 185 return null; 162 186 } 163 187 } else { 164 httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, "The target with the given idis not found in the database");188 httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, "The logged in user is not found in the database"); 165 189 return null; 166 190 } -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/rest/UserResource.java
r4245 r4252 29 29 import javax.servlet.http.HttpServletResponse; 30 30 import javax.ws.rs.Consumes; 31 import javax.ws.rs.DELETE; 31 32 import javax.ws.rs.GET; 32 33 import javax.ws.rs.POST; … … 72 73 @GET 73 74 @Produces(MediaType.TEXT_XML) 74 @Path("{userid: " + BackendConstants.regExp Identifier+ "}")75 @Path("{userid: " + BackendConstants.regExpRemoteId + "}") 75 76 @Transactional(readOnly = true) 76 77 public JAXBElement<User> getUser(@PathParam("userid") String ExternalIdentifier) throws SQLException, IOException { 77 dbIntegrityService.setServiceURI(uriInfo.getBaseUri().toString()); 78 final Number userID = dbIntegrityService.getUserInternalIdentifier(UUID.fromString(ExternalIdentifier)); 79 if (userID != null) { 80 final User user = dbIntegrityService.getUser(userID); 81 return new ObjectFactory().createUser(user); 82 } else { 83 httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, "The user with the given id is not found in the database"); 78 final Number remoteUserID = dbIntegrityService.getUserInternalIDFromRemoteID(httpServletRequest.getRemoteUser()); 79 if (remoteUserID != null) { 80 dbIntegrityService.setServiceURI(uriInfo.getBaseUri().toString()); 81 final Number userID = dbIntegrityService.getUserInternalIdentifier(UUID.fromString(ExternalIdentifier)); 82 if (userID != null) { 83 final User user = dbIntegrityService.getUser(userID); 84 return new ObjectFactory().createUser(user); 85 } else { 86 httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, "The user with the given id is not found in the database"); 87 return null; 88 } 89 } else { 90 httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, "The logged in user is not found in the database"); 84 91 return null; 85 92 } … … 91 98 @Transactional(readOnly = true) 92 99 public JAXBElement<User> getUserByInfo(@QueryParam("email") String email) throws SQLException, IOException { 93 dbIntegrityService.setServiceURI(uriInfo.getBaseUri().toString()); 94 final User user = dbIntegrityService.getUserByInfo(email); 95 if (user != null) { 96 return new ObjectFactory().createUser(user); 97 } else { 98 httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, "The user with the given info is not found in the database"); 100 final Number remoteUserID = dbIntegrityService.getUserInternalIDFromRemoteID(httpServletRequest.getRemoteUser()); 101 if (remoteUserID != null) { 102 dbIntegrityService.setServiceURI(uriInfo.getBaseUri().toString()); 103 final User user = dbIntegrityService.getUserByInfo(email); 104 if (user != null) { 105 return new ObjectFactory().createUser(user); 106 } else { 107 httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, "The user with the given info is not found in the database"); 108 return null; 109 } 110 } else { 111 httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, "The logged in user is not found in the database"); 99 112 return null; 100 113 } … … 106 119 @Transactional(readOnly = true) 107 120 public JAXBElement<CurrentUserInfo> getCurrentUserInfo(@PathParam("userid") String ExternalIdentifier) throws IOException { 108 dbIntegrityService.setServiceURI(uriInfo.getBaseUri().toString()); 109 final Number userID = dbIntegrityService.getUserInternalIdentifier(UUID.fromString(ExternalIdentifier)); 110 if (userID != null) { 111 final CurrentUserInfo userInfo = new CurrentUserInfo(); 112 userInfo.setRef(dbIntegrityService.getUserURI(userID)); 113 userInfo.setCurrentUser(ifLoggedIn(userID)); 114 return new ObjectFactory().createCurrentUserInfo(userInfo); 115 } else { 116 httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, "The user with the given id is not found in the database"); 121 final Number remoteUserID = dbIntegrityService.getUserInternalIDFromRemoteID(httpServletRequest.getRemoteUser()); 122 if (remoteUserID != null) { 123 dbIntegrityService.setServiceURI(uriInfo.getBaseUri().toString()); 124 final Number userID = dbIntegrityService.getUserInternalIdentifier(UUID.fromString(ExternalIdentifier)); 125 if (userID != null) { 126 final CurrentUserInfo userInfo = new CurrentUserInfo(); 127 userInfo.setRef(dbIntegrityService.getUserURI(userID)); 128 userInfo.setCurrentUser(ifLoggedIn(userID)); 129 return new ObjectFactory().createCurrentUserInfo(userInfo); 130 } else { 131 httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, "The user with the given id is not found in the database"); 132 return null; 133 } 134 } else { 135 httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, "The logged in user is not found in the database"); 117 136 return null; 118 137 } … … 120 139 121 140 @POST 122 @Consumes(MediaType.TEXT_XML) 123 @Produces(MediaType.TEXT_XML) 124 @Path("{remoteId: " + BackendConstants.regExpIdentifier + "}") 125 public JAXBElement<User> addUser(@PathParam("userid") String remoteId, User user) throws SQLException { 126 dbIntegrityService.setServiceURI(uriInfo.getBaseUri().toString()); 127 final Number userID = dbIntegrityService.addUser(user, remoteId); 128 final User addedUser = dbIntegrityService.getUser(userID); 129 return new ObjectFactory().createUser(addedUser); 141 @Consumes(MediaType.APPLICATION_XML) 142 @Produces(MediaType.APPLICATION_XML) 143 @Path("{remoteId: " + BackendConstants.regExpRemoteId+ "}") 144 public JAXBElement<User> addUser(@PathParam("remoteId") String remoteId, User user) throws SQLException, IOException { 145 final Number remoteUserID = dbIntegrityService.getUserInternalIDFromRemoteID(httpServletRequest.getRemoteUser()); 146 if (remoteUserID != null) { 147 if (dbIntegrityService.userHasAdminRights(remoteUserID)) { 148 dbIntegrityService.setServiceURI(uriInfo.getBaseUri().toString()); 149 final Number userID = dbIntegrityService.addUser(user, remoteId); 150 if (userID != null) { 151 final User addedUser = dbIntegrityService.getUser(userID); 152 return new ObjectFactory().createUser(addedUser); 153 } 154 else { 155 httpServletResponse.sendError(HttpServletResponse.SC_CONFLICT, "The user with the given e-mail already exists in the database"); 156 return null; 157 } 158 } else { 159 httpServletResponse.sendError(HttpServletResponse.SC_UNAUTHORIZED, "The logged in user does not have admin rights to add a user to the database"); 160 return null; 161 } 162 } else { 163 httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, "The logged in user is not found in the database"); 164 return null; 165 } 130 166 } 131 167 132 168 @PUT 133 @Consumes(MediaType. TEXT_XML)134 @Produces(MediaType. TEXT_XML)169 @Consumes(MediaType.APPLICATION_XML) 170 @Produces(MediaType.APPLICATION_XML) 135 171 @Path("") 136 public JAXBElement<User> updateUser(User user) throws IOException{ 137 dbIntegrityService.setServiceURI(uriInfo.getBaseUri().toString()); 138 final Number userID = dbIntegrityService.updateUser(user); 139 if (userID != null) { 140 final User addedUser = dbIntegrityService.getUser(userID); 141 return new ObjectFactory().createUser(addedUser); 142 } else { 143 httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, "The user with the given id is not found in the database"); 144 return null; 145 } 146 } 147 172 public JAXBElement<User> updateUser(User user) throws IOException { 173 final Number remoteUserID = dbIntegrityService.getUserInternalIDFromRemoteID(httpServletRequest.getRemoteUser()); 174 if (remoteUserID != null) { 175 if (dbIntegrityService.userHasAdminRights(remoteUserID)) { 176 dbIntegrityService.setServiceURI(uriInfo.getBaseUri().toString()); 177 final Number userID = dbIntegrityService.updateUser(user); 178 if (userID != null) { 179 final User addedUser = dbIntegrityService.getUser(userID); 180 return new ObjectFactory().createUser(addedUser); 181 } else { 182 httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, "The user with the given id is not found in the database"); 183 return null; 184 } 185 } else { 186 httpServletResponse.sendError(HttpServletResponse.SC_UNAUTHORIZED, "The logged in user does not have admin rights to update a user info in the database"); 187 return null; 188 } 189 } else { 190 httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, "The logged in user is not found in the database"); 191 return null; 192 } 193 } 194 195 196 197 @DELETE 198 @Path("{userId: " + BackendConstants.regExpRemoteId + "}") 199 public String deleteUser(@PathParam("userId") String externalIdentifier) throws IOException { 200 final Number remoteUserID = dbIntegrityService.getUserInternalIDFromRemoteID(httpServletRequest.getRemoteUser()); 201 if (remoteUserID != null) { 202 if (dbIntegrityService.userHasAdminRights(remoteUserID)) { 203 dbIntegrityService.setServiceURI(uriInfo.getBaseUri().toString()); 204 final Number userID = dbIntegrityService.getUserInternalIdentifier(UUID.fromString(externalIdentifier)); 205 if (userID != null) { 206 final Integer result = dbIntegrityService.deleteUser(userID); 207 return "There is "+ result.toString()+" row deleted"; 208 } else { 209 httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, "The user with the given id is not found in the database"); 210 return null; 211 } 212 } else { 213 httpServletResponse.sendError(HttpServletResponse.SC_UNAUTHORIZED, "The logged in user does not have admin rights to update a user info in the database"); 214 return null; 215 } 216 } else { 217 httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, "The logged in user is not found in the database"); 218 return null; 219 } 220 } 221 } 222 223 224 225 148 226 private boolean ifLoggedIn(Number userID) { 149 227 return httpServletRequest.getRemoteUser().equals(dbIntegrityService.getUserRemoteID(userID)); -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/webapp/WEB-INF/shhaa.xml
r4245 r4252 41 41 <sso action="lI">https://lux16.mpi.nl/Shibboleth.sso/Login</sso> 42 42 <slo action="lO">https://lux16.mpi.nl/Shibboleth.sso/Logout</slo> 43 <!-- <sso action="lI">http://localhost:8080/annotator-backend/api/index.jsp</sso>44 <slo action="lO">http://localhost:8080/annotator-backend/api/index.jsp</slo> -->45 43 </authentication> 46 44 … … 55 53 56 54 <authorization> 57 <location target="/hvwkejfhvwkehf/*" /> 55 <!-- lux16, 17, corpus1 --> 56 <location target="/*" /> 57 <!-- localhost --> 58 <location target="/dummy/*" /> 58 59 </authorization> 59 60 -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/webapp/WEB-INF/web.xml
r4245 r4252 42 42 </servlet-class> 43 43 <init-param> 44 <param-name> 45 com.sun.jersey.config.property.packages 46 </param-name> 44 <param-name>com.sun.jersey.config.property.packages</param-name> 47 45 <param-value>eu.dasish.annotation.backend</param-value> 48 46 </init-param> … … 67 65 </servlet-mapping> 68 66 69 <filter> 67 <!-- lux16, 17, corpus 1 (shibbolized) --> 68 <!-- <filter> 70 69 <filter-name>AAIFilter</filter-name> 71 70 <filter-class>de.mpg.aai.shhaa.AuthFilter</filter-class> … … 74 73 <filter-name>AAIFilter</filter-name> 75 74 <url-pattern>/*</url-pattern> 76 </filter-mapping> 75 </filter-mapping> --> 76 77 78 <!-- localhost auth experiments --> 79 80 81 <security-constraint> 82 <display-name>Backend localhost</display-name> 83 <web-resource-collection> 84 <web-resource-name> Backend rest service </web-resource-name> 85 <description /> 86 <url-pattern>/*</url-pattern> 87 <http-method>GET</http-method> 88 <http-method>POST</http-method> 89 <http-method>PUT</http-method> 90 <http-method>DELETE</http-method> 91 </web-resource-collection> 92 <auth-constraint> 93 <role-name>tomcat</role-name> 94 </auth-constraint> 95 </security-constraint> 96 <login-config> 97 <auth-method>BASIC</auth-method> 98 </login-config> 99 <security-role> 100 <description> The role that is required to log in to the Application 101 </description> 102 <role-name>tomcat</role-name> 103 </security-role> 104 77 105 </web-app>
Note: See TracChangeset
for help on using the changeset viewer.