Merge pull request #112 from Kitzanos/feature/GEPAFINBE-100
GEPAFINBE-100,99(S3 Management for Deleted and Amendment Documents)
This commit is contained in:
@@ -1076,7 +1076,7 @@ public class ApplicationDao {
|
|||||||
}
|
}
|
||||||
private String generateS3PathForDelegation(Long callId, Long applicationId) {
|
private String generateS3PathForDelegation(Long callId, Long applicationId) {
|
||||||
try {
|
try {
|
||||||
return s3ConfigBean.generateDocumentPathForOther(DocOtherSourceTypeEnum.USER_SIGNED_DOCUMENT, callId, applicationId);
|
return s3ConfigBean.generateDocumentPathForOther(DocOtherSourceTypeEnum.USER_SIGNED_DOCUMENT, callId, applicationId,0L);
|
||||||
} catch (IllegalArgumentException e) {
|
} catch (IllegalArgumentException e) {
|
||||||
throw new CustomValidationException(Status.VALIDATION_ERROR, Translator.toLocale(GepafinConstant.S3_PATH_GENERATION_ERROR_MSG));
|
throw new CustomValidationException(Status.VALIDATION_ERROR, Translator.toLocale(GepafinConstant.S3_PATH_GENERATION_ERROR_MSG));
|
||||||
}
|
}
|
||||||
@@ -1233,7 +1233,7 @@ public class ApplicationDao {
|
|||||||
try (ByteArrayOutputStream zipOutputStream = new ByteArrayOutputStream();
|
try (ByteArrayOutputStream zipOutputStream = new ByteArrayOutputStream();
|
||||||
ZipOutputStream zos = new ZipOutputStream(zipOutputStream)) {
|
ZipOutputStream zos = new ZipOutputStream(zipOutputStream)) {
|
||||||
|
|
||||||
String s3Folder = s3PathConfig.generateDocumentPath(DocumentSourceTypeEnum.APPLICATION, applicationEntity.getCall().getId(), applicationId);
|
String s3Folder = s3PathConfig.generateDocumentPath(DocumentSourceTypeEnum.APPLICATION, applicationEntity.getCall().getId(), applicationId,0L);
|
||||||
|
|
||||||
for (DocumentEntity document : documents) {
|
for (DocumentEntity document : documents) {
|
||||||
String fileName = Utils.extractFileName(document.getFilePath());
|
String fileName = Utils.extractFileName(document.getFilePath());
|
||||||
@@ -1241,7 +1241,7 @@ public class ApplicationDao {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (signedDocument != null) {
|
if (signedDocument != null) {
|
||||||
String signedDocS3Folder = s3PathConfig.generateDocumentPathForOther(DocOtherSourceTypeEnum.USER_SIGNED_DOCUMENT, applicationEntity.getCall().getId(), applicationId);
|
String signedDocS3Folder = s3PathConfig.generateDocumentPathForOther(DocOtherSourceTypeEnum.USER_SIGNED_DOCUMENT, applicationEntity.getCall().getId(), applicationId,0L);
|
||||||
String signedDocFileName = signedDocument.getFileName();
|
String signedDocFileName = signedDocument.getFileName();
|
||||||
addDocumentToZip(zos, signedDocS3Folder, signedDocument.getFilePath(), signedDocFileName);
|
addDocumentToZip(zos, signedDocS3Folder, signedDocument.getFilePath(), signedDocFileName);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -130,7 +130,7 @@ public class CallDao {
|
|||||||
ZipOutputStream zos = new ZipOutputStream(zipOutputStream)) {
|
ZipOutputStream zos = new ZipOutputStream(zipOutputStream)) {
|
||||||
|
|
||||||
for (DocumentEntity document : documents) {
|
for (DocumentEntity document : documents) {
|
||||||
String s3Folder = s3PathConfig.generateDocumentPath(DocumentSourceTypeEnum.CALL, callId, 0L);
|
String s3Folder = s3PathConfig.generateDocumentPath(DocumentSourceTypeEnum.CALL, callId, 0L,0L);
|
||||||
try (InputStream fileInputStream = amazonS3Service.getFile(s3Folder, document.getFilePath())) {
|
try (InputStream fileInputStream = amazonS3Service.getFile(s3Folder, document.getFilePath())) {
|
||||||
String fileName = Utils.extractFileName(document.getFilePath());
|
String fileName = Utils.extractFileName(document.getFilePath());
|
||||||
ZipEntry zipEntry = new ZipEntry(fileName);
|
ZipEntry zipEntry = new ZipEntry(fileName);
|
||||||
|
|||||||
@@ -84,7 +84,7 @@ public class DelegationDao {
|
|||||||
|
|
||||||
public ByteArrayOutputStream generateDocument(Map<String, String> placeholders, String templateName) {
|
public ByteArrayOutputStream generateDocument(Map<String, String> placeholders, String templateName) {
|
||||||
try {
|
try {
|
||||||
String s3Folder = s3ConfigBean.generateDocumentPathForOther(DocOtherSourceTypeEnum.TEMPLATE, 0L, 0L);
|
String s3Folder = s3ConfigBean.generateDocumentPathForOther(DocOtherSourceTypeEnum.TEMPLATE, 0L, 0L,0L);
|
||||||
InputStream templateStream = amazonS3Service.getFile(s3Folder ,templateName);
|
InputStream templateStream = amazonS3Service.getFile(s3Folder ,templateName);
|
||||||
XWPFDocument doc = loadTemplate(templateStream);
|
XWPFDocument doc = loadTemplate(templateStream);
|
||||||
replacePlaceholders(doc, placeholders);
|
replacePlaceholders(doc, placeholders);
|
||||||
@@ -288,6 +288,7 @@ public class DelegationDao {
|
|||||||
if (userCompanyDelegationEntity == null) {
|
if (userCompanyDelegationEntity == null) {
|
||||||
throw new ResourceNotFoundException(Status.NOT_FOUND, Translator.toLocale(GepafinConstant.DELEGATION_NOT_FOUND));
|
throw new ResourceNotFoundException(Status.NOT_FOUND, Translator.toLocale(GepafinConstant.DELEGATION_NOT_FOUND));
|
||||||
}
|
}
|
||||||
|
amazonS3Service.deleteDelegationfromS3(userCompanyDelegationEntity);
|
||||||
userCompanyDelegationEntity.setStatus(UserCompanyDelegationStatusEnum.INACTIVE.getValue());
|
userCompanyDelegationEntity.setStatus(UserCompanyDelegationStatusEnum.INACTIVE.getValue());
|
||||||
userCompanyDelegationRepository.save(userCompanyDelegationEntity);
|
userCompanyDelegationRepository.save(userCompanyDelegationEntity);
|
||||||
|
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
package net.gepafin.tendermanagement.dao;
|
package net.gepafin.tendermanagement.dao;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import jakarta.servlet.http.HttpServletRequest;
|
import jakarta.servlet.http.HttpServletRequest;
|
||||||
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.UserActionContextEnum;
|
||||||
import net.gepafin.tendermanagement.enums.VersionActionTypeEnum;
|
import net.gepafin.tendermanagement.enums.VersionActionTypeEnum;
|
||||||
@@ -18,20 +18,25 @@ import org.springframework.web.multipart.MultipartFile;
|
|||||||
|
|
||||||
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.entities.ApplicationEntity;
|
||||||
import net.gepafin.tendermanagement.entities.CallEntity;
|
import net.gepafin.tendermanagement.entities.CallEntity;
|
||||||
import net.gepafin.tendermanagement.entities.DocumentEntity;
|
import net.gepafin.tendermanagement.entities.DocumentEntity;
|
||||||
import net.gepafin.tendermanagement.enums.DocumentTypeEnum;
|
import net.gepafin.tendermanagement.enums.DocumentTypeEnum;
|
||||||
import net.gepafin.tendermanagement.model.response.DocumentResponseBean;
|
import net.gepafin.tendermanagement.model.response.DocumentResponseBean;
|
||||||
import net.gepafin.tendermanagement.model.response.UploadFileOnAmazonS3Response;
|
import net.gepafin.tendermanagement.model.response.UploadFileOnAmazonS3Response;
|
||||||
|
import net.gepafin.tendermanagement.repositories.ApplicationAmendmentRequestRepository;
|
||||||
import net.gepafin.tendermanagement.repositories.DocumentRepository;
|
import net.gepafin.tendermanagement.repositories.DocumentRepository;
|
||||||
import net.gepafin.tendermanagement.service.AmazonS3Service;
|
import net.gepafin.tendermanagement.service.AmazonS3Service;
|
||||||
|
import net.gepafin.tendermanagement.service.ApplicationAmendmentRequestService;
|
||||||
|
import net.gepafin.tendermanagement.service.ApplicationService;
|
||||||
import net.gepafin.tendermanagement.service.CallService;
|
import net.gepafin.tendermanagement.service.CallService;
|
||||||
import net.gepafin.tendermanagement.web.rest.api.errors.ResourceNotFoundException;
|
import net.gepafin.tendermanagement.web.rest.api.errors.ResourceNotFoundException;
|
||||||
import net.gepafin.tendermanagement.web.rest.api.errors.Status;
|
import net.gepafin.tendermanagement.web.rest.api.errors.Status;
|
||||||
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@Component
|
@Component
|
||||||
public class DocumentDao {
|
public class DocumentDao {
|
||||||
@@ -54,6 +59,18 @@ public class DocumentDao {
|
|||||||
@Autowired
|
@Autowired
|
||||||
private ApplicationRepository applicationFormRepository;
|
private ApplicationRepository applicationFormRepository;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
ApplicationService applicationService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
ApplicationAmendmentRequestService applicationAmendmentRequestService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
ApplicationAmendmentRequestRepository applicationAmendmentRequestRepository;
|
||||||
|
|
||||||
|
@Value("${aws.s3.bucket.name}")
|
||||||
|
private String bucketName;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private LoggingUtil loggingUtil;
|
private LoggingUtil loggingUtil;
|
||||||
|
|
||||||
@@ -122,27 +139,34 @@ public class DocumentDao {
|
|||||||
private UploadFileOnAmazonS3Response uploadFileOnAmazonS3(MultipartFile file, DocumentSourceTypeEnum type, Long sourceId) {
|
private UploadFileOnAmazonS3Response uploadFileOnAmazonS3(MultipartFile file, DocumentSourceTypeEnum type, Long sourceId) {
|
||||||
|
|
||||||
Long applicationId = 0L;
|
Long applicationId = 0L;
|
||||||
|
Long amendmentId = 0L;
|
||||||
Long callId = sourceId;
|
Long callId = sourceId;
|
||||||
if (type == DocumentSourceTypeEnum.APPLICATION) {
|
if (type == DocumentSourceTypeEnum.APPLICATION) {
|
||||||
applicationId = sourceId;
|
applicationId = sourceId;
|
||||||
callId = applicationFormRepository.findCallIdById(applicationId);
|
callId = applicationFormRepository.findCallIdById(applicationId);
|
||||||
|
} else if (type == DocumentSourceTypeEnum.AMENDMENT) {
|
||||||
|
amendmentId = sourceId;
|
||||||
|
ApplicationEntity applicationEntity = applicationAmendmentRequestRepository.findApplicationByAmendmentId(amendmentId);
|
||||||
|
applicationId = applicationEntity.getId();
|
||||||
|
callId = applicationEntity.getCall().getId();
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
String s3Path = generateS3Path(type, callId, applicationId);
|
String s3Path = generateS3Path(type, callId, applicationId, amendmentId);
|
||||||
log.info("Generated S3 path {}", s3Path);
|
log.info("Generated S3 path {}", s3Path);
|
||||||
return amazonS3Service.uploadFileOnAmazonS3(s3Path, file);
|
return amazonS3Service.uploadFileOnAmazonS3(s3Path, file);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new CustomValidationException(Status.VALIDATION_ERROR, Translator.toLocale(GepafinConstant.UPLOAD_ERROR_S3));
|
throw new CustomValidationException(Status.VALIDATION_ERROR, Translator.toLocale(GepafinConstant.UPLOAD_ERROR_S3));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public String generateS3Path(DocumentSourceTypeEnum typeOfDocument, Long callId, Long applicationId) {
|
|
||||||
|
|
||||||
|
public String generateS3Path(DocumentSourceTypeEnum typeOfDocument, Long callId, Long applicationId, Long amendmentId) {
|
||||||
try {
|
try {
|
||||||
return s3ConfigBean.generateDocumentPath(typeOfDocument, callId, applicationId);
|
return s3ConfigBean.generateDocumentPath(typeOfDocument, callId, applicationId, amendmentId);
|
||||||
} catch (IllegalArgumentException e) {
|
} catch (IllegalArgumentException e) {
|
||||||
throw new CustomValidationException(Status.VALIDATION_ERROR, Translator.toLocale(GepafinConstant.S3_PATH_GENERATION_ERROR_MSG));
|
throw new CustomValidationException(Status.VALIDATION_ERROR, Translator.toLocale(GepafinConstant.S3_PATH_GENERATION_ERROR_MSG));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private Long resolveSourceId(Long sourceId, DocumentSourceTypeEnum sourceType) {
|
private Long resolveSourceId(Long sourceId, DocumentSourceTypeEnum sourceType) {
|
||||||
|
|
||||||
if (sourceType == DocumentSourceTypeEnum.CALL) {
|
if (sourceType == DocumentSourceTypeEnum.CALL) {
|
||||||
@@ -159,17 +183,31 @@ public class DocumentDao {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void deleteFile(Long documentId) {
|
public void deleteFile(Long documentId) {
|
||||||
|
DocumentEntity documentEntity = documentRepository.findById(documentId).orElseThrow(() -> new ResourceNotFoundException(Status.NOT_FOUND,
|
||||||
DocumentEntity documentEntity = documentRepository.findById(documentId)
|
Translator.toLocale(GepafinConstant.DOCUMENT_NOT_FOUND)));
|
||||||
.orElseThrow(() -> new ResourceNotFoundException(Status.NOT_FOUND, Translator.toLocale(GepafinConstant.DOCUMENT_NOT_FOUND)));
|
if(Boolean.TRUE.equals(documentEntity.getIsDeleted())){
|
||||||
// String fileName= Utils.extractFileName(documentEntity.getFilePath());
|
return;
|
||||||
// deleteFileOnAmazonS3(fileName);
|
}
|
||||||
|
|
||||||
//cloned for old data
|
|
||||||
DocumentEntity oldDocumentEntity = Utils.getClonedEntityForData(documentEntity);
|
DocumentEntity oldDocumentEntity = Utils.getClonedEntityForData(documentEntity);
|
||||||
|
Long callId = null;
|
||||||
|
Long applicationId = null;
|
||||||
|
Long amendmentId = null;
|
||||||
|
|
||||||
// String fileName= Utils.extractFileName(documentEntity.getFilePath());
|
if (DocumentSourceTypeEnum.CALL.getValue().equalsIgnoreCase(documentEntity.getSource())) {
|
||||||
// deleteFileOnAmazonS3(fileName);
|
callId = documentEntity.getSourceId();
|
||||||
|
} else if (DocumentSourceTypeEnum.APPLICATION.getValue().equalsIgnoreCase(documentEntity.getSource())) {
|
||||||
|
applicationId = documentEntity.getSourceId();
|
||||||
|
ApplicationEntity applicationEntity = applicationService.validateApplication(applicationId);
|
||||||
|
callId = applicationEntity.getCall().getId();
|
||||||
|
}
|
||||||
|
else if(DocumentSourceTypeEnum.AMENDMENT.getValue().equalsIgnoreCase(documentEntity.getSource())){
|
||||||
|
amendmentId = documentEntity.getSourceId();
|
||||||
|
ApplicationEntity applicationEntity = applicationAmendmentRequestRepository.findApplicationByAmendmentId(amendmentId);
|
||||||
|
applicationId = applicationEntity.getId();
|
||||||
|
callId = applicationEntity.getCall().getId();
|
||||||
|
}
|
||||||
|
|
||||||
|
amazonS3Service.deleteFileFromS3(documentEntity, callId, applicationId,amendmentId);
|
||||||
documentEntity.setIsDeleted(true);
|
documentEntity.setIsDeleted(true);
|
||||||
documentRepository.save(documentEntity);
|
documentRepository.save(documentEntity);
|
||||||
|
|
||||||
@@ -178,7 +216,6 @@ public class DocumentDao {
|
|||||||
VersionHistoryRequest.builder().request(request).actionType(VersionActionTypeEnum.SOFT_DELETE).oldData(oldDocumentEntity).newData(documentEntity).build());
|
VersionHistoryRequest.builder().request(request).actionType(VersionActionTypeEnum.SOFT_DELETE).oldData(oldDocumentEntity).newData(documentEntity).build());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public DocumentEntity validateDocument(Long id) {
|
public DocumentEntity validateDocument(Long id) {
|
||||||
return documentRepository.findByIdAndNotDeleted(id).orElseThrow(() -> new ResourceNotFoundException(Status.NOT_FOUND,
|
return documentRepository.findByIdAndNotDeleted(id).orElseThrow(() -> new ResourceNotFoundException(Status.NOT_FOUND,
|
||||||
Translator.toLocale(GepafinConstant.DOCUMENT_NOT_FOUND)));
|
Translator.toLocale(GepafinConstant.DOCUMENT_NOT_FOUND)));
|
||||||
@@ -206,19 +243,28 @@ public class DocumentDao {
|
|||||||
}
|
}
|
||||||
return callDao.convertToDocumentResponseBean(documentEntity);
|
return callDao.convertToDocumentResponseBean(documentEntity);
|
||||||
}
|
}
|
||||||
|
|
||||||
private UploadFileOnAmazonS3Response updateFileOnAmazonS3(MultipartFile file, DocumentSourceTypeEnum type, Long id) {
|
private UploadFileOnAmazonS3Response updateFileOnAmazonS3(MultipartFile file, DocumentSourceTypeEnum type, Long id) {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Long callId;
|
Long callId=null;
|
||||||
Long applicationId;
|
Long applicationId=null;
|
||||||
if(type.equals(DocumentSourceTypeEnum.APPLICATION)){
|
Long amendmentId=null;
|
||||||
|
if (type.equals(DocumentSourceTypeEnum.APPLICATION)) {
|
||||||
callId = applicationFormRepository.findCallIdById(id);
|
callId = applicationFormRepository.findCallIdById(id);
|
||||||
applicationId = id;
|
applicationId = id;
|
||||||
}else{
|
}
|
||||||
|
else if(type.equals(DocumentSourceTypeEnum.AMENDMENT)){
|
||||||
|
amendmentId = id;
|
||||||
|
ApplicationEntity applicationEntity = applicationAmendmentRequestRepository.findApplicationByAmendmentId(amendmentId);
|
||||||
|
applicationId = applicationEntity.getId();
|
||||||
|
callId = applicationEntity.getCall().getId();
|
||||||
|
}
|
||||||
|
else {
|
||||||
callId = id;
|
callId = id;
|
||||||
applicationId = 0L;
|
applicationId = 0L;
|
||||||
}
|
}
|
||||||
String s3Path = generateS3Path(type, callId, applicationId);
|
String s3Path = generateS3Path(type, callId, applicationId,amendmentId);
|
||||||
log.info("Generated S3 path {}", s3Path);
|
log.info("Generated S3 path {}", s3Path);
|
||||||
return amazonS3Service.uploadFileOnAmazonS3(s3Path, file);
|
return amazonS3Service.uploadFileOnAmazonS3(s3Path, file);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
|||||||
@@ -13,25 +13,28 @@ public class S3PathConfig {
|
|||||||
@Autowired
|
@Autowired
|
||||||
S3ConfigRepository s3ConfigRepository;
|
S3ConfigRepository s3ConfigRepository;
|
||||||
|
|
||||||
public String generateDocumentPath(DocumentSourceTypeEnum type, Long callId, Long applicationId) {
|
public String generateDocumentPath(DocumentSourceTypeEnum type, Long callId, Long applicationId,Long amendmentId) {
|
||||||
|
|
||||||
S3ConfigEntity config = getDocumentPath(type);
|
S3ConfigEntity config = getDocumentPath(type);
|
||||||
return config.getParentFolder() + "/" + buildS3Path(config.getPath(), callId, applicationId);
|
return config.getParentFolder() + "/" + buildS3Path(config.getPath(), callId, applicationId,amendmentId);
|
||||||
}
|
}
|
||||||
public String generateDocumentPathForOther(DocOtherSourceTypeEnum type, Long callId, Long applicationId) {
|
public String generateDocumentPathForOther(DocOtherSourceTypeEnum type, Long callId, Long applicationId,Long amendmentId) {
|
||||||
|
|
||||||
S3ConfigEntity config = getDocumentPathForOther(type);
|
S3ConfigEntity config = getDocumentPathForOther(type);
|
||||||
return config.getParentFolder() + "/" + buildS3Path(config.getPath(), callId, applicationId);
|
return config.getParentFolder() + "/" + buildS3Path(config.getPath(), callId, applicationId,amendmentId);
|
||||||
}
|
|
||||||
private String buildS3Path(String pathTemplate, Long callId, Long applicationId) {
|
|
||||||
|
|
||||||
return pathTemplate.replace("{call_id}", callId != null && callId != 0L ? "call_" + callId : "").replace("{application_id}", applicationId != null && applicationId != 0L ? "application_" + applicationId : "");
|
|
||||||
}
|
}
|
||||||
public String generateDocumentPathForDelegationAndSignedDocument(DocOtherSourceTypeEnum type) {
|
public String generateDocumentPathForDelegationAndSignedDocument(DocOtherSourceTypeEnum type) {
|
||||||
|
|
||||||
S3ConfigEntity config = getDocumentPathForOther(type);
|
S3ConfigEntity config = getDocumentPathForOther(type);
|
||||||
return config.getParentFolder() + "/" + config.getPath();
|
return config.getParentFolder() + "/" + config.getPath();
|
||||||
}
|
}
|
||||||
|
private String buildS3Path(String pathTemplate, Long callId, Long applicationId, Long amendmentId) {
|
||||||
|
return pathTemplate
|
||||||
|
.replace("{call_id}", callId != null && callId != 0L ? "call_" + callId : "")
|
||||||
|
.replace("{application_id}", applicationId != null && applicationId != 0L ? "application_" + applicationId : "")
|
||||||
|
.replace("{amendment_id}", amendmentId != null && amendmentId != 0L ? "amendment_" + amendmentId : "");
|
||||||
|
}
|
||||||
|
|
||||||
private S3ConfigEntity getDocumentPath(DocumentSourceTypeEnum type) {
|
private S3ConfigEntity getDocumentPath(DocumentSourceTypeEnum type) {
|
||||||
|
|
||||||
return s3ConfigRepository.getPathByType(type.name()).orElseThrow(() -> new IllegalArgumentException("No path configuration found for type: " + type));
|
return s3ConfigRepository.getPathByType(type.name()).orElseThrow(() -> new IllegalArgumentException("No path configuration found for type: " + type));
|
||||||
|
|||||||
@@ -3,7 +3,11 @@ package net.gepafin.tendermanagement.enums;
|
|||||||
public enum DocOtherSourceTypeEnum {
|
public enum DocOtherSourceTypeEnum {
|
||||||
USER_SIGNED_DOCUMENT("USER_SIGNED_DOCUMENT"),
|
USER_SIGNED_DOCUMENT("USER_SIGNED_DOCUMENT"),
|
||||||
USER_DELEGATION("USER_DELEGATION"),
|
USER_DELEGATION("USER_DELEGATION"),
|
||||||
TEMPLATE("TEMPLATE");
|
TEMPLATE("TEMPLATE"),
|
||||||
|
DELETED_USER_DELEGATION("DELETED_USER_DELEGATION"),
|
||||||
|
DELETED_APPLICATION("DELETED_APPLICATION"),
|
||||||
|
DELETED_CALL("DELETED_CALL"),
|
||||||
|
DELETED_AMENDMENT("DELETED_AMENDMENT");
|
||||||
|
|
||||||
private String value;
|
private String value;
|
||||||
|
|
||||||
|
|||||||
@@ -3,7 +3,9 @@ package net.gepafin.tendermanagement.enums;
|
|||||||
public enum DocumentSourceTypeEnum {
|
public enum DocumentSourceTypeEnum {
|
||||||
CALL("CALL"),
|
CALL("CALL"),
|
||||||
|
|
||||||
APPLICATION("APPLICATION");
|
APPLICATION("APPLICATION"),
|
||||||
|
|
||||||
|
AMENDMENT("AMENDMENT");
|
||||||
|
|
||||||
private String value;
|
private String value;
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package net.gepafin.tendermanagement.repositories;
|
package net.gepafin.tendermanagement.repositories;
|
||||||
|
|
||||||
import net.gepafin.tendermanagement.entities.ApplicationAmendmentRequestEntity;
|
import net.gepafin.tendermanagement.entities.ApplicationAmendmentRequestEntity;
|
||||||
|
import net.gepafin.tendermanagement.entities.ApplicationEntity;
|
||||||
import net.gepafin.tendermanagement.entities.ApplicationEvaluationEntity;
|
import net.gepafin.tendermanagement.entities.ApplicationEvaluationEntity;
|
||||||
|
|
||||||
import org.springframework.data.jpa.repository.JpaRepository;
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
@@ -39,6 +40,13 @@ public interface ApplicationAmendmentRequestRepository extends JpaRepository<App
|
|||||||
|
|
||||||
List<ApplicationAmendmentRequestEntity> findByApplicationIdAndStatusInAndIsDeletedFalse(Long applicationId, List<String> statuses);
|
List<ApplicationAmendmentRequestEntity> findByApplicationIdAndStatusInAndIsDeletedFalse(Long applicationId, List<String> statuses);
|
||||||
|
|
||||||
|
@Query("SELECT app " +
|
||||||
|
"FROM ApplicationEntity app " +
|
||||||
|
"WHERE app.id = (SELECT aar.applicationId " +
|
||||||
|
"FROM ApplicationAmendmentRequestEntity aar " +
|
||||||
|
"WHERE aar.id = :amendmentId)")
|
||||||
|
ApplicationEntity findApplicationByAmendmentId(Long amendmentId);
|
||||||
|
|
||||||
@Query(value = "SELECT amr " +
|
@Query(value = "SELECT amr " +
|
||||||
"FROM ApplicationAmendmentRequestEntity amr " +
|
"FROM ApplicationAmendmentRequestEntity amr " +
|
||||||
"WHERE amr.applicationEvaluationEntity.id = :id " +
|
"WHERE amr.applicationEvaluationEntity.id = :id " +
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
package net.gepafin.tendermanagement.service;
|
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.stereotype.Component;
|
||||||
import org.springframework.web.multipart.MultipartFile;
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
@@ -9,7 +11,8 @@ import java.io.IOException;
|
|||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
|
|
||||||
@Component
|
@Component
|
||||||
public interface AmazonS3Service {
|
public interface
|
||||||
|
AmazonS3Service {
|
||||||
|
|
||||||
UploadFileOnAmazonS3Response uploadFileOnAmazonS3(String s3Folder, MultipartFile file);
|
UploadFileOnAmazonS3Response uploadFileOnAmazonS3(String s3Folder, MultipartFile file);
|
||||||
|
|
||||||
@@ -17,4 +20,14 @@ public interface AmazonS3Service {
|
|||||||
|
|
||||||
InputStream getFile(String s3Folder, String filePath) throws IOException;
|
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);
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -1,10 +1,17 @@
|
|||||||
package net.gepafin.tendermanagement.service.impl;
|
package net.gepafin.tendermanagement.service.impl;
|
||||||
|
|
||||||
|
import com.amazonaws.AmazonServiceException;
|
||||||
|
import com.amazonaws.SdkClientException;
|
||||||
import com.amazonaws.services.s3.AmazonS3;
|
import com.amazonaws.services.s3.AmazonS3;
|
||||||
|
import com.amazonaws.services.s3.AmazonS3Client;
|
||||||
import com.amazonaws.services.s3.model.*;
|
import com.amazonaws.services.s3.model.*;
|
||||||
|
|
||||||
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.S3PathConfig;
|
||||||
|
import net.gepafin.tendermanagement.entities.DocumentEntity;
|
||||||
|
import net.gepafin.tendermanagement.entities.UserCompanyDelegationEntity;
|
||||||
|
import net.gepafin.tendermanagement.enums.DocOtherSourceTypeEnum;
|
||||||
import net.gepafin.tendermanagement.model.response.UploadFileOnAmazonS3Response;
|
import net.gepafin.tendermanagement.model.response.UploadFileOnAmazonS3Response;
|
||||||
import net.gepafin.tendermanagement.service.AmazonS3Service;
|
import net.gepafin.tendermanagement.service.AmazonS3Service;
|
||||||
import net.gepafin.tendermanagement.util.Utils;
|
import net.gepafin.tendermanagement.util.Utils;
|
||||||
@@ -45,6 +52,18 @@ public class AmazonS3ServiceImpl implements AmazonS3Service {
|
|||||||
@Value("${aws.s3.url}")
|
@Value("${aws.s3.url}")
|
||||||
private String s3Url;
|
private String s3Url;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private S3PathConfig s3ConfigBean;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private AmazonS3Client s3Client;
|
||||||
|
|
||||||
|
@Value("${aws.s3.region}")
|
||||||
|
private String region;
|
||||||
|
|
||||||
|
private String getBucketUrlPrefix() {
|
||||||
|
return "https://" + bucketName + ".s3." + region + ".amazonaws.com/";
|
||||||
|
}
|
||||||
|
|
||||||
private String upload(String fileName, String s3Folder,
|
private String upload(String fileName, String s3Folder,
|
||||||
MultipartFile file) throws IOException {
|
MultipartFile file) throws IOException {
|
||||||
@@ -125,4 +144,84 @@ public class AmazonS3ServiceImpl implements AmazonS3Service {
|
|||||||
Translator.toLocale(GepafinConstant.UPLOAD_ERROR_S3));
|
Translator.toLocale(GepafinConstant.UPLOAD_ERROR_S3));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@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) {
|
||||||
|
try {
|
||||||
|
log.info("Moving file from {} to {} in bucket {}", oldPath, newPath, bucketName);
|
||||||
|
|
||||||
|
CopyObjectRequest copyRequest = new CopyObjectRequest(bucketName, oldPath, bucketName, newPath);
|
||||||
|
s3Client.copyObject(copyRequest);
|
||||||
|
log.info("File copied successfully from {} to {}", oldPath, newPath);
|
||||||
|
|
||||||
|
s3Client.deleteObject(bucketName, oldPath);
|
||||||
|
log.info("Original file deleted successfully: {}", oldPath);
|
||||||
|
} catch (AmazonServiceException e) {
|
||||||
|
log.error("AWS service error while moving file: {}", e.getErrorMessage(), e);
|
||||||
|
throw e;
|
||||||
|
} catch (SdkClientException e) {
|
||||||
|
log.error("SDK client error while moving file: {}", e.getMessage(), e);
|
||||||
|
throw e;
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("Unexpected error while moving file: {}", e.getMessage(), e);
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@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());
|
||||||
|
}
|
||||||
|
|
||||||
|
@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.");
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -164,10 +164,10 @@ public class S3ReUploadMigrationService {
|
|||||||
Long callId;
|
Long callId;
|
||||||
|
|
||||||
if (sourceType.equals(DocumentSourceTypeEnum.CALL)) {
|
if (sourceType.equals(DocumentSourceTypeEnum.CALL)) {
|
||||||
return s3ConfigBean.generateDocumentPath(sourceType, document.getSourceId(), 0L);
|
return s3ConfigBean.generateDocumentPath(sourceType, document.getSourceId(), 0L,0L);
|
||||||
} else {
|
} else {
|
||||||
callId = applicationRepository.findCallIdById(document.getSourceId());
|
callId = applicationRepository.findCallIdById(document.getSourceId());
|
||||||
return s3ConfigBean.generateDocumentPath(sourceType, callId, document.getSourceId());
|
return s3ConfigBean.generateDocumentPath(sourceType, callId, document.getSourceId(),0L);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -130,7 +130,7 @@ public class UserSignedAndDelegationServiceImpl {
|
|||||||
|
|
||||||
private String generateNewS3PathForDelegationDoc() {
|
private String generateNewS3PathForDelegationDoc() {
|
||||||
|
|
||||||
return s3ConfigBean.generateDocumentPathForOther(DocOtherSourceTypeEnum.USER_DELEGATION, 0L, 0L);
|
return s3ConfigBean.generateDocumentPathForOther(DocOtherSourceTypeEnum.USER_DELEGATION, 0L, 0L,0L);
|
||||||
}
|
}
|
||||||
|
|
||||||
private String generateNewS3PathForUserSignedDoc(ApplicationSignedDocumentEntity document) {
|
private String generateNewS3PathForUserSignedDoc(ApplicationSignedDocumentEntity document) {
|
||||||
|
|||||||
@@ -1899,6 +1899,53 @@
|
|||||||
</addColumn>
|
</addColumn>
|
||||||
</changeSet>
|
</changeSet>
|
||||||
|
|
||||||
|
<changeSet id="28-10-2024_1" author="Nisha Kashyap">
|
||||||
|
<insert tableName="s3_path_configuration">
|
||||||
|
<column name="type" value="DELETED_CALL"/>
|
||||||
|
<column name="path" value="call/{call_id}/deleted"/>
|
||||||
|
<column name="bucket_name" value="mementoresources"/>
|
||||||
|
<column name="created_date" value="2024-10-25 03:00:00"/>
|
||||||
|
<column name="updated_date" value="2024-10-25 03:00:00"/>
|
||||||
|
<column name="parent_folder" value="gepafin/local"/>
|
||||||
|
</insert>
|
||||||
|
|
||||||
|
<insert tableName="s3_path_configuration">
|
||||||
|
<column name="type" value="DELETED_APPLICATION"/>
|
||||||
|
<column name="path" value="call/{call_id}/application/{application_id}/deleted"/>
|
||||||
|
<column name="bucket_name" value="mementoresources"/>
|
||||||
|
<column name="created_date" value="2024-10-25 03:00:00"/>
|
||||||
|
<column name="updated_date" value="2024-10-25 03:00:00"/>
|
||||||
|
<column name="parent_folder" value="gepafin/local"/>
|
||||||
|
</insert>
|
||||||
|
|
||||||
|
<insert tableName="s3_path_configuration">
|
||||||
|
<column name="type" value="DELETED_USER_DELEGATION"/>
|
||||||
|
<column name="path" value="user_delegation/deleted"/>
|
||||||
|
<column name="bucket_name" value="mementoresources"/>
|
||||||
|
<column name="created_date" value="2024-10-25 03:00:00"/>
|
||||||
|
<column name="updated_date" value="2024-10-25 03:00:00"/>
|
||||||
|
<column name="parent_folder" value="gepafin/local"/>
|
||||||
|
</insert>
|
||||||
|
|
||||||
|
<insert tableName="s3_path_configuration">
|
||||||
|
<column name="type" value="AMENDMENT"/>
|
||||||
|
<column name="path" value="call/{call_id}/application/{application_id}/amendment/{amendment_id}"/>
|
||||||
|
<column name="bucket_name" value="mementoresources"/>
|
||||||
|
<column name="created_date" value="2024-10-25 03:00:00"/>
|
||||||
|
<column name="updated_date" value="2024-10-25 03:00:00"/>
|
||||||
|
<column name="parent_folder" value="gepafin/local"/>
|
||||||
|
</insert>
|
||||||
|
|
||||||
|
<insert tableName="s3_path_configuration">
|
||||||
|
<column name="type" value="DELETED_AMENDMENT"/>
|
||||||
|
<column name="path" value="call/{call_id}/application/{application_id}/amendment/{amendment_id}/deleted"/>
|
||||||
|
<column name="bucket_name" value="mementoresources"/>
|
||||||
|
<column name="created_date" value="2024-10-25 03:00:00"/>
|
||||||
|
<column name="updated_date" value="2024-10-25 03:00:00"/>
|
||||||
|
<column name="parent_folder" value="gepafin/local"/>
|
||||||
|
</insert>
|
||||||
|
</changeSet>
|
||||||
|
|
||||||
<changeSet id="22-11-2024_2" author="Piyush">
|
<changeSet id="22-11-2024_2" author="Piyush">
|
||||||
<addColumn tableName="user_action">
|
<addColumn tableName="user_action">
|
||||||
<column name="is_deleted" type="BOOLEAN" defaultValueBoolean="false">
|
<column name="is_deleted" type="BOOLEAN" defaultValueBoolean="false">
|
||||||
|
|||||||
Reference in New Issue
Block a user