Search in sources :

Example 1 with ResponsibilityFacadeEx

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

the class Investigation method getFromPostedAndApply.

@NotNull
public List<InvestigationWrapper> getFromPostedAndApply(@NotNull final ServiceLocator serviceLocator, final boolean allowMultipleResult) {
    checkIsValid();
    if (target == null) {
        throw new BadRequestException("Invalid 'investigation' entity: 'target' should be specified");
    }
    ProblemTarget.ProblemTargetData targetData;
    try {
        targetData = target.getFromPosted(serviceLocator);
    } catch (BadRequestException e) {
        throw new BadRequestException("Invalid 'investigation' entity: " + e.getMessage());
    }
    ResponsibilityEntry entry = new ResponsibilityEntryEx(TypedFinderBuilder.getEnumValue(state, ResponsibilityEntry.State.class), assignee.getFromPosted(serviceLocator.getSingletonService(UserFinder.class)), serviceLocator.getSingletonService(UserFinder.class).getCurrentUser(), new Date(), assignment == null || assignment.getTextFromPosted() == null ? "" : assignment.getTextFromPosted(), resolution.getFromPostedForInvestigation(serviceLocator));
    ResponsibilityFacadeEx responsibilityFacade = serviceLocator.getSingletonService(ResponsibilityFacadeEx.class);
    InvestigationFinder investigationFinder = serviceLocator.findSingletonService(InvestigationFinder.class);
    assert investigationFinder != null;
    List<InvestigationWrapper> resultEntries = new ArrayList<>(1);
    if (targetData.isAnyProblem()) {
        List<BuildType> buildTypesFromPosted = scope.getBuildTypesFromPosted(serviceLocator);
        if (!allowMultipleResult && buildTypesFromPosted.size() > 1) {
            throw new OnlySingleEntitySupportedException("Invalid 'scope' entity: for this request only single buildType is supported within 'buildTypes' entity");
        }
        for (BuildType buildType : buildTypesFromPosted) {
            responsibilityFacade.setBuildTypeResponsibility(buildType, entry);
            resultEntries.add(investigationFinder.getItem(InvestigationFinder.getLocator((SBuildType) buildType)));
        }
    } else {
        if (scope.buildTypes != null) {
            throw new BadRequestException("Invalid 'investigation' entity: Invalid 'scope' entity: 'buildTypes' should not be specified for not buildType-level investigation");
        }
        SProject project = scope.getProjectFromPosted(serviceLocator);
        List<STest> tests = targetData.getTests();
        if (!tests.isEmpty()) {
            if (!allowMultipleResult && tests.size() > 1) {
                throw new OnlySingleEntitySupportedException("Invalid 'target' entity: for this request only single test is supported within 'tests' entity");
            }
            responsibilityFacade.setTestNameResponsibility(tests.stream().map(sTest -> sTest.getName()).distinct().collect(Collectors.toList()), project.getProjectId(), entry);
            tests.stream().map(test -> // only one item should be found in the project
            investigationFinder.getItem(InvestigationFinder.getLocatorForTest(test.getTestNameId(), project))).distinct().forEachOrdered(resultEntries::add);
        }
        List<Long> problems = targetData.getProblemIds();
        if (!problems.isEmpty()) {
            if (!allowMultipleResult && problems.size() > 1) {
                throw new OnlySingleEntitySupportedException("Invalid 'target' entity: for this request only single problem is supported within 'problems' entity");
            }
            responsibilityFacade.setBuildProblemResponsibility(// seems like only id is used inside
            problems.stream().distinct().map(problemId -> ProblemWrapper.getBuildProblemInfo(problemId.intValue(), project.getProjectId())).collect(Collectors.toList()), project.getProjectId(), entry);
            problems.stream().distinct().map(problemId -> // only one item should be found in the project
            investigationFinder.getItem(InvestigationFinder.getLocatorForProblem(problemId.intValue(), project))).forEachOrdered(resultEntries::add);
        }
    }
    if (!allowMultipleResult && resultEntries.size() != 1) {
        throw new BadRequestException("Invalid 'investigation' entity: Invalid 'target' entity: found " + resultEntries.size() + " result entities, while exactly one is required");
    }
    return resultEntries;
}
Also used : Fields(jetbrains.buildServer.server.rest.model.Fields) User(jetbrains.buildServer.server.rest.model.user.User) Date(java.util.Date) InvestigationFinder(jetbrains.buildServer.server.rest.data.investigations.InvestigationFinder) ArrayList(java.util.ArrayList) BadRequestException(jetbrains.buildServer.server.rest.errors.BadRequestException) ResponsibilityEntryEx(jetbrains.buildServer.responsibility.ResponsibilityEntryEx) XmlType(javax.xml.bind.annotation.XmlType) Comment(jetbrains.buildServer.server.rest.model.Comment) STest(jetbrains.buildServer.serverSide.STest) TypedFinderBuilder(jetbrains.buildServer.server.rest.data.TypedFinderBuilder) InvestigationWrapper(jetbrains.buildServer.server.rest.data.investigations.InvestigationWrapper) Api(io.swagger.annotations.Api) SBuildType(jetbrains.buildServer.serverSide.SBuildType) ModelDescription(jetbrains.buildServer.server.rest.swagger.annotations.ModelDescription) XmlAttribute(javax.xml.bind.annotation.XmlAttribute) TeamCityProperties(jetbrains.buildServer.serverSide.TeamCityProperties) ProblemWrapper(jetbrains.buildServer.server.rest.data.problem.ProblemWrapper) ServiceLocator(jetbrains.buildServer.ServiceLocator) BuildType(jetbrains.buildServer.BuildType) XmlRootElement(javax.xml.bind.annotation.XmlRootElement) ValueWithDefault(jetbrains.buildServer.server.rest.util.ValueWithDefault) Collectors(java.util.stream.Collectors) List(java.util.List) ResponsibilityEntry(jetbrains.buildServer.responsibility.ResponsibilityEntry) Resolution(jetbrains.buildServer.server.rest.model.problem.Resolution) ResponsibilityFacadeEx(jetbrains.buildServer.responsibility.ResponsibilityFacadeEx) SProject(jetbrains.buildServer.serverSide.SProject) UserFinder(jetbrains.buildServer.server.rest.data.UserFinder) BeanContext(jetbrains.buildServer.server.rest.util.BeanContext) NotNull(org.jetbrains.annotations.NotNull) ApiModelProperty(io.swagger.annotations.ApiModelProperty) InvestigationRequest(jetbrains.buildServer.server.rest.request.InvestigationRequest) XmlElement(javax.xml.bind.annotation.XmlElement) InvestigationWrapper(jetbrains.buildServer.server.rest.data.investigations.InvestigationWrapper) ResponsibilityFacadeEx(jetbrains.buildServer.responsibility.ResponsibilityFacadeEx) ArrayList(java.util.ArrayList) ResponsibilityEntryEx(jetbrains.buildServer.responsibility.ResponsibilityEntryEx) InvestigationFinder(jetbrains.buildServer.server.rest.data.investigations.InvestigationFinder) SProject(jetbrains.buildServer.serverSide.SProject) Date(java.util.Date) BadRequestException(jetbrains.buildServer.server.rest.errors.BadRequestException) ResponsibilityEntry(jetbrains.buildServer.responsibility.ResponsibilityEntry) SBuildType(jetbrains.buildServer.serverSide.SBuildType) BuildType(jetbrains.buildServer.BuildType) STest(jetbrains.buildServer.serverSide.STest) NotNull(org.jetbrains.annotations.NotNull)

