Ejemplo n.º 1
0
  /**
   * 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();
    }
  }
Ejemplo n.º 2
0
  /**
   * 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();
    }
  }