Search in sources :

Example 1 with RequirementType

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);
}
Also used : RequirementType(jetbrains.buildServer.requirements.RequirementType) BadRequestException(jetbrains.buildServer.server.rest.errors.BadRequestException) Contract(org.jetbrains.annotations.Contract) Nullable(org.jetbrains.annotations.Nullable)

Example 2 with RequirementType

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);
}
Also used : RequirementType(jetbrains.buildServer.requirements.RequirementType) BadRequestException(jetbrains.buildServer.server.rest.errors.BadRequestException) Contract(org.jetbrains.annotations.Contract) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

RequirementType (jetbrains.buildServer.requirements.RequirementType)2 BadRequestException (jetbrains.buildServer.server.rest.errors.BadRequestException)2 Contract (org.jetbrains.annotations.Contract)2 Nullable (org.jetbrains.annotations.Nullable)2