updated code

This commit is contained in:
rajesh
2025-03-12 18:51:40 +05:30
parent 6bdf208741
commit bf5d3d79b3
7 changed files with 56 additions and 31 deletions

View File

@@ -19,4 +19,6 @@ AmazonS3Service {
UploadFileOnAmazonS3Response moveFile(String fileName, String oldPath, String newPath);
UploadFileOnAmazonS3Response copyFile(String fileName, String oldS3Path, String newS3Path);
}

View File

@@ -20,7 +20,7 @@ public interface CompanyDocumentService {
void deleteCompanyFile(HttpServletRequest request,Long companyDocumentId);
DocumentResponseBean validateAndDuplicateCompanyDocument(HttpServletRequest request, Long companyDocumentId, Long applicationId, DocumentTypeEnum typeEnum);
DocumentResponseBean createDuplicateCompanyDocument(HttpServletRequest request, Long companyDocumentId, Long applicationId, DocumentTypeEnum typeEnum);
List<CompanyDocumentResponseBean> getAllCompanyDocument(HttpServletRequest request ,Long companyId , CompanyDocumentTypeEnum typeEnum);

View File

@@ -160,20 +160,14 @@ public class AmazonS3ServiceImpl implements AmazonS3Service {
@Override
public UploadFileOnAmazonS3Response moveFile(String fileName, String oldPath, String newPath) {
try {
log.info("Original Paths - oldPath: {}, newPath: {}", oldPath, newPath);
oldPath = decodeS3Key(cleanOldPath(oldPath));
newPath = cleanNewPath(oldPath, newPath);
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);
UploadFileOnAmazonS3Response response = copyFile(fileName, oldPath, newPath);
s3Client.deleteObject(bucketName, oldPath);
s3Client.deleteObject(bucketName, decodeS3Key(cleanOldPath(oldPath)));
log.info("Original file deleted successfully: {}", oldPath);
String filePath = s3Url + newPath;
return UploadFileOnAmazonS3Response.builder().fileName(fileName).filePath(filePath).build();
return response;
} catch (AmazonServiceException e) {
log.error("AWS service error while moving file: {}", e.getErrorMessage(), e);
throw e;
@@ -193,4 +187,34 @@ public class AmazonS3ServiceImpl implements AmazonS3Service {
public String cleanOldPath(String oldPath) {
return oldPath.replace(s3Url, "");
}
@Override
public UploadFileOnAmazonS3Response copyFile(String fileName, String oldS3Path, String newS3Path){
try {
log.info("Copying file from {} to {} in bucket {}", oldS3Path, newS3Path, bucketName);
oldS3Path = decodeS3Key(cleanOldPath(oldS3Path));
newS3Path = cleanNewPath(oldS3Path, newS3Path);
log.info("Copying file from {} to {} in bucket {}", oldS3Path, newS3Path, bucketName);
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();
return UploadFileOnAmazonS3Response.builder().fileName(fileName).filePath(fileUrl).build();
}
catch (AmazonServiceException e) {
log.error("AWS service error while copying file: {}", e.getErrorMessage(), e);
throw e;
} catch (SdkClientException e) {
log.error("SDK client error while copying file: {}", e.getMessage(), e);
throw e;
} catch (Exception e) {
log.error("Unexpected error while copying file: {}", e.getMessage(), e);
throw e;
}
}
}

View File

@@ -53,9 +53,9 @@ public class CompanyDocumentServiceImpl implements CompanyDocumentService {
}
@Override
public DocumentResponseBean validateAndDuplicateCompanyDocument(HttpServletRequest request, Long companyDocumentId, Long applicationId, DocumentTypeEnum typeEnum) {
public DocumentResponseBean createDuplicateCompanyDocument(HttpServletRequest request, Long companyDocumentId, Long applicationId, DocumentTypeEnum typeEnum) {
UserEntity user = validator.validateUser(request);
return companyDocumentDao.validateAndDuplicateCompanyDocument(request, user.getId(), companyDocumentId,applicationId,typeEnum);
return companyDocumentDao.createDuplicateCompanyDocument(request, user.getId(), companyDocumentId,applicationId,typeEnum);
}
@Override