@Test(expected = ActionParamsException.class) public void testWithInvalidParamType() throws Exception { final Map<String, String> parameters = new HashMap<String, String>(); parameters.put("id", "this should be of type long"); final ActionParameters params = createActionParams(parameters, getLoggedInUser()); handler.handlePost(params); checkDeleteNotCalled(); fail("ActionParamsException should have been thrown"); }
@Override public void handlePost(ActionParameters params) throws ActionException { params.requireLoggedInUser(); final long id = ConversionHelper.getLong(params.getHttpParam(PARAM_ID), -1); if(id == -1) { throw new ActionParamsException("Parameter missing or non-numeric: " + PARAM_ID + "=" + params.getHttpParam(PARAM_ID)); } final Analysis analysis = analysisDataService.getAnalysisById(id); if(analysis == null) { throw new ActionParamsException("Analysis id didn't match any analysis: " + id); } if(!analysis.isOwnedBy(params.getUser().getUuid())) { throw new ActionDeniedException("Analysis belongs to another user"); } try { analysisDataService.deleteAnalysis(analysis); AuditLog.user(params.getClientIp(), params.getUser()) .withParam("id", id) .deleted(AuditLog.ResourceType.ANALYSIS); ResponseHelper.writeResponse(params, JSONHelper.createJSONObject("result", "success")); } catch (ServiceException ex) { throw new ActionException("Error deleting analysis", ex); } }
DeleteAnalysisDataHandler extends RestActionHandler { @Override public void handlePost(ActionParameters params) throws ActionException { params.requireLoggedInUser(); final long id = ConversionHelper.getLong(params.getHttpParam(PARAM_ID), -1); if(id == -1) { throw new ActionParamsException("Parameter missing or non-numeric: " + PARAM_ID + "=" + params.getHttpParam(PARAM_ID)); } final Analysis analysis = analysisDataService.getAnalysisById(id); if(analysis == null) { throw new ActionParamsException("Analysis id didn't match any analysis: " + id); } if(!analysis.isOwnedBy(params.getUser().getUuid())) { throw new ActionDeniedException("Analysis belongs to another user"); } try { analysisDataService.deleteAnalysis(analysis); AuditLog.user(params.getClientIp(), params.getUser()) .withParam("id", id) .deleted(AuditLog.ResourceType.ANALYSIS); ResponseHelper.writeResponse(params, JSONHelper.createJSONObject("result", "success")); } catch (ServiceException ex) { throw new ActionException("Error deleting analysis", ex); } } }
DeleteAnalysisDataHandler extends RestActionHandler { @Override public void handlePost(ActionParameters params) throws ActionException { params.requireLoggedInUser(); final long id = ConversionHelper.getLong(params.getHttpParam(PARAM_ID), -1); if(id == -1) { throw new ActionParamsException("Parameter missing or non-numeric: " + PARAM_ID + "=" + params.getHttpParam(PARAM_ID)); } final Analysis analysis = analysisDataService.getAnalysisById(id); if(analysis == null) { throw new ActionParamsException("Analysis id didn't match any analysis: " + id); } if(!analysis.isOwnedBy(params.getUser().getUuid())) { throw new ActionDeniedException("Analysis belongs to another user"); } try { analysisDataService.deleteAnalysis(analysis); AuditLog.user(params.getClientIp(), params.getUser()) .withParam("id", id) .deleted(AuditLog.ResourceType.ANALYSIS); ResponseHelper.writeResponse(params, JSONHelper.createJSONObject("result", "success")); } catch (ServiceException ex) { throw new ActionException("Error deleting analysis", ex); } }  }
DeleteAnalysisDataHandler extends RestActionHandler { @Override public void handlePost(ActionParameters params) throws ActionException { params.requireLoggedInUser(); final long id = ConversionHelper.getLong(params.getHttpParam(PARAM_ID), -1); if(id == -1) { throw new ActionParamsException("Parameter missing or non-numeric: " + PARAM_ID + "=" + params.getHttpParam(PARAM_ID)); } final Analysis analysis = analysisDataService.getAnalysisById(id); if(analysis == null) { throw new ActionParamsException("Analysis id didn't match any analysis: " + id); } if(!analysis.isOwnedBy(params.getUser().getUuid())) { throw new ActionDeniedException("Analysis belongs to another user"); } try { analysisDataService.deleteAnalysis(analysis); AuditLog.user(params.getClientIp(), params.getUser()) .withParam("id", id) .deleted(AuditLog.ResourceType.ANALYSIS); ResponseHelper.writeResponse(params, JSONHelper.createJSONObject("result", "success")); } catch (ServiceException ex) { throw new ActionException("Error deleting analysis", ex); } }  void setAnalysisDataService(final AnalysisDbService service); @Override void init(); @Override void handlePost(ActionParameters params); }
DeleteAnalysisDataHandler extends RestActionHandler { @Override public void handlePost(ActionParameters params) throws ActionException { params.requireLoggedInUser(); final long id = ConversionHelper.getLong(params.getHttpParam(PARAM_ID), -1); if(id == -1) { throw new ActionParamsException("Parameter missing or non-numeric: " + PARAM_ID + "=" + params.getHttpParam(PARAM_ID)); } final Analysis analysis = analysisDataService.getAnalysisById(id); if(analysis == null) { throw new ActionParamsException("Analysis id didn't match any analysis: " + id); } if(!analysis.isOwnedBy(params.getUser().getUuid())) { throw new ActionDeniedException("Analysis belongs to another user"); } try { analysisDataService.deleteAnalysis(analysis); AuditLog.user(params.getClientIp(), params.getUser()) .withParam("id", id) .deleted(AuditLog.ResourceType.ANALYSIS); ResponseHelper.writeResponse(params, JSONHelper.createJSONObject("result", "success")); } catch (ServiceException ex) { throw new ActionException("Error deleting analysis", ex); } }  void setAnalysisDataService(final AnalysisDbService service); @Override void init(); @Override void handlePost(ActionParameters params);  }