/** * Takes a set of labels represented as a string and parses them out. * * @param labelsString a String containing labels separated by LabelsField#SEPARATOR_CHAR * @return a Set of Label */ public static Set<Label> buildFromString(String labelsString) { return buildFromString(new StringToLabel(), labelsString); }
/** * Takes a set of labels represented as a string and parses them out. Any invalid labels will be * transformed to that they become valid. * * @param labelsString the string to parse. * @param factory class that will convert a string to the object required * @return the collection of labels contained within the string. */ public static <Y> Set<Y> buildFromString(CreateFromString<Y> factory, final String labelsString) { if (StringUtils.isBlank(labelsString)) { return Collections.emptySet(); } final String[] labelArray = StringUtils.split(labelsString, LabelsField.SEPARATOR_CHAR); final Set<Y> labels = new LinkedHashSet<Y>(); for (String label : labelArray) { final String cleanLabel = LabelParser.getCleanLabel(label); if (cleanLabel != null) { labels.add(factory.create(cleanLabel)); } } return labels; }
private void validateSingleLabel(final String theLabel) { final String label = theLabel.trim(); if (StringUtils.isBlank(label)) { throw new IllegalArgumentException("Labels cannot be blank!"); } if (!LabelParser.isValidLabelName(label)) { throw new IllegalArgumentException("The label '" + label + "' contained spaces which is invalid."); } if (label.length() > LabelParser.MAX_LABEL_LENGTH) { throw new IllegalArgumentException("The label '" + label + "' exceeds the maximum length allowed for labels of " + LabelParser.MAX_LABEL_LENGTH + " characters."); } } }
@Nonnull @Override public Map<String, Object> getVelocityParameters(Issue issue, CustomField field, FieldLayoutItem fieldLayoutItem) { final Map<String, Object> velocityParameters = super.getVelocityParameters(issue, field, fieldLayoutItem); if (issue == null || issue.getId() == null) { velocityParameters.put("canEdit", Boolean.FALSE); } else { final Issue issueFromDb = issueManager.getIssueObject(issue.getId()); velocityParameters.put("canEdit", issueManager.isEditable(issueFromDb, authContext.getUser())); velocityParameters.put("labels", getValueFromIssue(field, issue)); } velocityParameters.put("fieldId", field.getId()); velocityParameters.put("i18n", authContext.getI18nHelper()); velocityParameters.put("field", field); velocityParameters.put("labelUtil", labelUtil); velocityParameters.put("issue", issue); velocityParameters.put("labelParser", new LabelParser()); return velocityParameters; }
public MappedCustomFieldValue getMappedImportValue(final ProjectImportMapper projectImportMapper, final ExternalCustomFieldValue customFieldValue, final FieldConfig fieldConfig) { final String label = customFieldValue.getValue(); // strip out invalid labels if (LabelParser.isValidLabelName(label)) { return new MappedCustomFieldValue(label); } return new MappedCustomFieldValue(null); } }
private Set<Label> convertStringsToLabels(final Collection<String> labelStrings) { final Set<Label> ret = new LinkedHashSet<Label>(); for (String labelString : labelStrings) { if (labelString.length() > LabelParser.MAX_LABEL_LENGTH) { throw new FieldValidationException(authContext.getI18nHelper().getText("label.service.error.label.toolong", labelString)); } ret.addAll(LabelParser.buildFromString(labelString)); } return ret; }
private ErrorCollection validateForSuggestion(final ApplicationUser user, final String token) { final ErrorCollection errors = new SimpleErrorCollection(); //check if the token contains any invalid characters. If it does return this to the client if(StringUtils.isNotEmpty(token) && !LabelParser.isValidLabelName(token)) { errors.addErrorMessage(beanFactory.getInstance(user).getText("label.service.error.label.invalid", token)); } return errors; }
if(!com.atlassian.jira.issue.label.LabelParser.isValidLabelName(labelString))
public MessageSet canMapImportValue(final ProjectImportMapper projectImportMapper, final ExternalCustomFieldValue customFieldValue, final FieldConfig fieldConfig, final I18nHelper i18n) { //add warnings for invalid labels final MessageSet messageSet = new MessageSetImpl(); final String label = customFieldValue.getValue(); if (!LabelParser.isValidLabelName(label)) { messageSet.addWarningMessage(i18n.getText("label.project.import.error", label)); messageSet.addWarningMessageInEnglish("Dropping label '" + label + "' because it contains invalid characters."); } return messageSet; }
public void validateParams(final ApplicationUser user, final SearchContext searchContext, final FieldValuesHolder fieldValuesHolder, final I18nHelper i18nHelper, final ErrorCollection errors) { final String url = SystemSearchConstants.forLabels().getUrlParameter(); final Collection<String> labels = (Collection<String>) fieldValuesHolder.get(url); if (labels != null) { for (String label : labels) { if (!LabelParser.isValidLabelName(label)) { errors.addErrorMessage(i18nHelper.getText("label.service.error.label.invalid", label)); } if (label.length() > LabelParser.MAX_LABEL_LENGTH) { errors.addErrorMessage(i18nHelper.getText("label.service.error.label.toolong", label)); } } } }
public void validateParams(OperationContext operationContext, ErrorCollection errorCollectionToAddTo, I18nHelper i18n, Issue issue, FieldScreenRenderLayoutItem fieldScreenRenderLayoutItem) { final Map fieldValuesHolder = operationContext.getFieldValuesHolder(); @SuppressWarnings("unchecked") final Set<Label> labels = (Set<Label>) fieldValuesHolder.get(getId()); if(labels != null && !labels.isEmpty()) { for (Label theLabel : labels) { final String label = theLabel.getLabel().trim(); if (!LabelParser.isValidLabelName(label)) { errorCollectionToAddTo.addError(IssueFieldConstants.LABELS, i18n.getText("label.service.error.label.invalid", label)); break; } if (label.length() > LabelParser.MAX_LABEL_LENGTH) { errorCollectionToAddTo.addError(IssueFieldConstants.LABELS, i18n.getText("label.service.error.label.toolong", label)); break; } } } else if (fieldScreenRenderLayoutItem.isRequired()) { errorCollectionToAddTo.addError(getId(), i18n.getText("issue.field.required", i18n.getText(getNameKey()))); } }
@Override public Label getSingularObjectFromString(final String string) throws FieldValidationException { if (string == null) { return null; } final int labelLength = StringUtils.length(string.trim()); if (LabelParser.isValidLabelName(string) && labelLength <= LabelParser.MAX_LABEL_LENGTH) { return new Label(null, null, string); } else { if (labelLength > LabelParser.MAX_LABEL_LENGTH) { throw new FieldValidationException(authContext.getI18nHelper().getText("label.service.error.label.toolong", string)); } else { throw new FieldValidationException(authContext.getI18nHelper().getText("label.service.error.label.invalid", string)); } } }
if (!LabelParser.isValidLabelName(label))
if (!LabelParser.isValidLabelName(label))