Done ticket GEPAFINBE-6326 Ranking Management
This commit is contained in:
@@ -72,6 +72,7 @@ import java.time.OffsetDateTime;
|
||||
import java.time.temporal.ChronoUnit;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.*;
|
||||
import java.util.Objects;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.stream.Collectors;
|
||||
@@ -215,6 +216,9 @@ public class ApplicationDao {
|
||||
@Autowired
|
||||
private ApplicationFormViewRepository applicationFormViewRepository;
|
||||
|
||||
@Autowired
|
||||
private ApplicationRankingViewRepository applicationRankingViewRepository;
|
||||
|
||||
@Autowired
|
||||
private FormRepository formRepository;
|
||||
|
||||
@@ -509,6 +513,11 @@ public class ApplicationDao {
|
||||
responseBean.setDateAccepted(applicationEntity.getDateAccepted());
|
||||
responseBean.setDateRejected(applicationEntity.getDateRejected());
|
||||
responseBean.setNdg(applicationEntity.getNdg());
|
||||
if (applicationEntity.getRankingActionType() != null && !applicationEntity.getRankingActionType().isBlank()) {
|
||||
responseBean.setRankingActionType(
|
||||
ApplicationRankingActionTypeEnum.valueOf(applicationEntity.getRankingActionType().trim()));
|
||||
}
|
||||
responseBean.setManualRanking(applicationEntity.getManualRanking());
|
||||
return responseBean;
|
||||
}
|
||||
|
||||
@@ -1152,6 +1161,114 @@ public class ApplicationDao {
|
||||
return getApplicationResponse(applicationEntity);
|
||||
}
|
||||
|
||||
public ApplicationResponse updateApplicationRankingAction(HttpServletRequest request, Long applicationId,
|
||||
ApplicationRankingActionTypeEnum rankingActionType, Long manualRanking) {
|
||||
ApplicationEntity applicationEntity = validateApplication(applicationId);
|
||||
validator.validateRequest(request, RoleStatusEnum.ROLE_SUPER_ADMIN);
|
||||
validateCallClosedForRankingAction(applicationEntity.getCall());
|
||||
if (!ApplicationStatusTypeEnum.APPROVED.getValue().equals(applicationEntity.getStatus())) {
|
||||
throw new CustomValidationException(Status.BAD_REQUEST,
|
||||
Translator.toLocale(GepafinConstant.APPLICATION_RANKING_ACTION_INVALID));
|
||||
}
|
||||
validateRankingActionRequest(rankingActionType, manualRanking);
|
||||
ApplicationEntity oldApplicationEntity = Utils.getClonedEntityForData(applicationEntity);
|
||||
if (rankingActionType == null) {
|
||||
applicationEntity.setRankingActionType(null);
|
||||
applicationEntity.setManualRanking(null);
|
||||
} else {
|
||||
if (rankingActionType == ApplicationRankingActionTypeEnum.REPOSITION
|
||||
&& applicationRepository.existsByCallIdAndManualRankingAndIsDeletedFalseAndIdNot(
|
||||
applicationEntity.getCall().getId(), manualRanking, applicationEntity.getId())) {
|
||||
throw new CustomValidationException(Status.BAD_REQUEST,
|
||||
Translator.toLocale(GepafinConstant.APPLICATION_RANKING_ACTION_INVALID));
|
||||
}
|
||||
applicationEntity.setRankingActionType(rankingActionType.getValue());
|
||||
applicationEntity.setManualRanking(
|
||||
rankingActionType == ApplicationRankingActionTypeEnum.REPOSITION ? manualRanking : null);
|
||||
}
|
||||
applicationEntity = applicationRepository.save(applicationEntity);
|
||||
loggingUtil.addVersionHistory(
|
||||
VersionHistoryRequest.builder().request(request).actionType(VersionActionTypeEnum.UPDATE)
|
||||
.oldData(oldApplicationEntity).newData(applicationEntity).build());
|
||||
return getApplicationResponse(applicationEntity);
|
||||
}
|
||||
|
||||
public CallRankingSummaryResponse getApplicationRanking(Long callId,
|
||||
List<ApplicationRankingActionTypeEnum> rankingActionTypes) {
|
||||
CallEntity call = callRepository.findById(callId)
|
||||
.orElseThrow(() -> new ResourceNotFoundException(Status.NOT_FOUND,
|
||||
Translator.toLocale(GepafinConstant.CALL_NOT_FOUND)));
|
||||
|
||||
Specification<ApplicationRankingView> spec = (root, query, criteriaBuilder) -> {
|
||||
List<jakarta.persistence.criteria.Predicate> predicates = new ArrayList<>();
|
||||
predicates.add(criteriaBuilder.equal(root.get("callId"), callId));
|
||||
if (rankingActionTypes != null && !rankingActionTypes.isEmpty()) {
|
||||
List<String> types = rankingActionTypes.stream()
|
||||
.filter(Objects::nonNull)
|
||||
.map(ApplicationRankingActionTypeEnum::getValue)
|
||||
.distinct()
|
||||
.collect(Collectors.toList());
|
||||
if (!types.isEmpty()) {
|
||||
predicates.add(root.get("rankingActionType").in(types));
|
||||
}
|
||||
}
|
||||
query.orderBy(criteriaBuilder.asc(root.get("rank")));
|
||||
return criteriaBuilder.and(predicates.toArray(new jakarta.persistence.criteria.Predicate[0]));
|
||||
};
|
||||
List<ApplicationRankingView> rows = applicationRankingViewRepository.findAll(spec);
|
||||
|
||||
CallRankingSummaryResponse summary = new CallRankingSummaryResponse();
|
||||
summary.setCallId(call.getId());
|
||||
summary.setCallName(call.getName());
|
||||
summary.setAmount(call.getAmount());
|
||||
if (call.getRankingType() != null && !call.getRankingType().isBlank()) {
|
||||
summary.setRankingType(CallRankingTypeEnum.valueOf(call.getRankingType().trim()));
|
||||
}
|
||||
summary.setApplications(rows.stream()
|
||||
.map(this::convertToApplicationRankingResponse)
|
||||
.collect(Collectors.toList()));
|
||||
return summary;
|
||||
}
|
||||
|
||||
private ApplicationRankingResponse convertToApplicationRankingResponse(ApplicationRankingView entity) {
|
||||
ApplicationRankingResponse response = new ApplicationRankingResponse();
|
||||
response.setApplicationId(entity.getApplicationId());
|
||||
response.setCallId(entity.getCallId());
|
||||
response.setUserId(entity.getUserId());
|
||||
response.setStatus(entity.getStatus());
|
||||
response.setSubmissionDate(entity.getSubmissionDate());
|
||||
response.setProtocolDatetime(entity.getProtocolDatetime());
|
||||
response.setProtocolNumber(entity.getProtocolNumber());
|
||||
response.setNdg(entity.getNdg());
|
||||
response.setAmountAccepted(entity.getAmountAccepted());
|
||||
response.setPecEmail(entity.getPecEmail());
|
||||
response.setManualRanking(entity.getManualRanking());
|
||||
response.setRank(entity.getRank());
|
||||
response.setTotalScore(entity.getTotalScore());
|
||||
if (entity.getRankingActionType() != null && !entity.getRankingActionType().isBlank()) {
|
||||
response.setRankingActionType(ApplicationRankingActionTypeEnum.valueOf(entity.getRankingActionType().trim()));
|
||||
}
|
||||
if (entity.getRankingType() != null && !entity.getRankingType().isBlank()) {
|
||||
response.setRankingType(CallRankingTypeEnum.valueOf(entity.getRankingType().trim()));
|
||||
}
|
||||
return response;
|
||||
}
|
||||
|
||||
private void validateCallClosedForRankingAction(CallEntity callEntity) {
|
||||
if (!CallStatusEnum.EXPIRED.getValue().equals(callEntity.getStatus())) {
|
||||
throw new CustomValidationException(Status.BAD_REQUEST,
|
||||
Translator.toLocale(GepafinConstant.CALL_MUST_BE_CLOSED_FOR_RANKING_ACTION));
|
||||
}
|
||||
}
|
||||
|
||||
private void validateRankingActionRequest(ApplicationRankingActionTypeEnum rankingActionType, Long manualRanking) {
|
||||
if (rankingActionType == ApplicationRankingActionTypeEnum.REPOSITION
|
||||
&& (manualRanking == null || manualRanking <= 0)) {
|
||||
throw new CustomValidationException(Status.BAD_REQUEST,
|
||||
Translator.toLocale(GepafinConstant.APPLICATION_RANKING_ACTION_INVALID));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets all non-terminal amendments, the application evaluation (if any), and the assigned application row to CLOSE.
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user