Example 2 with ResponsibilityFacadeEx

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

the class BaseFinderTest method initFinders.

protected void initFinders() {
    myVcsManager = myFixture.getVcsManager();
    myFixture.addService(myVcsManager);
    myFixture.addService(myProjectManager);
    myPermissionChecker = new PermissionChecker(myServer.getSecurityContext(), myProjectManager);
    myFixture.addService(myPermissionChecker);
    myTimeCondition = new TimeCondition(myFixture);
    myFixture.addService(myTimeCondition);
    myProjectFinder = new ProjectFinder(myProjectManager, myPermissionChecker, myServer);
    myFixture.addService(myProjectFinder);
    myAgentFinder = new AgentFinder(myAgentManager, myFixture);
    myFixture.addService(myAgentFinder);
    myAgentPoolFinder = new AgentPoolFinder(myFixture.getAgentPoolManager(), myAgentFinder, myFixture);
    myFixture.addService(myAgentPoolFinder);
    myBuildTypeFinder = new BuildTypeFinder(myProjectManager, myProjectFinder, myAgentFinder, myPermissionChecker, myServer);
    myFixture.addService(myBuildTypeFinder);
    final VcsRootIdentifiersManagerImpl vcsRootIdentifiersManager = myFixture.getSingletonService(VcsRootIdentifiersManagerImpl.class);
    myVcsRootFinder = new VcsRootFinder(myVcsManager, myProjectFinder, myBuildTypeFinder, myProjectManager, vcsRootIdentifiersManager, myPermissionChecker);
    myFixture.addService(myVcsRootFinder);
    myVcsRootInstanceFinder = new VcsRootInstanceFinder(myVcsRootFinder, myVcsManager, myProjectFinder, myBuildTypeFinder, myProjectManager, myFixture.getSingletonService(VersionedSettingsManager.class), myTimeCondition, myPermissionChecker, myServer);
    myFixture.addService(myVcsRootInstanceFinder);
    myGroupFinder = new UserGroupFinder(getUserGroupManager());
    myFixture.addService(myGroupFinder);
    myUserFinder = new UserFinder(getUserModelEx(), myGroupFinder, myProjectFinder, myTimeCondition, myFixture.getRolesManager(), myPermissionChecker, myServer.getSecurityContext(), myServer);
    myFixture.addService(myUserFinder);
    myBranchFinder = new BranchFinder(myBuildTypeFinder, myFixture);
    myBuildPromotionFinder = new BuildPromotionFinder(myFixture.getBuildPromotionManager(), myFixture.getBuildQueue(), myServer, myVcsRootFinder, myProjectFinder, myBuildTypeFinder, myUserFinder, myAgentFinder, myBranchFinder, myTimeCondition, myPermissionChecker, null, myFixture);
    myFixture.addService(myBuildPromotionFinder);
    myBuildFinder = new BuildFinder(myServer, myBuildTypeFinder, myProjectFinder, myUserFinder, myBuildPromotionFinder, myAgentFinder);
    myFixture.addService(myBuildFinder);
    final TestName2Index testName2Index = myFixture.getSingletonService(TestName2Index.class);
    final ProblemMutingService problemMutingService = myFixture.getSingletonService(ProblemMutingService.class);
    myTestFinder = new TestFinder(myProjectFinder, myBuildTypeFinder, myBuildPromotionFinder, myFixture.getTestManager(), testName2Index, myFixture.getCurrentProblemsManager(), problemMutingService);
    myFixture.addService(myTestFinder);
    TestScopeFilterProducer filterProducer = new TestScopeFilterProducer(myBuildTypeFinder);
    final CurrentProblemsManager currentProblemsManager = myServer.getSingletonService(CurrentProblemsManager.class);
    myTestOccurrenceFinder = new TestOccurrenceFinder(myServer.getSecurityContext(), myTestFinder, myBuildFinder, myBuildTypeFinder, myProjectFinder, myFixture.getTestsHistory(), currentProblemsManager, myBranchFinder, filterProducer);
    myFixture.addService(myTestOccurrenceFinder);
    final BuildProblemManager buildProblemManager = myFixture.getSingletonService(BuildProblemManager.class);
    myProblemFinder = new ProblemFinder(myProjectFinder, myBuildPromotionFinder, buildProblemManager, myProjectManager, myFixture, problemMutingService);
    myFixture.addService(myProblemFinder);
    myProblemOccurrenceFinder = new ProblemOccurrenceFinder(myProjectFinder, myBuildFinder, myProblemFinder, buildProblemManager, myProjectManager, myFixture);
    myFixture.addService(myProblemOccurrenceFinder);
    final ResponsibilityFacadeEx responsibilityFacade = myFixture.getResponsibilityFacadeEx();
    myInvestigationFinder = new InvestigationFinder(myProjectFinder, myBuildTypeFinder, myProblemFinder, myTestFinder, myUserFinder, responsibilityFacade, responsibilityFacade, responsibilityFacade);
    myFixture.addService(myInvestigationFinder);
    myMuteFinder = new MuteFinder(myProjectFinder, myTimeCondition, myPermissionChecker, problemMutingService, (LowLevelProblemMutingServiceImpl) myFixture.getSingletonService(LowLevelProblemMutingService.class), myFixture);
    myFixture.addService(myMuteFinder);
    myQueuedBuildFinder = new QueuedBuildFinder(myServer.getQueue(), myProjectFinder, myBuildTypeFinder, myUserFinder, myAgentFinder, myAgentPoolFinder, myFixture.getBuildPromotionManager(), myServer);
    myFixture.addService(myQueuedBuildFinder);
    myChangeFinder = new ChangeFinder(myProjectFinder, myBuildFinder, myBuildPromotionFinder, myBuildTypeFinder, myVcsRootFinder, myVcsRootInstanceFinder, myUserFinder, myVcsManager, myFixture.getVcsHistory(), myBranchFinder, myFixture, myPermissionChecker);
    myFixture.addService(myChangeFinder);
    myFixture.addService(new HealthItemFinder(myFixture.getSingletonService(HealthStatusProvider.class), myFixture.getSingletonService(HealthStatusReportLocator.class), myFixture));
}
Also used : LowLevelProblemMutingService(jetbrains.buildServer.serverSide.mute.LowLevelProblemMutingService) ResponsibilityFacadeEx(jetbrains.buildServer.responsibility.ResponsibilityFacadeEx) VcsRootIdentifiersManagerImpl(jetbrains.buildServer.serverSide.identifiers.VcsRootIdentifiersManagerImpl) InvestigationFinder(jetbrains.buildServer.server.rest.data.investigations.InvestigationFinder) MuteFinder(jetbrains.buildServer.server.rest.data.mutes.MuteFinder) LowLevelProblemMutingService(jetbrains.buildServer.serverSide.mute.LowLevelProblemMutingService) ProblemMutingService(jetbrains.buildServer.serverSide.mute.ProblemMutingService) BuildProblemManager(jetbrains.buildServer.serverSide.problems.BuildProblemManager) CurrentProblemsManager(jetbrains.buildServer.serverSide.CurrentProblemsManager) TestName2Index(jetbrains.buildServer.serverSide.TestName2Index) TestOccurrenceFinder(jetbrains.buildServer.server.rest.data.problem.TestOccurrenceFinder) ProblemOccurrenceFinder(jetbrains.buildServer.server.rest.data.problem.ProblemOccurrenceFinder) TestScopeFilterProducer(jetbrains.buildServer.server.rest.data.problem.scope.TestScopeFilterProducer) TestFinder(jetbrains.buildServer.server.rest.data.problem.TestFinder) ProblemFinder(jetbrains.buildServer.server.rest.data.problem.ProblemFinder) LowLevelProblemMutingServiceImpl(jetbrains.buildServer.serverSide.mute.LowLevelProblemMutingServiceImpl)

