示例#1
0
 /**
  * Find total estimate point of all child of a parent issue
  *
  * @param issue - instance of Issue object
  * @return true if estimate point of parent and all child is equal, false in otherwise
  */
 public boolean findTotalChildEstimatePoint(Issue issue) {
   Issue issueTemp = issueService.findIssueById(issue.getIssueId());
   if (issueTemp != null) {
     String totalPoint = issueService.getTotalPoint(issueTemp);
     float totalPointFloat = Utils.convertPoint(totalPoint);
     float oldPointFloat = Utils.convertPoint(issueTemp.getEstimate());
     if ((totalPointFloat != oldPointFloat) && (issueTemp.getParent() == null)) {
       this.totalEstimatePoint = totalPoint;
       return true;
     }
   }
   return false;
 }
  /**
   * update user story on menu backlog (sprint backlog)
   *
   * @param userStoryId
   * @param name
   * @param value
   */
  public void updatePBLOnBacklogPage() {
    try {
      RequestContext requestContext = RequestContext.getCurrentInstance();
      String id = JSFUtils.getRequestParameter("Id");
      String name = JSFUtils.getRequestParameter("name");
      String description = JSFUtils.getRequestParameter("description");
      String value = JSFUtils.getRequestParameter("value");
      String risk = JSFUtils.getRequestParameter("risk");
      UserStory current = userStoryService.findUserStoryById(Long.parseLong(id.trim()));
      if (current == null) {
        requestContext.addCallbackParam("userStoryId", id);
        requestContext.addCallbackParam("error", EXCEPTION);
        return;
      }

      if (name.equals("")) {
        requestContext.addCallbackParam("userStoryId", id);
        requestContext.addCallbackParam("error", EMPTY_ERROR);
        return;
      }

      if ((userStoryService.checkExistUserStory(
                  Utils.standardizeString(name), current.getProject().getProjectId())
              != null)
          && !(current.getName().equals(Utils.standardizeString(name)))) {
        requestContext.addCallbackParam("userStoryId", id);
        requestContext.addCallbackParam("error", DUPPLICATE_ERROR);
        return;
      }
      if (Integer.parseInt(value) > MAX_BUSSINESS_VALUE || Integer.parseInt(value) < 0) {
        requestContext.addCallbackParam("userStoryId", id);
        requestContext.addCallbackParam("error", VALUE_ERROR);
        return;
      }
      if (Integer.parseInt(risk) > MAX_RISK_VALUE || Integer.parseInt(risk) < 0) {
        requestContext.addCallbackParam("userStoryId", id);
        requestContext.addCallbackParam("error", RISK_ERROR);
        return;
      }
      current.setName(name.replaceAll("\\p{Cntrl}", ""));
      current.setValue(Integer.parseInt(value));
      current.setRisk(Integer.parseInt(risk));
      current.setDescription(description.replaceAll("\\p{Cntrl}", ""));
      if (userStoryService.update(current)) {
        userStoryService.updateAllIssueOfUserStoryHaveTheSameContent(current);
      }
      requestContext.execute("PrimeFaces.ab({source:'',update:'form2'});");
    } catch (Exception e) {

    }
  }
  public void validateUserStoryName(FacesContext context, UIComponent validate, Object value)
      throws ValidatorException {

    if (userStoryService.checkExistUserStory(
            Utils.standardizeString(value.toString()), getProjectId())
        != null) {
      @SuppressWarnings("static-access")
      FacesMessage msg = new FacesMessage(utils.getMessage("myagile.backlog.Exists", null));
      throw new ValidatorException(msg);
    }
    if (utils.isExistTooLongWord(value.toString())) {
      @SuppressWarnings("static-access")
      FacesMessage msg = new FacesMessage(utils.getMessage("myagile.backlog.LongestLength", null));
      throw new ValidatorException(msg);
    }
  }
  public void updateUserStory() {
    RequestContext context = RequestContext.getCurrentInstance();
    if (userStory == null) {
      context.addCallbackParam("userStoryId", userStory.getUserStoryId());
      context.addCallbackParam("error", EXCEPTION);
      return;
    }

    if (userStory.getName().equals("")) {
      context.addCallbackParam("userStoryId", userStory.getUserStoryId());
      context.addCallbackParam("error", EMPTY_ERROR);
      return;
    }

    if (userStoryService.checkExistUserStory(
                Utils.standardizeString(userStory.getName()), getProjectId())
            != null
        && !(userStory.getName().equals(Utils.standardizeString(userStory.getName())))) {
      context.addCallbackParam("userStoryId", userStory.getUserStoryId());
      context.addCallbackParam("error", DUPPLICATE_ERROR);
      return;
    }

    if (userStory.getValue() > MAX_BUSSINESS_VALUE || userStory.getValue() < 0) {
      context.addCallbackParam("userStoryId", userStory.getUserStoryId());
      context.addCallbackParam("error", VALUE_ERROR);
      return;
    }

    userStory.setName(userStory.getName().replaceAll("\\p{Cntrl}", ""));
    userStory.setDescription(userStory.getDescription().replaceAll("\\p{Cntrl}", ""));

    if (userStoryService.update(userStory)) {
      userStoryService.updateAllIssueOfUserStoryHaveTheSameContent(userStory);
      setValueForUsList();
      context.addCallbackParam("error", NO_ERROR);
      context.addCallbackParam("userStoryId", userStory.getUserStoryId());
      JSFUtils.resloveMethodExpression(
          "#{homeBean.setDefaultHistoryList}", Void.class, new Class<?>[0], new Object[0]);
    } else {
      context.addCallbackParam("userStoryId", userStory.getUserStoryId());
      context.addCallbackParam("error", EXCEPTION);
    }
  }
  /** delete user story */
  public void deleteUserStory() {
    try {
      boolean flag = true;
      Member owner = memberService.findProjectOwner(getProjectId());
      UserStory userStoryTemp = userStoryService.findUserStoryById(Long.parseLong(deleteId));
      userStoryService.delete(Long.parseLong(deleteId));
      Member member = utils.getLoggedInMember();

      String mailContent =
          "User story #"
              + userStoryTemp.getUserStoryId()
              + " has been removed by <b>"
              + member.getLastName()
              + " "
              + member.getFirstName()
              + "</b><br/>";
      mailContent += "<hr>";
      mailContent +=
          "<h3>User story #"
              + userStoryTemp.getUserStoryId()
              + ": "
              + userStoryTemp.getName()
              + "</h3>";
      mailContent += "<ul><li>Name: " + userStoryTemp.getName() + "</li>";
      mailContent += "<li>Description: " + userStoryTemp.getDescription() + "</li>";
      mailContent += "<li>Value: " + userStoryTemp.getValue() + "</li>";
      mailContent += "<li>Status: " + userStoryTemp.getStatus() + "</li></ul>";
      mailContent += "<hr>";
      mailContent +=
          "You have received this notification because you have either subscribed to it, or are involved in it.";

      List<Team> teamList = teamService.findTeamsByProjectId(getProjectId());

      for (int i = 0; i < teamList.size(); i++) {
        List<TeamMember> teamMemberList =
            memberService.findTeamMemberListByTeamId(teamList.get(i).getTeamId());
        for (int j = 0; j < teamMemberList.size(); j++) {
          if (teamMemberList.get(j).getMember().getUsername().equals(owner.getUsername())) {
            flag = false;
          }
          mailService.sendMail(
              "Inform about remove user story",
              mailContent,
              teamMemberList.get(j).getMember().getUsername());
        }
      }
      if (flag) {
        mailService.sendMail("Inform about remove user story", mailContent, owner.getUsername());
      }
      this.setValueForUsList();
      JSFUtils.resloveMethodExpression(
          "#{homeBean.setDefaultHistoryList}", Void.class, new Class<?>[0], new Object[0]);
    } catch (Exception e) {

    }
  }
 public void validateUserStoryWhenEdit(FacesContext context, UIInput validate, Object value)
     throws ValidatorException {
   final Long userStoryId = this.userStory.getUserStoryId();
   final UserStory currentUserStory = this.userStoryService.findUserStoryById(userStoryId);
   final UserStory newUserStory =
       this.userStoryService.checkExistUserStory(
           Utils.standardizeString(value.toString()), this.userStory.getProject().getProjectId());
   if ((newUserStory != null)
       && !(currentUserStory.getName().equals(Utils.standardizeString(value.toString())))) {
     @SuppressWarnings("static-access")
     FacesMessage msg = new FacesMessage(utils.getMessage("myagile.backlog.Exists", null));
     throw new ValidatorException(msg);
   }
   if (utils.isExistTooLongWord(value.toString())) {
     @SuppressWarnings("static-access")
     FacesMessage msg = new FacesMessage(utils.getMessage("myagile.backlog.LongestLength", null));
     throw new ValidatorException(msg);
   }
 }
