Esempio n. 1
0
 @ExceptionHandler(IllegalArgumentException.class)
 @ResponseStatus(HttpStatus.BAD_REQUEST)
 @ResponseBody
 public Map<String, String> handleIllegalArgument(IllegalArgumentException e) {
   LOG.warn("Bad Request: " + e.getMessage(), e);
   return Collections.singletonMap("message", e.getMessage());
 }
Esempio n. 2
0
 @ExceptionHandler(IllegalArgumentException.class)
 ResponseEntity<String> sendBadRequestException(IllegalArgumentException ex) {
   LOGGER.warn(
       "Exception was thrown, with cause "
           + ex.getCause()
           + "\nMessage: "
           + ex.getLocalizedMessage(),
       ex);
   return new ResponseEntity<>(ex.getLocalizedMessage(), HttpStatus.BAD_REQUEST);
 }
Esempio n. 3
0
  /**
   * Group search API for the new filter type search and sort criteria
   *
   * @author DiepLe
   * @param searchAndSortCriteria
   * @return
   */
  @RequestMapping(value = "/search", method = RequestMethod.POST)
  @ResponseBody
  public ApiResponse<Object> getGroupSummaryByNewFilterTypeSearchAndSortCriteria(
      @RequestBody SearchAndSortCriteria searchAndSortCriteria) {

    final ApiResponse<Object> apiResponse = new ApiResponse<>();
    List<PermissionGroupSummaryDTO> permissionGroupSummaryDTO = null;
    Long totalRecords = null;
    PermissionGroupSummariesDTO summaries = null;

    try {
      permissionGroupSummaryDTO =
          groupService.getGroupSummaryByNewSearchAndSortCriteria(searchAndSortCriteria);
      totalRecords = groupService.getTotalCountForSearchAndSortCriteria(searchAndSortCriteria);
      summaries = new PermissionGroupSummariesDTO();
      summaries.setGroupList(permissionGroupSummaryDTO);
      summaries.setTotalRecords(totalRecords);
    } catch (IllegalStateException e) {
      e.printStackTrace();
      apiResponse.setStatus("failure");
      apiResponse.setData(null);
      apiResponse.setLevel(Level.ERROR);
      apiResponse.setCode("1069");
      apiResponse.setMessage(
          messageSource.getMessage(
              "1069", new Object[] {e.getMessage()}, LocaleContextHolder.getLocale()));
      return apiResponse;
    } catch (IllegalArgumentException e) {
      e.printStackTrace();
      apiResponse.setStatus("failure");
      apiResponse.setData(null);
      apiResponse.setLevel(Level.ERROR);
      apiResponse.setCode("1070");
      apiResponse.setMessage(
          messageSource.getMessage(
              "1070", new Object[] {e.getMessage()}, LocaleContextHolder.getLocale()));
      return apiResponse;
    } catch (Exception e) {
      throw new LucasRuntimeException(LucasRuntimeException.INTERNAL_ERROR, e);
    }

    apiResponse.setData(summaries);

    return apiResponse;
  }
Esempio n. 4
0
  /** POST -> delete the group details */
  @RequestMapping(value = "/delete", method = RequestMethod.POST)
  @ResponseBody
  public ApiResponse<Object> deleteGroupDetails(
      @RequestBody PermissionGroupsDTO permissionGroupsDTO) {
    LOG.debug("REST request to delete Group Details");
    final ApiResponse<Object> apiResponse = new ApiResponse<Object>();
    String groupName = null;
    boolean response = false;

    // Group name is required for the delete
    if (permissionGroupsDTO == null) {
      LOG.debug("Group Name is required");
      apiResponse.setExplicitDismissal(Boolean.TRUE);
      apiResponse.setLevel(Level.ERROR);
      apiResponse.setCode("1044");
      apiResponse.setStatus("failure");
      apiResponse.setMessage(
          messageSource.getMessage(
              "1044", new Object[] {groupName}, LocaleContextHolder.getLocale()));
      LOG.debug(apiResponse.getMessage());
      return apiResponse;
    }
    groupName = permissionGroupsDTO.getGroupName();
    // call service layer method deleteGroupDetails to delete the group
    try {
      response = groupService.deleteGroupDetails(permissionGroupsDTO);
    } catch (IllegalArgumentException ie) {
      LOG.debug("IllegalArgumentException thrown...", ie.getMessage());
      apiResponse.setExplicitDismissal(Boolean.TRUE);
      apiResponse.setLevel(Level.ERROR);
      apiResponse.setCode("1044");
      apiResponse.setStatus("failure");
      apiResponse.setMessage(
          messageSource.getMessage(
              "1044", new Object[] {groupName}, LocaleContextHolder.getLocale()));
      LOG.debug("return");
      return apiResponse;
    } catch (Exception e) {
      LOG.debug("Exception thrown...", e.getMessage());
      apiResponse.setExplicitDismissal(Boolean.TRUE);
      apiResponse.setLevel(Level.ERROR);
      apiResponse.setCode("1049");
      apiResponse.setStatus("failure");
      apiResponse.setMessage(
          messageSource.getMessage(
              "1049", new Object[] {groupName}, LocaleContextHolder.getLocale()));
      LOG.debug("return");
      return apiResponse;
    }
    if (response == true) {
      apiResponse.setStatus("success");
      apiResponse.setLevel(Level.INFO);
      apiResponse.setCode("1051");
      apiResponse.setMessage(
          messageSource.getMessage(
              "1051", new Object[] {groupName}, LocaleContextHolder.getLocale()));
    } else {
      apiResponse.setExplicitDismissal(Boolean.TRUE);
      apiResponse.setLevel(Level.ERROR);
      apiResponse.setCode("1052");
      apiResponse.setStatus("failure");
      apiResponse.setMessage(
          messageSource.getMessage(
              "1052", new Object[] {groupName}, LocaleContextHolder.getLocale()));
      LOG.debug("return");
    }
    LOG.debug("return");
    return apiResponse;
  }
