From 13fa7807e9c8829c7b7160abd93a38f3f920ca8d Mon Sep 17 00:00:00 2001 From: rajesh Date: Thu, 21 Nov 2024 17:36:41 +0530 Subject: [PATCH] Added column to communication table --- .../dao/CommunicationDao.java | 19 ++++++- .../entities/CommunicationEntity.java | 6 +++ .../response/CommunicationResponseBean.java | 4 ++ .../service/CommunicationService.java | 9 ++-- .../impl/CommunicationServiceImpl.java | 51 +++++++++++++++---- .../web/rest/api/CommunicationApi.java | 5 +- .../api/impl/CommunicationController.java | 10 ++-- .../db/changelog/db.changelog-1.0.0.xml | 41 ++++++++++----- 8 files changed, 110 insertions(+), 35 deletions(-) diff --git a/src/main/java/net/gepafin/tendermanagement/dao/CommunicationDao.java b/src/main/java/net/gepafin/tendermanagement/dao/CommunicationDao.java index afe7e21e..75926512 100644 --- a/src/main/java/net/gepafin/tendermanagement/dao/CommunicationDao.java +++ b/src/main/java/net/gepafin/tendermanagement/dao/CommunicationDao.java @@ -1,5 +1,6 @@ package net.gepafin.tendermanagement.dao; +import jakarta.servlet.http.HttpServletRequest; import net.gepafin.tendermanagement.config.Translator; import net.gepafin.tendermanagement.constants.GepafinConstant; import net.gepafin.tendermanagement.entities.ApplicationAmendmentRequestEntity; @@ -9,6 +10,7 @@ import net.gepafin.tendermanagement.model.response.ApplicationAmendmentResponse; import net.gepafin.tendermanagement.model.response.CommunicationResponseBean; import net.gepafin.tendermanagement.repositories.CommunicationRepository; import net.gepafin.tendermanagement.service.ApplicationAmendmentRequestService; +import net.gepafin.tendermanagement.util.Validator; import net.gepafin.tendermanagement.web.rest.api.errors.CustomValidationException; import net.gepafin.tendermanagement.web.rest.api.errors.Status; import org.slf4j.Logger; @@ -27,9 +29,12 @@ public class CommunicationDao { private CommunicationRepository communicationRepository; @Autowired - ApplicationAmendmentRequestService applicationAmendmentRequestService; + private ApplicationAmendmentRequestService applicationAmendmentRequestService; - public CommunicationResponseBean addCommentToAmendmentRequest(CommunicationRequestBean communicationReq, Long amendmentId) { + @Autowired + private Validator validator; + + public CommunicationResponseBean addCommentToAmendmentRequest(HttpServletRequest request, CommunicationRequestBean communicationReq, Long amendmentId) { log.info("Adding communication request..."); CommunicationEntity communicationEntity = convertToCommunicationCommentEntity(communicationReq, amendmentId); @@ -85,18 +90,28 @@ public class CommunicationDao { response.setCreatedDate(entity.getCreatedDate()); response.setUpdatedDate(entity.getUpdatedDate()); response.setTitle(entity.getCommunicationTitle()); + response.setSenderUserId(entity.getSenderUserId()); + response.setReceiverUserId(entity.getReceiverUserId()); return response; } private CommunicationEntity convertToCommunicationCommentEntity(CommunicationRequestBean communicationReq, Long amendmentId) { ApplicationAmendmentRequestEntity amendmentRequest = applicationAmendmentRequestService.validateApplicationAmendmentRequest(amendmentId); + CommunicationEntity communicationEntity = new CommunicationEntity(); communicationEntity.setApplicationAmendmentRequest(amendmentRequest); communicationEntity.setCommunicationTitle(communicationReq.getTitle()); communicationEntity.setCommunicationComment(communicationReq.getComment()); communicationEntity.setIsDeleted(false); communicationEntity.setCommentedDate(LocalDateTime.now()); + if(validator.checkIsPreInstructor()){ + communicationEntity.setSenderUserId(amendmentRequest.getApplicationEvaluationEntity().getUserId()); + communicationEntity.setReceiverUserId(amendmentRequest.getApplicationEvaluationEntity().getAssignedApplicationsEntity().getApplication().getUserId()); + } else if(validator.checkIsBeneficiary()) { + communicationEntity.setSenderUserId(amendmentRequest.getApplicationEvaluationEntity().getAssignedApplicationsEntity().getApplication().getUserId()); + communicationEntity.setReceiverUserId(amendmentRequest.getApplicationEvaluationEntity().getUserId()); + } return communicationEntity; } } diff --git a/src/main/java/net/gepafin/tendermanagement/entities/CommunicationEntity.java b/src/main/java/net/gepafin/tendermanagement/entities/CommunicationEntity.java index 7aa43acd..9029649e 100644 --- a/src/main/java/net/gepafin/tendermanagement/entities/CommunicationEntity.java +++ b/src/main/java/net/gepafin/tendermanagement/entities/CommunicationEntity.java @@ -26,6 +26,12 @@ public class CommunicationEntity extends BaseEntity { @Column(name = "COMMENTED_DATE") private LocalDateTime commentedDate; + @Column(name = "SENDER_USER_ID") + private Long senderUserId; + + @Column(name = "RECEIVER_USER_ID") + private Long receiverUserId; + @ManyToOne @JoinColumn(name = "AMENDMENT_ID", referencedColumnName = "id", nullable = false) private ApplicationAmendmentRequestEntity applicationAmendmentRequest; diff --git a/src/main/java/net/gepafin/tendermanagement/model/response/CommunicationResponseBean.java b/src/main/java/net/gepafin/tendermanagement/model/response/CommunicationResponseBean.java index d1405dd8..13afde4b 100644 --- a/src/main/java/net/gepafin/tendermanagement/model/response/CommunicationResponseBean.java +++ b/src/main/java/net/gepafin/tendermanagement/model/response/CommunicationResponseBean.java @@ -16,6 +16,10 @@ public class CommunicationResponseBean { private LocalDateTime updatedDate; + private Long senderUserId; + + private Long receiverUserId; + private Long amendmentId; public CommunicationResponseBean(LocalDateTime commentedDate, String comment, String title, LocalDateTime createdDate, LocalDateTime updatedDate, Long amendmentId) { diff --git a/src/main/java/net/gepafin/tendermanagement/service/CommunicationService.java b/src/main/java/net/gepafin/tendermanagement/service/CommunicationService.java index 5f8f1cd3..6c99f4a9 100644 --- a/src/main/java/net/gepafin/tendermanagement/service/CommunicationService.java +++ b/src/main/java/net/gepafin/tendermanagement/service/CommunicationService.java @@ -1,15 +1,16 @@ package net.gepafin.tendermanagement.service; +import jakarta.servlet.http.HttpServletRequest; import net.gepafin.tendermanagement.model.request.CommunicationRequestBean; import net.gepafin.tendermanagement.model.response.ApplicationAmendmentResponse; import net.gepafin.tendermanagement.model.response.CommunicationResponseBean; public interface CommunicationService { - CommunicationResponseBean addCommentToAmendmentRequest(CommunicationRequestBean communicationRequestBean, Long amendmentId); + CommunicationResponseBean addCommentToAmendmentRequest(HttpServletRequest request ,CommunicationRequestBean communicationRequestBean, Long amendmentId); - String deleteComment(Long amendmentId, Long commentId); + String deleteComment(HttpServletRequest request,Long amendmentId, Long commentId); - CommunicationResponseBean updateAmendmentComment(CommunicationRequestBean communicationRequestBean, Long amendmentId, Long commentId); + CommunicationResponseBean updateAmendmentComment(HttpServletRequest request,CommunicationRequestBean communicationRequestBean, Long amendmentId, Long commentId); - ApplicationAmendmentResponse getAmendmentComments(Long id); + ApplicationAmendmentResponse getAmendmentComments(HttpServletRequest request,Long id); } diff --git a/src/main/java/net/gepafin/tendermanagement/service/impl/CommunicationServiceImpl.java b/src/main/java/net/gepafin/tendermanagement/service/impl/CommunicationServiceImpl.java index 5a9b9c06..de3e5030 100644 --- a/src/main/java/net/gepafin/tendermanagement/service/impl/CommunicationServiceImpl.java +++ b/src/main/java/net/gepafin/tendermanagement/service/impl/CommunicationServiceImpl.java @@ -1,43 +1,76 @@ package net.gepafin.tendermanagement.service.impl; +import jakarta.servlet.http.HttpServletRequest; +import net.gepafin.tendermanagement.dao.ApplicationAmendmentRequestDao; import net.gepafin.tendermanagement.dao.CommunicationDao; +import net.gepafin.tendermanagement.entities.ApplicationAmendmentRequestEntity; import net.gepafin.tendermanagement.model.request.CommunicationRequestBean; import net.gepafin.tendermanagement.model.response.ApplicationAmendmentResponse; import net.gepafin.tendermanagement.model.response.CommunicationResponseBean; import net.gepafin.tendermanagement.service.CommunicationService; +import net.gepafin.tendermanagement.util.Validator; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; + @Service public class CommunicationServiceImpl implements CommunicationService { @Autowired CommunicationDao communicationDao; + @Autowired + ApplicationAmendmentRequestDao applicationAmendmentRequestDao; + + @Autowired + Validator validator; + @Override @Transactional(rollbackFor = Exception.class) - public CommunicationResponseBean addCommentToAmendmentRequest(CommunicationRequestBean communicationRequestBean, Long amendmentId) { - - return communicationDao.addCommentToAmendmentRequest(communicationRequestBean, amendmentId); + public CommunicationResponseBean addCommentToAmendmentRequest(HttpServletRequest request ,CommunicationRequestBean communicationRequestBean, Long amendmentId) { + ApplicationAmendmentRequestEntity applicationAmendmentRequestEntity = applicationAmendmentRequestDao.validateApplicationAmendmentRequest(amendmentId); + if (Boolean.FALSE.equals(validator.checkIsBeneficiary())) { + validator.validatePreInstructor(request, applicationAmendmentRequestEntity.getApplicationEvaluationEntity().getUserId()); + } else { + validator.validateUserId(request, applicationAmendmentRequestEntity.getApplicationEvaluationEntity().getAssignedApplicationsEntity().getApplication().getUserId()); + } + return communicationDao.addCommentToAmendmentRequest(request,communicationRequestBean, amendmentId); } + @Override @Transactional(rollbackFor = Exception.class) - public String deleteComment(Long amendmentId, Long commentId) { - + public String deleteComment(HttpServletRequest request ,Long amendmentId, Long commentId) { + ApplicationAmendmentRequestEntity applicationAmendmentRequestEntity = applicationAmendmentRequestDao.validateApplicationAmendmentRequest(amendmentId); + if (Boolean.FALSE.equals(validator.checkIsBeneficiary())) { + validator.validatePreInstructor(request, applicationAmendmentRequestEntity.getApplicationEvaluationEntity().getUserId()); + } else { + validator.validateUserId(request, applicationAmendmentRequestEntity.getApplicationEvaluationEntity().getAssignedApplicationsEntity().getApplication().getUserId()); + } return communicationDao.deleteComment(amendmentId, commentId); } @Override @Transactional(rollbackFor = Exception.class) - public CommunicationResponseBean updateAmendmentComment(CommunicationRequestBean communicationRequestBean, Long amendmentId, Long commentId) { - + public CommunicationResponseBean updateAmendmentComment(HttpServletRequest request,CommunicationRequestBean communicationRequestBean, Long amendmentId, Long commentId) { + ApplicationAmendmentRequestEntity applicationAmendmentRequestEntity = applicationAmendmentRequestDao.validateApplicationAmendmentRequest(amendmentId); + if (Boolean.FALSE.equals(validator.checkIsBeneficiary())) { + validator.validatePreInstructor(request, applicationAmendmentRequestEntity.getApplicationEvaluationEntity().getUserId()); + } else { + validator.validateUserId(request, applicationAmendmentRequestEntity.getApplicationEvaluationEntity().getAssignedApplicationsEntity().getApplication().getUserId()); + } return communicationDao.updateAmendmentComment(communicationRequestBean, amendmentId, commentId); } + @Override @Transactional(readOnly = true) - public ApplicationAmendmentResponse getAmendmentComments(Long id) { - + public ApplicationAmendmentResponse getAmendmentComments(HttpServletRequest request,Long id) { + ApplicationAmendmentRequestEntity applicationAmendmentRequestEntity = applicationAmendmentRequestDao.validateApplicationAmendmentRequest(id); + if (Boolean.FALSE.equals(validator.checkIsBeneficiary())) { + validator.validatePreInstructor(request, applicationAmendmentRequestEntity.getApplicationEvaluationEntity().getUserId()); + } else { + validator.validateUserId(request, applicationAmendmentRequestEntity.getApplicationEvaluationEntity().getAssignedApplicationsEntity().getApplication().getUserId()); + } return communicationDao.getAmendmentComments(id); } } diff --git a/src/main/java/net/gepafin/tendermanagement/web/rest/api/CommunicationApi.java b/src/main/java/net/gepafin/tendermanagement/web/rest/api/CommunicationApi.java index eb1351c9..a648b08b 100644 --- a/src/main/java/net/gepafin/tendermanagement/web/rest/api/CommunicationApi.java +++ b/src/main/java/net/gepafin/tendermanagement/web/rest/api/CommunicationApi.java @@ -14,6 +14,7 @@ import net.gepafin.tendermanagement.web.rest.api.errors.ErrorConstants; import org.springframework.data.repository.query.Param; import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; +import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.DeleteMapping; import org.springframework.web.bind.annotation.GetMapping; @@ -32,6 +33,7 @@ public interface CommunicationApi { @ApiResponse(responseCode = "400", description = "Bad Request", content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, examples = { @ExampleObject(value = ErrorConstants.BADREQUEST_ERROR_EXAMPLE) })) }) @PostMapping(value = "/{amendmentId}", produces = { "application/json" }) + @PreAuthorize("hasRole('ROLE_PRE_INSTRUCTOR') || hasRole('ROLE_BENEFICIARY')") ResponseEntity> addCommentToAmendmentRequest(HttpServletRequest request, @RequestBody @Parameter CommunicationRequestBean communicationResponseBean, @PathVariable(value = "amendmentId") Long amendmentId); @@ -43,7 +45,7 @@ public interface CommunicationApi { @ApiResponse(responseCode = "400", description = "Bad Request", content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, examples = @ExampleObject(value = ErrorConstants.BADREQUEST_ERROR_EXAMPLE))) }) @GetMapping(value = "/{amendmentId}", produces = "application/json") - public ResponseEntity> getAmendmentComments(@PathVariable(value = "amendmentId") Long amendmentId); + public ResponseEntity> getAmendmentComments(HttpServletRequest request,@PathVariable(value = "amendmentId") Long amendmentId); @Operation(summary = "Api to update communication comments", responses = { @ApiResponse(responseCode = "200", description = "OK"), @ApiResponse(responseCode = "404", description = "Not Found", content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, examples = { @@ -53,6 +55,7 @@ public interface CommunicationApi { @ApiResponse(responseCode = "400", description = "Bad Request", content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, examples = { @ExampleObject(value = ErrorConstants.BADREQUEST_ERROR_EXAMPLE) })) }) @PutMapping(value = "/{amendmentId}/{commentId}", produces = { "application/json" }) + @PreAuthorize("hasRole('ROLE_PRE_INSTRUCTOR') || hasRole('ROLE_BENEFICIARY')") ResponseEntity> updateCommunicationAmendment(HttpServletRequest request, @RequestBody @Parameter CommunicationRequestBean communicationResponseBean, @PathVariable(value = "amendmentId") Long amendmentId, @PathVariable(value = "commentId") Long commentId); diff --git a/src/main/java/net/gepafin/tendermanagement/web/rest/api/impl/CommunicationController.java b/src/main/java/net/gepafin/tendermanagement/web/rest/api/impl/CommunicationController.java index 4805d2ce..92aa71cf 100644 --- a/src/main/java/net/gepafin/tendermanagement/web/rest/api/impl/CommunicationController.java +++ b/src/main/java/net/gepafin/tendermanagement/web/rest/api/impl/CommunicationController.java @@ -27,28 +27,28 @@ public class CommunicationController implements CommunicationApi { public ResponseEntity> addCommentToAmendmentRequest(HttpServletRequest request, CommunicationRequestBean communicationRequestBean, Long amendmentId) { - CommunicationResponseBean communicationResponseBean = communicationService.addCommentToAmendmentRequest(communicationRequestBean, amendmentId); + CommunicationResponseBean communicationResponseBean = communicationService.addCommentToAmendmentRequest(request,communicationRequestBean, amendmentId); return ResponseEntity.status(HttpStatus.CREATED) .body(new Response<>(communicationResponseBean, Status.SUCCESS, Translator.toLocale(GepafinConstant.COMMUNICATION_ADDED_TO_AMENDMENT_REQUEST_SUCCESS))); } @Override - public ResponseEntity> getAmendmentComments(Long amendmentId) { + public ResponseEntity> getAmendmentComments(HttpServletRequest request,Long amendmentId) { - ApplicationAmendmentResponse response = communicationService.getAmendmentComments(amendmentId); + ApplicationAmendmentResponse response = communicationService.getAmendmentComments(request,amendmentId); return ResponseEntity.ok(new Response<>(response, Status.SUCCESS, Translator.toLocale(GepafinConstant.AMENDMENT_FOUND_SUCCESS))); } @Override public ResponseEntity> updateCommunicationAmendment(HttpServletRequest request, CommunicationRequestBean communicationRequestBean, Long amendmentId, Long commentId) { - CommunicationResponseBean communicationResponseBean = communicationService.updateAmendmentComment(communicationRequestBean, amendmentId, commentId); + CommunicationResponseBean communicationResponseBean = communicationService.updateAmendmentComment(request,communicationRequestBean, amendmentId, commentId); return ResponseEntity.status(HttpStatus.OK) .body(new Response<>(communicationResponseBean, Status.SUCCESS, Translator.toLocale(GepafinConstant.COMMENT_UPDATED_SUCCESS_MSG))); } @Override public ResponseEntity> deleteApplicationAmendmentComment(HttpServletRequest request, Long applicationAmendId, Long commentId) { - String communicationResponseBean = communicationService.deleteComment(applicationAmendId, commentId); + String communicationResponseBean = communicationService.deleteComment(request,applicationAmendId, commentId); return ResponseEntity.status(HttpStatus.OK) .body(new Response<>(communicationResponseBean, Status.SUCCESS, Translator.toLocale(GepafinConstant.COMMENT_DELETED_SUCCESS_MSG))); } diff --git a/src/main/resources/db/changelog/db.changelog-1.0.0.xml b/src/main/resources/db/changelog/db.changelog-1.0.0.xml index a7fe774d..05f8d108 100644 --- a/src/main/resources/db/changelog/db.changelog-1.0.0.xml +++ b/src/main/resources/db/changelog/db.changelog-1.0.0.xml @@ -1345,7 +1345,7 @@ referencedColumnNames="id"/> - + - + @@ -1693,15 +1693,15 @@ - - - UNIQUE_UUID = 'p4lk3bcx1RStqTaIVVbXs' - - - - UNIQUE_UUID = 't7jh5wfg9QXylNaTZkPoE' - - + + + UNIQUE_UUID = 'p4lk3bcx1RStqTaIVVbXs' + + + + UNIQUE_UUID = 't7jh5wfg9QXylNaTZkPoE' + + select setval('gepafin_schema.system_email_template_id_seq', (select @@ -1763,7 +1763,7 @@ - + @@ -1771,11 +1771,11 @@ - + - + @@ -1785,4 +1785,17 @@ + + + + + + + + + + + role_type = 'ROLE_PRE_INSTRUCTOR' + +