Created new endpoint to reject emails by director

This commit is contained in:
rajesh
2026-03-11 12:20:06 +05:30
parent e2c73db9f7
commit 5fe2291a3e
13 changed files with 64 additions and 1 deletions

View File

@@ -634,6 +634,7 @@ public class GepafinConstant {
public static final String APPLICATION_NOT_APPROVED="application.not.approved";
public static final String SUBJECT_AND_BODY_REQUIRED="subject.body.required";
public static final String MAIL_SENT_SUCCESSFULLY="mail.send.successfully";
public static final String PEC_EMAIL_REJECTED_SUCCESSFULLY="pec.email.rejected.successfully";
public static final String EMAIL_LOG_FETCHED="email.log.fetched";
public static final String APPLICATION_AMENDMENT_APPROPIATE_STATUS="amendment.appropiate.status";
public static final String UPLOAD_COMPANY_DOCUMENT_TO_APPLICATION_MSG="upload.company.document.to.application";

View File

@@ -15,6 +15,7 @@ import net.gepafin.tendermanagement.repositories.EmailLogRepository;
import net.gepafin.tendermanagement.repositories.UserActionsRepository;
import net.gepafin.tendermanagement.service.ApplicationService;
import net.gepafin.tendermanagement.service.CallService;
import net.gepafin.tendermanagement.util.DateTimeUtil;
import net.gepafin.tendermanagement.util.Utils;
import net.gepafin.tendermanagement.util.Validator;
import net.gepafin.tendermanagement.web.rest.api.errors.CustomValidationException;
@@ -24,6 +25,7 @@ import org.checkerframework.checker.units.qual.A;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;
@@ -74,6 +76,21 @@ public class PecMailDao {
return pecMailResponses;
}
public PecMailResponse rejectPecMail(HttpServletRequest request, Long userActionId, String motivation) {
List<EmailLogEntity> emailLogs = getEmailLogEntities(request, userActionId);
LocalDateTime rejectedAt = DateTimeUtil.DateServerToUTC(LocalDateTime.now());
for (EmailLogEntity log : emailLogs) {
log.setSendStatus(StatusTypeEnum.REJECTED.getValue());
log.setMotivation(motivation);
log.setSendDateTime(rejectedAt);
}
emailLogRepository.saveAll(emailLogs);
EmailLogEntity firstLog = emailLogs.get(0);
ApplicationEntity applicationEntity = applicationService.validateApplication(firstLog.getApplicationId());
String callName = applicationEntity.getCall().getName();
return createPecMailResponse(firstLog.getUserAction().getId(), firstLog, callName);
}
private List<EmailLogEntity> getEmailLogEntities(HttpServletRequest request, Long userActionId) {
UserActionEntity userActionEntity = userActionsRepository.findUserActionByIdAndIsDeletedFalse(userActionId);
if (userActionEntity == null) {
@@ -117,6 +134,7 @@ public class PecMailDao {
pecEmailLogResponse.setSubject(emailLogEntity.getEmailSubject());
pecEmailLogResponse.setHtmlContent(emailLogEntity.getEmailBody());
pecEmailLogResponse.setCallId(emailLogEntity.getCallId());
pecEmailLogResponse.setMotivation(emailLogEntity.getMotivation());
return pecEmailLogResponse;
}
private PecMailResponse createPecMailResponse(Long userActionId, EmailLogEntity emailLogEntity, String callName) {

View File

@@ -62,5 +62,8 @@ public class EmailLogEntity extends BaseEntity{
@Column(name = "ATTACHMENTS")
private String attachments;
@Column(name = "MOTIVATION", columnDefinition = "TEXT")
private String motivation;
}

View File

@@ -5,7 +5,8 @@ import com.fasterxml.jackson.annotation.JsonValue;
public enum StatusTypeEnum {
PENDING ("PENDING"),
SUCCESS ("SUCCESS"),
FAILED("FAILED");
FAILED("FAILED"),
REJECTED("REJECTED");
private String value;

View File

@@ -231,6 +231,7 @@ public enum UserActionContextEnum {
FETCH_APPLICATION_CONTRACT_BY_APPLICATION_ID("FETCH_APPLICATION_CONTRACT_BY_APPLICATION_ID"),
FETCH_APPLICATION_CONTRACT_BY_BENEFICIARY_USER_ID("FETCH_APPLICATION_CONTRACT_BY_BENEFICIARY_USER_ID"),
SEND_PEC_MAIL("SEND_PEC_MAIL"),
REJECT_PEC_MAIL("REJECT_PEC_MAIL"),
FETCH_EMAIL_LOG("FETCH_EMAIL_LOG"),
FETCH_ALL_EMAIL_LOG("FETCH_ALL_EMAIL_LOG"),
UPLOAD_COMPANY_DOCUMENT_TO_APPLICATION("UPLOAD_COMPANY_DOCUMENT_TO_APPLICATION");

View File

@@ -27,4 +27,6 @@ public class PecEmailLogResponse {
private Long callId;
private String motivation;
}

View File

@@ -10,6 +10,8 @@ public interface PecMailService {
public List<PecMailResponse> sendPecMail(HttpServletRequest request, List<Long> userActionIds);
public PecMailResponse rejectPecMail(HttpServletRequest request, Long userActionId, String motivation);
public List<PecEmailLogResponse> getEmailLogByUserActionId(HttpServletRequest request, Long userActionId);
public List<PecMailResponse> getAllEmailLogs(HttpServletRequest request);

View File

@@ -21,6 +21,11 @@ public class PecMailSerivceImpl implements PecMailService {
return pecMailDao.sendPecMail(request,userActionIds);
}
@Override
public PecMailResponse rejectPecMail(HttpServletRequest request, Long userActionId, String motivation) {
return pecMailDao.rejectPecMail(request, userActionId, motivation);
}
@Override
public List<PecEmailLogResponse> getEmailLogByUserActionId(HttpServletRequest request, Long userActionId) {
return pecMailDao.getEmailLogByUserActionId(request,userActionId);

View File

@@ -31,6 +31,17 @@ public interface PecMailApi {
ResponseEntity<Response< List<PecMailResponse>>> sendPecMail(HttpServletRequest request,
@Parameter(description = "The user action id", required = true) @RequestParam("userActionIds") List<Long> userActionIds);
@Operation(summary = "Api to reject PEC email for a user action with motivation.", responses = { @ApiResponse(responseCode = "200", description = "OK"),
@ApiResponse(responseCode = "404", description = "Not Found", content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, examples = @ExampleObject(value =
ErrorConstants.NOTFOUND_ERROR_EXAMPLE))),
@ApiResponse(responseCode = "401", description = "Unauthorized", content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, examples = @ExampleObject(value =
ErrorConstants.UNAUTHORIZED_ERROR_EXAMPLE))),
@ApiResponse(responseCode = "400", description = "Bad Request", content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, examples = @ExampleObject(value =
ErrorConstants.BADREQUEST_ERROR_EXAMPLE))) })
@PostMapping(value = "/userAction/{userActionId}/reject", produces = "application/json")
ResponseEntity<Response<PecMailResponse>> rejectPecMail(HttpServletRequest request,
@Parameter(description = "The user action id", required = true) @PathVariable("userActionId") Long userActionId,
@Parameter(description = "Motivation for rejection", required = true) @RequestParam("motivation") String motivation);
@Operation(summary = "Api to get email log by user action id", responses = { @ApiResponse(responseCode = "200", description = "OK"),
@ApiResponse(responseCode = "404", description = "Not Found", content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, examples = @ExampleObject(value =

View File

@@ -44,6 +44,17 @@ public class PecMailController implements PecMailApi {
}
@Override
public ResponseEntity<Response<PecMailResponse>> rejectPecMail(HttpServletRequest request, Long userActionId, String motivation) {
loggingUtil.logUserAction(UserActionRequest.builder().request(request).actionType(UserActionLogsEnum.EMAIL)
.actionContext(UserActionContextEnum.REJECT_PEC_MAIL).build());
PecMailResponse pecMailResponse = pecMailService.rejectPecMail(request, userActionId, motivation);
return ResponseEntity.status(HttpStatus.OK)
.body(new Response<>(pecMailResponse, Status.SUCCESS, Translator.toLocale(GepafinConstant.PEC_EMAIL_REJECTED_SUCCESSFULLY)));
}
@Override
public ResponseEntity<Response<List<PecEmailLogResponse>>> getEmailLogByUserActionId(HttpServletRequest request, Long userActionId) {
loggingUtil.logUserAction(UserActionRequest.builder().request(request).actionType(UserActionLogsEnum.EMAIL)

View File

@@ -3199,4 +3199,10 @@
</addColumn>
</changeSet>
<changeSet id="10-03-2026_RK_184231" author="Rajesh Khore">
<addColumn tableName="email_log">
<column name="motivation" type="TEXT"/>
</addColumn>
</changeSet>
</databaseChangeLog>

View File

@@ -426,6 +426,7 @@ application.contract.already.exist=Application contract already exist for this a
application.not.approved=Application is not approved.
subject.body.required=Subject and body is required to create contract.
mail.send.successfully=Mail sent succesfully.
pec.email.rejected.successfully=Email rejected successfully.
email.log.fetched=Email log fetched successfully.
amendment.appropiate.status=Application amendment is not in appropiate status for this operation.
upload.company.document.to.application=Uploaded company document to application successfully.

View File

@@ -417,6 +417,7 @@ application.contract.already.exist=Il contratto di applicazione esiste gi<67> per
application.not.approved=La domanda non � stata approvata.
subject.body.required=Per creare un contratto sono necessari oggetto e corpo.
mail.send.successfully=Email inviata con successo.
pec.email.rejected.successfully=Email rifiutata con successo.
email.log.fetched=Registro email recuperato correttamente.
amendment.appropiate.status=L'emendamento dell'applicazione non � in stato appropriato per questa operazione.
upload.company.document.to.application=Documento aziendale caricato correttamente nell'applicazione.