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);
}
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);
}
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;
}
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);
}
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());
}
Aggregations