Search in sources :

Example 1 with UserPreference

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;
}
Also used : List(java.util.List) ReportPortalUser(com.epam.ta.reportportal.commons.ReportPortalUser) GetPreferenceHandler(com.epam.ta.reportportal.core.preference.GetPreferenceHandler) Service(org.springframework.stereotype.Service) UserFilterConverter(com.epam.ta.reportportal.ws.converter.converters.UserFilterConverter) UserPreference(com.epam.ta.reportportal.entity.preference.UserPreference) Autowired(org.springframework.beans.factory.annotation.Autowired) UserFilterResource(com.epam.ta.reportportal.ws.model.filter.UserFilterResource) PreferenceResource(com.epam.ta.reportportal.ws.model.preference.PreferenceResource) Collectors(java.util.stream.Collectors) UserPreferenceRepository(com.epam.ta.reportportal.dao.UserPreferenceRepository) UserPreference(com.epam.ta.reportportal.entity.preference.UserPreference) PreferenceResource(com.epam.ta.reportportal.ws.model.preference.PreferenceResource) UserFilterResource(com.epam.ta.reportportal.ws.model.filter.UserFilterResource)

Example 2 with UserPreference

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

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.");
}
Also used : ReportPortalException(com.epam.ta.reportportal.exception.ReportPortalException) UserPreference(com.epam.ta.reportportal.entity.preference.UserPreference) OperationCompletionRS(com.epam.ta.reportportal.ws.model.OperationCompletionRS)

Example 4 with UserPreference

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());
}
Also used : UserFilter(com.epam.ta.reportportal.entity.filter.UserFilter) UserPreference(com.epam.ta.reportportal.entity.preference.UserPreference) Test(org.junit.jupiter.api.Test)

Aggregations

UserPreference (com.epam.ta.reportportal.entity.preference.UserPreference)4 UserFilter (com.epam.ta.reportportal.entity.filter.UserFilter)2 ReportPortalException (com.epam.ta.reportportal.exception.ReportPortalException)2 OperationCompletionRS (com.epam.ta.reportportal.ws.model.OperationCompletionRS)2 ReportPortalUser (com.epam.ta.reportportal.commons.ReportPortalUser)1 GetPreferenceHandler (com.epam.ta.reportportal.core.preference.GetPreferenceHandler)1 UserPreferenceRepository (com.epam.ta.reportportal.dao.UserPreferenceRepository)1 UserPreferenceBuilder (com.epam.ta.reportportal.ws.converter.builders.UserPreferenceBuilder)1 UserFilterConverter (com.epam.ta.reportportal.ws.converter.converters.UserFilterConverter)1 UserFilterResource (com.epam.ta.reportportal.ws.model.filter.UserFilterResource)1 PreferenceResource (com.epam.ta.reportportal.ws.model.preference.PreferenceResource)1 List (java.util.List)1 Collectors (java.util.stream.Collectors)1 Test (org.junit.jupiter.api.Test)1 Autowired (org.springframework.beans.factory.annotation.Autowired)1 Service (org.springframework.stereotype.Service)1