Search in sources :

Example 1 with BuildProject

use of jetbrains.buildServer.BuildProject in project teamcity-rest by JetBrains.

the class InvestigationFinder method getFilter.

@NotNull
@Override
public ItemFilter<InvestigationWrapper> getFilter(@NotNull final Locator locator) {
    final MultiCheckerFilter<InvestigationWrapper> result = new MultiCheckerFilter<InvestigationWrapper>();
    final String investigatorDimension = locator.getSingleDimensionValue(ASSIGNEE);
    if (investigatorDimension != null) {
        @NotNull final User user = myUserFinder.getItem(investigatorDimension);
        result.add(new FilterConditionChecker<InvestigationWrapper>() {

            public boolean isIncluded(@NotNull final InvestigationWrapper item) {
                return user.equals(item.getResponsibleUser());
            }
        });
    }
    final String reporterDimension = locator.getSingleDimensionValue(REPORTER);
    if (reporterDimension != null) {
        @NotNull final User user = myUserFinder.getItem(reporterDimension);
        result.add(new FilterConditionChecker<InvestigationWrapper>() {

            public boolean isIncluded(@NotNull final InvestigationWrapper item) {
                return user.equals(item.getReporterUser());
            }
        });
    }
    final String typeDimension = locator.getSingleDimensionValue(TYPE);
    if (typeDimension != null) {
        if (ProblemTarget.getKnownTypesForInvestigation().stream().noneMatch(s -> typeDimension.equalsIgnoreCase(s))) {
            throw new BadRequestException("Error in dimension '" + TYPE + "': unknown value '" + typeDimension + "'. Known values: " + StringUtil.join(ProblemTarget.getKnownTypesForInvestigation(), ", "));
        }
        result.add(new FilterConditionChecker<InvestigationWrapper>() {

            public boolean isIncluded(@NotNull final InvestigationWrapper item) {
                return typeDimension.equalsIgnoreCase(ProblemTarget.getType(item));
            }
        });
    }
    final String stateDimension = locator.getSingleDimensionValue(STATE);
    if (stateDimension != null) {
        if (!InvestigationWrapper.getKnownStates().contains(stateDimension.toLowerCase())) {
            throw new BadRequestException("Error in dimension '" + STATE + "': unknown value '" + stateDimension + "'. Known values: " + StringUtil.join(InvestigationWrapper.getKnownStates(), ", "));
        }
        result.add(new FilterConditionChecker<InvestigationWrapper>() {

            public boolean isIncluded(@NotNull final InvestigationWrapper item) {
                return stateDimension.equalsIgnoreCase(item.getState().name());
            }
        });
    }
    final String resolutionDimension = locator.getSingleDimensionValue(RESOLUTION);
    if (resolutionDimension != null) {
        ResponsibilityEntry.RemoveMethod removeMethod = Resolution.getRemoveMethodForInvestigation(resolutionDimension);
        result.add(item -> removeMethod.equals(item.getRemoveMethod()));
    }
    final String assignmentProjectDimension = locator.getSingleDimensionValue(ASSIGNMENT_PROJECT);
    if (assignmentProjectDimension != null) {
        @NotNull final SProject project = myProjectFinder.getItem(assignmentProjectDimension);
        result.add(new FilterConditionChecker<InvestigationWrapper>() {

            public boolean isIncluded(@NotNull final InvestigationWrapper item) {
                final BuildProject assignmentProject = item.getAssignmentProject();
                return assignmentProject != null && project.getProjectId().equals(assignmentProject.getProjectId());
            }
        });
    }
    final String affectedProjectDimension = locator.getSingleDimensionValue(AFFECTED_PROJECT);
    if (affectedProjectDimension != null) {
        @NotNull final SProject project = myProjectFinder.getItem(affectedProjectDimension);
        result.add(new FilterConditionChecker<InvestigationWrapper>() {

            public boolean isIncluded(@NotNull final InvestigationWrapper item) {
                final BuildProject assignmentProject = item.getAssignmentProject();
                final BuildType assignmentBuildType = item.getAssignmentBuildType();
                final BuildProject buildTypeProject = assignmentBuildType != null ? myProjectFinder.findProjectByInternalId(assignmentBuildType.getProjectId()) : null;
                return (assignmentProject != null && ProjectFinder.isSameOrParent(project, assignmentProject)) || (buildTypeProject != null && ProjectFinder.isSameOrParent(project, buildTypeProject));
            }
        });
    }
    final String sinceDateDimension = locator.getSingleDimensionValue(SINCE_DATE);
    if (sinceDateDimension != null) {
        final Date date = DataProvider.getDate(sinceDateDimension);
        result.add(new FilterConditionChecker<InvestigationWrapper>() {

            public boolean isIncluded(@NotNull final InvestigationWrapper item) {
                return date.before(item.getTimestamp());
            }
        });
    }
    // todo: add assignmentBuildType
    return result;
}
Also used : User(jetbrains.buildServer.users.User) BuildProject(jetbrains.buildServer.BuildProject) SProject(jetbrains.buildServer.serverSide.SProject) NotNull(org.jetbrains.annotations.NotNull) Date(java.util.Date) BadRequestException(jetbrains.buildServer.server.rest.errors.BadRequestException) SBuildType(jetbrains.buildServer.serverSide.SBuildType) BuildType(jetbrains.buildServer.BuildType) NotNull(org.jetbrains.annotations.NotNull)

