use of com.epam.ta.reportportal.entity.preference.UserPreference in project service-api by reportportal.
the class GetPreferenceHandlerImpl method getPreference.
@Override
public PreferenceResource getPreference(ReportPortalUser.ProjectDetails projectDetails, ReportPortalUser user) {
List<UserPreference> userPreferences = userPreferenceRepository.findByProjectIdAndUserId(projectDetails.getProjectId(), user.getUserId());
PreferenceResource preferenceResource = new PreferenceResource();
preferenceResource.setUserId(user.getUserId());
preferenceResource.setProjectId(projectDetails.getProjectId());
List<UserFilterResource> filters = userPreferences.stream().map(it -> UserFilterConverter.TO_FILTER_RESOURCE.apply(it.getFilter())).collect(Collectors.toList());
preferenceResource.setFilters(filters);
return preferenceResource;
}
use of com.epam.ta.reportportal.entity.preference.UserPreference 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.preference.UserPreference in project service-api by reportportal.
the class UpdatePreferenceHandlerImpl method removePreference.
@Override
public OperationCompletionRS removePreference(ReportPortalUser.ProjectDetails projectDetails, ReportPortalUser user, Long filterId) {
UserPreference userPreference = userPreferenceRepository.findByProjectIdAndUserIdAndFilterId(projectDetails.getProjectId(), user.getUserId(), filterId).orElseThrow(() -> new ReportPortalException(ErrorType.USER_FILTER_NOT_FOUND, filterId));
userPreferenceRepository.delete(userPreference);
return new OperationCompletionRS("Filter with id = " + filterId + " successfully removed from launches tab.");
}
use of com.epam.ta.reportportal.entity.preference.UserPreference in project service-api by reportportal.
the class UserPreferenceBuilderTest method userPreferenceBuilder.
@Test
void userPreferenceBuilder() {
final UserFilter filter = new UserFilter();
filter.setName("name");
filter.setOwner("owner");
final Long projectId = 1L;
final Long userId = 2L;
final UserPreference userPreference = new UserPreferenceBuilder().withFilter(filter).withProject(projectId).withUser(userId).get();
assertThat(userPreference.getFilter()).isEqualToComparingFieldByField(filter);
assertEquals(projectId, userPreference.getProject().getId());
assertEquals(userId, userPreference.getUser().getId());
}
Aggregations