Search in sources :

Example 1 with State

use of io.jenkins.blueocean.rest.model.BlueTestResult.State in project blueocean-plugin by jenkinsci.

the class BlueTestResultContainerImpl method filterByState.

// for testing purpose
public static Predicate<BlueTestResult> filterByState(String state) {
    String[] stateAtoms = StringUtils.split(state, ',');
    Predicate<BlueTestResult> predicate = blueTestResult -> false;
    if (stateAtoms == null || stateAtoms.length == 0) {
        throw new BadRequestException("state not provided");
    }
    for (String stateString : stateAtoms) {
        Predicate<BlueTestResult> statePredicate;
        try {
            if (stateString.startsWith("!")) {
                StatePredicate tmp = new StatePredicate(State.valueOf(stateString.toUpperCase().substring(1)));
                statePredicate = blueTestResult -> !tmp.test(blueTestResult);
            } else {
                statePredicate = new StatePredicate(State.valueOf(stateString.toUpperCase()));
            }
        } catch (IllegalArgumentException e) {
            throw new BadRequestException("bad state " + state, e);
        }
        predicate = predicate.or(statePredicate);
    }
    return predicate;
}
Also used : StringUtils(org.apache.commons.lang.StringUtils) Iterator(java.util.Iterator) StringUtils.isEmpty(org.apache.commons.lang.StringUtils.isEmpty) Predicate(java.util.function.Predicate) StaplerRequest(org.kohsuke.stapler.StaplerRequest) Reachable(io.jenkins.blueocean.rest.Reachable) IterableUtils(io.jenkins.blueocean.commons.IterableUtils) NotFoundException(io.jenkins.blueocean.commons.ServiceException.NotFoundException) Run(hudson.model.Run) BadRequestException(io.jenkins.blueocean.commons.ServiceException.BadRequestException) Status(io.jenkins.blueocean.rest.model.BlueTestResult.Status) BlueTestResult(io.jenkins.blueocean.rest.model.BlueTestResult) BlueTestResultFactory(io.jenkins.blueocean.rest.factory.BlueTestResultFactory) Stapler(org.kohsuke.stapler.Stapler) State(io.jenkins.blueocean.rest.model.BlueTestResult.State) BlueTestResultContainer(io.jenkins.blueocean.rest.model.BlueTestResultContainer) NonNull(edu.umd.cs.findbugs.annotations.NonNull) Nullable(edu.umd.cs.findbugs.annotations.Nullable) StreamSupport(java.util.stream.StreamSupport) Result(io.jenkins.blueocean.rest.factory.BlueTestResultFactory.Result) BadRequestException(io.jenkins.blueocean.commons.ServiceException.BadRequestException) BlueTestResult(io.jenkins.blueocean.rest.model.BlueTestResult)

Example 2 with State

use of io.jenkins.blueocean.rest.model.BlueTestResult.State in project blueocean-plugin by jenkinsci.

the class BlueTestResultContainerImpl method filterByState.

@VisibleForTesting
public static Iterator<BlueTestResult> filterByState(Iterable<BlueTestResult> results, String state) {
    String[] stateAtoms = StringUtils.split(state, ',');
    Predicate<BlueTestResult> predicate = Predicates.alwaysFalse();
    if (stateAtoms == null || stateAtoms.length == 0) {
        throw new BadRequestException("state not provided");
    }
    for (String stateString : stateAtoms) {
        State queryState;
        try {
            queryState = State.valueOf(stateString.toUpperCase());
        } catch (IllegalArgumentException e) {
            throw new BadRequestException("bad state " + state, e);
        }
        predicate = Predicates.or(predicate, new StatePredicate(queryState));
    }
    return Iterables.filter(results, predicate).iterator();
}
Also used : State(io.jenkins.blueocean.rest.model.BlueTestResult.State) BadRequestException(io.jenkins.blueocean.commons.ServiceException.BadRequestException) BlueTestResult(io.jenkins.blueocean.rest.model.BlueTestResult) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Aggregations

BadRequestException (io.jenkins.blueocean.commons.ServiceException.BadRequestException)2 BlueTestResult (io.jenkins.blueocean.rest.model.BlueTestResult)2 State (io.jenkins.blueocean.rest.model.BlueTestResult.State)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 NonNull (edu.umd.cs.findbugs.annotations.NonNull)1 Nullable (edu.umd.cs.findbugs.annotations.Nullable)1 Run (hudson.model.Run)1 IterableUtils (io.jenkins.blueocean.commons.IterableUtils)1 NotFoundException (io.jenkins.blueocean.commons.ServiceException.NotFoundException)1 Reachable (io.jenkins.blueocean.rest.Reachable)1 BlueTestResultFactory (io.jenkins.blueocean.rest.factory.BlueTestResultFactory)1 Result (io.jenkins.blueocean.rest.factory.BlueTestResultFactory.Result)1 Status (io.jenkins.blueocean.rest.model.BlueTestResult.Status)1 BlueTestResultContainer (io.jenkins.blueocean.rest.model.BlueTestResultContainer)1 Iterator (java.util.Iterator)1 Predicate (java.util.function.Predicate)1 StreamSupport (java.util.stream.StreamSupport)1 StringUtils (org.apache.commons.lang.StringUtils)1 StringUtils.isEmpty (org.apache.commons.lang.StringUtils.isEmpty)1 Stapler (org.kohsuke.stapler.Stapler)1