Merge pull request #102 from Kitzanos/feature/GEPAFINBE-117

GEPAFINBE-117(Added column to communication table)
This commit is contained in:
rbonazzo-KZ
2024-11-21 14:13:33 +01:00
committed by GitHub
8 changed files with 110 additions and 35 deletions

View File

@@ -1,5 +1,6 @@
package net.gepafin.tendermanagement.dao; package net.gepafin.tendermanagement.dao;
import jakarta.servlet.http.HttpServletRequest;
import net.gepafin.tendermanagement.config.Translator; import net.gepafin.tendermanagement.config.Translator;
import net.gepafin.tendermanagement.constants.GepafinConstant; import net.gepafin.tendermanagement.constants.GepafinConstant;
import net.gepafin.tendermanagement.entities.ApplicationAmendmentRequestEntity; 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.model.response.CommunicationResponseBean;
import net.gepafin.tendermanagement.repositories.CommunicationRepository; import net.gepafin.tendermanagement.repositories.CommunicationRepository;
import net.gepafin.tendermanagement.service.ApplicationAmendmentRequestService; 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.CustomValidationException;
import net.gepafin.tendermanagement.web.rest.api.errors.Status; import net.gepafin.tendermanagement.web.rest.api.errors.Status;
import org.slf4j.Logger; import org.slf4j.Logger;
@@ -27,9 +29,12 @@ public class CommunicationDao {
private CommunicationRepository communicationRepository; private CommunicationRepository communicationRepository;
@Autowired @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..."); log.info("Adding communication request...");
CommunicationEntity communicationEntity = convertToCommunicationCommentEntity(communicationReq, amendmentId); CommunicationEntity communicationEntity = convertToCommunicationCommentEntity(communicationReq, amendmentId);
@@ -85,18 +90,28 @@ public class CommunicationDao {
response.setCreatedDate(entity.getCreatedDate()); response.setCreatedDate(entity.getCreatedDate());
response.setUpdatedDate(entity.getUpdatedDate()); response.setUpdatedDate(entity.getUpdatedDate());
response.setTitle(entity.getCommunicationTitle()); response.setTitle(entity.getCommunicationTitle());
response.setSenderUserId(entity.getSenderUserId());
response.setReceiverUserId(entity.getReceiverUserId());
return response; return response;
} }
private CommunicationEntity convertToCommunicationCommentEntity(CommunicationRequestBean communicationReq, Long amendmentId) { private CommunicationEntity convertToCommunicationCommentEntity(CommunicationRequestBean communicationReq, Long amendmentId) {
ApplicationAmendmentRequestEntity amendmentRequest = applicationAmendmentRequestService.validateApplicationAmendmentRequest(amendmentId); ApplicationAmendmentRequestEntity amendmentRequest = applicationAmendmentRequestService.validateApplicationAmendmentRequest(amendmentId);
CommunicationEntity communicationEntity = new CommunicationEntity(); CommunicationEntity communicationEntity = new CommunicationEntity();
communicationEntity.setApplicationAmendmentRequest(amendmentRequest); communicationEntity.setApplicationAmendmentRequest(amendmentRequest);
communicationEntity.setCommunicationTitle(communicationReq.getTitle()); communicationEntity.setCommunicationTitle(communicationReq.getTitle());
communicationEntity.setCommunicationComment(communicationReq.getComment()); communicationEntity.setCommunicationComment(communicationReq.getComment());
communicationEntity.setIsDeleted(false); communicationEntity.setIsDeleted(false);
communicationEntity.setCommentedDate(LocalDateTime.now()); 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; return communicationEntity;
} }
} }

View File

