use of jetbrains.buildServer.BuildProject 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.BuildProject in project teamcity-rest by JetBrains.
the class ProjectFinder method isSameOrParent.
/**
* Calculates if the project is one of or an (indirect) child of the parent candidates passed
*/
public static boolean isSameOrParent(@NotNull final Collection<? extends BuildProject> parents, @NotNull final BuildProject project) {
Set<String> projectIds = parents.stream().map(p -> p.getProjectId()).collect(Collectors.toSet());
BuildProject currentProject = project;
while (currentProject != null) {
if (projectIds.contains(currentProject.getProjectId()))
return true;
currentProject = currentProject.getParentProject();
}
return false;
}
Aggregations