Search in sources :

Example 11 with LocatorProcessException

use of jetbrains.buildServer.server.rest.errors.LocatorProcessException in project teamcity-rest by JetBrains.

the class BuildPromotionFinder method getFilter.

@NotNull
@Override
public ItemFilter<BuildPromotion> getFilter(@NotNull final Locator locator) {
    final MultiCheckerFilter<BuildPromotion> result = new MultiCheckerFilter<BuildPromotion>();
    // checking permissions to view - workaround for TW-45544
    result.add(item -> {
        try {
            ensureCanView(item);
            return true;
        } catch (AccessDeniedException e) {
            // excluding from the lists as secure wrappers usually do
            return false;
        }
    });
    if (locator.isSingleValue()) {
        try {
            long foundPromotionId = getBuildPromotionById(locator.getSingleValueAsLong(), myBuildPromotionManager, myBuildsManager).getId();
            result.add(item -> foundPromotionId == item.getId());
        } catch (NotFoundException e) {
            result.add(item -> false);
        }
    }
    if (locator.isUnused(DEFAULT_FILTERING)) {
        // basically, mark as used if it is not yet processed, but is unset or is set to false
        final Boolean defaultFiltering = locator.getSingleDimensionValueAsBoolean(DEFAULT_FILTERING);
        if (defaultFiltering != null && defaultFiltering) {
            locator.markUnused(DEFAULT_FILTERING);
        }
    }
    final Long id = locator.getSingleDimensionValueAsLong(DIMENSION_ID);
    if (id != null) {
        try {
            long foundPromotionId = getBuildPromotionById(id, myBuildPromotionManager, myBuildsManager).getId();
            result.add(item -> foundPromotionId == item.getId());
        } catch (NotFoundException e) {
            result.add(item -> false);
        }
    }
    final Long promotionId = locator.getSingleDimensionValueAsLong(PROMOTION_ID);
    if (promotionId != null) {
        try {
            long foundPromotionId = BuildFinder.getBuildPromotion(promotionId, myBuildPromotionManager).getId();
            result.add(item -> foundPromotionId == item.getId());
        } catch (NotFoundException e) {
            result.add(item -> false);
        }
    }
    final Long promotionIdAlias = locator.getSingleDimensionValueAsLong(PROMOTION_ID_ALIAS);
    if (promotionIdAlias != null) {
        try {
            long foundPromotionId = BuildFinder.getBuildPromotion(promotionIdAlias, myBuildPromotionManager).getId();
            result.add(item -> foundPromotionId == item.getId());
        } catch (NotFoundException e) {
            result.add(item -> false);
        }
    }
    final Long buildId = locator.getSingleDimensionValueAsLong(BUILD_ID);
    if (buildId != null) {
        result.add(item -> buildId.equals(item.getAssociatedBuildId()));
    }
    Locator stateLocator = getStateLocator(locator);
    if (!isStateIncluded(stateLocator, STATE_QUEUED)) {
        result.add(new FilterConditionChecker<BuildPromotion>() {

            public boolean isIncluded(@NotNull final BuildPromotion item) {
                return item.getQueuedBuild() == null;
            }
        });
    }
    if (!isStateIncluded(stateLocator, STATE_RUNNING)) {
        result.add(new FilterConditionChecker<BuildPromotion>() {

            public boolean isIncluded(@NotNull final BuildPromotion item) {
                final SBuild associatedBuild = item.getAssociatedBuild();
                return associatedBuild == null || associatedBuild.isFinished();
            }
        });
    }
    if (!isStateIncluded(stateLocator, STATE_FINISHED)) {
        result.add(new FilterConditionChecker<BuildPromotion>() {

            public boolean isIncluded(@NotNull final BuildPromotion item) {
                final SBuild associatedBuild = item.getAssociatedBuild();
                return associatedBuild == null || !associatedBuild.isFinished();
            }
        });
    }
    final Boolean composite = locator.getSingleDimensionValueAsBoolean(COMPOSITE);
    if (composite != null) {
        result.add(item -> FilterUtil.isIncludedByBooleanFilter(composite, item.isCompositeBuild()));
    }
    if (locator.isUnused(PROJECT)) {
        SProject project = getProjectFromDimension(locator, PROJECT);
        if (project != null) {
            result.add(item -> {
                final SBuildType buildType = item.getBuildType();
                return buildType != null && project.equals(buildType.getProject());
            });
        }
    }
    if (locator.isUnused(AFFECTED_PROJECT)) {
        SProject affectedProject = getProjectFromDimension(locator, AFFECTED_PROJECT);
        if (affectedProject != null && !affectedProject.isRootProject()) {
            result.add(item -> {
                final SBuildType buildType = item.getBuildType();
                return buildType != null && ProjectFinder.isSameOrParent(affectedProject, buildType.getProject());
            });
        }
    }
    if (locator.isUnused(BUILD_TYPE)) {
        final String buildTypeLocator = locator.getSingleDimensionValue(BUILD_TYPE);
        if (buildTypeLocator != null) {
            final Set<SBuildType> buildTypes = new HashSet<>(myBuildTypeFinder.getBuildTypes(getProjectFromDimension(locator, PROJECT), buildTypeLocator));
            if (buildTypes.isEmpty()) {
                throw new NotFoundException("No build types found for locator '" + buildTypeLocator + "'");
            }
            result.add(new FilterConditionChecker<BuildPromotion>() {

                public boolean isIncluded(@NotNull final BuildPromotion item) {
                    return buildTypes.contains(item.getParentBuildType());
                }
            });
        }
    }
    final String branchLocatorValue = locator.getSingleDimensionValue(BRANCH);
    if (branchLocatorValue != null) {
        PagedSearchResult<? extends Branch> branches = null;
        BadRequestException exceptinoOnFullSearch = null;
        try {
            branches = myBranchFinder.getItemsIfValidBranchListLocator(locator.lookupSingleDimensionValue(BUILD_TYPE), branchLocatorValue);
        } catch (BadRequestException e) {
            // not a valid branches listing locator
            exceptinoOnFullSearch = e;
        }
        if (branches != null) {
            // branches found - use them
            Set<String> branchNames = getBranchNamesSet(branches.myEntries);
            Set<String> branchDisplayNames = getBranchDisplayNamesSet(branches.myEntries);
            boolean defaultBranchIncluded = branches.myEntries.stream().anyMatch(Branch::isDefaultBranch);
            result.add(new FilterConditionChecker<BuildPromotion>() {

                public boolean isIncluded(@NotNull final BuildPromotion item) {
                    final Branch buildBranch = BranchData.fromBuild(item);
                    return (defaultBranchIncluded && buildBranch.isDefaultBranch()) || branchNames.contains(buildBranch.getName()) || branchDisplayNames.contains(buildBranch.getDisplayName());
                }
            });
        } else {
            // branches not found by locator - try to use filter
            BranchFinder.BranchFilterDetails branchFilterDetails;
            try {
                branchFilterDetails = myBranchFinder.getBranchFilterDetails(branchLocatorValue);
            } catch (LocatorProcessException locatorException) {
                throw new BadRequestException("Invalid sub-locator '" + BRANCH + "': Cannot" + (exceptinoOnFullSearch != null ? " find branches: " + exceptinoOnFullSearch.getMessage() + "; and cannot " : "") + " create filter: " + locatorException.getMessage(), locatorException);
            }
            if (!branchFilterDetails.isAnyBranch()) {
                result.add(new FilterConditionChecker<BuildPromotion>() {

                    public boolean isIncluded(@NotNull final BuildPromotion item) {
                        return branchFilterDetails.isIncluded(item);
                    }
                });
            }
        }
    }
    final Boolean branched = locator.getSingleDimensionValueAsBoolean(BRANCHED);
    if (branched != null) {
        result.add(item -> FilterUtil.isIncludedByBooleanFilter(branched, item.getBranch() != null));
    }
    if (locator.isUnused(AGENT)) {
        final String agentLocator = locator.getSingleDimensionValue(AGENT);
        if (agentLocator != null) {
            Set<Integer> agentIds = myAgentFinder.getItemsNotEmpty(agentLocator).myEntries.stream().map(agent -> agent.getId()).filter(i -> i != Agent.UNKNOWN_AGENT_ID).collect(Collectors.toSet());
            result.add(item -> {
                // for queued build using compatible agents
                final SQueuedBuild queuedBuild = item.getQueuedBuild();
                if (queuedBuild != null) {
                    return queuedBuild.getCanRunOnAgents().stream().anyMatch(agent -> agentIds.contains(agent.getId()));
                }
                final SBuild build = item.getAssociatedBuild();
                if (build != null) {
                    return agentIds.contains(build.getAgent().getId());
                }
                return false;
            });
        }
    }
    // compatibility support
    final String tags = locator.getSingleDimensionValue(TAGS);
    if (tags != null) {
        final List<String> tagsList = Arrays.asList(tags.split(","));
        if (tagsList.size() > 0) {
            result.add(new FilterConditionChecker<BuildPromotion>() {

                public boolean isIncluded(@NotNull final BuildPromotion item) {
                    return item.getTags().containsAll(tagsList);
                }
            });
        }
    }
    if (locator.isUnused(TAG)) {
        result.add(getFilterByTag(locator.getDimensionValue(TAG)));
    }
    final String compatibleAgentLocator = locator.getSingleDimensionValue(COMPATIBLE_AGENT);
    if (compatibleAgentLocator != null) {
        List<SBuildAgent> agents = myAgentFinder.getItems(compatibleAgentLocator).myEntries;
        result.add(build -> agents.stream().anyMatch(agent -> myAgentFinder.canActuallyRun(agent, build)));
    }
    // experimental, only for queued builds
    final Long compatibleAgentsCount = locator.getSingleDimensionValueAsLong(COMPATIBLE_AGENTS_COUNT);
    if (compatibleAgentsCount != null) {
        result.add(new FilterConditionChecker<BuildPromotion>() {

            public boolean isIncluded(@NotNull final BuildPromotion item) {
                long count = 0;
                for (SBuildAgent agent : myAgentFinder.getItems(null).myEntries) {
                    // or should process unauthorized as well?
                    if (myAgentFinder.canActuallyRun(agent, item))
                        count++;
                    if (count > compatibleAgentsCount)
                        return false;
                }
                return count == compatibleAgentsCount;
            }
        });
    }
    final Boolean personal = locator.getSingleDimensionValueAsBoolean(PERSONAL);
    if (personal != null) {
        result.add(new FilterConditionChecker<BuildPromotion>() {

            public boolean isIncluded(@NotNull final BuildPromotion item) {
                return FilterUtil.isIncludedByBooleanFilter(personal, item.isPersonal());
            }
        });
    }
    final Boolean history = locator.getSingleDimensionValueAsBoolean(HISTORY);
    if (history != null) {
        result.add(new FilterConditionChecker<BuildPromotion>() {

            public boolean isIncluded(@NotNull final BuildPromotion item) {
                return FilterUtil.isIncludedByBooleanFilter(history, item.isOutOfChangesSequence());
            }
        });
    }
    final String userDimension = locator.getSingleDimensionValue(USER);
    if (userDimension != null) {
        final SUser user = myUserFinder.getItem(userDimension);
        result.add(new FilterConditionChecker<BuildPromotion>() {

            public boolean isIncluded(@NotNull final BuildPromotion item) {
                SUser owner = item.getOwner();
                if (owner != null) {
                    // if owner is present, consider only it: this is consistent with the builds search in the prefiltering
                    return user.getId() == owner.getId();
                }
                SUser actualUser = Util.resolveNull(getTriggeredBy(item), TriggeredBy::getUser);
                return actualUser != null && user.getId() == actualUser.getId();
            }
        });
    }
    final String triggeredDimension = locator.getSingleDimensionValue(TRIGGERED);
    if (triggeredDimension != null) {
        final ItemFilter<TriggeredBy> filter = myTriggerByFinder.getFilter(triggeredDimension);
        result.add(item -> Util.resolveNull(getTriggeredBy(item), filter::isIncluded, false));
    }
    final List<String> properties = locator.getDimensionValue(PROPERTY);
    if (!properties.isEmpty()) {
        final Matcher<ParametersProvider> parameterCondition = ParameterCondition.create(properties);
        result.add(new FilterConditionChecker<BuildPromotion>() {

            public boolean isIncluded(@NotNull final BuildPromotion item) {
                if (!Build.canViewRuntimeData(myPermissionChecker, item))
                    return false;
                // TeamCity open API issue
                return parameterCondition.matches(Build.getBuildResultingParameters(item, myServiceLocator));
            }
        });
    }
    if (locator.getUnusedDimensions().contains(SNAPSHOT_DEP)) {
        // performance optimization: do not filter if already processed
        final String snapshotDepDimension = locator.getSingleDimensionValue(SNAPSHOT_DEP);
        if (snapshotDepDimension != null) {
            final Set<BuildPromotion> snapshotRelatedBuilds = new HashSet<>(getSnapshotRelatedBuilds(snapshotDepDimension));
            result.add(new FilterConditionChecker<BuildPromotion>() {

                public boolean isIncluded(@NotNull final BuildPromotion item) {
                    return snapshotRelatedBuilds.contains(item);
                }
            });
        }
    }
    if (locator.getUnusedDimensions().contains(ARTIFACT_DEP)) {
        // performance optimization: do not filter if already processed
        final String artifactDepDimension = locator.getSingleDimensionValue(ARTIFACT_DEP);
        if (artifactDepDimension != null) {
            final Set<BuildPromotion> artifactRelatedBuilds = new HashSet<>(getArtifactRelatedBuilds(artifactDepDimension, locator));
            result.add(new FilterConditionChecker<BuildPromotion>() {

                public boolean isIncluded(@NotNull final BuildPromotion item) {
                    return artifactRelatedBuilds.contains(item);
                }
            });
        }
    }
    if (locator.isUnused(SNAPSHOT_PROBLEM)) {
        final String snapshotDepProblem = locator.getSingleDimensionValue(SNAPSHOT_PROBLEM);
        if (snapshotDepProblem != null) {
            final Set<BuildPromotion> snapshotDepProblemBuilds = new HashSet<>(getSnapshotDepProblemBuilds(snapshotDepProblem));
            result.add(item -> snapshotDepProblemBuilds.contains(item));
        }
    }
    if (locator.getUnusedDimensions().contains(EQUIVALENT)) {
        // performance optimization: do not filter if already processed
        final String equivalent = locator.getSingleDimensionValue(EQUIVALENT);
        if (equivalent != null) {
            final Set<BuildPromotion> filter = new HashSet<BuildPromotion>(((BuildPromotionEx) getItem(equivalent)).getStartedEquivalentPromotions(-1));
            result.add(new FilterConditionChecker<BuildPromotion>() {

                public boolean isIncluded(@NotNull final BuildPromotion item) {
                    return filter.contains(item);
                }
            });
        }
    }
    if (locator.getUnusedDimensions().contains(METADATA)) {
        // performance optimization: do not filter if already processed
        final String metadata = locator.getSingleDimensionValue(METADATA);
        if (metadata != null) {
            final Iterator<BuildMetadataEntry> metadataEntries = getBuildMetadataEntryIterator(metadata);
            final Set<Long> buildIds = new HashSet<Long>();
            while (metadataEntries.hasNext()) {
                BuildMetadataEntry metadataEntry = metadataEntries.next();
                buildIds.add(metadataEntry.getBuildId());
            }
            result.add(new FilterConditionChecker<BuildPromotion>() {

                public boolean isIncluded(@NotNull final BuildPromotion item) {
                    if (!Build.canViewRuntimeData(myPermissionChecker, item))
                        return false;
                    return buildIds.contains(item.getAssociatedBuildId());
                }
            });
        }
    }
    if (locator.getUnusedDimensions().contains(ORDERED)) {
        // performance optimization: do not filter if already processed
        final String graphLocator = locator.getSingleDimensionValue(ORDERED);
        if (graphLocator != null) {
            final GraphFinder<BuildPromotion> graphFinder = new BuildPromotionOrderedFinder(BuildPromotionFinder.this);
            final Set<BuildPromotion> filter = new HashSet<BuildPromotion>(graphFinder.getItems(graphLocator).myEntries);
            result.add(new FilterConditionChecker<BuildPromotion>() {

                public boolean isIncluded(@NotNull final BuildPromotion item) {
                    return filter.contains(item);
                }
            });
        }
    }
    final String sinceBuildDimension = locator.getSingleDimensionValue(SINCE_BUILD);
    BuildPromotion sinceBuildPromotion = null;
    Long sinceBuildId = null;
    if (sinceBuildDimension != null) {
        try {
            sinceBuildPromotion = getItem(sinceBuildDimension);
            final SQueuedBuild queuedBuild = sinceBuildPromotion.getQueuedBuild();
            if (queuedBuild != null) {
                // compare queued builds by id (triggering sequence)
                final long buildPromotionId = getBuildId(sinceBuildPromotion);
                result.add(new FilterConditionChecker<BuildPromotion>() {

                    public boolean isIncluded(@NotNull final BuildPromotion item) {
                        return buildPromotionId < getBuildId(item);
                    }
                });
            } else {
                // for started build, compare by start time
                final SBuild limitingBuild = sinceBuildPromotion.getAssociatedBuild();
                if (limitingBuild != null) {
                    final Date startDate = limitingBuild.getStartDate();
                    result.add(new FilterConditionChecker<BuildPromotion>() {

                        public boolean isIncluded(@NotNull final BuildPromotion item) {
                            final SBuild build = item.getAssociatedBuild();
                            if (build == null)
                                return true;
                            if (startDate.equals(build.getStartDate()) && limitingBuild.getBuildId() != build.getBuildId())
                                return true;
                            return startDate.before(build.getStartDate());
                        }
                    });
                }
            }
        } catch (NotFoundException e) {
            // build not found by sinceBuild locator, extract id ad filter using it
            sinceBuildId = getBuildId(sinceBuildDimension);
            final long sinceBuildIdFinal = sinceBuildId;
            result.add(new FilterConditionChecker<BuildPromotion>() {

                public boolean isIncluded(@NotNull final BuildPromotion item) {
                    return sinceBuildIdFinal < getBuildId(item);
                }
            });
        }
    }
    final String untilBuild = locator.getSingleDimensionValue(UNTIL_BUILD);
    if (untilBuild != null) {
        try {
            final BuildPromotion untilBuildPromotion = getItem(untilBuild);
            final SQueuedBuild queuedBuild = untilBuildPromotion.getQueuedBuild();
            if (queuedBuild != null) {
                // compare queued builds by id (triggering sequence)
                final long buildPromotionId = getBuildId(untilBuildPromotion);
                result.add(new FilterConditionChecker<BuildPromotion>() {

                    public boolean isIncluded(@NotNull final BuildPromotion item) {
                        return !(buildPromotionId < getBuildId(item));
                    }
                });
            } else {
                // for started build, compare by start time
                final SBuild limitingBuild = untilBuildPromotion.getAssociatedBuild();
                if (limitingBuild != null) {
                    final Date startDate = limitingBuild.getStartDate();
                    result.add(new FilterConditionChecker<BuildPromotion>() {

                        public boolean isIncluded(@NotNull final BuildPromotion item) {
                            final SBuild build = item.getAssociatedBuild();
                            return build == null || !startDate.before(build.getStartDate());
                        }
                    });
                }
            }
        } catch (NotFoundException e) {
            // build not found by sinceBuild locator, extract id ad filter using it
            final long untilBuildId = getBuildId(untilBuild);
            result.add(new FilterConditionChecker<BuildPromotion>() {

                public boolean isIncluded(@NotNull final BuildPromotion item) {
                    return !(untilBuildId < getBuildId(item));
                }
            });
        }
    }
    TimeCondition.FilterAndLimitingDate<BuildPromotion> queuedFiltering = myTimeCondition.processTimeConditions(QUEUED_TIME, locator, TimeCondition.QUEUED_BUILD_TIME, TimeCondition.QUEUED_BUILD_TIME);
    if (queuedFiltering != null)
        result.add(queuedFiltering.getFilter());
    TimeCondition.FilterAndLimitingDate<BuildPromotion> startedFiltering = myTimeCondition.processTimeConditions(STARTED_TIME, locator, TimeCondition.STARTED_BUILD_TIME, TimeCondition.STARTED_BUILD_TIME);
    @Nullable Date sinceStartDate = null;
    if (startedFiltering != null) {
        result.add(startedFiltering.getFilter());
        sinceStartDate = startedFiltering.getLimitingDate();
    }
    // todo: add processing cut of based on assumption of max build time (say, a week); for other times as well
    TimeCondition.FilterAndLimitingDate<BuildPromotion> finishFiltering = myTimeCondition.processTimeConditions(FINISHED_TIME, locator, TimeCondition.FINISHED_BUILD_TIME, TimeCondition.FINISHED_BUILD_TIME);
    if (finishFiltering != null)
        result.add(finishFiltering.getFilter());
    final String revisionLocatorText = locator.getSingleDimensionValue(REVISION);
    if (revisionLocatorText != null) {
        final Locator revisionLocator = new Locator(revisionLocatorText, "version", "internalVersion", "vcsRoot", Locator.LOCATOR_SINGLE_VALUE_UNUSED_NAME);
        final String revision = revisionLocator.getSingleValue();
        if (revision != null) {
            result.add(new FilterConditionChecker<BuildPromotion>() {

                public boolean isIncluded(@NotNull final BuildPromotion item) {
                    // use getAllrevisions map??
                    final List<BuildRevision> buildRevisions = item.getRevisions();
                    for (BuildRevision rev : buildRevisions) {
                        if (revision.equals(rev.getRevisionDisplayName())) {
                            return true;
                        }
                    }
                    return false;
                }
            });
        } else {
            final String vcsRootLocator = revisionLocator.getSingleDimensionValue("vcsRoot");
            final SVcsRoot vcsRoot = vcsRootLocator == null ? null : myVcsRootFinder.getItem(vcsRootLocator);
            final ValueCondition versionCondition = ParameterCondition.createValueCondition(revisionLocator.getSingleDimensionValue("version"));
            final ValueCondition internalVersionCondition = ParameterCondition.createValueCondition(revisionLocator.getSingleDimensionValue("internalVersion"));
            revisionLocator.checkLocatorFullyProcessed();
            if (vcsRoot != null || versionCondition != null || internalVersionCondition != null) {
                result.add(new FilterConditionChecker<BuildPromotion>() {

                    public boolean isIncluded(@NotNull final BuildPromotion item) {
                        // use getAllrevisions map??
                        final List<BuildRevision> revisions = item.getRevisions();
                        for (BuildRevision rev : revisions) {
                            if ((vcsRoot == null || vcsRoot.getId() == rev.getRoot().getParent().getId()) && (versionCondition == null || versionCondition.matches(rev.getRevisionDisplayName())) && (internalVersionCondition == null || internalVersionCondition.matches(rev.getRevision()))) {
                                return true;
                            }
                        }
                        return false;
                    }
                });
            }
        }
    }
    final MultiCheckerFilter<SBuild> buildFilter = getBuildFilter(locator);
    if (buildFilter.getSubFiltersCount() > 0) {
        result.add(new FilterConditionChecker<BuildPromotion>() {

            public boolean isIncluded(@NotNull final BuildPromotion item) {
                final SBuild build = item.getAssociatedBuild();
                if (build == null) {
                    return false;
                }
                return buildFilter.isIncluded(build);
            }
        });
    }
    // see also filtering in getBuildFilter
    sinceStartDate = TimeCondition.maxDate(sinceStartDate, DataProvider.parseDate(locator.getSingleDimensionValue(SINCE_DATE)));
    final Boolean canceled = locator.getSingleDimensionValueAsBoolean(CANCELED);
    if (canceled != null) {
        result.add(new FilterConditionChecker<BuildPromotion>() {

            public boolean isIncluded(@NotNull final BuildPromotion item) {
                final SBuild build = item.getAssociatedBuild();
                return FilterUtil.isIncludedByBooleanFilter(canceled, build != null && build.getCanceledInfo() != null);
            }
        });
    }
    final Boolean failedToStart = locator.getSingleDimensionValueAsBoolean(FAILED_TO_START);
    if (failedToStart != null) {
        result.add(new FilterConditionChecker<BuildPromotion>() {

            public boolean isIncluded(@NotNull final BuildPromotion item) {
                final SBuild build = item.getAssociatedBuild();
                return FilterUtil.isIncludedByBooleanFilter(failedToStart, build != null && build.isInternalError());
            }
        });
    }
    return getFilterWithProcessingCutOff(result, locator.getSingleDimensionValueAsLong(SINCE_BUILD_ID_LOOK_AHEAD_COUNT), sinceBuildPromotion, sinceBuildId, sinceStartDate);
}
Also used : LocatorProcessException(jetbrains.buildServer.server.rest.errors.LocatorProcessException) MetadataStorageEx(jetbrains.buildServer.serverSide.metadata.impl.MetadataStorageEx) Filter(jetbrains.buildServer.util.filters.Filter) java.util(java.util) LocatorName(jetbrains.buildServer.server.rest.swagger.constants.LocatorName) LocatorResource(jetbrains.buildServer.server.rest.swagger.annotations.LocatorResource) Agent(jetbrains.buildServer.server.rest.model.agent.Agent) BuildDependency(jetbrains.buildServer.serverSide.dependency.BuildDependency) Converter(jetbrains.buildServer.util.Converter) ParametersProvider(jetbrains.buildServer.parameters.ParametersProvider) BadRequestException(jetbrains.buildServer.server.rest.errors.BadRequestException) LocatorDimensionDataType(jetbrains.buildServer.server.rest.swagger.constants.LocatorDimensionDataType) AbstractMapParametersProvider(jetbrains.buildServer.parameters.impl.AbstractMapParametersProvider) TestOccurrenceFinder(jetbrains.buildServer.server.rest.data.problem.TestOccurrenceFinder) AccessDeniedException(jetbrains.buildServer.serverSide.auth.AccessDeniedException) ErrorData(jetbrains.buildServer.messages.ErrorData) StringUtil(jetbrains.buildServer.util.StringUtil) Build(jetbrains.buildServer.server.rest.model.build.Build) Logger(com.intellij.openapi.diagnostic.Logger) CollectionsUtil(jetbrains.buildServer.util.CollectionsUtil) jetbrains.buildServer.server.rest.data.util(jetbrains.buildServer.server.rest.data.util) PagerData(jetbrains.buildServer.server.rest.model.PagerData) SVcsRoot(jetbrains.buildServer.vcs.SVcsRoot) PatternSyntaxException(java.util.regex.PatternSyntaxException) Constants(jetbrains.buildServer.server.rest.request.Constants) ServiceLocator(jetbrains.buildServer.ServiceLocator) jetbrains.buildServer.serverSide(jetbrains.buildServer.serverSide) ItemsProviders(jetbrains.buildServer.server.rest.model.ItemsProviders) TagFinder(jetbrains.buildServer.server.rest.data.build.TagFinder) ItemProcessor(jetbrains.buildServer.util.ItemProcessor) StreamUtil(jetbrains.buildServer.server.rest.util.StreamUtil) Collectors(java.util.stream.Collectors) Nullable(org.jetbrains.annotations.Nullable) CommonLocatorDimensionsList(jetbrains.buildServer.server.rest.swagger.constants.CommonLocatorDimensionsList) Stream(java.util.stream.Stream) LocatorDimension(jetbrains.buildServer.server.rest.swagger.annotations.LocatorDimension) Util(jetbrains.buildServer.server.rest.model.Util) Permission(jetbrains.buildServer.serverSide.auth.Permission) NotFoundException(jetbrains.buildServer.server.rest.errors.NotFoundException) TestFinder(jetbrains.buildServer.server.rest.data.problem.TestFinder) BuildMetadataEntry(jetbrains.buildServer.serverSide.metadata.BuildMetadataEntry) Pattern(java.util.regex.Pattern) NotNull(org.jetbrains.annotations.NotNull) SUser(jetbrains.buildServer.users.SUser) AccessDeniedException(jetbrains.buildServer.serverSide.auth.AccessDeniedException) SUser(jetbrains.buildServer.users.SUser) ServiceLocator(jetbrains.buildServer.ServiceLocator) CommonLocatorDimensionsList(jetbrains.buildServer.server.rest.swagger.constants.CommonLocatorDimensionsList) Nullable(org.jetbrains.annotations.Nullable) NotFoundException(jetbrains.buildServer.server.rest.errors.NotFoundException) LocatorProcessException(jetbrains.buildServer.server.rest.errors.LocatorProcessException) ParametersProvider(jetbrains.buildServer.parameters.ParametersProvider) AbstractMapParametersProvider(jetbrains.buildServer.parameters.impl.AbstractMapParametersProvider) NotNull(org.jetbrains.annotations.NotNull) SVcsRoot(jetbrains.buildServer.vcs.SVcsRoot) BuildMetadataEntry(jetbrains.buildServer.serverSide.metadata.BuildMetadataEntry) BadRequestException(jetbrains.buildServer.server.rest.errors.BadRequestException) NotNull(org.jetbrains.annotations.NotNull)

