Ejemplo n.º 1
0
  public Issue plan(String issueKey, @Nullable String actionPlanKey) {
    verifyLoggedIn();

    DbSession session = dbClient.openSession(false);
    try {
      ActionPlan actionPlan = null;
      if (!Strings.isNullOrEmpty(actionPlanKey)) {
        actionPlan = actionPlanService.findByKey(actionPlanKey, userSession);
        if (actionPlan == null) {
          throw new BadRequestException("Unknown action plan: " + actionPlanKey);
        }
      }
      DefaultIssue issue = getByKeyForUpdate(session, issueKey).toDefaultIssue();

      IssueChangeContext context =
          IssueChangeContext.createUser(new Date(), userSession.getLogin());
      if (issueUpdater.plan(issue, actionPlan, context)) {
        saveIssue(session, issue, context, null);
      }
      return issue;

    } finally {
      session.close();
    }
  }
Ejemplo n.º 2
0
 public void setCloseDate(DefaultIssue issue, @Nullable Date d, IssueChangeContext context) {
   Date dateWithoutMilliseconds = d == null ? null : DateUtils.truncate(d, Calendar.SECOND);
   if (!Objects.equals(dateWithoutMilliseconds, issue.closeDate())) {
     issue.setCloseDate(d);
     issue.setUpdateDate(context.date());
     issue.setChanged(true);
   }
 }
Ejemplo n.º 3
0
 public boolean setMessage(DefaultIssue issue, @Nullable String s, IssueChangeContext context) {
   if (!Objects.equals(s, issue.message())) {
     issue.setMessage(s);
     issue.setUpdateDate(context.date());
     issue.setChanged(true);
     return true;
   }
   return false;
 }
Ejemplo n.º 4
0
 public boolean setType(DefaultIssue issue, RuleType type, IssueChangeContext context) {
   if (!Objects.equals(type, issue.type())) {
     issue.setFieldChange(context, TYPE, issue.type(), type);
     issue.setType(type);
     issue.setUpdateDate(context.date());
     issue.setChanged(true);
     return true;
   }
   return false;
 }
Ejemplo n.º 5
0
 public boolean setIssueMoved(
     DefaultIssue issue, String newComponentUuid, IssueChangeContext context) {
   if (!Objects.equals(newComponentUuid, issue.componentUuid())) {
     issue.setFieldChange(context, FILE, issue.componentUuid(), newComponentUuid);
     issue.setComponentUuid(newComponentUuid);
     issue.setUpdateDate(context.date());
     issue.setChanged(true);
     return true;
   }
   return false;
 }
Ejemplo n.º 6
0
 public boolean setGap(DefaultIssue issue, @Nullable Double d, IssueChangeContext context) {
   if (!Objects.equals(d, issue.gap())) {
     issue.setGap(d);
     issue.setUpdateDate(context.date());
     issue.setChanged(true);
     // Do not send notifications to prevent spam when installing the SQALE plugin,
     // and do not complete the changelog (for the moment)
     return true;
   }
   return false;
 }
Ejemplo n.º 7
0
 public boolean setStatus(DefaultIssue issue, String status, IssueChangeContext context) {
   if (!Objects.equals(status, issue.status())) {
     issue.setFieldChange(context, STATUS, issue.status(), status);
     issue.setStatus(status);
     issue.setUpdateDate(context.date());
     issue.setChanged(true);
     issue.setSendNotifications(true);
     return true;
   }
   return false;
 }
Ejemplo n.º 8
0
 public boolean setAttribute(
     DefaultIssue issue, String key, @Nullable String value, IssueChangeContext context) {
   String oldValue = issue.attribute(key);
   if (!Objects.equals(oldValue, value)) {
     issue.setFieldChange(context, key, oldValue, value);
     issue.setAttribute(key, value);
     issue.setUpdateDate(context.date());
     issue.setChanged(true);
     return true;
   }
   return false;
 }
Ejemplo n.º 9
0
 public boolean setAuthorLogin(
     DefaultIssue issue, @Nullable String authorLogin, IssueChangeContext context) {
   if (!Objects.equals(authorLogin, issue.authorLogin())) {
     issue.setFieldChange(context, AUTHOR, issue.authorLogin(), authorLogin);
     issue.setAuthorLogin(authorLogin);
     issue.setUpdateDate(context.date());
     issue.setChanged(true);
     // do not send notifications to prevent spam when installing the developer cockpit plugin
     return true;
   }
   return false;
 }
