Merge pull request #113 from Kitzanos/feature/GEPAFINBE-100

GEPAFINBE-100,99(Script for migrating deleted documents)
This commit is contained in:
rbonazzo-KZ
2024-12-02 08:29:31 +01:00
committed by GitHub
12 changed files with 162 additions and 124 deletions

View File

@@ -202,14 +202,8 @@ public class DelegationDao {
.findByUserIdAndUserWithCompanyIdAndStatus(userEntity.getId(), userWithCompanyEntity.getId(),
UserCompanyDelegationStatusEnum.ACTIVE.getValue());
UserCompanyDelegationEntity oldUserCompanyDelegationEntity = Utils.getClonedEntityForData(userCompanyDelegationEntity);
if (userCompanyDelegationEntity != null) {
userCompanyDelegationEntity.setStatus(UserCompanyDelegationStatusEnum.INACTIVE.getValue());
userCompanyDelegationRepository.save(userCompanyDelegationEntity);
/** This code is responsible for adding a version history log for the "update user company delegation status" operation. **/
loggingUtil.addVersionHistory(VersionHistoryRequest.builder().request(request).actionType(VersionActionTypeEnum.UPDATE).oldData(oldUserCompanyDelegationEntity)
.newData(userCompanyDelegationEntity).build());
deleteDelegationFromS3(userCompanyDelegationEntity);
}
UploadFileOnAmazonS3Response uploadFileOnAmazonS3Response = uploadFileOnAmazonS3ForCompanyDelegation(file);
userCompanyDelegationEntity = new UserCompanyDelegationEntity();
@@ -282,16 +276,22 @@ public class DelegationDao {
.findByUserIdAndUserWithCompanyIdAndStatus(userEntity.getId(), userWithCompanyEntity.getId(),
UserCompanyDelegationStatusEnum.ACTIVE.getValue());
companyDao.getUserWithCompany(userEntity.getId(), companyId);
//cloned entity for old data
UserCompanyDelegationEntity oldUserCompanyDelegation = Utils.getClonedEntityForData(userCompanyDelegationEntity);
if (userCompanyDelegationEntity == null) {
throw new ResourceNotFoundException(Status.NOT_FOUND, Translator.toLocale(GepafinConstant.DELEGATION_NOT_FOUND));
}
amazonS3Service.deleteDelegationfromS3(userCompanyDelegationEntity);
deleteDelegationFromS3(userCompanyDelegationEntity);
}
public void deleteDelegationFromS3(UserCompanyDelegationEntity userCompanyDelegationEntity) {
UserCompanyDelegationEntity oldUserCompanyDelegation = Utils.getClonedEntityForData(userCompanyDelegationEntity);
String oldS3Path = userCompanyDelegationEntity.getFilePath();
String newS3Path = s3ConfigBean.generateDocumentPathForDelegationAndSignedDocument(DocOtherSourceTypeEnum.DELETED_USER_DELEGATION);
UploadFileOnAmazonS3Response response = amazonS3Service.moveFile(userCompanyDelegationEntity.getFileName(), oldS3Path, newS3Path);
userCompanyDelegationEntity.setFileName(response.getFileName());
userCompanyDelegationEntity.setFilePath(response.getFilePath());
userCompanyDelegationEntity.setStatus(UserCompanyDelegationStatusEnum.INACTIVE.getValue());
userCompanyDelegationRepository.save(userCompanyDelegationEntity);
/** This code is responsible for adding a version history log for the "Soft Deleting company delegation " operation. **/
loggingUtil.addVersionHistory(
VersionHistoryRequest.builder().request(request).actionType(VersionActionTypeEnum.SOFT_DELETE).oldData(oldUserCompanyDelegation).newData(userCompanyDelegationEntity)

View File

@@ -4,9 +4,7 @@ import lombok.extern.slf4j.Slf4j;
import java.util.stream.Collectors;
import jakarta.servlet.http.HttpServletRequest;
import net.gepafin.tendermanagement.enums.DocumentSourceTypeEnum;
import net.gepafin.tendermanagement.enums.UserActionContextEnum;
import net.gepafin.tendermanagement.enums.VersionActionTypeEnum;
import net.gepafin.tendermanagement.enums.*;
import net.gepafin.tendermanagement.model.request.VersionHistoryRequest;
import net.gepafin.tendermanagement.repositories.ApplicationRepository;
import net.gepafin.tendermanagement.util.LoggingUtil;
@@ -21,7 +19,6 @@ import net.gepafin.tendermanagement.constants.GepafinConstant;
import net.gepafin.tendermanagement.entities.ApplicationEntity;
import net.gepafin.tendermanagement.entities.CallEntity;
import net.gepafin.tendermanagement.entities.DocumentEntity;
import net.gepafin.tendermanagement.enums.DocumentTypeEnum;
import net.gepafin.tendermanagement.model.response.DocumentResponseBean;
import net.gepafin.tendermanagement.model.response.UploadFileOnAmazonS3Response;
import net.gepafin.tendermanagement.repositories.ApplicationAmendmentRequestRepository;
@@ -188,7 +185,6 @@ public class DocumentDao {
if(Boolean.TRUE.equals(documentEntity.getIsDeleted())){
return;
}
DocumentEntity oldDocumentEntity = Utils.getClonedEntityForData(documentEntity);
Long callId = null;
Long applicationId = null;
Long amendmentId = null;
@@ -207,13 +203,8 @@ public class DocumentDao {
callId = applicationEntity.getCall().getId();
}
amazonS3Service.deleteFileFromS3(documentEntity, callId, applicationId,amendmentId);
documentEntity.setIsDeleted(true);
documentRepository.save(documentEntity);
deleteFileFromS3(documentEntity, callId, applicationId,amendmentId);
/** 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());
}
public DocumentEntity validateDocument(Long id) {
@@ -275,4 +266,26 @@ public class DocumentDao {
DocumentEntity documentEntity = validateDocument(documentId);
return callDao.convertToDocumentResponseBean(documentEntity);
}
public void deleteFileFromS3(DocumentEntity documentEntity, Long callId, Long applicationId,Long amendmentId) {
try {
DocumentEntity oldDocumentEntity = Utils.getClonedEntityForData(documentEntity);
String oldS3Path = documentEntity.getFilePath();
String newS3Path = s3ConfigBean.generateDocumentPathForOther(DocOtherSourceTypeEnum.valueOf("DELETED_" + documentEntity.getSource().toUpperCase()), callId, applicationId,amendmentId);
UploadFileOnAmazonS3Response response = amazonS3Service.moveFile(documentEntity.getFileName(), oldS3Path, newS3Path);
documentEntity.setFileName(response.getFileName());
documentEntity.setFilePath(response.getFilePath());
documentEntity.setIsDeleted(true);
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());
log.info("File for document ID {} successfully moved to deleted folder.", documentEntity.getId());
} catch (Exception e) {
log.error("Error moving file for document ID {} to deleted folder: {}", documentEntity.getId(), e.getMessage());
throw new CustomValidationException(Status.VALIDATION_ERROR, "Error occurred while moving file to deleted folder.");
}
}
}

View File

@@ -11,7 +11,8 @@ public enum UserActionLogsEnum {
INSERT("INSERT"),
DOWNLOAD("DOWNLOAD"),
UPLOAD("UPLOAD"),
SCHEDULER("SCHEDULER");
SCHEDULER("SCHEDULER"),
SCRIPT("SCRIPT");
private final String value;

View File

@@ -28,6 +28,10 @@ public interface DocumentRepository extends JpaRepository<DocumentEntity, Long>
@Query("SELECT d FROM DocumentEntity d WHERE d.isDeleted = false")
List<DocumentEntity> findAllByIsDeleteFalse();
@Query("SELECT d FROM DocumentEntity d WHERE d.isDeleted = true")
List<DocumentEntity> findAllByIsDeleteTrue();
List<DocumentEntity> findAllByIdInAndIsDeletedFalse(Set<Long> documentIds);
}

View File

@@ -1,7 +1,4 @@
package net.gepafin.tendermanagement.service;
import net.gepafin.tendermanagement.entities.DocumentEntity;
import net.gepafin.tendermanagement.entities.UserCompanyDelegationEntity;
import net.gepafin.tendermanagement.enums.DocOtherSourceTypeEnum;
import org.springframework.stereotype.Component;
import org.springframework.web.multipart.MultipartFile;
@@ -20,14 +17,6 @@ AmazonS3Service {
InputStream getFile(String s3Folder, String filePath) throws IOException;
String generateS3PathForDeletedDocument(DocOtherSourceTypeEnum typeOfDocument, Long callId, Long applicationId,Long amendmentId);
String generateS3PathForDeletedDocumentForOther();
void moveFile(String bucketName, String oldPath, String newPath);
void deleteDelegationfromS3(UserCompanyDelegationEntity userCompanyDelegationEntity);
void deleteFileFromS3(DocumentEntity documentEntity, Long callId, Long applicationId,Long amendmentId);
UploadFileOnAmazonS3Response moveFile(String fileName, String oldPath, String newPath);
}

View File

@@ -61,9 +61,9 @@ public class AmazonS3ServiceImpl implements AmazonS3Service {
@Value("${aws.s3.region}")
private String region;
private String getBucketUrlPrefix() {
return "https://" + bucketName + ".s3." + region + ".amazonaws.com/";
}
@Autowired
S3ReUploadMigrationService s3ReUploadMigrationService;
private String upload(String fileName, String s3Folder,
MultipartFile file) throws IOException {
@@ -146,32 +146,10 @@ public class AmazonS3ServiceImpl implements AmazonS3Service {
}
@Override
public String generateS3PathForDeletedDocument(DocOtherSourceTypeEnum typeOfDocument, Long callId, Long applicationId,Long amendmentId) {
try {
return s3ConfigBean.generateDocumentPathForOther(typeOfDocument, callId, applicationId,amendmentId);
} catch (IllegalArgumentException e) {
throw new CustomValidationException(
Status.VALIDATION_ERROR,
Translator.toLocale(GepafinConstant.S3_PATH_GENERATION_ERROR_MSG)
);
}
}
@Override
public String generateS3PathForDeletedDocumentForOther() {
try {
return s3ConfigBean.generateDocumentPathForDelegationAndSignedDocument(DocOtherSourceTypeEnum.DELETED_USER_DELEGATION);
} catch (IllegalArgumentException e) {
throw new CustomValidationException(
Status.VALIDATION_ERROR,
Translator.toLocale(GepafinConstant.S3_PATH_GENERATION_ERROR_MSG)
);
}
}
@Override
public void moveFile(String bucketName, String oldPath, String newPath) {
public UploadFileOnAmazonS3Response moveFile(String fileName, String oldPath, String newPath) {
try {
newPath = cleanNewPath(oldPath, newPath);
oldPath = cleanOldPath(oldPath);
log.info("Moving file from {} to {} in bucket {}", oldPath, newPath, bucketName);
CopyObjectRequest copyRequest = new CopyObjectRequest(bucketName, oldPath, bucketName, newPath);
@@ -180,6 +158,8 @@ public class AmazonS3ServiceImpl implements AmazonS3Service {
s3Client.deleteObject(bucketName, oldPath);
log.info("Original file deleted successfully: {}", oldPath);
String filePath = s3Url + newPath;
return UploadFileOnAmazonS3Response.builder().fileName(fileName).filePath(filePath).build();
} catch (AmazonServiceException e) {
log.error("AWS service error while moving file: {}", e.getErrorMessage(), e);
throw e;
@@ -192,36 +172,11 @@ public class AmazonS3ServiceImpl implements AmazonS3Service {
}
}
@Override
public void deleteDelegationfromS3(UserCompanyDelegationEntity userCompanyDelegationEntity) {
String oldS3Path = userCompanyDelegationEntity.getFilePath();
String newS3Path = generateS3PathForDeletedDocumentForOther()
+ "/" + oldS3Path.substring(oldS3Path.lastIndexOf("/") + 1);
String bucketUrlPrefix = getBucketUrlPrefix();
if (oldS3Path.startsWith(bucketUrlPrefix)) {
oldS3Path = oldS3Path.replace(bucketUrlPrefix, "");
}
moveFile(bucketName, oldS3Path, newS3Path);
log.info("File for company ID {} successfully moved to deleted folder.", userCompanyDelegationEntity.getId());
private String cleanNewPath(String oldPath, String newPath) {
return newPath + "/" + oldPath.substring(oldPath.lastIndexOf("/") + 1);
}
@Override
public void deleteFileFromS3(DocumentEntity documentEntity, Long callId, Long applicationId,Long amendmentId) {
try {
String oldS3Path = documentEntity.getFilePath();
String newS3Path = generateS3PathForDeletedDocument(DocOtherSourceTypeEnum.valueOf("DELETED_" + documentEntity.getSource().toUpperCase()), callId, applicationId,amendmentId)
+ "/" + oldS3Path.substring(oldS3Path.lastIndexOf("/") + 1);
String bucketUrlPrefix = getBucketUrlPrefix();
if (oldS3Path.startsWith(bucketUrlPrefix)) {
oldS3Path = oldS3Path.replace(bucketUrlPrefix, "");
}
moveFile(bucketName, oldS3Path, newS3Path);
log.info("File for document ID {} successfully moved to deleted folder.", documentEntity.getId());
} catch (Exception e) {
log.error("Error moving file for document ID {} to deleted folder: {}", documentEntity.getId(), e.getMessage());
throw new CustomValidationException(Status.VALIDATION_ERROR, "Error occurred while moving file to deleted folder.");
}
private String cleanOldPath(String oldPath) {
return oldPath.replace(s3Url, "");
}
}

View File

@@ -7,12 +7,17 @@ import com.amazonaws.services.s3.AmazonS3Client;
import com.amazonaws.services.s3.model.GetObjectRequest;
import com.amazonaws.services.s3.model.ObjectMetadata;
import lombok.extern.slf4j.Slf4j;
import net.gepafin.tendermanagement.dao.DocumentDao;
import net.gepafin.tendermanagement.dao.S3PathConfig;
import net.gepafin.tendermanagement.entities.ApplicationEntity;
import net.gepafin.tendermanagement.entities.DocumentEntity;
import net.gepafin.tendermanagement.enums.DocumentSourceTypeEnum;
import net.gepafin.tendermanagement.repositories.ApplicationAmendmentRequestRepository;
import net.gepafin.tendermanagement.repositories.ApplicationRepository;
import net.gepafin.tendermanagement.repositories.ApplicationSignedDocumentRepository;
import net.gepafin.tendermanagement.repositories.DocumentRepository;
import net.gepafin.tendermanagement.service.AmazonS3Service;
import net.gepafin.tendermanagement.service.ApplicationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
@@ -50,13 +55,35 @@ public class S3ReUploadMigrationService {
@Autowired
private AmazonS3 amazonS3;
@Autowired
ApplicationService applicationService;
@Value("${aws.s3.url}")
private String s3Url;
@Autowired
AmazonS3Service amazonS3Service;
@Value("${aws.s3.bucket.name}")
private String bucketName;
@Value("${aws.s3.region}")
private String region;
@Autowired
private ApplicationAmendmentRequestRepository applicationAmendmentRequestRepository;
@Autowired
private DocumentDao documentDao;
private boolean migrationCompleted = false;
public String reUploadAndMigrateDocuments(String providedKey) {
Long totalDocuments=0L;
Long failedDocuments=0L;
Long processDocuments=0L;
if (migrationCompleted) {
return "Migration already completed.";
}
@@ -66,26 +93,48 @@ public class S3ReUploadMigrationService {
return "Invalid or missing migration key.";
}
List<DocumentEntity> documents = documentRepository.findAllByIsDeleteFalse();
List<DocumentEntity> documents = documentRepository.findAllByIsDeleteTrue();
totalDocuments = Long.valueOf(documents.size());
if (documents.isEmpty()) {
return "No documents found to migrate.";
}
for (DocumentEntity document : documents) {
String oldUrl = document.getFilePath(); // This should contain the full URL
log.info("Processing {}", oldUrl);
log.info("Processing for the Document id and url:{} ",document.getId(),document.getFilePath());
try {
File localFile = downloadFileFromS3(oldUrl);
String newKey = generateNewS3Path(document); // Make sure this generates the correct new path
String uploadedPath = uploadFileToNewBucket(localFile, newKey);
updateDocumentPathAndNameEntry(document, uploadedPath);
Long callId = null;
Long applicationId = null;
Long amendmentId = null;
if (DocumentSourceTypeEnum.CALL.getValue().equalsIgnoreCase(document.getSource())) {
callId = document.getSourceId();
} else if (DocumentSourceTypeEnum.APPLICATION.getValue().equalsIgnoreCase(document.getSource())) {
applicationId = document.getSourceId();
ApplicationEntity applicationEntity = applicationService.validateApplication(applicationId);
callId = applicationEntity.getCall().getId();
}
else if(DocumentSourceTypeEnum.AMENDMENT.getValue().equalsIgnoreCase(document.getSource())){
amendmentId = document.getSourceId();
ApplicationEntity applicationEntity = applicationAmendmentRequestRepository.findApplicationByAmendmentId(amendmentId);
applicationId = applicationEntity.getId();
callId = applicationEntity.getCall().getId();
}
documentDao.deleteFileFromS3(document,callId,applicationId,amendmentId);
processDocuments++;
} catch (Exception e) {
log.error("Error processing document {}: {}", document.getId(), e.getMessage());
failedDocuments++;
}
}
log.info("Total Documents Fetched ",totalDocuments);
log.info("Total Process Documents :{}",processDocuments);
log.info("Total Failed Documents :{}",failedDocuments);
return "Migrated Successfully.";
}
private boolean isValidKey(String providedKey) {
@@ -177,13 +226,4 @@ public class S3ReUploadMigrationService {
return parts[parts.length - 1];
}
private void updateDocumentPathAndNameEntry(DocumentEntity document, String newPath) {
String fileName = extractFileName(newPath);
document.setFilePath(newPath);
document.setFileName(fileName);
documentRepository.save(document);
log.info("Migrated document ID: {} to new path: {}", document.getId(), newPath);
}
}

View File

@@ -6,6 +6,7 @@ import com.amazonaws.services.s3.AmazonS3Client;
import com.amazonaws.services.s3.model.GetObjectRequest;
import com.amazonaws.services.s3.model.ObjectMetadata;
import lombok.extern.slf4j.Slf4j;
import net.gepafin.tendermanagement.dao.DelegationDao;
import net.gepafin.tendermanagement.dao.S3PathConfig;
import net.gepafin.tendermanagement.entities.ApplicationSignedDocumentEntity;
import net.gepafin.tendermanagement.entities.UserCompanyDelegationEntity;
@@ -56,10 +57,16 @@ public class UserSignedAndDelegationServiceImpl {
@Value("${aws.s3.url}")
private String s3Url;
@Autowired
private DelegationDao delegationDao;
private boolean migrationCompleted = false;
public String migrateUserDelegatedDocuments(String providedKey) {
Long totalDocuments=0L;
Long failedDocuments=0L;
Long processDocuments=0L;
if (migrationCompleted) {
return "Migration already completed.";
}
@@ -69,25 +76,27 @@ public class UserSignedAndDelegationServiceImpl {
return "Invalid or missing migration key.";
}
List<UserCompanyDelegationEntity> documents = userCompanyDelegationRepository.findAllByStatus("ACTIVE");
List<UserCompanyDelegationEntity> documents = userCompanyDelegationRepository.findAllByStatus("INACTIVE");
totalDocuments = Long.valueOf(documents.size());
if (documents.isEmpty()) {
return "No documents found to migrate.";
}
for (UserCompanyDelegationEntity document : documents) {
String oldUrl = document.getFilePath();
log.info("Processing user designated document: {}", oldUrl);
log.info("Processing user designated document and old Url: {}", document.getId(),oldUrl);
try {
File localFile = downloadFileFromS3(oldUrl);
String newKey = generateNewS3PathForDelegationDoc();
String uploadedPath = uploadFileToNewBucket(localFile, newKey);
updateDelegatedDocumentPathAndNameEntry(document, uploadedPath);
delegationDao.deleteDelegationFromS3(document);
processDocuments++;
} catch (Exception e) {
log.error("Error processing user designated document {}: {}", document.getId(), e.getMessage());
failedDocuments++;
}
}
log.info("Total Documents Fetched:{} ",totalDocuments);
log.info("Total Process Documents :{}",processDocuments);
log.info("Total Failed Documents :{}",failedDocuments);
return "Migrated";
}

View File

@@ -5,9 +5,10 @@ import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.ExampleObject;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import jakarta.validation.Valid;
import jakarta.servlet.http.HttpServletRequest;
import net.gepafin.tendermanagement.web.rest.api.errors.ErrorConstants;
import org.springframework.data.repository.query.Param;
import org.springframework.http.MediaType;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PathVariable;
@@ -16,7 +17,7 @@ import org.springframework.web.bind.annotation.PutMapping;
@Validated
public interface S3MigrationApi {
@Operation(summary = "Api to migrate S3 doc to db and update s3 files as per specified folder.", responses = { @ApiResponse(responseCode = "200", description = "OK"),
@Operation(summary = "Api to migrate deleted documents to the deleted Folder ", 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 = {
@@ -24,5 +25,5 @@ public interface S3MigrationApi {
@ApiResponse(responseCode = "400", description = "Bad Request", content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, examples = {
@ExampleObject(value = ErrorConstants.BADREQUEST_ERROR_EXAMPLE) })) })
@PutMapping(value = "/{key}", produces = { "application/json" })
String reUploadAndMigrateDocuments(@Parameter(description = "The secret key", required = true) @PathVariable("key") String key);
String reUploadAndMigrateDocuments(HttpServletRequest request, @Parameter(description = "The secret key", required = true) @PathVariable("key") String key);
}

View File

@@ -5,6 +5,7 @@ import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.ExampleObject;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.validation.Valid;
import net.gepafin.tendermanagement.web.rest.api.errors.ErrorConstants;
import org.springframework.data.repository.query.Param;
@@ -16,7 +17,7 @@ import org.springframework.web.bind.annotation.PostMapping;
@Validated
public interface UserSignedAndDelegationApi {
@Operation(summary = "Api to migrate S3 doc to db and user-delegated folder", responses = { @ApiResponse(responseCode = "200", description = "OK"),
@Operation(summary = "Api to migrate S3 user-delegated deleted doc to deleted folder", 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 = {
@@ -24,7 +25,7 @@ public interface UserSignedAndDelegationApi {
@ApiResponse(responseCode = "400", description = "Bad Request", content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, examples = {
@ExampleObject(value = ErrorConstants.BADREQUEST_ERROR_EXAMPLE) })) })
@GetMapping(value = "/{key}", produces = { "application/json" })
String migrateUserDelegatedDocuments(@Parameter(description = "The secret key", required = true) @PathVariable("key") String key);
String migrateUserDelegatedDocuments(HttpServletRequest request, @Parameter(description = "The secret key", required = true) @PathVariable("key") String key);
@Operation(summary = "Api to migrate S3 doc to user-signed.", responses = { @ApiResponse(responseCode = "200", description = "OK"),
@ApiResponse(responseCode = "404", description = "Not Found", content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, examples = {

View File

@@ -1,6 +1,11 @@
package net.gepafin.tendermanagement.web.rest.api.impl;
import jakarta.servlet.http.HttpServletRequest;
import net.gepafin.tendermanagement.enums.UserActionContextEnum;
import net.gepafin.tendermanagement.enums.UserActionLogsEnum;
import net.gepafin.tendermanagement.model.request.UserActionRequest;
import net.gepafin.tendermanagement.service.impl.S3ReUploadMigrationService;
import net.gepafin.tendermanagement.util.LoggingUtil;
import net.gepafin.tendermanagement.web.rest.api.S3MigrationApi;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
@@ -12,8 +17,16 @@ public class S3MigrationApiController implements S3MigrationApi {
@Autowired
S3ReUploadMigrationService s3MigrationService;
@Autowired
LoggingUtil loggingUtil;
@Override
public String reUploadAndMigrateDocuments(String providedKey) {
public String reUploadAndMigrateDocuments(HttpServletRequest request,String providedKey) {
/** This code is responsible for creating user action logs for the "upload document for call or application" operation. **/
loggingUtil.logUserAction(UserActionRequest.builder().request(request).actionType(UserActionLogsEnum.SCRIPT).actionContext(UserActionContextEnum.GET_DOCUMENT).build());
return s3MigrationService.reUploadAndMigrateDocuments(providedKey);
}
}

View File

@@ -1,6 +1,11 @@
package net.gepafin.tendermanagement.web.rest.api.impl;
import jakarta.servlet.http.HttpServletRequest;
import net.gepafin.tendermanagement.enums.UserActionContextEnum;
import net.gepafin.tendermanagement.enums.UserActionLogsEnum;
import net.gepafin.tendermanagement.model.request.UserActionRequest;
import net.gepafin.tendermanagement.service.impl.UserSignedAndDelegationServiceImpl;
import net.gepafin.tendermanagement.util.LoggingUtil;
import net.gepafin.tendermanagement.web.rest.api.UserSignedAndDelegationApi;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
@@ -13,8 +18,15 @@ public class S3UserSignedAndDelegationMigrationController implements UserSignedA
@Autowired
UserSignedAndDelegationServiceImpl userSignedAndDelegationService;
@Autowired
LoggingUtil loggingUtil;
@Override
public String migrateUserDelegatedDocuments(String providedKey) {
public String migrateUserDelegatedDocuments(HttpServletRequest request,String providedKey) {
/** This code is responsible for creating user action logs for the "upload document for call or application" operation. **/
loggingUtil.logUserAction(UserActionRequest.builder().request(request).actionType(UserActionLogsEnum.SCRIPT).actionContext(UserActionContextEnum.GET_DOCUMENT).build());
return userSignedAndDelegationService.migrateUserDelegatedDocuments(providedKey);
}
@Override