updated code
This commit is contained in:
@@ -258,30 +258,29 @@ public class CompanyDocumentDao {
|
||||
return userActionContext;
|
||||
}
|
||||
|
||||
public DocumentResponseBean validateAndDuplicateCompanyDocument(HttpServletRequest request , Long userId ,Long companyDocumentId , Long applicationId , DocumentTypeEnum documentTypeEnum){
|
||||
public DocumentResponseBean createDuplicateCompanyDocument(HttpServletRequest request , Long userId ,Long companyDocumentId , Long applicationId , DocumentTypeEnum documentTypeEnum){
|
||||
ApplicationEntity applicationEntity = applicationService.validateApplication(applicationId);
|
||||
CompanyDocumentEntity companyDocumentEntity = validateCompanyDocument(companyDocumentId);
|
||||
validator.validateUserWithCompany(request,companyDocumentEntity.getCompanyId());
|
||||
|
||||
String oldS3Path = companyDocumentEntity.getFilePath();
|
||||
String newS3Path = s3ConfigBean.generateDocumentPath(DocumentSourceTypeEnum.APPLICATION,applicationEntity.getCall().getId(),applicationId,0L);
|
||||
String companyDocumentPath = companyDocumentEntity.getFilePath();
|
||||
String documentPath = s3ConfigBean.generateDocumentPath(DocumentSourceTypeEnum.APPLICATION,applicationEntity.getCall().getId(),applicationId,0L);
|
||||
|
||||
log.info("Original Paths - oldPath: {}, newPath: {}", oldS3Path, newS3Path);
|
||||
log.info("Original Paths - oldPath: {}, newPath: {}", companyDocumentPath, documentPath);
|
||||
|
||||
oldS3Path = amazonS3ServiceImpl.decodeS3Key(amazonS3ServiceImpl.cleanOldPath(oldS3Path));
|
||||
newS3Path = amazonS3ServiceImpl.cleanNewPath(oldS3Path, newS3Path);
|
||||
log.info("Moving file from {} to {} in bucket {}", oldS3Path, newS3Path, bucketName);
|
||||
UploadFileOnAmazonS3Response response;
|
||||
try {
|
||||
response = amazonS3ServiceImpl.copyFile(companyDocumentEntity.getName(), companyDocumentPath, documentPath);
|
||||
} catch (Exception e) {
|
||||
log.error("Error occurred while uploading file from Amazon S3: {}", e);
|
||||
throw new CustomValidationException(Status.VALIDATION_ERROR,
|
||||
Translator.toLocale(GepafinConstant.UPLOAD_ERROR_S3));
|
||||
}
|
||||
|
||||
CopyObjectRequest copyRequest = new CopyObjectRequest(bucketName, oldS3Path, bucketName, newS3Path);
|
||||
s3Client.copyObject(copyRequest);
|
||||
log.info("File copied successfully from {} to {}", oldS3Path, newS3Path);
|
||||
|
||||
URL amazonS3Url = amazonS3.getUrl(bucketName, newS3Path);
|
||||
String fileUrl = amazonS3Url.toString();
|
||||
|
||||
DocumentEntity entity = new DocumentEntity();
|
||||
entity.setFilePath(fileUrl);
|
||||
entity.setFileName(companyDocumentEntity.getFileName());
|
||||
entity.setFilePath(response.getFilePath());
|
||||
entity.setFileName(response.getFileName());
|
||||
entity.setSource(DocumentSourceTypeEnum.APPLICATION.getValue());
|
||||
entity.setType(documentTypeEnum.getValue());
|
||||
entity.setSourceId(applicationId);
|
||||
|
||||
Reference in New Issue
Block a user