Merge branch 'develop' of https://github.com/Kitzanos/GEPAFIN-BE into develop
This commit is contained in:
@@ -1047,7 +1047,7 @@ public class ApplicationAmendmentRequestDao {
|
|||||||
|
|
||||||
List<ApplicationAmendmentRequestEntity> amendmentRequests = applicationAmendmentRequestRepository.findAllByApplicationEvaluationIdAndIsDeletedFalse(
|
List<ApplicationAmendmentRequestEntity> amendmentRequests = applicationAmendmentRequestRepository.findAllByApplicationEvaluationIdAndIsDeletedFalse(
|
||||||
existingApplicationAmendment.getApplicationEvaluationEntity().getId());
|
existingApplicationAmendment.getApplicationEvaluationEntity().getId());
|
||||||
Boolean allClosed = amendmentRequests.stream().allMatch(amendment -> amendment.getStatus().equals(ApplicationAmendmentRequestEnum.CLOSE.getValue()));
|
Boolean allClosed = amendmentRequests.stream().allMatch(amendment -> (amendment.getStatus().equals(ApplicationAmendmentRequestEnum.CLOSE.getValue()) || amendment.getStatus().equals(ApplicationAmendmentRequestEnum.EXPIRED.getValue())));
|
||||||
ApplicationEntity application = applicationService.validateApplication(existingApplicationAmendment.getApplicationId());
|
ApplicationEntity application = applicationService.validateApplication(existingApplicationAmendment.getApplicationId());
|
||||||
ApplicationEntity oldApplicationEntityData = Utils.getClonedEntityForData(application);
|
ApplicationEntity oldApplicationEntityData = Utils.getClonedEntityForData(application);
|
||||||
if (Boolean.TRUE.equals(allClosed)) {
|
if (Boolean.TRUE.equals(allClosed)) {
|
||||||
|
|||||||
@@ -964,14 +964,6 @@ public class ApplicationDao {
|
|||||||
applicationEntity.setStatus(status.getValue());
|
applicationEntity.setStatus(status.getValue());
|
||||||
log.info("Status updated to DRAFT for applicationId: " + applicationId);
|
log.info("Status updated to DRAFT for applicationId: " + applicationId);
|
||||||
}
|
}
|
||||||
if(status.equals(ApplicationStatusTypeEnum.ADMISSIBLE) && Boolean.TRUE.equals(applicationEntity.getStatus().equals(ApplicationStatusTypeEnum.APPOINTMENT.getValue()))){
|
|
||||||
applicationEntity.setStatus(status.getValue());
|
|
||||||
log.info("Status updated to ADMISSIBLE for applicationId: " + applicationId);
|
|
||||||
emailNotificationDao.sendAdmissibilityNotificationEmailForAdmissibleApplication(applicationEntity);
|
|
||||||
}
|
|
||||||
if(status.equals(ApplicationStatusTypeEnum.TECHNICAL_EVALUATION) && Boolean.TRUE.equals(applicationEntity.getStatus().equals(ApplicationStatusTypeEnum.ADMISSIBLE.getValue()))){
|
|
||||||
processTechnicalEvaluation(applicationId, applicationEntity, status);
|
|
||||||
}
|
|
||||||
applicationEntity = applicationRepository.save(applicationEntity);
|
applicationEntity = applicationRepository.save(applicationEntity);
|
||||||
log.info("Application status updated successfully | applicationId: {}, newStatus: {}", applicationId, applicationEntity.getStatus());
|
log.info("Application status updated successfully | applicationId: {}, newStatus: {}", applicationId, applicationEntity.getStatus());
|
||||||
|
|
||||||
@@ -983,43 +975,6 @@ public class ApplicationDao {
|
|||||||
return getApplicationResponse(applicationEntity);
|
return getApplicationResponse(applicationEntity);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void processTechnicalEvaluation(Long applicationId, ApplicationEntity applicationEntity, ApplicationStatusTypeEnum status){
|
|
||||||
Optional<ApplicationEvaluationEntity> evaluationEntityOpt = applicationEvaluationRepository.findByApplicationIdAndIsDeletedFalse(applicationId);
|
|
||||||
if (evaluationEntityOpt.isPresent()){
|
|
||||||
ApplicationEvaluationEntity evaluationEntity = evaluationEntityOpt.get();
|
|
||||||
String criteriaJson = evaluationEntity.getCriteria();
|
|
||||||
if (criteriaJson != null){
|
|
||||||
Integer totalScore = calculateTotalScore(evaluationEntity.getCriteria());
|
|
||||||
if (totalScore > 40) {
|
|
||||||
applicationEntity.setStatus(status.getValue());
|
|
||||||
log.info("Status updated to TECHNICAL_EVALUATION for applicationId: " + applicationId);
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
throw new CustomValidationException(Status.BAD_REQUEST,Translator.toLocale(GepafinConstant.INSUFFICIENT_SCORE_MESSAGE));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private Integer calculateTotalScore(String criteriaJson){
|
|
||||||
try {
|
|
||||||
ObjectMapper objectMapper = new ObjectMapper();
|
|
||||||
// Convert JSON string to List of Maps
|
|
||||||
List<Map<String, Object>> criteriaList = objectMapper.readValue(criteriaJson, new TypeReference<>() {
|
|
||||||
});
|
|
||||||
|
|
||||||
// Sum all scores (ignoring null scores)
|
|
||||||
Integer totalScore = criteriaList.stream()
|
|
||||||
.mapToInt(obj -> obj.get("score") != null ? ((Number) obj.get("score")).intValue() : 0)
|
|
||||||
.sum();
|
|
||||||
|
|
||||||
return totalScore;
|
|
||||||
}
|
|
||||||
catch (Exception e) {
|
|
||||||
log.error(" Error parsing criteria JSON: {}", e.getMessage());
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
public Integer calculateProgress(Long totalSteps, Long completedSteps) {
|
public Integer calculateProgress(Long totalSteps, Long completedSteps) {
|
||||||
if (FieldValidator.isNullOrZero(totalSteps)) {
|
if (FieldValidator.isNullOrZero(totalSteps)) {
|
||||||
throw new CustomValidationException(Status.BAD_REQUEST,Translator.toLocale(GepafinConstant.TOTAL_STEPS_NOT_BE_ZERO));
|
throw new CustomValidationException(Status.BAD_REQUEST,Translator.toLocale(GepafinConstant.TOTAL_STEPS_NOT_BE_ZERO));
|
||||||
|
|||||||
@@ -1862,7 +1862,21 @@ public class ApplicationEvaluationDao {
|
|||||||
// UserEntity userEntity = userService.validateUser(application.getUserId());
|
// UserEntity userEntity = userService.validateUser(application.getUserId());
|
||||||
// callService.validatePublishedCall(application.getCall().getId(), userEntity.getHub().getId());
|
// callService.validatePublishedCall(application.getCall().getId(), userEntity.getHub().getId());
|
||||||
ApplicationEntity oldApplicationEntity = Utils.getClonedEntityForData(application);
|
ApplicationEntity oldApplicationEntity = Utils.getClonedEntityForData(application);
|
||||||
application.setStatus(newStatus.getValue());
|
|
||||||
|
|
||||||
|
if(newStatus.equals(ApplicationStatusForEvaluation.ADMISSIBLE) && Boolean.TRUE.equals(application.getStatus().equals(ApplicationStatusTypeEnum.APPOINTMENT.getValue()))){
|
||||||
|
application.setStatus(newStatus.getValue());
|
||||||
|
log.info("Status updated to ADMISSIBLE for applicationId: " + application.getId());
|
||||||
|
emailNotificationDao.sendAdmissibilityNotificationEmailForAdmissibleApplication(application);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(newStatus.equals(ApplicationStatusForEvaluation.TECHNICAL_EVALUATION) && Boolean.TRUE.equals(application.getStatus().equals(ApplicationStatusTypeEnum.ADMISSIBLE.getValue()))){
|
||||||
|
processTechnicalEvaluation(application.getId(), application, newStatus);
|
||||||
|
}
|
||||||
|
|
||||||
|
if((newStatus.equals(ApplicationStatusForEvaluation.APPROVED) || newStatus.equals(ApplicationStatusForEvaluation.REJECTED)) && application.getStatus().equals(ApplicationStatusTypeEnum.EVALUATION.getValue())) {
|
||||||
|
application.setStatus(newStatus.getValue());
|
||||||
|
}
|
||||||
application = applicationRepository.save(application);
|
application = applicationRepository.save(application);
|
||||||
|
|
||||||
/** This code is responsible for adding a version history log for the "Update Application" operation. **/
|
/** This code is responsible for adding a version history log for the "Update Application" operation. **/
|
||||||
@@ -2423,5 +2437,43 @@ public class ApplicationEvaluationDao {
|
|||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
private void processTechnicalEvaluation(Long applicationId, ApplicationEntity applicationEntity, ApplicationStatusForEvaluation status){
|
||||||
|
Optional<ApplicationEvaluationEntity> evaluationEntityOpt = applicationEvaluationRepository.findByApplicationIdAndIsDeletedFalse(applicationId);
|
||||||
|
if (evaluationEntityOpt.isPresent()){
|
||||||
|
ApplicationEvaluationEntity evaluationEntity = evaluationEntityOpt.get();
|
||||||
|
String criteriaJson = evaluationEntity.getCriteria();
|
||||||
|
if (criteriaJson != null){
|
||||||
|
Integer totalScore = calculateTotalScore(evaluationEntity.getCriteria());
|
||||||
|
if (totalScore > 40) {
|
||||||
|
applicationEntity.setStatus(status.getValue());
|
||||||
|
log.info("Status updated to TECHNICAL_EVALUATION for applicationId: " + applicationId);
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
throw new CustomValidationException(Status.BAD_REQUEST,Translator.toLocale(GepafinConstant.INSUFFICIENT_SCORE_MESSAGE));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private Integer calculateTotalScore(String criteriaJson){
|
||||||
|
try {
|
||||||
|
ObjectMapper objectMapper = new ObjectMapper();
|
||||||
|
// Convert JSON string to List of Maps
|
||||||
|
List<Map<String, Object>> criteriaList = objectMapper.readValue(criteriaJson, new TypeReference<>() {
|
||||||
|
});
|
||||||
|
|
||||||
|
// Sum all scores (ignoring null scores)
|
||||||
|
Integer totalScore = criteriaList.stream()
|
||||||
|
.mapToInt(obj -> obj.get("score") != null ? ((Number) obj.get("score")).intValue() : 0)
|
||||||
|
.sum();
|
||||||
|
|
||||||
|
return totalScore;
|
||||||
|
}
|
||||||
|
catch (Exception e) {
|
||||||
|
log.error(" Error parsing criteria JSON: {}", e.getMessage());
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -560,7 +560,7 @@ public class PdfDao {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Process 'fileupload' and 'checkboxes' cases as in the original logic
|
// Process 'fileupload' and 'checkboxes' cases as in the original logic
|
||||||
if (name.equals("fileupload")) {
|
if (name.equals("fileupload") || name.equals("fileselect")) {
|
||||||
if (fieldValue instanceof List<?> && ((List<?>) fieldValue).stream().allMatch(item -> item instanceof DocumentResponseBean)) {
|
if (fieldValue instanceof List<?> && ((List<?>) fieldValue).stream().allMatch(item -> item instanceof DocumentResponseBean)) {
|
||||||
List<DocumentResponseBean> documentList = (List<DocumentResponseBean>) fieldValue;
|
List<DocumentResponseBean> documentList = (List<DocumentResponseBean>) fieldValue;
|
||||||
List<String> names = documentList.stream()
|
List<String> names = documentList.stream()
|
||||||
|
|||||||
@@ -4,7 +4,9 @@ import com.fasterxml.jackson.annotation.JsonValue;
|
|||||||
|
|
||||||
public enum ApplicationStatusForEvaluation {
|
public enum ApplicationStatusForEvaluation {
|
||||||
APPROVED("APPROVED"),
|
APPROVED("APPROVED"),
|
||||||
REJECTED("REJECTED");
|
REJECTED("REJECTED"),
|
||||||
|
ADMISSIBLE("ADMISSIBLE"),
|
||||||
|
TECHNICAL_EVALUATION("TECHNICAL_EVALUATION");
|
||||||
|
|
||||||
private String value;
|
private String value;
|
||||||
|
|
||||||
|
|||||||
@@ -8,8 +8,6 @@ import org.springframework.data.repository.query.Param;
|
|||||||
import org.springframework.stereotype.Repository;
|
import org.springframework.stereotype.Repository;
|
||||||
|
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
import java.time.LocalDate;
|
|
||||||
import java.time.LocalDateTime;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
@@ -112,24 +110,31 @@ public interface ApplicationRepository extends JpaRepository<ApplicationEntity,
|
|||||||
@Param("userId") Long userId,
|
@Param("userId") Long userId,
|
||||||
@Param("userWithCompanyId") Long userWithCompanyId);
|
@Param("userWithCompanyId") Long userWithCompanyId);
|
||||||
|
|
||||||
@Query("""
|
@Query(value = """
|
||||||
SELECT TO_CHAR(a.submissionDate, 'Mon') AS month,
|
WITH months AS (
|
||||||
SUM(a.amountRequested) AS totalRequested,
|
SELECT TO_CHAR(generate_series(CURRENT_DATE - INTERVAL '5 months', CURRENT_DATE, INTERVAL '1 month'), 'Mon') AS month_label,
|
||||||
SUM(a.amountAccepted) AS totalApproved
|
EXTRACT(YEAR FROM generate_series(CURRENT_DATE - INTERVAL '5 months', CURRENT_DATE, INTERVAL '1 month')) AS year_value,
|
||||||
FROM ApplicationEntity a
|
EXTRACT(MONTH FROM generate_series(CURRENT_DATE - INTERVAL '5 months', CURRENT_DATE, INTERVAL '1 month')) AS month_value
|
||||||
WHERE a.isDeleted = false
|
)
|
||||||
AND a.status = 'APPROVED'
|
SELECT m.month_label AS month,
|
||||||
AND a.call.hub.id = :hubId
|
COALESCE(SUM(a.amount_requested), 0) AS totalRequested,
|
||||||
AND a.userId = :userId
|
COALESCE(SUM(a.amount_accepted), 0) AS totalApproved
|
||||||
AND a.userWithCompany.id = :userWithCompanyId
|
FROM months m
|
||||||
GROUP BY TO_CHAR(a.submissionDate, 'Mon'), EXTRACT(YEAR FROM a.submissionDate), EXTRACT(MONTH FROM a.submissionDate)
|
LEFT JOIN {h-schema}application a ON EXTRACT(YEAR FROM a.date_accepted) = m.year_value
|
||||||
ORDER BY EXTRACT(YEAR FROM a.submissionDate), EXTRACT(MONTH FROM a.submissionDate)
|
AND EXTRACT(MONTH FROM a.date_accepted) = m.month_value
|
||||||
""")
|
AND a.is_deleted = false
|
||||||
List<Object[]> findRequestedVsApprovedAmountsPerMonth(
|
AND a.status = 'APPROVED'
|
||||||
@Param("hubId") Long hubId,
|
AND a.hub_id = :hubId
|
||||||
@Param("userId") Long userId,
|
AND a.user_id = :userId
|
||||||
@Param("userWithCompanyId") Long userWithCompanyId
|
AND a.user_with_company_id = :userWithCompanyId
|
||||||
);
|
GROUP BY m.month_label, m.year_value, m.month_value
|
||||||
|
ORDER BY m.year_value, m.month_value
|
||||||
|
""", nativeQuery = true)
|
||||||
|
List<Object[]> findRequestedVsApprovedAmountsPerMonth(@Param("hubId") Long hubId,
|
||||||
|
@Param("userId") Long userId,
|
||||||
|
@Param("userWithCompanyId") Long userWithCompanyId);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@Query("SELECT COUNT(a) FROM ApplicationEntity a " +
|
@Query("SELECT COUNT(a) FROM ApplicationEntity a " +
|
||||||
"WHERE a.hubId = :hubId " +
|
"WHERE a.hubId = :hubId " +
|
||||||
@@ -164,4 +169,5 @@ public interface ApplicationRepository extends JpaRepository<ApplicationEntity,
|
|||||||
);
|
);
|
||||||
|
|
||||||
ApplicationEntity findByIdAndCompanyIdAndIsDeletedFalse(Long id,Long companyId);
|
ApplicationEntity findByIdAndCompanyIdAndIsDeletedFalse(Long id,Long companyId);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user