@@ -26,6 +26,12 @@ public class CommunicationEntity extends BaseEntity {
@Column(name = "COMMENTED_DATE") @Column(name = "COMMENTED_DATE")
private LocalDateTime commentedDate; private LocalDateTime commentedDate;
@Column(name = "SENDER_USER_ID")
private Long senderUserId;
@Column(name = "RECEIVER_USER_ID")
private Long receiverUserId;
@ManyToOne @ManyToOne
@JoinColumn(name = "AMENDMENT_ID", referencedColumnName = "id", nullable = false) @JoinColumn(name = "AMENDMENT_ID", referencedColumnName = "id", nullable = false)
private ApplicationAmendmentRequestEntity applicationAmendmentRequest; private ApplicationAmendmentRequestEntity applicationAmendmentRequest;

View File

@@ -16,6 +16,10 @@ public class CommunicationResponseBean {
private LocalDateTime updatedDate; private LocalDateTime updatedDate;
private Long senderUserId;
private Long receiverUserId;
private Long amendmentId; private Long amendmentId;
public CommunicationResponseBean(LocalDateTime commentedDate, String comment, String title, LocalDateTime createdDate, LocalDateTime updatedDate, Long amendmentId) { public CommunicationResponseBean(LocalDateTime commentedDate, String comment, String title, LocalDateTime createdDate, LocalDateTime updatedDate, Long amendmentId) {

View File

@@ -1,15 +1,16 @@
package net.gepafin.tendermanagement.service; package net.gepafin.tendermanagement.service;
import jakarta.servlet.http.HttpServletRequest;
import net.gepafin.tendermanagement.model.request.CommunicationRequestBean; import net.gepafin.tendermanagement.model.request.CommunicationRequestBean;
import net.gepafin.tendermanagement.model.response.ApplicationAmendmentResponse; import net.gepafin.tendermanagement.model.response.ApplicationAmendmentResponse;
import net.gepafin.tendermanagement.model.response.CommunicationResponseBean; import net.gepafin.tendermanagement.model.response.CommunicationResponseBean;
public interface CommunicationService { 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);
} }

View File

@@ -1,43 +1,76 @@
package net.gepafin.tendermanagement.service.impl; 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.dao.CommunicationDao;
import net.gepafin.tendermanagement.entities.ApplicationAmendmentRequestEntity;
import net.gepafin.tendermanagement.model.request.CommunicationRequestBean; import net.gepafin.tendermanagement.model.request.CommunicationRequestBean;
import net.gepafin.tendermanagement.model.response.ApplicationAmendmentResponse; import net.gepafin.tendermanagement.model.response.ApplicationAmendmentResponse;
import net.gepafin.tendermanagement.model.response.CommunicationResponseBean; import net.gepafin.tendermanagement.model.response.CommunicationResponseBean;
import net.gepafin.tendermanagement.service.CommunicationService; import net.gepafin.tendermanagement.service.CommunicationService;
import net.gepafin.tendermanagement.util.Validator;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
@Service @Service
public class CommunicationServiceImpl implements CommunicationService { public class CommunicationServiceImpl implements CommunicationService {
@Autowired @Autowired
CommunicationDao communicationDao; CommunicationDao communicationDao;
@Autowired
ApplicationAmendmentRequestDao applicationAmendmentRequestDao;
@Autowired
Validator validator;
@Override @Override
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public CommunicationResponseBean addCommentToAmendmentRequest(CommunicationRequestBean communicationRequestBean, Long amendmentId) { public CommunicationResponseBean addCommentToAmendmentRequest(HttpServletRequest request ,CommunicationRequestBean communicationRequestBean, Long amendmentId) {
ApplicationAmendmentRequestEntity applicationAmendmentRequestEntity = applicationAmendmentRequestDao.validateApplicationAmendmentRequest(amendmentId);
return communicationDao.addCommentToAmendmentRequest(communicationRequestBean, 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 @Override
@Transactional(rollbackFor = Exception.class) @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); return communicationDao.deleteComment(amendmentId, commentId);
} }
@Override @Override
@Transactional(rollbackFor = Exception.class) @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); return communicationDao.updateAmendmentComment(communicationRequestBean, amendmentId, commentId);
} }
@Override @Override
@Transactional(readOnly = true) @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); return communicationDao.getAmendmentComments(id);
} }
} }

