Search in sources :

Example 1 with CompositeFilter

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);
}
Also used : BusinessRule(com.epam.ta.reportportal.commons.validation.BusinessRule) WebDataBinderFactory(org.springframework.web.bind.support.WebDataBinderFactory) HandlerMethodArgumentResolver(org.springframework.web.method.support.HandlerMethodArgumentResolver) Predicate(java.util.function.Predicate) Filter(com.epam.ta.reportportal.commons.querygen.Filter) ModelAndViewContainer(org.springframework.web.method.support.ModelAndViewContainer) ErrorType(com.epam.ta.reportportal.ws.model.ErrorType) Operator(org.jooq.Operator) Collectors(java.util.stream.Collectors) PredefinedFilterType(com.epam.ta.reportportal.core.filter.predefined.PredefinedFilterType) NativeWebRequest(org.springframework.web.context.request.NativeWebRequest) List(java.util.List) Queryable(com.epam.ta.reportportal.commons.querygen.Queryable) MethodParameter(org.springframework.core.MethodParameter) PredefinedFilters(com.epam.ta.reportportal.core.filter.predefined.PredefinedFilters) Optional(java.util.Optional) CompositeFilter(com.epam.ta.reportportal.commons.querygen.CompositeFilter) Collections(java.util.Collections) CompositeFilter(com.epam.ta.reportportal.commons.querygen.CompositeFilter) Optional(java.util.Optional) Queryable(com.epam.ta.reportportal.commons.querygen.Queryable)

Example 2 with CompositeFilter

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.");
    }
}
Also used : CompositeFilter(com.epam.ta.reportportal.commons.querygen.CompositeFilter) ReportPortalException(com.epam.ta.reportportal.exception.ReportPortalException) ReportFormat(com.epam.ta.reportportal.entity.jasper.ReportFormat) OutputStream(java.io.OutputStream) IOException(java.io.IOException) ApiOperation(io.swagger.annotations.ApiOperation) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) Transactional(org.springframework.transaction.annotation.Transactional)

Example 3 with CompositeFilter

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);
}
Also used : CRITERIA_PROJECT_ID(com.epam.ta.reportportal.commons.querygen.constant.GeneralCriteriaConstant.CRITERIA_PROJECT_ID) TestItem(com.epam.ta.reportportal.entity.item.TestItem) TestItemHistory(com.epam.ta.reportportal.entity.item.history.TestItemHistory) Autowired(org.springframework.beans.factory.annotation.Autowired) Operator(org.jooq.Operator) Function(java.util.function.Function) TestItemsHistoryHandler(com.epam.ta.reportportal.core.item.history.TestItemsHistoryHandler) Value(org.springframework.beans.factory.annotation.Value) MIN_HISTORY_DEPTH_BOUND(com.epam.ta.reportportal.ws.model.ValidationConstraints.MIN_HISTORY_DEPTH_BOUND) Lists(com.google.common.collect.Lists) ReportPortalUser(com.epam.ta.reportportal.commons.ReportPortalUser) TestItemResource(com.epam.ta.reportportal.ws.model.TestItemResource) Service(org.springframework.stereotype.Service) TestItemConverter(com.epam.ta.reportportal.ws.converter.converters.TestItemConverter) Map(java.util.Map) UNABLE_LOAD_TEST_ITEM_HISTORY(com.epam.ta.reportportal.ws.model.ErrorType.UNABLE_LOAD_TEST_ITEM_HISTORY) Pageable(org.springframework.data.domain.Pageable) CRITERIA_LAUNCH_MODE(com.epam.ta.reportportal.commons.querygen.constant.LaunchCriteriaConstant.CRITERIA_LAUNCH_MODE) TestItemRepository(com.epam.ta.reportportal.dao.TestItemRepository) CRITERIA_HAS_STATS(com.epam.ta.reportportal.commons.querygen.constant.TestItemCriteriaConstant.CRITERIA_HAS_STATS) TestItemHistoryElement(com.epam.ta.reportportal.ws.model.TestItemHistoryElement) BusinessRule(com.epam.ta.reportportal.commons.validation.BusinessRule) Predicate(java.util.function.Predicate) Optional.ofNullable(java.util.Optional.ofNullable) Filter(com.epam.ta.reportportal.commons.querygen.Filter) LaunchModeEnum(com.epam.ta.reportportal.entity.enums.LaunchModeEnum) TestItemUpdaterContent(com.epam.ta.reportportal.ws.converter.utils.item.content.TestItemUpdaterContent) ReportPortalException(com.epam.ta.reportportal.exception.ReportPortalException) PageableExecutionUtils(org.springframework.data.repository.support.PageableExecutionUtils) FilterCondition(com.epam.ta.reportportal.commons.querygen.FilterCondition) Page(org.springframework.data.domain.Page) Collectors(java.util.stream.Collectors) PagedResourcesAssembler(com.epam.ta.reportportal.ws.converter.PagedResourcesAssembler) List(java.util.List) HistoryProviderFactory(com.epam.ta.reportportal.core.item.impl.history.provider.HistoryProviderFactory) Queryable(com.epam.ta.reportportal.commons.querygen.Queryable) Optional(java.util.Optional) CompositeFilter(com.epam.ta.reportportal.commons.querygen.CompositeFilter) Suppliers(com.epam.ta.reportportal.commons.validation.Suppliers) MAX_HISTORY_DEPTH_BOUND(com.epam.ta.reportportal.ws.model.ValidationConstraints.MAX_HISTORY_DEPTH_BOUND) ResourceUpdater(com.epam.ta.reportportal.ws.converter.utils.ResourceUpdater) HistoryRequestParams(com.epam.ta.reportportal.core.item.impl.history.param.HistoryRequestParams) ResourceUpdaterProvider(com.epam.ta.reportportal.ws.converter.utils.ResourceUpdaterProvider) CompositeFilter(com.epam.ta.reportportal.commons.querygen.CompositeFilter) ReportPortalException(com.epam.ta.reportportal.exception.ReportPortalException) TestItemHistory(com.epam.ta.reportportal.entity.item.history.TestItemHistory)

