Search in sources :

Example 1 with InvestigationWrapper

use of jetbrains.buildServer.server.rest.data.investigations.InvestigationWrapper in project teamcity-rest by JetBrains.

the class InvestigationRequest method replaceInstance.

@PUT
@Path("/{investigationLocator}")
@Consumes({ "application/xml", "application/json" })
@Produces({ "application/xml", "application/json" })
@ApiOperation(value = "Update investigation matching the locator.", nickname = "replaceInvestigation")
public Investigation replaceInstance(@ApiParam(format = LocatorName.INVESTIGATION) @PathParam("investigationLocator") String locatorText, Investigation investigation, @QueryParam("fields") String fields) {
    InvestigationWrapper item = myInvestigationFinder.getItem(locatorText);
    item.remove(myServiceLocator);
    return createInstance(investigation, fields);
}
Also used : InvestigationWrapper(jetbrains.buildServer.server.rest.data.investigations.InvestigationWrapper) ApiOperation(io.swagger.annotations.ApiOperation)

Example 2 with InvestigationWrapper

use of jetbrains.buildServer.server.rest.data.investigations.InvestigationWrapper in project teamcity-rest by JetBrains.

the class InvestigationRequest method deleteInstance.

@DELETE
@Path("/{investigationLocator}")
@Produces({ "application/xml", "application/json" })
@ApiOperation(value = "Delete investigation matching the locator.", nickname = "deleteInvestigation")
public void deleteInstance(@ApiParam(format = LocatorName.INVESTIGATION) @PathParam("investigationLocator") String locatorText) {
    InvestigationWrapper item = myInvestigationFinder.getItem(locatorText);
    item.remove(myServiceLocator);
}
Also used : InvestigationWrapper(jetbrains.buildServer.server.rest.data.investigations.InvestigationWrapper) ApiOperation(io.swagger.annotations.ApiOperation)

Example 3 with InvestigationWrapper

use of jetbrains.buildServer.server.rest.data.investigations.InvestigationWrapper 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 4 with InvestigationWrapper

use of jetbrains.buildServer.server.rest.data.investigations.InvestigationWrapper in project teamcity-rest by JetBrains.

the class InvestigationRequestTest method testAssignInvestigation.

@Test
void testAssignInvestigation() throws Throwable {
    final SUser user2 = createUser("user2");
    Investigation investigation = new Investigation();
    investigation.state = "taken";
    investigation.assignee = new User();
    investigation.assignee.setId(user2.getId());
    investigation.assignment = new Comment();
    investigation.assignment.text = "comment here";
    investigation.scope = new ProblemScope();
    investigation.scope.project = new Project();
    investigation.scope.project.id = myProject.getExternalId();
    investigation.target = new ProblemTarget();
    investigation.target.tests = new Tests();
    jetbrains.buildServer.server.rest.model.problem.Test test = new jetbrains.buildServer.server.rest.model.problem.Test();
    test.name = "testname";
    investigation.target.tests.items = Collections.singletonList(test);
    investigation.resolution = new Resolution();
    investigation.resolution.type = Resolution.ResolutionType.manually;
    investigation.resolution.time = "20900512T163700";
    assertEmpty(myInvestigationFinder.getItems(null).myEntries);
    createBuildWithFailedTest("testname");
    Investigation result = myRequest.createInstance(investigation, "$long");
    assertEquals("testname", result.target.tests.items.get(0).name);
    List<InvestigationWrapper> currentInvestigations = myInvestigationFinder.getItems(null).myEntries;
    assertEquals(1, currentInvestigations.size());
    InvestigationWrapper investigationWrapper = currentInvestigations.get(0);
    assertEquals(ResponsibilityEntry.State.TAKEN, investigationWrapper.getState());
    assertEquals(user2.getId(), investigationWrapper.getResponsibleUser().getId());
    assertEquals("comment here", investigationWrapper.getComment());
    assertEquals(null, investigationWrapper.getProblemRE());
    assertEquals(myProject.getProjectId(), investigationWrapper.getTestRE().getProjectId());
    assertEquals("testname", investigationWrapper.getTestRE().getTestName().getAsString());
    assertEquals(myProject.getProjectId(), investigationWrapper.getAssignmentProject().getProjectId());
    myRequest.deleteInstance(investigationWrapper.getId());
    assertEmpty(myInvestigationFinder.getItems(null).myEntries);
}
Also used : Comment(jetbrains.buildServer.server.rest.model.Comment) InvestigationWrapper(jetbrains.buildServer.server.rest.data.investigations.InvestigationWrapper) User(jetbrains.buildServer.server.rest.model.user.User) SUser(jetbrains.buildServer.users.SUser) ProblemTarget(jetbrains.buildServer.server.rest.model.buildType.ProblemTarget) SUser(jetbrains.buildServer.users.SUser) Tests(jetbrains.buildServer.server.rest.model.problem.Tests) ProblemScope(jetbrains.buildServer.server.rest.model.buildType.ProblemScope) Project(jetbrains.buildServer.server.rest.model.project.Project) BaseFinderTest(jetbrains.buildServer.server.rest.data.BaseFinderTest) Test(org.testng.annotations.Test) Investigation(jetbrains.buildServer.server.rest.model.buildType.Investigation) Resolution(jetbrains.buildServer.server.rest.model.problem.Resolution) BaseFinderTest(jetbrains.buildServer.server.rest.data.BaseFinderTest) Test(org.testng.annotations.Test)

