Merge branch 'develop' of https://github.com/Kitzanos/GEPAFIN-BE into develop

This commit is contained in:
nisha
2024-11-05 15:03:34 +05:30
9 changed files with 228 additions and 46 deletions

View File

@@ -22,8 +22,8 @@ import net.gepafin.tendermanagement.model.response.SystemEmailTemplateResponse;
import net.gepafin.tendermanagement.repositories.*;
import net.gepafin.tendermanagement.service.*;
import net.gepafin.tendermanagement.util.DateTimeUtil;
import net.gepafin.tendermanagement.util.Validator;
import net.gepafin.tendermanagement.entities.SystemEmailTemplatesEntity.SystemEmailTemplatesEntityTypeEnum;
import net.gepafin.tendermanagement.util.MailUtil;
import net.gepafin.tendermanagement.util.Utils;
import net.gepafin.tendermanagement.web.rest.api.errors.CustomValidationException;
import net.gepafin.tendermanagement.web.rest.api.errors.ResourceNotFoundException;
@@ -33,7 +33,6 @@ import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.stereotype.Component;
import java.time.ZoneId;
import java.time.temporal.ChronoUnit;
@@ -96,6 +95,9 @@ public class ApplicationAmendmentRequestDao {
// @Autowired
// private MailUtil mailUtil;
@Autowired
private Validator validator;
public ApplicationAmendmentRequestResponse getApplicationDataForAmendment(HttpServletRequest request, Long applicationEvaluationId) {
log.info("Fetching the application data for the Amendment process {}", applicationEvaluationId);
ApplicationEvaluationEntity applicationEvaluationEntity = applicationEvaluationService.validateApplicationEvaluation(applicationEvaluationId);
@@ -338,7 +340,14 @@ public class ApplicationAmendmentRequestDao {
return response;
}
public List<ApplicationAmendmentRequestResponse> getAllApplicationAmendmentRequest(Long userId) {
public List<ApplicationAmendmentRequestResponse> getAllApplicationAmendmentRequest(HttpServletRequest request,Long userId) {
UserEntity user = validator.validateUser(request);
if(validator.checkIsPreInstructor() && userId == null) {
throw new CustomValidationException(Status.BAD_REQUEST, Translator.toLocale(GepafinConstant.USER_ID_NOT_NULL_MSG));
}
if(userId != null) {
validator.validatePreInstructor(request, userId);
}
Specification<ApplicationAmendmentRequestEntity> spec = search(userId);
List<ApplicationAmendmentRequestEntity> applicationAmendmentRequestEntities =
applicationAmendmentRequestRepository.findAll(spec);
@@ -369,8 +378,8 @@ public class ApplicationAmendmentRequestDao {
ApplicationAmendmentRequestEntity existingApplicationAmendment = validateApplicationAmendmentRequest(id);
setIfUpdated(existingApplicationAmendment::getNote, existingApplicationAmendment::setNote, updateRequest.getNote());
if (updateRequest.getUpdatedFormFields() != null) {
updateApplicationFormFields(existingApplicationAmendment, updateRequest.getUpdatedFormFields());
if (updateRequest.getApplicationFormFields() != null) {
updateApplicationFormFields(existingApplicationAmendment, updateRequest.getApplicationFormFields());
}
existingApplicationAmendment.setUpdatedDate(DateTimeUtil.DateServerToUTC(LocalDateTime.now()));
@@ -380,27 +389,52 @@ 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());
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;
// Check if fieldValue is an array
if (updatedFormField.getFieldValue() instanceof List) {
documentIds = ((List<?>) updatedFormField.getFieldValue()).stream()
.map(Object::toString)
.collect(Collectors.toList());
if (updatedFormField.getFieldValue() instanceof String && updatedFormField.getFieldValue() != null) {
documentIds = Arrays.asList(((String) updatedFormField.getFieldValue()).split(","));
} else {
log.warn("Expected fieldValue as a list but got: {}", updatedFormField.getFieldValue());
log.warn("Expected fieldValue as a comma-separated String but got: {}", updatedFormField.getFieldValue());
return;
}
List<String> validDocumentIds = new ArrayList<>();
for (String documentId : documentIds) {
DocumentEntity documentEntity = documentService.validateDocument(Long.parseLong(documentId));
if (documentEntity != null) {
validDocumentIds.add(documentId);
} else {
log.warn("Document with ID {} does not exist. Skipping this ID.", documentId);
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());
}
}
@@ -425,8 +459,7 @@ public class ApplicationAmendmentRequestDao {
}
if (!fieldUpdated) {
log.warn("No ApplicationFormFieldEntity found for application ID {} and field ID {}. Skipping update.",
applicationAmendment.getApplicationId(), updatedFormField.getFieldId());
throw new CustomValidationException(Status.NOT_FOUND,"No ApplicationFormField found for application ID {} and field ID {}. Skipping update.");
}
} else {
log.warn("No valid document IDs found for update. Skipping field ID {}", updatedFormField.getFieldId());
@@ -434,8 +467,9 @@ public class ApplicationAmendmentRequestDao {
}
public List<ApplicationAmendmentRequestResponse> getAllAmendmentRequestByBeneficiaryId(Long beneficiaryId) {
public List<ApplicationAmendmentRequestResponse> getAllAmendmentRequestByBeneficiaryId(Long beneficiaryId) {
UserEntity userEntity = userService.validateUser(beneficiaryId);
List<ApplicationAmendmentRequestEntity> entities =
applicationAmendmentRequestRepository.findByUserId(beneficiaryId);
@@ -508,8 +542,10 @@ public class ApplicationAmendmentRequestDao {
String subject = prepareSubject(emailTemplate, amendment, beneficiaryUser);
String body = prepareBody(emailTemplate, amendment, beneficiaryUser);
String email = beneficiaryUser.getEmail();
if (Boolean.TRUE.equals(amendment.getIsEmail())&&email != null && !email.isEmpty()) {
String companyEmail = applicationEntity.getCompany().getEmail();
if (Boolean.TRUE.equals(amendment.getIsEmail())&&email != null && !email.isEmpty() && companyEmail != null && !companyEmail.isEmpty()) {
emailNotificationDao.sendMail(hub.getId(), subject, body, List.of(email));
emailNotificationDao.sendMail(hub.getId(), subject, body, List.of(companyEmail));
// mailUtil.sendByMailGun(subject,body,List.of(email),null);
} else {
throw new CustomValidationException(Status.BAD_REQUEST, Translator.toLocale(GepafinConstant.BENEFICIARY_EMAIL_NOT_FOUND_MSG));

View File

@@ -97,6 +97,7 @@ public class DocumentDao {
private Long resolveSourceId(Long sourceId, DocumentSourceTypeEnum sourceType) {
if (sourceType == DocumentSourceTypeEnum.CALL) {
CallEntity callEntity = callService.validateCall(sourceId);
callDao.validateUpdate(callEntity);
return callEntity.getId();
}
// else if (sourceType == SourceTypeEnum.APPLICATION) {

View File

@@ -5,5 +5,5 @@ import lombok.Data;
@Data
public class ApplicationAmendmentRequestBean {
private String note;
private ApplicationFormFieldRequestBean updatedFormFields;
private ApplicationFormFieldRequestBean applicationFormFields;
}

View File

@@ -29,15 +29,15 @@ public interface ApplicationRepository extends JpaRepository<ApplicationEntity,
public Optional<ApplicationEntity> findByIdAndUserIdAndCallIdAndIsDeletedFalse(Long applicationId, Long userId,
Long callId);
@Query("SELECT COUNT(a) FROM ApplicationEntity a WHERE a.userId = :userId AND a.company.id = :companyId AND a.status = 'SUBMIT' ")
@Query("SELECT COUNT(a) FROM ApplicationEntity a WHERE a.userId = :userId AND a.company.id = :companyId AND a.status = 'SUBMIT' AND a.isDeleted = false")
Long countSubmittedApplicationsByUserId(@Param("userId") Long userId, @Param("companyId") Long companyId);
List<ApplicationEntity> findByCompanyIdAndUserIdAndIsDeletedFalse(Long companyId,Long userId);
@Query("SELECT COUNT(a) FROM ApplicationEntity a WHERE a.status = 'SUBMIT' And a.hubId = :hubId")
@Query("SELECT COUNT(a) FROM ApplicationEntity a WHERE a.status = 'SUBMIT' And a.hubId = :hubId AND a.isDeleted = false")
public Long countSubmittedApplicationsByHubId(@Param("hubId") Long hubId);
@Query("SELECT COUNT(a) FROM ApplicationEntity a WHERE a.status = 'DRAFT' And a.hubId = :hubId")
@Query("SELECT COUNT(a) FROM ApplicationEntity a WHERE a.status = 'DRAFT' And a.hubId = :hubId AND a.isDeleted = false")
public Long countDraftApplicationsByHubId(@Param("hubId") Long hubId);
@Query("SELECT a.call.id FROM ApplicationEntity a WHERE a.id = :id")

View File

@@ -8,7 +8,6 @@ import net.gepafin.tendermanagement.entities.ApplicationAmendmentRequestEntity;
import net.gepafin.tendermanagement.entities.ApplicationEvaluationEntity;
import net.gepafin.tendermanagement.entities.UserEntity;
import net.gepafin.tendermanagement.enums.ApplicationAmendmentRequestEnum;
import net.gepafin.tendermanagement.enums.ApplicationStatusTypeEnum;
import net.gepafin.tendermanagement.model.request.ApplicationAmendmentRequest;
import net.gepafin.tendermanagement.model.request.ApplicationAmendmentRequestBean;
import net.gepafin.tendermanagement.model.request.CloseAmendmentRequest;
@@ -62,7 +61,7 @@ public class ApplicationAmendmentRequestServiceImpl implements ApplicationAmendm
@Override
public List<ApplicationAmendmentRequestResponse> getAllApplicationAmendmentRequest(HttpServletRequest request,Long userId) {
return applicationAmendmentRequestDao.getAllApplicationAmendmentRequest(userId);
return applicationAmendmentRequestDao.getAllApplicationAmendmentRequest(request,userId);
}
@Override

View File

@@ -181,7 +181,7 @@ public interface ApplicationAmendmentRequestApi {
@ApiResponse(responseCode = "401", description = "Unauthorized", content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, examples = {
@ExampleObject(value = ErrorConstants.UNAUTHORIZED_ERROR_EXAMPLE) }))
})
@PostMapping(value = "sendReminderEmail/{amendmentId}", produces = MediaType.APPLICATION_JSON_VALUE)
@PostMapping(value = "/{amendmentId}/reminder", produces = MediaType.APPLICATION_JSON_VALUE)
ResponseEntity<Response<Void>> sendReminderEmail(HttpServletRequest request,
@Parameter( required = true)
@PathVariable(value = "amendmentId") Long amendmentId);