Search in sources :

Example 1 with UserFilter

use of com.epam.ta.reportportal.entity.filter.UserFilter in project service-api by reportportal.

the class FilterCollector method collect.

@Override
public List<Long> collect(Long filerId, Launch launch) {
    UserFilter userFilter = userFilterRepository.findByIdAndProjectId(filerId, launch.getProjectId()).orElseThrow(() -> new ReportPortalException(ErrorType.USER_FILTER_NOT_FOUND_IN_PROJECT, filerId, launch.getProjectId()));
    ObjectType targetClass = userFilter.getTargetClass();
    expect(targetClass, equalTo(ObjectType.Launch)).verify(ErrorType.INCORRECT_FILTER_PARAMETERS, formattedSupplier("Filter type '{}' is not supported", targetClass));
    Filter filter = ProjectFilter.of(new Filter(targetClass.getClassObject(), Lists.newArrayList(userFilter.getFilterCondition())), launch.getProjectId());
    PageRequest pageable = PageRequest.of(0, LAUNCHES_FILTER_LIMIT, Sort.by(DESC, CRITERIA_START_TIME));
    return launchRepository.findByFilter(filter, pageable).stream().map(Launch::getId).collect(Collectors.toList());
}
Also used : ObjectType(com.epam.ta.reportportal.entity.filter.ObjectType) PageRequest(org.springframework.data.domain.PageRequest) ReportPortalException(com.epam.ta.reportportal.exception.ReportPortalException) UserFilter(com.epam.ta.reportportal.entity.filter.UserFilter) Filter(com.epam.ta.reportportal.commons.querygen.Filter) ProjectFilter(com.epam.ta.reportportal.commons.querygen.ProjectFilter) UserFilter(com.epam.ta.reportportal.entity.filter.UserFilter)

Example 2 with UserFilter

use of com.epam.ta.reportportal.entity.filter.UserFilter in project service-api by reportportal.

the class UpdatePreferenceHandlerImpl method addPreference.

@Override
public OperationCompletionRS addPreference(ReportPortalUser.ProjectDetails projectDetails, ReportPortalUser user, Long filterId) {
    if (userPreferenceRepository.findByProjectIdAndUserIdAndFilterId(projectDetails.getProjectId(), user.getUserId(), filterId).isPresent()) {
        throw new ReportPortalException(ErrorType.RESOURCE_ALREADY_EXISTS, "User Preference");
    }
    UserFilter filter = getShareableEntityHandler.getPermitted(filterId, projectDetails);
    UserPreference userPreference = new UserPreferenceBuilder().withUser(user.getUserId()).withProject(projectDetails.getProjectId()).withFilter(filter).get();
    userPreferenceRepository.save(userPreference);
    return new OperationCompletionRS("Filter with id = " + filterId + " successfully added to launches tab.");
}
Also used : UserPreferenceBuilder(com.epam.ta.reportportal.ws.converter.builders.UserPreferenceBuilder) ReportPortalException(com.epam.ta.reportportal.exception.ReportPortalException) UserFilter(com.epam.ta.reportportal.entity.filter.UserFilter) UserPreference(com.epam.ta.reportportal.entity.preference.UserPreference) OperationCompletionRS(com.epam.ta.reportportal.ws.model.OperationCompletionRS)

Example 3 with UserFilter

use of com.epam.ta.reportportal.entity.filter.UserFilter in project service-api by reportportal.

the class UserFilterControllerTest method createFilterPositive.

@Test
void createFilterPositive() throws Exception {
    String name = "userFilter";
    String description = "description";
    UpdateUserFilterRQ request = new UpdateUserFilterRQ();
    request.setName(name);
    request.setObjectType("Launch");
    final Order order = new Order();
    order.setIsAsc(false);
    order.setSortingColumnName("startTime");
    request.setOrders(Lists.newArrayList(order));
    request.setDescription(description);
    request.setConditions(Sets.newHashSet(new UserFilterCondition("name", "cnt", "test")));
    MvcResult mvcResult = mockMvc.perform(post(DEFAULT_PROJECT_BASE_URL + "/filter").with(token(oAuthHelper.getDefaultToken())).content(objectMapper.writeValueAsBytes(request)).contentType(APPLICATION_JSON)).andExpect(status().isCreated()).andReturn();
    EntryCreatedRS response = objectMapper.readValue(mvcResult.getResponse().getContentAsString(), new TypeReference<EntryCreatedRS>() {
    });
    final Optional<UserFilter> optionalFilter = repository.findById(response.getId());
    assertTrue(optionalFilter.isPresent());
    assertEquals(name, optionalFilter.get().getName());
    assertEquals(description, optionalFilter.get().getDescription());
}
Also used : Order(com.epam.ta.reportportal.ws.model.filter.Order) UpdateUserFilterRQ(com.epam.ta.reportportal.ws.model.filter.UpdateUserFilterRQ) UserFilterCondition(com.epam.ta.reportportal.ws.model.filter.UserFilterCondition) UserFilter(com.epam.ta.reportportal.entity.filter.UserFilter) EntryCreatedRS(com.epam.ta.reportportal.ws.model.EntryCreatedRS) MvcResult(org.springframework.test.web.servlet.MvcResult) BaseMvcTest(com.epam.ta.reportportal.ws.BaseMvcTest) Test(org.junit.jupiter.api.Test)