Example 12 with LocatorProcessException

use of jetbrains.buildServer.server.rest.errors.LocatorProcessException in project teamcity-rest by JetBrains.

the class BuildPromotionFinder method getPrefilteredItems.

@NotNull
@Override
public ItemHolder<BuildPromotion> getPrefilteredItems(@NotNull Locator locator) {
    if (!myPermissionChecker.hasPermissionInAnyProject(Permission.VIEW_PROJECT)) {
        // TeamCity issue: should be handled in core. Do not spend any resources on user without permissions
        return getItemHolder(Collections.emptyList());
    }
    final Boolean byPromotion = locator.getSingleDimensionValueAsBoolean(BY_PROMOTION);
    if (byPromotion != null && !byPromotion) {
        throw new BadRequestException("Found '" + BY_PROMOTION + "' locator set to 'false' which is not supported");
    }
    final String strob = locator.getSingleDimensionValue(STROB);
    if (strob != null) {
        final Locator strobLocator = new Locator(strob, BUILD_TYPE, BRANCH, STROB_BUILD_LOCATOR);
        List<Locator> partialLocators = Collections.singletonList(Locator.createEmptyLocator());
        partialLocators = getPartialLocatorsForStrobDimension(partialLocators, strobLocator, BUILD_TYPE, myBuildTypeFinder);
        partialLocators = getPartialLocatorsForStrobDimension(partialLocators, strobLocator, BRANCH, myBranchFinder);
        final String strobBuildLocator = strobLocator.getSingleDimensionValue(STROB_BUILD_LOCATOR);
        final AggregatingItemHolder<BuildPromotion> strobResult = new AggregatingItemHolder<>();
        for (Locator partialLocator : partialLocators) {
            // limit to single item per strob item by default
            partialLocator.setDimensionIfNotPresent(PagerData.COUNT, "1");
            final String finalBuildLocator = Locator.createLocator(strobBuildLocator, partialLocator, new String[] {}).getStringRepresentation();
            strobResult.add(getItemHolder(getItems(finalBuildLocator).myEntries));
        }
        strobLocator.checkLocatorFullyProcessed();
        return strobResult;
    }
    setLocatorDefaults(locator);
    final String equivalent = locator.getSingleDimensionValue(EQUIVALENT);
    if (equivalent != null) {
        final BuildPromotionEx build = (BuildPromotionEx) getItem(equivalent);
        final List<BuildPromotionEx> result = build.getStartedEquivalentPromotions(-1);
        final Set<BuildPromotion> convertedResult = new TreeSet<BuildPromotion>(BUILD_PROMOTIONS_COMPARATOR);
        for (BuildPromotionEx item : result) {
            convertedResult.add(item);
        }
        return getItemHolder(convertedResult);
    }
    final String metadata = locator.getSingleDimensionValue(METADATA);
    if (metadata != null) {
        final Iterator<BuildMetadataEntry> metadataEntries = getBuildMetadataEntryIterator(metadata);
        return new ItemHolder<BuildPromotion>() {

            @Override
            public void process(@NotNull final ItemProcessor<BuildPromotion> processor) {
                while (metadataEntries.hasNext()) {
                    BuildMetadataEntry metadataEntry = metadataEntries.next();
                    SBuild build = myBuildsManager.findBuildInstanceById(metadataEntry.getBuildId());
                    if (build != null && Build.canViewRuntimeData(myPermissionChecker, build.getBuildPromotion())) {
                        processor.processItem(build.getBuildPromotion());
                    }
                }
            }
        };
    }
    final String graphLocator = locator.getSingleDimensionValue(ORDERED);
    if (graphLocator != null) {
        final GraphFinder<BuildPromotion> graphFinder = new BuildPromotionOrderedFinder(this);
        // consider performance optimization by converting id to build only on actual retrieve (use GraphFinder<Int/buildId>)
        return getItemHolder(graphFinder.getItems(graphLocator).myEntries);
    }
    final String snapshotDepDimension = locator.getSingleDimensionValue(SNAPSHOT_DEP);
    if (snapshotDepDimension != null) {
        return getItemHolder(getSnapshotRelatedBuilds(snapshotDepDimension));
    }
    final String artifactDepDimension = locator.getSingleDimensionValue(ARTIFACT_DEP);
    if (artifactDepDimension != null) {
        return getItemHolder(getArtifactRelatedBuilds(artifactDepDimension, locator));
    }
    final String snapshotDepProblem = locator.getSingleDimensionValue(SNAPSHOT_PROBLEM);
    if (snapshotDepProblem != null) {
        return getItemHolder(getSnapshotDepProblemBuilds(snapshotDepProblem));
    }
    final String number = locator.getSingleDimensionValue(NUMBER);
    if (number != null) {
        final String buildTypeLocator = locator.getSingleDimensionValue(BUILD_TYPE);
        if (buildTypeLocator != null) {
            final List<SBuildType> buildTypes = myBuildTypeFinder.getBuildTypes(null, buildTypeLocator);
            final Set<BuildPromotion> builds = new TreeSet<BuildPromotion>(BUILD_PROMOTIONS_COMPARATOR);
            for (SBuildType buildType : buildTypes) {
                // todo: ensure due builds sorting
                builds.addAll(BuildFinder.toBuildPromotions(myBuildsManager.findBuildInstancesByBuildNumber(buildType.getBuildTypeId(), number)));
            }
            return getItemHolder(builds);
        } else {
            // if build type is not specified, search by scanning (performance impact)
            locator.markUnused(NUMBER, BUILD_TYPE);
        }
    }
    if (locator.isAnyPresent(TAG) && TeamCityProperties.getBooleanOrTrue("rest.request.builds.prefilterByTag")) {
        // using locator copy so that no dimensions are marked as used
        Locator stateLocator = getStateLocator(new Locator(locator));
        if (isStateIncluded(stateLocator, STATE_FINISHED)) {
            // no sense in going further here if no finished builds are requested
            // not marking as used to enforce filter processing later
            final List<String> tagLocators = locator.lookupDimensionValue(TAG);
            Stream<BuildPromotion> finishedBuilds = TagFinder.getPrefilteredFinishedBuildPromotions(tagLocators, myServiceLocator);
            if (finishedBuilds != null) {
                FilterConditionChecker<BuildPromotion> tagsFilter = getFilterByTag(tagLocators);
                // After this point no other builds will be added
                locator.markUsed(Collections.singleton(TAG));
                Stream<BuildPromotion> queuedBuilds = Stream.empty();
                if (isStateIncluded(stateLocator, STATE_QUEUED)) {
                    queuedBuilds = myBuildQueue.getItems().stream().map(SQueuedBuild::getBuildPromotion);
                }
                Stream<BuildPromotion> runningBuilds = Stream.empty();
                if (isStateIncluded(stateLocator, STATE_RUNNING)) {
                    // BuildsManager.processBuilds could be used here instead of getting finished and running builds separately, but BuildQueryOptions support
                    // only exact tag name match, so we can't satisfy all possible TAG queriy conditions with it. To counter that we use
                    // TagFinder.getPrefilteredFinishedBuildPromotions to obtain a subset of required finished builds and BuildsManager.getRunningBuilds()
                    // to get all runing builds and later filter everything properly.
                    runningBuilds = myBuildsManager.getRunningBuilds().stream().map(SRunningBuild::getBuildPromotion);
                }
                // None of the concatenated streams were properly filtered, so let's filter them now.
                // This hopefully allows for avoiding of hitting a lookupLimit because of a large queue.
                Stream<BuildPromotion> allBuildsFilteredByTag = Stream.concat(Stream.concat(queuedBuilds, runningBuilds), finishedBuilds).filter(tagsFilter::isIncluded);
                return processor -> allBuildsFilteredByTag.forEach(processor::processItem);
            }
        }
    }
    final String testOccurrence = locator.getSingleDimensionValue(TEST_OCCURRENCE);
    if (testOccurrence != null) {
        TestOccurrenceFinder testOccurrenceFinder = myServiceLocator.getSingletonService(TestOccurrenceFinder.class);
        return FinderDataBinding.getItemHolder(testOccurrenceFinder.getItems(testOccurrence).myEntries.stream().map(sTestRun -> sTestRun.getBuild().getBuildPromotion()));
    }
    SBuildAgent agent;
    final String agentLocator = locator.getSingleDimensionValue(AGENT);
    if (agentLocator != null) {
        List<SBuildAgent> agents = myAgentFinder.getItemsNotEmpty(agentLocator).myEntries;
        if (agents.size() == 1) {
            agent = agents.get(0);
        } else {
            // only if builds processor cannot handle this
            Stream<BuildPromotion> result = Stream.empty();
            Locator stateLocator = getStateLocator(locator);
            if (isStateIncluded(stateLocator, STATE_QUEUED)) {
                // todo: should sort backwards as currently the order does not seem right...
                result = Stream.concat(result, myBuildQueue.getItems().stream().filter(build -> !CollectionsUtil.intersect(build.getCanRunOnAgents(), agents).isEmpty()).map(build -> build.getBuildPromotion()));
            }
            if (isStateIncluded(stateLocator, STATE_RUNNING)) {
                // todo: address an issue when a build can appear twice in the output
                // agent instance can be different when disconnecting, so need to check id
                Set<Integer> agentIds = agents.stream().map(a -> a.getId()).collect(Collectors.toSet());
                Set<String> agentNames = agents.stream().map(a -> a.getName()).collect(Collectors.toSet());
                result = Stream.concat(result, myBuildsManager.getRunningBuilds().stream().filter(build -> {
                    SBuildAgent buildAgent = build.getAgent();
                    int agentId = buildAgent.getId();
                    return agentId > 0 ? agentIds.contains(agentId) : agentNames.contains(buildAgent.getName());
                }).map(build -> build.getBuildPromotion()));
            }
            if (isStateIncluded(stateLocator, STATE_FINISHED)) {
                // todo: optimize for user and canceled
                Stream<BuildPromotion> finishedBuilds = StreamUtil.merge(agents.stream().map(a -> a.getBuildHistory(null, true).stream().map(b -> b.getBuildPromotion())), BUILD_PROMOTIONS_COMPARATOR);
                result = Stream.concat(result, finishedBuilds);
            }
            return FinderDataBinding.getItemHolder(result);
        }
    } else {
        agent = null;
    }
    // process by build states
    final List<BuildPromotion> result = new ArrayList<BuildPromotion>();
    Set<Long> includedPromotionIds = new HashSet<>();
    @Nullable Set<SBuildType> buildTypes = getBuildTypes(locator);
    String agentName;
    String agentNameCondition = locator.lookupSingleDimensionValue(AGENT_NAME);
    if (agentNameCondition != null) {
        agentName = ParameterCondition.createValueCondition(agentNameCondition).getConstantValueIfSimpleEqualsCondition();
        if (agentName != null)
            locator.markUsed(Collections.singleton(AGENT_NAME));
    } else {
        agentName = null;
    }
    Long agentTypeId = locator.getSingleDimensionValueAsLong(AGENT_TYPE_ID);
    Locator stateLocator = getStateLocator(locator);
    if (isStateIncluded(stateLocator, STATE_QUEUED)) {
        // todo: should sort backwards as currently the order does not seem right...
        Stream<SQueuedBuild> builds = myBuildQueue.getItems().stream();
        if (buildTypes != null) {
            // make sure buildTypes retrieved from the locator are used
            builds = builds.filter(qb -> buildTypes.contains(qb.getBuildPromotion().getParentBuildType()));
        }
        if (agentTypeId != null) {
            builds = builds.filter(build -> build.getCanRunOnAgents().stream().anyMatch(a -> a.getAgentTypeId() == agentTypeId.intValue()));
        }
        if (agent != null) {
            // todo: check
            builds = builds.filter(build -> build.getCanRunOnAgents().stream().anyMatch(a -> a.equals(agent)));
        }
        if (agentName != null) {
            builds = builds.filter(build -> build.getCanRunOnAgents().stream().anyMatch(a -> a.getName().equals(agentName)));
        }
        builds.map(b -> b.getBuildPromotion()).forEach(p -> {
            if (includedPromotionIds.add(p.getId())) {
                result.add(p);
            }
        });
    }
    if (isStateIncluded(stateLocator, STATE_RUNNING)) {
        Stream<SRunningBuild> builds = myBuildsManager.getRunningBuilds().stream();
        if (buildTypes != null) {
            // make sure buildTypes retrieved from the locator are used
            builds = builds.filter(b -> buildTypes.contains(b.getBuildPromotion().getParentBuildType()));
        }
        if (agentTypeId != null) {
            builds = builds.filter(build -> build.getAgent().getAgentTypeId() == agentTypeId.intValue());
        }
        if (agent != null) {
            builds = builds.filter(build -> {
                SBuildAgent buildAgent = build.getAgent();
                int agentId = buildAgent.getId();
                return agentId > 0 ? agent.getId() == agentId : agent.getName().equals(buildAgent.getName());
            });
        }
        if (agentName != null) {
            builds = builds.filter(build -> build.getAgentName().equals(agentName));
        }
        builds.map(b -> b.getBuildPromotion()).forEach(p -> {
            if (includedPromotionIds.add(p.getId())) {
                result.add(p);
            }
        });
    }
    ItemHolder<BuildPromotion> finishedBuilds = null;
    if (isStateIncluded(stateLocator, STATE_FINISHED)) {
        final BuildQueryOptions options = new BuildQueryOptions();
        if (buildTypes != null) {
            options.setBuildTypeIds(buildTypes.stream().map(bt -> bt.getBuildTypeId()).collect(Collectors.toList()));
        }
        if (agentTypeId != null) {
            options.setAgentTypeId(agentTypeId.intValue());
        }
        if (agent != null) {
            options.setAgent(agent);
        }
        if (agentName != null) {
            options.setAgentName(agentName);
        }
        final Boolean personal = locator.lookupSingleDimensionValueAsBoolean(PERSONAL);
        if (personal == null || personal) {
            final String userDimension = locator.getSingleDimensionValue(USER);
            options.setIncludePersonal(true, userDimension == null ? null : myUserFinder.getItem(userDimension));
        } else {
            options.setIncludePersonal(false, null);
        }
        final Boolean failedToStart = locator.lookupSingleDimensionValueAsBoolean(FAILED_TO_START);
        final Boolean canceled = locator.lookupSingleDimensionValueAsBoolean(CANCELED);
        if (canceled == null || canceled || failedToStart == null || failedToStart) {
            // also includes failed to start builds, TW-32060
            options.setIncludeCanceled(true);
        } else {
            options.setIncludeCanceled(false);
        }
        final Boolean pinned = locator.getSingleDimensionValueAsBoolean(PINNED);
        if (pinned != null) {
            options.setPinStatus(pinned);
        }
        TagFinder.FilterOptions tagFilterOptions = TagFinder.getFilterOptions(locator.lookupDimensionValue(TAG), myServiceLocator);
        if (tagFilterOptions != null) {
            options.setTagName(tagFilterOptions.getTagName(), tagFilterOptions.getTagOwner());
        }
        // do not mark dimension as used as not all can be used from it
        final String branchLocatorValue = locator.lookupSingleDimensionValue(BRANCH);
        if (branchLocatorValue != null) {
            BranchFinder.BranchFilterDetails branchFilterDetails;
            try {
                branchFilterDetails = myBranchFinder.getBranchFilterDetailsWithoutLocatorCheck(branchLocatorValue);
                // parsed OK, setting options
                if (branchFilterDetails.isAnyBranch()) {
                    options.setMatchAllBranches(true);
                } else {
                    if (branchFilterDetails.isDefaultBranchOrNotBranched()) {
                        options.setMatchAllBranches(false);
                        options.setBranch(Branch.DEFAULT_BRANCH_NAME);
                    }
                    if (branchFilterDetails.getBranchName() != null) {
                        // causes a bug in certain cases, see https://youtrack.jetbrains.com/issue/TW-61530 however, no performant fix is possible so far
                        options.setMatchAllBranches(false);
                        options.setBranch(branchFilterDetails.getBranchName());
                    }
                }
            } catch (LocatorProcessException e) {
                // not parsed, cannot extract name or default status
                options.setMatchAllBranches(true);
            }
        } else {
            options.setMatchAllBranches(true);
        }
        // running builds are retrieved separately and appear before finished ones
        options.setIncludeRunning(false);
        options.setOrderByChanges(false);
        Long count = locator.getSingleDimensionValueAsLong(PagerData.COUNT);
        if (count != null) {
            options.setPageSize(count.intValue());
        }
        finishedBuilds = new ItemHolder<BuildPromotion>() {

            public void process(@NotNull final ItemProcessor<BuildPromotion> processor) {
                myBuildsManager.processBuilds(options, new ItemProcessor<SBuild>() {

                    public boolean processItem(SBuild item) {
                        // ignore already added builds
                        if (includedPromotionIds.contains(item.getBuildPromotion().getId()))
                            return true;
                        return processor.processItem(item.getBuildPromotion());
                    }
                });
            }
        };
    }
    stateLocator.checkLocatorFullyProcessed();
    final ItemHolder<BuildPromotion> finishedBuildsFinal = finishedBuilds;
    return new ItemHolder<BuildPromotion>() {

        public void process(@NotNull final ItemProcessor<BuildPromotion> processor) {
            new CollectionItemHolder<BuildPromotion>(result).process(processor);
            if (finishedBuildsFinal != null) {
                finishedBuildsFinal.process(processor);
            }
        }
    };
}
Also used : LocatorProcessException(jetbrains.buildServer.server.rest.errors.LocatorProcessException) MetadataStorageEx(jetbrains.buildServer.serverSide.metadata.impl.MetadataStorageEx) Filter(jetbrains.buildServer.util.filters.Filter) java.util(java.util) LocatorName(jetbrains.buildServer.server.rest.swagger.constants.LocatorName) LocatorResource(jetbrains.buildServer.server.rest.swagger.annotations.LocatorResource) Agent(jetbrains.buildServer.server.rest.model.agent.Agent) BuildDependency(jetbrains.buildServer.serverSide.dependency.BuildDependency) Converter(jetbrains.buildServer.util.Converter) ParametersProvider(jetbrains.buildServer.parameters.ParametersProvider) BadRequestException(jetbrains.buildServer.server.rest.errors.BadRequestException) LocatorDimensionDataType(jetbrains.buildServer.server.rest.swagger.constants.LocatorDimensionDataType) AbstractMapParametersProvider(jetbrains.buildServer.parameters.impl.AbstractMapParametersProvider) TestOccurrenceFinder(jetbrains.buildServer.server.rest.data.problem.TestOccurrenceFinder) AccessDeniedException(jetbrains.buildServer.serverSide.auth.AccessDeniedException) ErrorData(jetbrains.buildServer.messages.ErrorData) StringUtil(jetbrains.buildServer.util.StringUtil) Build(jetbrains.buildServer.server.rest.model.build.Build) Logger(com.intellij.openapi.diagnostic.Logger) CollectionsUtil(jetbrains.buildServer.util.CollectionsUtil) jetbrains.buildServer.server.rest.data.util(jetbrains.buildServer.server.rest.data.util) PagerData(jetbrains.buildServer.server.rest.model.PagerData) SVcsRoot(jetbrains.buildServer.vcs.SVcsRoot) PatternSyntaxException(java.util.regex.PatternSyntaxException) Constants(jetbrains.buildServer.server.rest.request.Constants) ServiceLocator(jetbrains.buildServer.ServiceLocator) jetbrains.buildServer.serverSide(jetbrains.buildServer.serverSide) ItemsProviders(jetbrains.buildServer.server.rest.model.ItemsProviders) TagFinder(jetbrains.buildServer.server.rest.data.build.TagFinder) ItemProcessor(jetbrains.buildServer.util.ItemProcessor) StreamUtil(jetbrains.buildServer.server.rest.util.StreamUtil) Collectors(java.util.stream.Collectors) Nullable(org.jetbrains.annotations.Nullable) CommonLocatorDimensionsList(jetbrains.buildServer.server.rest.swagger.constants.CommonLocatorDimensionsList) Stream(java.util.stream.Stream) LocatorDimension(jetbrains.buildServer.server.rest.swagger.annotations.LocatorDimension) Util(jetbrains.buildServer.server.rest.model.Util) Permission(jetbrains.buildServer.serverSide.auth.Permission) NotFoundException(jetbrains.buildServer.server.rest.errors.NotFoundException) TestFinder(jetbrains.buildServer.server.rest.data.problem.TestFinder) BuildMetadataEntry(jetbrains.buildServer.serverSide.metadata.BuildMetadataEntry) Pattern(java.util.regex.Pattern) NotNull(org.jetbrains.annotations.NotNull) SUser(jetbrains.buildServer.users.SUser) ServiceLocator(jetbrains.buildServer.ServiceLocator) ItemProcessor(jetbrains.buildServer.util.ItemProcessor) TagFinder(jetbrains.buildServer.server.rest.data.build.TagFinder) TestOccurrenceFinder(jetbrains.buildServer.server.rest.data.problem.TestOccurrenceFinder) Nullable(org.jetbrains.annotations.Nullable) NotNull(org.jetbrains.annotations.NotNull) LocatorProcessException(jetbrains.buildServer.server.rest.errors.LocatorProcessException) BuildMetadataEntry(jetbrains.buildServer.serverSide.metadata.BuildMetadataEntry) BadRequestException(jetbrains.buildServer.server.rest.errors.BadRequestException) NotNull(org.jetbrains.annotations.NotNull)