Aggregations

ResponsibilityFacadeEx (jetbrains.buildServer.responsibility.ResponsibilityFacadeEx)2 InvestigationFinder (jetbrains.buildServer.server.rest.data.investigations.InvestigationFinder)2 Api (io.swagger.annotations.Api)1 ApiModelProperty (io.swagger.annotations.ApiModelProperty)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 List (java.util.List)1 Collectors (java.util.stream.Collectors)1 XmlAttribute (javax.xml.bind.annotation.XmlAttribute)1 XmlElement (javax.xml.bind.annotation.XmlElement)1 XmlRootElement (javax.xml.bind.annotation.XmlRootElement)1 XmlType (javax.xml.bind.annotation.XmlType)1 BuildType (jetbrains.buildServer.BuildType)1 ServiceLocator (jetbrains.buildServer.ServiceLocator)1 ResponsibilityEntry (jetbrains.buildServer.responsibility.ResponsibilityEntry)1 ResponsibilityEntryEx (jetbrains.buildServer.responsibility.ResponsibilityEntryEx)1 TypedFinderBuilder (jetbrains.buildServer.server.rest.data.TypedFinderBuilder)1 UserFinder (jetbrains.buildServer.server.rest.data.UserFinder)1 InvestigationWrapper (jetbrains.buildServer.server.rest.data.investigations.InvestigationWrapper)1 MuteFinder (jetbrains.buildServer.server.rest.data.mutes.MuteFinder)1