Resolved conflicts

This commit is contained in:
nisha
2024-10-23 11:39:46 +05:30
9 changed files with 66 additions and 91 deletions

View File

@@ -127,8 +127,9 @@ public class CallDao {
ZipOutputStream zos = new ZipOutputStream(zipOutputStream)) {
for (DocumentEntity document : documents) {
try (InputStream fileInputStream = amazonS3Service.getFile(s3Folder, document.getFileName())) {
ZipEntry zipEntry = new ZipEntry(document.getFileName());
try (InputStream fileInputStream = amazonS3Service.getFile(s3Folder, document.getFilePath())) {
String fileName = Utils.extractFileName(document.getFilePath());
ZipEntry zipEntry = new ZipEntry(fileName);
zos.putNextEntry(zipEntry);
IOUtils.copy(fileInputStream, zos);
zos.closeEntry();

View File

@@ -7,7 +7,6 @@ import java.util.HashMap;
import java.util.Map;
import java.util.function.Function;
import org.apache.commons.io.FilenameUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.poi.xwpf.usermodel.XWPFDocument;
import org.springframework.beans.factory.annotation.Autowired;
@@ -24,6 +23,7 @@ import net.gepafin.tendermanagement.entities.UserEntity;
import net.gepafin.tendermanagement.enums.UserCompanyDelegationStatusEnum;
import net.gepafin.tendermanagement.model.request.CompanyDelegationRequest;
import net.gepafin.tendermanagement.model.response.CompanyDelegationResponse;
import net.gepafin.tendermanagement.model.response.UploadFileOnAmazonS3Response;
import net.gepafin.tendermanagement.model.response.UserResponseBean;
import net.gepafin.tendermanagement.repositories.DocumentRepository;
import net.gepafin.tendermanagement.repositories.UserCompanyDelegationRepository;
@@ -96,7 +96,7 @@ public class DelegationDao {
companyDao.getUserWithCompany(userEntity.getId(), companyId);
updatePlaceholdersForDelegation(user, companyEntity, placeholders, companyDelegationRequest);
DocumentEntity documentEntity = documentRepository.findBySource(GepafinConstant.DELEGATION_TEMPLATE).get(0);
return generateDocument(placeholders, documentEntity.getFileName());
return generateDocument(placeholders, documentEntity.getFilePath());
}
private Map<String, String> updatePlaceholdersForDelegation(UserResponseBean user, CompanyEntity companyEntity,
@@ -179,7 +179,7 @@ public class DelegationDao {
userCompanyDelegationEntity.setStatus(UserCompanyDelegationStatusEnum.INACTIVE.getValue());
userCompanyDelegationRepository.save(userCompanyDelegationEntity);
}
UploadFileOnAmazonS3 uploadFileOnAmazonS3 = uploadFileOnAmazonS3(file);
UploadFileOnAmazonS3Response uploadFileOnAmazonS3Response = amazonS3Service.uploadFileOnAmazonS3(s3Folder, file);
userCompanyDelegationEntity = new UserCompanyDelegationEntity();
userCompanyDelegationEntity.setCompanyId(companyId);
userCompanyDelegationEntity.setUserId(userEntity.getId());
@@ -187,8 +187,8 @@ public class DelegationDao {
userCompanyDelegationEntity.setBeneficiaryId(userEntity.getBeneficiary().getId());
}
userCompanyDelegationEntity.setStatus(UserCompanyDelegationStatusEnum.ACTIVE.getValue());
userCompanyDelegationEntity.setFileName(uploadFileOnAmazonS3.fileName());
userCompanyDelegationEntity.setFilePath(uploadFileOnAmazonS3.filepath());
userCompanyDelegationEntity.setFileName(uploadFileOnAmazonS3Response.getFileName());
userCompanyDelegationEntity.setFilePath(uploadFileOnAmazonS3Response.getFilePath());
userCompanyDelegationRepository.save(userCompanyDelegationEntity);
return convertUserCompanyDelegationToCompanyDelegationResponse(userCompanyDelegationEntity);
}
@@ -197,25 +197,6 @@ public class DelegationDao {
UserCompanyDelegationEntity userCompanyDelegationEntity) {
return Utils.convertSourceObjectToDestinationObject(userCompanyDelegationEntity, CompanyDelegationResponse.class);
}
private UploadFileOnAmazonS3 uploadFileOnAmazonS3(MultipartFile file){
String extension = FilenameUtils.getExtension(file.getOriginalFilename());
String fileName = org.springframework.util.StringUtils.cleanPath(file.getOriginalFilename());
String firstNameContain = fileName.substring(0, fileName.lastIndexOf('.'));
firstNameContain+=Utils.randomKey(5);
fileName = (firstNameContain + "." + extension);
try {
String filepath = amazonS3Service.upload(fileName, s3Folder, file);
return new UploadFileOnAmazonS3(fileName, filepath);
} catch (Exception e) {
throw new CustomValidationException(Status.VALIDATION_ERROR,
Translator.toLocale(GepafinConstant.UPLOAD_ERROR_S3));
}
}
private record UploadFileOnAmazonS3(String fileName, String filepath) {
}
private void validateFileType(MultipartFile file) {
if (file.isEmpty()) {

View File

@@ -1,14 +1,11 @@
package net.gepafin.tendermanagement.dao;
import java.io.IOException;
import java.util.stream.Collectors;
import net.gepafin.tendermanagement.enums.DocumentSourceTypeEnum;
import org.apache.commons.io.FilenameUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;
import org.springframework.web.multipart.MultipartFile;
import net.gepafin.tendermanagement.config.Translator;
@@ -17,10 +14,10 @@ import net.gepafin.tendermanagement.entities.CallEntity;
import net.gepafin.tendermanagement.entities.DocumentEntity;
import net.gepafin.tendermanagement.enums.DocumentTypeEnum;
import net.gepafin.tendermanagement.model.response.DocumentResponseBean;
import net.gepafin.tendermanagement.model.response.UploadFileOnAmazonS3Response;
import net.gepafin.tendermanagement.repositories.DocumentRepository;
import net.gepafin.tendermanagement.service.AmazonS3Service;
import net.gepafin.tendermanagement.service.CallService;
import net.gepafin.tendermanagement.util.Utils;
import net.gepafin.tendermanagement.web.rest.api.errors.ResourceNotFoundException;
import net.gepafin.tendermanagement.web.rest.api.errors.Status;
@@ -49,19 +46,17 @@ public class DocumentDao {
List<DocumentEntity> documentEntities = new ArrayList<>();
Long source = resolveSourceId(sourceId, sourceType);
for (MultipartFile file : files) {
try {
uploadFileOnAmazonS3 result = uploadFileOnAmazonS3(file);
if (result != null) {
DocumentEntity documentEntity = new DocumentEntity();
documentEntity.setFileName(result.fileName());
documentEntity.setSource(sourceType.getValue());
documentEntity.setSourceId(source);
documentEntity.setType(fileType.getValue());
documentEntity.setFilePath(result.filepath());
documentEntity.setIsDeleted(false);
documentEntities.add(documentEntity);
}
} catch (IOException e) {
UploadFileOnAmazonS3Response uploadFileOnAmazonS3Response = amazonS3Service.uploadFileOnAmazonS3(s3Folder,
file);
if (uploadFileOnAmazonS3Response != null) {
DocumentEntity documentEntity = new DocumentEntity();
documentEntity.setFileName(uploadFileOnAmazonS3Response.getFileName());
documentEntity.setSource(sourceType.getValue());
documentEntity.setSourceId(source);
documentEntity.setType(fileType.getValue());
documentEntity.setFilePath(uploadFileOnAmazonS3Response.getFilePath());
documentEntity.setIsDeleted(false);
documentEntities.add(documentEntity);
}
}
documentRepository.saveAll(documentEntities);
@@ -80,19 +75,6 @@ public class DocumentDao {
return sourceId;
}
private uploadFileOnAmazonS3 uploadFileOnAmazonS3(MultipartFile file) throws IOException {
String extension = FilenameUtils.getExtension(file.getOriginalFilename());
String fileName = StringUtils.cleanPath(file.getOriginalFilename());
String firstNameContain = fileName.substring(0, fileName.lastIndexOf('.'));
fileName = (firstNameContain + "." + extension);
String filepath = amazonS3Service.upload(fileName, s3Folder, file);
uploadFileOnAmazonS3 result = new uploadFileOnAmazonS3(fileName, filepath);
return result;
}
private record uploadFileOnAmazonS3(String fileName, String filepath) {
}
public void deleteFile(Long documentId) {
DocumentEntity documentEntity = validateDocument(documentId);
// String fileName= Utils.extractFileName(documentEntity.getFilePath());
@@ -101,13 +83,6 @@ public class DocumentDao {
documentRepository.save(documentEntity);
}
private DocumentEntity deleteFileOnAmazonS3(String fileName) {
try {
amazonS3Service.delete(s3Folder, fileName);
} catch (Exception e) {
}
return null;
}
public DocumentEntity validateDocument(Long id) {
return documentRepository.findById(id).orElseThrow(() -> new ResourceNotFoundException(Status.NOT_FOUND,
@@ -116,16 +91,10 @@ public class DocumentDao {
public DocumentResponseBean updateDocument(Long documentId, MultipartFile file, DocumentTypeEnum documentTypeEnum) {
DocumentEntity documentEntity = validateDocument(documentId);
String fileName = Utils.extractFileName(documentEntity.getFilePath());
deleteFileOnAmazonS3(fileName);
uploadFileOnAmazonS3 result = null;
try {
result = uploadFileOnAmazonS3(file);
} catch (IOException e) {
}
if (result != null) {
documentEntity.setFilePath(result.filepath);
documentEntity.setFileName(result.fileName);
UploadFileOnAmazonS3Response uploadFileOnAmazonS3Response = amazonS3Service.uploadFileOnAmazonS3(s3Folder, file);
if (uploadFileOnAmazonS3Response != null) {
documentEntity.setFileName(uploadFileOnAmazonS3Response.getFileName());
documentEntity.setFilePath(uploadFileOnAmazonS3Response.getFilePath());
documentEntity.setType(documentTypeEnum.getValue());
documentEntity.setSource(documentEntity.getSource());
documentEntity.setSourceId(documentEntity.getSourceId());