public String addGroup() throws Exception {
    if (isUserNotMaker()) {
      writeAuditLog("Cannot access add new group page. User is not a maker account.", form);

      return RESTRICTED_ERROR;
    }

    setFormStatus(FORM_ADD);
    setFormAction("add-group-process");

    this.functionList = functionService.findAll();
    this.divisionList = divisionService.findAll();

    writeAuditLog("Viewed add group form page.", form);

    return INPUT_ADD;
  }
  public String editGroup() throws Exception {
    if (isUserNotMaker()) {
      writeAuditLog("Cannot access edit group page. User is not a maker account.", form);

      return RESTRICTED_ERROR;
    }

    setFormStatus(FORM_EDIT);
    setFormAction("edit-group-process");

    this.group = groupService.findGroup(getId());
    this.functionList = functionService.findAll();
    this.assignedFunction = groupService.getFunctionGroupById(getId());
    this.divisionList = divisionService.findAll();
    this.categoryList = categoryService.findCategoriesByGroup(getId());

    logGroup(getGroup(), "Viewed edit group of");

    return INPUT_EDIT;
  }
  // BEGIN VALIDATION
  public void validate() {
    if (getValidate() != null) {
      boolean hasErrors = false;

      group.setCd(EscapeUtils.escape(group.getCd()));
      group.setName(EscapeUtils.escape(group.getName()));
      group.setDescription(EscapeUtils.escape(group.getDescription()));

      try {
        if (getValidate().equals(FORM_ADD)) {
          if (group.getCd().isEmpty()) {
            this.addFieldError("group.cd", Messages.REQUIRED);
            hasErrors = true;
          } else if (group.getCd().length() < 2) {
            this.addFieldError("group.cd", Messages.TOO_SHORT);
            hasErrors = true;
          } else if (group.getCd().length() > 2) {
            if (groupService.findGroupByCode(group.getCd()) != null) {
              this.addFieldError("group.cd", Messages.CODE_EXISTS);
              hasErrors = true;
            }
          }
        }

        if (group.getName().isEmpty()) {
          this.addFieldError("group.name", Messages.REQUIRED);
          hasErrors = true;
        } else if (group.getName().length() < 2) {
          this.addFieldError("group.name", Messages.TOO_SHORT);
          hasErrors = true;
        }

        if (group.getDescription().isEmpty()) {
          this.addFieldError("group.description", Messages.REQUIRED);
          hasErrors = true;
        } else if (group.getDescription().length() < 3) {
          this.addFieldError("group.description", Messages.TOO_SHORT);
          hasErrors = true;
        }

        if (function == null) {
          this.addFieldError("function", Messages.NO_FUNCTION);
          hasErrors = true;
        }

        if (getDivision() != null) {
          if (getDivision().equals("")) {
            this.addFieldError("division", Messages.NO_DIVISION);
            hasErrors = true;
          }
        }

        this.functionList = functionService.findAll();
        this.divisionList = divisionService.findAll();

        if (getValidate().equals("add")) {
          setFormStatus(FORM_ADD);
          setFormAction("add-group-process");
        } else if (getValidate().equals("edit")) {
          setFormStatus(FORM_EDIT);
          setFormAction("edit-group-process");

          this.assignedFunction = groupService.getFunctionGroupById(group.getId());
        }

        if (hasErrors) {
          writeAuditLog(
              "ERROR: Group form contained empty, invalid, or duplicate field values upon submission.",
              form);
        }
      } catch (Exception e) {
        log.error("Exception occured", e);
      }
    }
  }