updated code

This commit is contained in:
rajesh
2025-03-04 16:41:34 +05:30
parent 9cfb383046
commit 59d6387b3f

View File

@@ -1,5 +1,6 @@
package net.gepafin.tendermanagement.dao; package net.gepafin.tendermanagement.dao;
import com.amazonaws.services.s3.AmazonS3;
import com.amazonaws.services.s3.AmazonS3Client; import com.amazonaws.services.s3.AmazonS3Client;
import com.amazonaws.services.s3.model.CopyObjectRequest; import com.amazonaws.services.s3.model.CopyObjectRequest;
import jakarta.persistence.criteria.Predicate; import jakarta.persistence.criteria.Predicate;
@@ -33,6 +34,7 @@ import org.springframework.data.jpa.domain.Specification;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartFile;
import java.net.URL;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@@ -86,6 +88,9 @@ public class CompanyDocumentDao {
@Autowired @Autowired
private Validator validator; private Validator validator;
@Autowired
private AmazonS3 amazonS3;
public List<CompanyDocumentResponseBean> uploadFileForCompany(HttpServletRequest request, Long userId, List<MultipartFile> files, Long companyId, Long documentCategoryId, CompanyDocumentTypeEnum companyDocumentSourceTypeEnum, LocalDateTime expirationDate,String name){ public List<CompanyDocumentResponseBean> uploadFileForCompany(HttpServletRequest request, Long userId, List<MultipartFile> files, Long companyId, Long documentCategoryId, CompanyDocumentTypeEnum companyDocumentSourceTypeEnum, LocalDateTime expirationDate,String name){
DocumentCategoryEntity categoryEntity = categoryDao.validateCategory(documentCategoryId); DocumentCategoryEntity categoryEntity = categoryDao.validateCategory(documentCategoryId);
validator.validateUserWithCompany(request,companyId); validator.validateUserWithCompany(request,companyId);
@@ -271,8 +276,11 @@ public class CompanyDocumentDao {
s3Client.copyObject(copyRequest); s3Client.copyObject(copyRequest);
log.info("File copied successfully from {} to {}", oldS3Path, newS3Path); log.info("File copied successfully from {} to {}", oldS3Path, newS3Path);
URL amazonS3Url = amazonS3.getUrl(bucketName, newS3Path);
String fileUrl = amazonS3Url.toString();
DocumentEntity entity = new DocumentEntity(); DocumentEntity entity = new DocumentEntity();
entity.setFilePath(newS3Path); entity.setFilePath(fileUrl);
entity.setFileName(companyDocumentEntity.getFileName()); entity.setFileName(companyDocumentEntity.getFileName());
entity.setSource(DocumentSourceTypeEnum.APPLICATION.getValue()); entity.setSource(DocumentSourceTypeEnum.APPLICATION.getValue());
entity.setType(documentTypeEnum.getValue()); entity.setType(documentTypeEnum.getValue());