/**
   * This method inserts new TerminationReason record into the database table
   *
   * @param actionRequest
   * @param actionResponse
   * @throws IOException
   * @throws PortletException
   * @throws SystemException
   */
  public void saveTerminationReasons(ActionRequest actionRequest, ActionResponse actionResponse)
      throws IOException, PortletException, SystemException {
    ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY);
    try {
      TerminationReasons terminationReasons =
          TerminationReasonsLocalServiceUtil.createTerminationReasons(
              CounterLocalServiceUtil.increment());

      String id = ParamUtil.getString(actionRequest, "terminationreasonsId");
      String name = ParamUtil.getString(actionRequest, "terminationreasonsName");
      String terminationReason = name.trim();
      if (terminationReason.equals("") || terminationReason == null) {

        System.out.println("Empty value in TerminationReason...");
        SessionMessages.add(actionRequest.getPortletSession(), "termination-form-error");
        actionResponse.setRenderParameter("mvcPath", "/html/terminationreasons/add.jsp");
      } else {

        System.out.println("id == " + id + "Name = " + name);
        if (id == "" || id == null) {

          DynamicQuery dynamicQuery =
              DynamicQueryFactoryUtil.forClass(
                  TerminationReasons.class, PortalClassLoaderUtil.getClassLoader());

          dynamicQuery.add(RestrictionsFactoryUtil.eq("terminationreasonsName", name));
          List<TerminationReasons> list =
              TerminationReasonsLocalServiceUtil.dynamicQuery(dynamicQuery);

          if (list.size() > 0) {
            TerminationReasons terminationReasons2 = list.get(0);

            if (terminationReasons2 != null) {

              SessionMessages.add(
                  actionRequest.getPortletSession(), "termination-form-duplicate-error");
              actionResponse.setRenderParameter("mvcPath", "/html/terminationreasons/add.jsp");
            }
          } else {

            terminationReasons.setTerminationreasonsName(
                ParamUtil.getString(actionRequest, "terminationreasonsName"));
            terminationReasons.setCreateDate(date);
            terminationReasons.setModifiedDate(date);
            terminationReasons.setCompanyId(themeDisplay.getCompanyId());
            terminationReasons.setGroupId(themeDisplay.getCompanyGroupId());
            terminationReasons.setUserId(themeDisplay.getUserId());
            terminationReasons =
                TerminationReasonsLocalServiceUtil.addTerminationReasons(terminationReasons);
          }
        }
      }
    } catch (SystemException e) {

      e.printStackTrace();
    }
  }
  /**
   * This method deletes the TerminationReasons record from database based on TerminationReasons
   * record Id
   *
   * @param resourceRequest
   * @param resourceResponse
   * @throws IOException
   * @throws PortletException
   * @throws SystemException
   * @throws PortalException
   * @throws NumberFormatException
   */
  public void serveResource(ResourceRequest resourceRequest, ResourceResponse resourceResponse)
      throws IOException {
    if (resourceRequest.getResourceID().equals("deleteTerminationReasons")) {
      System.out.println("deleting thes TerminationReasons");

      String[] idsArray = ParamUtil.getParameterValues(resourceRequest, "terminationreasonsIds");
      System.out.println(idsArray.length);

      for (int i = 0; i <= idsArray.length - 1; i++) {

        try {
          try {
            TerminationReasonsLocalServiceUtil.deleteTerminationReasons(
                Long.parseLong(idsArray[i]));
          } catch (PortalException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
          } catch (SystemException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
          }
        } catch (NumberFormatException e) {
        }
      }
    }
  }
  /**
   * This method gets a single TerminationReason Record from database based on given
   * TerminationReason recordId
   *
   * @param actionRequest
   * @param actionResponse
   * @throws IOException
   * @throws PortletException
   * @throws NumberFormatException
   * @throws PortalException
   * @throws SystemException
   */
  public void editTerminationReasons(ActionRequest actionRequest, ActionResponse actionResponse)
      throws IOException, PortletException, NumberFormatException, PortalException,
          SystemException {
    Long terminationreasonsId = ParamUtil.getLong(actionRequest, "terminationreasonsId");
    TerminationReasons terminationReasons =
        TerminationReasonsLocalServiceUtil.getTerminationReasons(terminationreasonsId);

    actionRequest.setAttribute("editTerminationReasons", terminationReasons);
    actionResponse.setRenderParameter("jspPage", "/html/terminationreasons/edit.jsp");
  }
  /**
   * This method updates the TerminationReason record based on TerminationReason recordId
   *
   * @param actionRequest
   * @param actionResponse
   * @throws IOException
   * @throws PortletException
   * @throws SystemException
   */
  public void updateTerminationReasons(ActionRequest actionRequest, ActionResponse actionResponse)
      throws IOException, PortletException, SystemException {
    ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY);

    String id = ParamUtil.getString(actionRequest, "terminationreasonsId");
    String name = ParamUtil.getString(actionRequest, "terminationreasonsName");
    System.out.println("id == " + id);
    TerminationReasons terminationReasons;

    try {
      String terminationReason = name.trim();
      if (terminationReason.equals("") || terminationReason == null) {

        System.out.println("Empty value in TerminationReason...");
        TerminationReasons terminationReasons2 =
            TerminationReasonsLocalServiceUtil.getTerminationReasons(Long.parseLong(id));

        actionRequest.setAttribute("editTerminationReasons", terminationReasons2);

        SessionMessages.add(actionRequest.getPortletSession(), "termination-form-error");
        actionResponse.setRenderParameter("mvcPath", "/html/terminationreasons/edit.jsp");
      } else {

        terminationReasons =
            TerminationReasonsLocalServiceUtil.getTerminationReasons(Long.parseLong(id));
        terminationReasons.setCreateDate(date);
        terminationReasons.setModifiedDate(date);
        terminationReasons.setCompanyId(themeDisplay.getCompanyId());
        terminationReasons.setGroupId(themeDisplay.getCompanyGroupId());
        terminationReasons.setUserId(themeDisplay.getUserId());
        terminationReasons.setTerminationreasonsName(name);
        terminationReasons =
            TerminationReasonsLocalServiceUtil.updateTerminationReasons(terminationReasons);
      }
    } catch (NumberFormatException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    } catch (PortalException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
  }