Example 13 with LocatorProcessException

use of jetbrains.buildServer.server.rest.errors.LocatorProcessException in project teamcity-rest by JetBrains.

the class BuildPromotionFinder method findSingleItem.

@Nullable
@Override
public BuildPromotion findSingleItem(@NotNull final Locator locator) {
    if (locator.isSingleValue()) {
        @NotNull final Long singleValueAsLong;
        try {
            // noinspection ConstantConditions
            singleValueAsLong = locator.getSingleValueAsLong();
        } catch (LocatorProcessException e) {
            throw new BadRequestException("Invalid single value: '" + locator.getSingleValue() + "'. Should be a numeric build id", e);
        }
        // difference from 9.0 behavior where we never searched by promotion id in case of single value locators
        return getBuildPromotionById(singleValueAsLong, myBuildPromotionManager, myBuildsManager);
    }
    Long promotionId = locator.getSingleDimensionValueAsLong(PROMOTION_ID);
    if (promotionId == null) {
        // support TeamCity 8.0 dimension
        promotionId = locator.getSingleDimensionValueAsLong(PROMOTION_ID_ALIAS);
    }
    if (promotionId != null) {
        return BuildFinder.getBuildPromotion(promotionId, myBuildPromotionManager);
    }
    Long buildId = locator.getSingleDimensionValueAsLong(BUILD_ID);
    if (buildId != null) {
        final SBuild build = myBuildsManager.findBuildInstanceById(buildId);
        if (build != null) {
            return build.getBuildPromotion();
        }
        throw new NotFoundException("No build found by build id '" + buildId + "'.");
    }
    final Long id = locator.getSingleDimensionValueAsLong(DIMENSION_ID);
    if (id != null) {
        return getBuildPromotionById(id, myBuildPromotionManager, myBuildsManager);
    }
    return null;
}
Also used : BadRequestException(jetbrains.buildServer.server.rest.errors.BadRequestException) NotFoundException(jetbrains.buildServer.server.rest.errors.NotFoundException) NotNull(org.jetbrains.annotations.NotNull) LocatorProcessException(jetbrains.buildServer.server.rest.errors.LocatorProcessException) Nullable(org.jetbrains.annotations.Nullable)

