use of jetbrains.buildServer.BuildType 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;
}
use of jetbrains.buildServer.BuildType 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;
}
Aggregations