@Override public Label addLabel(final ApplicationUser remoteUser, final Long issueId, final String label, final boolean sendNotification) { notNull("issueId", issueId); notNull("label", label); validateSingleLabel(label); final Issue issue = findIssue(issueId); return addIfNotContains(issue, label, null, remoteUser, sendNotification); }
private boolean differentLabels(final Set<String> labels, final Set<Label> existingLabels) { if (labels.size() != existingLabels.size()) { return true; } return !labels.containsAll(asSortedStringLabels(existingLabels)); }
private void issueUpdated(Set<Label> newLabels, Set<Label> oldLabels, Issue originalIssue, final Long customFieldId, ApplicationUser remoteUser, boolean sendNotification) { IssueUpdateBean updateBean = createIssueUpdateBean(remoteUser, originalIssue, sendNotification); updateBean.setChangeItems(Lists.newArrayList(createLabelsChangeItem(newLabels, oldLabels, customFieldId))); doUpdate(updateBean); }
@Override public Set<Label> setLabels(final ApplicationUser remoteUser, final Long issueId, final Set<String> labels, final boolean sendNotification, final boolean causesChangeNotification) { notNull("issueId", issueId); notNull("labels", labels); validateLabels(labels); final Issue issue = findIssue(issueId); return setIfNotEqual(issue, labels, null, remoteUser, sendNotification, causesChangeNotification); }
private Label addIfNotContains(final Issue issue, final String label, Long customFieldId, final ApplicationUser remoteUser, final boolean sendNotification) { Set<Label> oldLabels = labelStore.getLabels(issue.getId(), customFieldId); if (containsLabel(label, oldLabels)) { return getLabel(label, oldLabels); } else { final Label newLabel = labelStore.addLabel(issue.getId(), customFieldId, label); issueUpdated(newLabel, oldLabels, issue, customFieldId, remoteUser, sendNotification); return newLabel; } }
private Set<Label> setIfNotEqual(final Issue issue, final Set<String> labels, final Long customFieldId, final ApplicationUser remoteUser, final boolean sendNotification,final boolean causesChangeNotification) { Set<Label> oldLabels = labelStore.getLabels(issue.getId(), customFieldId); if (differentLabels(labels, oldLabels)) { final Set<Label> newLabels = labelStore.setLabels(issue.getId(), customFieldId, labels); // JRADEV-2126 Only create a History entry if you are updating labels after creating the issue // note that if causesChangeNotification is false then the labels manager does not fire any // update events at all, and the index is not reindexed if (causesChangeNotification) { issueUpdated(newLabels, oldLabels, issue, customFieldId, remoteUser, sendNotification); } return newLabels; } else { return oldLabels; } }
private String resolveFieldName(Long customFieldId) { if (customFieldId == null) { return IssueFieldConstants.LABELS; } else { return getFromCustomField(customFieldId); } }
private String getFromCustomField(final Long customFieldId) { CustomField field = getFieldManager().getCustomFieldObject(customFieldId); if (field == null) { throw new IllegalArgumentException("No custom field with ID [" + customFieldId + "] found"); } return field.getName(); }
@Override public Set<Label> setLabels(final ApplicationUser remoteUser, final Long issueId, final Long customFieldId, final Set<String> labels, final boolean sendNotification, final boolean causesChangeNotification) { notNull("issueId", issueId); notNull("customFieldId", customFieldId); notNull("labels", labels); validateLabels(labels); final Issue issue = findIssue(issueId); return setIfNotEqual(issue, labels, customFieldId, remoteUser, sendNotification, causesChangeNotification); }
@Override public Label addLabel(final ApplicationUser remoteUser, final Long issueId, final Long customFieldId, final String label, final boolean sendNotification) { notNull("issueId", issueId); notNull("label", label); notNull("customFieldId", customFieldId); validateSingleLabel(label); return addIfNotContains(findIssue(issueId), label, customFieldId, remoteUser, sendNotification); }
private String toString(final Set<Label> labels) { if (labels.isEmpty()) { return ""; } StringBuilder accumulator = new StringBuilder(labels.size() * 8); for (String label : asSortedStringLabels(labels)) { accumulator.append(label).append(" "); } return accumulator.deleteCharAt(accumulator.length()-1).toString(); }