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;
}
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()));
}
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));
}
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;
}
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();
}
Aggregations