use of com.epam.ta.reportportal.commons.querygen.CompositeFilter in project service-api by reportportal.
the class PredefinedFilterCriteriaResolver method resolveArgument.
@Override
public Queryable resolveArgument(MethodParameter methodParameter, ModelAndViewContainer paramModelAndViewContainer, NativeWebRequest webRequest, WebDataBinderFactory paramWebDataBinderFactory) {
Class<?> domainModelType = methodParameter.getParameterAnnotation(FilterFor.class).value();
List<Queryable> filterConditions = webRequest.getParameterMap().entrySet().stream().filter(parameter -> parameter.getKey().startsWith(PREDEFINED_FILTER_PREFIX)).map(parameter -> {
BusinessRule.expect(parameter.getValue(), v -> null != v && v.length == 1).verify(ErrorType.INCORRECT_REQUEST, "Incorrect filter value");
String filterName = parameter.getKey().split("\\.")[1];
String[] filterParameters = parameter.getValue()[0].split(",");
Optional<PredefinedFilterType> predefinedFilterType = PredefinedFilterType.fromString(filterName);
BusinessRule.expect(predefinedFilterType, Optional::isPresent).verify(ErrorType.BAD_REQUEST_ERROR, "Incorrect predefined filter type " + filterName);
BusinessRule.expect(PredefinedFilters.hasFilter(predefinedFilterType.get()), Predicate.isEqual(true)).verify(ErrorType.INCORRECT_REQUEST, "Unknown filter '" + filterName + "'");
final Queryable queryable = PredefinedFilters.buildFilter(predefinedFilterType.get(), filterParameters);
BusinessRule.expect(queryable.getTarget().getClazz(), Predicate.isEqual(domainModelType)).verify(ErrorType.INCORRECT_REQUEST, "Incorrect filter target class type");
return queryable;
}).collect(Collectors.toList());
return filterConditions.isEmpty() ? nop(domainModelType) : new CompositeFilter(Operator.AND, filterConditions);
}
use of com.epam.ta.reportportal.commons.querygen.CompositeFilter in project service-api by reportportal.
the class UserController method export.
@Transactional(readOnly = true)
@GetMapping(value = "/export")
@PreAuthorize(ADMIN_ONLY)
@ApiOperation(value = "Exports information about all users", notes = "Allowable only for users with administrator role")
public void export(@ApiParam(allowableValues = "csv") @RequestParam(value = "view", required = false, defaultValue = "csv") String view, @FilterFor(User.class) Filter filter, @FilterFor(User.class) Queryable queryable, @AuthenticationPrincipal ReportPortalUser currentUser, HttpServletResponse response) {
ReportFormat format = jasperReportHandler.getReportFormat(view);
response.setContentType(format.getContentType());
response.setHeader(com.google.common.net.HttpHeaders.CONTENT_DISPOSITION, String.format("attachment; filename=RP_USERS_%s_Report.%s", format.name(), format.getValue()));
try (OutputStream outputStream = response.getOutputStream()) {
getUserHandler.exportUsers(format, outputStream, new CompositeFilter(Operator.AND, filter, queryable));
} catch (IOException e) {
throw new ReportPortalException(ErrorType.BAD_REQUEST_ERROR, "Unable to write data to the response.");
}
}
use of com.epam.ta.reportportal.commons.querygen.CompositeFilter in project service-api by reportportal.
the class TestItemsHistoryHandlerImpl method getItemsHistory.
@Override
public Iterable<TestItemHistoryElement> getItemsHistory(ReportPortalUser.ProjectDetails projectDetails, Queryable filter, Pageable pageable, HistoryRequestParams historyRequestParams, ReportPortalUser user) {
validateHistoryDepth(historyRequestParams.getHistoryDepth());
CompositeFilter itemHistoryFilter = new CompositeFilter(Operator.AND, filter, Filter.builder().withTarget(filter.getTarget().getClazz()).withCondition(FilterCondition.builder().eq(CRITERIA_PROJECT_ID, String.valueOf(projectDetails.getProjectId())).build()).withCondition(FilterCondition.builder().eq(CRITERIA_LAUNCH_MODE, LaunchModeEnum.DEFAULT.name()).build()).withCondition(FilterCondition.builder().eq(CRITERIA_HAS_STATS, String.valueOf(Boolean.TRUE)).build()).build());
Page<TestItemHistory> testItemHistoryPage = historyProviderFactory.getProvider(historyRequestParams).orElseThrow(() -> new ReportPortalException(UNABLE_LOAD_TEST_ITEM_HISTORY, "Unable to find suitable history baseline provider")).provide(itemHistoryFilter, pageable, historyRequestParams, projectDetails, user, !oldHistory);
return buildHistoryElements(oldHistory ? TestItemResource::getUniqueId : testItemResource -> String.valueOf(testItemResource.getTestCaseHash()), testItemHistoryPage, projectDetails.getProjectId(), pageable);
}
use of com.epam.ta.reportportal.commons.querygen.CompositeFilter in project service-api by reportportal.
the class ProjectController method exportProjects.
@Transactional(readOnly = true)
@PreAuthorize(ADMIN_ONLY)
@GetMapping(value = "/export")
@ResponseStatus(HttpStatus.OK)
@ApiOperation(value = "Exports information about all projects", notes = "Allowable only for users with administrator role")
public void exportProjects(@ApiParam(allowableValues = "csv") @RequestParam(value = "view", required = false, defaultValue = "csv") String view, @FilterFor(ProjectInfo.class) Filter filter, @FilterFor(ProjectInfo.class) Queryable predefinedFilter, @AuthenticationPrincipal ReportPortalUser user, HttpServletResponse response) {
ReportFormat format = jasperReportHandler.getReportFormat(view);
response.setContentType(format.getContentType());
response.setHeader(CONTENT_DISPOSITION, String.format("attachment; filename=RP_PROJECTS_%s_Report.%s", format.name(), format.getValue()));
try (OutputStream outputStream = response.getOutputStream()) {
getProjectHandler.exportProjects(format, new CompositeFilter(Operator.AND, filter, predefinedFilter), outputStream);
} catch (IOException e) {
throw new ReportPortalException(ErrorType.BAD_REQUEST_ERROR, "Unable to write data to the response.");
}
}
Aggregations