View File

@@ -14,6 +14,7 @@ import net.gepafin.tendermanagement.web.rest.api.errors.ErrorConstants;
import org.springframework.data.repository.query.Param; import org.springframework.data.repository.query.Param;
import org.springframework.http.MediaType; import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated; import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.DeleteMapping; import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping; 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 = { @ApiResponse(responseCode = "400", description = "Bad Request", content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, examples = {
@ExampleObject(value = ErrorConstants.BADREQUEST_ERROR_EXAMPLE) })) }) @ExampleObject(value = ErrorConstants.BADREQUEST_ERROR_EXAMPLE) })) })
@PostMapping(value = "/{amendmentId}", produces = { "application/json" }) @PostMapping(value = "/{amendmentId}", produces = { "application/json" })
@PreAuthorize("hasRole('ROLE_PRE_INSTRUCTOR') || hasRole('ROLE_BENEFICIARY')")
ResponseEntity<Response<CommunicationResponseBean>> addCommentToAmendmentRequest(HttpServletRequest request, ResponseEntity<Response<CommunicationResponseBean>> addCommentToAmendmentRequest(HttpServletRequest request,
@RequestBody @Parameter CommunicationRequestBean communicationResponseBean, @PathVariable(value = "amendmentId") Long amendmentId); @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 = @ApiResponse(responseCode = "400", description = "Bad Request", content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, examples = @ExampleObject(value =
ErrorConstants.BADREQUEST_ERROR_EXAMPLE))) }) ErrorConstants.BADREQUEST_ERROR_EXAMPLE))) })
@GetMapping(value = "/{amendmentId}", produces = "application/json") @GetMapping(value = "/{amendmentId}", produces = "application/json")
public ResponseEntity<Response<ApplicationAmendmentResponse>> getAmendmentComments(@PathVariable(value = "amendmentId") Long amendmentId); public ResponseEntity<Response<ApplicationAmendmentResponse>> getAmendmentComments(HttpServletRequest request,@PathVariable(value = "amendmentId") Long amendmentId);
@Operation(summary = "Api to update communication comments", responses = { @ApiResponse(responseCode = "200", description = "OK"), @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 = { @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 = { @ApiResponse(responseCode = "400", description = "Bad Request", content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, examples = {
@ExampleObject(value = ErrorConstants.BADREQUEST_ERROR_EXAMPLE) })) }) @ExampleObject(value = ErrorConstants.BADREQUEST_ERROR_EXAMPLE) })) })
@PutMapping(value = "/{amendmentId}/{commentId}", produces = { "application/json" }) @PutMapping(value = "/{amendmentId}/{commentId}", produces = { "application/json" })
@PreAuthorize("hasRole('ROLE_PRE_INSTRUCTOR') || hasRole('ROLE_BENEFICIARY')")
ResponseEntity<Response<CommunicationResponseBean>> updateCommunicationAmendment(HttpServletRequest request, ResponseEntity<Response<CommunicationResponseBean>> updateCommunicationAmendment(HttpServletRequest request,
@RequestBody @Parameter CommunicationRequestBean communicationResponseBean, @PathVariable(value = "amendmentId") Long amendmentId, @PathVariable(value = "commentId") Long commentId); @RequestBody @Parameter CommunicationRequestBean communicationResponseBean, @PathVariable(value = "amendmentId") Long amendmentId, @PathVariable(value = "commentId") Long commentId);

View File

