use of net.nemerosa.ontrack.model.buildfilter.BuildFilterProviderData in project ontrack by nemerosa.
the class GQLRootQueryBuilds method buildFetcher.
private DataFetcher buildFetcher() {
return environment -> {
Integer id = environment.getArgument("id");
Optional<String> oProject = GraphqlUtils.getStringArgument(environment, PROJECT_ARGUMENT);
Optional<String> oBranch = GraphqlUtils.getStringArgument(environment, BRANCH_ARGUMENT);
Object branchFilter = environment.getArgument(BUILD_BRANCH_FILTER_ARGUMENT);
Object projectFilter = environment.getArgument(BUILD_PROJECT_FILTER_ARGUMENT);
// Per ID
if (id != null) {
checkArgList(environment, "id");
return Collections.singletonList(structureService.getBuild(ID.of(id)));
} else // Per project
if (oProject.isPresent()) {
// ... and branch
if (oBranch.isPresent()) {
// Gets the branch
Branch branch = structureService.findBranchByName(oProject.get(), oBranch.get()).orElseThrow(() -> new BranchNotFoundException(oProject.get(), oBranch.get()));
// Configurable branch filter
BuildFilterProviderData<?> filter = inputBuildStandardFilter.convert(branchFilter);
// Runs the filter
return filter.filterBranchBuilds(branch);
} else // Project only
{
// Gets the project
Project project = structureService.findProjectByName(oProject.get()).orElseThrow(() -> new ProjectNotFoundException(oProject.get()));
// Build search form as argument
BuildSearchForm form = inputBuildSearchForm.convert(projectFilter);
return structureService.buildSearch(project.getId(), form);
}
} else // Branch filter only - not accepted
if (branchFilter != null) {
throw new IllegalStateException(String.format("%s must be used together with %s", BUILD_BRANCH_FILTER_ARGUMENT, BRANCH_ARGUMENT));
} else // Project filter only - not accepted
if (projectFilter != null) {
throw new IllegalStateException(String.format("%s must be used together with %s", BUILD_PROJECT_FILTER_ARGUMENT, PROJECT_ARGUMENT));
} else // None
{
return Collections.emptyList();
}
};
}
Aggregations