updated code
This commit is contained in:
@@ -357,6 +357,7 @@ public class GepafinConstant {
|
||||
public static final String USER_WITH_COMPANY_NOT_FOUND = "user.with.company.not.found";
|
||||
|
||||
public static final String USER_ACTION_FETCHED_SUCCESSFULLY = "user.action.fetched.successfully";
|
||||
public static final String ACTION_CONTEXT_LABELS_FETCHED_SUCCESSFULLY = "action.context.labels.fetched.successfully";
|
||||
//action log response
|
||||
public static final String STATUS_CODE_STRING = "statusCode";
|
||||
public static final String GET_STATUS_CODE_STRING = "status";
|
||||
|
||||
@@ -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());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -166,7 +166,8 @@ public enum UserActionContextEnum {
|
||||
CREATE_APPOINTMENT("CREATE_APPOINTMENT"),
|
||||
UPLOAD_DOCUMENT_TO_EXTERNAL_SYSTEM("UPLOAD_DOCUMENT_TO_EXTERNAL_SYSTEM"),
|
||||
|
||||
GET_USER_ACTION("GET_USER_ACTION");
|
||||
GET_USER_ACTION("GET_USER_ACTION"),
|
||||
GET_ACTION_CONTEXT_LABELS("GET_ACTION_CONTEXT_LABELS");
|
||||
|
||||
private final String value;
|
||||
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
package net.gepafin.tendermanagement.model.response;
|
||||
import lombok.Data;
|
||||
import net.gepafin.tendermanagement.enums.UserActionContextEnum;
|
||||
|
||||
@Data
|
||||
public class ActionContextLabelResponse {
|
||||
private Long id;
|
||||
private UserActionContextEnum actionContext;
|
||||
private Long roleId;
|
||||
private Boolean isViewed;
|
||||
private String description;
|
||||
}
|
||||
@@ -14,6 +14,5 @@ public class SummaryPageResponseBean {
|
||||
private LocalDateTime registrationDate;
|
||||
private Long numberOfLoginAttempts;
|
||||
private Long applicationsProcessed;
|
||||
private List<String> actionContextLabels;
|
||||
private List<UserActionResponseBean> userActions;
|
||||
}
|
||||
|
||||
@@ -3,13 +3,17 @@ package net.gepafin.tendermanagement.repositories;
|
||||
import net.gepafin.tendermanagement.entities.RoleActionContextEntity;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
|
||||
import org.springframework.data.jpa.repository.Query;
|
||||
import org.springframework.data.repository.query.Param;
|
||||
import org.springframework.stereotype.Repository;
|
||||
import java.util.List;
|
||||
|
||||
@Repository
|
||||
public interface RoleActionContextRepository extends JpaRepository<RoleActionContextEntity,Long>, JpaSpecificationExecutor<RoleActionContextEntity> {
|
||||
|
||||
List<RoleActionContextEntity> findByRoleIdAndIsDeletedFalse(Long roleId);
|
||||
@Query("SELECT r FROM RoleActionContextEntity r WHERE r.roleId = :roleId AND r.isDeleted = false AND r.isViewed = true")
|
||||
List<RoleActionContextEntity> findActionContextLabel(@Param("roleId") Long roleId);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -2,8 +2,14 @@ package net.gepafin.tendermanagement.service;
|
||||
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
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 java.util.List;
|
||||
|
||||
public interface UserActionService {
|
||||
public SummaryPageResponseBean getUserAction(HttpServletRequest request, Long userId, TimePeriodEnum timeFilter, String actionContext);
|
||||
public SummaryPageResponseBean getUserAction(HttpServletRequest request, Long userId, TimePeriodEnum timeFilter, List<UserActionContextEnum> actionContext);
|
||||
|
||||
public List<ActionContextLabelResponse> getActionContextLabels(HttpServletRequest request, Long userId);
|
||||
}
|
||||
|
||||
@@ -4,12 +4,16 @@ import jakarta.servlet.http.HttpServletRequest;
|
||||
import net.gepafin.tendermanagement.dao.UserActionDao;
|
||||
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.service.UserActionService;
|
||||
import net.gepafin.tendermanagement.util.Validator;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
public class UserActionServiceImpl implements UserActionService {
|
||||
|
||||
@@ -21,8 +25,14 @@ public class UserActionServiceImpl implements UserActionService {
|
||||
|
||||
|
||||
@Override
|
||||
public SummaryPageResponseBean getUserAction(HttpServletRequest request, Long userId, TimePeriodEnum timeFilter, String actionContext) {
|
||||
public SummaryPageResponseBean getUserAction(HttpServletRequest request, Long userId, TimePeriodEnum timeFilter, List<UserActionContextEnum> actionContext) {
|
||||
UserEntity user = validator.validateUserId(request, userId);
|
||||
return userActionDao.getUserAction(request,user,timeFilter,actionContext);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ActionContextLabelResponse> getActionContextLabels(HttpServletRequest request, Long userId) {
|
||||
UserEntity user = validator.validateUserId(request, userId);
|
||||
return userActionDao.getActionContextLabels(request,user);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,6 +7,8 @@ import io.swagger.v3.oas.annotations.media.ExampleObject;
|
||||
import io.swagger.v3.oas.annotations.responses.ApiResponse;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
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.util.Response;
|
||||
import net.gepafin.tendermanagement.web.rest.api.errors.ErrorConstants;
|
||||
@@ -16,6 +18,8 @@ import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface UserActionApi {
|
||||
@Operation(summary = "Api to get user action",
|
||||
responses = {
|
||||
@@ -26,8 +30,20 @@ public interface UserActionApi {
|
||||
@ExampleObject(value = ErrorConstants.UNAUTHORIZED_ERROR_EXAMPLE) })),
|
||||
@ApiResponse(responseCode = "400", description = "Bad Request", content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, examples = {
|
||||
@ExampleObject(value = ErrorConstants.BADREQUEST_ERROR_EXAMPLE) })) })
|
||||
@GetMapping(value = "/{userId}", produces = { "application/json" })
|
||||
@GetMapping(value = "/user/{userId}", produces = { "application/json" })
|
||||
ResponseEntity<Response<SummaryPageResponseBean>> getUserAction(HttpServletRequest request, @Parameter(description = "The user id", required = true) @PathVariable("userId") Long userId,
|
||||
@Parameter(description = "Time Filter") @RequestParam(value = "timeFilter", required = false) TimePeriodEnum timeFilter,
|
||||
@Parameter(description = "Action Context") @RequestParam(value = "actionContext", required = false) String actionContext);
|
||||
@Parameter(description = "Action Context") @RequestParam(value = "actionContext", required = false) List<UserActionContextEnum> actionContext);
|
||||
|
||||
@Operation(summary = "Api to get action context label",
|
||||
responses = {
|
||||
@ApiResponse(responseCode = "200", description = "OK"),
|
||||
@ApiResponse(responseCode = "404", description = "Not Found", content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, examples = {
|
||||
@ExampleObject(value = ErrorConstants.NOTFOUND_ERROR_EXAMPLE) })),
|
||||
@ApiResponse(responseCode = "401", description = "Unauthorized", content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, examples = {
|
||||
@ExampleObject(value = ErrorConstants.UNAUTHORIZED_ERROR_EXAMPLE) })),
|
||||
@ApiResponse(responseCode = "400", description = "Bad Request", content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, examples = {
|
||||
@ExampleObject(value = ErrorConstants.BADREQUEST_ERROR_EXAMPLE) })) })
|
||||
@GetMapping(value = "/user/{userId}/action-context", produces = { "application/json" })
|
||||
ResponseEntity<Response<List<ActionContextLabelResponse>>> getActionContextLabels(HttpServletRequest request, @Parameter(description = "The user id", required = true) @PathVariable("userId") Long userId);
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ import net.gepafin.tendermanagement.enums.TimePeriodEnum;
|
||||
import net.gepafin.tendermanagement.enums.UserActionContextEnum;
|
||||
import net.gepafin.tendermanagement.enums.UserActionLogsEnum;
|
||||
import net.gepafin.tendermanagement.model.request.UserActionRequest;
|
||||
import net.gepafin.tendermanagement.model.response.ActionContextLabelResponse;
|
||||
import net.gepafin.tendermanagement.model.response.SummaryPageResponseBean;
|
||||
import net.gepafin.tendermanagement.model.util.Response;
|
||||
import net.gepafin.tendermanagement.service.UserActionService;
|
||||
@@ -19,6 +20,8 @@ import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("${openapi.gepafin.base-path:/v1/userAction}")
|
||||
public class UserActionApiController implements UserActionApi {
|
||||
@@ -30,7 +33,7 @@ public class UserActionApiController implements UserActionApi {
|
||||
private LoggingUtil loggingUtil;
|
||||
|
||||
@Override
|
||||
public ResponseEntity<Response<SummaryPageResponseBean>> getUserAction(HttpServletRequest request, Long userId, TimePeriodEnum timeFilter, String actionContext) {
|
||||
public ResponseEntity<Response<SummaryPageResponseBean>> getUserAction(HttpServletRequest request, Long userId, TimePeriodEnum timeFilter, List<UserActionContextEnum> actionContext) {
|
||||
|
||||
/** This code is responsible for creating user action logs for the "get user action" operation. **/
|
||||
loggingUtil.logUserAction(UserActionRequest.builder().request(request).actionType(UserActionLogsEnum.VIEW)
|
||||
@@ -39,5 +42,17 @@ public class UserActionApiController implements UserActionApi {
|
||||
return ResponseEntity.status(HttpStatus.OK)
|
||||
.body(new Response<>(userActionResponse, Status.SUCCESS, Translator.toLocale(GepafinConstant.USER_ACTION_FETCHED_SUCCESSFULLY)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResponseEntity<Response<List<ActionContextLabelResponse>>> getActionContextLabels(HttpServletRequest request, Long userId) {
|
||||
|
||||
/** This code is responsible for creating user action logs for the "get user action context labels" operation. **/
|
||||
loggingUtil.logUserAction(UserActionRequest.builder().request(request).actionType(UserActionLogsEnum.VIEW)
|
||||
.actionContext(UserActionContextEnum.GET_ACTION_CONTEXT_LABELS).build());
|
||||
|
||||
List<ActionContextLabelResponse> actionContextResponse= userActionService.getActionContextLabels(request,userId);
|
||||
return ResponseEntity.status(HttpStatus.OK)
|
||||
.body(new Response<>(actionContextResponse, Status.SUCCESS, Translator.toLocale(GepafinConstant.ACTION_CONTEXT_LABELS_FETCHED_SUCCESSFULLY)));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user