Esempio n. 5
0
  /** POST -> get the group details for saving */
  @RequestMapping(value = "/{groupName}/save", method = RequestMethod.POST)
  @ResponseBody
  public ApiResponse<Object> saveGroupDetails(
      @PathVariable String groupName, @RequestBody PermissionGroupsDTO permissionGroupsDTO) {
    LOG.debug("REST request to save Group Details");
    final ApiResponse<Object> apiResponse = new ApiResponse<Object>();
    boolean response = false;

    // groupName is required
    if (groupName == null || groupName.length() <= 0) {
      LOG.debug("Group Name is required");
      apiResponse.setExplicitDismissal(Boolean.TRUE);
      apiResponse.setLevel(Level.ERROR);
      apiResponse.setCode("1045");
      apiResponse.setStatus("failure");
      apiResponse.setMessage(
          messageSource.getMessage(
              "1045", new Object[] {groupName}, LocaleContextHolder.getLocale()));
      LOG.debug(apiResponse.getMessage());
      return apiResponse;
    }
    // Group details is required for the save
    if (permissionGroupsDTO == null) {
      LOG.debug("Group Details is required");
      apiResponse.setExplicitDismissal(Boolean.TRUE);
      apiResponse.setLevel(Level.ERROR);
      apiResponse.setCode("1050");
      apiResponse.setStatus("failure");
      apiResponse.setMessage(
          messageSource.getMessage(
              "1050", new Object[] {groupName}, LocaleContextHolder.getLocale()));
      LOG.debug(apiResponse.getMessage());
      return apiResponse;
    }
    // call service layer method saveGroupDetails to save the group details
    try {
      response = groupService.saveGroupDetails(permissionGroupsDTO);
      LOG.debug("Response ", response);
      if (response == true) {
        apiResponse.setExplicitDismissal(Boolean.FALSE);
        apiResponse.setLevel(Level.INFO);
        apiResponse.setCode("1043");
        apiResponse.setStatus("success");
        apiResponse.setMessage(
            messageSource.getMessage(
                "1043", new Object[] {groupName}, LocaleContextHolder.getLocale()));
      } else {
        LOG.debug("An error has occurred");
        apiResponse.setExplicitDismissal(Boolean.TRUE);
        apiResponse.setLevel(Level.ERROR);
        apiResponse.setCode("1049");
        apiResponse.setStatus("failure");
        apiResponse.setMessage(
            messageSource.getMessage(
                "1049", new Object[] {groupName}, LocaleContextHolder.getLocale()));
      }
    } catch (IllegalArgumentException ie) {
      LOG.debug("IllegalArgumentException thrown...", ie.getMessage());
      String errorMessage = ie.getMessage();
      String code = null;
      if (errorMessage.equals("Group Name is required")) {
        code = "1044";
      } else if (errorMessage.equals("Assigned Permissions list is required")) {
        code = "1045";
      } else if (errorMessage.equals("Unknown permission")) {
        code = "1046";
      } else if (errorMessage.equals("Enrolled Users list is required")) {
        code = "1048";
      } else if (errorMessage.equals("Unknown user")) {
        code = "1047";
      }
      apiResponse.setExplicitDismissal(Boolean.TRUE);
      apiResponse.setLevel(Level.ERROR);
      apiResponse.setCode(code);
      apiResponse.setStatus("failure");
      apiResponse.setMessage(
          messageSource.getMessage(
              code, new Object[] {groupName}, LocaleContextHolder.getLocale()));
    } catch (Exception e) {
      LOG.debug("Exception thrown...", e.getMessage());
      apiResponse.setExplicitDismissal(Boolean.TRUE);
      apiResponse.setLevel(Level.ERROR);
      apiResponse.setCode("1049");
      apiResponse.setStatus("failure");
      apiResponse.setMessage(
          messageSource.getMessage(
              "1049", new Object[] {groupName}, LocaleContextHolder.getLocale()));
    }

    LOG.debug("return");
    return apiResponse;
  }