Example 5 with InvestigationWrapper

use of jetbrains.buildServer.server.rest.data.investigations.InvestigationWrapper in project teamcity-rest by JetBrains.

the class InvestigationFinderTest method testBuildTypeInvestigation.

@Test
public void testBuildTypeInvestigation() throws Exception {
    createFailingBuild();
    myFixture.getResponsibilityFacadeEx().setBuildTypeResponsibility(myBuildType, createRespEntry(ResponsibilityEntry.State.TAKEN, myUser));
    final PagedSearchResult<InvestigationWrapper> result = myInvestigationFinder.getItems((String) null);
    assertEquals(1, result.myEntries.size());
    final InvestigationWrapper investigation1 = result.myEntries.get(0);
    assertEquals(true, investigation1.isBuildType());
    assertEquals(false, investigation1.isProblem());
    assertEquals(false, investigation1.isTest());
    assertEquals("anyProblem", ProblemTarget.getType(investigation1));
    final BuildTypeResponsibilityEntry buildTypeRE = investigation1.getBuildTypeRE();
    assertEquals(true, buildTypeRE != null);
    assertEquals(myUser, investigation1.getResponsibleUser());
    assertEquals(ResponsibilityEntry.State.TAKEN, investigation1.getState());
}
Also used : InvestigationWrapper(jetbrains.buildServer.server.rest.data.investigations.InvestigationWrapper) BuildTypeResponsibilityEntry(jetbrains.buildServer.responsibility.BuildTypeResponsibilityEntry) Test(org.testng.annotations.Test)

Aggregations

InvestigationWrapper (jetbrains.buildServer.server.rest.data.investigations.InvestigationWrapper)9 Test (org.testng.annotations.Test)5 Investigation (jetbrains.buildServer.server.rest.model.buildType.Investigation)4 Investigations (jetbrains.buildServer.server.rest.model.buildType.Investigations)3 ApiOperation (io.swagger.annotations.ApiOperation)2 BuildProblemResponsibilityEntry (jetbrains.buildServer.responsibility.BuildProblemResponsibilityEntry)2 Comment (jetbrains.buildServer.server.rest.model.Comment)2 Resolution (jetbrains.buildServer.server.rest.model.problem.Resolution)2 User (jetbrains.buildServer.server.rest.model.user.User)2 NotNull (org.jetbrains.annotations.NotNull)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 TreeSet (java.util.TreeSet)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