Done ticket GEPAFINBE-6139

This commit is contained in:
rajesh
2025-10-13 21:50:26 +05:30
parent 2bf9fe368c
commit 38515ed38b
42 changed files with 561 additions and 150 deletions

View File

@@ -5,13 +5,19 @@ import net.gepafin.tendermanagement.config.Translator;
import net.gepafin.tendermanagement.constants.GepafinConstant;
import net.gepafin.tendermanagement.entities.ApplicationAmendmentRequestEntity;
import net.gepafin.tendermanagement.entities.CommunicationEntity;
import net.gepafin.tendermanagement.entities.DocumentEntity;
import net.gepafin.tendermanagement.enums.CommunicationInitiatorTypeEnum;
import net.gepafin.tendermanagement.enums.DocumentSourceTypeEnum;
import net.gepafin.tendermanagement.enums.DocumentTypeEnum;
import net.gepafin.tendermanagement.enums.VersionActionTypeEnum;
import net.gepafin.tendermanagement.model.request.CommunicationRequestBean;
import net.gepafin.tendermanagement.model.request.VersionHistoryRequest;
import net.gepafin.tendermanagement.model.response.ApplicationAmendmentResponse;
import net.gepafin.tendermanagement.model.response.CommunicationResponseBean;
import net.gepafin.tendermanagement.model.response.DocumentResponseBean;
import net.gepafin.tendermanagement.repositories.CommunicationRepository;
import net.gepafin.tendermanagement.service.ApplicationAmendmentRequestService;
import net.gepafin.tendermanagement.service.DocumentService;
import net.gepafin.tendermanagement.util.LoggingUtil;
import net.gepafin.tendermanagement.util.Utils;
import net.gepafin.tendermanagement.util.Validator;
@@ -22,9 +28,12 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.multipart.MultipartFile;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
@Component
public class CommunicationDao {
@@ -45,17 +54,48 @@ public class CommunicationDao {
@Autowired
private HttpServletRequest request;
public CommunicationResponseBean addCommentToAmendmentRequest(HttpServletRequest request, CommunicationRequestBean communicationReq, Long amendmentId) {
@Autowired
private DocumentDao documentDao;
@Autowired
private ApplicationAmendmentRequestDao applicationAmendmentRequestDao;
@Autowired
private DocumentService documentService;
public CommunicationResponseBean addCommentToAmendmentRequest(HttpServletRequest request, CommunicationRequestBean communicationReq, Long amendmentId, List<MultipartFile> files) {
log.info("Adding communication request...");
CommunicationEntity communicationEntity = convertToCommunicationCommentEntity(communicationReq, amendmentId);
communicationEntity = communicationRepository.save(communicationEntity);
List<DocumentResponseBean> communicationDocumentBeans = new ArrayList<>();
CommunicationEntity communicationEntity = convertToCommunicationCommentEntity(communicationReq, amendmentId,communicationDocumentBeans,files);
/** This code is responsible for adding a version history log for the "adding comment to amendment request" operation. **/
loggingUtil.addVersionHistory(VersionHistoryRequest.builder().request(request).actionType(VersionActionTypeEnum.INSERT).oldData(null).newData(communicationEntity).build());
log.info("Added comment: {}", communicationEntity);
return convertToCommunicationResponseBean(communicationEntity);
communicationDocumentBeans=getDocumentResponseBean(communicationEntity);
return convertToCommunicationResponseBean(communicationEntity,communicationDocumentBeans);
}
private List<DocumentResponseBean> getDocumentResponseBean(CommunicationEntity communicationEntity) {
List<Long> documentIds = applicationAmendmentRequestDao.extractIds(communicationEntity.getDocuments());
List<DocumentResponseBean> documentResponseBeans = documentIds.stream()
.map(id -> {
DocumentEntity documentEntity = documentService.validateDocument(id);
DocumentResponseBean responseBean = new DocumentResponseBean();
responseBean.setId(documentEntity.getId());
responseBean.setName(documentEntity.getFileName());
responseBean.setType(DocumentTypeEnum.valueOf(documentEntity.getType()));
responseBean.setSource(DocumentSourceTypeEnum.valueOf(documentEntity.getSource()));
responseBean.setSourceId(documentEntity.getSourceId());
responseBean.setFilePath(documentEntity.getFilePath());
responseBean.setCreatedDate(documentEntity.getCreatedDate());
responseBean.setUpdatedDate(documentEntity.getUpdatedDate());
responseBean.setDocumentAttachmentId(documentEntity.getDocumentAttachmentId());
return responseBean;
})
.toList();
return documentResponseBeans;
}
public String deleteComment(Long amendmentId, Long commentId) {
@@ -90,6 +130,7 @@ public class CommunicationDao {
public CommunicationResponseBean updateAmendmentComment(CommunicationRequestBean communicationRequestBean, Long amendmentId, Long commentId) {
log.info("Updating communication comment...");
CommunicationEntity existingComment = communicationRepository.findById(commentId)
.orElseThrow(() -> new CustomValidationException(Status.NOT_FOUND, Translator.toLocale(GepafinConstant.COMMENT_NOT_FOUND)));
//cloned for old data for communication
@@ -106,11 +147,11 @@ public class CommunicationDao {
/** This code is responsible for adding a version history log for the "updating comment to amendment request" operation. **/
loggingUtil.addVersionHistory(VersionHistoryRequest.builder().request(request).actionType(VersionActionTypeEnum.UPDATE).oldData(oldCommentData).newData(existingComment).build());
return convertToCommunicationResponseBean(existingComment);
List<DocumentResponseBean> communicationDocumentBeans=getDocumentResponseBean(existingComment);
return convertToCommunicationResponseBean(existingComment,communicationDocumentBeans);
}
private CommunicationResponseBean convertToCommunicationResponseBean(CommunicationEntity entity) {
private CommunicationResponseBean convertToCommunicationResponseBean(CommunicationEntity entity,List<DocumentResponseBean> communicationResponseBean) {
CommunicationResponseBean response = new CommunicationResponseBean();
response.setComment(entity.getCommunicationComment());
@@ -122,10 +163,11 @@ public class CommunicationDao {
response.setSenderUserId(entity.getSenderUserId());
response.setReceiverUserId(entity.getReceiverUserId());
response.setId(entity.getId());
response.setDocuments(communicationResponseBean);
return response;
}
private CommunicationEntity convertToCommunicationCommentEntity(CommunicationRequestBean communicationReq, Long amendmentId) {
private CommunicationEntity convertToCommunicationCommentEntity(CommunicationRequestBean communicationReq, Long amendmentId,List<DocumentResponseBean> communicationDocumentBean,List<MultipartFile> files) {
ApplicationAmendmentRequestEntity amendmentRequest = applicationAmendmentRequestService.validateApplicationAmendmentRequest(amendmentId);
@@ -136,12 +178,24 @@ public class CommunicationDao {
communicationEntity.setIsDeleted(false);
communicationEntity.setCommentedDate(LocalDateTime.now());
if(validator.checkIsPreInstructor()){
communicationEntity.setIntiatorType(CommunicationInitiatorTypeEnum.INSTRUCTOR.getValue());
communicationEntity.setSenderUserId(amendmentRequest.getApplicationEvaluationEntity().getUserId());
communicationEntity.setReceiverUserId(amendmentRequest.getApplicationEvaluationEntity().getAssignedApplicationsEntity().getApplication().getUserId());
} else if(Boolean.TRUE.equals(validator.checkIsBeneficiary()) || Boolean.TRUE.equals(validator.checkIsConfidi())) {
communicationEntity.setIntiatorType(CommunicationInitiatorTypeEnum.BENEFICIARY.getValue());
communicationEntity.setSenderUserId(amendmentRequest.getApplicationEvaluationEntity().getAssignedApplicationsEntity().getApplication().getUserId());
communicationEntity.setReceiverUserId(amendmentRequest.getApplicationEvaluationEntity().getUserId());
}
communicationEntity = communicationRepository.save(communicationEntity);
communicationDocumentBean=documentDao.uploadFiles(communicationEntity.getSenderUserId(),files,communicationEntity.getId(), DocumentSourceTypeEnum.COMMUNICATION, DocumentTypeEnum.DOCUMENT);
List<Long> communicationDocumentIds = communicationDocumentBean.stream()
.map(DocumentResponseBean::getId)
.collect(Collectors.toList());
String communicationDocumentId = communicationDocumentIds.stream()
.map(String::valueOf)
.collect(Collectors.joining(","));
communicationEntity.setDocuments(communicationDocumentId);
communicationEntity = communicationRepository.save(communicationEntity);
return communicationEntity;
}
}