Merge pull request #108 from Kitzanos/develop
Sync master with develop branch(25/11/2024)
This commit is contained in:
7
pom.xml
7
pom.xml
@@ -29,6 +29,13 @@
|
||||
<artifactId>lombok</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- https://mvnrepository.com/artifact/com.mashape.unirest/unirest-java -->
|
||||
<dependency>
|
||||
<groupId>com.mashape.unirest</groupId>
|
||||
<artifactId>unirest-java</artifactId>
|
||||
<version>1.4.9</version>
|
||||
</dependency>
|
||||
|
||||
<!-- H2 Database for in-memory testing -->
|
||||
<dependency>
|
||||
<groupId>com.h2database</groupId>
|
||||
|
||||
@@ -292,5 +292,9 @@ public class GepafinConstant {
|
||||
public static final String ENCRYPT_KEY = "U2VjdXJlRW5jcnlwdEtleQ==";
|
||||
public static final String APPLICATION_DOCUMENTS_NOT_FOUND_MSG = "application.documents.not.found";
|
||||
public static final String DUPLICATE_BENEFICIARY_CALL = "beneficiary.call.duplicate";
|
||||
public static final String USER_MUST_BE_ASSOCIATED_WITH_COMPANY="user.must.be.associated.with.company.to.create.application";
|
||||
public static final String COMPANY_ID_REQUIRED_FOR_PREFERRED_CALL = "company.id.required.for.preferred.call";
|
||||
public static final String SUBMISSION_DATE = "submissionDate";
|
||||
public static final String ASSIGNED_AT = "assignedAt";
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package net.gepafin.tendermanagement.dao;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import jakarta.persistence.criteria.Join;
|
||||
@@ -11,10 +10,8 @@ import net.gepafin.tendermanagement.constants.GepafinConstant;
|
||||
import net.gepafin.tendermanagement.entities.*;
|
||||
import net.gepafin.tendermanagement.entities.SystemEmailTemplatesEntity.SystemEmailTemplatesEntityTypeEnum;
|
||||
import net.gepafin.tendermanagement.enums.*;
|
||||
import net.gepafin.tendermanagement.model.request.ApplicationAmendmentRequest;
|
||||
import net.gepafin.tendermanagement.model.request.ApplicationAmendmentRequestBean;
|
||||
import net.gepafin.tendermanagement.model.request.ApplicationFormFieldRequestBean;
|
||||
import net.gepafin.tendermanagement.model.request.CloseAmendmentRequest;
|
||||
import net.gepafin.tendermanagement.model.request.*;
|
||||
import net.gepafin.tendermanagement.model.request.AmendmentFormField.AmendmentIsUploadedByEnum;
|
||||
import net.gepafin.tendermanagement.model.response.*;
|
||||
import net.gepafin.tendermanagement.repositories.*;
|
||||
import net.gepafin.tendermanagement.service.*;
|
||||
@@ -24,6 +21,8 @@ import net.gepafin.tendermanagement.util.Validator;
|
||||
import net.gepafin.tendermanagement.web.rest.api.errors.CustomValidationException;
|
||||
import net.gepafin.tendermanagement.web.rest.api.errors.ResourceNotFoundException;
|
||||
import net.gepafin.tendermanagement.web.rest.api.errors.Status;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.data.jpa.domain.Specification;
|
||||
@@ -32,6 +31,7 @@ import org.springframework.stereotype.Component;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.temporal.ChronoUnit;
|
||||
import java.util.*;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static net.gepafin.tendermanagement.util.Utils.log;
|
||||
@@ -83,20 +83,15 @@ public class ApplicationAmendmentRequestDao {
|
||||
@Autowired
|
||||
private SystemEmailTemplatesService systemEmailTemplatesService;
|
||||
|
||||
@Autowired
|
||||
private CallDao callDao;
|
||||
|
||||
@Autowired
|
||||
private DocumentRepository documentRepository;
|
||||
|
||||
@Autowired
|
||||
private HubService hubService;
|
||||
// @Autowired
|
||||
// private MailUtil mailUtil;
|
||||
|
||||
@Autowired
|
||||
private Validator validator;
|
||||
|
||||
@Autowired
|
||||
private EmailLogDao emailLogDao;
|
||||
|
||||
public ApplicationAmendmentRequestResponse getApplicationDataForAmendment(Long applicationEvaluationId) {
|
||||
log.info("Fetching the application data for the Amendment process {}", applicationEvaluationId);
|
||||
ApplicationEvaluationEntity applicationEvaluationEntity = applicationEvaluationService.validateApplicationEvaluation(applicationEvaluationId);
|
||||
@@ -216,10 +211,10 @@ public class ApplicationAmendmentRequestDao {
|
||||
applicationAmendmentRequestEntity.setApplicationId(applicationId);
|
||||
|
||||
if (applicationAmendmentRequest.getFormFields() != null) {
|
||||
List<ApplicationFormFieldRequestBean> formFieldRequestBean = applicationAmendmentRequest.getFormFields().stream()
|
||||
List<AmendmentFormField> formFieldRequestBean = applicationAmendmentRequest.getFormFields().stream()
|
||||
.filter(AmendmentFormFieldResponse::isSelected)
|
||||
.map(amendmentFormFieldRequest -> {
|
||||
ApplicationFormFieldRequestBean formField = new ApplicationFormFieldRequestBean();
|
||||
AmendmentFormField formField = new AmendmentFormField();
|
||||
formField.setFieldId(amendmentFormFieldRequest.getFieldId());
|
||||
formField.setFieldValue(null);
|
||||
return formField;
|
||||
@@ -235,19 +230,23 @@ public class ApplicationAmendmentRequestDao {
|
||||
userEntity.getHub().getId());
|
||||
applicationAmendmentRequestEntity.setProtocol(protocolEntity);
|
||||
ApplicationAmendmentRequestEntity applicationAmendment = saveApplicationAmendmentRequestEntity(applicationAmendmentRequestEntity);
|
||||
|
||||
//Set Status
|
||||
String evaluationStatusType = applicationEvaluationEntity.getStatus();
|
||||
if (Boolean.FALSE.equals(evaluationStatusType.equals((ApplicationEvaluationStatusTypeEnum.SOCCORSO.getValue())))){
|
||||
applicationEvaluationEntity.setStatus(ApplicationEvaluationStatusTypeEnum.SOCCORSO.getValue());
|
||||
applicationEvaluationRepository.save(applicationEvaluationEntity);
|
||||
|
||||
}
|
||||
ApplicationEntity applicationEntity = applicationService.validateApplication(applicationId);
|
||||
String applicationStatusType = applicationEntity.getStatus();
|
||||
if (Boolean.FALSE.equals(applicationStatusType.equals((ApplicationStatusTypeEnum.SOCCORSO.getValue())))) {
|
||||
applicationEntity.setStatus(ApplicationStatusTypeEnum.SOCCORSO.getValue());
|
||||
applicationRepository.save(applicationEntity);
|
||||
|
||||
}
|
||||
AssignedApplicationsEntity assignedApplicationsEntity = assignedApplicationsService.validateAssignedApplication(assignedApplicationId);
|
||||
String assignedStatusType = assignedApplicationsEntity.getStatus();
|
||||
if (Boolean.FALSE.equals(assignedStatusType.equals((AssignedApplicationEnum.SOCCORSO.getValue())))) {
|
||||
assignedApplicationsEntity.setStatus(AssignedApplicationEnum.SOCCORSO.getValue());
|
||||
assignedApplicationsRepository.save(assignedApplicationsEntity);
|
||||
|
||||
}
|
||||
return applicationAmendment;
|
||||
}
|
||||
|
||||
@@ -257,130 +256,132 @@ public class ApplicationAmendmentRequestDao {
|
||||
}
|
||||
|
||||
public ApplicationAmendmentRequestResponse convertEntityToResponse(ApplicationAmendmentRequestEntity applicationAmendmentRequestEntity) {
|
||||
ApplicationAmendmentRequestResponse applicationAmendmentRequestResponse = new ApplicationAmendmentRequestResponse();
|
||||
applicationAmendmentRequestResponse.setId(applicationAmendmentRequestEntity.getId());
|
||||
Long applicationId = applicationAmendmentRequestEntity.getApplicationId();
|
||||
ApplicationAmendmentRequestResponse response = initializeBasicResponse(applicationAmendmentRequestEntity);
|
||||
|
||||
ApplicationEntity application = applicationService.validateApplication(applicationId);
|
||||
applicationAmendmentRequestResponse.setApplicationId(applicationId);
|
||||
applicationAmendmentRequestResponse.setCallEmail(application.getCall().getEmail());
|
||||
applicationAmendmentRequestResponse.setApplicationEvaluationId(applicationAmendmentRequestEntity.getApplicationEvaluationEntity().getId());
|
||||
applicationAmendmentRequestResponse.setNote(applicationAmendmentRequestEntity.getNote());
|
||||
applicationAmendmentRequestResponse.setStatus(ApplicationAmendmentRequestEnum.valueOf(applicationAmendmentRequestEntity.getStatus()));
|
||||
applicationAmendmentRequestResponse.setResponseDays(applicationAmendmentRequestEntity.getResponseDays());
|
||||
applicationAmendmentRequestResponse.setInternalNote(applicationAmendmentRequestEntity.getInternalNote());
|
||||
LocalDateTime startDate = applicationAmendmentRequestEntity.getStartDate();
|
||||
applicationAmendmentRequestResponse.setStartDate(startDate);
|
||||
List<ApplicationFormEntity> forms = applicationFormRepository.findByApplicationId(applicationAmendmentRequestEntity.getApplicationId());
|
||||
Map<String, String> fieldIdToLabelMap = extractFieldIdToLabelMap(forms);
|
||||
|
||||
LocalDateTime expirationDate = startDate.plus(expirationDays, ChronoUnit.DAYS);
|
||||
applicationAmendmentRequestResponse.setExpirationDate(expirationDate);
|
||||
List<AmendmentFormField> amendmentFormFields = Utils.convertJsonStringToList(
|
||||
applicationAmendmentRequestEntity.getFormFields(), AmendmentFormField.class);
|
||||
Map<String, ApplicationFormFieldEntity> formFieldEntityMap = getApplicationFormFieldEntityMap(applicationAmendmentRequestEntity, amendmentFormFields);
|
||||
|
||||
applicationAmendmentRequestResponse.setIsSendEmail(applicationAmendmentRequestEntity.getIsEmail());
|
||||
applicationAmendmentRequestResponse.setIsSendNotification(applicationAmendmentRequestEntity.getIsNotification());
|
||||
String callName = application.getCall().getName();
|
||||
Long protocolNumber = (applicationAmendmentRequestEntity.getProtocol() != null && applicationAmendmentRequestEntity.getProtocol().getProtocolNumber() != null)
|
||||
? applicationAmendmentRequestEntity.getProtocol().getProtocolNumber()
|
||||
: null;
|
||||
UserEntity userEntity = userService.validateUser(application.getUserId());
|
||||
String firstName = userEntity.getBeneficiary() != null ? userEntity.getBeneficiary().getFirstName() : "";
|
||||
String lastName = userEntity.getBeneficiary() != null ? userEntity.getBeneficiary().getLastName() : "";
|
||||
processFormFields(amendmentFormFields, fieldIdToLabelMap, formFieldEntityMap, response);
|
||||
|
||||
String beneficiaryName = (!firstName.isBlank() ? firstName : "") +
|
||||
(!lastName.isBlank() ? " " + lastName : "");
|
||||
|
||||
beneficiaryName = beneficiaryName.isBlank() ? "" : beneficiaryName;
|
||||
applicationAmendmentRequestResponse.setCallName(callName);
|
||||
applicationAmendmentRequestResponse.setProtocolNumber(protocolNumber);
|
||||
applicationAmendmentRequestResponse.setBeneficiaryName(beneficiaryName);
|
||||
|
||||
List<ApplicationFormEntity> forms = applicationFormRepository.findByApplicationId(applicationId);
|
||||
List<AmendmentFormFieldResponse> allFormFields = new ArrayList<>();
|
||||
|
||||
for (ApplicationFormEntity form : forms) {
|
||||
String content = form.getForm().getContent();
|
||||
List<Map<String, Object>> result = filterByName(content, "fileupload");
|
||||
allFormFields.addAll(getIdAndLabelFromResult(result));
|
||||
return response;
|
||||
}
|
||||
|
||||
Map<String, String> fieldIdToLabelMap = allFormFields.stream()
|
||||
private ApplicationAmendmentRequestResponse initializeBasicResponse(ApplicationAmendmentRequestEntity entity) {
|
||||
ApplicationAmendmentRequestResponse response = new ApplicationAmendmentRequestResponse();
|
||||
response.setId(entity.getId());
|
||||
response.setApplicationId(entity.getApplicationId());
|
||||
response.setApplicationEvaluationId(entity.getApplicationEvaluationEntity().getId());
|
||||
response.setNote(entity.getNote());
|
||||
response.setStatus(ApplicationAmendmentRequestEnum.valueOf(entity.getStatus()));
|
||||
response.setResponseDays(entity.getResponseDays());
|
||||
response.setInternalNote(entity.getInternalNote());
|
||||
|
||||
LocalDateTime startDate = entity.getStartDate();
|
||||
response.setStartDate(startDate);
|
||||
response.setExpirationDate(startDate.plus(expirationDays, ChronoUnit.DAYS));
|
||||
response.setIsSendEmail(entity.getIsEmail());
|
||||
response.setIsSendNotification(entity.getIsNotification());
|
||||
|
||||
ApplicationEntity application = applicationService.validateApplication(entity.getApplicationId());
|
||||
response.setCallEmail(application.getCall().getEmail());
|
||||
response.setCallName(application.getCall().getName());
|
||||
|
||||
UserEntity userEntity = userService.validateUser(application.getUserId());
|
||||
response.setBeneficiaryName(buildBeneficiaryName(userEntity));
|
||||
|
||||
Long protocolNumber = entity.getProtocol() != null ? entity.getProtocol().getProtocolNumber() : null;
|
||||
response.setProtocolNumber(protocolNumber);
|
||||
|
||||
return response;
|
||||
}
|
||||
|
||||
private Map<String, String> extractFieldIdToLabelMap(List<ApplicationFormEntity> forms) {
|
||||
return forms.stream()
|
||||
.flatMap(form -> {
|
||||
String content = form.getForm().getContent();
|
||||
return getIdAndLabelFromResult(filterByName(content, "fileupload")).stream();
|
||||
})
|
||||
.collect(Collectors.toMap(AmendmentFormFieldResponse::getFieldId, AmendmentFormFieldResponse::getLabel));
|
||||
}
|
||||
|
||||
String formFieldsJson = applicationAmendmentRequestEntity.getFormFields();
|
||||
List<AmendmentFormFieldResponse> formFields = Utils.convertJsonToList(
|
||||
formFieldsJson, new TypeReference<List<AmendmentFormFieldResponse>>() {
|
||||
});
|
||||
private Map<String, ApplicationFormFieldEntity> getApplicationFormFieldEntityMap(
|
||||
ApplicationAmendmentRequestEntity entity, List<AmendmentFormField> amendmentFormFields) {
|
||||
List<String> fieldIds = amendmentFormFields.stream()
|
||||
.map(AmendmentFormField::getFieldId)
|
||||
.toList();
|
||||
return getApplicationFormFieldList(entity, fieldIds).stream()
|
||||
.collect(Collectors.toMap(ApplicationFormFieldEntity::getFieldId, Function.identity()));
|
||||
}
|
||||
|
||||
for (AmendmentFormFieldResponse formField : formFields) {
|
||||
String label = fieldIdToLabelMap.get(formField.getFieldId());
|
||||
private void processFormFields(List<AmendmentFormField> amendmentFormFields, Map<String, String> fieldIdToLabelMap,
|
||||
Map<String, ApplicationFormFieldEntity> formFieldEntityMap, ApplicationAmendmentRequestResponse response) {
|
||||
List<AmendmentFormFieldResponse> formFields = new ArrayList<>();
|
||||
List<ApplicationFormFieldResponseBean> fileDetails = new ArrayList<>();
|
||||
|
||||
for (AmendmentFormField amendmentFormField : amendmentFormFields) {
|
||||
// Create form field response
|
||||
createFormField(formFields, fieldIdToLabelMap, amendmentFormField);
|
||||
|
||||
// Create document responses
|
||||
List<Long> documentIds = extractIds(amendmentFormField.getFieldValue());
|
||||
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());
|
||||
return responseBean;
|
||||
})
|
||||
.toList();
|
||||
|
||||
// Map to application form field response bean
|
||||
ApplicationFormFieldEntity formFieldEntity = formFieldEntityMap.get(amendmentFormField.getFieldId());
|
||||
ApplicationFormFieldResponseBean responseBean = new ApplicationFormFieldResponseBean();
|
||||
responseBean.setApplicationFormId(formFieldEntity.getApplicationForm().getId());
|
||||
responseBean.setId(formFieldEntity.getId());
|
||||
responseBean.setFieldId(amendmentFormField.getFieldId());
|
||||
responseBean.setCreatedDate(formFieldEntity.getCreatedDate());
|
||||
responseBean.setUpdatedDate(formFieldEntity.getUpdatedDate());
|
||||
responseBean.setFieldValue(documentResponseBeans);
|
||||
|
||||
fileDetails.add(responseBean);
|
||||
}
|
||||
|
||||
response.setFormFields(formFields);
|
||||
response.setApplicationFormFields(fileDetails);
|
||||
}
|
||||
|
||||
private String buildBeneficiaryName(UserEntity userEntity) {
|
||||
if (userEntity.getBeneficiary() == null) {
|
||||
return "";
|
||||
}
|
||||
String firstName = userEntity.getBeneficiary().getFirstName();
|
||||
String lastName = userEntity.getBeneficiary().getLastName();
|
||||
return (firstName != null ? firstName : "") +
|
||||
(lastName != null && !lastName.isBlank() ? " " + lastName : "");
|
||||
}
|
||||
|
||||
|
||||
private void createFormField(List<AmendmentFormFieldResponse> formFields, Map<String, String> fieldIdToLabelMap,
|
||||
AmendmentFormField amendmentFormField) {
|
||||
AmendmentFormFieldResponse formField = new AmendmentFormFieldResponse();
|
||||
String label = fieldIdToLabelMap.get(amendmentFormField.getFieldId());
|
||||
formField.setFieldId(amendmentFormField.getFieldId());
|
||||
formField.setLabel(label);
|
||||
formField.setSelected(true);
|
||||
}
|
||||
// Set the filtered formFields in the response
|
||||
applicationAmendmentRequestResponse.setFormFields(formFields);
|
||||
|
||||
String applicationFormFieldsJson = applicationAmendmentRequestEntity.getFormFields();
|
||||
List<ApplicationFormFieldResponseBean> applicationFormFields = Utils.convertJsonToList(
|
||||
formFieldsJson, new TypeReference<List<ApplicationFormFieldResponseBean>>() {
|
||||
});
|
||||
|
||||
List<ApplicationFormFieldResponseBean> fileDetailResponses = new ArrayList<>();
|
||||
for (ApplicationFormFieldResponseBean field : applicationFormFields) {
|
||||
ApplicationFormFieldResponseBean responseBean = new ApplicationFormFieldResponseBean();
|
||||
responseBean.setFieldId(field.getFieldId());
|
||||
|
||||
Optional<ApplicationFormFieldEntity> formFieldEntity = Optional.empty();
|
||||
for (ApplicationFormEntity form : forms) {
|
||||
formFieldEntity = applicationFormFieldRepository
|
||||
.findByApplicationFormIdAndFieldId(form.getId(), field.getFieldId());
|
||||
if (formFieldEntity.isPresent()) {
|
||||
// Set the applicationFormId from the matching form
|
||||
responseBean.setApplicationFormId(form.getId());
|
||||
responseBean.setId(formFieldEntity.get().getId());
|
||||
responseBean.setCreatedDate(formFieldEntity.get().getCreatedDate());
|
||||
responseBean.setUpdatedDate(formFieldEntity.get().getUpdatedDate());
|
||||
break;
|
||||
}
|
||||
formFields.add(formField);
|
||||
}
|
||||
|
||||
// Check if fieldValue is not null and is a String
|
||||
if (field.getFieldValue() instanceof String && field.getFieldValue() != null && !((String) field.getFieldValue()).isBlank()) {
|
||||
String fieldValueString = (String) field.getFieldValue();
|
||||
String[] documentIds = fieldValueString.split(",");
|
||||
List<DocumentResponseBean> documentResponseBeans = new ArrayList<>();
|
||||
|
||||
// Process each document ID
|
||||
for (String docId : documentIds) {
|
||||
try {
|
||||
Long documentId = Long.valueOf(docId.trim());
|
||||
documentRepository.findByIdAndNotDeleted(documentId).ifPresent(documentEntity -> {
|
||||
DocumentResponseBean docBean = new DocumentResponseBean();
|
||||
docBean.setId(documentEntity.getId());
|
||||
docBean.setName(documentEntity.getFileName());
|
||||
docBean.setType(DocumentTypeEnum.valueOf(documentEntity.getType()));
|
||||
docBean.setSource(DocumentSourceTypeEnum.valueOf(documentEntity.getSource()));
|
||||
docBean.setSourceId(documentEntity.getSourceId());
|
||||
docBean.setFilePath(documentEntity.getFilePath());
|
||||
docBean.setCreatedDate(documentEntity.getCreatedDate());
|
||||
docBean.setUpdatedDate(documentEntity.getUpdatedDate());
|
||||
documentResponseBeans.add(docBean);
|
||||
});
|
||||
} catch (NumberFormatException e) {
|
||||
// Handle the case where documentId is not a valid number
|
||||
// Log the error if necessary
|
||||
}
|
||||
}
|
||||
responseBean.setFieldValue(documentResponseBeans);
|
||||
} else {
|
||||
responseBean.setFieldValue(null);
|
||||
}
|
||||
|
||||
fileDetailResponses.add(responseBean);
|
||||
}
|
||||
|
||||
applicationAmendmentRequestResponse.setApplicationFormFields(fileDetailResponses);
|
||||
|
||||
return applicationAmendmentRequestResponse;
|
||||
}
|
||||
|
||||
public ApplicationAmendmentRequestEntity validateApplicationAmendmentRequest(Long id) {
|
||||
return applicationAmendmentRequestRepository.findByIdAndIsDeletedFalse(id)
|
||||
@@ -441,11 +442,21 @@ public class ApplicationAmendmentRequestDao {
|
||||
ApplicationAmendmentRequestEntity existingApplicationAmendment = validateApplicationAmendmentRequest(id);
|
||||
|
||||
setIfUpdated(existingApplicationAmendment::getNote, existingApplicationAmendment::setNote, updateRequest.getNote());
|
||||
|
||||
Map<String, AmendmentFormField> amendmentFormFieldMap = Utils
|
||||
.convertJsonStringToList(existingApplicationAmendment.getFormFields(), AmendmentFormField.class)
|
||||
.stream().collect(Collectors.toMap(AmendmentFormField::getFieldId, Function.identity()));
|
||||
Map<String, ApplicationFormFieldEntity> applicationFormFieldMap = getApplicationFormFieldList(existingApplicationAmendment, amendmentFormFieldMap.keySet().stream().toList()).stream().collect(Collectors.toMap(ApplicationFormFieldEntity::getFieldId, Function.identity()));
|
||||
|
||||
if(updateRequest.getApplicationFormFields() != null) {
|
||||
updateApplicationFormFields(existingApplicationAmendment, updateRequest.getApplicationFormFields());
|
||||
updateFormFieldsJson(existingApplicationAmendment, updateRequest.getApplicationFormFields());
|
||||
updateRequest.getApplicationFormFields().stream().forEach(applicationFormFieldRequest->{
|
||||
AmendmentFormField amendmentFormField = getAmendmentFormField(amendmentFormFieldMap,applicationFormFieldRequest.getFieldId());
|
||||
ApplicationFormFieldEntity applicationFormFieldEntity = getApplicationFormField(applicationFormFieldMap, applicationFormFieldRequest.getFieldId());
|
||||
updateApplicationFormField(applicationFormFieldEntity,applicationFormFieldRequest, amendmentFormField);
|
||||
updateFormField(applicationFormFieldRequest, amendmentFormField);
|
||||
});
|
||||
existingApplicationAmendment.setFormFields(Utils.convertListToJsonString(amendmentFormFieldMap.values().stream().toList()));
|
||||
}
|
||||
existingApplicationAmendment.setUpdatedDate(DateTimeUtil.DateServerToUTC(LocalDateTime.now()));
|
||||
|
||||
ApplicationAmendmentRequestEntity updatedApplicationAmendment = saveApplicationAmendmentRequestEntity(existingApplicationAmendment);
|
||||
ApplicationAmendmentRequestResponse response = convertEntityToResponse(updatedApplicationAmendment);
|
||||
@@ -453,185 +464,298 @@ public class ApplicationAmendmentRequestDao {
|
||||
return response;
|
||||
}
|
||||
|
||||
private void updateApplicationFormFields(ApplicationAmendmentRequestEntity applicationAmendment, ApplicationFormFieldRequestBean updatedFormField) {
|
||||
if (updatedFormField.getFieldValue() == null || "".equals(updatedFormField.getFieldValue().toString().trim())) {
|
||||
List<ApplicationFormEntity> applicationForms = applicationFormRepository.findByApplicationId(applicationAmendment.getApplicationId());
|
||||
private List<Long> updateApplicationFormField(ApplicationFormFieldEntity applicationFormFieldEntity,
|
||||
ApplicationFormFieldRequestBean applicationFormFieldRequest, AmendmentFormField amendmentFormField) {
|
||||
// Step 1: Extract IDs
|
||||
List<Long> applicationFormFieldIds = extractIds(applicationFormFieldEntity.getFieldValue());
|
||||
List<Long> amendmentFormFieldIds = extractIds(amendmentFormField.getFieldValue());
|
||||
List<Long> requestedIds = extractIds(applicationFormFieldRequest.getFieldValue());
|
||||
|
||||
boolean fieldUpdated = false;
|
||||
// Step 2: Optimize operations by finding differences
|
||||
// Remove only those IDs from currentIds that exist in presentIds but not in requestedIds
|
||||
List<Long> idsToRemove = amendmentFormFieldIds.stream()
|
||||
.filter(id -> !requestedIds.contains(id))
|
||||
.toList();
|
||||
applicationFormFieldIds.removeAll(idsToRemove);
|
||||
|
||||
for (ApplicationFormEntity applicationForm : applicationForms) {
|
||||
Optional<ApplicationFormFieldEntity> formFieldEntityOptional = applicationFormFieldRepository
|
||||
.findByApplicationFormIdAndFieldId(applicationForm.getId(), updatedFormField.getFieldId());
|
||||
// Add only those IDs to currentIds that exist in requestedIds but not in presentIds
|
||||
List<Long> idsToAdd = requestedIds.stream()
|
||||
.filter(id -> !amendmentFormFieldIds.contains(id))
|
||||
.toList();
|
||||
applicationFormFieldIds.addAll(idsToAdd);
|
||||
|
||||
if (formFieldEntityOptional.isPresent()) {
|
||||
ApplicationFormFieldEntity formEntity = formFieldEntityOptional.get();
|
||||
formEntity.setFieldValue(null); // Set field value to null
|
||||
applicationFormFieldRepository.save(formEntity);
|
||||
log.info("Set field value to null for application ID {} and field ID {}", applicationAmendment.getApplicationId(), updatedFormField.getFieldId());
|
||||
fieldUpdated = true;
|
||||
break;
|
||||
}
|
||||
// Step 3: Update the applicationFormFieldEntity fieldValue with requestedIds if it has changed
|
||||
if (!amendmentFormFieldIds.equals(requestedIds)) {
|
||||
String updatedFieldValue = applicationFormFieldIds.stream()
|
||||
.map(String::valueOf)
|
||||
.collect(Collectors.joining(","));
|
||||
applicationFormFieldEntity.setFieldValue(updatedFieldValue);
|
||||
applicationFormFieldRepository.save(applicationFormFieldEntity);
|
||||
}
|
||||
|
||||
if (!fieldUpdated) {
|
||||
throw new CustomValidationException(Status.NOT_FOUND, "No ApplicationFormField found for application ID " + applicationAmendment.getApplicationId() + " and field ID " + updatedFormField.getFieldId());
|
||||
// Step 4: Return the updated currentIds
|
||||
return applicationFormFieldIds;
|
||||
|
||||
}
|
||||
|
||||
|
||||
private ApplicationFormFieldEntity getApplicationFormField(
|
||||
Map<String, ApplicationFormFieldEntity> applicationFormFieldMap, String fieldId) {
|
||||
ApplicationFormFieldEntity applicationFormFieldEntity = applicationFormFieldMap.get(fieldId);
|
||||
if (applicationFormFieldEntity == null) {
|
||||
throw new CustomValidationException(Status.BAD_REQUEST, GepafinConstant.APPLICATION_FORM_FIELD_NOT_FOUND);
|
||||
}
|
||||
return applicationFormFieldEntity;
|
||||
}
|
||||
|
||||
|
||||
private List<ApplicationFormFieldEntity> getApplicationFormFieldList(
|
||||
ApplicationAmendmentRequestEntity applicationAmendment,
|
||||
List<String> fieldIds) {
|
||||
List<ApplicationFormEntity> applicationFormList = applicationFormRepository
|
||||
.findByApplicationId(applicationAmendment.getApplicationId());
|
||||
|
||||
return applicationFormList.stream().flatMap(applicationForm -> applicationFormFieldRepository
|
||||
.findByApplicationFormIdAndFieldIdIn(applicationForm.getId(), fieldIds).stream()).toList();
|
||||
}
|
||||
|
||||
|
||||
private AmendmentFormField getAmendmentFormField(Map<String, AmendmentFormField> amendmentFormFieldMap,
|
||||
String fieldId) {
|
||||
AmendmentFormField amendmentFormField = amendmentFormFieldMap.get(fieldId);
|
||||
if (amendmentFormField == null) {
|
||||
throw new CustomValidationException(Status.BAD_REQUEST, GepafinConstant.APPLICATION_FORM_FIELD_NOT_FOUND);
|
||||
}
|
||||
return amendmentFormField;
|
||||
}
|
||||
|
||||
|
||||
private void updateFormField(ApplicationFormFieldRequestBean applicationFormFieldRequest,
|
||||
AmendmentFormField amendmentFormField) {
|
||||
List<Long> requestedDocumentIds = extractIds(applicationFormFieldRequest.getFieldValue());
|
||||
List<Long> existingDocumentIds = extractIds(amendmentFormField.getFieldValue());
|
||||
|
||||
if (requestedDocumentIds.isEmpty()) {
|
||||
if (!existingDocumentIds.isEmpty()) {
|
||||
existingDocumentIds.forEach(this::softDeleteDocument);
|
||||
amendmentFormField.setFieldValue(null);
|
||||
setIsUploadedBy(amendmentFormField);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
List<String> documentIds;
|
||||
requestedDocumentIds.forEach(documentId -> documentService.validateDocument(documentId).getId());
|
||||
existingDocumentIds.stream().filter(documentId -> !requestedDocumentIds.contains(documentId))
|
||||
.forEach(this::softDeleteDocument);
|
||||
|
||||
if (updatedFormField.getFieldValue() instanceof String && updatedFormField.getFieldValue() != null) {
|
||||
documentIds = Arrays.asList(((String) updatedFormField.getFieldValue()).split(","));
|
||||
String newFieldValue = String.join(",",
|
||||
requestedDocumentIds.stream().map(String::valueOf).collect(Collectors.toList()));
|
||||
|
||||
if (!newFieldValue.equals(amendmentFormField.getFieldValue())) {
|
||||
amendmentFormField.setFieldValue(newFieldValue);
|
||||
setIsUploadedBy(amendmentFormField);
|
||||
}
|
||||
}
|
||||
|
||||
private List<Long> extractIds(Object fieldValue) {
|
||||
if (fieldValue instanceof String && !StringUtils.isEmpty((String) fieldValue)) {
|
||||
return Arrays.stream(((String) fieldValue).split(","))
|
||||
.map(Long::valueOf)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
|
||||
|
||||
private void setIsUploadedBy(AmendmentFormField amendmentFormField) {
|
||||
if(validator.checkIsBeneficiary()) {
|
||||
amendmentFormField.setIsUploadedBy(AmendmentIsUploadedByEnum.BENEFICIARY.getValue());
|
||||
}else {
|
||||
log.warn("Expected fieldValue as a comma-separated String but got: {}", updatedFormField.getFieldValue());
|
||||
return;
|
||||
amendmentFormField.setIsUploadedBy(AmendmentIsUploadedByEnum.PRE_INSTRUCTOR.getValue());
|
||||
}
|
||||
|
||||
List<String> validDocumentIds = new ArrayList<>();
|
||||
for (String documentId : documentIds) {
|
||||
try {
|
||||
DocumentEntity documentEntity = documentService.validateDocument(Long.parseLong(documentId.trim()));
|
||||
if (documentEntity != null) {
|
||||
validDocumentIds.add(documentId.trim());
|
||||
} else {
|
||||
log.warn("Document with ID {} does not exist. Skipping this ID.", documentId);
|
||||
}
|
||||
} catch (NumberFormatException e) {
|
||||
log.error("Invalid document ID format: {}. Error: {}", documentId, e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
if (!validDocumentIds.isEmpty()) {
|
||||
List<ApplicationFormEntity> applicationForms = applicationFormRepository.findByApplicationId(applicationAmendment.getApplicationId());
|
||||
|
||||
boolean fieldUpdated = false;
|
||||
|
||||
// Parse the formFields JSON string to get amendment field values
|
||||
String amendmentFieldValue = null;
|
||||
try {
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
List<ApplicationFormFieldRequestBean> amendmentFields = mapper.readValue(
|
||||
applicationAmendment.getFormFields(),
|
||||
mapper.getTypeFactory().constructCollectionType(List.class, ApplicationFormFieldRequestBean.class)
|
||||
);
|
||||
|
||||
// Find the matching field value and convert to string if found
|
||||
Optional<Object> amendmentFieldObj = amendmentFields.stream()
|
||||
.filter(field -> updatedFormField.getFieldId().equals(field.getFieldId()))
|
||||
.map(ApplicationFormFieldRequestBean::getFieldValue)
|
||||
.findFirst();
|
||||
|
||||
if (amendmentFieldObj.isPresent() && amendmentFieldObj.get() instanceof String) {
|
||||
amendmentFieldValue = (String) amendmentFieldObj.get();
|
||||
}
|
||||
|
||||
} catch (JsonProcessingException e) {
|
||||
log.error("Error parsing formFields JSON: {}", e.getMessage());
|
||||
return;
|
||||
}
|
||||
|
||||
if (amendmentFieldValue == null) {
|
||||
log.warn("No matching field found in amendment for field ID {}", updatedFormField.getFieldId());
|
||||
return;
|
||||
}
|
||||
|
||||
List<String> amendmentDocumentIds = Arrays.asList(amendmentFieldValue.split(","));
|
||||
|
||||
for (ApplicationFormEntity applicationForm : applicationForms) {
|
||||
Optional<ApplicationFormFieldEntity> formFieldEntityOptional = applicationFormFieldRepository
|
||||
.findByApplicationFormIdAndFieldId(applicationForm.getId(), updatedFormField.getFieldId());
|
||||
|
||||
if (formFieldEntityOptional.isPresent()) {
|
||||
ApplicationFormFieldEntity formEntity = formFieldEntityOptional.get();
|
||||
|
||||
// Retrieve existing document IDs in ApplicationFormFieldTable
|
||||
String existingFieldValue = formEntity.getFieldValue();
|
||||
Set<String> existingDocumentIds = existingFieldValue != null
|
||||
? new HashSet<>(Arrays.asList(existingFieldValue.split(",")))
|
||||
: new HashSet<>();
|
||||
|
||||
// Remove amendment documents from existing document IDs
|
||||
existingDocumentIds.removeAll(amendmentDocumentIds);
|
||||
|
||||
// Add valid new document IDs from the request
|
||||
existingDocumentIds.addAll(validDocumentIds);
|
||||
|
||||
// Set the combined document IDs back as the field value
|
||||
formEntity.setFieldValue(String.join(",", existingDocumentIds));
|
||||
applicationFormFieldRepository.save(formEntity);
|
||||
|
||||
log.info("Updated field value for application ID {} and field ID {} with document IDs {}",
|
||||
applicationAmendment.getApplicationId(), updatedFormField.getFieldId(), String.join(",", existingDocumentIds));
|
||||
fieldUpdated = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!fieldUpdated) {
|
||||
throw new CustomValidationException(Status.NOT_FOUND,
|
||||
String.format("No ApplicationFormField found for application ID %s and field ID %s. Skipping update.",
|
||||
applicationAmendment.getApplicationId(), updatedFormField.getFieldId()));
|
||||
}
|
||||
} else {
|
||||
log.warn("No valid document IDs found for update. Skipping field ID {}", updatedFormField.getFieldId());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void updateFormFieldsJson(ApplicationAmendmentRequestEntity applicationAmendment, ApplicationFormFieldRequestBean updatedFormField) {
|
||||
if (updatedFormField != null) {
|
||||
try {
|
||||
// Step 1: Fetch the existing form fields JSON
|
||||
String existingFormFieldsJson = applicationAmendment.getFormFields();
|
||||
List<ApplicationFormFieldRequestBean> formFieldsList;
|
||||
|
||||
if (existingFormFieldsJson == null || existingFormFieldsJson.isEmpty()) {
|
||||
formFieldsList = new ArrayList<>(); // If no existing data, start with an empty list
|
||||
} else {
|
||||
// Step 2: Deserialize the existing JSON into a list of objects
|
||||
formFieldsList = new ObjectMapper().readValue(existingFormFieldsJson, new TypeReference<List<ApplicationFormFieldRequestBean>>() {
|
||||
});
|
||||
}
|
||||
|
||||
// Step 3: Check if the field ID already exists in the list and update it
|
||||
boolean fieldUpdated = false;
|
||||
for (ApplicationFormFieldRequestBean field : formFieldsList) {
|
||||
if (field.getFieldId().equals(updatedFormField.getFieldId())) {
|
||||
field.setFieldValue(updatedFormField.getFieldValue()); // Update field value
|
||||
fieldUpdated = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// If field wasn't updated, log a warning message instead of adding a new field
|
||||
if (!fieldUpdated) {
|
||||
log.warn("Field ID {} does not exist in the form fields for application amendment ID {}", updatedFormField.getFieldId(), applicationAmendment.getId());
|
||||
throw new CustomValidationException(Status.NOT_FOUND, "Field ID {} does not exist in the form fields for application amendment ID {}");
|
||||
|
||||
}
|
||||
|
||||
// Step 4: Serialize the updated list back to JSON if the update was successful
|
||||
String updatedFormFieldsJson = new ObjectMapper().writeValueAsString(formFieldsList);
|
||||
applicationAmendment.setFormFields(updatedFormFieldsJson); // Update the form fields with the modified list
|
||||
|
||||
log.info("Updated form fields JSON for application amendment ID {}: {}", applicationAmendment.getId(), updatedFormFieldsJson);
|
||||
|
||||
} catch (JsonProcessingException e) {
|
||||
log.error("Error processing JSON for form fields for application amendment ID {}: {}", applicationAmendment.getId(), e.getMessage());
|
||||
throw new CustomValidationException(Status.BAD_REQUEST, "Error processing JSON for form fields");
|
||||
}
|
||||
} else {
|
||||
log.warn("No form field data to update for application amendment ID {}", applicationAmendment.getId());
|
||||
throw new CustomValidationException(Status.NOT_FOUND, "No form field data to update for application amendment ID {}");
|
||||
}
|
||||
}
|
||||
// private void updateApplicationFormFields(ApplicationAmendmentRequestEntity applicationAmendment, ApplicationFormFieldRequestBean updatedFormField) {
|
||||
// if (updatedFormField.getFieldValue() == null || "".equals(updatedFormField.getFieldValue().toString().trim())) {
|
||||
// List<ApplicationFormEntity> applicationForms = applicationFormRepository.findByApplicationId(applicationAmendment.getApplicationId());
|
||||
//
|
||||
// boolean fieldUpdated = false;
|
||||
//
|
||||
// for (ApplicationFormEntity applicationForm : applicationForms) {
|
||||
// Optional<ApplicationFormFieldEntity> formFieldEntityOptional = applicationFormFieldRepository
|
||||
// .findByApplicationFormIdAndFieldId(applicationForm.getId(), updatedFormField.getFieldId());
|
||||
//
|
||||
// if (formFieldEntityOptional.isPresent()) {
|
||||
// ApplicationFormFieldEntity formEntity = formFieldEntityOptional.get();
|
||||
// formEntity.setFieldValue(null); // Set field value to null
|
||||
// applicationFormFieldRepository.save(formEntity);
|
||||
// log.info("Set field value to null for application ID {} and field ID {}", applicationAmendment.getApplicationId(), updatedFormField.getFieldId());
|
||||
// fieldUpdated = true;
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// if (!fieldUpdated) {
|
||||
// throw new CustomValidationException(Status.NOT_FOUND, "No ApplicationFormField found for application ID " + applicationAmendment.getApplicationId() + " and field ID " + updatedFormField.getFieldId());
|
||||
// }
|
||||
// return;
|
||||
// }
|
||||
//
|
||||
// List<String> documentIds;
|
||||
//
|
||||
// if (updatedFormField.getFieldValue() instanceof String && updatedFormField.getFieldValue() != null) {
|
||||
// documentIds = Arrays.asList(((String) updatedFormField.getFieldValue()).split(","));
|
||||
// } else {
|
||||
// log.warn("Expected fieldValue as a comma-separated String but got: {}", updatedFormField.getFieldValue());
|
||||
// return;
|
||||
// }
|
||||
//
|
||||
// List<String> validDocumentIds = new ArrayList<>();
|
||||
// for (String documentId : documentIds) {
|
||||
// try {
|
||||
// DocumentEntity documentEntity = documentService.validateDocument(Long.parseLong(documentId.trim()));
|
||||
// if (documentEntity != null) {
|
||||
// validDocumentIds.add(documentId.trim());
|
||||
// } else {
|
||||
// log.warn("Document with ID {} does not exist. Skipping this ID.", documentId);
|
||||
// }
|
||||
// } catch (NumberFormatException e) {
|
||||
// log.error("Invalid document ID format: {}. Error: {}", documentId, e.getMessage());
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// if (!validDocumentIds.isEmpty()) {
|
||||
// List<ApplicationFormEntity> applicationForms = applicationFormRepository.findByApplicationId(applicationAmendment.getApplicationId());
|
||||
//
|
||||
// boolean fieldUpdated = false;
|
||||
//
|
||||
// // Parse the formFields JSON string to get amendment field values
|
||||
// String amendmentFieldValue = null;
|
||||
// try {
|
||||
// ObjectMapper mapper = new ObjectMapper();
|
||||
// List<ApplicationFormFieldRequestBean> amendmentFields = mapper.readValue(
|
||||
// applicationAmendment.getFormFields(),
|
||||
// mapper.getTypeFactory().constructCollectionType(List.class, ApplicationFormFieldRequestBean.class)
|
||||
// );
|
||||
//
|
||||
// // Find the matching field value and convert to string if found
|
||||
// Optional<Object> amendmentFieldObj = amendmentFields.stream()
|
||||
// .filter(field -> updatedFormField.getFieldId().equals(field.getFieldId()))
|
||||
// .map(ApplicationFormFieldRequestBean::getFieldValue)
|
||||
// .findFirst();
|
||||
//
|
||||
// if (amendmentFieldObj.isPresent() && amendmentFieldObj.get() instanceof String) {
|
||||
// amendmentFieldValue = (String) amendmentFieldObj.get();
|
||||
// }
|
||||
//
|
||||
// } catch (JsonProcessingException e) {
|
||||
// log.error("Error parsing formFields JSON: {}", e.getMessage());
|
||||
// return;
|
||||
// }
|
||||
//
|
||||
// if (amendmentFieldValue == null) {
|
||||
// log.warn("No matching field found in amendment for field ID {}", updatedFormField.getFieldId());
|
||||
// return;
|
||||
// }
|
||||
//
|
||||
// List<String> amendmentDocumentIds = Arrays.asList(amendmentFieldValue.split(","));
|
||||
//
|
||||
// for (ApplicationFormEntity applicationForm : applicationForms) {
|
||||
// Optional<ApplicationFormFieldEntity> formFieldEntityOptional = applicationFormFieldRepository
|
||||
// .findByApplicationFormIdAndFieldId(applicationForm.getId(), updatedFormField.getFieldId());
|
||||
//
|
||||
// if (formFieldEntityOptional.isPresent()) {
|
||||
// ApplicationFormFieldEntity formEntity = formFieldEntityOptional.get();
|
||||
//
|
||||
// // Retrieve existing document IDs in ApplicationFormFieldTable
|
||||
// String existingFieldValue = formEntity.getFieldValue();
|
||||
// Set<String> existingDocumentIds = existingFieldValue != null
|
||||
// ? new HashSet<>(Arrays.asList(existingFieldValue.split(",")))
|
||||
// : new HashSet<>();
|
||||
//
|
||||
// // Remove amendment documents from existing document IDs
|
||||
// existingDocumentIds.removeAll(amendmentDocumentIds);
|
||||
//
|
||||
// // Add valid new document IDs from the request
|
||||
// existingDocumentIds.addAll(validDocumentIds);
|
||||
// applicationDao.updateDocumentDeletionStatus(formEntity, updatedFormField, formEntity.getApplicationForm().getForm(), null,validDocumentIds,true);
|
||||
// // Set the combined document IDs back as the field value
|
||||
// formEntity.setFieldValue(String.join(",", existingDocumentIds));
|
||||
// applicationFormFieldRepository.save(formEntity);
|
||||
// log.info("Updated field value for application ID {} and field ID {} with document IDs {}",
|
||||
// applicationAmendment.getApplicationId(), updatedFormField.getFieldId(), String.join(",", existingDocumentIds));
|
||||
// fieldUpdated = true;
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// if (!fieldUpdated) {
|
||||
// throw new CustomValidationException(Status.NOT_FOUND,
|
||||
// String.format("No ApplicationFormField found for application ID %s and field ID %s. Skipping update.",
|
||||
// applicationAmendment.getApplicationId(), updatedFormField.getFieldId()));
|
||||
// }
|
||||
// } else {
|
||||
// log.warn("No valid document IDs found for update. Skipping field ID {}", updatedFormField.getFieldId());
|
||||
// }
|
||||
// }
|
||||
//
|
||||
//
|
||||
// private void updateFormFieldsJson(ApplicationAmendmentRequestEntity applicationAmendment, ApplicationFormFieldRequestBean updatedFormField) {
|
||||
// if (updatedFormField != null) {
|
||||
// try {
|
||||
// // Step 1: Fetch the existing form fields JSON
|
||||
// String existingFormFieldsJson = applicationAmendment.getFormFields();
|
||||
// List<ApplicationFormFieldRequestBean> formFieldsList;
|
||||
//
|
||||
// if (existingFormFieldsJson == null || existingFormFieldsJson.isEmpty()) {
|
||||
// formFieldsList = new ArrayList<>(); // If no existing data, start with an empty list
|
||||
// } else {
|
||||
// // Step 2: Deserialize the existing JSON into a list of objects
|
||||
// formFieldsList = new ObjectMapper().readValue(existingFormFieldsJson, new TypeReference<List<ApplicationFormFieldRequestBean>>() {
|
||||
// });
|
||||
// }
|
||||
//
|
||||
// // Step 3: Check if the field ID already exists in the list and update it
|
||||
// boolean fieldUpdated = false;
|
||||
// for (ApplicationFormFieldRequestBean field : formFieldsList) {
|
||||
// if (field.getFieldId().equals(updatedFormField.getFieldId())) {
|
||||
// field.setFieldValue(updatedFormField.getFieldValue()); // Update field value
|
||||
// fieldUpdated = true;
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// // If field wasn't updated, log a warning message instead of adding a new field
|
||||
// if (!fieldUpdated) {
|
||||
// log.warn("Field ID {} does not exist in the form fields for application amendment ID {}", updatedFormField.getFieldId(), applicationAmendment.getId());
|
||||
// throw new CustomValidationException(Status.NOT_FOUND, "Field ID {} does not exist in the form fields for application amendment ID {}");
|
||||
//
|
||||
// }
|
||||
//
|
||||
// // Step 4: Serialize the updated list back to JSON if the update was successful
|
||||
// String updatedFormFieldsJson = new ObjectMapper().writeValueAsString(formFieldsList);
|
||||
// applicationAmendment.setFormFields(updatedFormFieldsJson); // Update the form fields with the modified list
|
||||
//
|
||||
// log.info("Updated form fields JSON for application amendment ID {}: {}", applicationAmendment.getId(), updatedFormFieldsJson);
|
||||
//
|
||||
// } catch (JsonProcessingException e) {
|
||||
// log.error("Error processing JSON for form fields for application amendment ID {}: {}", applicationAmendment.getId(), e.getMessage());
|
||||
// throw new CustomValidationException(Status.BAD_REQUEST, "Error processing JSON for form fields");
|
||||
// }
|
||||
// } else {
|
||||
// log.warn("No form field data to update for application amendment ID {}", applicationAmendment.getId());
|
||||
// throw new CustomValidationException(Status.NOT_FOUND, "No form field data to update for application amendment ID {}");
|
||||
// }
|
||||
// }
|
||||
|
||||
|
||||
public List<ApplicationAmendmentRequestResponse> getAllAmendmentRequestByBeneficiaryId(Long beneficiaryId) {
|
||||
UserEntity userEntity = userService.validateUser(beneficiaryId);
|
||||
public List<ApplicationAmendmentRequestResponse> getAllAmendmentRequestByBeneficiaryId(Long beneficiaryUserId) {
|
||||
UserEntity userEntity = userService.validateUser(beneficiaryUserId);
|
||||
List<ApplicationAmendmentRequestEntity> entities =
|
||||
applicationAmendmentRequestRepository.findByUserId(beneficiaryId);
|
||||
applicationAmendmentRequestRepository.findByUserId(beneficiaryUserId);
|
||||
|
||||
return entities.stream()
|
||||
.map(this::convertEntityToResponse)
|
||||
@@ -649,12 +773,16 @@ public class ApplicationAmendmentRequestDao {
|
||||
ApplicationAmendmentRequestResponse response = convertEntityToResponse(updatedApplicationAmendment);
|
||||
|
||||
List<ApplicationAmendmentRequestEntity> amendmentRequests = applicationAmendmentRequestRepository.findAllByApplicationEvaluationIdAndIsDeletedFalse(existingApplicationAmendment.getApplicationEvaluationEntity().getId());
|
||||
boolean allClosed = amendmentRequests.stream()
|
||||
Boolean allClosed = amendmentRequests.stream()
|
||||
.allMatch(amendment -> amendment.getStatus().equals(ApplicationAmendmentRequestEnum.CLOSE.getValue()));
|
||||
|
||||
if (allClosed) {
|
||||
ApplicationEntity application = applicationService.validateApplication(existingApplicationAmendment.getApplicationId());
|
||||
if (Boolean.TRUE.equals(allClosed)){
|
||||
existingApplicationAmendment.getApplicationEvaluationEntity().setStatus(ApplicationEvaluationStatusTypeEnum.OPEN.getValue());
|
||||
applicationEvaluationRepository.save(existingApplicationAmendment.getApplicationEvaluationEntity());
|
||||
application.setStatus(ApplicationStatusTypeEnum.EVALUATION.getValue());
|
||||
applicationRepository.save(application);
|
||||
existingApplicationAmendment.getApplicationEvaluationEntity().getAssignedApplicationsEntity().setStatus(AssignedApplicationEnum.OPEN.getValue());
|
||||
assignedApplicationsRepository.save(existingApplicationAmendment.getApplicationEvaluationEntity().getAssignedApplicationsEntity());
|
||||
log.info("All amendments are closed. Application Evaluation status set to OPEN.");
|
||||
}
|
||||
log.info("Application Amendment closed successfully: {}", response);
|
||||
@@ -705,9 +833,9 @@ public class ApplicationAmendmentRequestDao {
|
||||
public ApplicationAmendmentRequestResponse updateApplicationAmendmentStatus(
|
||||
Long id, ApplicationAmendmentRequestEnum statusTypeEnum) {
|
||||
|
||||
log.info("Updating application amendement with status: {}", id);
|
||||
log.info("Updating application amendment with status: {}", id);
|
||||
ApplicationAmendmentRequestEntity existingApplicationAmendment = validateApplicationAmendmentRequest(id);
|
||||
if (Boolean.TRUE.equals(existingApplicationAmendment.getStatus().equals(ApplicationAmendmentRequestEnum.AWAITING.getValue())) && Boolean.TRUE.equals(statusTypeEnum.equals(ApplicationAmendmentRequestEnum.RESPONSE_RECEIVED))) {
|
||||
if (Boolean.TRUE.equals(existingApplicationAmendment.getStatus().equals(ApplicationAmendmentRequestEnum.AWAITING.getValue())) || Boolean.TRUE.equals(statusTypeEnum.equals(ApplicationAmendmentRequestEnum.RESPONSE_RECEIVED))) {
|
||||
existingApplicationAmendment.setStatus(ApplicationAmendmentRequestEnum.RESPONSE_RECEIVED.getValue());
|
||||
existingApplicationAmendment.setUpdatedDate(DateTimeUtil.DateServerToUTC(LocalDateTime.now()));
|
||||
applicationAmendmentRequestRepository.save(existingApplicationAmendment);
|
||||
@@ -733,7 +861,8 @@ public class ApplicationAmendmentRequestDao {
|
||||
String body = prepareBody(emailTemplate, amendment, beneficiaryUser);
|
||||
String email = beneficiaryUser.getEmail();
|
||||
if (Boolean.TRUE.equals(amendment.getIsEmail())&&email != null && !email.isEmpty()) {
|
||||
emailNotificationDao.sendMail(hub.getId(), subject, body, List.of(email));
|
||||
EmailLogRequest emailLogRequest=emailLogDao.createEmailLogRequest(emailTemplate.getEmailScenario(),RecipientTypeEnum.USER,beneficiaryUser.getId(),email,beneficiaryUser.getId(),applicationEntity.getId(),amendment.getId(),applicationEntity.getCall().getId());
|
||||
emailNotificationDao.sendMail(hub.getId(), subject, body, List.of(email),emailLogRequest);
|
||||
} else {
|
||||
throw new CustomValidationException(Status.BAD_REQUEST, Translator.toLocale(GepafinConstant.BENEFICIARY_EMAIL_NOT_FOUND_MSG));
|
||||
}
|
||||
@@ -769,4 +898,9 @@ public class ApplicationAmendmentRequestDao {
|
||||
}
|
||||
|
||||
|
||||
private void softDeleteDocument(Long documentId) {
|
||||
documentService.deleteFile(documentId);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ import net.gepafin.tendermanagement.enums.*;
|
||||
import net.gepafin.tendermanagement.model.request.ApplicationFormFieldRequestBean;
|
||||
import net.gepafin.tendermanagement.model.request.ApplicationRequest;
|
||||
import net.gepafin.tendermanagement.model.request.ApplicationRequestBean;
|
||||
import net.gepafin.tendermanagement.model.request.EmailLogRequest;
|
||||
import net.gepafin.tendermanagement.model.response.*;
|
||||
import net.gepafin.tendermanagement.repositories.*;
|
||||
import net.gepafin.tendermanagement.service.AmazonS3Service;
|
||||
@@ -142,6 +143,8 @@ public class ApplicationDao {
|
||||
@Autowired
|
||||
private FormDao formDao;
|
||||
|
||||
@Autowired
|
||||
private EmailLogDao emailLogDao;
|
||||
|
||||
public ApplicationResponseBean createApplication(HttpServletRequest request, ApplicationRequestBean applicationRequestBean, Long formId, Long applicationId) {
|
||||
FormEntity formEntity = formService.validateForm(formId);
|
||||
@@ -334,6 +337,10 @@ public class ApplicationDao {
|
||||
.collect(Collectors.toList());
|
||||
predicate = builder.and(predicate, root.get("status").in(statusNames));
|
||||
}
|
||||
query.orderBy(
|
||||
builder.desc(builder.isNotNull(root.get(GepafinConstant.SUBMISSION_DATE))),
|
||||
builder.desc(root.get(GepafinConstant.SUBMISSION_DATE))
|
||||
);
|
||||
predicate = builder.and(predicate, builder.equal(root.get("hubId"), userEntity.getHub().getId()));
|
||||
return predicate;
|
||||
};
|
||||
@@ -405,7 +412,7 @@ public class ApplicationDao {
|
||||
|
||||
ApplicationFormFieldEntity applicationFormFieldEntity=null;
|
||||
|
||||
validateFileUploadDocuments(applicationFormFieldRequestBean, formEntity);
|
||||
List<Long> newDocumentIds =validateFileUploadDocuments(applicationFormFieldRequestBean, formEntity);
|
||||
|
||||
if(applicationFormFieldEntities==null || applicationFormFieldEntities.isEmpty()){
|
||||
applicationFormFieldEntity = new ApplicationFormFieldEntity();
|
||||
@@ -427,13 +434,79 @@ public class ApplicationDao {
|
||||
Utils.setIfUpdated(applicationFormFieldEntity::getFieldId, applicationFormFieldEntity::setFieldId, applicationFormFieldRequestBean.getFieldId());
|
||||
|
||||
if(applicationFormFieldRequestBean.getFieldValue() !=null ) {
|
||||
updateDocumentDeletionStatus(applicationFormFieldEntity, applicationFormFieldRequestBean,formEntity,newDocumentIds,null,false);
|
||||
applicationFormFieldEntity.setFieldValue(Utils.convertObjectToJsonString(applicationFormFieldRequestBean.getFieldValue()));
|
||||
}
|
||||
if(applicationFormFieldRequestBean.getFieldValue() ==null ) {
|
||||
updateDocumentDeletionStatus(applicationFormFieldEntity, applicationFormFieldRequestBean,formEntity,newDocumentIds,null,false);
|
||||
applicationFormFieldEntity.setFieldValue(null);
|
||||
}
|
||||
return applicationFormFieldRepository.save(applicationFormFieldEntity);
|
||||
}
|
||||
void updateDocumentDeletionStatus(ApplicationFormFieldEntity applicationFormFieldEntity, ApplicationFormFieldRequestBean applicationFormFieldRequestBean, FormEntity formEntity, List<Long> newDocumentIds,
|
||||
List<String> preInstructorDocumentId,boolean isPreInstructor) {
|
||||
if (newDocumentIds == null) {
|
||||
newDocumentIds = Collections.emptyList();
|
||||
}
|
||||
if (preInstructorDocumentId == null) {
|
||||
preInstructorDocumentId = Collections.emptyList();
|
||||
}
|
||||
|
||||
List<ContentResponseBean> contentResponseBeans = formDao.convertFormEntityToFormResponseBean(formEntity).getContent();
|
||||
for (ContentResponseBean contentResponseBean : contentResponseBeans) {
|
||||
if (Boolean.FALSE.equals(contentResponseBean.getName().equals("fileupload"))) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
if(!isPreInstructor){
|
||||
List<Long> currentDocumentIds = parseDocumentIds(applicationFormFieldEntity.getFieldValue());
|
||||
if (Boolean.TRUE.equals(newDocumentIds.isEmpty())) {
|
||||
currentDocumentIds.forEach(docId -> documentService.deleteFile(docId));
|
||||
} else {
|
||||
List<Long> finalNewDocumentIds = newDocumentIds;
|
||||
List<Long> documentsToDelete = currentDocumentIds.stream()
|
||||
.filter(docId -> !finalNewDocumentIds.contains(docId))
|
||||
.toList();
|
||||
documentsToDelete.forEach(docId -> documentService.deleteFile(docId));
|
||||
}}
|
||||
else{
|
||||
List<Long> currentDocumentIds = parseDocumentIds(applicationFormFieldEntity.getFieldValue());
|
||||
if (Boolean.TRUE.equals(preInstructorDocumentId.isEmpty())) {
|
||||
currentDocumentIds.forEach(docId -> documentService.deleteFile(docId));
|
||||
} else {
|
||||
List<Long> preInstructorDocIds = preInstructorDocumentId.stream()
|
||||
.map(Long::valueOf)
|
||||
.collect(Collectors.toList());
|
||||
|
||||
List<Long> documentsToDelete = currentDocumentIds.stream()
|
||||
.filter(docId -> !preInstructorDocIds.contains(docId))
|
||||
.toList();
|
||||
documentsToDelete.forEach(docId -> documentService.deleteFile(docId));
|
||||
}}
|
||||
}
|
||||
|
||||
|
||||
private List<Long> parseDocumentIds(String fieldValue) {
|
||||
if (fieldValue == null || fieldValue.isEmpty()) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
if (fieldValue.contains(",")) {
|
||||
return Arrays.stream(fieldValue.split(","))
|
||||
.map(String::trim)
|
||||
.map(Long::parseLong)
|
||||
.collect(Collectors.toList());
|
||||
} else {
|
||||
try {
|
||||
return Collections.singletonList(Long.parseLong(fieldValue.trim()));
|
||||
} catch (NumberFormatException e) {
|
||||
e.printStackTrace();
|
||||
return Collections.emptyList();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
private List<Long> validateFileUploadDocuments(ApplicationFormFieldRequestBean applicationFormFieldRequestBean, FormEntity formEntity) {
|
||||
List<Long> documentIds=null;
|
||||
@@ -795,12 +868,14 @@ public class ApplicationDao {
|
||||
// Replace placeholders in the subject and body
|
||||
String subject = Utils.replacePlaceholders(systemEmailTemplateResponse.getSubject(), subjectPlaceholders);
|
||||
String body = Utils.replacePlaceholders(systemEmailTemplateResponse.getHtmlContent(), bodyPlaceholders);
|
||||
|
||||
EmailLogRequest emailLogRequest=emailLogDao.createEmailLogRequest(systemEmailTemplateResponse.getEmailScenario(),RecipientTypeEnum.USER,userEntity.getId(),userEntity.getEmail(),userEntity.getId(),applicationEntity.getId(),null,applicationEntity.getCall().getId());
|
||||
String email = userEntity.getEmail();
|
||||
if (userEntity.getBeneficiary() != null) {
|
||||
emailLogRequest.setRecipientType(RecipientTypeEnum.BENEFICIARY);
|
||||
email = userEntity.getBeneficiary().getEmail();
|
||||
emailLogRequest.setUserId(userEntity.getBeneficiary().getId());
|
||||
}
|
||||
emailNotificationDao.sendMail(hub.getId(), subject, body, List.of(email));
|
||||
emailNotificationDao.sendMail(hub.getId(), subject, body, List.of(email),emailLogRequest);
|
||||
List<String> recipientEmails = new ArrayList<>();
|
||||
// recipientEmails.add(email);
|
||||
String companyEmail = company.getEmail();
|
||||
@@ -813,7 +888,12 @@ public class ApplicationDao {
|
||||
if (contactEmail != null && !contactEmail.isEmpty() && !contactEmail.equals(companyEmail)) {
|
||||
recipientEmails.add(contactEmail);
|
||||
}
|
||||
emailNotificationDao.sendMail(hub.getId(), subject, body, recipientEmails);
|
||||
if(Boolean.FALSE.equals(recipientEmails.isEmpty())){
|
||||
emailLogRequest.setRecipientId(applicationEntity.getCompany().getId());
|
||||
emailLogRequest.setRecipientType(RecipientTypeEnum.COMPANY);
|
||||
emailLogRequest.setRecipientEmails(companyEmail);
|
||||
}
|
||||
emailNotificationDao.sendMail(hub.getId(), subject, body, recipientEmails,emailLogRequest);
|
||||
}
|
||||
private void sendMailTodefaultSystemAndGepafin(UserEntity userEntity, ApplicationEntity applicationEntity) {
|
||||
CallEntity call = applicationEntity.getCall();
|
||||
@@ -840,17 +920,22 @@ public class ApplicationDao {
|
||||
String subject = Utils.replacePlaceholders(systemEmailTemplateResponse.getSubject(), subjectPlaceholders);
|
||||
String body = Utils.replacePlaceholders(systemEmailTemplateResponse.getHtmlContent(), bodyPlaceholders);
|
||||
|
||||
EmailLogRequest emailLogRequest=emailLogDao.createEmailLogRequest(systemEmailTemplateResponse.getEmailScenario(),RecipientTypeEnum.PROPERTIES,null,userEntity.getEmail(),userEntity.getId(),applicationEntity.getId(),null,applicationEntity.getCall().getId());
|
||||
|
||||
// mailUtil.sendByMailGun(subject, body, List.of(defaultSystemReceiverEmail), null);
|
||||
// mailUtil.sendByMailGun(subject, body, List.of(gepafinEmail), null);
|
||||
// mailUtil.sendByMailGun(subject, body, List.of(rinaldoEmail), null);
|
||||
if(validator.isProductionProfileActivated()) {
|
||||
emailLogRequest.setRecipientEmails(carloEmail);
|
||||
// mailUtil.sendByMailGun(subject, body, List.of(carloEmail), null);
|
||||
emailNotificationDao.sendMail(hub.getId(), subject, body, List.of(carloEmail));
|
||||
emailNotificationDao.sendMail(hub.getId(), subject, body, List.of(carloEmail),emailLogRequest);
|
||||
}
|
||||
emailNotificationDao.sendMail(hub.getId(), subject, body, List.of(hub.getEmail()));
|
||||
emailNotificationDao.sendMail(hub.getId(), subject, body, List.of(defaultSystemReceiverEmail));
|
||||
emailNotificationDao.sendMail(hub.getId(), subject, body, List.of(rinaldoEmail));
|
||||
emailLogRequest.setRecipientEmails(hub.getEmail());
|
||||
emailNotificationDao.sendMail(hub.getId(), subject, body, List.of(hub.getEmail()),emailLogRequest);
|
||||
emailLogRequest.setRecipientEmails(defaultSystemReceiverEmail);
|
||||
emailNotificationDao.sendMail(hub.getId(), subject, body, List.of(defaultSystemReceiverEmail),emailLogRequest);
|
||||
emailLogRequest.setRecipientEmails(rinaldoEmail);
|
||||
emailNotificationDao.sendMail(hub.getId(), subject, body, List.of(rinaldoEmail),emailLogRequest);
|
||||
|
||||
}
|
||||
public ApplicationSignedDocumentResponse uploadSignedDocument(HttpServletRequest request, Long applicationId,
|
||||
|
||||
@@ -15,6 +15,7 @@ import net.gepafin.tendermanagement.model.request.FieldRequest;
|
||||
import net.gepafin.tendermanagement.model.response.*;
|
||||
import net.gepafin.tendermanagement.repositories.*;
|
||||
import net.gepafin.tendermanagement.service.ApplicationService;
|
||||
import net.gepafin.tendermanagement.service.AssignedApplicationsService;
|
||||
import net.gepafin.tendermanagement.service.CallService;
|
||||
import net.gepafin.tendermanagement.service.UserService;
|
||||
import net.gepafin.tendermanagement.util.Utils;
|
||||
@@ -82,11 +83,14 @@ public class ApplicationEvaluationDao {
|
||||
@Autowired
|
||||
private FormDao formDao;
|
||||
|
||||
@Autowired
|
||||
private AssignedApplicationsService assignedApplicationsService;
|
||||
|
||||
private ApplicationEvaluationEntity convertToEntity(UserEntity user, ApplicationEvaluationRequest req, Long assignedApplciationId) {
|
||||
|
||||
ApplicationEvaluationEntity entity = new ApplicationEvaluationEntity();
|
||||
|
||||
AssignedApplicationsEntity assignedApplications = assignedApplicationsRepository.findByIdAndIsDeletedFalse(assignedApplciationId).orElse(null);
|
||||
AssignedApplicationsEntity assignedApplications = assignedApplicationsService.validateAssignedApplication(assignedApplciationId);
|
||||
ApplicationEntity application = applicationService.validateApplication(assignedApplications.getApplication().getId());
|
||||
entity.setApplicationId(application.getId());
|
||||
entity.setAssignedApplicationsEntity(assignedApplications);
|
||||
@@ -95,6 +99,7 @@ public class ApplicationEvaluationDao {
|
||||
entity.setChecklist(Utils.convertObjectToJson(req.getChecklist()));
|
||||
entity.setFile(Utils.convertObjectToJson(req.getFiles()));
|
||||
entity.setNote(req.getNote());
|
||||
entity.setMotivation(req.getMotivation());
|
||||
entity.setIsDeleted(false);
|
||||
entity.setStatus(ApplicationEvaluationStatusTypeEnum.OPEN.getValue());
|
||||
return entity;
|
||||
@@ -126,6 +131,7 @@ public class ApplicationEvaluationDao {
|
||||
AssignedApplicationsEntity assignedApplications = assignedApplicationsRepository.findByIdAndIsDeletedFalse(entity.getAssignedApplicationsEntity().getId()).orElse(null);
|
||||
response.setAssignedApplicationId(assignedApplications.getId());
|
||||
response.setNote(entity.getNote());
|
||||
response.setMotivation(entity.getMotivation());
|
||||
response.setStatus(ApplicationEvaluationStatusTypeEnum.valueOf(entity.getStatus()));
|
||||
response.setCreatedDate(entity.getCreatedDate());
|
||||
response.setUpdatedDate(entity.getUpdatedDate());
|
||||
@@ -249,6 +255,7 @@ public class ApplicationEvaluationDao {
|
||||
List<DocumentResponseBean> documentResponseBeans = new ArrayList<>();
|
||||
|
||||
for (String docId : documentIds) {
|
||||
if (Boolean.FALSE.equals(docId.isEmpty())){
|
||||
Long documentId = Long.valueOf(docId.trim());
|
||||
documentRepository.findByIdAndNotDeleted(documentId).ifPresent(documentEntity -> {
|
||||
DocumentResponseBean responseBean = new DocumentResponseBean();
|
||||
@@ -263,6 +270,7 @@ public class ApplicationEvaluationDao {
|
||||
documentResponseBeans.add(responseBean);
|
||||
});
|
||||
}
|
||||
}
|
||||
mappedField.setFieldValue(documentResponseBeans);
|
||||
}
|
||||
}
|
||||
@@ -351,6 +359,7 @@ public class ApplicationEvaluationDao {
|
||||
List<DocumentResponseBean> documentResponseBeans = new ArrayList<>();
|
||||
|
||||
for (String docId : documentIds) {
|
||||
if (Boolean.FALSE.equals(docId.isEmpty())){
|
||||
Long documentId = Long.valueOf(docId.trim());
|
||||
documentRepository.findByIdAndNotDeleted(documentId).ifPresent(documentEntity -> {
|
||||
DocumentResponseBean responseBean = new DocumentResponseBean();
|
||||
@@ -365,6 +374,7 @@ public class ApplicationEvaluationDao {
|
||||
documentResponseBeans.add(responseBean);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
fieldResponse.setFileDetail(documentResponseBeans);
|
||||
}
|
||||
@@ -429,6 +439,7 @@ public class ApplicationEvaluationDao {
|
||||
entity.setFile(Utils.convertObjectToJson(filterNonNullFields(processField(entity, req))));
|
||||
entity.setIsDeleted(false);
|
||||
setIfUpdated(entity::getNote, entity::setNote, req.getNote());
|
||||
setIfUpdated(entity::getMotivation, entity::setMotivation, req.getMotivation());
|
||||
} else {
|
||||
entity = convertToEntity(user, req, assignedApplicationId);
|
||||
}
|
||||
@@ -628,6 +639,7 @@ public class ApplicationEvaluationDao {
|
||||
response.setApplicationId(application.getId());
|
||||
response.setAssignedApplicationId(assignedApplications.getId());
|
||||
response.setNote(null);
|
||||
response.setMotivation(null);
|
||||
response.setApplicationStatus(ApplicationStatusTypeEnum.valueOf(application.getStatus()));
|
||||
response.setStatus(ApplicationEvaluationStatusTypeEnum.valueOf(ApplicationEvaluationStatusTypeEnum.OPEN.getValue()));
|
||||
response.setMinScore(call.getThreshold()!=null?call.getThreshold():null);
|
||||
@@ -888,6 +900,7 @@ public class ApplicationEvaluationDao {
|
||||
List<DocumentResponseBean> documentResponseBeans = new ArrayList<>();
|
||||
|
||||
for (String docId : documentIds) {
|
||||
if (Boolean.FALSE.equals(docId.isEmpty())) {
|
||||
Long documentId = Long.valueOf(docId.trim());
|
||||
documentRepository.findByIdAndNotDeleted(documentId).ifPresent(documentEntity -> {
|
||||
DocumentResponseBean responseBean = new DocumentResponseBean();
|
||||
@@ -902,6 +915,7 @@ public class ApplicationEvaluationDao {
|
||||
documentResponseBeans.add(responseBean);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
fieldResponse.setFileDetail(documentResponseBeans);
|
||||
}
|
||||
@@ -1247,6 +1261,7 @@ public class ApplicationEvaluationDao {
|
||||
List<DocumentResponseBean> documentResponseBeans = new ArrayList<>();
|
||||
|
||||
for (String docId : documentIds) {
|
||||
if (Boolean.FALSE.equals(docId.isEmpty())){
|
||||
Long documentId = Long.valueOf(docId.trim());
|
||||
documentRepository.findByIdAndNotDeleted(documentId).ifPresent(documentEntity -> {
|
||||
DocumentResponseBean responseBean = new DocumentResponseBean();
|
||||
@@ -1261,7 +1276,7 @@ public class ApplicationEvaluationDao {
|
||||
documentResponseBeans.add(responseBean);
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
fieldResponse.setFileDetail(documentResponseBeans);
|
||||
fieldResponses.add(fieldResponse);
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ import net.gepafin.tendermanagement.entities.AssignedApplicationsEntity;
|
||||
import net.gepafin.tendermanagement.entities.UserEntity;
|
||||
import net.gepafin.tendermanagement.enums.ApplicationStatusTypeEnum;
|
||||
import net.gepafin.tendermanagement.enums.AssignedApplicationEnum;
|
||||
import net.gepafin.tendermanagement.model.request.ApplicationEvaluationRequest;
|
||||
import net.gepafin.tendermanagement.model.request.AssignedApplicationsRequest;
|
||||
import net.gepafin.tendermanagement.model.response.AssignedApplicationsResponse;
|
||||
import net.gepafin.tendermanagement.repositories.ApplicationRepository;
|
||||
@@ -47,6 +48,8 @@ public class AssignedApplicationsDao {
|
||||
|
||||
@Autowired
|
||||
private Validator validator;
|
||||
@Autowired
|
||||
private ApplicationEvaluationDao applicationEvaluationDao;
|
||||
|
||||
public AssignedApplicationsResponse createAssignedApplications(Long applicationId, Long userId, UserEntity assignedByUser, AssignedApplicationsRequest assignedApplicationsRequest){
|
||||
log.info("Assigning application to pre-Instructor with details: {}", applicationId,userId);
|
||||
@@ -69,7 +72,7 @@ public class AssignedApplicationsDao {
|
||||
UserEntity user = userService.validateUser(userId);
|
||||
AssignedApplicationsEntity assignment = createAssignmentEntity(application, user.getId(), assignedByUser, assignedApplicationsRequest);
|
||||
AssignedApplicationsResponse assignApplicationToInstructorResponse = convertEntityToResponse(assignment);
|
||||
|
||||
applicationEvaluationDao.createOrUpdateApplicationEvaluation(user, new ApplicationEvaluationRequest(), assignApplicationToInstructorResponse.getId());
|
||||
log.info("Application assigned succesfully {}", assignApplicationToInstructorResponse);
|
||||
return assignApplicationToInstructorResponse;
|
||||
}
|
||||
@@ -128,6 +131,7 @@ public class AssignedApplicationsDao {
|
||||
assignedApplicationsResponse.setAssignedAt(assignedApplications.getAssignedAt());
|
||||
assignedApplicationsResponse.setProtocolNumber(protocolNumber);
|
||||
assignedApplicationsResponse.setCallName(callName);
|
||||
assignedApplicationsResponse.setCompanyName(application.getCompany().getCompanyName());
|
||||
assignedApplicationsResponse.setBeneficiaryName(beneficiaryName);
|
||||
assignedApplicationsResponse.setSubmissionDate(submissionDate);
|
||||
assignedApplicationsResponse.setCallEndDate(callEndDate);
|
||||
@@ -171,6 +175,10 @@ public class AssignedApplicationsDao {
|
||||
if (userId != null) {
|
||||
predicate = builder.and(predicate, builder.equal(root.get("userId"), userId));
|
||||
}
|
||||
query.orderBy(
|
||||
builder.desc(builder.isNotNull(root.get(GepafinConstant.ASSIGNED_AT))),
|
||||
builder.desc(root.get(GepafinConstant.ASSIGNED_AT))
|
||||
);
|
||||
predicate = builder.and(predicate, builder.equal(root.get("application").get("hubId"), hubId));
|
||||
return predicate;
|
||||
};
|
||||
|
||||
@@ -656,13 +656,29 @@ public class CallDao {
|
||||
return createCallResponseBean;
|
||||
}
|
||||
|
||||
public List<CallDetailsResponseBean> getAllCalls(HttpServletRequest request,UserEntity user, Long companyId) {
|
||||
public List<CallDetailsResponseBean> getAllCalls(HttpServletRequest request,UserEntity user, Long companyId,Boolean onlyPreferredCall) {
|
||||
String type = user.getRoleEntity().getRoleType();
|
||||
List<String> callStatusList = CallStatusEnum.getStatusValues();
|
||||
if (Boolean.FALSE.equals(ROLE_SUPER_ADMIN.getValue().equals(type))) {
|
||||
callStatusList = List.of(CallStatusEnum.PUBLISH.getValue());
|
||||
}
|
||||
List<CallEntity> calls = callRepository.findByStatusInAndHubId(callStatusList, user.getHub().getId());
|
||||
List<CallEntity> calls;
|
||||
if (Boolean.TRUE.equals(onlyPreferredCall) && companyId == null) {
|
||||
throw new CustomValidationException(Status.VALIDATION_ERROR,
|
||||
Translator.toLocale(GepafinConstant.COMPANY_ID_REQUIRED_FOR_PREFERRED_CALL));
|
||||
}
|
||||
|
||||
if (Boolean.TRUE.equals(onlyPreferredCall)) {
|
||||
validator.validateUserWithCompany(request, companyId);
|
||||
List<BeneficiaryPreferredCallEntity> preferredCalls = beneficiaryPreferredCallRepository
|
||||
.findByUserIdAndCompanyIdAndIsDeletedFalse(user.getId(), companyId);
|
||||
List<Long> preferredCallIds = preferredCalls.stream()
|
||||
.map(BeneficiaryPreferredCallEntity::getCallId)
|
||||
.collect(Collectors.toList());
|
||||
calls = callRepository.findByIdInAndStatusIn(preferredCallIds, callStatusList);
|
||||
} else {
|
||||
calls = callRepository.findByStatusInAndHubId(callStatusList, user.getHub().getId());
|
||||
}
|
||||
List<Long> callIds = calls.stream().map(CallEntity::getId).collect(Collectors.toList());
|
||||
Map<String, BeneficiaryPreferredCallEntity> preferredCallsMap =
|
||||
getBeneficiaryPreferredCallsForUser(request,user, callIds, companyId);
|
||||
|
||||
@@ -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);
|
||||
@@ -53,7 +58,7 @@ public class CommunicationDao {
|
||||
public ApplicationAmendmentResponse getAmendmentComments(Long amendmentId) {
|
||||
|
||||
ApplicationAmendmentRequestEntity amendmentData = applicationAmendmentRequestService.validateApplicationAmendmentRequest(amendmentId);
|
||||
List<CommunicationResponseBean> commentsList = communicationRepository.findCommentDetailsByAmendmentId(amendmentId);
|
||||
List<CommunicationResponseBean> commentsList = communicationRepository.findCommentListDetailsByAmendmentId(amendmentId);
|
||||
if (commentsList == null) {
|
||||
throw new CustomValidationException(Status.NOT_FOUND, Translator.toLocale(GepafinConstant.COMMENT_NOT_FOUND));
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -109,7 +109,8 @@ public class DocumentDao {
|
||||
}
|
||||
|
||||
public void deleteFile(Long documentId) {
|
||||
DocumentEntity documentEntity = validateDocument(documentId);
|
||||
DocumentEntity documentEntity = documentRepository.findById(documentId).orElseThrow(() -> new ResourceNotFoundException(Status.NOT_FOUND,
|
||||
Translator.toLocale(GepafinConstant.DOCUMENT_NOT_FOUND)));
|
||||
// String fileName= Utils.extractFileName(documentEntity.getFilePath());
|
||||
// deleteFileOnAmazonS3(fileName);
|
||||
documentEntity.setIsDeleted(true);
|
||||
@@ -118,7 +119,7 @@ public class DocumentDao {
|
||||
|
||||
|
||||
public DocumentEntity validateDocument(Long id) {
|
||||
return documentRepository.findById(id).orElseThrow(() -> new ResourceNotFoundException(Status.NOT_FOUND,
|
||||
return documentRepository.findByIdAndNotDeleted(id).orElseThrow(() -> new ResourceNotFoundException(Status.NOT_FOUND,
|
||||
Translator.toLocale(GepafinConstant.DOCUMENT_NOT_FOUND)));
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,59 @@
|
||||
package net.gepafin.tendermanagement.dao;
|
||||
|
||||
import net.gepafin.tendermanagement.entities.EmailLogEntity;
|
||||
import net.gepafin.tendermanagement.enums.EmailScenarioTypeEnum;
|
||||
import net.gepafin.tendermanagement.enums.EmailEntityTypeEnum;
|
||||
import net.gepafin.tendermanagement.enums.RecipientTypeEnum;
|
||||
import net.gepafin.tendermanagement.model.request.EmailLogRequest;
|
||||
import net.gepafin.tendermanagement.repositories.EmailLogRepository;
|
||||
import net.gepafin.tendermanagement.util.DateTimeUtil;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
@Component
|
||||
public class EmailLogDao {
|
||||
|
||||
@Autowired
|
||||
private EmailLogRepository emailLogRepository;
|
||||
|
||||
|
||||
public EmailLogEntity createEmailLog(EmailLogRequest emailLogRequest){
|
||||
EmailLogEntity emailLogEntity=new EmailLogEntity();
|
||||
emailLogEntity.setEmailType(emailLogRequest.getEmailType().getValue());
|
||||
emailLogEntity.setRecipientType(emailLogRequest.getRecipientType().getValue());
|
||||
emailLogEntity.setRecipientId(emailLogRequest.getRecipientId());
|
||||
emailLogEntity.setEmailSubject(emailLogRequest.getEmailSubject());
|
||||
emailLogEntity.setEmailBody(emailLogRequest.getEmailBody());
|
||||
emailLogEntity.setSendStatus(emailLogRequest.getSendStatus());
|
||||
emailLogEntity.setSendDateTime(DateTimeUtil.DateServerToUTC(LocalDateTime.now())); // Set to now if null
|
||||
emailLogEntity.setErrorMessage(emailLogRequest.getErrorMessage());
|
||||
emailLogEntity.setUserId(emailLogRequest.getUserId());
|
||||
emailLogEntity.setEmailServiceResponse(emailLogRequest.getEmailServiceResponse());
|
||||
emailLogEntity.setRecipientEmails(emailLogRequest.getRecipientEmails());
|
||||
emailLogEntity.setEmailServiceType(emailLogRequest.getEmailServiceType().getValue());
|
||||
emailLogEntity.setIsDeleted(false);
|
||||
emailLogEntity.setApplicationId(emailLogRequest.getApplicatioId());
|
||||
emailLogEntity.setAmendmentId(emailLogRequest.getAmendmentId());
|
||||
emailLogEntity.setCallId(emailLogRequest.getCallId());
|
||||
emailLogEntity=saveEmailLogEntity(emailLogEntity);
|
||||
return emailLogEntity;
|
||||
}
|
||||
public EmailLogEntity saveEmailLogEntity(EmailLogEntity emailLogEntity){
|
||||
return emailLogRepository.save(emailLogEntity);
|
||||
}
|
||||
public EmailLogRequest createEmailLogRequest(EmailScenarioTypeEnum emailType, RecipientTypeEnum recipientType, Long recipientId,
|
||||
String recipientEmails, Long userId,Long applicationId,Long amendmentId,Long callId) {
|
||||
EmailLogRequest emailLogRequest = new EmailLogRequest();
|
||||
emailLogRequest.setEmailType(emailType);
|
||||
emailLogRequest.setRecipientType(recipientType);
|
||||
emailLogRequest.setRecipientId(recipientId);
|
||||
emailLogRequest.setUserId(userId);
|
||||
emailLogRequest.setRecipientEmails(recipientEmails);
|
||||
emailLogRequest.setApplicatioId(applicationId);
|
||||
emailLogRequest.setAmendmentId(amendmentId);
|
||||
emailLogRequest.setCallId(callId);
|
||||
return emailLogRequest;
|
||||
}
|
||||
}
|
||||
@@ -5,8 +5,14 @@ import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import net.gepafin.tendermanagement.constants.GepafinConstant;
|
||||
import net.gepafin.tendermanagement.entities.*;
|
||||
import net.gepafin.tendermanagement.enums.EmailEntityTypeEnum;
|
||||
import net.gepafin.tendermanagement.enums.RecipientTypeEnum;
|
||||
import net.gepafin.tendermanagement.enums.StatusTypeEnum;
|
||||
import net.gepafin.tendermanagement.entities.*;
|
||||
import net.gepafin.tendermanagement.model.request.EmailConfig;
|
||||
import net.gepafin.tendermanagement.model.request.EmailLogRequest;
|
||||
import net.gepafin.tendermanagement.model.response.SystemEmailTemplateResponse;
|
||||
import net.gepafin.tendermanagement.repositories.EmailLogRepository;
|
||||
import net.gepafin.tendermanagement.repositories.HubRepository;
|
||||
import net.gepafin.tendermanagement.service.ApplicationService;
|
||||
import net.gepafin.tendermanagement.service.HubService;
|
||||
@@ -21,10 +27,8 @@ import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.*;
|
||||
|
||||
@Component
|
||||
public class EmailNotificationDao {
|
||||
@@ -49,8 +53,15 @@ public class EmailNotificationDao {
|
||||
@Autowired
|
||||
HubRepository hubRepository;
|
||||
|
||||
@Autowired
|
||||
private EmailLogDao emailLogDao;
|
||||
|
||||
@Autowired
|
||||
private EmailLogRepository emailLogRepository;
|
||||
|
||||
|
||||
private void sendEmail(ApplicationEntity applicationEntity, SystemEmailTemplatesEntity.SystemEmailTemplatesEntityTypeEnum templateType,
|
||||
Map<String, String> bodyPlaceholders, List<String> additionalRecipients) {
|
||||
Map<String, String> bodyPlaceholders, List<String> additionalRecipients,Long amendmentId) {
|
||||
|
||||
HubEntity hubEntity = hubService.valdateHub(applicationEntity.getHubId());
|
||||
String service = determineService(applicationEntity.getHubId());
|
||||
@@ -66,7 +77,8 @@ public class EmailNotificationDao {
|
||||
|
||||
UserEntity userEntity = userService.validateUser(applicationEntity.getUserId());
|
||||
List<String> recipientEmails = getRecipientEmails(applicationEntity, userEntity, additionalRecipients);
|
||||
sendMail(applicationEntity.getHubId(), subject, body, recipientEmails);
|
||||
EmailLogRequest emailLogRequest=emailLogDao.createEmailLogRequest(systemEmailTemplateResponse.getEmailScenario(), RecipientTypeEnum.BENEFICIARY,userEntity.getBeneficiary().getId(),Utils.listToCommaSeparatedString(recipientEmails),userEntity.getId(),applicationEntity.getId(),amendmentId ,applicationEntity.getCall().getId());
|
||||
sendMail(applicationEntity.getHubId(), subject, body, recipientEmails,emailLogRequest);
|
||||
}
|
||||
private List<String> getRecipientEmails(ApplicationEntity applicationEntity, UserEntity userEntity, List<String> additionalRecipients) {
|
||||
List<String> recipientEmails = new ArrayList<>();
|
||||
@@ -125,17 +137,24 @@ public class EmailNotificationDao {
|
||||
log.error("Failed to parse form fields JSON: ", e);
|
||||
}
|
||||
bodyPlaceholders.put("{{note}}", applicationAmendmentRequest.getNote());
|
||||
sendEmail(applicationEntity, SystemEmailTemplatesEntity.SystemEmailTemplatesEntityTypeEnum.DOCUMENTATION_INTEGRATION_REQUEST, bodyPlaceholders, null);
|
||||
sendEmail(applicationEntity, SystemEmailTemplatesEntity.SystemEmailTemplatesEntityTypeEnum.DOCUMENTATION_INTEGRATION_REQUEST, bodyPlaceholders, null,applicationAmendmentRequest.getId());
|
||||
}
|
||||
|
||||
public void sendApplicationFailureNotificationEmail(ApplicationAmendmentRequestEntity amendmentRequest) {
|
||||
|
||||
ApplicationEntity applicationEntity = applicationService.validateApplication(amendmentRequest.getApplicationId());
|
||||
UserEntity user = userService.validateUser(applicationEntity.getUserId());
|
||||
Map<String, String> bodyPlaceholders = new HashMap<>();
|
||||
bodyPlaceholders.put("{{call_name}}", applicationEntity.getCall().getName());
|
||||
bodyPlaceholders.put("{{date_time_emailSend}}", DateTimeUtil.formatLocalDateTime(amendmentRequest.getCreatedDate(), GepafinConstant.DD_MM_YYYY_HH_MM));
|
||||
LocalDateTime lastReminderDateTime=amendmentRequest.getCreatedDate();
|
||||
List<EmailLogEntity> emailLogEntity = emailLogRepository.findByUserIdAndAmendmentIdAndIsDeletedFalse(user.getId(),amendmentRequest.getId());
|
||||
if(emailLogEntity!=null && (!emailLogEntity.isEmpty())){
|
||||
EmailLogEntity emailLogEntity1=emailLogEntity.get(0);
|
||||
lastReminderDateTime=emailLogEntity1.getSendDateTime();
|
||||
}
|
||||
bodyPlaceholders.put("{{date_time_emailSend}}", DateTimeUtil.formatLocalDateTime(lastReminderDateTime, GepafinConstant.DD_MM_YYYY));
|
||||
|
||||
sendEmail(applicationEntity, SystemEmailTemplatesEntity.SystemEmailTemplatesEntityTypeEnum.INADMISSIBILITY_NOTIFICATION_DUE_TO_FAILURE, bodyPlaceholders, null);
|
||||
sendEmail(applicationEntity, SystemEmailTemplatesEntity.SystemEmailTemplatesEntityTypeEnum.INADMISSIBILITY_NOTIFICATION_DUE_TO_FAILURE, bodyPlaceholders, null,amendmentRequest.getId());
|
||||
}
|
||||
|
||||
public void sendAdmissibilityNotificationEmailForApprovedApplication(ApplicationEntity applicationEntity) {
|
||||
@@ -145,7 +164,7 @@ public class EmailNotificationDao {
|
||||
bodyPlaceholders.put("{{protocol_date}}", DateTimeUtil.formatCreatedDate(applicationEntity.getProtocol().getCreatedDate()));
|
||||
bodyPlaceholders.put("{{protocol_time}}", DateTimeUtil.parseLocalTimeToString(applicationEntity.getProtocol().getTime(), GepafinConstant.HH_MM_SS));
|
||||
|
||||
sendEmail(applicationEntity, SystemEmailTemplatesEntity.SystemEmailTemplatesEntityTypeEnum.ADMISSIBILITY_NOTIFICATION, bodyPlaceholders, null);
|
||||
sendEmail(applicationEntity, SystemEmailTemplatesEntity.SystemEmailTemplatesEntityTypeEnum.ADMISSIBILITY_NOTIFICATION, bodyPlaceholders, null,null);
|
||||
}
|
||||
|
||||
public void sendInadmissibilityEmailForRejectedApplication(ApplicationEntity applicationEntity,ApplicationEvaluationEntity applicationEvaluationEntity) {
|
||||
@@ -156,14 +175,14 @@ public class EmailNotificationDao {
|
||||
bodyPlaceholders.put("{{protocol_time}}", DateTimeUtil.parseLocalTimeToString(applicationEntity.getProtocol().getTime(), GepafinConstant.HH_MM_SS));
|
||||
bodyPlaceholders.put("{{form_text}}", applicationEvaluationEntity.getNote());
|
||||
|
||||
sendEmail(applicationEntity, SystemEmailTemplatesEntity.SystemEmailTemplatesEntityTypeEnum.INADMISSIBILITY_TEMPLATE, bodyPlaceholders, null);
|
||||
sendEmail(applicationEntity, SystemEmailTemplatesEntity.SystemEmailTemplatesEntityTypeEnum.INADMISSIBILITY_TEMPLATE, bodyPlaceholders, null,null);
|
||||
}
|
||||
|
||||
public void sendMail(Long hubId, String subject, String body, List<String> recipientEmails) {
|
||||
public void sendMail(Long hubId, String subject, String body, List<String> recipientEmails, EmailLogRequest emailLogRequest) {
|
||||
|
||||
EmailConfig emailConfig = retrieveEmailConfig(hubId);
|
||||
EmailService emailService = emailServiceFactory.getEmailService(emailConfig.getEmailServiceType());
|
||||
emailService.sendEmail(subject, body, recipientEmails, emailConfig);
|
||||
emailService.sendEmail(subject, body, recipientEmails, emailConfig,emailLogRequest);
|
||||
}
|
||||
|
||||
public EmailConfig retrieveEmailConfig(Long hubId) {
|
||||
|
||||
@@ -4,6 +4,7 @@ import java.util.HashMap;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
|
||||
import net.gepafin.tendermanagement.enums.EmailScenarioTypeEnum;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
@@ -78,6 +79,7 @@ public class SystemEmailTemplatesDao {
|
||||
systemEmailTemplateResponse.setHtmlContent(htmlContent);
|
||||
systemEmailTemplateResponse.setSubject(subject);
|
||||
systemEmailTemplateResponse.setJsonMap(languageMap);
|
||||
systemEmailTemplateResponse.setEmailScenario(EmailScenarioTypeEnum.valueOf(dbSystemEmailTemplatesEntity.getEmailScenario()));
|
||||
return systemEmailTemplateResponse;
|
||||
}
|
||||
|
||||
|
||||
@@ -29,6 +29,9 @@ public class ApplicationEvaluationEntity extends BaseEntity{
|
||||
@Column(name = "status")
|
||||
private String status;
|
||||
|
||||
@Column(name = "MOTIVATION")
|
||||
private String motivation;
|
||||
|
||||
@Column(name="IS_DELETED")
|
||||
private Boolean isDeleted;
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -0,0 +1,60 @@
|
||||
package net.gepafin.tendermanagement.entities;
|
||||
import jakarta.persistence.*;
|
||||
import lombok.Data;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
@Entity
|
||||
@Data
|
||||
@Table(name = "email_log")
|
||||
public class EmailLogEntity extends BaseEntity{
|
||||
|
||||
@Column(name = "email_type", nullable = false, length = 255)
|
||||
private String emailType;
|
||||
|
||||
@Column(name = "recipient_type", nullable = false, columnDefinition = "TEXT")
|
||||
private String recipientType;
|
||||
|
||||
@Column(name = "recipient_id", nullable = false)
|
||||
private Long recipientId;
|
||||
|
||||
@Column(name = "email_subject", columnDefinition = "TEXT")
|
||||
private String emailSubject;
|
||||
|
||||
@Column(name = "email_body", columnDefinition = "TEXT")
|
||||
private String emailBody;
|
||||
|
||||
@Column(name = "send_status", length = 255)
|
||||
private String sendStatus;
|
||||
|
||||
@Column(name = "send_date_time")
|
||||
private LocalDateTime sendDateTime;
|
||||
|
||||
@Column(name = "error_message", columnDefinition = "TEXT")
|
||||
private String errorMessage;
|
||||
|
||||
@Column(name = "email_service_response")
|
||||
private String emailServiceResponse;
|
||||
|
||||
@Column(name = "email_service_type")
|
||||
private String emailServiceType;
|
||||
|
||||
@Column(name = "recipient_emails")
|
||||
private String recipientEmails;
|
||||
|
||||
@Column(name = "user_id")
|
||||
private Long userId;
|
||||
|
||||
@Column(name = "application_id")
|
||||
private Long applicationId;
|
||||
|
||||
@Column(name = "amendment_id")
|
||||
private Long amendmentId;
|
||||
|
||||
@Column(name = "call_id")
|
||||
private Long callId;
|
||||
|
||||
@Column(name = "is_deleted")
|
||||
private Boolean isDeleted;
|
||||
}
|
||||
|
||||
@@ -36,6 +36,9 @@ public class SystemEmailTemplatesEntity extends BaseEntity {
|
||||
@Column(name ="IS_DELETED", nullable = false)
|
||||
private Boolean isDeleted = false;
|
||||
|
||||
@Column(name = "email_scenario")
|
||||
private String emailScenario;
|
||||
|
||||
public enum SystemEmailTemplatesEntityTypeEnum {
|
||||
|
||||
APPLICATION_SUBMISSION_TO_USER_AND_COMPANY("APPLICATION_SUBMISSION_TO_USER_AND_COMPANY"),
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
package net.gepafin.tendermanagement.enums;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonValue;
|
||||
|
||||
public enum EmailEntityTypeEnum {
|
||||
|
||||
AMENDMENT("AMENDMENT"),
|
||||
APPLICATION("APPLICATION");
|
||||
|
||||
private String value;
|
||||
|
||||
EmailEntityTypeEnum(String value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
@JsonValue
|
||||
public String getValue() {
|
||||
return value;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package net.gepafin.tendermanagement.enums;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonValue;
|
||||
|
||||
public enum EmailScenarioTypeEnum {
|
||||
|
||||
APPLICATION_SUBMITTED("APPLICATION_SUBMITTED"),
|
||||
APPLICATION_AMENDMENT_REQUESTED("APPLICATION_AMENDMENT_REQUESTED"),
|
||||
APPLICATION_AMENDMENT_EXPIRED("APPLICATION_AMENDMENT_EXPIRED"),
|
||||
APPLICATION_AMENDMENT_REMINDER("APPLICATION_AMENDMENT_REMINDER"),
|
||||
APPLICATION_APPROVED("APPLICATION_APPROVED"),
|
||||
APPLICATION_REJECTED("APPLICATION_REJECTED");
|
||||
|
||||
private final String value;
|
||||
|
||||
EmailScenarioTypeEnum(String value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
@JsonValue
|
||||
public String getValue() {
|
||||
return value;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package net.gepafin.tendermanagement.enums;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonValue;
|
||||
|
||||
public enum EmailServiceTypeEnum {
|
||||
|
||||
MAILGUN_SERVICE("MAILGUN_SERVICE"),
|
||||
PEC_SERVICE("PEC_SERVICE");
|
||||
|
||||
private String value;
|
||||
|
||||
EmailServiceTypeEnum(String value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
@JsonValue
|
||||
public String getValue() {
|
||||
return value;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package net.gepafin.tendermanagement.enums;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonValue;
|
||||
|
||||
public enum RecipientTypeEnum {
|
||||
|
||||
BENEFICIARY ("BENEFICIARY"),
|
||||
USER("USER"),
|
||||
COMPANY("COMPANY"),
|
||||
PROPERTIES("PROPERTIES");
|
||||
|
||||
private String value;
|
||||
|
||||
RecipientTypeEnum(String value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
@JsonValue
|
||||
public String getValue() {
|
||||
return value;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package net.gepafin.tendermanagement.enums;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonValue;
|
||||
|
||||
public enum StatusTypeEnum {
|
||||
|
||||
SUCCESS ("SUCCESS"),
|
||||
FAILED("FAILED");
|
||||
|
||||
private String value;
|
||||
|
||||
StatusTypeEnum(String value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
@JsonValue
|
||||
public String getValue() {
|
||||
return value;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
package net.gepafin.tendermanagement.model.request;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonValue;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class AmendmentFormField {
|
||||
|
||||
private String fieldId;
|
||||
|
||||
private String fieldValue;
|
||||
|
||||
private String isUploadedBy;
|
||||
|
||||
|
||||
public enum AmendmentIsUploadedByEnum {
|
||||
PRE_INSTRUCTOR("PRE_INSTRUCTOR"),
|
||||
BENEFICIARY("BENEFICIARY");
|
||||
|
||||
private String value;
|
||||
|
||||
AmendmentIsUploadedByEnum(String value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
@JsonValue
|
||||
public String getValue() {
|
||||
return value;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,9 +1,11 @@
|
||||
package net.gepafin.tendermanagement.model.request;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class ApplicationAmendmentRequestBean {
|
||||
private String note;
|
||||
private ApplicationFormFieldRequestBean applicationFormFields;
|
||||
private List<ApplicationFormFieldRequestBean> applicationFormFields;
|
||||
}
|
||||
|
||||
@@ -12,4 +12,5 @@ public class ApplicationEvaluationRequest {
|
||||
private List<FieldRequest> files;
|
||||
private String note;
|
||||
private ApplicationStatusForEvaluation applicationStatus;
|
||||
private String motivation;
|
||||
}
|
||||
|
||||
@@ -13,6 +13,7 @@ public class EmailConfig {
|
||||
private String domain;
|
||||
private String mailgunApiUrl;
|
||||
private String pecApiUrl;
|
||||
private String url;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
package net.gepafin.tendermanagement.model.request;
|
||||
|
||||
import lombok.Data;
|
||||
import net.gepafin.tendermanagement.enums.EmailScenarioTypeEnum;
|
||||
import net.gepafin.tendermanagement.enums.EmailEntityTypeEnum;
|
||||
import net.gepafin.tendermanagement.enums.EmailServiceTypeEnum;
|
||||
import net.gepafin.tendermanagement.enums.RecipientTypeEnum;
|
||||
|
||||
@Data
|
||||
public class EmailLogRequest {
|
||||
|
||||
private EmailScenarioTypeEnum emailType;
|
||||
|
||||
private RecipientTypeEnum recipientType;
|
||||
|
||||
private Long recipientId;
|
||||
|
||||
private String emailSubject;
|
||||
|
||||
private String emailBody;
|
||||
|
||||
private String sendStatus;
|
||||
|
||||
private String errorMessage;
|
||||
|
||||
private Long userId;
|
||||
|
||||
private String emailServiceResponse;
|
||||
|
||||
private EmailServiceTypeEnum emailServiceType;
|
||||
|
||||
private String recipientEmails;
|
||||
|
||||
private Long applicatioId;
|
||||
|
||||
private Long amendmentId;
|
||||
|
||||
private Long callId;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package net.gepafin.tendermanagement.model.request;
|
||||
|
||||
import lombok.Data;
|
||||
import net.gepafin.tendermanagement.entities.EmailLogEntity;
|
||||
|
||||
@Data
|
||||
public class EmailTrackingRequest {
|
||||
|
||||
private EmailLogEntity emailLogEntity;
|
||||
|
||||
private Long userId;
|
||||
|
||||
private Long entityId;
|
||||
|
||||
private String entityType;
|
||||
}
|
||||
@@ -26,6 +26,7 @@ public class ApplicationEvaluationResponse {
|
||||
private String beneficiary;
|
||||
private Long protocolNumber;
|
||||
private String callName;
|
||||
private String motivation;
|
||||
private LocalDateTime submissionDate;
|
||||
private LocalDateTime evaluationDate;
|
||||
private LocalDateTime callEndDate;
|
||||
|
||||
@@ -20,6 +20,7 @@ public class AssignedApplicationsResponse extends BaseBean {
|
||||
private LocalDateTime submissionDate;
|
||||
private LocalDateTime callStartDate;
|
||||
private LocalDateTime callEndDate;
|
||||
private String companyName;
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -27,6 +31,18 @@ public class CommunicationResponseBean {
|
||||
this.amendmentId = amendmentId;
|
||||
}
|
||||
|
||||
public CommunicationResponseBean(LocalDateTime commentedDate, String comment, String title, LocalDateTime createdDate, LocalDateTime updatedDate, Long amendmentId,Long senderUserId,Long receiverUserId) {
|
||||
|
||||
this.commentedDate = commentedDate;
|
||||
this.comment = comment;
|
||||
this.title = title;
|
||||
this.createdDate = createdDate;
|
||||
this.updatedDate = updatedDate;
|
||||
this.amendmentId = amendmentId;
|
||||
this.senderUserId = senderUserId;
|
||||
this.receiverUserId = receiverUserId;
|
||||
}
|
||||
|
||||
public CommunicationResponseBean() {
|
||||
|
||||
}
|
||||
|
||||
@@ -3,10 +3,13 @@ package net.gepafin.tendermanagement.model.response;
|
||||
import java.util.Map;
|
||||
|
||||
import lombok.Data;
|
||||
import net.gepafin.tendermanagement.enums.EmailScenarioTypeEnum;
|
||||
|
||||
@Data
|
||||
public class SystemEmailTemplateResponse {
|
||||
|
||||
EmailScenarioTypeEnum emailScenario;
|
||||
|
||||
String htmlContent;
|
||||
|
||||
String subject;
|
||||
|
||||
@@ -38,4 +38,6 @@ public interface ApplicationFormFieldRepository extends JpaRepository<Applicatio
|
||||
public ApplicationFormFieldEntity findByFieldId(String FieldId);
|
||||
|
||||
Optional<ApplicationFormFieldEntity> findByApplicationFormIdAndFieldId(Long id, String fieldId);
|
||||
|
||||
public List<ApplicationFormFieldEntity> findByApplicationFormIdAndFieldIdIn(Long id, List<String> fieldIds);
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@ public interface BeneficiaryPreferredCallRepository extends JpaRepository<Benefi
|
||||
List<BeneficiaryPreferredCallEntity> findByBeneficiaryIdAndIsDeletedFalse(Long beneficiaryId);
|
||||
List<BeneficiaryPreferredCallEntity> findByUserIdAndIsDeletedFalse(Long userId);
|
||||
|
||||
@Query("SELECT preferredCall FROM BeneficiaryPreferredCallEntity preferredCall where preferredCall.userId=:userId AND (:companyId is null OR preferredCall.companyId=:companyId)")
|
||||
@Query("SELECT preferredCall FROM BeneficiaryPreferredCallEntity preferredCall where preferredCall.userId=:userId AND (:companyId is null OR preferredCall.companyId=:companyId) AND isDeleted=false")
|
||||
List<BeneficiaryPreferredCallEntity> findByUserIdAndCompanyIdAndIsDeletedFalse(@Param("userId") Long userId, @Param("companyId") Long companyId);
|
||||
List<BeneficiaryPreferredCallEntity> findByBeneficiaryIdAndCompanyId(Long beneficiaryId,Long companyId);
|
||||
List<BeneficiaryPreferredCallEntity> findByUserIdAndCallIdInAndIsDeletedFalse(Long userId, List<Long> callIds);
|
||||
|
||||
@@ -45,4 +45,6 @@ public interface CallRepository extends JpaRepository<CallEntity, Long> {
|
||||
|
||||
@Query("SELECT COALESCE(SUM(c.amount), 0) FROM CallEntity c WHERE c.status = 'PUBLISH' And c.hub.id = :hubId")
|
||||
BigDecimal findTotalAmountOfPublishedCallsAndHubId(@Param("hubId") Long hubId);
|
||||
@Query("SELECT c FROM CallEntity c WHERE c.id IN :ids AND c.status IN :status")
|
||||
List<CallEntity> findByIdInAndStatusIn(@Param("ids") List<Long> ids, @Param("status") List<String> status);
|
||||
}
|
||||
|
||||
@@ -15,7 +15,8 @@ public interface CommunicationRepository extends JpaRepository<CommunicationEnti
|
||||
List<CommunicationResponseBean> findCommentsByApplicationAmendmentRequestId(@Param("applicationAmendmentRequestId") Long amendmentRequestId);
|
||||
|
||||
@Query("SELECT new net.gepafin.tendermanagement.model.response.CommunicationResponseBean( " + "c.commentedDate, c.communicationComment, c.communicationTitle, c.createdDate, c" +
|
||||
".updatedDate, c.applicationAmendmentRequest.id) " + "FROM CommunicationEntity c " + "WHERE c.applicationAmendmentRequest.id = :amendmentId AND c.isDeleted = false")
|
||||
List<CommunicationResponseBean> findCommentDetailsByAmendmentId(@Param("amendmentId") Long amendmentId);
|
||||
".updatedDate, c.applicationAmendmentRequest.id,c.senderUserId, c.receiverUserId) " + "FROM CommunicationEntity c " + "WHERE c.applicationAmendmentRequest.id = :amendmentId AND c.isDeleted = false")
|
||||
List<CommunicationResponseBean> findCommentListDetailsByAmendmentId(@Param("amendmentId") Long amendmentId);
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
package net.gepafin.tendermanagement.repositories;
|
||||
|
||||
import net.gepafin.tendermanagement.entities.EmailLogEntity;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface EmailLogRepository extends JpaRepository<EmailLogEntity,Long> {
|
||||
|
||||
List<EmailLogEntity> findByUserIdAndAmendmentIdAndIsDeletedFalse(Long userId,Long amendmentId);
|
||||
}
|
||||
@@ -4,6 +4,8 @@ import net.gepafin.tendermanagement.dao.EmailNotificationDao;
|
||||
import net.gepafin.tendermanagement.entities.ApplicationAmendmentRequestEntity;
|
||||
import net.gepafin.tendermanagement.entities.ApplicationEntity;
|
||||
import net.gepafin.tendermanagement.entities.UserEntity;
|
||||
import net.gepafin.tendermanagement.enums.ApplicationAmendmentRequestEnum;
|
||||
import net.gepafin.tendermanagement.enums.ApplicationStatusTypeEnum;
|
||||
import net.gepafin.tendermanagement.repositories.ApplicationAmendmentRequestRepository;
|
||||
import net.gepafin.tendermanagement.repositories.ApplicationRepository;
|
||||
import net.gepafin.tendermanagement.repositories.UserRepository;
|
||||
@@ -41,12 +43,12 @@ public class NotificationScheduler {
|
||||
ApplicationAmendmentRequestEntity amendmentRequest = getAmendmentRequestForApplication(application, amendmentRequestList);
|
||||
|
||||
if (amendmentRequest != null) {
|
||||
LocalDateTime requestDate = amendmentRequest.getCreatedDate();
|
||||
if (requestDate.plusDays(amendmentRequest.getResponseDays()).isAfter(today)) {
|
||||
LocalDateTime requestDate = amendmentRequest.getStartDate();
|
||||
if (requestDate.plusDays(amendmentRequest.getResponseDays()).isBefore(today)) {
|
||||
// Update the application status to REJECTED
|
||||
application.setStatus("REJECTED");
|
||||
application.setStatus(ApplicationStatusTypeEnum.REJECTED.getValue());
|
||||
applicationRepository.save(application);
|
||||
amendmentRequest.setStatus("CLOSE");
|
||||
amendmentRequest.setStatus(ApplicationAmendmentRequestEnum.CLOSE.getValue());
|
||||
applicationAmendmentRepository.save(amendmentRequest);
|
||||
emailNotificationDao.sendApplicationFailureNotificationEmail(amendmentRequest);
|
||||
}
|
||||
@@ -56,6 +58,6 @@ public class NotificationScheduler {
|
||||
|
||||
private ApplicationAmendmentRequestEntity getAmendmentRequestForApplication(ApplicationEntity application, List<ApplicationAmendmentRequestEntity> amendmentRequestList) {
|
||||
|
||||
return amendmentRequestList.stream().filter(request -> request.getId().equals(application.getId())).findFirst().orElse(null);
|
||||
return amendmentRequestList.stream().filter(request -> request.getApplicationId().equals(application.getId())).findFirst().orElse(null);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@ public interface CallService {
|
||||
|
||||
CallResponse getCallById (HttpServletRequest request, Long callId,Long companyId);
|
||||
|
||||
List<CallDetailsResponseBean> getAllCalls(HttpServletRequest request,Long companyId);
|
||||
List<CallDetailsResponseBean> getAllCalls(HttpServletRequest request,Long companyId,Boolean onlyPreferredCall);
|
||||
|
||||
CallResponse validateCallData(HttpServletRequest request, Long callId);
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -1,24 +0,0 @@
|
||||
package net.gepafin.tendermanagement.service.feignClient;
|
||||
|
||||
import org.springframework.cloud.openfeign.FeignClient;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestHeader;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@FeignClient(name = "mailgunClient", url = "${mailGun_base_url}")
|
||||
public interface MailgunFeignClient {
|
||||
@PostMapping("/v3/{domain}/messages")
|
||||
ResponseEntity<Void> sendEmail(
|
||||
@PathVariable("domain") String domain,
|
||||
@RequestParam("from") String from,
|
||||
@RequestParam("to") List<String> to,
|
||||
@RequestParam("subject") String subject,
|
||||
@RequestParam("html") String htmlBody,
|
||||
@RequestHeader("Authorization") String authorizationHeader);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,17 +0,0 @@
|
||||
package net.gepafin.tendermanagement.service.feignClient;
|
||||
|
||||
import feign.Headers;
|
||||
import net.gepafin.tendermanagement.model.request.PecEmailRequest;
|
||||
import org.springframework.cloud.openfeign.FeignClient;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestHeader;
|
||||
|
||||
@FeignClient(name = "pecClient", url = "${api.pecUrl}")
|
||||
public interface PecFeignClient {
|
||||
@PostMapping("/send")
|
||||
ResponseEntity<Void> sendEmail(@RequestHeader("Authorization") String token,
|
||||
@RequestBody PecEmailRequest emailRequest);
|
||||
}
|
||||
|
||||
@@ -87,13 +87,12 @@ public class ApplicationAmendmentRequestServiceImpl implements ApplicationAmendm
|
||||
|
||||
@Override
|
||||
public ApplicationAmendmentRequestResponse updateApplicationAmendment(HttpServletRequest request, Long id, ApplicationAmendmentRequestBean applicationAmendmentRequestBean) {
|
||||
ApplicationAmendmentRequestEntity amendment = applicationAmendmentRequestRepository.findByIdAndIsDeletedFalse(id)
|
||||
.orElseThrow(() -> new ResourceNotFoundException(Status.NOT_FOUND,
|
||||
Translator.toLocale(GepafinConstant.APPLICATION_AMENDMENT_NOT_FOUND_MSG)));
|
||||
ApplicationAmendmentRequestEntity amendment = applicationAmendmentRequestDao.validateApplicationAmendmentRequest(id);
|
||||
|
||||
Optional<ApplicationEvaluationEntity> entityOptional = applicationEvaluationRepository.findByIdAndIsDeletedFalse(amendment.getApplicationEvaluationEntity().getId());
|
||||
if (entityOptional.isPresent()) {
|
||||
UserEntity user = validator.validatePreInstructor(request, entityOptional.get().getUserId());
|
||||
if (Boolean.FALSE.equals(validator.checkIsBeneficiary())) {
|
||||
validator.validatePreInstructor(request, amendment.getApplicationEvaluationEntity().getUserId());
|
||||
} else {
|
||||
validator.validateUserId(request, amendment.getApplicationEvaluationEntity().getAssignedApplicationsEntity().getApplication().getUserId());
|
||||
}
|
||||
return applicationAmendmentRequestDao.updateApplicationAmendment(id,applicationAmendmentRequestBean);
|
||||
}
|
||||
@@ -105,9 +104,9 @@ public class ApplicationAmendmentRequestServiceImpl implements ApplicationAmendm
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ApplicationAmendmentRequestResponse> getAllAmendmentRequestByBeneficiaryId(HttpServletRequest request, Long beneficiaryId) {
|
||||
public List<ApplicationAmendmentRequestResponse> getAllAmendmentRequestByBeneficiaryId(HttpServletRequest request, Long beneficiaryUserId) {
|
||||
UserEntity user= validator.validateUser(request);
|
||||
return applicationAmendmentRequestDao.getAllAmendmentRequestByBeneficiaryId(beneficiaryId);
|
||||
return applicationAmendmentRequestDao.getAllAmendmentRequestByBeneficiaryId(beneficiaryUserId);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
package net.gepafin.tendermanagement.service.impl;
|
||||
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import net.gepafin.tendermanagement.config.Translator;
|
||||
import net.gepafin.tendermanagement.constants.GepafinConstant;
|
||||
import net.gepafin.tendermanagement.dao.ApplicationDao;
|
||||
import net.gepafin.tendermanagement.dao.FlowFormDao;
|
||||
import net.gepafin.tendermanagement.entities.ApplicationEntity;
|
||||
@@ -17,6 +19,8 @@ import net.gepafin.tendermanagement.model.response.ApplicationSignedDocumentResp
|
||||
import net.gepafin.tendermanagement.model.response.NextOrPreviousFormResponse;
|
||||
import net.gepafin.tendermanagement.service.ApplicationService;
|
||||
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.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
@@ -64,6 +68,9 @@ public class ApplicationServiceImpl implements ApplicationService {
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public ApplicationResponse createApplication(HttpServletRequest request, Long companyId, ApplicationRequest applicationRequest, Long callId) {
|
||||
UserEntity userEntity = validator.validateUser(request);
|
||||
if(companyId==null){
|
||||
throw new CustomValidationException(Status.VALIDATION_ERROR, Translator.toLocale(GepafinConstant.USER_MUST_BE_ASSOCIATED_WITH_COMPANY));
|
||||
}
|
||||
CompanyEntity companyEntity = validator.validateUserWithCompany(request, companyId);
|
||||
validator.validateUserWithCall(userEntity, callId);
|
||||
return applicationDao.createApplicationByCallId(companyEntity, applicationRequest, callId, userEntity);
|
||||
|
||||
@@ -62,9 +62,9 @@ public class CallServiceImpl implements CallService {
|
||||
|
||||
@Override
|
||||
@Transactional(readOnly = true)
|
||||
public List<CallDetailsResponseBean> getAllCalls(HttpServletRequest request,Long companyId) {
|
||||
public List<CallDetailsResponseBean> getAllCalls(HttpServletRequest request,Long companyId,Boolean onlyPreferredCall) {
|
||||
UserEntity user = validator.validateUser(request);
|
||||
return callDao.getAllCalls(request,user,companyId);
|
||||
return callDao.getAllCalls(request,user,companyId,onlyPreferredCall);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
package net.gepafin.tendermanagement.service.impl;
|
||||
|
||||
import net.gepafin.tendermanagement.model.request.EmailConfig;
|
||||
import net.gepafin.tendermanagement.model.request.EmailLogRequest;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface EmailService {
|
||||
void sendEmail(String subject, String body, List<String> recipientEmails, EmailConfig emailConfig);
|
||||
void sendEmail(String subject, String body, List<String> recipientEmails, EmailConfig emailConfig, EmailLogRequest emailLogRequest);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,12 +1,18 @@
|
||||
package net.gepafin.tendermanagement.service.impl;
|
||||
|
||||
import com.mashape.unirest.http.HttpResponse;
|
||||
import com.mashape.unirest.http.Unirest;
|
||||
import net.gepafin.tendermanagement.dao.EmailLogDao;
|
||||
import net.gepafin.tendermanagement.entities.EmailLogEntity;
|
||||
import net.gepafin.tendermanagement.enums.EmailServiceTypeEnum;
|
||||
import net.gepafin.tendermanagement.enums.StatusTypeEnum;
|
||||
import net.gepafin.tendermanagement.model.request.EmailConfig;
|
||||
import net.gepafin.tendermanagement.service.feignClient.MailgunFeignClient;
|
||||
import net.gepafin.tendermanagement.model.request.EmailLogRequest;
|
||||
import net.gepafin.tendermanagement.util.Utils;
|
||||
import net.gepafin.tendermanagement.util.Validator;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.Base64;
|
||||
@@ -15,34 +21,56 @@ import java.util.List;
|
||||
@Service
|
||||
public class MailgunEmailService implements EmailService {
|
||||
|
||||
@Autowired
|
||||
private MailgunFeignClient mailgunFeignClient;
|
||||
|
||||
@Value("${isMailSendingEnabled}")
|
||||
private String isEmailSendingEnabled;
|
||||
|
||||
@Autowired
|
||||
private Validator validator;
|
||||
|
||||
@Autowired
|
||||
private EmailLogDao emailLogDao;
|
||||
|
||||
@Override
|
||||
public void sendEmail(String subject, String body, List<String> recipientEmails, EmailConfig emailConfig) {
|
||||
public void sendEmail(String subject, String body, List<String> recipientEmails, EmailConfig emailConfig, EmailLogRequest emailLogRequest) {
|
||||
|
||||
if (Boolean.FALSE.equals(Boolean.parseBoolean(isEmailSendingEnabled))) {
|
||||
return;
|
||||
}
|
||||
|
||||
String domain = emailConfig.getDomain();
|
||||
String url = emailConfig.getUrl();
|
||||
String from = emailConfig.getSender();
|
||||
String apiKey = emailConfig.getApiKey();
|
||||
String authHeader = "Basic " + Base64.getEncoder().encodeToString(("api:" + apiKey).getBytes());
|
||||
|
||||
// Send email via Mailgun API
|
||||
HttpResponse<String> response2=null;
|
||||
if (Boolean.FALSE.equals(validator.isTestProfileActivated())) {
|
||||
ResponseEntity<Void> response = mailgunFeignClient.sendEmail(domain, from, recipientEmails, subject, body, authHeader);
|
||||
if (!response.getStatusCode().is2xxSuccessful()) {
|
||||
throw new RuntimeException("Failed to send email via Mailgun: " + response.getStatusCode());
|
||||
emailLogRequest.setEmailSubject(subject);
|
||||
emailLogRequest.setEmailBody(body);
|
||||
emailLogRequest.setSendStatus(StatusTypeEnum.SUCCESS.getValue());
|
||||
emailLogRequest.setRecipientEmails(Utils.listToCommaSeparatedString(recipientEmails));
|
||||
try {
|
||||
Unirest.setTimeouts(0, 0);
|
||||
response2 = Unirest.post(url)
|
||||
.header("Authorization", authHeader)
|
||||
// .header("content-type", "multipart/form-data")
|
||||
.field("from", from)
|
||||
.field("to", recipientEmails)
|
||||
.field("subject", subject)
|
||||
.field("html", body)
|
||||
.asString();
|
||||
}catch(Exception e) {
|
||||
emailLogRequest.setSendStatus(StatusTypeEnum.FAILED.getValue());
|
||||
emailLogRequest.setEmailServiceType(EmailServiceTypeEnum.MAILGUN_SERVICE);
|
||||
emailLogRequest.setErrorMessage(e.getMessage());
|
||||
EmailLogEntity emailLogEntity= emailLogDao.createEmailLog(emailLogRequest);
|
||||
throw new RuntimeException("Failed to send email via Mailgun: " + response2.getStatus());
|
||||
}
|
||||
emailLogRequest.setEmailServiceResponse(response2.getBody());
|
||||
}
|
||||
emailLogRequest.setEmailServiceType(EmailServiceTypeEnum.MAILGUN_SERVICE);
|
||||
EmailLogEntity emailLogEntity= emailLogDao.createEmailLog(emailLogRequest);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,14 +1,20 @@
|
||||
package net.gepafin.tendermanagement.service.impl;
|
||||
|
||||
import com.mashape.unirest.http.HttpResponse;
|
||||
import com.mashape.unirest.http.Unirest;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import net.gepafin.tendermanagement.dao.EmailLogDao;
|
||||
import net.gepafin.tendermanagement.entities.EmailLogEntity;
|
||||
import net.gepafin.tendermanagement.enums.EmailServiceTypeEnum;
|
||||
import net.gepafin.tendermanagement.enums.StatusTypeEnum;
|
||||
import net.gepafin.tendermanagement.model.request.EmailConfig;
|
||||
import net.gepafin.tendermanagement.model.request.EmailLogRequest;
|
||||
import net.gepafin.tendermanagement.model.request.PecEmailRequest;
|
||||
import net.gepafin.tendermanagement.service.feignClient.PecFeignClient;
|
||||
import net.gepafin.tendermanagement.util.Utils;
|
||||
import net.gepafin.tendermanagement.util.Validator;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
@@ -16,12 +22,6 @@ import java.util.List;
|
||||
@Slf4j
|
||||
@Service
|
||||
public class PecEmailService implements EmailService {
|
||||
private final PecFeignClient pecFeignClient;
|
||||
|
||||
public PecEmailService(PecFeignClient pecFeignClient) {
|
||||
|
||||
this.pecFeignClient = pecFeignClient;
|
||||
}
|
||||
|
||||
@Value("${isMailSendingEnabled}")
|
||||
private String isEmailSendingEnabled;
|
||||
@@ -29,8 +29,11 @@ public class PecEmailService implements EmailService {
|
||||
@Autowired
|
||||
private Validator validator;
|
||||
|
||||
@Autowired
|
||||
private EmailLogDao emailLogDao;
|
||||
|
||||
@Override
|
||||
public void sendEmail(String subject, String body, List<String> recipientEmails, EmailConfig emailConfig) {
|
||||
public void sendEmail(String subject, String body, List<String> recipientEmails, EmailConfig emailConfig, EmailLogRequest emailLogRequest) {
|
||||
|
||||
if (Boolean.FALSE.equals(Boolean.parseBoolean(isEmailSendingEnabled))) {
|
||||
return;
|
||||
@@ -38,20 +41,37 @@ public class PecEmailService implements EmailService {
|
||||
|
||||
PecEmailRequest emailRequest = new PecEmailRequest();
|
||||
emailRequest.setSender(emailConfig.getSender());
|
||||
emailRequest.setRecipient(recipientEmails);
|
||||
emailRequest.setSubject(subject);
|
||||
emailRequest.setBody(body);
|
||||
emailRequest.setUsername(emailConfig.getUsername());
|
||||
emailRequest.setPassword(emailConfig.getPassword());
|
||||
|
||||
emailRequest.setRecipient(recipientEmails);
|
||||
String url=emailConfig.getUrl();
|
||||
String authToken = emailConfig.getAuthToken();
|
||||
HttpResponse<String> response2=null;
|
||||
if (Boolean.FALSE.equals(validator.isTestProfileActivated())) {
|
||||
ResponseEntity<Void> response = pecFeignClient.sendEmail("Bearer " + authToken, emailRequest);
|
||||
log.info("Mail response status: {}, headers: {}, body: {}", response.getStatusCode(), response.getHeaders(), response.getBody());
|
||||
if (!response.getStatusCode().is2xxSuccessful()) {
|
||||
throw new RuntimeException("Failed to send email via PEC: " + response.getStatusCode());
|
||||
emailLogRequest.setEmailSubject(emailRequest.getSubject());
|
||||
emailLogRequest.setEmailBody(emailRequest.getBody());
|
||||
emailLogRequest.setSendStatus(StatusTypeEnum.SUCCESS.getValue());
|
||||
emailLogRequest.setRecipientEmails(Utils.listToCommaSeparatedString(emailRequest.getRecipient()));
|
||||
try {
|
||||
Unirest.setTimeouts(0, 0);
|
||||
response2 = Unirest.post(url)
|
||||
.header("Authorization", "Bearer " + authToken)
|
||||
.header("Content-Type", "application/json")
|
||||
.body(Utils.convertObjectToJson(emailRequest)) // Serialize the emailRequest object to JSON
|
||||
.asString();
|
||||
}catch(Exception e) {
|
||||
emailLogRequest.setSendStatus(StatusTypeEnum.FAILED.getValue());
|
||||
emailLogRequest.setEmailServiceType(EmailServiceTypeEnum.PEC_SERVICE);
|
||||
emailLogRequest.setErrorMessage(e.getMessage());
|
||||
EmailLogEntity emailLogEntity= emailLogDao.createEmailLog(emailLogRequest);
|
||||
throw new RuntimeException("Failed to send email via PEC: " + response2.getStatus());
|
||||
}
|
||||
emailLogRequest.setEmailServiceResponse(response2.getBody());
|
||||
}
|
||||
emailLogRequest.setEmailServiceType(EmailServiceTypeEnum.PEC_SERVICE);
|
||||
EmailLogEntity emailLogEntity= emailLogDao.createEmailLog(emailLogRequest);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -24,6 +24,7 @@ import net.gepafin.tendermanagement.constants.GepafinConstant;
|
||||
import org.apache.commons.collections4.MapUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.HttpStatus;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
@@ -40,6 +41,7 @@ import net.gepafin.tendermanagement.web.rest.api.errors.FeignClientForbiddenExce
|
||||
import net.gepafin.tendermanagement.web.rest.api.errors.FeignClientNotFoundException;
|
||||
import net.gepafin.tendermanagement.web.rest.api.errors.FeignClientUnauthorizedException;
|
||||
import net.gepafin.tendermanagement.web.rest.api.errors.FeignClientValidationException;
|
||||
import org.springframework.http.MediaType;
|
||||
|
||||
import javax.crypto.Cipher;
|
||||
import javax.crypto.spec.IvParameterSpec;
|
||||
@@ -515,4 +517,7 @@ public class Utils {
|
||||
}
|
||||
return null;
|
||||
}
|
||||
public static <T> String listToCommaSeparatedString(List<T> list) {
|
||||
return String.join(", ", list.stream().map(String::valueOf).toList());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -115,7 +115,7 @@ public interface ApplicationAmendmentRequestApi {
|
||||
@ExampleObject(value = ErrorConstants.BADREQUEST_ERROR_EXAMPLE) })) })
|
||||
@GetMapping(value = "/beneficiary/user/{id}", produces = "application/json")
|
||||
ResponseEntity<Response<List<ApplicationAmendmentRequestResponse>>> getAllAmendmentRequestByBeneficiaryId(HttpServletRequest request,
|
||||
@Parameter(description = "Id", required = false) @PathVariable(value = "id",required = false) Long beneficiaryId);
|
||||
@Parameter(description = "Id", required = false) @PathVariable(value = "id",required = false) Long beneficiaryUserId);
|
||||
@Operation(summary = "Api to extend response days for an amendment request",
|
||||
responses = {
|
||||
@ApiResponse(responseCode = "200", description = "OK"),
|
||||
|
||||
@@ -99,7 +99,7 @@ public interface ApplicationApi {
|
||||
@PostMapping(value = "/call/{callId}",
|
||||
produces = { "application/json" })
|
||||
ResponseEntity<Response<ApplicationResponse>> createApplicationByCallId(HttpServletRequest request,
|
||||
@Parameter(description = "The company ID", required = true) @RequestParam(value = "companyId", required = true) Long companyId,
|
||||
@Parameter(description = "The company ID") @RequestParam(value = "companyId", required = false) Long companyId,
|
||||
@Parameter(description = " Flow request object", required = true) @Valid @RequestBody ApplicationRequest applicationRequest,
|
||||
@Parameter(description = "The call ID", required = true) @PathVariable("callId") Long callId);
|
||||
|
||||
|
||||
@@ -100,7 +100,7 @@ public interface CallApi {
|
||||
@ExampleObject(value = ErrorConstants.BADREQUEST_ERROR_EXAMPLE) })) })
|
||||
@GetMapping(value = "",
|
||||
produces = { "application/json" })
|
||||
ResponseEntity<Response<List<CallDetailsResponseBean>>> getAllCalls(HttpServletRequest request,@RequestParam(value = "companyId", required = false) Long companyId);
|
||||
ResponseEntity<Response<List<CallDetailsResponseBean>>> getAllCalls(HttpServletRequest request,@RequestParam(value = "companyId", required = false) Long companyId , @RequestParam(value = "onlyPreferredCall", required = false, defaultValue = "false") Boolean onlyPreferredCall);
|
||||
|
||||
|
||||
@Operation(summary = "Api to validate call",
|
||||
|
||||
@@ -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<Response<CommunicationResponseBean>> 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<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"),
|
||||
@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<Response<CommunicationResponseBean>> updateCommunicationAmendment(HttpServletRequest request,
|
||||
@RequestBody @Parameter CommunicationRequestBean communicationResponseBean, @PathVariable(value = "amendmentId") Long amendmentId, @PathVariable(value = "commentId") Long commentId);
|
||||
|
||||
|
||||
@@ -76,9 +76,9 @@ public class ApplicationAmendmentRequestController implements ApplicationAmendme
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResponseEntity<Response<List<ApplicationAmendmentRequestResponse>>> getAllAmendmentRequestByBeneficiaryId(HttpServletRequest request, Long beneficiaryId) {
|
||||
public ResponseEntity<Response<List<ApplicationAmendmentRequestResponse>>> getAllAmendmentRequestByBeneficiaryId(HttpServletRequest request, Long beneficiaryUserId) {
|
||||
log.info("Get All Application Amendment Request By Beneficiary ID");
|
||||
List<ApplicationAmendmentRequestResponse> applicationAmendmentRequestResponseList = applicationAmendmentRequestService.getAllAmendmentRequestByBeneficiaryId(request, beneficiaryId);
|
||||
List<ApplicationAmendmentRequestResponse> applicationAmendmentRequestResponseList = applicationAmendmentRequestService.getAllAmendmentRequestByBeneficiaryId(request, beneficiaryUserId);
|
||||
return ResponseEntity.status(HttpStatus.CREATED)
|
||||
.body(new Response<>(applicationAmendmentRequestResponseList, Status.SUCCESS, Translator.toLocale(GepafinConstant.GET_APPLICATION_AMENDMENT_SUCCESS_MSG)));
|
||||
}
|
||||
|
||||
@@ -67,8 +67,8 @@ public class CallApiController implements CallApi {
|
||||
|
||||
@Override
|
||||
@Transactional(readOnly = true)
|
||||
public ResponseEntity<Response<List<CallDetailsResponseBean>>> getAllCalls(HttpServletRequest request,Long companyId) {
|
||||
List<CallDetailsResponseBean> calls = callService.getAllCalls(request,companyId);
|
||||
public ResponseEntity<Response<List<CallDetailsResponseBean>>> getAllCalls(HttpServletRequest request,Long companyId,Boolean onlyPreferredCall) {
|
||||
List<CallDetailsResponseBean> calls = callService.getAllCalls(request,companyId,onlyPreferredCall);
|
||||
|
||||
return ResponseEntity.status(HttpStatus.OK)
|
||||
.body(new Response<>(calls, Status.SUCCESS, Translator.toLocale(GepafinConstant.CALL_FETCH_SUCCESS_MSG)));
|
||||
|
||||
@@ -27,28 +27,28 @@ public class CommunicationController implements CommunicationApi {
|
||||
public ResponseEntity<Response<CommunicationResponseBean>> 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<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)));
|
||||
}
|
||||
@Override
|
||||
public ResponseEntity<Response<CommunicationResponseBean>> 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<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)
|
||||
.body(new Response<>(communicationResponseBean, Status.SUCCESS, Translator.toLocale(GepafinConstant.COMMENT_DELETED_SUCCESS_MSG)));
|
||||
}
|
||||
|
||||
@@ -1720,11 +1720,50 @@
|
||||
<sqlFile dbms="postgresql"
|
||||
path="db/dump/update_system_email_template_for_notification_mail_05_11_2024_4.sql"/>
|
||||
</changeSet>
|
||||
<changeSet id="15-11-2024_1" author="Nisha Kashyap">
|
||||
<createTable tableName="email_log">
|
||||
<column autoIncrement="true" name="id" type="INTEGER">
|
||||
<constraints nullable="false" primaryKey="true"
|
||||
primaryKeyName="pk_email_logs"/>
|
||||
</column>
|
||||
<column name="email_type" type="VARCHAR(255)">
|
||||
<constraints nullable="false"/>
|
||||
</column>
|
||||
<column name="recipient_type" type="VARCHAR(255)">
|
||||
<constraints nullable="false"/>
|
||||
</column>
|
||||
<column name="recipient_id" type="INTEGER">
|
||||
</column>
|
||||
<column name="email_subject" type="TEXT"/>
|
||||
<column name="email_body" type="TEXT"/>
|
||||
<column name="send_status" type="VARCHAR(255)"/>
|
||||
<column name="send_date_time" type="TIMESTAMP WITHOUT TIME ZONE"/>
|
||||
<column name="created_date" type="TIMESTAMP WITHOUT TIME ZONE" defaultValueComputed="CURRENT_TIMESTAMP"/>
|
||||
<column name="updated_date" type="TIMESTAMP WITHOUT TIME ZONE"/>
|
||||
<column name="email_service_response" type="TEXT"></column>
|
||||
<column name="email_service_type" type="VARCHAR(255)"></column>
|
||||
<column name="recipient_emails" type="TEXT"></column>
|
||||
<column name="user_id" type="INTEGER"></column>
|
||||
<column name="error_message" type="TEXT"/>
|
||||
<column name="entity_id" type="INTEGER"></column>
|
||||
<column name="entity_type" type="VARCHAR(255)"></column>
|
||||
</createTable>
|
||||
</changeSet>
|
||||
<changeSet id="15-11-2024_2" author="Nisha kashyap">
|
||||
<addColumn tableName="system_email_template">
|
||||
<column name="email_scenario" type="VARCHAR(255)"></column>
|
||||
</addColumn>
|
||||
<sqlFile dbms="postgresql"
|
||||
path="db/dump/updated_system_email_template_for_email_scenario_15-11-2024.sql"/>
|
||||
<sqlFile dbms="postgresql"
|
||||
path="db/dump/updated_hub_data_for_email_service_config_15-11-2024.sql"/>
|
||||
</changeSet>
|
||||
|
||||
<changeSet id="13-11-2024_1" author="Rajesh Khore">
|
||||
<dropNotNullConstraint tableName="application_amendment_request" columnName="is_email"/>
|
||||
<dropNotNullConstraint tableName="application_amendment_request" columnName="is_notification"/>
|
||||
</changeSet>
|
||||
|
||||
<changeSet id="13-11-2024_2" author="Harish Bagora">
|
||||
<addColumn tableName="beneficiary_preferred_call">
|
||||
<column name="is_deleted" type="BOOLEAN" defaultValueBoolean="false">
|
||||
@@ -1732,4 +1771,36 @@
|
||||
</column>
|
||||
</addColumn>
|
||||
</changeSet>
|
||||
|
||||
<changeSet id="18-11-2024_1" author="Nisha Kashyap">
|
||||
<addColumn tableName="email_log">
|
||||
<column name="is_deleted" type="BOOLEAN" defaultValueBoolean="false"></column>
|
||||
<column name="application_id" type="INTEGER"></column>
|
||||
<column name="amendment_id" type="INTEGER"></column>
|
||||
<column name="call_id" type="INTEGER"></column>
|
||||
</addColumn>
|
||||
<dropColumn tableName="email_log">
|
||||
<column name="entity_id"></column>
|
||||
<column name="entity_type"></column>
|
||||
</dropColumn>
|
||||
</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>
|
||||
<changeSet id="22-11-2024_1" author="Rajesh Khore">
|
||||
<addColumn tableName="application_evaluation">
|
||||
<column name="MOTIVATION" type="TEXT"></column>
|
||||
</addColumn>
|
||||
</changeSet>
|
||||
</databaseChangeLog>
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
UPDATE hub
|
||||
SET email_service_type = 'PEC_SERVICE',
|
||||
email_service_config = 'JkFbBfuVvq7VWwp5LcWIi+hAa1RJ1ekI0jq3w7gLTXETZiTaN8zC4OBWD53x8FtbfFTh3L/5805CIYTH1BQGa3X9q16q9SDzMy7DKHdmJzOnLKhn74C5akoXKaeXUCGnzp0cSk2c01FV6lwefC29IshijFSumCHtVlgWNeZigBzmWK+M7NS+EXf4goIMzguL5bHpYXfoQunQozeY1SpOo+28gDDpzZRMXdtcwKkTgESFGwsy6S1m1TBxJwZC7p8W'
|
||||
WHERE UNIQUE_UUID = 'p4lk3bcx1RStqTaIVVbXs';
|
||||
|
||||
UPDATE hub
|
||||
SET email_service_type = 'MAILGUN_SERVICE',
|
||||
email_service_config = 'QlICHJMvBHd09ci/B2+EDR0q6kFsEdu5gOSI1hgG/7SAm2wXQZagDsAbkBrA6JPHXUS3Bkw6UD9x5boYYxBi3tnpu16i0NgdZqcc2BBhMF1VgRlJMgX+KgsOJsnQbHAJ/9YZaeIVrJpxceHFx93NTbfjT3TzzaZ9cW/64wbeZFspEp6WwgKgV1/3+j297Q1QtKIiWKanolYaU9myx9KwPJZc8AmPe0PR2ViyA7VyGn6iQSrX2pr15tBw3xVIm0tfHh6pktHro4gRYs5CEypQ2cSbP5wv4Z6pDa//FHXzYpRvnb1AUh0thGOix5FZl9Kn'
|
||||
WHERE UNIQUE_UUID = 't7jh5wfg9QXylNaTZkPoE';
|
||||
@@ -0,0 +1,17 @@
|
||||
UPDATE gepafin_schema.system_email_template SET email_scenario='APPLICATION_SUBMITTED' WHERE "type"='APPLICATION_SUBMISSION_TO_USER_AND_COMPANY' AND "system"=true ;
|
||||
|
||||
UPDATE gepafin_schema.system_email_template SET email_scenario='APPLICATION_SUBMITTED' WHERE "type"='APPLICATION_SUBMISSION_TO_GEPAFIN' AND "system"=true ;
|
||||
|
||||
UPDATE gepafin_schema.system_email_template SET email_scenario='APPLICATION_AMENDMENT_REMINDER' WHERE "type"='AMENDMENT_REMINDER' AND "system"=true ;
|
||||
|
||||
UPDATE gepafin_schema.system_email_template SET email_scenario='APPLICATION_AMENDMENT_EXPIRED' WHERE "type"='INADMISSIBILITY_NOTIFICATION_DUE_TO_FAILURE' AND "system"=true ;
|
||||
|
||||
UPDATE gepafin_schema.system_email_template SET email_scenario='APPLICATION_APPROVED' WHERE "type"='ADMISSIBILITY_NOTIFICATION' AND "system"=true ;
|
||||
|
||||
UPDATE gepafin_schema.system_email_template SET email_scenario='APPLICATION_REJECTED' WHERE "type"='INADMISSIBILITY_NOTIFICATION' AND "system"=true ;
|
||||
|
||||
UPDATE gepafin_schema.system_email_template SET email_scenario='APPLICATION_AMENDMENT_REQUESTED' WHERE "type"='DOCUMENTATION_INTEGRATION_REQUEST' AND "system"=true ;
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -308,3 +308,5 @@ invalid.amendment.for.comment = Invalid Amendment Request for the Given Comment.
|
||||
DD_MM_YYYY_HH_MM = dd_MM_yyyy HH:mm
|
||||
application.documents.not.found=No documents found for the application.
|
||||
beneficiary.call.duplicate = A preferred call with this call ID and company ID already exists for this user.
|
||||
user.must.be.associated.with.company.to.create.application=You must be associated with a company to apply for this application.
|
||||
company.id.required.for.preferred.call=Company ID is required when requesting only preferred calls.
|
||||
|
||||
@@ -303,3 +303,5 @@ beneficiary.email.not.found.msg=L'indirizzo email per il beneficiario non <20> st
|
||||
reminder.email.sent.success.msg=Email di promemoria inviata con successo!
|
||||
application.documents.not.found=Nessun documento trovato per la domanda.
|
||||
beneficiary.call.duplicate = Una chiamata preferita con questo ID di chiamata e ID azienda esiste gi<67> per questo utente.
|
||||
user.must.be.associated.with.company.to.create.application=Devi essere associato a un'azienda per poter presentare domanda per questa applicazione.
|
||||
company.id.required.for.preferred.call=ID azienda obbligatorio quando si richiedono solo chiamate preferite.
|
||||
|
||||
Reference in New Issue
Block a user