Example 4 with UserFilter

use of com.epam.ta.reportportal.entity.filter.UserFilter in project service-api by reportportal.

the class DeleteUserFilterHandlerImpl method deleteFilter.

@Override
public OperationCompletionRS deleteFilter(Long id, ReportPortalUser.ProjectDetails projectDetails, ReportPortalUser user) {
    UserFilter userFilter = getShareableEntityHandler.getAdministrated(id, projectDetails);
    expect(userFilter.getProject().getId(), Predicate.isEqual(projectDetails.getProjectId())).verify(USER_FILTER_NOT_FOUND, id, projectDetails.getProjectId(), user.getUserId());
    userFilterRepository.delete(userFilter);
    aclHandler.deleteAclForObject(userFilter);
    messageBus.publishActivity(new FilterDeletedEvent(TO_ACTIVITY_RESOURCE.apply(userFilter), user.getUserId(), user.getUsername()));
    return new OperationCompletionRS("User filter with ID = '" + id + "' successfully deleted.");
}
Also used : FilterDeletedEvent(com.epam.ta.reportportal.core.events.activity.FilterDeletedEvent) UserFilter(com.epam.ta.reportportal.entity.filter.UserFilter) OperationCompletionRS(com.epam.ta.reportportal.ws.model.OperationCompletionRS)

Example 5 with UserFilter

use of com.epam.ta.reportportal.entity.filter.UserFilter in project service-api by reportportal.

the class UpdateUserFilterHandlerImpl method updateUserFilter.

@Override
public OperationCompletionRS updateUserFilter(Long userFilterId, UpdateUserFilterRQ updateRQ, ReportPortalUser.ProjectDetails projectDetails, ReportPortalUser user) {
    validateFilterRq(updateRQ);
    UserFilter userFilter = getShareableEntityHandler.getAdministrated(userFilterId, projectDetails);
    expect(userFilter.getProject().getId(), Predicate.isEqual(projectDetails.getProjectId())).verify(USER_FILTER_NOT_FOUND, userFilterId, projectDetails.getProjectId(), user.getUserId());
    if (!userFilter.getName().equals(updateRQ.getName())) {
        BusinessRule.expect(userFilterRepository.existsByNameAndOwnerAndProjectId(updateRQ.getName(), userFilter.getOwner(), projectDetails.getProjectId()), BooleanUtils::isFalse).verify(ErrorType.USER_FILTER_ALREADY_EXISTS, updateRQ.getName(), userFilter.getOwner(), projectDetails.getProjectName());
    }
    UserFilterActivityResource before = TO_ACTIVITY_RESOURCE.apply(userFilter);
    UserFilter updated = new UserFilterBuilder(userFilter).addFilterRq(updateRQ).get();
    if (before.isShared() != updated.isShared()) {
        aclHandler.updateAcl(updated, projectDetails.getProjectId(), updated.isShared());
    }
    messageBus.publishActivity(new FilterUpdatedEvent(before, TO_ACTIVITY_RESOURCE.apply(updated), user.getUserId(), user.getUsername()));
    return new OperationCompletionRS("User filter with ID = '" + updated.getId() + "' successfully updated.");
}
Also used : UserFilterActivityResource(com.epam.ta.reportportal.ws.model.activity.UserFilterActivityResource) UserFilter(com.epam.ta.reportportal.entity.filter.UserFilter) FilterUpdatedEvent(com.epam.ta.reportportal.core.events.activity.FilterUpdatedEvent) UserFilterBuilder(com.epam.ta.reportportal.ws.converter.builders.UserFilterBuilder) OperationCompletionRS(com.epam.ta.reportportal.ws.model.OperationCompletionRS)

Aggregations

UserFilter (com.epam.ta.reportportal.entity.filter.UserFilter)23 Filter (com.epam.ta.reportportal.commons.querygen.Filter)7 Widget (com.epam.ta.reportportal.entity.widget.Widget)7 ReportPortalException (com.epam.ta.reportportal.exception.ReportPortalException)7 Test (org.junit.jupiter.api.Test)7 ReportPortalUser (com.epam.ta.reportportal.commons.ReportPortalUser)6 FilterSort (com.epam.ta.reportportal.entity.filter.FilterSort)5 ProjectFilter (com.epam.ta.reportportal.commons.querygen.ProjectFilter)4 WidgetBuilder (com.epam.ta.reportportal.ws.converter.builders.WidgetBuilder)4 Condition (com.epam.ta.reportportal.commons.querygen.Condition)3 DashboardWidget (com.epam.ta.reportportal.entity.dashboard.DashboardWidget)3 ObjectType (com.epam.ta.reportportal.entity.filter.ObjectType)3 Project (com.epam.ta.reportportal.entity.project.Project)3 ErrorType (com.epam.ta.reportportal.ws.model.ErrorType)3 OperationCompletionRS (com.epam.ta.reportportal.ws.model.OperationCompletionRS)3 Order (com.epam.ta.reportportal.ws.model.filter.Order)3 UpdateUserFilterRQ (com.epam.ta.reportportal.ws.model.filter.UpdateUserFilterRQ)3 UserFilterCondition (com.epam.ta.reportportal.ws.model.filter.UserFilterCondition)3 WidgetRQ (com.epam.ta.reportportal.ws.model.widget.WidgetRQ)3 List (java.util.List)3