Done changes related to evaluation document
This commit is contained in:
@@ -6,6 +6,7 @@ import java.util.stream.Collectors;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import net.gepafin.tendermanagement.enums.*;
|
||||
import net.gepafin.tendermanagement.model.request.VersionHistoryRequest;
|
||||
import net.gepafin.tendermanagement.repositories.ApplicationEvaluationRepository;
|
||||
import net.gepafin.tendermanagement.repositories.ApplicationRepository;
|
||||
import net.gepafin.tendermanagement.util.LoggingUtil;
|
||||
import net.gepafin.tendermanagement.util.Utils;
|
||||
@@ -54,7 +55,7 @@ public class DocumentDao {
|
||||
private S3PathConfig s3ConfigBean;
|
||||
|
||||
@Autowired
|
||||
private ApplicationRepository applicationFormRepository;
|
||||
private ApplicationRepository applicationRepository;
|
||||
|
||||
@Autowired
|
||||
ApplicationService applicationService;
|
||||
@@ -64,6 +65,8 @@ public class DocumentDao {
|
||||
|
||||
@Autowired
|
||||
ApplicationAmendmentRequestRepository applicationAmendmentRequestRepository;
|
||||
@Autowired
|
||||
private ApplicationEvaluationRepository applicationEvaluationRepository;
|
||||
|
||||
@Value("${aws.s3.bucket.name}")
|
||||
private String bucketName;
|
||||
@@ -77,7 +80,7 @@ public class DocumentDao {
|
||||
// @Value("${aws.s3.url.folder}")
|
||||
// private String s3Folder;
|
||||
|
||||
public List<DocumentResponseBean> uploadFiles(List<MultipartFile> files, Long sourceId, DocumentSourceTypeEnum sourceType, DocumentTypeEnum fileType) {
|
||||
public List<DocumentResponseBean> uploadFiles(Long userId,List<MultipartFile> files, Long sourceId, DocumentSourceTypeEnum sourceType, DocumentTypeEnum fileType) {
|
||||
|
||||
List<DocumentEntity> documentEntities = new ArrayList<>();
|
||||
Long source = resolveSourceId(sourceId, sourceType);
|
||||
@@ -91,6 +94,7 @@ public class DocumentDao {
|
||||
documentEntity.setType(fileType.getValue());
|
||||
documentEntity.setFilePath(uploadFileOnAmazonS3Response.getFilePath());
|
||||
documentEntity.setIsDeleted(false);
|
||||
documentEntity.setUploadedBy(userId);
|
||||
documentEntities.add(documentEntity);
|
||||
}
|
||||
}
|
||||
@@ -137,18 +141,24 @@ public class DocumentDao {
|
||||
|
||||
Long applicationId = 0L;
|
||||
Long amendmentId = 0L;
|
||||
Long evaluationId = 0L;
|
||||
Long callId = sourceId;
|
||||
if (type == DocumentSourceTypeEnum.APPLICATION) {
|
||||
applicationId = sourceId;
|
||||
callId = applicationFormRepository.findCallIdById(applicationId);
|
||||
callId = applicationRepository.findCallIdById(applicationId);
|
||||
} else if (type == DocumentSourceTypeEnum.AMENDMENT) {
|
||||
amendmentId = sourceId;
|
||||
ApplicationEntity applicationEntity = applicationAmendmentRequestRepository.findApplicationByAmendmentId(amendmentId);
|
||||
applicationId = applicationEntity.getId();
|
||||
callId = applicationEntity.getCall().getId();
|
||||
}else if (type == DocumentSourceTypeEnum.EVALUATION) {
|
||||
evaluationId = sourceId;
|
||||
ApplicationEntity applicationEntity = applicationEvaluationRepository.findApplicationByEvaluationId(evaluationId);
|
||||
applicationId = applicationEntity.getId();
|
||||
callId = applicationEntity.getCall().getId();
|
||||
}
|
||||
try {
|
||||
String s3Path = generateS3Path(type, callId, applicationId, amendmentId);
|
||||
String s3Path = generateS3Path(type, callId, applicationId, amendmentId, evaluationId);
|
||||
log.info("Generated S3 path {}", s3Path);
|
||||
return amazonS3Service.uploadFileOnAmazonS3(s3Path, file);
|
||||
} catch (Exception e) {
|
||||
@@ -156,9 +166,9 @@ public class DocumentDao {
|
||||
}
|
||||
}
|
||||
|
||||
public String generateS3Path(DocumentSourceTypeEnum typeOfDocument, Long callId, Long applicationId, Long amendmentId) {
|
||||
public String generateS3Path(DocumentSourceTypeEnum typeOfDocument, Long callId, Long applicationId, Long amendmentId,Long evaluationId) {
|
||||
try {
|
||||
return s3ConfigBean.generateDocumentPath(typeOfDocument, callId, applicationId, amendmentId);
|
||||
return s3ConfigBean.generateDocumentPath(typeOfDocument, callId, applicationId, amendmentId,evaluationId);
|
||||
} catch (IllegalArgumentException e) {
|
||||
throw new CustomValidationException(Status.VALIDATION_ERROR, Translator.toLocale(GepafinConstant.S3_PATH_GENERATION_ERROR_MSG));
|
||||
}
|
||||
@@ -188,6 +198,7 @@ public class DocumentDao {
|
||||
Long callId = null;
|
||||
Long applicationId = null;
|
||||
Long amendmentId = null;
|
||||
Long evaluationId = null;
|
||||
|
||||
if (DocumentSourceTypeEnum.CALL.getValue().equalsIgnoreCase(documentEntity.getSource())) {
|
||||
callId = documentEntity.getSourceId();
|
||||
@@ -201,9 +212,14 @@ public class DocumentDao {
|
||||
ApplicationEntity applicationEntity = applicationAmendmentRequestRepository.findApplicationByAmendmentId(amendmentId);
|
||||
applicationId = applicationEntity.getId();
|
||||
callId = applicationEntity.getCall().getId();
|
||||
} else if(DocumentSourceTypeEnum.EVALUATION.getValue().equalsIgnoreCase(documentEntity.getSource())){
|
||||
evaluationId = documentEntity.getSourceId();
|
||||
ApplicationEntity applicationEntity = applicationEvaluationRepository.findApplicationByEvaluationId(evaluationId);
|
||||
applicationId = applicationEntity.getId();
|
||||
callId = applicationEntity.getCall().getId();
|
||||
}
|
||||
|
||||
deleteFileFromS3(documentEntity, callId, applicationId,amendmentId);
|
||||
deleteFileFromS3(documentEntity, callId, applicationId,amendmentId,evaluationId);
|
||||
|
||||
}
|
||||
|
||||
@@ -241,8 +257,9 @@ public class DocumentDao {
|
||||
Long callId=null;
|
||||
Long applicationId=null;
|
||||
Long amendmentId=null;
|
||||
Long evaluationId=null;
|
||||
if (type.equals(DocumentSourceTypeEnum.APPLICATION)) {
|
||||
callId = applicationFormRepository.findCallIdById(id);
|
||||
callId = applicationRepository.findCallIdById(id);
|
||||
applicationId = id;
|
||||
}
|
||||
else if(type.equals(DocumentSourceTypeEnum.AMENDMENT)){
|
||||
@@ -250,12 +267,18 @@ public class DocumentDao {
|
||||
ApplicationEntity applicationEntity = applicationAmendmentRequestRepository.findApplicationByAmendmentId(amendmentId);
|
||||
applicationId = applicationEntity.getId();
|
||||
callId = applicationEntity.getCall().getId();
|
||||
}else if(type.equals(DocumentSourceTypeEnum.EVALUATION)){
|
||||
evaluationId = id;
|
||||
ApplicationEntity applicationEntity = applicationEvaluationRepository.findApplicationByEvaluationId(evaluationId);
|
||||
applicationId = applicationEntity.getId();
|
||||
callId = applicationEntity.getCall().getId();
|
||||
}
|
||||
|
||||
else {
|
||||
callId = id;
|
||||
applicationId = 0L;
|
||||
}
|
||||
String s3Path = generateS3Path(type, callId, applicationId,amendmentId);
|
||||
String s3Path = generateS3Path(type, callId, applicationId,amendmentId,evaluationId);
|
||||
log.info("Generated S3 path {}", s3Path);
|
||||
return amazonS3Service.uploadFileOnAmazonS3(s3Path, file);
|
||||
} catch (Exception e) {
|
||||
@@ -267,12 +290,12 @@ public class DocumentDao {
|
||||
return callDao.convertToDocumentResponseBean(documentEntity);
|
||||
}
|
||||
|
||||
public void deleteFileFromS3(DocumentEntity documentEntity, Long callId, Long applicationId,Long amendmentId) {
|
||||
public void deleteFileFromS3(DocumentEntity documentEntity, Long callId, Long applicationId,Long amendmentId,Long evaluationId) {
|
||||
try {
|
||||
|
||||
DocumentEntity oldDocumentEntity = Utils.getClonedEntityForData(documentEntity);
|
||||
String oldS3Path = documentEntity.getFilePath();
|
||||
String newS3Path = s3ConfigBean.generateDocumentPathForOther(DocOtherSourceTypeEnum.valueOf("DELETED_" + documentEntity.getSource().toUpperCase()), callId, applicationId,amendmentId);
|
||||
String newS3Path = s3ConfigBean.generateDocumentPathForOther(DocOtherSourceTypeEnum.valueOf("DELETED_" + documentEntity.getSource().toUpperCase()), callId, applicationId,amendmentId,evaluationId);
|
||||
UploadFileOnAmazonS3Response response = amazonS3Service.moveFile(documentEntity.getFileName(), oldS3Path, newS3Path);
|
||||
documentEntity.setFileName(response.getFileName());
|
||||
documentEntity.setFilePath(response.getFilePath());
|
||||
|
||||
Reference in New Issue
Block a user