private void executeAction(
      String action, HttpServletRequest request, ResponsePayload responsePayload)
      throws AWInvalidParameterException, AWNoSuchEntityException, AWInvalidResourceIdException {
    Object payload = ServletUtils.getNoResponsePayload();
    boolean includeMetadata = ServletUtils.getIncludeMetadataParameter(request);
    Integer offset = ServletUtils.getOffsetParameter(request);
    Integer limit = ServletUtils.getLimitParameter(request);

    switch (action) {
      case ServletConstants.REQ_PARAM_SELECT_ACTION_ALL:
        ValidatorUtils.validateRequest(
            ServletUtils.getPagingRequestParams(offset, limit), responsePayload, mRequestValidator);

        if (!responsePayload.hasErrors()) {
          payload = mFactorController.getFactors(offset, limit, responsePayload, includeMetadata);
        }
        break;
      case ServletConstants.REQ_PARAM_SELECT_ACTION_SEL_ID:
        Long factorId =
            ServletUtils.getParseResourceId(ServletUtils.getSelectEntityIdParameter(request));
        payload = mFactorController.getFactor(factorId);
        break;
      case ServletConstants.REQ_PARAM_SELECT_ACTION_LIKE:
        String like = ServletUtils.getSelectLikeParameter(request);
        ValidatorUtils.validateRequest(
            ServletUtils.getPagingRequestParams(offset, limit), responsePayload, mRequestValidator);

        if (!responsePayload.hasErrors()) {
          payload =
              mFactorController.getFactorsLike(
                  like, offset, limit, responsePayload, includeMetadata);
        }
        break;
      default:
        payload = ServletUtils.getNoResponsePayload();
        break;
    }

    responsePayload.setData(payload);
  }
  @Override
  protected void doPost(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {
    String requestFactorJson = request.getParameter("factor");
    FactorClientData clientData =
        (FactorClientData) mRequestConverter.convert(requestFactorJson, FactorClientData.class);
    ResponsePayload responsePayload = new ResponsePayload();

    mFactorController.storeFactor(
        clientData, responsePayload, ServletSecurityUtils.getLoggedUser(request));

    if (responsePayload.getErrors().size() > 0) {
      ServletUtils.setResponseClientError(response);
    } else {
      ServletUtils.setResponseCreated(response);
    }
    ServletUtils.setResponseBody(response, mResponseFormatter.toJson(responsePayload));
  }
  @Override
  protected void doPut(HttpServletRequest request, HttpServletResponse response)
      throws IOException, ServletException {
    String factorHousingJson = ServletUtils.getRequestBody(request);
    FactorClientData clientData =
        (FactorClientData) mRequestConverter.convert(factorHousingJson, FactorClientData.class);
    ResponsePayload responsePayload = new ResponsePayload();
    Long factorId = ServletUtils.getNumberResourceId(request);

    if (!ValidatorUtils.isResourceValid(factorId, HttpMethod.PUT)) {
      ServletUtils.setResponseResourceNotFound(response);
      return;
    }

    mFactorController.updateFactor(
        factorId, clientData, responsePayload, ServletSecurityUtils.getLoggedUser(request));

    if (responsePayload.getErrors().size() > 0) {
      ServletUtils.setResponseClientError(response);
    } else {
      ServletUtils.setResponseOk(response);
    }
    ServletUtils.setResponseBody(response, mResponseFormatter.toJson(responsePayload));
  }