Search in sources :

Example 1 with Locator

use of jetbrains.buildServer.server.rest.data.Locator in project teamcity-rest by JetBrains.

the class Orders method getComparator.

@NotNull
public Comparator<T> getComparator(@NotNull final String orderLocatorText) {
    Locator locator = new Locator(orderLocatorText, getNames());
    if (locator.isSingleValue()) {
        // noinspection ConstantConditions
        return get(locator.getSingleValue());
    }
    Comparator<T> ALL_EQUAL = (o1, o2) -> 0;
    Comparator<T> comparator = ALL_EQUAL;
    for (Map.Entry<String, Comparator<T>> compPair : myComparators.entrySet()) {
        String name = compPair.getKey();
        String dimension = locator.getSingleDimensionValue(name);
        if (dimension != null) {
            if ("asc".equals(dimension) || "".equals(dimension)) {
                comparator = comparator.thenComparing(compPair.getValue());
            } else if ("desc".equals(dimension)) {
                comparator = comparator.thenComparing(compPair.getValue().reversed());
            } else {
                throw new BadRequestException("Dimension \"" + name + "\" has invalid value \"" + dimension + "\". Should be \"asc\" or \"desc\"");
            }
        }
    }
    locator.checkLocatorFullyProcessed();
    if (comparator == ALL_EQUAL) {
        throw new BadRequestException("No order is defined by the supplied ordering locator");
    }
    return comparator;
}
Also used : LinkedHashMap(java.util.LinkedHashMap) Arrays(java.util.Arrays) Map(java.util.Map) Comparator(java.util.Comparator) Locator(jetbrains.buildServer.server.rest.data.Locator) NotNull(org.jetbrains.annotations.NotNull) BadRequestException(jetbrains.buildServer.server.rest.errors.BadRequestException) Locator(jetbrains.buildServer.server.rest.data.Locator) BadRequestException(jetbrains.buildServer.server.rest.errors.BadRequestException) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) Comparator(java.util.Comparator) NotNull(org.jetbrains.annotations.NotNull)

Example 2 with Locator

use of jetbrains.buildServer.server.rest.data.Locator in project teamcity-rest by JetBrains.

the class TestScopeTreeCollector method buildTree.

@NotNull
private ScopeTree<STestRun, TestCountersData> buildTree(@NotNull Locator locator) {
    Locator scopesLocator = prepareScopesLocator(locator);
    Stream<TestScope> testScopes = myScopeCollector.getItems(scopesLocator);
    return new ScopeTree<STestRun, TestCountersData>(TestScopeInfo.ROOT, new TestCountersData(), // this is a bit fragile as we require all of those to be CLASS
    testScopes.collect(Collectors.toList()));
}
Also used : Locator(jetbrains.buildServer.server.rest.data.Locator) TestCountersData(jetbrains.buildServer.server.rest.data.problem.TestCountersData) NotNull(org.jetbrains.annotations.NotNull)

Example 3 with Locator

use of jetbrains.buildServer.server.rest.data.Locator in project teamcity-rest by JetBrains.

the class TestScopeTreeCollector method getSlicedTreeFromBuildPromotions.