Ejemplo n.º 10
0
 public boolean setResolution(
     DefaultIssue issue, @Nullable String resolution, IssueChangeContext context) {
   if (!Objects.equals(resolution, issue.resolution())) {
     issue.setFieldChange(context, RESOLUTION, issue.resolution(), resolution);
     issue.setResolution(resolution);
     issue.setUpdateDate(context.date());
     issue.setChanged(true);
     issue.setSendNotifications(true);
     return true;
   }
   return false;
 }
Ejemplo n.º 11
0
 public boolean setSeverity(DefaultIssue issue, String severity, IssueChangeContext context) {
   if (issue.manualSeverity()) {
     throw new IllegalStateException("Severity can't be changed");
   }
   if (!Objects.equals(severity, issue.severity())) {
     issue.setFieldChange(context, SEVERITY, issue.severity(), severity);
     issue.setSeverity(severity);
     issue.setUpdateDate(context.date());
     issue.setChanged(true);
     return true;
   }
   return false;
 }
Ejemplo n.º 12
0
 public boolean setManualSeverity(
     DefaultIssue issue, String severity, IssueChangeContext context) {
   if (!issue.manualSeverity() || !Objects.equals(severity, issue.severity())) {
     issue.setFieldChange(context, SEVERITY, issue.severity(), severity);
     issue.setSeverity(severity);
     issue.setManualSeverity(true);
     issue.setUpdateDate(context.date());
     issue.setChanged(true);
     issue.setSendNotifications(true);
     return true;
   }
   return false;
 }
Ejemplo n.º 13
0
 /** Used to set the author when it was null */
 public boolean setNewAuthor(
     DefaultIssue issue, @Nullable String newAuthorLogin, IssueChangeContext context) {
   if (isNullOrEmpty(newAuthorLogin)) {
     return false;
   }
   checkState(
       issue.authorLogin() == null,
       "It's not possible to update the author with this method, please use setAuthorLogin()");
   issue.setFieldChange(context, AUTHOR, null, newAuthorLogin);
   issue.setAuthorLogin(newAuthorLogin);
   issue.setUpdateDate(context.date());
   issue.setChanged(true);
   // do not send notifications to prevent spam when installing the developer cockpit plugin
   return true;
 }
Ejemplo n.º 14
0
 /** Used to set the assignee when it was null */
 public boolean setNewAssignee(
     DefaultIssue issue, @Nullable String newAssignee, IssueChangeContext context) {
   if (newAssignee == null) {
     return false;
   }
   checkState(
       issue.assignee() == null,
       "It's not possible to update the assignee with this method, please use assign()");
   issue.setFieldChange(context, ASSIGNEE, UNUSED, newAssignee);
   issue.setAssignee(newAssignee);
   issue.setUpdateDate(context.date());
   issue.setChanged(true);
   issue.setSendNotifications(true);
   return true;
 }
Ejemplo n.º 15
0
 public boolean assign(DefaultIssue issue, @Nullable User user, IssueChangeContext context) {
   String sanitizedAssignee = null;
   if (user != null) {
     sanitizedAssignee = StringUtils.defaultIfBlank(user.login(), null);
   }
   if (!Objects.equals(sanitizedAssignee, issue.assignee())) {
     String newAssigneeName = user != null ? user.name() : null;
     issue.setFieldChange(context, ASSIGNEE, UNUSED, newAssigneeName);
     issue.setAssignee(sanitizedAssignee);
     issue.setUpdateDate(context.date());
     issue.setChanged(true);
     issue.setSendNotifications(true);
     return true;
   }
   return false;
 }
Ejemplo n.º 16
0
 public boolean setEffort(
     DefaultIssue issue, @Nullable Duration value, IssueChangeContext context) {
   Duration oldValue = issue.effort();
   if (!Objects.equals(value, oldValue)) {
     issue.setEffort(value != null ? value : null);
     issue.setFieldChange(
         context,
         TECHNICAL_DEBT,
         oldValue != null ? oldValue.toMinutes() : null,
         value != null ? value.toMinutes() : null);
     issue.setUpdateDate(context.date());
     issue.setChanged(true);
     return true;
   }
   return false;
 }
Ejemplo n.º 17
0
  public Collection<String> setTags(String issueKey, Collection<String> tags) {
    verifyLoggedIn();

    DbSession session = dbClient.openSession(false);
    try {
      DefaultIssue issue = getByKeyForUpdate(session, issueKey).toDefaultIssue();
      IssueChangeContext context =
          IssueChangeContext.createUser(new Date(), userSession.getLogin());
      if (issueUpdater.setTags(issue, tags, context)) {
        saveIssue(session, issue, context, null);
      }
      return issue.tags();

    } finally {
      session.close();
    }
  }