Example 14 with LocatorProcessException

use of jetbrains.buildServer.server.rest.errors.LocatorProcessException in project teamcity-rest by JetBrains.

the class BuildFinder method getBuildsForRequest.

public Builds getBuildsForRequest(final SBuildType buildType, final String status, final String userLocator, final boolean includePersonal, final boolean includeCanceled, final boolean onlyPinned, final List<String> tags, final String agentName, final String sinceBuildLocator, final String sinceDate, final Long start, final Integer count, final String locatorText, final String locatorParameterName, final UriInfo uriInfo, final HttpServletRequest request, @NotNull final Fields fields, @NotNull final BeanContext beanContext) {
    boolean legacyFieldsPresent = status != null || userLocator != null || includePersonal || includeCanceled || onlyPinned || (tags != null && !tags.isEmpty()) || agentName != null || sinceBuildLocator != null || sinceDate != null || start != null || // so far buildType is not included here as it can come from context, not query
    count != null;
    String resultingLocatorText;
    Locator locator;
    if (locatorText != null || !legacyFieldsPresent) {
        resultingLocatorText = locatorText;
        try {
            // legacy: override start and count only if set in URL query parameters and not set in locator
            if (resultingLocatorText != null && !(new Locator(resultingLocatorText)).isSingleValue()) {
                if (start != null)
                    resultingLocatorText = Locator.setDimensionIfNotPresent(resultingLocatorText, PagerData.START, String.valueOf(start));
                if (count != null)
                    resultingLocatorText = Locator.setDimensionIfNotPresent(resultingLocatorText, PagerData.COUNT, String.valueOf(count));
            }
        } catch (LocatorProcessException e) {
        // unparsable locator - proceed to report a due error later with all the supported locators
        }
    } else {
        locator = Locator.createEmptyLocator();
        if (buildType != null)
            locator.setDimension("buildType", BuildTypeFinder.getLocator(buildType));
        if (status != null)
            locator.setDimension("status", status);
        if (userLocator != null)
            locator.setDimension("user", userLocator);
        // preserve 5.0 logic for personal/canceled/pinned builds; see also http://youtrack.jetbrains.com/issue/TW-25778
        if (includePersonal)
            locator.setDimension("personal", "any");
        if (includeCanceled)
            locator.setDimension("canceled", "any");
        locator.setDimension("running", "false");
        if (onlyPinned)
            locator.setDimension("pinned", "true");
        // behavior changed comparing to 9.0: not supporting tags with comma here
        if (tags != null && !tags.isEmpty())
            locator.setDimension("tags", StringUtil.join(",", tags));
        if (agentName != null)
            locator.setDimension("agentName", agentName);
        if (sinceBuildLocator != null)
            locator.setDimension("sinceBuild", sinceBuildLocator);
        if (sinceDate != null)
            locator.setDimension("sinceDate", sinceDate);
        if (start != null)
            locator.setDimension(PagerData.START, String.valueOf(start));
        if (count != null)
            locator.setDimension(PagerData.COUNT, String.valueOf(count));
        resultingLocatorText = locator.getStringRepresentation();
    }
    if (legacyFieldsPresent && !TeamCityProperties.getBooleanOrTrue(SUPPORT_NON_LOCATOR_FILTERS)) {
        throw new BadRequestException("Legacy query syntax supplied. Try URL parameter instead: " + locatorParameterName + "=" + resultingLocatorText + "\n" + "Set \"" + SUPPORT_NON_LOCATOR_FILTERS + "=true\" server internal property to allow such legacy queries until next TeamCity upgrade.");
    }
    final PagedSearchResult<BuildPromotion> pagedResult = getBuilds(buildType, resultingLocatorText);
    final PagerData pagerData = new PagerData(uriInfo.getRequestUriBuilder(), request.getContextPath(), pagedResult, locatorText == null ? null : resultingLocatorText, locatorParameterName);
    return Builds.createFromBuildPromotions(pagedResult.myEntries, pagerData, fields, beanContext);
}
Also used : ServiceLocator(jetbrains.buildServer.ServiceLocator) BadRequestException(jetbrains.buildServer.server.rest.errors.BadRequestException) PagerData(jetbrains.buildServer.server.rest.model.PagerData) LocatorProcessException(jetbrains.buildServer.server.rest.errors.LocatorProcessException)