@NotNull
public List<ScopeTree.Node<STestRun, TestCountersData>> getSlicedTreeFromBuildPromotions(@NotNull Stream<BuildPromotion> promotions, @NotNull Locator treeLocator) {
    treeLocator.addSupportedDimensions(NEW_FAILURE, SUBTREE_ROOT_ID);
    final String testRunsLocator = "build:%d,status:failure,muted:false,ignored:false" + (treeLocator.isAnyPresent(NEW_FAILURE) ? ",newFailure:" + treeLocator.getSingleDimensionValue(NEW_FAILURE) : "");
    Stream<STestRun> testRunStream = promotions.filter(promotion -> promotion.getAssociatedBuildId() != null).flatMap(promotion -> myTestOccurrenceFinder.getItems(String.format(testRunsLocator, promotion.getAssociatedBuildId())).myEntries.stream());
    Stream<TestScope> scopeStream = myScopeCollector.groupByClass(testRunStream, new TestScopeFilterImpl(Collections.emptyList(), ""));
    scopeStream = myScopeCollector.splitByBuildType(scopeStream);
    List<TestScope> scopes = scopeStream.collect(Collectors.toList());
    ScopeTree<STestRun, TestCountersData> tree = new ScopeTree<STestRun, TestCountersData>(TestScopeInfo.ROOT, new TestCountersData(), scopes);
    if (treeLocator.isAnyPresent(SUBTREE_ROOT_ID)) {
        String subTreeRootId = treeLocator.getSingleDimensionValue(SUBTREE_ROOT_ID);
        treeLocator.checkLocatorFullyProcessed();
        // noinspection ConstantConditions
        return tree.getFullNodeAndSlicedOrderedSubtree(subTreeRootId, DEFAULT_MAX_CHILDREN, STestRun.NEW_FIRST_NAME_COMPARATOR, SUPPORTED_ORDERS.getComparator(DEFAULT_NODE_ORDER_BY_NEW_FAILED_COUNT));
    }
    treeLocator.checkLocatorFullyProcessed();
    return tree.getSlicedOrderedTree(DEFAULT_MAX_CHILDREN, STestRun.NEW_FIRST_NAME_COMPARATOR, SUPPORTED_ORDERS.getComparator(DEFAULT_NODE_ORDER_BY_NEW_FAILED_COUNT));
}
Also used : LocatorProcessException(jetbrains.buildServer.server.rest.errors.LocatorProcessException) java.util(java.util) BuildPromotion(jetbrains.buildServer.serverSide.BuildPromotion) STestRun(jetbrains.buildServer.serverSide.STestRun) Locator(jetbrains.buildServer.server.rest.data.Locator) Collectors(java.util.stream.Collectors) TestCountersData(jetbrains.buildServer.server.rest.data.problem.TestCountersData) jetbrains.buildServer.server.rest.data.problem.tree(jetbrains.buildServer.server.rest.data.problem.tree) Stream(java.util.stream.Stream) Orders(jetbrains.buildServer.server.rest.data.problem.Orders) TestOccurrenceFinder(jetbrains.buildServer.server.rest.data.problem.TestOccurrenceFinder) NotNull(org.jetbrains.annotations.NotNull) PagerData(jetbrains.buildServer.server.rest.model.PagerData) STestRun(jetbrains.buildServer.serverSide.STestRun) TestCountersData(jetbrains.buildServer.server.rest.data.problem.TestCountersData) NotNull(org.jetbrains.annotations.NotNull)

Example 4 with Locator

use of jetbrains.buildServer.server.rest.data.Locator in project teamcity-rest by JetBrains.

the class TestScopesCollector method getItems.

