Search in sources :

Example 1 with ActivityAction

use of com.epam.ta.reportportal.entity.activity.ActivityAction in project service-api by reportportal.

the class ActivityBuilderTest method activityBuilderTest.

@Test
void activityBuilderTest() {
    final ActivityAction action = FINISH_LAUNCH;
    final Activity.ActivityEntityType entity = LAUNCH;
    final String objectName = "objectName";
    final Long projectId = 1L;
    final Long userId = 2L;
    final String username = "username";
    final LocalDateTime localDateTime = LocalDateTime.of(2019, 2, 6, 18, 25);
    final Long objectId = 3L;
    Activity activity = new ActivityBuilder().addAction(action).addActivityEntityType(entity).addObjectName(objectName).addProjectId(projectId).addUserId(userId).addObjectId(objectId).addUserName(username).addCreatedAt(localDateTime).addHistoryField("field", "before", "after").get();
    assertEquals(action.getValue(), activity.getAction());
    assertEquals(entity.getValue(), activity.getActivityEntityType());
    assertEquals(objectName, activity.getDetails().getObjectName());
    assertEquals(projectId, activity.getProjectId());
    assertEquals(userId, activity.getUserId());
    assertEquals(objectId, activity.getObjectId());
    assertEquals(username, activity.getUsername());
    assertEquals(localDateTime, activity.getCreatedAt());
}
Also used : LocalDateTime(java.time.LocalDateTime) ActivityAction(com.epam.ta.reportportal.entity.activity.ActivityAction) Activity(com.epam.ta.reportportal.entity.activity.Activity) Test(org.junit.jupiter.api.Test)

Example 2 with ActivityAction

use of com.epam.ta.reportportal.entity.activity.ActivityAction in project service-api by reportportal.

the class GetProjectInfoHandlerImpl method getActivities.

private Map<String, List<ActivityResource>> getActivities(Project project, InfoInterval infoInterval) {
    String value = Arrays.stream(ActivityAction.values()).filter(not(ACTIVITIES_PROJECT_FILTER)).map(ActivityAction::getValue).collect(joining(","));
    Filter filter = new Filter(Activity.class, Lists.newArrayList(new FilterCondition(IN, false, value, CRITERIA_ACTION), new FilterCondition(EQUALS, false, String.valueOf(project.getId()), CRITERIA_PROJECT_ID), new FilterCondition(GREATER_THAN_OR_EQUALS, false, String.valueOf(Timestamp.valueOf(getStartIntervalDate(infoInterval)).getTime()), CRITERIA_CREATION_DATE)));
    List<Activity> activities = activityRepository.findByFilter(filter, PageRequest.of(0, LIMIT, Sort.by(Sort.Direction.DESC, CRITERIA_CREATION_DATE))).getContent();
    Map<Long, String> userIdLoginMapping = userRepository.findAllById(activities.stream().filter(a -> a.getUserId() != null).map(Activity::getUserId).collect(Collectors.toSet())).stream().collect(toMap(User::getId, User::getLogin));
    return Collections.singletonMap(RESULT, activities.stream().map(a -> ofNullable(a.getUserId()).map(userId -> TO_RESOURCE_WITH_USER.apply(a, userIdLoginMapping.get(userId))).orElseGet(() -> TO_RESOURCE.apply(a))).peek(resource -> resource.setProjectName(project.getName())).collect(toList()));
}
Also used : Autowired(org.springframework.beans.factory.annotation.Autowired) ProjectInfo(com.epam.ta.reportportal.entity.project.ProjectInfo) InfoInterval(com.epam.ta.reportportal.entity.enums.InfoInterval) BAD_REQUEST_ERROR(com.epam.ta.reportportal.ws.model.ErrorType.BAD_REQUEST_ERROR) Pageable(org.springframework.data.domain.Pageable) Sort(org.springframework.data.domain.Sort) ZoneOffset(java.time.ZoneOffset) Predicates.not(com.epam.ta.reportportal.commons.Predicates.not) RoundingMode(java.math.RoundingMode) CRITERIA_PROJECT_NAME(com.epam.ta.reportportal.commons.querygen.constant.ProjectCriteriaConstant.CRITERIA_PROJECT_NAME) ProjectInfoResource(com.epam.ta.reportportal.ws.model.project.ProjectInfoResource) GetProjectInfoHandler(com.epam.ta.reportportal.core.project.GetProjectInfoHandler) Launch(com.epam.ta.reportportal.entity.launch.Launch) Predicate(java.util.function.Predicate) Filter(com.epam.ta.reportportal.commons.querygen.Filter) Timestamp(java.sql.Timestamp) ReportPortalException(com.epam.ta.reportportal.exception.ReportPortalException) PageRequest(org.springframework.data.domain.PageRequest) Page(org.springframework.data.domain.Page) Collectors(java.util.stream.Collectors) PagedResourcesAssembler(com.epam.ta.reportportal.ws.converter.PagedResourcesAssembler) ProjectSettingsConverter(com.epam.ta.reportportal.ws.converter.converters.ProjectSettingsConverter) TO_RESOURCE(com.epam.ta.reportportal.ws.converter.converters.ActivityConverter.TO_RESOURCE) Queryable(com.epam.ta.reportportal.commons.querygen.Queryable) LaunchConverter(com.epam.ta.reportportal.ws.converter.converters.LaunchConverter) TO_RESOURCE_WITH_USER(com.epam.ta.reportportal.ws.converter.converters.ActivityConverter.TO_RESOURCE_WITH_USER) Mode(com.epam.ta.reportportal.ws.model.launch.Mode) ActivityResource(com.epam.ta.reportportal.ws.model.ActivityResource) ProjectInfoWidget(com.epam.ta.reportportal.entity.project.email.ProjectInfoWidget) LaunchesPerUser(com.epam.ta.reportportal.ws.model.project.LaunchesPerUser) CRITERIA_PROJECT_ID(com.epam.ta.reportportal.commons.querygen.constant.GeneralCriteriaConstant.CRITERIA_PROJECT_ID) java.util(java.util) Project(com.epam.ta.reportportal.entity.project.Project) LocalDateTime(java.time.LocalDateTime) Activity(com.epam.ta.reportportal.entity.activity.Activity) CRITERIA_ACTION(com.epam.ta.reportportal.commons.querygen.constant.ActivityCriteriaConstant.CRITERIA_ACTION) CRITERIA_PROJECT_CREATION_DATE(com.epam.ta.reportportal.commons.querygen.constant.ProjectCriteriaConstant.CRITERIA_PROJECT_CREATION_DATE) Lists(com.google.common.collect.Lists) Service(org.springframework.stereotype.Service) PROJECT_NOT_FOUND(com.epam.ta.reportportal.ws.model.ErrorType.PROJECT_NOT_FOUND) Condition(com.epam.ta.reportportal.commons.querygen.Condition) ActivityAction(com.epam.ta.reportportal.entity.activity.ActivityAction) Optional.ofNullable(java.util.Optional.ofNullable) LaunchModeEnum(com.epam.ta.reportportal.entity.enums.LaunchModeEnum) User(com.epam.ta.reportportal.entity.user.User) com.epam.ta.reportportal.dao(com.epam.ta.reportportal.dao) DecimalFormat(java.text.DecimalFormat) FilterCondition(com.epam.ta.reportportal.commons.querygen.FilterCondition) CRITERIA_CREATION_DATE(com.epam.ta.reportportal.commons.querygen.constant.ActivityCriteriaConstant.CRITERIA_CREATION_DATE) EntityUtils.normalizeId(com.epam.ta.reportportal.commons.EntityUtils.normalizeId) RESULT(com.epam.ta.reportportal.core.widget.content.constant.ContentLoaderConstants.RESULT) Clock(java.time.Clock) Filter(com.epam.ta.reportportal.commons.querygen.Filter) FilterCondition(com.epam.ta.reportportal.commons.querygen.FilterCondition) Activity(com.epam.ta.reportportal.entity.activity.Activity)