@@ -27,28 +27,28 @@ public class CommunicationController implements CommunicationApi {
public ResponseEntity<Response<CommunicationResponseBean>> addCommentToAmendmentRequest(HttpServletRequest request, CommunicationRequestBean communicationRequestBean, public ResponseEntity<Response<CommunicationResponseBean>> addCommentToAmendmentRequest(HttpServletRequest request, CommunicationRequestBean communicationRequestBean,
Long amendmentId) { Long amendmentId) {
CommunicationResponseBean communicationResponseBean = communicationService.addCommentToAmendmentRequest(communicationRequestBean, amendmentId); CommunicationResponseBean communicationResponseBean = communicationService.addCommentToAmendmentRequest(request,communicationRequestBean, amendmentId);
return ResponseEntity.status(HttpStatus.CREATED) return ResponseEntity.status(HttpStatus.CREATED)
.body(new Response<>(communicationResponseBean, Status.SUCCESS, Translator.toLocale(GepafinConstant.COMMUNICATION_ADDED_TO_AMENDMENT_REQUEST_SUCCESS))); .body(new Response<>(communicationResponseBean, Status.SUCCESS, Translator.toLocale(GepafinConstant.COMMUNICATION_ADDED_TO_AMENDMENT_REQUEST_SUCCESS)));
} }
@Override @Override
public ResponseEntity<Response<ApplicationAmendmentResponse>> getAmendmentComments(Long amendmentId) { public ResponseEntity<Response<ApplicationAmendmentResponse>> 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))); return ResponseEntity.ok(new Response<>(response, Status.SUCCESS, Translator.toLocale(GepafinConstant.AMENDMENT_FOUND_SUCCESS)));
} }
@Override @Override
public ResponseEntity<Response<CommunicationResponseBean>> updateCommunicationAmendment(HttpServletRequest request, CommunicationRequestBean communicationRequestBean, public ResponseEntity<Response<CommunicationResponseBean>> updateCommunicationAmendment(HttpServletRequest request, CommunicationRequestBean communicationRequestBean,
Long amendmentId, Long commentId) { Long amendmentId, Long commentId) {
CommunicationResponseBean communicationResponseBean = communicationService.updateAmendmentComment(communicationRequestBean, amendmentId, commentId); CommunicationResponseBean communicationResponseBean = communicationService.updateAmendmentComment(request,communicationRequestBean, amendmentId, commentId);
return ResponseEntity.status(HttpStatus.OK) return ResponseEntity.status(HttpStatus.OK)
.body(new Response<>(communicationResponseBean, Status.SUCCESS, Translator.toLocale(GepafinConstant.COMMENT_UPDATED_SUCCESS_MSG))); .body(new Response<>(communicationResponseBean, Status.SUCCESS, Translator.toLocale(GepafinConstant.COMMENT_UPDATED_SUCCESS_MSG)));
} }
@Override @Override
public ResponseEntity<Response<String>> deleteApplicationAmendmentComment(HttpServletRequest request, Long applicationAmendId, Long commentId) { public ResponseEntity<Response<String>> 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) return ResponseEntity.status(HttpStatus.OK)
.body(new Response<>(communicationResponseBean, Status.SUCCESS, Translator.toLocale(GepafinConstant.COMMENT_DELETED_SUCCESS_MSG))); .body(new Response<>(communicationResponseBean, Status.SUCCESS, Translator.toLocale(GepafinConstant.COMMENT_DELETED_SUCCESS_MSG)));
} }

View File

@@ -1785,4 +1785,17 @@
</dropColumn> </dropColumn>
</changeSet> </changeSet>
<changeSet id="21-11-2024_1" author="Rajesh Khore">
<addColumn tableName="communication">
<column name="sender_user_id" type="INTEGER"></column>
<column name="receiver_user_id" type="INTEGER"></column>
</addColumn>
</changeSet>
<changeSet id="21-11-2024_2" author="Rajesh Khore">
<update tableName="role">
<column name="role_name" value='Instructor'/>
<where>role_type = 'ROLE_PRE_INSTRUCTOR'</where>
</update>
</changeSet>
</databaseChangeLog> </databaseChangeLog>