Resolved Conflicts
This commit is contained in:
@@ -6,6 +6,7 @@ import net.gepafin.tendermanagement.entities.*;
|
||||
import net.gepafin.tendermanagement.entities.SystemEmailTemplatesEntity.SystemEmailTemplatesEntityTypeEnum;
|
||||
import net.gepafin.tendermanagement.enums.ApplicationSignedDocumentStatusEnum;
|
||||
import net.gepafin.tendermanagement.enums.ApplicationStatusTypeEnum;
|
||||
import net.gepafin.tendermanagement.enums.DocOtherSourceTypeEnum;
|
||||
import net.gepafin.tendermanagement.enums.DocumentSourceTypeEnum;
|
||||
import net.gepafin.tendermanagement.enums.RoleStatusEnum;
|
||||
import net.gepafin.tendermanagement.enums.UserCompanyDelegationStatusEnum;
|
||||
@@ -127,6 +128,9 @@ public class ApplicationDao {
|
||||
@Autowired
|
||||
private UserService userService;
|
||||
|
||||
@Autowired
|
||||
S3PathConfig s3ConfigBean;
|
||||
|
||||
|
||||
public ApplicationResponseBean createApplication(HttpServletRequest request, ApplicationRequestBean applicationRequestBean, Long formId, Long applicationId) {
|
||||
FormEntity formEntity = formService.validateForm(formId);
|
||||
@@ -789,9 +793,9 @@ public class ApplicationDao {
|
||||
// applicationSignedDocument.setStatus(ApplicationSignedDocumentStatusEnum.INACTIVE.getValue());
|
||||
// applicationSignedDocumentRepository.save(applicationSignedDocument);
|
||||
}
|
||||
UploadFileOnAmazonS3Response uploadFileOnAmazonS3 = amazonS3Service.uploadFileOnAmazonS3(signedDocumentS3Folder,
|
||||
file);
|
||||
applicationSignedDocument = new ApplicationSignedDocumentEntity();
|
||||
UploadFileOnAmazonS3Response uploadFileOnAmazonS3 = uploadFileOnAmazonS3ForUserSignedDocument(file,
|
||||
applicationEntity.getCall().getId(), applicationId);
|
||||
applicationSignedDocument = new ApplicationSignedDocumentEntity();
|
||||
applicationSignedDocument.setApplication(applicationEntity);
|
||||
applicationSignedDocument.setFileName(uploadFileOnAmazonS3.getFileName());
|
||||
applicationSignedDocument.setFilePath(uploadFileOnAmazonS3.getFilePath());
|
||||
@@ -801,7 +805,22 @@ public class ApplicationDao {
|
||||
applicationRepository.save(applicationEntity);
|
||||
return convertApplicationSignedDocumentToApplicationSignedDocumentResponse(applicationSignedDocument);
|
||||
}
|
||||
|
||||
private UploadFileOnAmazonS3Response uploadFileOnAmazonS3ForUserSignedDocument(MultipartFile file, Long callId, Long applicationId) {
|
||||
try {
|
||||
String s3Path = generateS3PathForDelegation(callId, applicationId);
|
||||
log.info("S3 Path {}", s3Path);
|
||||
return amazonS3Service.uploadFileOnAmazonS3(s3Path, file);
|
||||
} catch (Exception e) {
|
||||
throw new CustomValidationException(Status.VALIDATION_ERROR, Translator.toLocale(GepafinConstant.UPLOAD_ERROR_S3));
|
||||
}
|
||||
}
|
||||
private String generateS3PathForDelegation(Long callId, Long applicationId) {
|
||||
try {
|
||||
return s3ConfigBean.generateDocumentPathForOther(DocOtherSourceTypeEnum.USER_SIGNED_DOCUMENT, callId, applicationId);
|
||||
} catch (IllegalArgumentException e) {
|
||||
throw new CustomValidationException(Status.VALIDATION_ERROR, Translator.toLocale(GepafinConstant.S3_PATH_GENERATION_ERROR_MSG));
|
||||
}
|
||||
}
|
||||
private ApplicationSignedDocumentResponse convertApplicationSignedDocumentToApplicationSignedDocumentResponse(
|
||||
ApplicationSignedDocumentEntity applicationSignedDocument) {
|
||||
ApplicationSignedDocumentResponse applicationSignedDocumentResponse = new ApplicationSignedDocumentResponse();
|
||||
|
||||
@@ -7,6 +7,7 @@ import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.function.Function;
|
||||
|
||||
import net.gepafin.tendermanagement.enums.DocOtherSourceTypeEnum;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.poi.xwpf.usermodel.XWPFDocument;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -53,6 +54,9 @@ public class DelegationDao {
|
||||
|
||||
@Autowired
|
||||
private DocumentRepository documentRepository;
|
||||
|
||||
@Autowired
|
||||
private S3PathConfig s3ConfigBean;
|
||||
|
||||
@Value("${aws.s3.url.folder.delegation}")
|
||||
private String s3Folder;
|
||||
@@ -185,7 +189,7 @@ public class DelegationDao {
|
||||
userCompanyDelegationEntity.setStatus(UserCompanyDelegationStatusEnum.INACTIVE.getValue());
|
||||
userCompanyDelegationRepository.save(userCompanyDelegationEntity);
|
||||
}
|
||||
UploadFileOnAmazonS3Response uploadFileOnAmazonS3Response = amazonS3Service.uploadFileOnAmazonS3(s3Folder, file);
|
||||
UploadFileOnAmazonS3Response uploadFileOnAmazonS3Response = uploadFileOnAmazonS3ForCompanyDelegation(file);
|
||||
userCompanyDelegationEntity = new UserCompanyDelegationEntity();
|
||||
userCompanyDelegationEntity.setCompanyId(companyId);
|
||||
userCompanyDelegationEntity.setUserId(userEntity.getId());
|
||||
@@ -198,7 +202,21 @@ public class DelegationDao {
|
||||
userCompanyDelegationRepository.save(userCompanyDelegationEntity);
|
||||
return convertUserCompanyDelegationToCompanyDelegationResponse(userCompanyDelegationEntity);
|
||||
}
|
||||
|
||||
private UploadFileOnAmazonS3Response uploadFileOnAmazonS3ForCompanyDelegation(MultipartFile file) {
|
||||
try {
|
||||
String s3Path = generateS3PathForDelegation();
|
||||
return amazonS3Service.uploadFileOnAmazonS3(s3Path, file);
|
||||
} catch (Exception e) {
|
||||
throw new CustomValidationException(Status.VALIDATION_ERROR, Translator.toLocale(GepafinConstant.UPLOAD_ERROR_S3));
|
||||
}
|
||||
}
|
||||
private String generateS3PathForDelegation() {
|
||||
try {
|
||||
return s3ConfigBean.generateDocumentPathForDelegationAndSignedDocument(DocOtherSourceTypeEnum.USER_DELEGATION);
|
||||
} catch (IllegalArgumentException e) {
|
||||
throw new CustomValidationException(Status.VALIDATION_ERROR, Translator.toLocale(GepafinConstant.S3_PATH_GENERATION_ERROR_MSG));
|
||||
}
|
||||
}
|
||||
private CompanyDelegationResponse convertUserCompanyDelegationToCompanyDelegationResponse(
|
||||
UserCompanyDelegationEntity userCompanyDelegationEntity) {
|
||||
return Utils.convertSourceObjectToDestinationObject(userCompanyDelegationEntity, CompanyDelegationResponse.class);
|
||||
|
||||
@@ -2,7 +2,10 @@ package net.gepafin.tendermanagement.dao;
|
||||
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import net.gepafin.tendermanagement.enums.DocumentSourceTypeEnum;
|
||||
import net.gepafin.tendermanagement.repositories.ApplicationRepository;
|
||||
import net.gepafin.tendermanagement.web.rest.api.errors.CustomValidationException;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Component;
|
||||
@@ -24,6 +27,7 @@ import net.gepafin.tendermanagement.web.rest.api.errors.Status;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@Slf4j
|
||||
@Component
|
||||
public class DocumentDao {
|
||||
|
||||
@@ -38,6 +42,12 @@ public class DocumentDao {
|
||||
|
||||
@Autowired
|
||||
private CallService callService;
|
||||
|
||||
@Autowired
|
||||
private S3PathConfig s3ConfigBean;
|
||||
|
||||
@Autowired
|
||||
private ApplicationRepository applicationFormRepository;
|
||||
|
||||
@Value("${aws.s3.url.folder}")
|
||||
private String s3Folder;
|
||||
@@ -46,8 +56,7 @@ public class DocumentDao {
|
||||
List<DocumentEntity> documentEntities = new ArrayList<>();
|
||||
Long source = resolveSourceId(sourceId, sourceType);
|
||||
for (MultipartFile file : files) {
|
||||
UploadFileOnAmazonS3Response uploadFileOnAmazonS3Response = amazonS3Service.uploadFileOnAmazonS3(s3Folder,
|
||||
file);
|
||||
UploadFileOnAmazonS3Response uploadFileOnAmazonS3Response = uploadFileOnAmazonS3(file, sourceType, sourceId);
|
||||
if (uploadFileOnAmazonS3Response != null) {
|
||||
DocumentEntity documentEntity = new DocumentEntity();
|
||||
documentEntity.setFileName(uploadFileOnAmazonS3Response.getFileName());
|
||||
@@ -62,6 +71,30 @@ public class DocumentDao {
|
||||
documentRepository.saveAll(documentEntities);
|
||||
return documentEntities.stream().map(callDao::convertToDocumentResponseBean).collect(Collectors.toList());
|
||||
}
|
||||
private UploadFileOnAmazonS3Response uploadFileOnAmazonS3(MultipartFile file, DocumentSourceTypeEnum type, Long sourceId) {
|
||||
|
||||
Long applicationId = 0L;
|
||||
Long callId = sourceId;
|
||||
if (type == DocumentSourceTypeEnum.APPLICATION) {
|
||||
applicationId = sourceId;
|
||||
callId = applicationFormRepository.findCallIdById(applicationId);
|
||||
}
|
||||
try {
|
||||
String s3Path = generateS3Path(type, callId, applicationId);
|
||||
log.info("Generated S3 path {}", s3Path);
|
||||
return amazonS3Service.uploadFileOnAmazonS3(s3Path, file);
|
||||
} catch (Exception e) {
|
||||
throw new CustomValidationException(Status.VALIDATION_ERROR, Translator.toLocale(GepafinConstant.UPLOAD_ERROR_S3));
|
||||
}
|
||||
}
|
||||
public String generateS3Path(DocumentSourceTypeEnum typeOfDocument, Long callId, Long applicationId) {
|
||||
|
||||
try {
|
||||
return s3ConfigBean.generateDocumentPath(typeOfDocument, callId, applicationId);
|
||||
} catch (IllegalArgumentException e) {
|
||||
throw new CustomValidationException(Status.VALIDATION_ERROR, Translator.toLocale(GepafinConstant.S3_PATH_GENERATION_ERROR_MSG));
|
||||
}
|
||||
}
|
||||
private Long resolveSourceId(Long sourceId, DocumentSourceTypeEnum sourceType) {
|
||||
if (sourceType == DocumentSourceTypeEnum.CALL) {
|
||||
CallEntity callEntity = callService.validateCall(sourceId);
|
||||
@@ -91,8 +124,9 @@ public class DocumentDao {
|
||||
|
||||
public DocumentResponseBean updateDocument(Long documentId, MultipartFile file, DocumentTypeEnum documentTypeEnum) {
|
||||
DocumentEntity documentEntity = validateDocument(documentId);
|
||||
UploadFileOnAmazonS3Response uploadFileOnAmazonS3Response = amazonS3Service.uploadFileOnAmazonS3(s3Folder, file);
|
||||
if (uploadFileOnAmazonS3Response != null) {
|
||||
String type = documentEntity.getSource();
|
||||
UploadFileOnAmazonS3Response uploadFileOnAmazonS3Response = updateFileOnAmazonS3(file, DocumentSourceTypeEnum.valueOf(type), documentEntity.getSourceId());
|
||||
if (uploadFileOnAmazonS3Response != null) {
|
||||
documentEntity.setFileName(uploadFileOnAmazonS3Response.getFileName());
|
||||
documentEntity.setFilePath(uploadFileOnAmazonS3Response.getFilePath());
|
||||
documentEntity.setType(documentTypeEnum.getValue());
|
||||
@@ -102,7 +136,25 @@ public class DocumentDao {
|
||||
}
|
||||
return callDao.convertToDocumentResponseBean(documentEntity);
|
||||
}
|
||||
private UploadFileOnAmazonS3Response updateFileOnAmazonS3(MultipartFile file, DocumentSourceTypeEnum type, Long id) {
|
||||
|
||||
try {
|
||||
Long callId;
|
||||
Long applicationId;
|
||||
if(type.equals("APPLICATION")){
|
||||
callId = applicationFormRepository.findCallIdById(id);
|
||||
applicationId = id;
|
||||
}else{
|
||||
callId = id;
|
||||
applicationId = 0L;
|
||||
}
|
||||
String s3Path = generateS3Path(type, callId, applicationId);
|
||||
log.info("Generated S3 path {}", s3Path);
|
||||
return amazonS3Service.uploadFileOnAmazonS3(s3Path, file);
|
||||
} catch (Exception e) {
|
||||
throw new CustomValidationException(Status.VALIDATION_ERROR, Translator.toLocale(GepafinConstant.UPLOAD_ERROR_S3));
|
||||
}
|
||||
}
|
||||
public DocumentResponseBean getDocument(Long documentId) {
|
||||
DocumentEntity documentEntity = validateDocument(documentId);
|
||||
return callDao.convertToDocumentResponseBean(documentEntity);
|
||||
|
||||
104
src/main/java/net/gepafin/tendermanagement/dao/S3ConfigDao.java
Normal file
104
src/main/java/net/gepafin/tendermanagement/dao/S3ConfigDao.java
Normal file
@@ -0,0 +1,104 @@
|
||||
package net.gepafin.tendermanagement.dao;
|
||||
|
||||
import net.gepafin.tendermanagement.config.Translator;
|
||||
import net.gepafin.tendermanagement.constants.GepafinConstant;
|
||||
import net.gepafin.tendermanagement.entities.S3ConfigEntity;
|
||||
import net.gepafin.tendermanagement.model.request.S3ConfigReq;
|
||||
import net.gepafin.tendermanagement.model.response.S3ConfigBean;
|
||||
import net.gepafin.tendermanagement.repositories.S3ConfigRepository;
|
||||
import net.gepafin.tendermanagement.web.rest.api.errors.CustomValidationException;
|
||||
import net.gepafin.tendermanagement.web.rest.api.errors.Status;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
import static net.gepafin.tendermanagement.util.Utils.setIfUpdated;
|
||||
|
||||
@Component
|
||||
public class S3ConfigDao {
|
||||
private static final Logger log = LoggerFactory.getLogger(S3ConfigDao.class);
|
||||
|
||||
@Autowired
|
||||
S3ConfigRepository s3ConfigRepository;
|
||||
|
||||
public S3ConfigBean addS3Path(S3ConfigReq s3PathConfigurationReq) {
|
||||
|
||||
log.info("Adding s3 s3PathConfigurationReq structure with it's type..");
|
||||
S3ConfigEntity s3PathConfigurationEntity = convertToS3pathEntity(s3PathConfigurationReq);
|
||||
s3PathConfigurationEntity = s3ConfigRepository.save(s3PathConfigurationEntity);
|
||||
log.info("Added s3 path config details {} to DB.", s3PathConfigurationEntity);
|
||||
return convertToS3pathBean(s3PathConfigurationEntity);
|
||||
}
|
||||
private S3ConfigEntity convertToS3pathEntity(S3ConfigReq s3PathConfigReq) {
|
||||
|
||||
S3ConfigEntity s3PathConfigEntity = new S3ConfigEntity();
|
||||
s3PathConfigEntity.setPath(s3PathConfigReq.getPath());
|
||||
s3PathConfigEntity.setType(s3PathConfigReq.getType());
|
||||
s3PathConfigEntity.setBucketName(s3PathConfigReq.getBucketName());
|
||||
return s3PathConfigEntity;
|
||||
}
|
||||
private S3ConfigBean convertToS3pathBean(S3ConfigEntity s3PathConfigReq) {
|
||||
|
||||
S3ConfigBean s3PathConfigBean = new S3ConfigBean();
|
||||
s3PathConfigBean.setPath(s3PathConfigReq.getPath());
|
||||
s3PathConfigBean.setType(s3PathConfigReq.getType());
|
||||
s3PathConfigBean.setBucketName(s3PathConfigReq.getBucketName());
|
||||
return s3PathConfigBean;
|
||||
}
|
||||
|
||||
public Optional<S3ConfigEntity> getS3PathByType(String type) {
|
||||
|
||||
log.info("Fetching S3-Path structure by type: {}", type);
|
||||
Optional<S3ConfigEntity> s3PathData = s3ConfigRepository.getPathByType(type);
|
||||
if (s3PathData == null) {
|
||||
log.error("No S3-Path found for type: {}", type);
|
||||
throw new CustomValidationException(Status.NOT_FOUND, Translator.toLocale(GepafinConstant.S3_PATH_STRUCTURE_NOT_FOUND_BY_TYPE_MSG));
|
||||
}
|
||||
log.info("Fetched S3-Path: {} for type: {}", s3PathData, type);
|
||||
return s3PathData;
|
||||
}
|
||||
|
||||
public S3ConfigEntity deleteS3PathConfigById(Long id) {
|
||||
|
||||
log.info("Checking s3-path associated with this id {} to delete....", id);
|
||||
S3ConfigEntity s3PathConfigData = s3ConfigRepository.findS3PathConfigurationById(id);
|
||||
if (s3PathConfigData == null) {
|
||||
log.error("No S3-Path found for id: {}", id);
|
||||
throw new CustomValidationException(Status.NOT_FOUND, Translator.toLocale(GepafinConstant.S3_PATH_STRUCTURE_NOT_FOUND_BY_ID_MSG));
|
||||
} else {
|
||||
log.info("Found s3-path associated with this id {} to delete.", id);
|
||||
s3ConfigRepository.deleteById(id);
|
||||
log.error("Deleted s3-path configuration successfully for id: {}", id);
|
||||
return s3PathConfigData;
|
||||
}
|
||||
}
|
||||
public S3ConfigBean updateS3PathConfiguration(S3ConfigReq s3PathConfigurationReq, Long id) {
|
||||
|
||||
log.info("Updating S3-path Configuration.");
|
||||
S3ConfigEntity s3PathConfigDataExists = s3ConfigRepository.findS3PathConfigurationById(id);
|
||||
if (s3PathConfigDataExists == null) {
|
||||
log.error("No S3-Path found for id: {}", id);
|
||||
throw new CustomValidationException(Status.NOT_FOUND, Translator.toLocale(GepafinConstant.S3_PATH_STRUCTURE_NOT_FOUND_BY_ID_MSG));
|
||||
} else {
|
||||
Optional<S3ConfigEntity> s3PathData = s3ConfigRepository.getPathByType(s3PathConfigurationReq.getType());
|
||||
if(s3PathData != null){
|
||||
log.error("S3-Path type already exist. {}", s3PathData);
|
||||
throw new CustomValidationException(Status.BAD_REQUEST, Translator.toLocale(GepafinConstant.S3_PATH_CONFIG_DUPLICATE_TYPE_ALREADY_EXIST));
|
||||
}
|
||||
S3ConfigEntity s3PathConfigurationEntity = convertToS3pathEntity(s3PathConfigurationReq);
|
||||
setIfUpdated(s3PathConfigurationEntity::getPath, s3PathConfigurationEntity::setPath, s3PathConfigurationReq.getPath());
|
||||
setIfUpdated(s3PathConfigurationEntity::getBucketName, s3PathConfigurationEntity::setBucketName, s3PathConfigurationReq.getBucketName());
|
||||
setIfUpdated(s3PathConfigurationEntity::getType, s3PathConfigurationEntity::setType, s3PathConfigurationReq.getType());
|
||||
// s3PathConfigurationEntity.setType(s3PathConfigurationReq.getType());
|
||||
// s3PathConfigurationEntity.setPath(s3PathConfigurationReq.getPath());
|
||||
// s3PathConfigurationEntity.setBucketName(s3PathConfigurationReq.getBucketName());
|
||||
s3ConfigRepository.save(s3PathConfigurationEntity);
|
||||
log.info("Updated S3-path-configuration successfully.");
|
||||
return convertToS3pathBean(s3PathConfigurationEntity);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
package net.gepafin.tendermanagement.dao;
|
||||
|
||||
import net.gepafin.tendermanagement.entities.S3ConfigEntity;
|
||||
import net.gepafin.tendermanagement.enums.DocOtherSourceTypeEnum;
|
||||
import net.gepafin.tendermanagement.enums.DocumentSourceTypeEnum;
|
||||
import net.gepafin.tendermanagement.repositories.S3ConfigRepository;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
public class S3PathConfig {
|
||||
|
||||
@Autowired
|
||||
S3ConfigRepository s3ConfigRepository;
|
||||
|
||||
public String generateDocumentPath(DocumentSourceTypeEnum type, Long callId, Long applicationId) {
|
||||
|
||||
S3ConfigEntity config = getDocumentPath(type);
|
||||
return config.getParentFolder() + "/" + buildS3Path(config.getPath(), callId, applicationId);
|
||||
}
|
||||
public String generateDocumentPathForOther(DocOtherSourceTypeEnum type, Long callId, Long applicationId) {
|
||||
|
||||
S3ConfigEntity config = getDocumentPathForOther(type);
|
||||
return config.getParentFolder() + "/" + buildS3Path(config.getPath(), callId, applicationId);
|
||||
}
|
||||
private String buildS3Path(String pathTemplate, Long callId, Long applicationId) {
|
||||
|
||||
return pathTemplate.replace("{call_id}", callId != null && callId != 0L ? "call_" + callId : "").replace("{application_id}", applicationId != null && applicationId != 0L ? "application_" + applicationId : "");
|
||||
}
|
||||
public String generateDocumentPathForDelegationAndSignedDocument(DocOtherSourceTypeEnum type) {
|
||||
|
||||
S3ConfigEntity config = getDocumentPathForOther(type);
|
||||
return config.getParentFolder() + "/" + config.getPath();
|
||||
}
|
||||
private S3ConfigEntity getDocumentPath(DocumentSourceTypeEnum type) {
|
||||
|
||||
return s3ConfigRepository.getPathByType(type.name()).orElseThrow(() -> new IllegalArgumentException("No path configuration found for type: " + type));
|
||||
}
|
||||
private S3ConfigEntity getDocumentPathForOther(DocOtherSourceTypeEnum type) {
|
||||
|
||||
return s3ConfigRepository.getPathByType(type.name()).orElseThrow(() -> new IllegalArgumentException("No path configuration found for type: " + type));
|
||||
}
|
||||
public String getBucketNameForOtherType(DocOtherSourceTypeEnum type){
|
||||
return s3ConfigRepository.getBucketNameByType(type);
|
||||
}
|
||||
public String getBucketNameForCallAppType(DocumentSourceTypeEnum type){
|
||||
return s3ConfigRepository.getBucketNameByType(type);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user