Aggregations

Activity (com.epam.ta.reportportal.entity.activity.Activity)2 ActivityAction (com.epam.ta.reportportal.entity.activity.ActivityAction)2 EntityUtils.normalizeId (com.epam.ta.reportportal.commons.EntityUtils.normalizeId)1 Predicates.not (com.epam.ta.reportportal.commons.Predicates.not)1 Condition (com.epam.ta.reportportal.commons.querygen.Condition)1 Filter (com.epam.ta.reportportal.commons.querygen.Filter)1 FilterCondition (com.epam.ta.reportportal.commons.querygen.FilterCondition)1 Queryable (com.epam.ta.reportportal.commons.querygen.Queryable)1 CRITERIA_ACTION (com.epam.ta.reportportal.commons.querygen.constant.ActivityCriteriaConstant.CRITERIA_ACTION)1 CRITERIA_CREATION_DATE (com.epam.ta.reportportal.commons.querygen.constant.ActivityCriteriaConstant.CRITERIA_CREATION_DATE)1 CRITERIA_PROJECT_ID (com.epam.ta.reportportal.commons.querygen.constant.GeneralCriteriaConstant.CRITERIA_PROJECT_ID)1 CRITERIA_PROJECT_CREATION_DATE (com.epam.ta.reportportal.commons.querygen.constant.ProjectCriteriaConstant.CRITERIA_PROJECT_CREATION_DATE)1 CRITERIA_PROJECT_NAME (com.epam.ta.reportportal.commons.querygen.constant.ProjectCriteriaConstant.CRITERIA_PROJECT_NAME)1 GetProjectInfoHandler (com.epam.ta.reportportal.core.project.GetProjectInfoHandler)1 RESULT (com.epam.ta.reportportal.core.widget.content.constant.ContentLoaderConstants.RESULT)1 com.epam.ta.reportportal.dao (com.epam.ta.reportportal.dao)1 InfoInterval (com.epam.ta.reportportal.entity.enums.InfoInterval)1 LaunchModeEnum (com.epam.ta.reportportal.entity.enums.LaunchModeEnum)1 Launch (com.epam.ta.reportportal.entity.launch.Launch)1 Project (com.epam.ta.reportportal.entity.project.Project)1