Example 15 with LocatorProcessException

use of jetbrains.buildServer.server.rest.errors.LocatorProcessException in project teamcity-rest by JetBrains.

the class BuildTypeFinder method getFilter.

@NotNull
@Override
public ItemFilter<BuildTypeOrTemplate> getFilter(@NotNull final Locator locator) {
    final MultiCheckerFilter<BuildTypeOrTemplate> result = new MultiCheckerFilter<BuildTypeOrTemplate>();
    if (locator.isUnused(DIMENSION_ID)) {
        final String id = locator.getSingleDimensionValue(DIMENSION_ID);
        if (id != null) {
            result.add(item -> id.equals(item.getId()));
        }
    }
    if (locator.isUnused(DIMENSION_INTERNAL_ID)) {
        final String internalId = locator.getSingleDimensionValue(DIMENSION_INTERNAL_ID);
        if (internalId != null) {
            result.add(item -> internalId.equals(item.getInternalId()));
        }
    }
    if (locator.isUnused(DIMENSION_UUID)) {
        final String uuid = locator.getSingleDimensionValue(DIMENSION_UUID);
        if (uuid != null) {
            result.add(item -> uuid.equals(((BuildTypeIdentityEx) item.getIdentity()).getEntityId().getConfigId()));
        }
    }
    final String name = locator.getSingleDimensionValue(DIMENSION_NAME);
    if (name != null) {
        result.add(new FilterConditionChecker<BuildTypeOrTemplate>() {

            public boolean isIncluded(@NotNull final BuildTypeOrTemplate item) {
                return name.equalsIgnoreCase(item.getName());
            }
        });
    }
    if (locator.isUnused(DIMENSION_PROJECT)) {
        final String projectLocator = locator.getSingleDimensionValue(DIMENSION_PROJECT);
        if (projectLocator != null) {
            final List<SProject> projects = myProjectFinder.getItems(projectLocator).myEntries;
            if (projects.size() == 1) {
                final SProject internalProject = projects.iterator().next();
                result.add(new FilterConditionChecker<BuildTypeOrTemplate>() {

                    public boolean isIncluded(@NotNull final BuildTypeOrTemplate item) {
                        return internalProject.getProjectId().equals(item.getProject().getProjectId());
                    }
                });
            } else {
                result.add(new FilterConditionChecker<BuildTypeOrTemplate>() {

                    public boolean isIncluded(@NotNull final BuildTypeOrTemplate item) {
                        return projects.contains(item.getProject());
                    }
                });
            }
        }
    }
    final String affectedProjectDimension = locator.getSingleDimensionValue(AFFECTED_PROJECT);
    if (affectedProjectDimension != null) {
        @NotNull final SProject parentProject = myProjectFinder.getItem(affectedProjectDimension);
        result.add(new FilterConditionChecker<BuildTypeOrTemplate>() {

            public boolean isIncluded(@NotNull final BuildTypeOrTemplate item) {
                return ProjectFinder.isSameOrParent(parentProject, item.getProject());
            }
        });
    }
    final Boolean paused = locator.getSingleDimensionValueAsBoolean(PAUSED);
    if (paused != null) {
        result.add(new FilterConditionChecker<BuildTypeOrTemplate>() {

            public boolean isIncluded(@NotNull final BuildTypeOrTemplate item) {
                final Boolean pausedState = item.isPaused();
                return FilterUtil.isIncludedByBooleanFilter(paused, pausedState != null && pausedState);
            }
        });
    }
    if (locator.isUnused(BUILD)) {
        String buildLocator = locator.getSingleDimensionValue(BUILD);
        if (buildLocator != null) {
            List<BuildPromotion> builds = myServiceLocator.getSingletonService(BuildPromotionFinder.class).getItems(buildLocator).myEntries;
            Set<String> buldTypeIds = builds.stream().map(build -> build.getBuildType()).filter(Objects::nonNull).map(buildType -> buildType.getInternalId()).collect(Collectors.toSet());
            result.add(item -> buldTypeIds.contains(item.getInternalId()));
        }
    }
    // experimental
    final String compatibleAagentLocator = locator.getSingleDimensionValue(COMPATIBLE_AGENT);
    if (compatibleAagentLocator != null) {
        final List<SBuildAgent> agents = myAgentFinder.getItems(compatibleAagentLocator).myEntries;
        result.add(new FilterConditionChecker<BuildTypeOrTemplate>() {

            public boolean isIncluded(@NotNull final BuildTypeOrTemplate item) {
                if (item.getBuildType() == null)
                    return false;
                for (SBuildAgent agent : agents) {
                    if (AgentFinder.canActuallyRun(agent, item.getBuildType()))
                        return true;
                }
                return false;
            }
        });
    }
    // experimental
    final Long compatibleAgentsCount = locator.getSingleDimensionValueAsLong(COMPATIBLE_AGENTS_COUNT);
    if (compatibleAgentsCount != null) {
        result.add(new FilterConditionChecker<BuildTypeOrTemplate>() {

            public boolean isIncluded(@NotNull final BuildTypeOrTemplate item) {
                if (item.getBuildType() == null)
                    return false;
                long count = 0;
                for (SBuildAgent agent : myAgentFinder.getItems(null).myEntries) {
                    // or should process unauthorized as well?
                    if (AgentFinder.canActuallyRun(agent, item.getBuildType()) && agent.isRegistered() && agent.isAuthorized() && agent.isEnabled())
                        count++;
                    if (count > compatibleAgentsCount)
                        return false;
                }
                return count == compatibleAgentsCount;
            }
        });
    }
    if (locator.isUnused(DIMENSION_SELECTED)) {
        final String selectedByUser = locator.getSingleDimensionValue(DIMENSION_SELECTED);
        if (selectedByUser != null) {
            List<BuildTypeOrTemplate> filterSet = getSelectedByUser(locator, selectedByUser);
            result.add(item -> filterSet.contains(item));
        }
    }
    final String parameterDimension = locator.getSingleDimensionValue(PARAMETER);
    if (parameterDimension != null) {
        final ParameterCondition parameterCondition = ParameterCondition.create(parameterDimension);
        result.add(new FilterConditionChecker<BuildTypeOrTemplate>() {

            public boolean isIncluded(@NotNull final BuildTypeOrTemplate item) {
                final boolean canView = !BuildType.shouldRestrictSettingsViewing(item.get(), myPermissionChecker);
                if (!canView) {
                    LOG.debug("While filtering build types by " + PARAMETER + " user does not have enough permissions to see settings. Excluding build type: " + item.describe(false));
                    return false;
                }
                return parameterCondition.matches(item.get());
            }
        });
    }
    final String settingDimension = locator.getSingleDimensionValue(SETTING);
    if (settingDimension != null) {
        final ParameterCondition condition = ParameterCondition.create(settingDimension);
        result.add(item -> {
            final boolean canView = !BuildType.shouldRestrictSettingsViewing(item.get(), myPermissionChecker);
            if (!canView) {
                LOG.debug("While filtering build types by " + SETTING + " user does not have enough permissions to see settings. Excluding build type: " + item.describe(false));
                return false;
            }
            return condition.matches(new MapParametersProviderImpl(BuildTypeUtil.getSettingsParameters(item, null, true, false)), new MapParametersProviderImpl(BuildTypeUtil.getSettingsParameters(item, null, true, false)));
        });
    }
    final Boolean template = locator.getSingleDimensionValueAsBoolean(TEMPLATE_FLAG_DIMENSION_NAME);
    if (template != null) {
        result.add(new FilterConditionChecker<BuildTypeOrTemplate>() {

            public boolean isIncluded(@NotNull final BuildTypeOrTemplate item) {
                return FilterUtil.isIncludedByBooleanFilter(template, item.isTemplate());
            }
        });
    }
    final String type = locator.getSingleDimensionValue(TYPE);
    if (type != null) {
        String typeOptionValue = TypedFinderBuilder.getEnumValue(type, BuildTypeOptions.BuildConfigurationType.class).name();
        result.add(item -> typeOptionValue.equals(item.get().getOption(BuildTypeOptions.BT_BUILD_CONFIGURATION_TYPE)));
    }
    // experimental
    final String filterBuilds = locator.getSingleDimensionValue(FILTER_BUILDS);
    if (filterBuilds != null) {
        BuildPromotionFinder promotionFinder = myServiceLocator.getSingletonService(BuildPromotionFinder.class);
        FinderSearchMatcher<BuildPromotion> matcher = new FinderSearchMatcher<>(filterBuilds, promotionFinder);
        result.add(new FilterConditionChecker<BuildTypeOrTemplate>() {

            @Override
            public boolean isIncluded(@NotNull final BuildTypeOrTemplate item) {
                SBuildType buildType = item.getBuildType();
                if (buildType == null)
                    return false;
                String defaults = Locator.getStringLocator(BuildPromotionFinder.BUILD_TYPE, BuildTypeFinder.getLocator(buildType), PagerData.COUNT, "1");
                return matcher.matches(defaults);
            }
        });
    }
    final String snapshotDependencies = locator.getSingleDimensionValue(SNAPSHOT_DEPENDENCY);
    if (snapshotDependencies != null) {
        final GraphFinder<BuildTypeOrTemplate> graphFinder = new GraphFinder<BuildTypeOrTemplate>(this, new SnapshotDepsTraverser(myPermissionChecker));
        final List<BuildTypeOrTemplate> boundingList = graphFinder.getItems(snapshotDependencies).myEntries;
        result.add(new FilterConditionChecker<BuildTypeOrTemplate>() {

            public boolean isIncluded(@NotNull final BuildTypeOrTemplate item) {
                return boundingList.contains(item);
            }
        });
    }
    final String artifactDependencies = locator.getSingleDimensionValue(ARTIFACT_DEPENDENCY);
    if (artifactDependencies != null) {
        final GraphFinder<BuildTypeOrTemplate> graphFinder = new GraphFinder<BuildTypeOrTemplate>(this, new ArtifactDepsTraverser(myPermissionChecker));
        final List<BuildTypeOrTemplate> boundingList = graphFinder.getItems(artifactDependencies).myEntries;
        result.add(new FilterConditionChecker<BuildTypeOrTemplate>() {

            public boolean isIncluded(@NotNull final BuildTypeOrTemplate item) {
                return boundingList.contains(item);
            }
        });
    }
    final String templateLocator = locator.getSingleDimensionValue(TEMPLATE_DIMENSION_NAME);
    if (templateLocator != null) {
        try {
            // only this can throw exceptions caught later
            final BuildTypeTemplate buildTemplate = getBuildTemplate(null, templateLocator, true);
            final List<BuildTypeOrTemplate> boundingList = BuildTypes.fromBuildTypes(buildTemplate.getUsages());
            result.add(new FilterConditionChecker<BuildTypeOrTemplate>() {

                public boolean isIncluded(@NotNull final BuildTypeOrTemplate item) {
                    return boundingList.contains(item);
                }
            });
        } catch (NotFoundException e) {
            // legacy support for boolean template
            Boolean legacyTemplateFlag = null;
            try {
                legacyTemplateFlag = locator.getSingleDimensionValueAsBoolean(TEMPLATE_DIMENSION_NAME);
            } catch (LocatorProcessException eNested) {
                // not a boolean, throw original error
                throw new NotFoundException("No templates found by locator '" + templateLocator + "' specified in '" + TEMPLATE_DIMENSION_NAME + "' dimension : " + e.getMessage());
            }
            // legacy request detected
            if (legacyTemplateFlag != null) {
                final boolean legacyTemplateFlagFinal = legacyTemplateFlag;
                result.add(new FilterConditionChecker<BuildTypeOrTemplate>() {

                    public boolean isIncluded(@NotNull final BuildTypeOrTemplate item) {
                        return FilterUtil.isIncludedByBooleanFilter(legacyTemplateFlagFinal, item.isTemplate());
                    }
                });
            }
        } catch (BadRequestException e) {
            throw new BadRequestException("Error while searching for templates by locator '" + templateLocator + "' specified in '" + TEMPLATE_DIMENSION_NAME + "' dimension : " + e.getMessage(), e);
        }
    }
    if (locator.isUnused(VCS_ROOT_DIMENSION)) {
        final String vcsRoot = locator.getSingleDimensionValue(VCS_ROOT_DIMENSION);
        if (vcsRoot != null) {
            final Set<SVcsRoot> vcsRoots = new HashSet<SVcsRoot>(myServiceLocator.getSingletonService(VcsRootFinder.class).getItems(vcsRoot).myEntries);
            result.add(new FilterConditionChecker<BuildTypeOrTemplate>() {

                public boolean isIncluded(@NotNull final BuildTypeOrTemplate item) {
                    for (VcsRootInstanceEntry vcsRootInstanceEntry : item.getVcsRootInstanceEntries()) {
                        if (vcsRoots.contains(vcsRootInstanceEntry.getVcsRoot().getParent()))
                            return true;
                    }
                    return false;
                }
            });
        }
    }
    if (locator.isUnused(VCS_ROOT_INSTANCE_DIMENSION)) {
        final String vcsRootInstance = locator.getSingleDimensionValue(VCS_ROOT_INSTANCE_DIMENSION);
        if (vcsRootInstance != null) {
            final Set<jetbrains.buildServer.vcs.VcsRootInstance> vcsRootInstances = new HashSet<jetbrains.buildServer.vcs.VcsRootInstance>(myServiceLocator.getSingletonService(VcsRootInstanceFinder.class).getItems(vcsRootInstance).myEntries);
            result.add(new FilterConditionChecker<BuildTypeOrTemplate>() {

                public boolean isIncluded(@NotNull final BuildTypeOrTemplate item) {
                    for (VcsRootInstanceEntry vcsRootInstanceEntry : item.getVcsRootInstanceEntries()) {
                        if (vcsRootInstances.contains(vcsRootInstanceEntry.getVcsRoot()))
                            return true;
                    }
                    return false;
                }
            });
        }
    }
    return result;
}
Also used : LocatorProcessException(jetbrains.buildServer.server.rest.errors.LocatorProcessException) java.util(java.util) AuthorizationFailedException(jetbrains.buildServer.server.rest.errors.AuthorizationFailedException) LocatorName(jetbrains.buildServer.server.rest.swagger.constants.LocatorName) LocatorResource(jetbrains.buildServer.server.rest.swagger.annotations.LocatorResource) BuildTypeOrTemplate(jetbrains.buildServer.server.rest.util.BuildTypeOrTemplate) Converter(jetbrains.buildServer.util.Converter) BadRequestException(jetbrains.buildServer.server.rest.errors.BadRequestException) BuildType(jetbrains.buildServer.server.rest.model.buildType.BuildType) LocatorDimensionDataType(jetbrains.buildServer.server.rest.swagger.constants.LocatorDimensionDataType) Dependency(jetbrains.buildServer.serverSide.dependency.Dependency) VcsRootInstanceEntry(jetbrains.buildServer.vcs.VcsRootInstanceEntry) SArtifactDependency(jetbrains.buildServer.serverSide.artifacts.SArtifactDependency) StringUtil(jetbrains.buildServer.util.StringUtil) LogUtil(jetbrains.buildServer.serverSide.impl.LogUtil) Logger(com.intellij.openapi.diagnostic.Logger) CollectionsUtil(jetbrains.buildServer.util.CollectionsUtil) PagerData(jetbrains.buildServer.server.rest.model.PagerData) SVcsRoot(jetbrains.buildServer.vcs.SVcsRoot) ServiceLocator(jetbrains.buildServer.ServiceLocator) BuildTypeUtil(jetbrains.buildServer.server.rest.model.buildType.BuildTypeUtil) jetbrains.buildServer.serverSide(jetbrains.buildServer.serverSide) Collectors(java.util.stream.Collectors) APIController(jetbrains.buildServer.server.rest.APIController) MapParametersProviderImpl(jetbrains.buildServer.parameters.impl.MapParametersProviderImpl) Nullable(org.jetbrains.annotations.Nullable) LocatorDimension(jetbrains.buildServer.server.rest.swagger.annotations.LocatorDimension) Permission(jetbrains.buildServer.serverSide.auth.Permission) NotFoundException(jetbrains.buildServer.server.rest.errors.NotFoundException) BuildTypes(jetbrains.buildServer.server.rest.model.buildType.BuildTypes) NotNull(org.jetbrains.annotations.NotNull) VcsManager(jetbrains.buildServer.vcs.VcsManager) SUser(jetbrains.buildServer.users.SUser) NotFoundException(jetbrains.buildServer.server.rest.errors.NotFoundException) NotNull(org.jetbrains.annotations.NotNull) LocatorProcessException(jetbrains.buildServer.server.rest.errors.LocatorProcessException) SVcsRoot(jetbrains.buildServer.vcs.SVcsRoot) BuildTypeOrTemplate(jetbrains.buildServer.server.rest.util.BuildTypeOrTemplate) VcsRootInstanceEntry(jetbrains.buildServer.vcs.VcsRootInstanceEntry) BadRequestException(jetbrains.buildServer.server.rest.errors.BadRequestException) MapParametersProviderImpl(jetbrains.buildServer.parameters.impl.MapParametersProviderImpl) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