public Stream<TestScope> getItems(@NotNull Locator locator) {
    locator.addSupportedDimensions(SCOPE_TYPE, TEST_OCCURRENCES, ORDER_BY, PagerData.START, PagerData.COUNT);
    locator.addSupportedDimensions(TestScopeFilterImpl.SUPPORTED_DIMENSIONS);
    String scopeName = locator.getSingleDimensionValue(SCOPE_TYPE);
    if (scopeName == null || !SUPPORTED_SCOPES.contains(scopeName)) {
        throw new BadRequestException("Invalid scope. Only scopes " + String.join(",", SUPPORTED_SCOPES) + " are supported.");
    }
    TestScopeFilter filter = myTestScopeFilterProducer.createFromLocator(locator);
    Locator testOccurrencesLocator = new Locator(locator.getSingleDimensionValue(TEST_OCCURRENCES));
    if (!StringUtil.isEmpty(filter.getLocatorString()))
        testOccurrencesLocator.setDimension(TestOccurrenceFinder.SCOPE, filter.getLocatorString());
    PagedSearchResult<STestRun> items = myTestOccurrenceFinder.getItems(testOccurrencesLocator.getStringRepresentation());
    Stream<TestScope> scopes = groupByScope(items, filter, scopeName);
    if (locator.isAnyPresent(ORDER_BY)) {
        String orderDimension = locator.getSingleDimensionValue(ORDER_BY);
        // noinspection ConstantConditions
        scopes = scopes.sorted(SUPPORTED_ORDERS.getComparator(orderDimension));
    }
    if (locator.isAnyPresent(SPLIT_BY_BUILD_TYPE)) {
        Boolean split = locator.getSingleDimensionValueAsBoolean(SPLIT_BY_BUILD_TYPE);
        if (BooleanUtils.isTrue(split)) {
            scopes = splitByBuildType(scopes);
        }
    }
    return scopes;
}
Also used : Locator(jetbrains.buildServer.server.rest.data.Locator) STestRun(jetbrains.buildServer.serverSide.STestRun) BadRequestException(jetbrains.buildServer.server.rest.errors.BadRequestException)

Example 5 with Locator

use of jetbrains.buildServer.server.rest.data.Locator in project teamcity-rest by JetBrains.

the class Property method getAllowedValues.

@NotNull
private static List<String> getAllowedValues() {
    // allow empty values by default
    String valuesLocatorText = TeamCityProperties.getPropertyOrNull("rest.listSecureProperties.valuesLocator", "password:()");
    try {
        if (!StringUtil.isEmpty(valuesLocatorText)) {
            Locator valuesLocator = new Locator(valuesLocatorText, "password", "enabled");
            Boolean enabled = valuesLocator.getSingleDimensionValueAsBoolean("enabled", true);
            if (enabled != null && !enabled) {
                return Collections.emptyList();
            }
            List<String> values = valuesLocator.getDimensionValue("password");
            valuesLocator.checkLocatorFullyProcessed();
            return values;
        }
    } catch (LocatorProcessException e) {
        throw new InvalidStateException("Wrong '" + "rest.listSecureProperties.valuesLocator" + "' server internal property value, remove it or use format 'password:(),password:(sample)', error: " + e.getMessage());
    }
    return Collections.emptyList();
}
Also used : ServiceLocator(jetbrains.buildServer.ServiceLocator) Locator(jetbrains.buildServer.server.rest.data.Locator) InvalidStateException(jetbrains.buildServer.server.rest.errors.InvalidStateException) LocatorProcessException(jetbrains.buildServer.server.rest.errors.LocatorProcessException) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

Locator (jetbrains.buildServer.server.rest.data.Locator)19 NotNull (org.jetbrains.annotations.NotNull)9 ServiceLocator (jetbrains.buildServer.ServiceLocator)8 BadRequestException (jetbrains.buildServer.server.rest.errors.BadRequestException)8 ApiOperation (io.swagger.annotations.ApiOperation)7 Fields (jetbrains.buildServer.server.rest.model.Fields)7 BuildPromotion (jetbrains.buildServer.serverSide.BuildPromotion)5 PagerData (jetbrains.buildServer.server.rest.model.PagerData)4 ChangeStatus (jetbrains.buildServer.vcs.ChangeStatus)4 ChangeStatusProvider (jetbrains.buildServer.vcs.ChangeStatusProvider)4 SVcsModification (jetbrains.buildServer.vcs.SVcsModification)4 List (java.util.List)3 Objects (java.util.Objects)3 HashMap (java.util.HashMap)2 Map (java.util.Map)2 Collectors (java.util.stream.Collectors)2 Stream (java.util.stream.Stream)2 UriBuilder (javax.ws.rs.core.UriBuilder)2 TestCountersData (jetbrains.buildServer.server.rest.data.problem.TestCountersData)2 LocatorProcessException (jetbrains.buildServer.server.rest.errors.LocatorProcessException)2