Ejemplo n.º 18
0
 void saveIssue(
     DbSession session, DefaultIssue issue, IssueChangeContext context, @Nullable String comment) {
   String projectKey = issue.projectKey();
   if (projectKey == null) {
     throw new IllegalStateException(String.format("Issue '%s' has no project key", issue.key()));
   }
   issueStorage.save(session, issue);
   Rule rule = getNullableRuleByKey(issue.ruleKey());
   ComponentDto project = dbClient.componentDao().selectOrFailByKey(session, projectKey);
   notificationService.scheduleForSending(
       new IssueChangeNotification()
           .setIssue(issue)
           .setChangeAuthorLogin(context.login())
           .setRuleName(rule != null ? rule.getName() : null)
           .setProject(project.getKey(), project.name())
           .setComponent(dbClient.componentDao().selectOrFailByKey(session, issue.componentKey()))
           .setComment(comment));
 }
Ejemplo n.º 19
0
  public Issue setSeverity(String issueKey, String severity) {
    verifyLoggedIn();

    DbSession session = dbClient.openSession(false);
    try {
      DefaultIssue issue = getByKeyForUpdate(session, issueKey).toDefaultIssue();
      userSession.checkComponentPermission(UserRole.ISSUE_ADMIN, issue.projectKey());

      IssueChangeContext context =
          IssueChangeContext.createUser(new Date(), userSession.getLogin());
      if (issueUpdater.setManualSeverity(issue, severity, context)) {
        saveIssue(session, issue, context, null);
      }
      return issue;
    } finally {
      session.close();
    }
  }
Ejemplo n.º 20
0
  public Issue doTransition(String issueKey, String transitionKey) {
    verifyLoggedIn();

    DbSession session = dbClient.openSession(false);
    try {
      DefaultIssue defaultIssue = getByKeyForUpdate(session, issueKey).toDefaultIssue();
      IssueChangeContext context =
          IssueChangeContext.createUser(new Date(), userSession.getLogin());
      checkTransitionPermission(transitionKey, userSession, defaultIssue);
      if (workflow.doTransition(defaultIssue, transitionKey, context)) {
        saveIssue(session, defaultIssue, context, null);
      }
      return defaultIssue;

    } finally {
      session.close();
    }
  }
Ejemplo n.º 21
0
  public boolean setTags(DefaultIssue issue, Collection<String> tags, IssueChangeContext context) {
    Set<String> newTags =
        Sets.newHashSet(
            Collections2.transform(
                Collections2.filter(
                    tags,
                    new Predicate<String>() {
                      @Override
                      public boolean apply(@Nullable String tag) {
                        return tag != null && !tag.isEmpty();
                      }
                    }),
                new Function<String, String>() {
                  @Override
                  public String apply(String tag) {
                    String lowerCaseTag = tag.toLowerCase(Locale.ENGLISH);
                    RuleTagFormat.validate(lowerCaseTag);
                    return lowerCaseTag;
                  }
                }));

    Set<String> oldTags = Sets.newHashSet(issue.tags());

    if (!oldTags.equals(newTags)) {
      issue.setFieldChange(
          context,
          TAGS,
          oldTags.isEmpty() ? null : CHANGELOG_TAG_JOINER.join(oldTags),
          newTags.isEmpty() ? null : CHANGELOG_TAG_JOINER.join(newTags));
      issue.setTags(newTags);
      issue.setUpdateDate(context.date());
      issue.setChanged(true);
      issue.setSendNotifications(true);
      return true;
    }
    return false;
  }
Ejemplo n.º 22
0
  public Issue assign(String issueKey, @Nullable String assignee) {
    verifyLoggedIn();

    DbSession session = dbClient.openSession(false);
    try {
      DefaultIssue issue = getByKeyForUpdate(session, issueKey).toDefaultIssue();
      User user = null;
      if (!Strings.isNullOrEmpty(assignee)) {
        user = userFinder.findByLogin(assignee);
        if (user == null) {
          throw new BadRequestException("Unknown user: " + assignee);
        }
      }
      IssueChangeContext context =
          IssueChangeContext.createUser(new Date(), userSession.getLogin());
      if (issueUpdater.assign(issue, user, context)) {
        saveIssue(session, issue, context, null);
      }
      return issue;

    } finally {
      session.close();
    }
  }
Ejemplo n.º 23
0
 public void addComment(DefaultIssue issue, String text, IssueChangeContext context) {
   issue.addComment(DefaultIssueComment.create(issue.key(), context.login(), text));
   issue.setUpdateDate(context.date());
   issue.setChanged(true);
 }