LocatorProcessException (jetbrains.buildServer.server.rest.errors.LocatorProcessException)16 NotNull (org.jetbrains.annotations.NotNull)13 BadRequestException (jetbrains.buildServer.server.rest.errors.BadRequestException)12 ServiceLocator (jetbrains.buildServer.ServiceLocator)8 NotFoundException (jetbrains.buildServer.server.rest.errors.NotFoundException)7 Nullable (org.jetbrains.annotations.Nullable)7 PagerData (jetbrains.buildServer.server.rest.model.PagerData)4 SUser (jetbrains.buildServer.users.SUser)4 Logger (com.intellij.openapi.diagnostic.Logger)3 java.util (java.util)3 Collectors (java.util.stream.Collectors)3 GenericBuildsFilter (jetbrains.buildServer.server.rest.data.build.GenericBuildsFilter)3 LocatorDimension (jetbrains.buildServer.server.rest.swagger.annotations.LocatorDimension)3 LocatorResource (jetbrains.buildServer.server.rest.swagger.annotations.LocatorResource)3 LocatorDimensionDataType (jetbrains.buildServer.server.rest.swagger.constants.LocatorDimensionDataType)3 LocatorName (jetbrains.buildServer.server.rest.swagger.constants.LocatorName)3 jetbrains.buildServer.serverSide (jetbrains.buildServer.serverSide)3 Permission (jetbrains.buildServer.serverSide.auth.Permission)3 CollectionsUtil (jetbrains.buildServer.util.CollectionsUtil)3 Converter (jetbrains.buildServer.util.Converter)3