示例#7
0
  /** Upload attachment file for issue */
  public void uploadFile() {
    String filename = JSFUtils.getRequestParameter("filename");
    String diskFileName =
        this.attachmentService.fileNameProcess(FilenameUtils.removeExtension(filename));
    diskFileName = this.attachmentService.replaceFile(filename, diskFileName);
    attachment = new Attachment();
    attachment.setFilename(filename);
    attachment.setDiskFilename(diskFileName);
    attachment.setContainerId(issue.getIssueId());
    attachment.setContainerType(Attachment.ISSUE_ATTACHMENT);
    // add files of Issue in user story for easy to handle.
    if (issue.getUserStory() != null) {
      attachment.setContainerId(issue.getUserStory().getUserStoryId());
      attachment.setContainerType(Attachment.USERSTORY_ATTACHMENT);
    }

    attachment.setTemp(false);
    attachment.setCreatedOn(new Date());
    attachment.setAuthor(utils.getLoggedInMember());
    attachmentService.save(attachment);
    Attachment newAttachment = attachmentService.findAttachmentById(attachment.getAttachmentId());

    if (attachmentNotAddList == null) {
      attachmentNotAddList = new ArrayList<Attachment>();
    }

    if (newAttachment.getContainerId() != null) {
      attachment.setTemp(false);
      attachmentService.moveAttachmentFile(attachment, projectId);
    } else {
      attachment.setTemp(true);
      attachmentNotAddList.add(newAttachment);
    }

    attachmentListByIssue = attachmentService.findAttachmentByIssue(issue);
    if (issue.getUserStory() != null) {
      attachmentListByIssue.addAll(
          attachmentService.findAttachmentByUserStory(issue.getUserStory()));
    }
  }
  /** Create new user story with information entered in view, then save it into database */
  public void addUserStory() {
    RequestContext requestContext = RequestContext.getCurrentInstance();

    if (getProjectId() == 0) {
      requestContext.addCallbackParam("success", false);
      return;
    }
    try {
      UserStory us = new UserStory();

      // Remove Control Characters
      us.setName(Utils.standardizeString(userStory.getName()).replaceAll("\\p{Cntrl}", ""));
      us.setDescription(userStory.getDescription().replaceAll("\\p{Cntrl}", ""));

      us.setStatus(UserStory.StatusType.TODO);
      us.setValue(userStory.getValue());
      us.setProject(projectService.findProjectById(getProjectId()));
      us.setRisk(0);
      us.setPriority(UserStory.PriorityType.NONE);
      if (userStoryService.create(us)) {
        saveAttachmentsToDatabase(us);

        resetUserStoryValue();
        setValueForUsList();
        setCreateMode(false);
        requestContext.addCallbackParam("success", true);
        JSFUtils.resloveMethodExpression(
            "#{homeBean.setDefaultHistoryList}", Void.class, new Class<?>[0], new Object[0]);
      } else {
        throw new Exception();
      }
    } catch (Exception e) {
      requestContext.addCallbackParam("success", false);
      LOGGER.error("HomePage addUserStory: " + e);
    }
  }
示例#9
0
 public Member getLoggedInMember() {
   return utils.getLoggedInMember();
 }