Changeset 4260


Ignore:
Timestamp:
01/13/14 17:06:18 (10 years ago)
Author:
olhsha
Message:

adding permission for aninexisting user is fixed. It is not added and, if it for /annotations/aid/permissions/uid, the erver send an error message.

Location:
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/UserDao.java

    r4252 r4260  
    5050     
    5151     public int deleteUser(Number intenralID);
     52     
     53     public int deleteUserSafe(Number internalID);
    5254 
    5355     
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/impl/DBIntegrityServiceImlp.java

    r4252 r4260  
    9898    }
    9999
    100    
    101100    @Override
    102101    public Number getTargetInternalIdentifier(UUID externalID) {
     
    139138    }
    140139
    141    
    142140    @Override
    143141    public Annotation getAnnotation(Number annotationID) {
     
    349347
    350348    @Override
    351     public boolean userHasAdminRights(Number userID){
    352        return userDao.hasAdminRights(userID);
    353     }
    354    
     349    public boolean userHasAdminRights(Number userID) {
     350        return userDao.hasAdminRights(userID);
     351    }
     352
    355353    ///// UPDATERS /////////////////
    356354    @Override
     
    366364        for (UserWithPermission userWithPermission : usersWithPermissions) {
    367365            Number userID = userDao.getInternalID(UUID.fromString(userDao.stringURItoExternalID(userWithPermission.getRef())));
    368             Permission permission = userWithPermission.getPermission();
    369             Permission currentPermission = annotationDao.getPermission(annotationID, userID);
    370             if (currentPermission != null) {
    371                 if (!permission.value().equals(currentPermission.value())) {
    372                     result = result + annotationDao.updateAnnotationPrincipalPermission(annotationID, userID, permission);
     366            if (userID != null) {
     367                Permission permission = userWithPermission.getPermission();
     368                Permission currentPermission = annotationDao.getPermission(annotationID, userID);
     369                if (currentPermission != null) {
     370                    if (!permission.value().equals(currentPermission.value())) {
     371                        result = result + annotationDao.updateAnnotationPrincipalPermission(annotationID, userID, permission);
     372                    }
     373                } else {
     374                    result = result + annotationDao.addAnnotationPrincipalPermission(annotationID, userID, permission);
    373375                }
    374             } else {
    375                 result = result + annotationDao.addAnnotationPrincipalPermission(annotationID, userID, permission);
    376376            }
    377377        }
     
    392392        return updatedAnnotations;
    393393    }
    394    
    395      
     394
    396395    // TODO: unit test
    397396    @Override
    398397    public int updateAnnotationBody(Number internalID, AnnotationBody annotationBody) {
    399398        String[] body = annotationDao.retrieveBodyComponents(annotationBody);
    400         return annotationDao.updateAnnotationBody(internalID, body[0], body[1], annotationBody.getXmlBody()!=null);
    401     }
    402    
    403    
    404    
     399        return annotationDao.updateAnnotationBody(internalID, body[0], body[1], annotationBody.getXmlBody() != null);
     400    }
     401
    405402    /////////////// ADDERS  /////////////////////////////////
    406403    @Override
     
    554551        return addedPermissions;
    555552    }
    556    
    557      private TargetInfo getTargetInfoFromTarget(Target target) {
     553
     554    private TargetInfo getTargetInfoFromTarget(Target target) {
    558555        TargetInfo targetInfo = new TargetInfo();
    559556        targetInfo.setRef(target.getURI());
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/impl/JdbcUserDao.java

    r4257 r4260  
    146146   
    147147     ///////////////////// ADDERS ////////////////////////////
     148     @Override
    148149     public Number addUser(User user, String remoteID){
    149150        UUID externalIdentifier = UUID.randomUUID();
     
    161162     
    162163     ////////// UPDATERS ///////////////////////
    163      
     164      @Override
    164165      public Number updateUser(User user){
    165166        Number principalID = this.getInternalIDFromURI(user.getURI());
     
    175176     
    176177     ////// DELETERS ////////////
     178     @Override
    177179     public int deleteUser(Number internalID){
     180           
     181        StringBuilder sql = new StringBuilder("DELETE FROM ");
     182        sql.append(principalTableName).append(" where ").append(principal_id).append(" = ?");
     183        return getSimpleJdbcTemplate().update(sql.toString(), internalID);
     184
     185     }
     186     
     187    @Override
     188    public int deleteUserSafe(Number internalID){
    178189          if (userIsInUse(internalID)) {
    179190            return 0;
     
    184195
    185196     }
    186    
    187197}
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/rest/AnnotationResource.java

    r4252 r4260  
    240240                }
    241241            } 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");
     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.");
    248248            return null;
    249249        }
     
    263263            return new ObjectFactory().createResponseBody(makeAnnotationResponseEnvelope(annotationID));
    264264        } else {
    265             httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, "The logged in user is not found in the database");
     265            httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, "The logged in user is not found in the database.");
    266266            return null;
    267267        }
     
    297297                }
    298298            } 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");
     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.");
    304304            return null;
    305305        }
     
    322322                    return new ObjectFactory().createResponseBody(makeAnnotationResponseEnvelope(annotationID));
    323323                } 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");
     324                    httpServletResponse.sendError(HttpServletResponse.SC_UNAUTHORIZED, "The logged-in user cannot change the body of this annotation because (s)he is  not its 'writer'.");
     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.");
    333333            return null;
    334334        }
     
    341341    public String updatePermission(@PathParam("annotationid") String annotationExternalId, @PathParam("userid") String userExternalId, Permission permission) throws IOException {
    342342        dbIntegrityService.setServiceURI(uriInfo.getBaseUri().toString());
    343         final Number annotationID = dbIntegrityService.getAnnotationInternalIdentifier(UUID.fromString(annotationExternalId));
    344343        final Number remoteUserID = dbIntegrityService.getUserInternalIDFromRemoteID(httpServletRequest.getRemoteUser());
    345         final Number userID = dbIntegrityService.getUserInternalIdentifier(UUID.fromString(userExternalId));
    346344        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");
     345            final Number userID = dbIntegrityService.getUserInternalIdentifier(UUID.fromString(userExternalId));
     346            if (userID != null) {
     347                final Number annotationID = dbIntegrityService.getAnnotationInternalIdentifier(UUID.fromString(annotationExternalId));
     348                if (annotationID != null) {
     349                    if (isOwner(remoteUserID, annotationID)) {
     350                        int result = (dbIntegrityService.getPermission(annotationID, userID) != null)
     351                                ? dbIntegrityService.updateAnnotationPrincipalPermission(annotationID, userID, permission)
     352                                : dbIntegrityService.addAnnotationPrincipalPermission(annotationID, userID, permission);
     353                        logger.info("updatePermission method: OK");
     354                        return result + " rows are updated/added";
     355
     356                    } else {
     357                        httpServletResponse.sendError(HttpServletResponse.SC_UNAUTHORIZED, "The logged-in user cannot change the rights on this annotation because (s)he is  not its owner.");
     358                        return null;
     359                    }
     360                } else {
     361                    httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, "The annotation with the given id is not found in the database.");
     362                    return null;
     363                }
     364            } else {
     365                httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, "The user with the given id is not found in the database.");
     366                return null;
     367            }
     368
     369        } else {
     370            httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, "The logged in user is not found in the database.");
    366371            return null;
    367372        }
     
    380385                if (isOwner(remoteUserID, annotationID)) {
    381386                    int updatedRows = dbIntegrityService.updatePermissions(annotationID, permissions);
    382                     logger.info("updatePermissions method: OK");
    383387                    return new ObjectFactory().createResponseBody(makePermissionResponseEnvelope(annotationID));
    384388                } 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");
     389                    httpServletResponse.sendError(HttpServletResponse.SC_UNAUTHORIZED, "The logged-in user cannot change the rights on this annotation because (s)he is  not its owner.");
     390                    return null;
     391                }
     392            } else {
     393                httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, "The annotation with the given id is not found in the database.");
     394                return null;
     395            }
     396        } else {
     397            httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, "The logged in user is not found in the database.");
    394398            return null;
    395399        }
    396400    }
    397401/////////////////////////////////////////
     402
    398403    private ResponseBody makeAnnotationResponseEnvelope(Number annotationID) {
    399404        ResponseBody result = new ResponseBody();
Note: See TracChangeset for help on using the changeset viewer.