use of jetbrains.buildServer.requirements.RequirementType in project teamcity-rest by JetBrains.
the class ParameterCondition method createValueCondition.
@Nullable
@Contract("!null -> !null; null -> null")
private static ValueCondition createValueCondition(@Nullable final String propertyConditionLocator, boolean surroundingBracesHaveSpecialMeaning) {
if (propertyConditionLocator == null) {
return null;
}
final Locator locator = new Locator(propertyConditionLocator, new Locator.Metadata(false, surroundingBracesHaveSpecialMeaning), VALUE, TYPE, IGNORE_CASE, Locator.LOCATOR_SINGLE_VALUE_UNUSED_NAME);
final String value = locator.isSingleValue() ? locator.getSingleValue() : locator.getSingleDimensionValue(VALUE);
RequirementType requirement;
final String type = locator.getSingleDimensionValue(TYPE);
if (type != null) {
requirement = RequirementType.findByName(type);
if (requirement == null || RequirementType.EXISTS.equals(requirement) || RequirementType.NOT_EXISTS.equals(requirement)) {
List<String> supportedSingleValueRequirementTypes = new ArrayList<>(getAllRequirementTypes());
supportedSingleValueRequirementTypes.remove(RequirementType.EXISTS.getName());
supportedSingleValueRequirementTypes.remove(RequirementType.NOT_EXISTS.getName());
throw new BadRequestException("Unsupported value '" + type + "' for '" + TYPE + "' for single value condition. Supported are: " + supportedSingleValueRequirementTypes);
}
} else {
if (locator.isSingleValue()) {
requirement = RequirementType.EQUALS;
} else {
requirement = getDefaultMatchCondition(locator);
}
}
Boolean ignoreCase = locator.getSingleDimensionValueAsBoolean(IGNORE_CASE);
locator.checkLocatorFullyProcessed();
return new ValueCondition(requirement, value, ignoreCase);
}
use of jetbrains.buildServer.requirements.RequirementType in project teamcity-rest by JetBrains.
the class ParameterCondition method create.
@Nullable
@Contract("!null -> !null; null -> null")
public static ParameterCondition create(@Nullable final Locator locator) {
if (locator == null) {
return null;
}
locator.addSupportedDimensions(NAME, VALUE, TYPE, IGNORE_CASE, NAME_MATCH_CHECK, INHERITED, Locator.LOCATOR_SINGLE_VALUE_UNUSED_NAME);
locator.processHelpRequest();
final String value = locator.getSingleDimensionValue(VALUE);
RequirementType requirement;
final String type = locator.getSingleDimensionValue(TYPE);
if (type != null) {
requirement = RequirementType.findByName(type);
if (requirement == null) {
throw new BadRequestException("Unsupported value '" + type + "' for '" + TYPE + "'. Supported are: " + getAllRequirementTypes());
}
} else {
requirement = value != null ? getDefaultMatchCondition(locator) : RequirementType.EXISTS;
}
ValueCondition nameCondition;
final String name = locator.isSingleValue() ? locator.getSingleValue() : locator.getSingleDimensionValue(NAME);
if (name == null) {
nameCondition = new ValueCondition(RequirementType.ANY, name, null);
} else {
try {
nameCondition = createValueCondition(name);
} catch (BadRequestException e) {
throw new BadRequestException("Wrong name condition: " + e.getMessage(), e);
}
}
final String nameRequirementCheck = locator.getSingleDimensionValue(NAME_MATCH_CHECK);
final boolean nameCheckShouldMatchAll;
if (StringUtil.isEmpty(nameRequirementCheck) || "any".equals(nameRequirementCheck) || "or".equals(nameRequirementCheck)) {
nameCheckShouldMatchAll = false;
} else if ("all".equals(nameRequirementCheck) || "and".equals(nameRequirementCheck)) {
nameCheckShouldMatchAll = true;
} else {
throw new BadRequestException("Unsupported value for '" + NAME_MATCH_CHECK + "'. Supported are: " + "any, all");
}
Boolean ignoreCase = locator.getSingleDimensionValueAsBoolean(IGNORE_CASE);
Boolean inherited = locator.getSingleDimensionValueAsBoolean(INHERITED);
return new ParameterCondition(nameCondition, new ValueCondition(requirement, value, ignoreCase), nameCheckShouldMatchAll, inherited);
}
Aggregations