Example 2 with BuildProject

use of jetbrains.buildServer.BuildProject in project teamcity-rest by JetBrains.

the class ProjectFinder method isSameOrParent.

/**
 * Calculates if the project is one of or an (indirect) child of the parent candidates passed
 */
public static boolean isSameOrParent(@NotNull final Collection<? extends BuildProject> parents, @NotNull final BuildProject project) {
    Set<String> projectIds = parents.stream().map(p -> p.getProjectId()).collect(Collectors.toSet());
    BuildProject currentProject = project;
    while (currentProject != null) {
        if (projectIds.contains(currentProject.getProjectId()))
            return true;
        currentProject = currentProject.getParentProject();
    }
    return false;
}
Also used : 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) PropEntityProjectFeature(jetbrains.buildServer.server.rest.model.project.PropEntityProjectFeature) LocatorDimensionDataType(jetbrains.buildServer.server.rest.swagger.constants.LocatorDimensionDataType) AgentPool(jetbrains.buildServer.serverSide.agentPools.AgentPool) AccessDeniedException(jetbrains.buildServer.serverSide.auth.AccessDeniedException) StringUtil(jetbrains.buildServer.util.StringUtil) Logger(com.intellij.openapi.diagnostic.Logger) PagerData(jetbrains.buildServer.server.rest.model.PagerData) SVcsRoot(jetbrains.buildServer.vcs.SVcsRoot) ServiceLocator(jetbrains.buildServer.ServiceLocator) jetbrains.buildServer.serverSide(jetbrains.buildServer.serverSide) Collectors(java.util.stream.Collectors) APIController(jetbrains.buildServer.server.rest.APIController) Project(jetbrains.buildServer.server.rest.model.project.Project) 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) NotNull(org.jetbrains.annotations.NotNull) SUser(jetbrains.buildServer.users.SUser) BuildProject(jetbrains.buildServer.BuildProject) UserEx(jetbrains.buildServer.users.impl.UserEx) BuildProject(jetbrains.buildServer.BuildProject)

Aggregations

BuildProject (jetbrains.buildServer.BuildProject)2 NotNull (org.jetbrains.annotations.NotNull)2 Logger (com.intellij.openapi.diagnostic.Logger)1 java.util (java.util)1 Date (java.util.Date)1 Collectors (java.util.stream.Collectors)1 BuildType (jetbrains.buildServer.BuildType)1 ServiceLocator (jetbrains.buildServer.ServiceLocator)1 APIController (jetbrains.buildServer.server.rest.APIController)1 AuthorizationFailedException (jetbrains.buildServer.server.rest.errors.AuthorizationFailedException)1 BadRequestException (jetbrains.buildServer.server.rest.errors.BadRequestException)1 NotFoundException (jetbrains.buildServer.server.rest.errors.NotFoundException)1 PagerData (jetbrains.buildServer.server.rest.model.PagerData)1 Project (jetbrains.buildServer.server.rest.model.project.Project)1 PropEntityProjectFeature (jetbrains.buildServer.server.rest.model.project.PropEntityProjectFeature)1 LocatorDimension (jetbrains.buildServer.server.rest.swagger.annotations.LocatorDimension)1 LocatorResource (jetbrains.buildServer.server.rest.swagger.annotations.LocatorResource)1 LocatorDimensionDataType (jetbrains.buildServer.server.rest.swagger.constants.LocatorDimensionDataType)1 LocatorName (jetbrains.buildServer.server.rest.swagger.constants.LocatorName)1 BuildTypeOrTemplate (jetbrains.buildServer.server.rest.util.BuildTypeOrTemplate)1