Search in sources :

Example 1 with GenericBuildsFilter

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

the class BuildFinder method getBuildsFilter.

@NotNull
private BuildsFilter getBuildsFilter(@NotNull final Locator buildLocator, @Nullable final SBuildType buildType) {
    // todo: report unknown locator dimensions
    final SBuildType actualBuildType = myBuildTypeFinder.deriveBuildTypeFromLocator(buildType, buildLocator.getSingleDimensionValue("buildType"));
    final String projectFromLocator = buildLocator.getSingleDimensionValue("project");
    final SProject project = StringUtil.isEmpty(projectFromLocator) ? null : myProjectFinder.getItem(projectFromLocator);
    final String userLocator = buildLocator.getSingleDimensionValue("user");
    final String tagsString = buildLocator.getSingleDimensionValue("tags");
    final String singleTagString = buildLocator.getSingleDimensionValue("tag");
    if (tagsString != null && singleTagString != null) {
        throw new BadRequestException("Both 'tags' and 'tag' dimensions specified. Only one can be present.");
    }
    List<String> tagsList = null;
    if (singleTagString != null) {
        tagsList = Collections.singletonList(singleTagString);
    } else if (tagsString != null) {
        tagsList = Arrays.asList(tagsString.split(","));
    }
    final Long count = buildLocator.getSingleDimensionValueAsLong(PagerData.COUNT);
    BranchMatcher branchMatcher;
    final String branchLocatorValue = buildLocator.getSingleDimensionValue("branch");
    try {
        branchMatcher = new BranchMatcher(branchLocatorValue);
    } catch (LocatorProcessException e) {
        throw new LocatorProcessException("Invalid sub-locator 'branch': " + e.getMessage());
    }
    Collection<SBuildAgent> agents = null;
    final String agentLocator = buildLocator.getSingleDimensionValue("agent");
    if (agentLocator != null) {
        agents = myAgentFinder.getItems(agentLocator).myEntries;
    }
    return new GenericBuildsFilter(actualBuildType, project, buildLocator.getSingleDimensionValue("status"), buildLocator.getSingleDimensionValue("number"), userLocator == null ? null : myUserFinder.getItem(userLocator), buildLocator.getSingleDimensionValueAsBoolean("personal", false), buildLocator.getSingleDimensionValueAsBoolean("canceled", false), buildLocator.getSingleDimensionValueAsBoolean("running", false), buildLocator.getSingleDimensionValueAsBoolean("pinned"), tagsList, branchMatcher, // deprecated, use "agent" instead
    buildLocator.getSingleDimensionValue("agentName"), agents, ParameterCondition.create(buildLocator.getSingleDimensionValue("property")), getRangeLimit(actualBuildType, buildLocator.getSingleDimensionValue("sinceBuild"), DataProvider.parseDate(buildLocator.getSingleDimensionValue("sinceDate"))), getRangeLimit(actualBuildType, buildLocator.getSingleDimensionValue("untilBuild"), DataProvider.parseDate(buildLocator.getSingleDimensionValue("untilDate"))), buildLocator.getSingleDimensionValueAsLong(PagerData.START), count == null ? null : count.intValue(), buildLocator.getSingleDimensionValueAsLong("lookupLimit"), myServiceLocator);
}
Also used : GenericBuildsFilter(jetbrains.buildServer.server.rest.data.build.GenericBuildsFilter) BadRequestException(jetbrains.buildServer.server.rest.errors.BadRequestException) LocatorProcessException(jetbrains.buildServer.server.rest.errors.LocatorProcessException) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

GenericBuildsFilter (jetbrains.buildServer.server.rest.data.build.GenericBuildsFilter)1 BadRequestException (jetbrains.buildServer.server.rest.errors.BadRequestException)1 LocatorProcessException (jetbrains.buildServer.server.rest.errors.LocatorProcessException)1 NotNull (org.jetbrains.annotations.NotNull)1