updated code
This commit is contained in:
@@ -1,11 +1,14 @@
|
||||
package net.gepafin.tendermanagement.dao;
|
||||
|
||||
import jakarta.persistence.criteria.CriteriaBuilder;
|
||||
import jakarta.persistence.criteria.Predicate;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import net.gepafin.tendermanagement.entities.RoleActionContextEntity;
|
||||
import net.gepafin.tendermanagement.entities.UserActionEntity;
|
||||
import net.gepafin.tendermanagement.entities.UserEntity;
|
||||
import net.gepafin.tendermanagement.enums.TimePeriodEnum;
|
||||
import net.gepafin.tendermanagement.enums.UserActionContextEnum;
|
||||
import net.gepafin.tendermanagement.model.response.ActionContextLabelResponse;
|
||||
import net.gepafin.tendermanagement.model.response.SummaryPageResponseBean;
|
||||
import net.gepafin.tendermanagement.model.response.UserActionResponseBean;
|
||||
import net.gepafin.tendermanagement.repositories.AssignedApplicationsRepository;
|
||||
@@ -38,18 +41,16 @@ public class UserActionDao {
|
||||
@Autowired
|
||||
private RoleActionContextRepository roleActionContextRepository;
|
||||
|
||||
public SummaryPageResponseBean getUserAction(HttpServletRequest request, UserEntity userEntity, TimePeriodEnum timeFilter, String actionContext){
|
||||
public SummaryPageResponseBean getUserAction(HttpServletRequest request, UserEntity userEntity, TimePeriodEnum timeFilter, List<UserActionContextEnum> actionContext){
|
||||
Long numberOfLoginAttempts = userActionsRepository.countUserLoginAttempts(userEntity.getId());
|
||||
Long applicationsProcessed = assignedApplicationsRepository.countAssignedApplicationsByUserId(userEntity.getId());
|
||||
|
||||
List<RoleActionContextEntity> actionContextLabel = roleActionContextRepository.findByRoleIdAndIsDeletedFalse(userEntity.getRoleEntity().getId());
|
||||
|
||||
List<UserActionEntity> userActions = getFilterUserActions(userEntity.getId(),timeFilter,actionContext);
|
||||
|
||||
return createSummaryPageResponse(userEntity,numberOfLoginAttempts,applicationsProcessed,actionContextLabel,userActions);
|
||||
return createSummaryPageResponse(userEntity,numberOfLoginAttempts,applicationsProcessed,userActions);
|
||||
}
|
||||
|
||||
public SummaryPageResponseBean createSummaryPageResponse(UserEntity user, Long numberOfLoginAttempts, Long applicationsProcessed, List<RoleActionContextEntity> actionContextLabel, List<UserActionEntity> userActions){
|
||||
public SummaryPageResponseBean createSummaryPageResponse(UserEntity user, Long numberOfLoginAttempts, Long applicationsProcessed, List<UserActionEntity> userActions){
|
||||
SummaryPageResponseBean response = new SummaryPageResponseBean();
|
||||
response.setRole(user.getRoleEntity().getRoleName());
|
||||
response.setLastLogin(user.getLastLogin());
|
||||
@@ -58,11 +59,6 @@ public class UserActionDao {
|
||||
response.setEmail(user.getEmail());
|
||||
response.setNumberOfLoginAttempts(numberOfLoginAttempts);
|
||||
response.setApplicationsProcessed(applicationsProcessed);
|
||||
List<String> actionContextNames = actionContextLabel.stream()
|
||||
.map(RoleActionContextEntity::getActionContext)
|
||||
.collect(Collectors.toList());
|
||||
|
||||
response.setActionContextLabels(actionContextNames);
|
||||
|
||||
List<UserActionResponseBean> userAction = convertEntityToResponse(userActions);
|
||||
response.setUserActions(userAction);
|
||||
@@ -70,12 +66,17 @@ public class UserActionDao {
|
||||
}
|
||||
|
||||
|
||||
public List<UserActionEntity> getFilterUserActions(Long userId ,TimePeriodEnum timeFilter, String actionContext) {
|
||||
public List<UserActionEntity> getFilterUserActions(Long userId ,TimePeriodEnum timeFilter, List<UserActionContextEnum> actionContextList) {
|
||||
LocalDateTime endDate = LocalDateTime.now();
|
||||
LocalDateTime startDate = (timeFilter != null) ? getStartTimeFromFilter(timeFilter) : null;
|
||||
Pageable pageable = PageRequest.of(0, 25);
|
||||
|
||||
Specification<UserActionEntity> spec = getUserActionsSpecification(userId, startDate, endDate, actionContext);
|
||||
// String actionContextLabel = (actionContext != null) ? actionContext.toString() : null;
|
||||
List<String> actionContextLabels = (actionContextList != null && !actionContextList.isEmpty())
|
||||
? actionContextList.stream().map(Enum::toString).collect(Collectors.toList())
|
||||
: null;
|
||||
|
||||
Specification<UserActionEntity> spec = getUserActionsSpecification(userId, startDate, endDate, actionContextLabels);
|
||||
Page<UserActionEntity> pageResult = userActionsRepository.findAll(spec, pageable);
|
||||
|
||||
return pageResult.getContent();
|
||||
@@ -97,7 +98,7 @@ public class UserActionDao {
|
||||
}
|
||||
}
|
||||
|
||||
public Specification<UserActionEntity> getUserActionsSpecification(Long userId, LocalDateTime startDate, LocalDateTime endDate, String actionContext) {
|
||||
public Specification<UserActionEntity> getUserActionsSpecification(Long userId, LocalDateTime startDate, LocalDateTime endDate, List<String> actionContextList) {
|
||||
return (root, query, builder) -> {
|
||||
Predicate predicate = builder.isFalse(root.get("isDeleted"));
|
||||
|
||||
@@ -107,10 +108,14 @@ public class UserActionDao {
|
||||
predicate = builder.and(predicate, builder.between(root.get("createdDate"), startDate, endDate));
|
||||
}
|
||||
|
||||
if (actionContext != null) {
|
||||
predicate = builder.and(predicate, builder.equal(root.get("actionContext"), actionContext));
|
||||
}
|
||||
|
||||
if (actionContextList != null && !actionContextList.isEmpty()) {
|
||||
CriteriaBuilder.In<Object> inClause = builder.in(root.get("actionContext"));
|
||||
for (String actionContext : actionContextList) {
|
||||
inClause.value(actionContext);
|
||||
}
|
||||
predicate = builder.and(predicate, inClause);
|
||||
}
|
||||
query.orderBy(builder.desc(root.get("createdDate")));
|
||||
|
||||
return predicate;
|
||||
@@ -135,4 +140,21 @@ public class UserActionDao {
|
||||
return responseBean;
|
||||
}).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
public List<ActionContextLabelResponse> getActionContextLabels(HttpServletRequest request, UserEntity userEntity){
|
||||
List<RoleActionContextEntity> actionContextLabel = roleActionContextRepository.findActionContextLabel(userEntity.getRoleEntity().getId());
|
||||
return convertRoleContextEntityToResponse(actionContextLabel);
|
||||
}
|
||||
|
||||
private List<ActionContextLabelResponse> convertRoleContextEntityToResponse(List<RoleActionContextEntity> actionContextEntities){
|
||||
return actionContextEntities.stream().map(actionContext -> {
|
||||
ActionContextLabelResponse responseBean = new ActionContextLabelResponse();
|
||||
responseBean.setId(actionContext.getId());
|
||||
responseBean.setActionContext(UserActionContextEnum.valueOf(actionContext.getActionContext()));
|
||||
responseBean.setRoleId(actionContext.getRoleId());
|
||||
responseBean.setDescription(actionContext.getDescription());
|
||||
responseBean.setIsViewed(actionContext.getIsViewed());
|
||||
return responseBean;
|
||||
}).collect(Collectors.toList());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user