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());
}
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.");
}
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());
}
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.");
}
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.");
}
Aggregations