Example 4 with CompositeFilter

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.");
    }
}
Also used : CompositeFilter(com.epam.ta.reportportal.commons.querygen.CompositeFilter) ReportPortalException(com.epam.ta.reportportal.exception.ReportPortalException) ReportFormat(com.epam.ta.reportportal.entity.jasper.ReportFormat) OutputStream(java.io.OutputStream) IOException(java.io.IOException) ApiOperation(io.swagger.annotations.ApiOperation) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

CompositeFilter (com.epam.ta.reportportal.commons.querygen.CompositeFilter)4 ReportPortalException (com.epam.ta.reportportal.exception.ReportPortalException)3 Filter (com.epam.ta.reportportal.commons.querygen.Filter)2 Queryable (com.epam.ta.reportportal.commons.querygen.Queryable)2 BusinessRule (com.epam.ta.reportportal.commons.validation.BusinessRule)2 ReportFormat (com.epam.ta.reportportal.entity.jasper.ReportFormat)2 ApiOperation (io.swagger.annotations.ApiOperation)2 IOException (java.io.IOException)2 List (java.util.List)2 Optional (java.util.Optional)2 Predicate (java.util.function.Predicate)2 Collectors (java.util.stream.Collectors)2 Operator (org.jooq.Operator)2 ReportPortalUser (com.epam.ta.reportportal.commons.ReportPortalUser)1 FilterCondition (com.epam.ta.reportportal.commons.querygen.FilterCondition)1 CRITERIA_PROJECT_ID (com.epam.ta.reportportal.commons.querygen.constant.GeneralCriteriaConstant.CRITERIA_PROJECT_ID)1 CRITERIA_LAUNCH_MODE (com.epam.ta.reportportal.commons.querygen.constant.LaunchCriteriaConstant.CRITERIA_LAUNCH_MODE)1 CRITERIA_HAS_STATS (com.epam.ta.reportportal.commons.querygen.constant.TestItemCriteriaConstant.CRITERIA_HAS_STATS)1 Suppliers (com.epam.ta.reportportal.commons.validation.Suppliers)1 PredefinedFilterType (com.epam.ta.reportportal.core.filter.predefined.PredefinedFilterType)1