Search in sources :

Example 1 with User

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

the class InvestigationFinder method getPrefilteredItems.

@NotNull
@Override
public ItemHolder<InvestigationWrapper> getPrefilteredItems(@NotNull final Locator locator) {
    final String problemDimension = locator.getSingleDimensionValue(PROBLEM_DIMENSION);
    if (problemDimension != null) {
        final ProblemWrapper problem = myProblemFinder.getItem(problemDimension);
        return getItemHolder(problem.getInvestigations());
    }
    final String testDimension = locator.getSingleDimensionValue(TEST_DIMENSION);
    if (testDimension != null) {
        final STest test = myTestFinder.getItem(testDimension);
        return getItemHolder(getInvestigationWrappers(test));
    }
    final String buildTypeDimension = locator.getSingleDimensionValue(BUILD_TYPE);
    if (buildTypeDimension != null) {
        final SBuildType buildType = myBuildTypeFinder.getBuildType(null, buildTypeDimension, false);
        return getItemHolder(getInvestigationWrappersForBuildType(buildType));
    }
    @Nullable User user = null;
    final String investigatorDimension = locator.getSingleDimensionValue(ASSIGNEE);
    if (investigatorDimension != null) {
        user = myUserFinder.getItem(investigatorDimension);
    }
    final String assignmentProjectDimension = locator.getSingleDimensionValue(ASSIGNMENT_PROJECT);
    if (assignmentProjectDimension != null) {
        @NotNull final SProject project = myProjectFinder.getItem(assignmentProjectDimension);
        return getItemHolder(getInvestigationWrappersForProject(project, user));
    }
    final String affectedProjectDimension = locator.getSingleDimensionValue(AFFECTED_PROJECT);
    if (affectedProjectDimension != null) {
        @NotNull final SProject project = myProjectFinder.getItem(affectedProjectDimension);
        return getItemHolder(getInvestigationWrappersForProjectWithSubprojects(project, user));
    }
    if (user != null) {
        return getItemHolder(getInvestigationWrappersForProjectWithSubprojects(myProjectFinder.getRootProject(), user));
    }
    locator.markUnused(ASSIGNEE);
    return getItemHolder(getInvestigationWrappersForProjectWithSubprojects(myProjectFinder.getRootProject(), null));
}
Also used : User(jetbrains.buildServer.users.User) SBuildType(jetbrains.buildServer.serverSide.SBuildType) ProblemWrapper(jetbrains.buildServer.server.rest.data.problem.ProblemWrapper) STest(jetbrains.buildServer.serverSide.STest) SProject(jetbrains.buildServer.serverSide.SProject) NotNull(org.jetbrains.annotations.NotNull) Nullable(org.jetbrains.annotations.Nullable) NotNull(org.jetbrains.annotations.NotNull)

Example 2 with User

use of jetbrains.buildServer.users.User 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 3 with User

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

the class DebugRequest method getCurrentSession.

@GET
@Path("/currentRequest/session")
@Produces({ "application/xml", "application/json" })
public Session getCurrentSession(@Context HttpServletRequest request, @QueryParam("fields") final String fields, @Context @NotNull final BeanContext beanContext) {
    User currentUser = myServiceLocator.getSingletonService(PermissionChecker.class).getCurrent().getAssociatedUser();
    HttpSession session = request.getSession();
    return new Session(session.getId(), currentUser != null ? currentUser.getId() : null, new Date(session.getCreationTime()), new Date(session.getLastAccessedTime()), new Fields(fields), beanContext);
}
Also used : SessionUser(jetbrains.buildServer.web.util.SessionUser) User(jetbrains.buildServer.users.User) HttpSession(javax.servlet.http.HttpSession) Session(jetbrains.buildServer.server.rest.model.debug.Session) HttpSession(javax.servlet.http.HttpSession)

Example 4 with User

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

the class BuildRequest method addProblemToBuild.

/**
 * Experimental.
 * Adds a build problem with given details. The same as marking the build as failed from UI.
 */
@POST
@Path("/{buildLocator}/problemOccurrences")
@Consumes({ "text/plain" })
@Produces({ "application/xml", "application/json" })
@ApiOperation(value = "Add a build problem to the matching build.", nickname = "addProblemToBuild")
public ProblemOccurrence addProblemToBuild(@ApiParam(format = LocatorName.BUILD) @PathParam("buildLocator") String buildLocator, String problemDetails, @QueryParam("fields") String fields) {
    BuildPromotion buildPromotion = myBuildFinder.getBuildPromotion(null, buildLocator);
    SBuild build = buildPromotion.getAssociatedBuild();
    if (build == null) {
        throw new NotFoundException("No finished build associated with promotion id " + buildPromotion.getId());
    }
    User user = myPermissionChecker.getCurrent().getAssociatedUser();
    if (user == null) {
        throw new BadRequestException("Cannot perform operation: no current user");
    }
    BuildProblemData problemData = build.addUserBuildProblem((SUser) user, problemDetails);
    return new ProblemOccurrence(myBeanContext.getSingletonService(ProblemOccurrenceFinder.class).getProblem(build, problemData), myBeanContext, new Fields(fields));
}
Also used : SessionUser(jetbrains.buildServer.web.util.SessionUser) SUser(jetbrains.buildServer.users.SUser) User(jetbrains.buildServer.users.User) BuildProblemData(jetbrains.buildServer.BuildProblemData) ProblemOccurrence(jetbrains.buildServer.server.rest.model.problem.ProblemOccurrence) ApiOperation(io.swagger.annotations.ApiOperation)

Aggregations

User (jetbrains.buildServer.users.User)4 SBuildType (jetbrains.buildServer.serverSide.SBuildType)2 SProject (jetbrains.buildServer.serverSide.SProject)2 SessionUser (jetbrains.buildServer.web.util.SessionUser)2 NotNull (org.jetbrains.annotations.NotNull)2 ApiOperation (io.swagger.annotations.ApiOperation)1 Date (java.util.Date)1 HttpSession (javax.servlet.http.HttpSession)1 BuildProblemData (jetbrains.buildServer.BuildProblemData)1 BuildProject (jetbrains.buildServer.BuildProject)1 BuildType (jetbrains.buildServer.BuildType)1 ProblemWrapper (jetbrains.buildServer.server.rest.data.problem.ProblemWrapper)1 BadRequestException (jetbrains.buildServer.server.rest.errors.BadRequestException)1 Session (jetbrains.buildServer.server.rest.model.debug.Session)1 ProblemOccurrence (jetbrains.buildServer.server.rest.model.problem.ProblemOccurrence)1 STest (jetbrains.buildServer.serverSide.STest)1 SUser (jetbrains.buildServer.users.SUser)1 Nullable (org.jetbrains.annotations.Nullable)1