Added user action and versioning for document.
This commit is contained in:
@@ -2,9 +2,15 @@ package net.gepafin.tendermanagement.dao;
|
|||||||
|
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
import jakarta.servlet.http.HttpServletRequest;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import net.gepafin.tendermanagement.enums.DocumentSourceTypeEnum;
|
import net.gepafin.tendermanagement.enums.DocumentSourceTypeEnum;
|
||||||
|
import net.gepafin.tendermanagement.enums.UserActionContextEnum;
|
||||||
|
import net.gepafin.tendermanagement.enums.VersionActionTypeEnum;
|
||||||
|
import net.gepafin.tendermanagement.model.request.VersionHistoryRequest;
|
||||||
import net.gepafin.tendermanagement.repositories.ApplicationRepository;
|
import net.gepafin.tendermanagement.repositories.ApplicationRepository;
|
||||||
|
import net.gepafin.tendermanagement.util.LoggingUtil;
|
||||||
|
import net.gepafin.tendermanagement.util.Utils;
|
||||||
import net.gepafin.tendermanagement.web.rest.api.errors.CustomValidationException;
|
import net.gepafin.tendermanagement.web.rest.api.errors.CustomValidationException;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
@@ -48,10 +54,17 @@ public class DocumentDao {
|
|||||||
@Autowired
|
@Autowired
|
||||||
private ApplicationRepository applicationFormRepository;
|
private ApplicationRepository applicationFormRepository;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private LoggingUtil loggingUtil;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private HttpServletRequest request;
|
||||||
|
|
||||||
// @Value("${aws.s3.url.folder}")
|
// @Value("${aws.s3.url.folder}")
|
||||||
// private String s3Folder;
|
// private String s3Folder;
|
||||||
|
|
||||||
public List<DocumentResponseBean> uploadFiles(List<MultipartFile> files, Long sourceId, DocumentSourceTypeEnum sourceType, DocumentTypeEnum fileType) {
|
public List<DocumentResponseBean> uploadFiles(List<MultipartFile> files, Long sourceId, DocumentSourceTypeEnum sourceType, DocumentTypeEnum fileType) {
|
||||||
|
|
||||||
List<DocumentEntity> documentEntities = new ArrayList<>();
|
List<DocumentEntity> documentEntities = new ArrayList<>();
|
||||||
Long source = resolveSourceId(sourceId, sourceType);
|
Long source = resolveSourceId(sourceId, sourceType);
|
||||||
for (MultipartFile file : files) {
|
for (MultipartFile file : files) {
|
||||||
@@ -68,8 +81,44 @@ public class DocumentDao {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
documentRepository.saveAll(documentEntities);
|
documentRepository.saveAll(documentEntities);
|
||||||
|
|
||||||
|
/** This code is responsible for adding a version history log for the "Upload call or application document based on source type" operation. **/
|
||||||
|
|
||||||
|
documentEntities.forEach(entity -> loggingUtil.addVersionHistory(
|
||||||
|
VersionHistoryRequest.builder().request(request).actionType(VersionActionTypeEnum.INSERT).oldData(null).newData(entity).build()));
|
||||||
|
|
||||||
return documentEntities.stream().map(callDao::convertToDocumentResponseBean).collect(Collectors.toList());
|
return documentEntities.stream().map(callDao::convertToDocumentResponseBean).collect(Collectors.toList());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public UserActionContextEnum getUserActionContextEnum(DocumentSourceTypeEnum sourceType, DocumentTypeEnum fileType) {
|
||||||
|
|
||||||
|
UserActionContextEnum userActionContext = null;
|
||||||
|
|
||||||
|
if (fileType.equals(DocumentTypeEnum.DOCUMENT) && sourceType.equals(DocumentSourceTypeEnum.CALL)) {
|
||||||
|
userActionContext = UserActionContextEnum.UPLOAD_CALL_DOCUMENT;
|
||||||
|
} else if (fileType.equals(DocumentTypeEnum.IMAGES) && sourceType.equals(DocumentSourceTypeEnum.CALL)) {
|
||||||
|
userActionContext = UserActionContextEnum.UPLOAD_CALL_IMAGES;
|
||||||
|
} else if (fileType.equals(DocumentTypeEnum.DOCUMENT) && sourceType.equals(DocumentSourceTypeEnum.APPLICATION)) {
|
||||||
|
userActionContext = UserActionContextEnum.UPLOAD_APPLICATION_DOCUMENT;
|
||||||
|
} else if (fileType.equals(DocumentTypeEnum.IMAGES) && sourceType.equals(DocumentSourceTypeEnum.APPLICATION)) {
|
||||||
|
userActionContext = UserActionContextEnum.UPLOAD_APPLICATION_IMAGES;
|
||||||
|
}
|
||||||
|
|
||||||
|
return userActionContext;
|
||||||
|
}
|
||||||
|
|
||||||
|
public UserActionContextEnum getUserActionContextForUpdatingDocOrImage(DocumentTypeEnum documentTypeEnum) {
|
||||||
|
|
||||||
|
UserActionContextEnum userActionContext;
|
||||||
|
|
||||||
|
if (DocumentTypeEnum.DOCUMENT.equals(documentTypeEnum)) {
|
||||||
|
userActionContext = UserActionContextEnum.UPDATE_DOCUMENT;
|
||||||
|
} else{
|
||||||
|
userActionContext = UserActionContextEnum.UPDATE_IMAGES;
|
||||||
|
}
|
||||||
|
return userActionContext;
|
||||||
|
}
|
||||||
|
|
||||||
private UploadFileOnAmazonS3Response uploadFileOnAmazonS3(MultipartFile file, DocumentSourceTypeEnum type, Long sourceId) {
|
private UploadFileOnAmazonS3Response uploadFileOnAmazonS3(MultipartFile file, DocumentSourceTypeEnum type, Long sourceId) {
|
||||||
|
|
||||||
Long applicationId = 0L;
|
Long applicationId = 0L;
|
||||||
@@ -109,11 +158,19 @@ public class DocumentDao {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void deleteFile(Long documentId) {
|
public void deleteFile(Long documentId) {
|
||||||
|
|
||||||
DocumentEntity documentEntity = validateDocument(documentId);
|
DocumentEntity documentEntity = validateDocument(documentId);
|
||||||
// String fileName= Utils.extractFileName(documentEntity.getFilePath());
|
//cloned for old data
|
||||||
// deleteFileOnAmazonS3(fileName);
|
DocumentEntity oldDocumentEntity = Utils.getClonedEntityForData(documentEntity);
|
||||||
|
|
||||||
|
// String fileName= Utils.extractFileName(documentEntity.getFilePath());
|
||||||
|
// deleteFileOnAmazonS3(fileName);
|
||||||
documentEntity.setIsDeleted(true);
|
documentEntity.setIsDeleted(true);
|
||||||
documentRepository.save(documentEntity);
|
documentRepository.save(documentEntity);
|
||||||
|
|
||||||
|
/** This code is responsible for adding a version history log for the "Soft delete document" operation. **/
|
||||||
|
loggingUtil.addVersionHistory(
|
||||||
|
VersionHistoryRequest.builder().request(request).actionType(VersionActionTypeEnum.SOFT_DELETE).oldData(oldDocumentEntity).newData(documentEntity).build());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -123,7 +180,11 @@ public class DocumentDao {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public DocumentResponseBean updateDocument(Long documentId, MultipartFile file, DocumentTypeEnum documentTypeEnum) {
|
public DocumentResponseBean updateDocument(Long documentId, MultipartFile file, DocumentTypeEnum documentTypeEnum) {
|
||||||
|
|
||||||
DocumentEntity documentEntity = validateDocument(documentId);
|
DocumentEntity documentEntity = validateDocument(documentId);
|
||||||
|
//cloned entity for old data
|
||||||
|
DocumentEntity oldDocumentData = Utils.getClonedEntityForData(documentEntity);
|
||||||
|
|
||||||
String type = documentEntity.getSource();
|
String type = documentEntity.getSource();
|
||||||
UploadFileOnAmazonS3Response uploadFileOnAmazonS3Response = updateFileOnAmazonS3(file, DocumentSourceTypeEnum.valueOf(type), documentEntity.getSourceId());
|
UploadFileOnAmazonS3Response uploadFileOnAmazonS3Response = updateFileOnAmazonS3(file, DocumentSourceTypeEnum.valueOf(type), documentEntity.getSourceId());
|
||||||
if (uploadFileOnAmazonS3Response != null) {
|
if (uploadFileOnAmazonS3Response != null) {
|
||||||
@@ -133,6 +194,10 @@ public class DocumentDao {
|
|||||||
documentEntity.setSource(documentEntity.getSource());
|
documentEntity.setSource(documentEntity.getSource());
|
||||||
documentEntity.setSourceId(documentEntity.getSourceId());
|
documentEntity.setSourceId(documentEntity.getSourceId());
|
||||||
documentRepository.save(documentEntity);
|
documentRepository.save(documentEntity);
|
||||||
|
|
||||||
|
/** This code is responsible for adding a version history log for the "updating doc or image" operation. **/
|
||||||
|
loggingUtil.addVersionHistory(
|
||||||
|
VersionHistoryRequest.builder().request(request).actionType(VersionActionTypeEnum.UPDATE).oldData(oldDocumentData).newData(documentEntity).build());
|
||||||
}
|
}
|
||||||
return callDao.convertToDocumentResponseBean(documentEntity);
|
return callDao.convertToDocumentResponseBean(documentEntity);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -88,7 +88,17 @@ public enum UserActionContextEnum {
|
|||||||
CREATE_ASSIGNED_APPLICATION("CREATE_ASSIGNED_APPLICATION"),
|
CREATE_ASSIGNED_APPLICATION("CREATE_ASSIGNED_APPLICATION"),
|
||||||
DELETE_ASSIGNED_APPLICATION("DELETE_ASSIGNED_APPLICATION"),
|
DELETE_ASSIGNED_APPLICATION("DELETE_ASSIGNED_APPLICATION"),
|
||||||
GET_ASSIGNED_APPLICATION("GET_ASSIGNED_APPLICATION"),
|
GET_ASSIGNED_APPLICATION("GET_ASSIGNED_APPLICATION"),
|
||||||
UPDATE_ASSIGNED_APPLICATION_DETAILS("UPDATE_ASSIGNED_APPLICATION_DETAILS");
|
UPDATE_ASSIGNED_APPLICATION_DETAILS("UPDATE_ASSIGNED_APPLICATION_DETAILS"),
|
||||||
|
|
||||||
|
/** Document action context **/
|
||||||
|
UPLOAD_CALL_DOCUMENT("UPLOAD_CALL_DOCUMENT"),
|
||||||
|
UPLOAD_CALL_IMAGES("UPLOAD_CALL_IMAGES"),
|
||||||
|
UPLOAD_APPLICATION_DOCUMENT("UPLOAD_APPLICATION_DOCUMENT"),
|
||||||
|
UPLOAD_APPLICATION_IMAGES("UPLOAD_APPLICATION_IMAGES"),
|
||||||
|
DELETE_DOCUMENT("DELETE_DOCUMENT"),
|
||||||
|
UPDATE_DOCUMENT("UPDATE_DOCUEMENT"),
|
||||||
|
UPDATE_IMAGES("UPDATE_IMAGES"),
|
||||||
|
GET_DOCUMENT("GET_DOCUMENT");
|
||||||
|
|
||||||
private final String value;
|
private final String value;
|
||||||
|
|
||||||
|
|||||||
@@ -3,11 +3,16 @@ package net.gepafin.tendermanagement.web.rest.api.impl;
|
|||||||
import jakarta.servlet.http.HttpServletRequest;
|
import jakarta.servlet.http.HttpServletRequest;
|
||||||
import net.gepafin.tendermanagement.config.Translator;
|
import net.gepafin.tendermanagement.config.Translator;
|
||||||
import net.gepafin.tendermanagement.constants.GepafinConstant;
|
import net.gepafin.tendermanagement.constants.GepafinConstant;
|
||||||
|
import net.gepafin.tendermanagement.dao.DocumentDao;
|
||||||
import net.gepafin.tendermanagement.enums.DocumentSourceTypeEnum;
|
import net.gepafin.tendermanagement.enums.DocumentSourceTypeEnum;
|
||||||
import net.gepafin.tendermanagement.enums.DocumentTypeEnum;
|
import net.gepafin.tendermanagement.enums.DocumentTypeEnum;
|
||||||
|
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.DocumentResponseBean;
|
import net.gepafin.tendermanagement.model.response.DocumentResponseBean;
|
||||||
import net.gepafin.tendermanagement.model.util.Response;
|
import net.gepafin.tendermanagement.model.util.Response;
|
||||||
import net.gepafin.tendermanagement.service.DocumentService;
|
import net.gepafin.tendermanagement.service.DocumentService;
|
||||||
|
import net.gepafin.tendermanagement.util.LoggingUtil;
|
||||||
import net.gepafin.tendermanagement.web.rest.api.DocumentApi;
|
import net.gepafin.tendermanagement.web.rest.api.DocumentApi;
|
||||||
import net.gepafin.tendermanagement.web.rest.api.errors.CustomValidationException;
|
import net.gepafin.tendermanagement.web.rest.api.errors.CustomValidationException;
|
||||||
import net.gepafin.tendermanagement.web.rest.api.errors.Status;
|
import net.gepafin.tendermanagement.web.rest.api.errors.Status;
|
||||||
@@ -27,10 +32,21 @@ DocumentApiController implements DocumentApi {
|
|||||||
@Autowired
|
@Autowired
|
||||||
private DocumentService documentService;
|
private DocumentService documentService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private LoggingUtil loggingUtil;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private DocumentDao documentDao;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ResponseEntity<Response<List<DocumentResponseBean>>> uploadFile(HttpServletRequest httpServletRequest, Long sourceId, DocumentSourceTypeEnum sourceType,
|
public ResponseEntity<Response<List<DocumentResponseBean>>> uploadFile(HttpServletRequest httpServletRequest, Long sourceId, DocumentSourceTypeEnum sourceType,
|
||||||
List<MultipartFile> files, DocumentTypeEnum fileType) {
|
List<MultipartFile> files, DocumentTypeEnum fileType) {
|
||||||
try {
|
try {
|
||||||
|
UserActionContextEnum userActionContext = documentDao.getUserActionContextEnum(sourceType, fileType);
|
||||||
|
|
||||||
|
/** This code is responsible for creating user action logs for the "upload document for call or application" operation. **/
|
||||||
|
loggingUtil.logUserAction(UserActionRequest.builder().request(httpServletRequest).actionType(UserActionLogsEnum.UPLOAD).actionContext(userActionContext).build());
|
||||||
|
|
||||||
List<DocumentResponseBean> responseBeans = documentService.uploadFile(files, sourceId, sourceType, fileType);
|
List<DocumentResponseBean> responseBeans = documentService.uploadFile(files, sourceId, sourceType, fileType);
|
||||||
return ResponseEntity.status(HttpStatus.CREATED)
|
return ResponseEntity.status(HttpStatus.CREATED)
|
||||||
.body(new Response<List<DocumentResponseBean>>(responseBeans, Status.SUCCESS, Translator.toLocale(GepafinConstant.FILES_UPLOADED_MSG)));
|
.body(new Response<List<DocumentResponseBean>>(responseBeans, Status.SUCCESS, Translator.toLocale(GepafinConstant.FILES_UPLOADED_MSG)));
|
||||||
@@ -40,6 +56,10 @@ DocumentApiController implements DocumentApi {
|
|||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
public ResponseEntity<Response<Void>> deleteFile(HttpServletRequest httpServletRequest, Long documentId) {
|
public ResponseEntity<Response<Void>> deleteFile(HttpServletRequest httpServletRequest, Long documentId) {
|
||||||
|
|
||||||
|
/** This code is responsible for creating user action logs for the "delete document" operation. **/
|
||||||
|
loggingUtil.logUserAction(UserActionRequest.builder().request(httpServletRequest).actionType(UserActionLogsEnum.DELETE).actionContext(UserActionContextEnum.DELETE_DOCUMENT).build());
|
||||||
|
|
||||||
documentService.deleteFile(documentId);
|
documentService.deleteFile(documentId);
|
||||||
return ResponseEntity.status(HttpStatus.CREATED)
|
return ResponseEntity.status(HttpStatus.CREATED)
|
||||||
.body(new Response<Void>(null, Status.SUCCESS, Translator.toLocale(GepafinConstant.FILE_DELETED_SUCCESSFULLY_MSG)));
|
.body(new Response<Void>(null, Status.SUCCESS, Translator.toLocale(GepafinConstant.FILE_DELETED_SUCCESSFULLY_MSG)));
|
||||||
@@ -47,6 +67,12 @@ DocumentApiController implements DocumentApi {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ResponseEntity<Response<DocumentResponseBean>> updateDocument(HttpServletRequest httpServletRequest, Long documentId, MultipartFile file, DocumentTypeEnum documentTypeEnum) {
|
public ResponseEntity<Response<DocumentResponseBean>> updateDocument(HttpServletRequest httpServletRequest, Long documentId, MultipartFile file, DocumentTypeEnum documentTypeEnum) {
|
||||||
|
|
||||||
|
UserActionContextEnum userActionContext = documentDao.getUserActionContextForUpdatingDocOrImage(documentTypeEnum);
|
||||||
|
|
||||||
|
/** This code is responsible for creating user action logs for the "update document or image" operation. **/
|
||||||
|
loggingUtil.logUserAction(UserActionRequest.builder().request(httpServletRequest).actionType(UserActionLogsEnum.UPDATE).actionContext(userActionContext).build());
|
||||||
|
|
||||||
DocumentResponseBean responseBeans = documentService.updateDocument(httpServletRequest, documentId, file, documentTypeEnum);
|
DocumentResponseBean responseBeans = documentService.updateDocument(httpServletRequest, documentId, file, documentTypeEnum);
|
||||||
return ResponseEntity.status(HttpStatus.CREATED)
|
return ResponseEntity.status(HttpStatus.CREATED)
|
||||||
.body(new Response<DocumentResponseBean>(responseBeans, Status.SUCCESS, Translator.toLocale(GepafinConstant.DOCUMENT_UPDATED_SUCCESSFULLY)));
|
.body(new Response<DocumentResponseBean>(responseBeans, Status.SUCCESS, Translator.toLocale(GepafinConstant.DOCUMENT_UPDATED_SUCCESSFULLY)));
|
||||||
@@ -54,8 +80,12 @@ DocumentApiController implements DocumentApi {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ResponseEntity<Response<DocumentResponseBean>> getDocumentById(HttpServletRequest request, Long id) {
|
public ResponseEntity<Response<DocumentResponseBean>> getDocumentById(HttpServletRequest request, Long id) {
|
||||||
DocumentResponseBean documentResponseBean= documentService.getDocument(request,id);
|
|
||||||
|
/** This code is responsible for creating user action logs for the "Get Document" operation. **/
|
||||||
|
loggingUtil.logUserAction(UserActionRequest.builder().request(request).actionType(UserActionLogsEnum.VIEW).actionContext(UserActionContextEnum.GET_DOCUMENT).build());
|
||||||
|
|
||||||
|
DocumentResponseBean documentResponseBean = documentService.getDocument(request, id);
|
||||||
return ResponseEntity.status(HttpStatus.CREATED)
|
return ResponseEntity.status(HttpStatus.CREATED)
|
||||||
.body(new Response<DocumentResponseBean>(documentResponseBean, Status.SUCCESS, Translator.toLocale(GepafinConstant.DOCUMENT_FETCHED_SUCCESSFULLY)));
|
.body(new Response<DocumentResponseBean>(documentResponseBean, Status.SUCCESS, Translator.toLocale(GepafinConstant.DOCUMENT_FETCHED_SUCCESSFULLY)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user