public Set<Label> getLabels() { if (labels == null) { if (genericValue != null) { labels = labelManager.getLabels(getId()); } else { labels = Collections.emptySet(); } } return labels; }
public Results getPossibleValues(final ApplicationUser user, final String jqlClauseName, final String valuePrefix, final int maxNumResults) { final ApplicationUser searcher = user; final Set<String> suggestions = new TreeSet<String>(); final Collection<String> fieldIds = getSearchHandlerManager().getFieldIds(searcher, jqlClauseName); for (String fieldId : fieldIds) { if(fieldId.equals(SystemSearchConstants.forLabels().getFieldId())) { suggestions.addAll(labelManager.getSuggestedLabels(searcher, null, valuePrefix)); } else { suggestions.addAll(labelManager.getSuggestedLabels(searcher, null, CustomFieldUtils.getCustomFieldId(fieldId), valuePrefix)); } } final List<Result> results = Lists.newArrayListWithCapacity(suggestions.size()); for (String suggestion : suggestions) { if(results.size() == maxNumResults) { break; } results.add(new Result(suggestion)); } return new Results(results); }
@Override public Set<Long> remove(final CustomField field) { return labelManager.removeLabelsForCustomField(field.getIdAsLong()); }
private void setLabels(final CustomField field, final Issue issue, final Set<Label> value) { final Set<String> labelStrings = new LinkedHashSet<String>(); if (value != null) { for (Label label : value) { labelStrings.add(label.getLabel()); } } //validation should have already happened by now labelManager.setLabels(authContext.getUser(), issue.getId(), field.getIdAsLong(), labelStrings, false, false); }
@Override public LabelsResult addLabel(final ApplicationUser user, final AddLabelValidationResult result, final boolean sendNotification) { notNull("result", result); if (!result.isValid()) { throw new IllegalStateException("Cannot add label with invalid validation result!"); } if (result.getCustomFieldId() != null) { labelManager.addLabel(user, result.getIssueId(), result.getCustomFieldId(), result.getLabel().trim(), sendNotification); return getLabels(user, result.getIssueId(), result.getCustomFieldId()); } else { labelManager.addLabel(user, result.getIssueId(), result.getLabel(), sendNotification); return getLabels(user, result.getIssueId()); } }
public void createValue(final Issue issue, final Object value) { String labelString = (String) value; final Set<String> labels = getLabelSet(labelString); //validation should have already happened by now. No need to check the result labelManager.setLabels(authenticationContext.getUser(), issue.getId(), labels, false, false); }
@Override public Set<Label> getValueFromIssue(CustomField field, Issue issue) { final Set<Label> labels = labelManager.getLabels(issue.getId(), field.getIdAsLong()); // We should return null if there are no labels. if (labels.isEmpty()) { return null; } return labels; }
@Override public LabelsResult setLabels(final ApplicationUser user, final SetLabelValidationResult result, final boolean sendNotification, final boolean causeChangeNotification) { notNull("result", result); if (!result.isValid()) { throw new IllegalArgumentException("Cannot set labels with invalid validation result!"); } Set<Label> newLabels; Set<String> cleanLabels = getCleanLabels(result.getLabels()); if (result.getCustomFieldId() != null) { newLabels = labelManager.setLabels(user, result.getIssueId(), result.getCustomFieldId(), cleanLabels, sendNotification, causeChangeNotification); } else { newLabels = labelManager.setLabels(user, result.getIssueId(), cleanLabels, sendNotification, causeChangeNotification); } return new LabelsResult(newLabels, new SimpleErrorCollection()); }
@Override public LabelSuggestionResult getSuggestedLabels(final ApplicationUser user, final Long issueId, final String token) { final ErrorCollection errors = validateForSuggestion(user, token); if(errors.hasAnyErrors()) { return new LabelSuggestionResult(Collections.<String>emptySet(), errors); } return new LabelSuggestionResult(labelManager.getSuggestedLabels(user, issueId, token), new SimpleErrorCollection()); }
public String getEditHtml(final FieldLayoutItem fieldLayoutItem, final OperationContext operationContext, final Action action, final Issue issue, final Map displayParameters) { Map<String, Object> velocityParams = getVelocityParams(fieldLayoutItem, action, issue, displayParameters); final Map fieldValuesHolder = operationContext.getFieldValuesHolder(); if (fieldValuesHolder.containsKey(getId())) { velocityParams.put("labels", fieldValuesHolder.get(getId())); } else if (!(issue == null || issue.getId() == null)) { // Values to edit weren't passed in the action, e.g., bulk edit. velocityParams.put("labels", labelManager.getLabels(issue.getId())); } return renderTemplate("labels-edit.vm", velocityParams); }
public void updateValue(final FieldLayoutItem fieldLayoutItem, final Issue issue, final ModifiedValue modifiedValue, final IssueChangeHolder issueChangeHolder) { final String oldLabelString = (String) modifiedValue.getOldValue(); final String labelString = (String) modifiedValue.getNewValue(); final Set<String> oldLabels = getLabelSet(oldLabelString); final Set<String> labels = getLabelSet(labelString); if (valueChanged(oldLabels, labels)) { final Set<Label> newLabels = labelManager.setLabels(authenticationContext.getUser(), issue.getId(), labels, false, false); issueChangeHolder.addChangeItem(new ChangeItemBean(ChangeItemBean.STATIC_FIELD, IssueFieldConstants.LABELS, null, oldLabelString, null, StringUtils.join(newLabels, SEPARATOR_CHAR))); } }
@Override public LabelSuggestionResult getSuggestedLabels(final ApplicationUser user, final Long issueId, final Long customFieldId, final String token) { notNull("customFieldId", customFieldId); final ErrorCollection errors = validateForSuggestion(user, token); final CustomField field = customFieldManager.getCustomFieldObject(customFieldId); if (field == null) { final I18nHelper i18n = beanFactory.getInstance(user); errors.addErrorMessage(i18n.getText("label.service.error.custom.field.doesnt.exist", customFieldId)); } if(errors.hasAnyErrors()) { return new LabelSuggestionResult(Collections.<String>emptySet(), errors); } return new LabelSuggestionResult(labelManager.getSuggestedLabels(user, issueId, customFieldId, token), new SimpleErrorCollection()); }
@Override public LabelsResult getLabels(final ApplicationUser user, final Long issueId) { notNull("issueId", issueId); final ErrorCollection errorCollection = validateBrowseIssuePermission(user, issueId); if (errorCollection.hasAnyErrors()) { return new LabelsResult(Collections.<Label>emptySet(), errorCollection); } return new LabelsResult(labelManager.getLabels(issueId), new SimpleErrorCollection()); }
@Override public LabelsResult getLabels(final ApplicationUser user, final Long issueId, final Long customFieldId) { notNull("issueId", issueId); notNull("customFieldId", customFieldId); final ErrorCollection errorCollection = validateBrowseIssuePermission(user, issueId); final CustomField field = customFieldManager.getCustomFieldObject(customFieldId); if (field == null) { final I18nHelper i18n = beanFactory.getInstance(user); errorCollection.addErrorMessage(i18n.getText("label.service.error.custom.field.doesnt.exist", customFieldId)); } if (errorCollection.hasAnyErrors()) { return new LabelsResult(Collections.<Label>emptySet(), errorCollection); } return new LabelsResult(labelManager.getLabels(issueId, customFieldId), new SimpleErrorCollection()); }