Resolved conflicts
This commit is contained in:
@@ -598,7 +598,7 @@ public class ApplicationAmendmentRequestDao {
|
||||
return response;
|
||||
}
|
||||
|
||||
public List<ApplicationAmendmentRequestResponse> getAllApplicationAmendmentRequest(HttpServletRequest request, Long userId) {
|
||||
public List<GetAllAmendmentResponseBean> getAllApplicationAmendmentRequest(HttpServletRequest request, Long userId) {
|
||||
if (validator.checkIsPreInstructor() && userId == null) {
|
||||
throw new CustomValidationException(Status.BAD_REQUEST, Translator.toLocale(GepafinConstant.USER_ID_NOT_NULL_MSG));
|
||||
}
|
||||
@@ -610,7 +610,7 @@ public class ApplicationAmendmentRequestDao {
|
||||
applicationAmendmentRequestRepository.findAll(spec);
|
||||
|
||||
return applicationAmendmentRequestEntities.stream()
|
||||
.map(entity -> convertEntityToResponse(entity, false))
|
||||
.map(this::initializeGetAllBasicResponse)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@@ -996,7 +996,7 @@ public class ApplicationAmendmentRequestDao {
|
||||
}
|
||||
setIfUpdated(existingApplicationAmendment::getInternalNote, existingApplicationAmendment::setInternalNote, closeAmendmentRequest.getInternalNote());
|
||||
setIfUpdated(existingApplicationAmendment::getStatus, existingApplicationAmendment::setStatus, ApplicationAmendmentRequestEnum.CLOSE.getValue());
|
||||
|
||||
existingApplicationAmendment.setClosingDate(LocalDateTime.now());
|
||||
ApplicationAmendmentRequestEntity updatedApplicationAmendment = saveApplicationAmendmentRequestEntity(existingApplicationAmendment, oldApplicationAmendmentEntity,
|
||||
VersionActionTypeEnum.UPDATE);
|
||||
ApplicationAmendmentRequestResponse response = convertEntityToResponse(updatedApplicationAmendment,false);
|
||||
@@ -1089,7 +1089,7 @@ public class ApplicationAmendmentRequestDao {
|
||||
List<ApplicationAmendmentRequestResponse> response = new ArrayList<>();
|
||||
if (applicationAmendmentRequestEntity != null) {
|
||||
response = applicationAmendmentRequestEntity.stream()
|
||||
.map(entity -> convertEntityToResponse(entity, false))
|
||||
.map(entity -> convertEntityToResponse(entity, true))
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
return response;
|
||||
@@ -1184,6 +1184,37 @@ public class ApplicationAmendmentRequestDao {
|
||||
return applicationEvaluation;
|
||||
|
||||
|
||||
}
|
||||
|
||||
private GetAllAmendmentResponseBean initializeGetAllBasicResponse(ApplicationAmendmentRequestEntity entity) {
|
||||
GetAllAmendmentResponseBean response = new GetAllAmendmentResponseBean();
|
||||
ApplicationEntity applicationEntity = entity.getApplicationEvaluationEntity().getAssignedApplicationsEntity().getApplication();
|
||||
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(entity.getEndDate());
|
||||
response.setEvaluationEndDate(entity.getApplicationEvaluationEntity().getEndDate());
|
||||
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));
|
||||
CompanyEntity company = companyService.validateCompany(application.getCompanyId());
|
||||
response.setCompanyName(company.getCompanyName());
|
||||
Long protocolNumber = entity.getProtocol() != null ? entity.getProtocol().getProtocolNumber() : null;
|
||||
response.setProtocolNumber(protocolNumber);
|
||||
return response;
|
||||
}
|
||||
private void softDeleteDocument(Long documentId) {
|
||||
documentService.deleteFile(documentId);
|
||||
|
||||
@@ -31,6 +31,7 @@ import net.gepafin.tendermanagement.web.rest.api.errors.ResourceNotFoundExceptio
|
||||
import net.gepafin.tendermanagement.web.rest.api.errors.Status;
|
||||
|
||||
import org.h2.util.IOUtils;
|
||||
import org.json.JSONObject;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -49,11 +50,16 @@ import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.math.BigDecimal;
|
||||
import java.text.MessageFormat;
|
||||
import java.text.NumberFormat;
|
||||
import java.text.ParseException;
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.LocalTime;
|
||||
import java.util.*;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
import java.util.zip.ZipEntry;
|
||||
import java.util.zip.ZipOutputStream;
|
||||
|
||||
@@ -94,29 +100,29 @@ public class ApplicationDao {
|
||||
|
||||
@Autowired
|
||||
private FlowDataRepository flowDataRepository;
|
||||
|
||||
|
||||
@Autowired
|
||||
private UserCompanyDelegationRepository userCompanyDelegationRepository;
|
||||
|
||||
|
||||
@Autowired
|
||||
private Validator validator;
|
||||
|
||||
|
||||
@Autowired
|
||||
private CompanyService companyService;
|
||||
@Autowired
|
||||
private S3PathConfig s3PathConfig;
|
||||
|
||||
|
||||
@Autowired
|
||||
private SystemEmailTemplatesService systemEmailTemplatesService;
|
||||
@Autowired
|
||||
private AssignedApplicationsRepository assignedApplicationsRepository;
|
||||
|
||||
|
||||
@Value("${default_System_Receiver_Email}")
|
||||
private String defaultSystemReceiverEmail;
|
||||
|
||||
|
||||
@Value("${rinaldo_email}")
|
||||
private String rinaldoEmail;
|
||||
|
||||
|
||||
@Value("${carlo_email}")
|
||||
private String carloEmail;
|
||||
|
||||
@@ -125,37 +131,37 @@ public class ApplicationDao {
|
||||
|
||||
@Autowired
|
||||
private AmazonS3Service amazonS3Service;
|
||||
|
||||
|
||||
@Autowired
|
||||
private ApplicationSignedDocumentRepository applicationSignedDocumentRepository;
|
||||
|
||||
|
||||
// @Value("${aws.s3.url.folder.signed.document}")
|
||||
// private String signedDocumentS3Folder;
|
||||
|
||||
|
||||
@Value("${default.hub.uuid}")
|
||||
private String defaultHubUuid;
|
||||
|
||||
|
||||
@Autowired
|
||||
private UserService userService;
|
||||
|
||||
@Autowired
|
||||
private S3PathConfig s3ConfigBean;
|
||||
|
||||
|
||||
@Autowired
|
||||
private ProtocolDao protocolDao;
|
||||
|
||||
|
||||
@Autowired
|
||||
private HubService hubService;
|
||||
|
||||
@Autowired
|
||||
private EmailNotificationDao emailNotificationDao;
|
||||
|
||||
|
||||
@Autowired
|
||||
private FormDao formDao;
|
||||
|
||||
@Autowired
|
||||
private EmailLogDao emailLogDao;
|
||||
|
||||
|
||||
@Autowired
|
||||
private UserWithCompanyRepository userWithCompanyRepository;
|
||||
|
||||
@@ -183,6 +189,7 @@ public class ApplicationDao {
|
||||
@Autowired
|
||||
private ApplicationEvaluationRepository applicationEvaluationRepository;
|
||||
|
||||
|
||||
public ApplicationResponseBean createApplication(HttpServletRequest request, ApplicationRequestBean applicationRequestBean, Long formId, Long applicationId) {
|
||||
FormEntity formEntity = formService.validateForm(formId);
|
||||
// callService.validatePublishedCall(formEntity.getCall().getId());
|
||||
@@ -234,6 +241,7 @@ public class ApplicationDao {
|
||||
entity.setUserWithCompany(userWithCompany);
|
||||
entity.setIsDeleted(false);
|
||||
entity.setStatus(ApplicationStatusTypeEnum.DRAFT.getValue());
|
||||
entity.setEvaluationVersion(call.getEvaluationVersion());
|
||||
return entity;
|
||||
}
|
||||
|
||||
@@ -257,7 +265,7 @@ public class ApplicationDao {
|
||||
|
||||
// List<ContentResponseBean> contentResponseBeans = Utils.convertJsonStringToList(
|
||||
// applicationFormEntity.getForm().getContent(), ContentResponseBean.class);
|
||||
|
||||
|
||||
List<ContentResponseBean> contentResponseBeans = formDao.convertFormEntityToFormResponseBean(applicationFormEntity.getForm()).getContent();
|
||||
|
||||
for (ApplicationFormFieldEntity applicationFormFieldEntity : applicationFormFieldEntities) {
|
||||
@@ -308,7 +316,7 @@ public class ApplicationDao {
|
||||
);
|
||||
}
|
||||
ApplicationEntity oldApplicationDataEntity = Utils.getClonedEntityForData(applicationEntity);
|
||||
|
||||
|
||||
validator.validateUserWithCompany(request, applicationEntity.getCompanyId());
|
||||
applicationEntity.setIsDeleted(true);
|
||||
applicationEntity = applicationRepository.save(applicationEntity);
|
||||
@@ -355,9 +363,9 @@ public class ApplicationDao {
|
||||
//
|
||||
// return applicationResponses;
|
||||
// }
|
||||
|
||||
|
||||
public List<ApplicationResponse> getAllApplications(UserEntity userEntity, Long callId, Long companyId,List<ApplicationStatusTypeEnum> statusList) {
|
||||
|
||||
|
||||
log.info("Fetching applications for RoleType: {}", userEntity.getRoleEntity().getRoleType());
|
||||
|
||||
Specification<ApplicationEntity> spec = search(userEntity, callId, companyId,statusList);
|
||||
@@ -402,7 +410,7 @@ public class ApplicationDao {
|
||||
ApplicationResponse responseBean = new ApplicationResponse();
|
||||
List<FlowEdgesEntity> flowEdgesList = flowEdgesRepository.findByCallId(applicationEntity.getCall().getId());
|
||||
Long totalFormSteps = flowFormDao.calculateTotalSteps(flowEdgesList);
|
||||
Long completedSteps= Long.valueOf(flowFormDao.getCompletedSteps(applicationEntity));
|
||||
Long completedSteps= Long.valueOf(flowFormDao.getCompletedSteps(applicationEntity, false));
|
||||
Integer progress = calculateProgress(totalFormSteps, completedSteps);
|
||||
responseBean.setId(applicationEntity.getId());
|
||||
responseBean.setProgress(progress);
|
||||
@@ -413,6 +421,7 @@ public class ApplicationDao {
|
||||
responseBean.setCallId(applicationEntity.getCall().getId());
|
||||
responseBean.setSubmissionDate(applicationEntity.getSubmissionDate());
|
||||
responseBean.setStatus(applicationEntity.getStatus());
|
||||
responseBean.setEvaluationVersion(EvaluationVersionEnum.valueOf(applicationEntity.getCall().getEvaluationVersion()));
|
||||
responseBean.setComments(applicationEntity.getComments());
|
||||
responseBean.setCompanyId(applicationEntity.getCompanyId());
|
||||
Optional<AssignedApplicationsEntity> assignedApplicationsOptional =
|
||||
@@ -480,15 +489,18 @@ public class ApplicationDao {
|
||||
|
||||
public List<ApplicationFormFieldEntity> createOrUpdateMultipleFormFields(List<ApplicationFormFieldRequestBean> formFieldResponseBeans,
|
||||
ApplicationFormEntity applicationFormEntity, FormEntity formEntity) {
|
||||
FieldValidator fieldValidator = FieldValidator.create();
|
||||
|
||||
List<ApplicationFormFieldEntity> existingFields = applicationFormFieldRepository.findByApplicationFormId(applicationFormEntity.getId());
|
||||
|
||||
return formFieldResponseBeans.stream().map(requestBean -> createOrUpdateApplicationFormField(requestBean, applicationFormEntity, existingFields, formEntity))
|
||||
List<ApplicationFormFieldEntity> applicationFormFieldEntities=formFieldResponseBeans.stream().map(requestBean -> createOrUpdateApplicationFormField(requestBean, applicationFormEntity, existingFields, formEntity,fieldValidator))
|
||||
.collect(Collectors.toList());
|
||||
fieldValidator.validate();
|
||||
return applicationFormFieldEntities;
|
||||
}
|
||||
|
||||
public ApplicationFormFieldEntity createOrUpdateApplicationFormField(ApplicationFormFieldRequestBean applicationFormFieldRequestBean,
|
||||
ApplicationFormEntity applicationFormEntity, List<ApplicationFormFieldEntity> applicationFormFieldEntities, FormEntity formEntity) {
|
||||
ApplicationFormEntity applicationFormEntity, List<ApplicationFormFieldEntity> applicationFormFieldEntities, FormEntity formEntity,FieldValidator fieldValidator) {
|
||||
|
||||
ApplicationFormFieldEntity applicationFormFieldEntity = new ApplicationFormFieldEntity();
|
||||
|
||||
@@ -497,27 +509,23 @@ public class ApplicationDao {
|
||||
VersionActionTypeEnum actionType = VersionActionTypeEnum.INSERT;
|
||||
List<ContentResponseBean> contentResponseBeans = formDao.convertFormEntityToFormResponseBean(formEntity).getContent();
|
||||
|
||||
contentResponseBeans.stream()
|
||||
.filter(content -> "numberinput".equals(content.getName()))
|
||||
.map(ContentResponseBean::getSettings)
|
||||
.flatMap(List::stream)
|
||||
.filter(setting -> "isRequestedAmount".equals(setting.getName()) && Boolean.TRUE.equals(setting.getValue()))
|
||||
.findFirst()
|
||||
.ifPresent(setting -> {
|
||||
Object fieldValue = applicationFormFieldRequestBean.getFieldValue();
|
||||
if(fieldValue!=null) {
|
||||
if (fieldValue instanceof String) {
|
||||
try {
|
||||
BigDecimal amountRequested = new BigDecimal((String) fieldValue);
|
||||
applicationFormEntity.getApplication().setAmountRequested(amountRequested);
|
||||
} catch (NumberFormatException e) {
|
||||
throw new IllegalArgumentException("Field value is not a valid number: " + fieldValue, e);
|
||||
}
|
||||
} else {
|
||||
throw new IllegalArgumentException("Field value is not a String: " + fieldValue);
|
||||
}
|
||||
}
|
||||
});
|
||||
contentResponseBeans.stream()
|
||||
.filter(content -> "numberinput".equals(content.getName()) && content.getId().toString().equals(applicationFormFieldRequestBean.getFieldId()))
|
||||
.map(ContentResponseBean::getSettings)
|
||||
.flatMap(List::stream)
|
||||
.filter(setting -> "isRequestedAmount".equals(setting.getName()) && Boolean.TRUE.equals(setting.getValue()))
|
||||
.findFirst()
|
||||
.ifPresent(setting -> {
|
||||
Object fieldValue = applicationFormFieldRequestBean.getFieldValue();
|
||||
if(fieldValue!=null) {
|
||||
try {
|
||||
BigDecimal amountRequested = new BigDecimal(fieldValue.toString());
|
||||
applicationFormEntity.getApplication().setAmountRequested(amountRequested);
|
||||
} catch (NumberFormatException e) {
|
||||
throw new IllegalArgumentException("Field value is not a valid number: " + fieldValue, e);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
ApplicationFormFieldEntity oldApplicationFormFieldData = null;
|
||||
@@ -539,6 +547,7 @@ public class ApplicationDao {
|
||||
}
|
||||
}
|
||||
}
|
||||
calculationProcessForFormula(applicationFormEntity,contentResponseBeans,applicationFormFieldRequestBean,fieldValidator);
|
||||
Utils.setIfUpdated(applicationFormFieldEntity::getFieldId, applicationFormFieldEntity::setFieldId, applicationFormFieldRequestBean.getFieldId());
|
||||
|
||||
if (applicationFormFieldRequestBean.getFieldValue() != null) {
|
||||
@@ -561,7 +570,6 @@ public class ApplicationDao {
|
||||
VersionHistoryRequest.builder().request(request).actionType(actionType).oldData(oldApplicationFormFieldData).newData(applicationFormField).build());
|
||||
|
||||
log.info("Version history logged for action: {}, Field ID: {}", actionType, applicationFormFieldEntity.getFieldId());
|
||||
|
||||
return applicationFormField;
|
||||
}
|
||||
|
||||
@@ -670,7 +678,7 @@ public class ApplicationDao {
|
||||
return documentIds;
|
||||
}
|
||||
|
||||
private List<Long> validateDocumentIds(String documentId) {
|
||||
public List<Long> validateDocumentIds(String documentId) {
|
||||
if (documentId != null && !documentId.isEmpty()) {
|
||||
return Arrays.stream(documentId.split(","))
|
||||
.map(Long::parseLong)
|
||||
@@ -819,7 +827,7 @@ public class ApplicationDao {
|
||||
if(formApplicationResponse.getContent() != null && formApplicationResponse.getFormFields() != null) {
|
||||
formApplicationResponses.add(formApplicationResponse);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
public FormApplicationResponse processForm(FormEntity formEntity, ApplicationEntity applicationEntity) {
|
||||
@@ -879,6 +887,10 @@ public class ApplicationDao {
|
||||
checkCallEndDate(call);
|
||||
// call = callService.validatePublishedCall(call.getId());
|
||||
// checkIfApplicationExists(call, userWithCompanyEntity, userEntity);
|
||||
HubEntity hubEntity = hubService.valdateHub(call.getHub().getId());
|
||||
if(hubEntity.getUniqueUuid().equals(defaultHubUuid)){
|
||||
checkIfApplicationExists(call, userWithCompanyEntity, userEntity);
|
||||
}
|
||||
ApplicationEntity applicationEntity = createApplicationEntity(userEntity, call, userWithCompanyEntity);
|
||||
applicationEntity.setComments(applicationRequest.getComments());
|
||||
applicationEntity = saveApplicationEntity(applicationEntity);
|
||||
@@ -891,6 +903,18 @@ public class ApplicationDao {
|
||||
// }
|
||||
// }
|
||||
|
||||
public void checkIfApplicationExists(CallEntity call, UserWithCompanyEntity userWithCompanyEntity, UserEntity userEntity){
|
||||
|
||||
List<ApplicationEntity> applications = applicationRepository.findByUserIdAndUserWithCompany_IdAndCall_IdAndIsDeletedFalseAndStatusNot(
|
||||
userEntity.getId(), userWithCompanyEntity.getId(), call.getId(), ApplicationStatusTypeEnum.REJECTED.name()
|
||||
);
|
||||
|
||||
if (!applications.isEmpty()) {
|
||||
throw new CustomValidationException(Status.BAD_REQUEST, Translator.toLocale(GepafinConstant.APPLICATION_ALREADY_EXISTS));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public ApplicationResponse updateApplicationStatus(HttpServletRequest request, Long applicationId, ApplicationStatusTypeEnum status) {
|
||||
|
||||
ApplicationEntity applicationEntity = validateApplication(applicationId);
|
||||
@@ -955,7 +979,7 @@ public class ApplicationDao {
|
||||
return (int) Math.round(progress);
|
||||
}
|
||||
public void validateFormFields(ApplicationRequestBean request, FormEntity formEntity) {
|
||||
|
||||
|
||||
// List<ContentResponseBean> contentResponseBeans=Utils.convertJsonStringToList(formEntity.getContent(),ContentResponseBean.class);
|
||||
List<ContentResponseBean> contentResponseBeans=formDao.convertFormEntityToFormResponseBean(formEntity).getContent();
|
||||
|
||||
@@ -1035,7 +1059,7 @@ public class ApplicationDao {
|
||||
SystemEmailTemplateResponse systemEmailTemplateResponse = systemEmailTemplatesService
|
||||
.retrieveTemplateByTypeAndCall(SystemEmailTemplatesEntityTypeEnum.APPLICATION_SUBMISSION_TO_USER_AND_COMPANY,
|
||||
hub, null);
|
||||
|
||||
|
||||
// Create the map for subject placeholders
|
||||
Map<String, String> subjectPlaceholders = new HashMap<>();
|
||||
subjectPlaceholders.put("{{call_name}}", call.getName());
|
||||
@@ -1108,15 +1132,28 @@ public class ApplicationDao {
|
||||
// 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),emailLogRequest);
|
||||
}
|
||||
// if(Boolean.TRUE.equals(hub.getUniqueUuid().equals(defaultHubUuid))) {
|
||||
// if (validator.isProductionProfileActivated()) {
|
||||
// emailLogRequest.setRecipientEmails(carloEmail);
|
||||
//// mailUtil.sendByMailGun(subject, body, List.of(carloEmail), null);
|
||||
// emailNotificationDao.sendMail(hub.getId(), subject, body, List.of(carloEmail),emailLogRequest);
|
||||
// }
|
||||
// List<String> listDefaultSystemReceiverEmail = Arrays.stream(defaultSystemReceiverEmail.split(","))
|
||||
// .map(String::trim)
|
||||
// .filter(email -> !email.isEmpty())
|
||||
// .toList();
|
||||
//
|
||||
// emailLogRequest.setRecipientEmails(defaultSystemReceiverEmail);
|
||||
// emailNotificationDao.sendMail(hub.getId(), subject, body, listDefaultSystemReceiverEmail, emailLogRequest);
|
||||
// }
|
||||
|
||||
List<String> hubEmails = Arrays.stream(hub.getEmail().split(","))
|
||||
.map(String::trim)
|
||||
.filter(email -> !email.isEmpty())
|
||||
.toList();
|
||||
|
||||
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);
|
||||
emailNotificationDao.sendMail(hub.getId(), subject, body,hubEmails,emailLogRequest);
|
||||
emailLogRequest.setRecipientEmails(rinaldoEmail);
|
||||
emailNotificationDao.sendMail(hub.getId(), subject, body, List.of(rinaldoEmail),emailLogRequest);
|
||||
}
|
||||
@@ -1212,17 +1249,17 @@ public class ApplicationDao {
|
||||
}
|
||||
|
||||
public ApplicationSignedDocumentResponse getSignedDocument(HttpServletRequest request, Long applicationId) {
|
||||
|
||||
|
||||
ApplicationEntity applicationEntity = validateApplication(applicationId);
|
||||
// validator.validateUserWithCompany(request, applicationEntity.getCompanyId());
|
||||
|
||||
|
||||
if (validator.checkIsPreInstructor()) {
|
||||
ApplicationEvaluationEntity applicationEvaluationEntity = applicationEvaluationService.validateApplicationEvaluationByApplicationId(applicationId);
|
||||
validator.validatePreInstructor(request, applicationEvaluationEntity.getUserId());
|
||||
} else {
|
||||
validator.validateUserId(request, applicationEntity.getUserId());
|
||||
}
|
||||
|
||||
|
||||
ApplicationSignedDocumentEntity applicationSignedDocument = applicationSignedDocumentRepository
|
||||
.findByApplicationIdAndStatus(applicationId, ApplicationSignedDocumentStatusEnum.ACTIVE.getValue());
|
||||
if(applicationSignedDocument == null) {
|
||||
@@ -1231,11 +1268,11 @@ public class ApplicationDao {
|
||||
}
|
||||
return convertApplicationSignedDocumentToApplicationSignedDocumentResponse(applicationSignedDocument);
|
||||
}
|
||||
|
||||
|
||||
public void deleteSignedDocument(HttpServletRequest request, Long applicationId) {
|
||||
ApplicationEntity applicationEntity = validateApplication(applicationId);
|
||||
validator.validateUserWithCompany(request, applicationEntity.getCompanyId());
|
||||
|
||||
|
||||
ApplicationSignedDocumentEntity applicationSignedDocument = applicationSignedDocumentRepository
|
||||
.findByApplicationIdAndStatus(applicationId, ApplicationSignedDocumentStatusEnum.ACTIVE.getValue());
|
||||
//cloned entity for old data
|
||||
@@ -1263,9 +1300,12 @@ public class ApplicationDao {
|
||||
if (Boolean.FALSE.equals(ApplicationStatusTypeEnum.DRAFT.getValue().equals(applicationEntity.getStatus()))) {
|
||||
throw new CustomValidationException(Status.BAD_REQUEST, Translator.toLocale(GepafinConstant.APPLICATION_NOT_IN_DRAFT_STATUS));
|
||||
}
|
||||
if (applicationEntity.getAmountRequested() == null || applicationEntity.getAmountRequested().compareTo(BigDecimal.ZERO) <= 0 ) {
|
||||
throw new CustomValidationException(Status.BAD_REQUEST, Translator.toLocale(GepafinConstant.AMOUNT_REQUEST_SHOULD_GREATED_THEN_ZERO));
|
||||
}
|
||||
List<FlowEdgesEntity> flowEdgesList = flowEdgesRepository.findByCallId(applicationEntity.getCall().getId());
|
||||
Long totalSteps = flowFormDao.calculateTotalSteps(flowEdgesList);
|
||||
Integer completedSteps = flowFormDao.getCompletedSteps(applicationEntity);
|
||||
Integer completedSteps = flowFormDao.getCompletedSteps(applicationEntity, true);
|
||||
if (totalSteps.intValue() != completedSteps) {
|
||||
throw new CustomValidationException(Status.BAD_REQUEST, Translator.toLocale(GepafinConstant.APPLICATION_IS_INCOMPLETE_MSG));
|
||||
}
|
||||
@@ -1402,6 +1442,9 @@ public class ApplicationDao {
|
||||
public PageableResponseBean<List<ApplicationResponse>> getAllApplicationByPagination(UserEntity userEntity, Long callId, Long companyId, ApplicationPageableRequestBean applicationPageableRequestBean) {
|
||||
Integer pageNo = null;
|
||||
Integer pageLimit = null;
|
||||
|
||||
UserWithCompanyEntity userWithCompany= userWithCompanyRepository.findByUserIdAndCompanyIdAndIsDeletedFalse(userEntity.getId(), companyId).orElse(null);
|
||||
|
||||
if (applicationPageableRequestBean.getGlobalFilters() != null) {
|
||||
pageNo = applicationPageableRequestBean.getGlobalFilters().getPage();
|
||||
pageLimit = applicationPageableRequestBean.getGlobalFilters().getLimit();
|
||||
@@ -1412,7 +1455,7 @@ public class ApplicationDao {
|
||||
if (pageNo == null || pageNo <= 0) {
|
||||
pageNo = GepafinConstant.DEFAULT_PAGE;
|
||||
}
|
||||
Specification<ApplicationEntity> spec = search(callId, companyId, applicationPageableRequestBean, userEntity);
|
||||
Specification<ApplicationEntity> spec = search(callId,companyId, userWithCompany.getId(), applicationPageableRequestBean, userEntity);
|
||||
Page<ApplicationEntity> entityPage = applicationRepository.findAll(spec, PageRequest.of(pageNo - 1, pageLimit));
|
||||
// Prepare the response
|
||||
|
||||
@@ -1435,10 +1478,10 @@ public class ApplicationDao {
|
||||
return pageableResponseBean;
|
||||
}
|
||||
|
||||
public Specification<ApplicationEntity> search(Long callId, Long companyId, ApplicationPageableRequestBean applicationPageableRequestBean, UserEntity userEntity) {
|
||||
public Specification<ApplicationEntity> search(Long callId, Long companyId, Long userWithCompanyId, ApplicationPageableRequestBean applicationPageableRequestBean, UserEntity userEntity) {
|
||||
return (root, query, criteriaBuilder) -> {
|
||||
|
||||
List<Predicate> predicates = getPredicates(applicationPageableRequestBean, criteriaBuilder, root, callId, companyId, userEntity);
|
||||
List<Predicate> predicates = getPredicates(applicationPageableRequestBean, criteriaBuilder, root, callId,companyId, userWithCompanyId, userEntity);
|
||||
SortBy sortBy = new SortBy(GepafinConstant.CREATED_DATE, true);
|
||||
|
||||
if (applicationPageableRequestBean.getGlobalFilters() != null
|
||||
@@ -1462,13 +1505,15 @@ public class ApplicationDao {
|
||||
|
||||
|
||||
private List<Predicate> getPredicates(ApplicationPageableRequestBean applicationPageableRequestBean,
|
||||
CriteriaBuilder criteriaBuilder, Root<ApplicationEntity> root, Long callId, Long companyId, UserEntity userEntity) {
|
||||
CriteriaBuilder criteriaBuilder, Root<ApplicationEntity> root, Long callId,Long companyId, Long userWithCompanyId, UserEntity userEntity) {
|
||||
|
||||
Integer year = null;
|
||||
String search = null;
|
||||
Integer daysRange = null;
|
||||
if (applicationPageableRequestBean.getGlobalFilters() != null) {
|
||||
year = applicationPageableRequestBean.getGlobalFilters().getYear();
|
||||
search = applicationPageableRequestBean.getGlobalFilters().getSearch();
|
||||
daysRange = applicationPageableRequestBean.getDaysRange();
|
||||
}
|
||||
List<Predicate> predicates = new ArrayList<>();
|
||||
|
||||
@@ -1526,16 +1571,24 @@ public class ApplicationDao {
|
||||
}
|
||||
|
||||
// Optional companyId filter
|
||||
if (userWithCompanyId != null) {
|
||||
predicates.add(criteriaBuilder.equal(root.get(GepafinConstant.USER_WITH_COMPANY).get(GepafinConstant.ID), userWithCompanyId));
|
||||
}
|
||||
if (companyId != null) {
|
||||
predicates.add(criteriaBuilder.equal(root.get(GepafinConstant.COMPANY_ID), companyId));
|
||||
}
|
||||
|
||||
if (daysRange != null && daysRange >= 0) {
|
||||
LocalDateTime today = LocalDateTime.now();
|
||||
LocalDateTime pastDate = today.minusDays(daysRange);
|
||||
predicates.add(criteriaBuilder.between(root.get(GepafinConstant.CREATED_DATE), pastDate, today));
|
||||
}
|
||||
predicates.add(criteriaBuilder.isFalse(root.get(GepafinConstant.IS_DELETED)));
|
||||
|
||||
predicates.add(criteriaBuilder.equal(root.get(GepafinConstant.HUB_ID), userEntity.getHub().getId()));
|
||||
|
||||
|
||||
return predicates;
|
||||
|
||||
}
|
||||
public void checkCallEndDate(CallEntity call) {
|
||||
LocalDateTime now = DateTimeUtil.DateServerToUTC(LocalDateTime.now());
|
||||
@@ -1553,5 +1606,135 @@ public class ApplicationDao {
|
||||
}
|
||||
}
|
||||
|
||||
public void calculationProcessForFormula(ApplicationFormEntity applicationFormEntity, List<ContentResponseBean> contentResponseBeans, ApplicationFormFieldRequestBean applicationFormFieldRequestBean,FieldValidator fieldValidator) {
|
||||
List<String> formulaValue = new ArrayList<>();
|
||||
String formulaValueOpt=null;
|
||||
String label=null;
|
||||
for (ContentResponseBean contentResponseBean:contentResponseBeans){
|
||||
if(contentResponseBean.getId().equals(applicationFormFieldRequestBean.getFieldId())){
|
||||
for (SettingResponseBean settingResponseBean:contentResponseBean.getSettings()){
|
||||
if (settingResponseBean.getName().equals("label")){
|
||||
label= String.valueOf(settingResponseBean.getValue());
|
||||
}
|
||||
if(settingResponseBean.getName().equals("formula")){
|
||||
String value= (String) settingResponseBean.getValue();
|
||||
formulaValueOpt=value;
|
||||
formulaValue=Utils.extractValues(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Map<String, String> mappedFormulaValue = new HashMap<>();
|
||||
Object fieldValue = applicationFormFieldRequestBean.getFieldValue();
|
||||
if (formulaValueOpt != null && fieldValue==null) {
|
||||
fieldValue=0;
|
||||
}
|
||||
|
||||
for (ContentResponseBean contentResponseBean : contentResponseBeans) {
|
||||
String contentId = contentResponseBean.getId();
|
||||
|
||||
// Extract variable values once per contentResponseBean to avoid repeated stream operations
|
||||
Set<String> variableValues = contentResponseBean.getSettings().stream()
|
||||
.filter(setting -> "variable".equals(setting.getName()))
|
||||
.flatMap(setting -> {
|
||||
Object value = setting.getValue(); // Get the raw value
|
||||
if (value instanceof String) {
|
||||
return Stream.of((String) value); // Handle single String case
|
||||
} else if (value instanceof List) {
|
||||
return ((List<?>) value).stream()
|
||||
.filter(item -> item instanceof String) // Ensure it's a String
|
||||
.map(item -> (String) item); // Convert to String
|
||||
} else {
|
||||
return Stream.empty(); // Ignore unexpected types
|
||||
}
|
||||
})
|
||||
.collect(Collectors.toSet()); // Collect into a Set for uniqueness
|
||||
|
||||
for (String formula : formulaValue) {
|
||||
if (variableValues.contains(formula)) { // O(1) lookup instead of O(n)
|
||||
mappedFormulaValue.put(formula, contentId);
|
||||
}
|
||||
}
|
||||
}
|
||||
Map<String, String> updatedMappedFormulaValue = new HashMap<>();
|
||||
|
||||
for (Map.Entry<String, String> entry : mappedFormulaValue.entrySet()) {
|
||||
String variable = entry.getKey();
|
||||
String contentId = entry.getValue();
|
||||
|
||||
// Repository call using contentId
|
||||
Optional<ApplicationFormFieldEntity> optionalEntity = applicationFormFieldRepository.findByApplicationFormIdAndFieldId(applicationFormEntity.getId(),contentId);
|
||||
// If entity is found, extract fieldValue and fieldId
|
||||
optionalEntity.ifPresent(entity -> {
|
||||
String entityFieldValue = entity.getFieldValue(); // Assuming getter method exists
|
||||
String fieldId = entity.getFieldId(); // Assuming getter method exists
|
||||
String tableType = contentResponseBeans.stream()
|
||||
.filter(content -> content.getId().equals(fieldId)) // Match Content ID with fieldId
|
||||
.flatMap(content -> content.getSettings().stream()) // Extract settings
|
||||
.filter(setting -> "criteria_table_columns".equals(setting.getName())) // Match name
|
||||
.map(setting -> setting.getName()) // Return the name of the setting
|
||||
.findFirst() // Get the first match
|
||||
.orElse(null); // Default to null if no match
|
||||
|
||||
if(tableType!=null){
|
||||
JSONObject jsonObject = new JSONObject(entityFieldValue);
|
||||
|
||||
// Extract the value of total
|
||||
entityFieldValue = jsonObject.getString("total");
|
||||
|
||||
}
|
||||
|
||||
updatedMappedFormulaValue.put(fieldId, entityFieldValue);
|
||||
});
|
||||
}
|
||||
if(formulaValueOpt==null || formulaValueOpt.isEmpty()){
|
||||
return;
|
||||
}
|
||||
double finalValue = evaluateFormula(formulaValueOpt, mappedFormulaValue, updatedMappedFormulaValue);
|
||||
|
||||
fieldValidator.formulaValidation(fieldValue, finalValue, label);
|
||||
}
|
||||
|
||||
|
||||
public static double evaluateFormula(String formula, Map<String, String> mappedFormulaValue, Map<String, String> updatedMappedFormulaValue) {
|
||||
// Step 1: Extract all placeholders (variables) like {rest}, {another_var}, etc.
|
||||
Pattern pattern = Pattern.compile("\\{(.*?)\\}");
|
||||
Matcher matcher = pattern.matcher(formula);
|
||||
List<String> variables = new ArrayList<>();
|
||||
|
||||
while (matcher.find()) {
|
||||
variables.add(matcher.group(1)); // Extract variable names inside the curly braces
|
||||
}
|
||||
|
||||
// Step 2: Replace placeholders with corresponding fieldValue
|
||||
Map<String, Double> variableValues = new HashMap<>();
|
||||
|
||||
for (String variable : variables) {
|
||||
String fieldId = mappedFormulaValue.get(variable);
|
||||
if (fieldId != null && updatedMappedFormulaValue.containsKey(fieldId)) {
|
||||
String fieldValueStr = updatedMappedFormulaValue.get(fieldId);
|
||||
try {
|
||||
double fieldValue = Double.parseDouble(fieldValueStr); // Assuming fieldValue is numeric
|
||||
variableValues.put(variable, fieldValue);
|
||||
} catch (NumberFormatException e) {
|
||||
// Handle invalid number format gracefully (e.g., log an error or default to 0)
|
||||
variableValues.put(variable, 0.0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Step 3: Replace variables in the formula with their corresponding values
|
||||
String expression = formula;
|
||||
for (String variable : variables) {
|
||||
Double value = variableValues.get(variable);
|
||||
if (value != null) {
|
||||
// Replace {variable} with its corresponding value in the formula
|
||||
expression = expression.replace("{" + variable + "}", String.valueOf(value));
|
||||
}
|
||||
}
|
||||
|
||||
// Step 4: Evaluate the mathematical expression
|
||||
return Utils.evaluateExpression(expression);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -12,10 +12,7 @@ import net.gepafin.tendermanagement.model.request.*;
|
||||
import net.gepafin.tendermanagement.model.response.*;
|
||||
import net.gepafin.tendermanagement.repositories.*;
|
||||
import net.gepafin.tendermanagement.service.*;
|
||||
import net.gepafin.tendermanagement.util.DateTimeUtil;
|
||||
import net.gepafin.tendermanagement.util.LoggingUtil;
|
||||
import net.gepafin.tendermanagement.util.Utils;
|
||||
import net.gepafin.tendermanagement.util.Validator;
|
||||
import net.gepafin.tendermanagement.util.*;
|
||||
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;
|
||||
@@ -25,6 +22,7 @@ import org.springframework.stereotype.Component;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.text.MessageFormat;
|
||||
import java.time.Duration;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.temporal.ChronoUnit;
|
||||
@@ -32,6 +30,7 @@ import java.util.*;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static net.gepafin.tendermanagement.util.Utils.log;
|
||||
import static net.gepafin.tendermanagement.util.Utils.setIfUpdated;
|
||||
|
||||
@Component
|
||||
@@ -113,12 +112,49 @@ public class ApplicationEvaluationDao {
|
||||
@Autowired
|
||||
private ApplicationAmendmentRequestDao applicationAmendmentRequestDao;
|
||||
|
||||
@Autowired
|
||||
private HubService hubService;
|
||||
|
||||
@Autowired
|
||||
private EvaluationFormService evaluationFormService;
|
||||
|
||||
@Autowired
|
||||
private EvaluationFormDao evaluationFormDao;
|
||||
|
||||
@Autowired
|
||||
private ApplicationEvaluationFormRepository applicationEvaluationFormRepository;
|
||||
|
||||
@Autowired
|
||||
private ApplicationEvaluationFormFieldRepository applicationEvaluationFormFieldRepository;
|
||||
|
||||
@Autowired
|
||||
private ApplicationDao applicationDao;
|
||||
|
||||
@Autowired
|
||||
private ApplicationEvaluationService applicationEvaluationService;
|
||||
|
||||
@Autowired
|
||||
private CallDao callDao;
|
||||
|
||||
@Autowired
|
||||
private EvaluationFormRepository evaluationFormRepository;
|
||||
|
||||
@Autowired
|
||||
private ObjectMapper objectMapper;
|
||||
|
||||
|
||||
private ApplicationEvaluationEntity convertToEntity(UserEntity user, ApplicationEvaluationRequest req, Long assignedApplciationId) {
|
||||
|
||||
ApplicationEvaluationEntity entity = new ApplicationEvaluationEntity();
|
||||
|
||||
AssignedApplicationsEntity assignedApplications = assignedApplicationsService.validateAssignedApplication(assignedApplciationId);
|
||||
ApplicationEntity application = applicationService.validateApplication(assignedApplications.getApplication().getId());
|
||||
|
||||
Long hubId = application.getHubId();
|
||||
HubEntity hub = hubService.valdateHub(hubId);
|
||||
|
||||
Long initialDays = (hub != null) ? hub.getEvaluationExpirationDays() : 30L;
|
||||
|
||||
entity.setApplicationId(application.getId());
|
||||
entity.setAssignedApplicationsEntity(assignedApplications);
|
||||
entity.setUserId(user.getId());
|
||||
@@ -128,11 +164,12 @@ public class ApplicationEvaluationDao {
|
||||
entity.setNote(req.getNote());
|
||||
entity.setMotivation(req.getMotivation());
|
||||
entity.setIsDeleted(false);
|
||||
entity.setInitialDays(30L);
|
||||
entity.setRemainingDays(30L);
|
||||
entity.setInitialDays(initialDays);
|
||||
entity.setRemainingDays(initialDays);
|
||||
entity.setSuspendedDays(0L);
|
||||
entity.setStartDate(DateTimeUtil.DateServerToUTC(LocalDateTime.now()));
|
||||
entity.setEndDate(DateTimeUtil.DateServerToUTC(application.getSubmissionDate().plusDays(30)));
|
||||
entity.setEndDate(DateTimeUtil.DateServerToUTC(application.getSubmissionDate().plusDays(initialDays)));
|
||||
entity.setEvaluationVersion(application.getEvaluationVersion());
|
||||
entity.setStatus(ApplicationEvaluationStatusTypeEnum.OPEN.getValue());
|
||||
return entity;
|
||||
}
|
||||
@@ -254,9 +291,13 @@ public class ApplicationEvaluationDao {
|
||||
response.setNote(entity.getNote());
|
||||
response.setMotivation(entity.getMotivation());
|
||||
response.setStatus(ApplicationEvaluationStatusTypeEnum.valueOf(entity.getStatus()));
|
||||
response.setEvaluationVersion(EvaluationVersionEnum.valueOf(entity.getEvaluationVersion()));
|
||||
response.setEvaluationEndDate(entity.getEndDate());
|
||||
response.setCreatedDate(entity.getCreatedDate());
|
||||
response.setUpdatedDate(entity.getUpdatedDate());
|
||||
response.setNumberOfCheck(entity.getAssignedApplicationsEntity().getApplication().getCall().getNumberOfCheck());
|
||||
response.setProductId(entity.getAssignedApplicationsEntity().getApplication().getCall().getProductId());
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -603,6 +644,7 @@ public class ApplicationEvaluationDao {
|
||||
ApplicationEvaluationEntity oldApplicationEvaluation = null;
|
||||
ApplicationEntity application = applicationService.validateApplication(assignedApplications.get().getApplication().getId());
|
||||
VersionActionTypeEnum actionType = VersionActionTypeEnum.INSERT;
|
||||
validateApplicationEvaluationRequest(req, application);
|
||||
if (existingEntityOptional.isPresent()) {
|
||||
entity = existingEntityOptional.get();
|
||||
oldApplicationEvaluation = Utils.getClonedEntityForData(entity);
|
||||
@@ -625,16 +667,33 @@ public class ApplicationEvaluationDao {
|
||||
application.setAmountAccepted(req.getAmountAccepted());
|
||||
}
|
||||
actionType = VersionActionTypeEnum.UPDATE;
|
||||
|
||||
entity = applicationEvaluationRepository.save(entity);
|
||||
|
||||
} else {
|
||||
AssignedApplicationsEntity assignedApplicationsEntity = assignedApplicationsService.validateAssignedApplication(assignedApplicationId);
|
||||
entity = convertToEntity(user, req, assignedApplicationId);
|
||||
actionType = VersionActionTypeEnum.INSERT;
|
||||
|
||||
entity = applicationEvaluationRepository.save(entity);
|
||||
|
||||
ApplicationEntity oldApplication = Utils.getClonedEntityForData(application);
|
||||
|
||||
application.setApplicationEvaluationId(entity.getId());
|
||||
|
||||
/** This code is responsible for adding a version history log for the "Update Application" operation. **/
|
||||
loggingUtil.addVersionHistory(VersionHistoryRequest.builder().request(request).actionType(actionType).oldData(oldApplication).newData(application).build());
|
||||
|
||||
Map<String, String> placeHolders = notificationDao.sendNotificationToBeneficiary(application, NotificationTypeEnum.EVALUATION_CREATION);
|
||||
notificationDao.sendNotificationToSuperUser(application,placeHolders,NotificationTypeEnum.EVALUATION_CREATION);
|
||||
notificationDao.sendNotificationToInstructor(placeHolders,entity,NotificationTypeEnum.EVALUATION_CREATION);
|
||||
|
||||
}
|
||||
|
||||
|
||||
/** This code is responsible for adding a version history log for the "Update Application Evaluation" operation. **/
|
||||
loggingUtil.addVersionHistory(VersionHistoryRequest.builder().request(request).actionType(actionType).oldData(oldApplicationEvaluation).newData(entity).build());
|
||||
|
||||
ApplicationStatusForEvaluation status = req.getApplicationStatus();
|
||||
// Fetch all amendment request entities associated with the evaluation ID
|
||||
List<ApplicationAmendmentRequestEntity> applicationAmendmentRequestEntities =
|
||||
@@ -644,25 +703,27 @@ public class ApplicationEvaluationDao {
|
||||
}
|
||||
// Fetch amendment details from the request
|
||||
if(req.getAmendmentDetails()!=null) {
|
||||
List<AmendmentDetailsRequest> amendmentDetailsRequests = req.getAmendmentDetails();
|
||||
|
||||
updateAmendmentDocumentsAndFormFields(applicationAmendmentRequestEntities, amendmentDetailsRequests);
|
||||
}
|
||||
|
||||
ApplicationEvaluationEntity savedEntity = applicationEvaluationRepository.save(entity);
|
||||
|
||||
/** This code is responsible for adding a version history log for the "Update Application Evaluation" operation. **/
|
||||
loggingUtil.addVersionHistory(VersionHistoryRequest.builder().request(request).actionType(actionType).oldData(oldApplicationEvaluation).newData(entity).build());
|
||||
List<AmendmentDetailsRequest> amendmentDetailsRequests = req.getAmendmentDetails();
|
||||
|
||||
updateAmendmentDocumentsAndFormFields(applicationAmendmentRequestEntities, amendmentDetailsRequests);
|
||||
}
|
||||
|
||||
if (status != null) {
|
||||
AssignedApplicationsEntity assignedApplicationsEntity = assignedApplications.get();
|
||||
return updateApplicationEvaluationStatus(application, assignedApplicationsEntity, status);
|
||||
} else {
|
||||
return convertToResponse(savedEntity);
|
||||
return convertToResponse(entity);
|
||||
}
|
||||
}
|
||||
|
||||
private void updateAmendmentDocumentsAndFormFields(List<ApplicationAmendmentRequestEntity> applicationAmendmentRequestEntities, List<AmendmentDetailsRequest> amendmentFormFields) {
|
||||
private void validateApplicationEvaluationRequest(ApplicationEvaluationRequest req, ApplicationEntity application) {
|
||||
if(EvaluationVersionEnum.V2.getValue().equals(application.getEvaluationVersion())) {
|
||||
req.setChecklist(null);
|
||||
req.setCriteria(null);
|
||||
}
|
||||
}
|
||||
|
||||
private void updateAmendmentDocumentsAndFormFields(List<ApplicationAmendmentRequestEntity> applicationAmendmentRequestEntities, List<AmendmentDetailsRequest> amendmentFormFields) {
|
||||
// Iterate through amendment request entities
|
||||
|
||||
//
|
||||
@@ -1086,6 +1147,7 @@ public class ApplicationEvaluationDao {
|
||||
List<ApplicationFormEntity> applicationFormEntities = applicationFormRepository.findByApplicationId(applicationId);
|
||||
response.setApplicationId(application.getId());
|
||||
response.setAssignedApplicationId(assignedApplications.getId());
|
||||
response.setEvaluationVersion(EvaluationVersionEnum.valueOf(application.getEvaluationVersion()));
|
||||
response.setNote(null);
|
||||
response.setMotivation(null);
|
||||
response.setApplicationStatus(ApplicationStatusTypeEnum.valueOf(application.getStatus()));
|
||||
@@ -1094,6 +1156,8 @@ public class ApplicationEvaluationDao {
|
||||
response.setEvaluationEndDate(entity.getEndDate());
|
||||
LocalDateTime callEndDate = application.getCall().getEndDate();
|
||||
response.setCallEndDate(callEndDate);
|
||||
response.setNumberOfCheck(call.getNumberOfCheck());
|
||||
response.setProductId(call.getProductId());
|
||||
setCriteriaResponses(entity, application.getId(), response, evaluationCriterias);
|
||||
setChecklistResponses(entity, application.getId(), response, checklistEntities);
|
||||
setFileResponses(entity, application.getId(), response, applicationFormEntities);
|
||||
@@ -1886,5 +1950,321 @@ public class ApplicationEvaluationDao {
|
||||
loggingUtil.addVersionHistory(VersionHistoryRequest.builder().request(request).actionType(VersionActionTypeEnum.UPDATE).oldData(oldApplicationEvaluation).newData(savedEntity).build());
|
||||
return convertToResponse(savedEntity);
|
||||
}
|
||||
|
||||
public ApplicationEvaluationFormResponse createApplicationEvaluation(HttpServletRequest request, ApplicationEvaluationFormRequestBean applicationEvaluationFormRequestBean, Long evaluationFormId, Long assignedApplicationId){
|
||||
|
||||
UserEntity user = validator.validateUser(request);
|
||||
AssignedApplicationsEntity assignedApplicationsEntity = assignedApplicationsService.validateAssignedApplication(assignedApplicationId);
|
||||
ApplicationEntity application = applicationService.validateApplication(assignedApplicationsEntity.getApplication().getId());
|
||||
|
||||
// Convert FormRequestBean to ApplicationEvaluationRequest
|
||||
ApplicationEvaluationRequest req = convertToApplicationEvaluationRequest(applicationEvaluationFormRequestBean);
|
||||
|
||||
// Call the existing method to create or update evaluation
|
||||
ApplicationEvaluationResponse evaluationResponse = createOrUpdateApplicationEvaluation(user, req, assignedApplicationId);
|
||||
|
||||
ApplicationEvaluationEntity entity = applicationEvaluationService.validateApplicationEvaluation(evaluationResponse.getId());
|
||||
|
||||
//Handling Application Evaluation form
|
||||
EvaluationFormEntity evaluationFormEntity = evaluationFormService.validateEvaluationForm(evaluationFormId);
|
||||
validateFormFields(applicationEvaluationFormRequestBean,evaluationFormEntity);
|
||||
// ApplicationEvaluationEntity applicationEvaluationEntity = applicationEvaluationRepository.findByAssignedApplicationsId(assignedApplicationId);
|
||||
ApplicationEvaluationFormEntity applicationEvaluationFormEntity = getApplicationEvaluationFormOrCreate(evaluationFormEntity,entity);
|
||||
createOrUpdateMultipleFormFields(applicationEvaluationFormRequestBean.getFormFields(), applicationEvaluationFormEntity, evaluationFormEntity);
|
||||
return processEvaluationForm(entity);
|
||||
}
|
||||
|
||||
private ApplicationEvaluationFormEntity getApplicationEvaluationFormOrCreate(EvaluationFormEntity evaluationFormEntity, ApplicationEvaluationEntity applicationEvaluationEntity) {
|
||||
|
||||
ApplicationEvaluationFormEntity applicationEvaluationFormEntity = applicationEvaluationFormRepository.findByEvaluationIdAndEvaluationFormId(applicationEvaluationEntity.getId(), evaluationFormEntity.getId());
|
||||
ApplicationEvaluationFormEntity oldApplicationEvaluationFormEntity = Utils.getClonedEntityForData(applicationEvaluationFormEntity);
|
||||
if (applicationEvaluationFormEntity == null) {
|
||||
applicationEvaluationFormEntity = createApplicationEvaluationFormEntity(applicationEvaluationEntity, evaluationFormEntity);
|
||||
|
||||
/** This code is responsible for adding a version history log for the "Create application evalaution form" operation. **/
|
||||
loggingUtil.addVersionHistory(
|
||||
VersionHistoryRequest.builder().request(request).actionType(VersionActionTypeEnum.INSERT).oldData(oldApplicationEvaluationFormEntity).newData(applicationEvaluationFormEntity)
|
||||
.build());
|
||||
}
|
||||
return applicationEvaluationFormEntity;
|
||||
}
|
||||
|
||||
public ApplicationEvaluationFormEntity createApplicationEvaluationFormEntity(ApplicationEvaluationEntity applicationEvaluationEntity, EvaluationFormEntity evaluationFormEntity) {
|
||||
ApplicationEvaluationFormEntity applicationEvaluationFormEntity = new ApplicationEvaluationFormEntity();
|
||||
applicationEvaluationFormEntity.setApplicationId(applicationEvaluationEntity.getApplicationId());
|
||||
applicationEvaluationFormEntity.setEvaluationForm(evaluationFormEntity);
|
||||
applicationEvaluationFormEntity.setApplicationEvaluation(applicationEvaluationEntity);
|
||||
applicationEvaluationFormEntity.setIsDeleted(false);
|
||||
return saveApplicationEvaluationFormEntity(applicationEvaluationFormEntity);
|
||||
}
|
||||
|
||||
public void validateFormFields(ApplicationEvaluationFormRequestBean request, EvaluationFormEntity evaluationFormEntity) {
|
||||
|
||||
List<ContentResponseBean> contentResponseBeans=evaluationFormDao.convertEvaluationFormEntityToEvaluationFormResponseBean(evaluationFormEntity).getContent();
|
||||
|
||||
List<ApplicationFormFieldRequestBean> requestFields = request.getFormFields();
|
||||
|
||||
Map<String, String> contentMap = contentResponseBeans.stream()
|
||||
.collect(Collectors.toMap(ContentResponseBean::getId, ContentResponseBean::getLabel)); // Change getLabel() if needed
|
||||
FieldValidator validator = FieldValidator.create();
|
||||
for (ApplicationFormFieldRequestBean requestField : requestFields) {
|
||||
String fieldId = requestField.getFieldId();
|
||||
|
||||
if (!contentMap.containsKey(fieldId)) {
|
||||
validator.addError(MessageFormat.format(Translator.toLocale(GepafinConstant.FIELD_ID_NOT_FOUND), fieldId));
|
||||
}
|
||||
|
||||
}
|
||||
validator.validate();
|
||||
}
|
||||
|
||||
public ApplicationEvaluationFormEntity saveApplicationEvaluationFormEntity(ApplicationEvaluationFormEntity applicationEvaluationFormEntity) {
|
||||
return applicationEvaluationFormRepository.save(applicationEvaluationFormEntity);
|
||||
}
|
||||
|
||||
public List<ApplicationEvaluationFormFieldEntity> createOrUpdateMultipleFormFields(List<ApplicationFormFieldRequestBean> formFieldRequestBeans,
|
||||
ApplicationEvaluationFormEntity applicationEvaluationFormEntity, EvaluationFormEntity evaluationFormEntity) {
|
||||
|
||||
List<ApplicationEvaluationFormFieldEntity> existingFields = applicationEvaluationFormFieldRepository.findByApplicationEvaluationFormId(applicationEvaluationFormEntity.getId());
|
||||
|
||||
return formFieldRequestBeans.stream().map(requestBean -> createOrUpdateApplicationEvaluationFormField(requestBean, applicationEvaluationFormEntity, existingFields, evaluationFormEntity))
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
public ApplicationEvaluationFormFieldEntity createOrUpdateApplicationEvaluationFormField(ApplicationFormFieldRequestBean applicationFormFieldRequestBean,
|
||||
ApplicationEvaluationFormEntity applicationEvaluationFormEntity,
|
||||
List<ApplicationEvaluationFormFieldEntity> applicationEvaluationFormFieldEntities,
|
||||
EvaluationFormEntity evaluationFormEntity){
|
||||
ApplicationEvaluationFormFieldEntity applicationEvaluationFormFieldEntity = new ApplicationEvaluationFormFieldEntity();
|
||||
validateFileUploadDocuments(applicationFormFieldRequestBean, evaluationFormEntity);
|
||||
VersionActionTypeEnum actionType = VersionActionTypeEnum.INSERT;
|
||||
ApplicationEvaluationFormFieldEntity oldApplicationEvaluationFormFieldData = null;
|
||||
if (applicationEvaluationFormFieldEntities == null || applicationEvaluationFormFieldEntities.isEmpty()) {
|
||||
applicationEvaluationFormFieldEntity = new ApplicationEvaluationFormFieldEntity();
|
||||
applicationEvaluationFormFieldEntity.setApplicationEvaluationForm(applicationEvaluationFormEntity);
|
||||
applicationEvaluationFormFieldEntity.setIsDeleted(false);
|
||||
}else{
|
||||
for (ApplicationEvaluationFormFieldEntity existingFieldEntity : applicationEvaluationFormFieldEntities) {
|
||||
if (existingFieldEntity.getFieldId().equals(applicationFormFieldRequestBean.getFieldId())) {
|
||||
applicationEvaluationFormFieldEntity = existingFieldEntity;
|
||||
oldApplicationEvaluationFormFieldData = Utils.getClonedEntityForData(existingFieldEntity);
|
||||
actionType = VersionActionTypeEnum.UPDATE;
|
||||
break;
|
||||
} else {
|
||||
applicationEvaluationFormFieldEntity.setApplicationEvaluationForm(applicationEvaluationFormEntity);
|
||||
applicationEvaluationFormFieldEntity.setIsDeleted(Boolean.FALSE);
|
||||
}
|
||||
}
|
||||
}
|
||||
Utils.setIfUpdated(applicationEvaluationFormFieldEntity::getFieldId, applicationEvaluationFormFieldEntity::setFieldId, applicationFormFieldRequestBean.getFieldId());
|
||||
|
||||
if (applicationFormFieldRequestBean.getFieldValue() != null) {
|
||||
applicationEvaluationFormFieldEntity.setFieldValue(Utils.convertObjectToJsonString(applicationFormFieldRequestBean.getFieldValue()));
|
||||
} else {
|
||||
applicationEvaluationFormFieldEntity.setFieldValue(null);
|
||||
}
|
||||
|
||||
ApplicationEvaluationFormFieldEntity savedEvaluationFormFieldEntity = applicationEvaluationFormFieldRepository.save(applicationEvaluationFormFieldEntity);
|
||||
|
||||
loggingUtil.addVersionHistory(VersionHistoryRequest.builder().request(request).actionType(actionType).oldData(oldApplicationEvaluationFormFieldData).newData(savedEvaluationFormFieldEntity).build());
|
||||
|
||||
log.info("Version history logged for action: {}, Field ID: {}", actionType, applicationEvaluationFormFieldEntity.getFieldId());
|
||||
|
||||
return savedEvaluationFormFieldEntity;
|
||||
}
|
||||
|
||||
private List<Long> validateFileUploadDocuments(ApplicationFormFieldRequestBean applicationFormFieldRequestBean, EvaluationFormEntity evaluationFormEntity) {
|
||||
List<Long> documentIds=null;
|
||||
|
||||
List<ContentResponseBean> contentResponseBeans=evaluationFormDao.convertEvaluationFormEntityToEvaluationFormResponseBean(evaluationFormEntity).getContent();
|
||||
for (ContentResponseBean contentResponseBean:contentResponseBeans){
|
||||
if(Boolean.TRUE.equals(contentResponseBean.getName().equals("fileupload"))) {
|
||||
if (contentResponseBean.getId().equals(applicationFormFieldRequestBean.getFieldId())) {
|
||||
Object fieldValueObject = applicationFormFieldRequestBean.getFieldValue();
|
||||
if (fieldValueObject instanceof String) {
|
||||
// Safely cast the object to a string
|
||||
String documentId = (String) fieldValueObject;
|
||||
// Now you can use documentId as needed
|
||||
documentIds = applicationDao.validateDocumentIds(documentId);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return documentIds;
|
||||
}
|
||||
|
||||
|
||||
private List<ApplicationEvaluationFormFieldReponseBean> createEvaluationFormFieldResponse(
|
||||
List<ApplicationEvaluationFormFieldEntity> evaluationFormFieldEntities,
|
||||
ApplicationEvaluationFormEntity applicationEvaluationFormEntity){
|
||||
List<ApplicationEvaluationFormFieldReponseBean> evaluationFormFieldResponseBeans = new ArrayList<>();
|
||||
List<ContentResponseBean> contentResponseBeans =evaluationFormDao.convertEvaluationFormEntityToEvaluationFormResponseBean(applicationEvaluationFormEntity.getEvaluationForm()).getContent();
|
||||
|
||||
for (ApplicationEvaluationFormFieldEntity applicationEvaluationFormFieldEntity : evaluationFormFieldEntities) {
|
||||
|
||||
Optional<ContentResponseBean> fileUploadContent = contentResponseBeans.stream()
|
||||
.filter(contentResponseBean -> "fileupload".equals(contentResponseBean.getName()) &&
|
||||
contentResponseBean.getId().equals(applicationEvaluationFormFieldEntity.getFieldId()))
|
||||
.findFirst();
|
||||
|
||||
List<DocumentResponseBean> documentResponseBeans = new ArrayList<>();
|
||||
if (fileUploadContent.isPresent()) {
|
||||
String documentId = applicationEvaluationFormFieldEntity.getFieldValue();
|
||||
if (documentId != null && !documentId.isEmpty()) {
|
||||
documentResponseBeans = Arrays.stream(documentId.split(","))
|
||||
.map(String::trim)
|
||||
.map(Long::parseLong)
|
||||
.map(docId -> {
|
||||
DocumentEntity documentEntity = documentService.validateDocument(docId);
|
||||
// if (Boolean.FALSE.equals(DocumentSourceTypeEnum.APPLICATION.getValue().equals(documentEntity.getSource()))) {
|
||||
// throw new CustomValidationException(Status.NOT_FOUND,Translator.toLocale(GepafinConstant.DOCUMENT_NOT_FOUND));
|
||||
// }
|
||||
return documentEntity;
|
||||
})
|
||||
.map(callDao::convertToDocumentResponseBean)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
}
|
||||
ApplicationEvaluationFormFieldReponseBean responseBean = convertToEvaluationFormFieldResponseBean(
|
||||
applicationEvaluationFormFieldEntity, applicationEvaluationFormEntity.getId());
|
||||
if (!documentResponseBeans.isEmpty()) {
|
||||
responseBean.setFieldValue(documentResponseBeans);
|
||||
}
|
||||
evaluationFormFieldResponseBeans.add(responseBean);
|
||||
}
|
||||
return evaluationFormFieldResponseBeans;
|
||||
|
||||
}
|
||||
|
||||
private ApplicationEvaluationFormFieldReponseBean convertToEvaluationFormFieldResponseBean(ApplicationEvaluationFormFieldEntity entity,Long applicationEvaluationFormId){
|
||||
ApplicationEvaluationFormFieldReponseBean applicationEvaluationFormFieldReponseBean = new ApplicationEvaluationFormFieldReponseBean();
|
||||
applicationEvaluationFormFieldReponseBean.setApplicationEvaluationFormId(applicationEvaluationFormId);
|
||||
applicationEvaluationFormFieldReponseBean.setFieldId(entity.getFieldId());
|
||||
if(entity.getFieldValue() != null) {
|
||||
applicationEvaluationFormFieldReponseBean.setFieldValue(Utils.getFieldValueAsObject(entity.getFieldValue()));
|
||||
}
|
||||
applicationEvaluationFormFieldReponseBean.setId(entity.getId());
|
||||
applicationEvaluationFormFieldReponseBean.setCreatedDate(entity.getCreatedDate());
|
||||
applicationEvaluationFormFieldReponseBean.setUpdatedDate(entity.getUpdatedDate());
|
||||
return applicationEvaluationFormFieldReponseBean;
|
||||
}
|
||||
|
||||
private ApplicationEvaluationFormResponse convertToApplicationEvaluationResponseBean(ApplicationEvaluationResponse applicationEvaluationResponse){
|
||||
ApplicationEvaluationFormResponse response = new ApplicationEvaluationFormResponse();
|
||||
response.setId(applicationEvaluationResponse.getId());
|
||||
response.setApplicationId(applicationEvaluationResponse.getApplicationId());
|
||||
response.setNote(applicationEvaluationResponse.getNote());
|
||||
response.setEvaluationVersion(applicationEvaluationResponse.getEvaluationVersion());
|
||||
response.setCreatedDate(applicationEvaluationResponse.getCreatedDate());
|
||||
response.setUpdatedDate(applicationEvaluationResponse.getUpdatedDate());
|
||||
response.setApplicationStatus(applicationEvaluationResponse.getApplicationStatus());
|
||||
response.setAssignedApplicationId(applicationEvaluationResponse.getAssignedApplicationId());
|
||||
response.setMinScore(applicationEvaluationResponse.getMinScore());
|
||||
response.setStatus(applicationEvaluationResponse.getStatus());
|
||||
response.setFiles(applicationEvaluationResponse.getFiles());
|
||||
response.setEvaluationDocument(applicationEvaluationResponse.getEvaluationDocument());
|
||||
response.setAmendmentDetails(applicationEvaluationResponse.getAmendmentDetails());
|
||||
response.setBeneficiary(applicationEvaluationResponse.getBeneficiary());
|
||||
response.setAssignedUserId(applicationEvaluationResponse.getAssignedUserId());
|
||||
response.setAssignedUserName(applicationEvaluationResponse.getAssignedUserName());
|
||||
response.setProtocolNumber(applicationEvaluationResponse.getProtocolNumber());
|
||||
response.setCallName(applicationEvaluationResponse.getCallName());
|
||||
response.setMotivation(applicationEvaluationResponse.getMotivation());
|
||||
response.setSubmissionDate(applicationEvaluationResponse.getSubmissionDate());
|
||||
response.setEvaluationEndDate(applicationEvaluationResponse.getEvaluationEndDate());
|
||||
response.setCallEndDate(applicationEvaluationResponse.getCallEndDate());
|
||||
response.setCompanyName(applicationEvaluationResponse.getCompanyName());
|
||||
response.setAssignedAt(applicationEvaluationResponse.getAssignedAt());
|
||||
response.setNdg(applicationEvaluationResponse.getNdg());
|
||||
response.setAppointmentId(applicationEvaluationResponse.getAppointmentId());
|
||||
response.setAmountRequested(applicationEvaluationResponse.getAmountRequested());
|
||||
response.setAmountAccepted(applicationEvaluationResponse.getAmountAccepted());
|
||||
response.setDateAccepted(applicationEvaluationResponse.getDateAccepted());
|
||||
response.setDateRejected(applicationEvaluationResponse.getDateRejected());
|
||||
|
||||
return response;
|
||||
}
|
||||
|
||||
public ApplicationEvaluationFormResponse getApplicationEvaluationForm(HttpServletRequest request, Long applicationId, Long assignedApplicationId ){
|
||||
|
||||
if (applicationId == null && assignedApplicationId == null) {
|
||||
throw new CustomValidationException(Status.BAD_REQUEST,Translator.toLocale(GepafinConstant.EITHER_APPLICATION_ID_OR_ASSIGNED_APPLICATION_ID_MUST_BE_PROVIDED));
|
||||
}
|
||||
|
||||
ApplicationEvaluationEntity evaluationEntity = applicationEvaluationRepository.findByApplicationIdAndAssignedApplicationId(applicationId, assignedApplicationId);
|
||||
|
||||
return (evaluationEntity != null) ? processEvaluationForm(evaluationEntity) : null;
|
||||
}
|
||||
|
||||
private ApplicationEvaluationFormResponse processEvaluationForm(ApplicationEvaluationEntity evaluationEntity){
|
||||
|
||||
Object convertedResponse = convertToResponse(evaluationEntity);
|
||||
|
||||
ApplicationEvaluationFormResponse response = objectMapper.convertValue(convertedResponse, ApplicationEvaluationFormResponse.class);
|
||||
EvaluationFormEntity evaluationFormEntity = evaluationFormRepository.findByCallIdAndIsDeletedFalse(evaluationEntity.getAssignedApplicationsEntity().getApplication().getCall().getId());
|
||||
|
||||
if (evaluationFormEntity != null) {
|
||||
response.setApplicationEvaluationFormResponse(convertEvaluationFormToResponse(evaluationFormEntity, evaluationEntity));
|
||||
}
|
||||
|
||||
return response;
|
||||
}
|
||||
|
||||
private ApplicationEvaluationFormResponseBean convertEvaluationFormToResponse(EvaluationFormEntity evaluationForm, ApplicationEvaluationEntity applicationEvaluationEntity) {
|
||||
ApplicationEvaluationFormResponseBean applicationEvaluationFormResponseBean = createEvaluationFormResponse(evaluationForm);
|
||||
|
||||
ApplicationEvaluationFormEntity applicationEvaluationFormEntity = applicationEvaluationFormRepository.findByEvaluationIdAndEvaluationFormId(applicationEvaluationEntity.getId(), evaluationForm.getId());
|
||||
|
||||
if(applicationEvaluationFormEntity!=null) {
|
||||
List<ApplicationEvaluationFormFieldEntity> applicationEvaluationFormFieldEntities = applicationEvaluationFormFieldRepository.findByApplicationEvaluationFormId(applicationEvaluationFormEntity.getId());
|
||||
List<ApplicationEvaluationFormFieldReponseBean> evaluationFormFieldResponseBeans = createEvaluationFormFieldResponse(applicationEvaluationFormFieldEntities, applicationEvaluationFormEntity);
|
||||
applicationEvaluationFormResponseBean.setFormFields(evaluationFormFieldResponseBeans);
|
||||
}
|
||||
|
||||
return applicationEvaluationFormResponseBean;
|
||||
}
|
||||
|
||||
private ApplicationEvaluationFormResponseBean createEvaluationFormResponse(EvaluationFormEntity evaluationFormEntity) {
|
||||
ApplicationEvaluationFormResponseBean evaluationFormResponseBean = new ApplicationEvaluationFormResponseBean();
|
||||
evaluationFormResponseBean.setId(evaluationFormEntity.getId());
|
||||
evaluationFormResponseBean.setLabel(evaluationFormEntity.getLabel());
|
||||
evaluationFormResponseBean.setCallId(evaluationFormEntity.getCall().getId());
|
||||
evaluationFormResponseBean.setContent(evaluationFormDao.convertEvaluationFormEntityToEvaluationFormResponseBean(evaluationFormEntity).getContent());
|
||||
return evaluationFormResponseBean;
|
||||
}
|
||||
|
||||
public ApplicationEvaluationVersionResponse getApplicationEvaluationVersion(HttpServletRequest request, Long applicationId){
|
||||
|
||||
log.info("Fetching application evaluation version with ID: {}", applicationId);
|
||||
|
||||
ApplicationEntity applicationEntity = applicationService.validateApplication(applicationId);
|
||||
return buildApplicationEvaluationVersionResponse(applicationEntity);
|
||||
|
||||
}
|
||||
private ApplicationEvaluationVersionResponse buildApplicationEvaluationVersionResponse(ApplicationEntity applicationEntity) {
|
||||
ApplicationEvaluationVersionResponse response = new ApplicationEvaluationVersionResponse();
|
||||
response.setApplicationId(applicationEntity.getId());
|
||||
response.setCallId(applicationEntity.getCall().getId());
|
||||
response.setCompanyId(applicationEntity.getCompanyId());
|
||||
response.setEvaluationVersion(EvaluationVersionEnum.valueOf(applicationEntity.getEvaluationVersion()));
|
||||
response.setEvaluationId(applicationEntity.getApplicationEvaluationId());
|
||||
return response;
|
||||
}
|
||||
|
||||
public static ApplicationEvaluationRequest convertToApplicationEvaluationRequest(ApplicationEvaluationFormRequestBean formRequestBean) {
|
||||
ApplicationEvaluationRequest request = new ApplicationEvaluationRequest();
|
||||
request.setFiles(formRequestBean.getFiles());
|
||||
request.setEvaluationDocument(formRequestBean.getEvaluationDocument());
|
||||
request.setAmendmentDetails(formRequestBean.getAmendmentDetails());
|
||||
request.setNote(formRequestBean.getNote());
|
||||
request.setApplicationStatus(formRequestBean.getApplicationStatus());
|
||||
request.setMotivation(formRequestBean.getMotivation());
|
||||
request.setAmountAccepted(formRequestBean.getAmountAccepted());
|
||||
|
||||
request.setCriteria(null);
|
||||
request.setChecklist(null);
|
||||
|
||||
return request;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -11,6 +11,11 @@ import net.gepafin.tendermanagement.enums.ApplicationStatusTypeEnum;
|
||||
import net.gepafin.tendermanagement.enums.AssignedApplicationEnum;
|
||||
import net.gepafin.tendermanagement.model.request.*;
|
||||
import net.gepafin.tendermanagement.enums.VersionActionTypeEnum;
|
||||
import net.gepafin.tendermanagement.enums.*;
|
||||
import net.gepafin.tendermanagement.model.request.ApplicationEvaluationRequest;
|
||||
import net.gepafin.tendermanagement.model.request.AssignedApplicationsRequest;
|
||||
import net.gepafin.tendermanagement.model.request.UpdateAssignedApplicationRequest;
|
||||
import net.gepafin.tendermanagement.model.request.VersionHistoryRequest;
|
||||
import net.gepafin.tendermanagement.model.response.ApplicationResponse;
|
||||
import net.gepafin.tendermanagement.model.response.AssignedApplicationsResponse;
|
||||
import net.gepafin.tendermanagement.model.response.PageableResponseBean;
|
||||
@@ -37,6 +42,7 @@ import org.springframework.stereotype.Component;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@@ -81,8 +87,13 @@ public class AssignedApplicationsDao {
|
||||
log.info("Assigning application to pre-Instructor with details: {}", applicationId, userId);
|
||||
|
||||
AssignedApplicationsEntity assignedApplications = assignedApplicationsRepository.findByApplicationIdAndIsDeletedFalse(applicationId).orElse(null);
|
||||
if (assignedApplications != null) {
|
||||
if (assignedApplications != null && assignedApplications.getUserId().equals(userId)) {
|
||||
throw new CustomValidationException(Status.BAD_REQUEST, Translator.toLocale(GepafinConstant.APPLICATION_ALREADY_ASSIGNED));
|
||||
} else if(assignedApplications != null) {
|
||||
assignedApplications = reassignApplication(userId, assignedByUser, assignedApplications);
|
||||
AssignedApplicationsResponse assignApplicationToInstructorResponse = convertEntityToResponse(assignedApplications);
|
||||
log.info("Application re-assigned succesfully {}", assignApplicationToInstructorResponse);
|
||||
return assignApplicationToInstructorResponse;
|
||||
}
|
||||
ApplicationEntity application = applicationService.validateApplication(applicationId);
|
||||
|
||||
@@ -108,15 +119,37 @@ public class AssignedApplicationsDao {
|
||||
return assignApplicationToInstructorResponse;
|
||||
}
|
||||
|
||||
private AssignedApplicationsEntity reassignApplication(Long userId, UserEntity assignedByUser,
|
||||
AssignedApplicationsEntity assignedApplication) {
|
||||
|
||||
AssignedApplicationsEntity oldAssignedApplicationEntity = Utils.getClonedEntityForData(assignedApplication);
|
||||
|
||||
setIfUpdated(assignedApplication::getAssignedBy, assignedApplication::setAssignedBy, assignedByUser.getId());
|
||||
setIfUpdated(assignedApplication::getUserId, assignedApplication::setUserId, userId);
|
||||
assignedApplication.setAssignedAt(DateTimeUtil.DateServerToUTC(LocalDateTime.now()));
|
||||
assignedApplication.setStatus(AssignedApplicationEnum.AWAITING.getValue());
|
||||
Optional<ApplicationEvaluationEntity> entityOptional = applicationEvaluationRepository.findByAssignedApplicationsEntity_IdAndIsDeletedFalse(assignedApplication.getId());
|
||||
if(entityOptional.isPresent()) {
|
||||
ApplicationEvaluationEntity oldApplicationEvaluationEntity = Utils.getClonedEntityForData(entityOptional.get());
|
||||
setIfUpdated(entityOptional.get()::getUserId, entityOptional.get()::setUserId, userId);
|
||||
applicationEvaluationRepository.save(entityOptional.get());
|
||||
/** This code is responsible for adding a version history log for the "Create Application" operation. **/
|
||||
loggingUtil.addVersionHistory(VersionHistoryRequest.builder().request(request).actionType(VersionActionTypeEnum.UPDATE).oldData(oldApplicationEvaluationEntity).newData(entityOptional.get()).build());
|
||||
|
||||
};
|
||||
assignedApplication = assignedApplicationsRepository.save(assignedApplication);
|
||||
/** This code is responsible for adding a version history log for the "Create Application" operation. **/
|
||||
loggingUtil.addVersionHistory(VersionHistoryRequest.builder().request(request).actionType(VersionActionTypeEnum.UPDATE).oldData(oldAssignedApplicationEntity).newData(assignedApplication).build());
|
||||
|
||||
return assignedApplication;
|
||||
}
|
||||
|
||||
public AssignedApplicationsEntity createAssignmentEntity(ApplicationEntity application, Long userId, UserEntity assignedByUser, AssignedApplicationsRequest assignedApplicationsRequest) {
|
||||
AssignedApplicationsEntity assignApplication = new AssignedApplicationsEntity();
|
||||
assignApplication.setApplication(application);
|
||||
assignApplication.setAssignedBy(assignedByUser.getId());
|
||||
assignApplication.setUserId(userId);
|
||||
assignApplication.setStatus(AssignedApplicationEnum.OPEN.getValue());
|
||||
if (assignedApplicationsRequest.getStatus() != null) {
|
||||
assignApplication.setStatus(assignedApplicationsRequest.getStatus().getValue());
|
||||
}
|
||||
assignApplication.setStatus(AssignedApplicationEnum.AWAITING.getValue());
|
||||
assignApplication.setNote(assignedApplicationsRequest.getNote());
|
||||
assignApplication.setIsDeleted(false);
|
||||
assignApplication.setAssignedAt(DateTimeUtil.DateServerToUTC(LocalDateTime.now()));
|
||||
@@ -175,9 +208,12 @@ public class AssignedApplicationsDao {
|
||||
assignedApplicationsResponse.setSubmissionDate(submissionDate);
|
||||
assignedApplicationsResponse.setCallEndDate(callEndDate);
|
||||
assignedApplicationsResponse.setCallStartDate(callStartDate);
|
||||
assignedApplicationsResponse.setEvaluationVersion(EvaluationVersionEnum.valueOf(application.getCall().getEvaluationVersion()));
|
||||
if(applicationEvaluationEntity.isPresent()){
|
||||
assignedApplicationsResponse.setEvaluationEndDate(applicationEvaluationEntity.get().getEndDate());
|
||||
}
|
||||
assignedApplicationsResponse.setNumberOfCheck(application.getCall().getNumberOfCheck());
|
||||
assignedApplicationsResponse.setProductId(application.getCall().getProductId());
|
||||
return assignedApplicationsResponse;
|
||||
}
|
||||
|
||||
@@ -197,7 +233,7 @@ public class AssignedApplicationsDao {
|
||||
log.info("Assigned Application deleted with ID: {}", id);
|
||||
}
|
||||
|
||||
public List<AssignedApplicationsResponse> getAllAssignedApplications(HttpServletRequest request, Long userId) {
|
||||
public List<AssignedApplicationsResponse> getAllAssignedApplications(HttpServletRequest request, Long userId,List<AssignedApplicationEnum> statusList) {
|
||||
UserEntity user = validator.validateUser(request);
|
||||
if(validator.checkIsPreInstructor() && userId == null) {
|
||||
throw new CustomValidationException(Status.BAD_REQUEST, Translator.toLocale(GepafinConstant.USER_ID_NOT_NULL_MSG));
|
||||
@@ -205,18 +241,24 @@ public class AssignedApplicationsDao {
|
||||
if(userId != null) {
|
||||
validator.validatePreInstructor(request, userId);
|
||||
}
|
||||
Specification<AssignedApplicationsEntity> spec = search(user.getHub().getId() ,userId);
|
||||
Specification<AssignedApplicationsEntity> spec = search(user.getHub().getId() ,userId,statusList);
|
||||
List<AssignedApplicationsEntity> assignedApplicationsEntityList = assignedApplicationsRepository.findAll(spec);
|
||||
return assignedApplicationsEntityList.stream()
|
||||
.map(entity -> convertEntityToResponse(entity))
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
private Specification<AssignedApplicationsEntity> search(Long hubId, Long userId) {
|
||||
private Specification<AssignedApplicationsEntity> search(Long hubId, Long userId,List<AssignedApplicationEnum> statusList) {
|
||||
return (root, query, builder) -> {
|
||||
Predicate predicate = builder.isFalse(root.get("isDeleted"));
|
||||
if (userId != null) {
|
||||
predicate = builder.and(predicate, builder.equal(root.get("userId"), userId));
|
||||
}
|
||||
if (statusList != null && !statusList.isEmpty()) {
|
||||
List<String> statusNames = statusList.stream()
|
||||
.map(Enum::name)
|
||||
.collect(Collectors.toList());
|
||||
predicate = builder.and(predicate, root.get("status").in(statusNames));
|
||||
}
|
||||
query.orderBy(
|
||||
builder.desc(builder.isNotNull(root.get(GepafinConstant.ASSIGNED_AT))),
|
||||
builder.desc(root.get(GepafinConstant.ASSIGNED_AT))
|
||||
@@ -370,5 +412,14 @@ public class AssignedApplicationsDao {
|
||||
return predicates;
|
||||
|
||||
}
|
||||
public AssignedApplicationsResponse updateAssignedApplicationStatus(HttpServletRequest request, Long assignedApplicationId, AssignedApplicationEnum status) {
|
||||
|
||||
AssignedApplicationsEntity assignedApplication = validateAssignedApplication(assignedApplicationId);
|
||||
validator.validatePreInstructor(request, assignedApplication.getUserId());
|
||||
|
||||
AssignedApplicationsEntity oldAssignedApplicationEntity = Utils.getClonedEntityForData(assignedApplication);
|
||||
assignedApplication.setStatus(status.getValue());
|
||||
AssignedApplicationsEntity updatedAssignment = saveAssignedApplication(assignedApplication, oldAssignedApplicationEntity, VersionActionTypeEnum.UPDATE);
|
||||
return convertEntityToResponse(updatedAssignment);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -116,6 +116,9 @@ public class CallDao {
|
||||
@Autowired
|
||||
private NotificationTypeRepository notificationTypeRepository;
|
||||
|
||||
@Autowired
|
||||
private EvaluationFormDao evalualtionFormDao;
|
||||
|
||||
public CallResponse createCallStep1(CreateCallRequestStep1 createCallRequest, UserEntity userEntity) {
|
||||
createCallRequest.setRegionId(userEntity.getRoleEntity().getRegion().getId());
|
||||
CallEntity callEntity = convertToCallEntity(createCallRequest, userEntity);
|
||||
@@ -178,6 +181,7 @@ public class CallDao {
|
||||
}
|
||||
}
|
||||
callEntity.setStatus(CallStatusEnum.DRAFT.getValue());
|
||||
callEntity.setEvaluationVersion(createCallRequest.getEvaluationVersion().getValue());
|
||||
callEntity.setAmountMax(createCallRequest.getAmountMax());
|
||||
callEntity.setAmount(createCallRequest.getAmount());
|
||||
callEntity.setConfidi(false);
|
||||
@@ -197,6 +201,8 @@ public class CallDao {
|
||||
callEntity.setStartTime(DateTimeUtil.parseTime(createCallRequest.getStartTime()));
|
||||
callEntity.setEndTime(DateTimeUtil.parseTime(createCallRequest.getEndTime()));
|
||||
callEntity.setHub(userEntity.getHub());
|
||||
callEntity.setNumberOfCheck(createCallRequest.getNumberOfCheck());
|
||||
callEntity.setProductId(createCallRequest.getProductId());
|
||||
callEntity = callRepository.save(callEntity);
|
||||
|
||||
/** This code is responsible for adding a version history log for the "Create Call" operation. **/
|
||||
@@ -362,6 +368,7 @@ public class CallDao {
|
||||
createCallResponseBean.setDescriptionShort(callEntity.getDescriptionShort());
|
||||
createCallResponseBean.setDescriptionLong(callEntity.getDescriptionLong());
|
||||
createCallResponseBean.setStatus(CallStatusEnum.valueOf(callEntity.getStatus()));
|
||||
createCallResponseBean.setEvaluationVersion(EvaluationVersionEnum.valueOf(callEntity.getEvaluationVersion()));
|
||||
createCallResponseBean.setRegionId(callEntity.getRegion().getId());
|
||||
createCallResponseBean.setAmount(callEntity.getAmount());
|
||||
createCallResponseBean.setAmountMax(callEntity.getAmountMax());
|
||||
@@ -601,6 +608,9 @@ public class CallDao {
|
||||
setIfUpdated(callEntity::getStartTime, callEntity::setStartTime, DateTimeUtil.parseTime(updateCallRequest.getStartTime()));
|
||||
setIfUpdated(callEntity::getEndTime, callEntity::setEndTime, DateTimeUtil.parseTime(updateCallRequest.getEndTime()));
|
||||
setIfUpdated(callEntity::getConfidi, callEntity::setConfidi, updateCallRequest.getConfidi());
|
||||
setIfUpdated(callEntity::getEvaluationVersion, callEntity::setEvaluationVersion, updateCallRequest.getEvaluationVersion().getValue());
|
||||
setIfUpdated(callEntity::getNumberOfCheck, callEntity::setNumberOfCheck, updateCallRequest.getNumberOfCheck());
|
||||
setIfUpdated(callEntity::getProductId, callEntity::setProductId, updateCallRequest.getProductId());
|
||||
callEntity = callRepository.save(callEntity);
|
||||
|
||||
/** This code is responsible for adding a version history log for the "update call step 1" operation **/
|
||||
@@ -691,6 +701,7 @@ public class CallDao {
|
||||
callDetailsResponseBean.setDescriptionShort(callEntity.getDescriptionShort());
|
||||
callDetailsResponseBean.setDescriptionLong(callEntity.getDescriptionLong());
|
||||
callDetailsResponseBean.setStatus(CallStatusEnum.valueOf(callEntity.getStatus()));
|
||||
callDetailsResponseBean.setEvaluationVersion(EvaluationVersionEnum.valueOf(callEntity.getEvaluationVersion()));
|
||||
callDetailsResponseBean.setRegionId(callEntity.getRegion().getId());
|
||||
callDetailsResponseBean.setAmount(callEntity.getAmount());
|
||||
callDetailsResponseBean.setAmountMax(callEntity.getAmountMax());
|
||||
@@ -706,7 +717,8 @@ public class CallDao {
|
||||
callDetailsResponseBean.setPhoneNumber(callEntity.getPhoneNumber());
|
||||
callDetailsResponseBean.setCreatedDate(callEntity.getCreatedDate());
|
||||
callDetailsResponseBean.setUpdatedDate(callEntity.getUpdatedDate());
|
||||
|
||||
callDetailsResponseBean.setNumberOfCheck(callEntity.getNumberOfCheck());
|
||||
callDetailsResponseBean.setProductId(callEntity.getProductId());
|
||||
return callDetailsResponseBean;
|
||||
}
|
||||
|
||||
@@ -730,6 +742,8 @@ public class CallDao {
|
||||
createCallResponseBean.setFaq(faqService.getFaqByCallId(callEntity.getId()));
|
||||
createCallResponseBean.setAimedTo(amiedTo);
|
||||
createCallResponseBean.setCheckList(checkList);
|
||||
createCallResponseBean.setNumberOfCheck(callEntity.getNumberOfCheck());
|
||||
createCallResponseBean.setProductId(callEntity.getProductId());
|
||||
return createCallResponseBean;
|
||||
}
|
||||
|
||||
@@ -811,7 +825,8 @@ public class CallDao {
|
||||
CallResponse callResponseBean = getCallResponseBean(callEntity);
|
||||
FlowResponseBean flowResponseBean = flowDao.getFlowByCallId(callEntity.getId());
|
||||
List<FormResponseBean> formResponseBean = formDao.getFormsByCallId(callEntity);
|
||||
CallValidatorServiceImpl.validateResponse(callResponseBean,flowResponseBean,formResponseBean);
|
||||
EvaluationFormResponseBean evaluationFormResponseBean = evalualtionFormDao.getEvaluationFormByCallId(callEntity);
|
||||
CallValidatorServiceImpl.validateResponse(callResponseBean,flowResponseBean,formResponseBean,evaluationFormResponseBean);
|
||||
callEntity.setStatus(CallStatusEnum.READY_TO_PUBLISH.getValue());
|
||||
callEntity = callRepository.save(callEntity);
|
||||
|
||||
@@ -1063,4 +1078,15 @@ public class CallDao {
|
||||
return predicates;
|
||||
|
||||
}
|
||||
|
||||
public CallResponse createCallStep2EvaluationV2(CallEntity callEntity, CreateCallRequestStep2EvaluationV2 createCallRequest, UserEntity user) {
|
||||
|
||||
convertToDocumentEntities(createCallRequest.getDocs(), callEntity.getId(), DocumentTypeEnum.DOCUMENT);
|
||||
|
||||
convertToDocumentEntities(createCallRequest.getImages(), callEntity.getId(), DocumentTypeEnum.IMAGES);
|
||||
|
||||
CallResponse createCallResponseBean = getCallResponseBean(callEntity);
|
||||
createCallResponseBean.setCurrentStep(GepafinConstant.EVALUATION_V2_STEP_2);
|
||||
return createCallResponseBean;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -122,10 +122,40 @@ public class CompanyDao {
|
||||
userWithCompanyEntity.setPec(companyRequest.getPec());
|
||||
userWithCompanyEntity.setContactName(companyRequest.getContactName());
|
||||
userWithCompanyEntity.setContactEmail(companyRequest.getContactEmail());
|
||||
userWithCompanyEntity.setJson(Utils.convertMapIntoJsonString(companyRequest.getVatCheckResponse()) );
|
||||
UserWithCompanyEntity userWithCompany = userWithCompanyRepository.save(userWithCompanyEntity);
|
||||
/** This code is responsible for adding a version history log for the "adding user with company" operation. **/
|
||||
loggingUtil.addVersionHistory(VersionHistoryRequest.builder().request(request).actionType(VersionActionTypeEnum.INSERT).oldData(null).newData(userWithCompany).build());
|
||||
if (StringUtils.isEmpty(companyEntity.getJson())) {
|
||||
companyEntity.setJson(Utils.convertMapIntoJsonString(companyRequest.getVatCheckResponse()));
|
||||
Map<String, Object> vatCheckResponse = companyRequest.getVatCheckResponse();
|
||||
Map<String, Object> data = (Map<String, Object>) vatCheckResponse.get("data");
|
||||
if (data != null) {
|
||||
if (data.containsKey("dettaglio")) {
|
||||
Map<String, Object> dettaglio = (Map<String, Object>) data.get("dettaglio");
|
||||
if (dettaglio != null) {
|
||||
if (dettaglio.containsKey("codice_ateco")) {
|
||||
Object codiceAtecoObj = dettaglio.get("codice_ateco");
|
||||
String codiceAteco = (codiceAtecoObj != null) ? codiceAtecoObj.toString() : null;
|
||||
|
||||
if (codiceAteco != null) {
|
||||
companyEntity.setCodiceAteco(codiceAteco);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
companyEntity = companyRepository.save(companyEntity);
|
||||
|
||||
/** This code is responsible for adding a version history log for "updating company json field" operation. **/
|
||||
loggingUtil.addVersionHistory(VersionHistoryRequest.builder()
|
||||
.request(request)
|
||||
.actionType(VersionActionTypeEnum.INSERT)
|
||||
.oldData(null)
|
||||
.newData(companyEntity)
|
||||
.build());
|
||||
}
|
||||
|
||||
return userWithCompany;
|
||||
}
|
||||
|
||||
@@ -143,6 +173,7 @@ public class CompanyDao {
|
||||
entity.setNumberOfEmployees(request.getNumberOfEmployees());
|
||||
entity.setAnnualRevenue(request.getAnnualRevenue());
|
||||
entity.setHub(userEntity.getHub());
|
||||
entity.setJson(Utils.convertMapIntoJsonString(request.getVatCheckResponse()));
|
||||
if (request.getVatCheckResponse() != null) {
|
||||
Map<String, Object> vatCheckResponse = request.getVatCheckResponse();
|
||||
Map<String, Object> data = (Map<String, Object>) vatCheckResponse.get("data");
|
||||
@@ -226,12 +257,12 @@ public class CompanyDao {
|
||||
UserWithCompanyEntity userWithCompanyEntity = getUserWithCompany(userEntity.getId(), companyId);
|
||||
//cloned entity for old data
|
||||
UserWithCompanyEntity oldUserWithCompanyData = Utils.getClonedEntityForData(userWithCompanyEntity);
|
||||
if(StringUtils.isNotBlank(companyRequest.getVatNumber())) {
|
||||
String responseJson = companyRequest.getVatCheckResponse() != null ? Utils.convertMapIntoJsonString(companyRequest.getVatCheckResponse()) : null;
|
||||
setIfUpdated(userWithCompanyEntity::getJson, userWithCompanyEntity::setJson, responseJson);
|
||||
}
|
||||
setIfUpdated(userWithCompanyEntity::getPec, userWithCompanyEntity::setPec, userWithCompanyEntity.getPec());
|
||||
setIfUpdated(userWithCompanyEntity::getEmail, userWithCompanyEntity::setEmail, userWithCompanyEntity.getEmail());
|
||||
// if(StringUtils.isNotBlank(companyRequest.getVatNumber())) {
|
||||
// String responseJson = companyRequest.getVatCheckResponse() != null ? Utils.convertMapIntoJsonString(companyRequest.getVatCheckResponse()) : null;
|
||||
// setIfUpdated(companyEntity::getJson, companyEntity::setJson, responseJson);
|
||||
// }
|
||||
setIfUpdated(userWithCompanyEntity::getPec, userWithCompanyEntity::setPec, companyRequest.getPec());
|
||||
setIfUpdated(userWithCompanyEntity::getEmail, userWithCompanyEntity::setEmail, companyRequest.getEmail());
|
||||
setIfUpdated(userWithCompanyEntity::getContactName, userWithCompanyEntity::setContactName, companyRequest.getContactName());
|
||||
setIfUpdated(userWithCompanyEntity::getContactEmail, userWithCompanyEntity::setContactEmail, companyRequest.getContactEmail());
|
||||
setIfUpdated(userWithCompanyEntity::getIsLegalRepresentant, userWithCompanyEntity::setIsLegalRepresentant, companyRequest.getIsLegalRepresentant());
|
||||
|
||||
@@ -1,35 +1,33 @@
|
||||
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.CompanyEntity;
|
||||
import net.gepafin.tendermanagement.entities.UserActionEntity;
|
||||
import net.gepafin.tendermanagement.entities.UserEntity;
|
||||
import net.gepafin.tendermanagement.entities.UserWithCompanyEntity;
|
||||
import net.gepafin.tendermanagement.entities.*;
|
||||
import net.gepafin.tendermanagement.enums.CallStatusEnum;
|
||||
import net.gepafin.tendermanagement.enums.RoleStatusEnum;
|
||||
import net.gepafin.tendermanagement.enums.UserStatusEnum;
|
||||
import net.gepafin.tendermanagement.model.response.ApplicationWidgetResponseBean;
|
||||
import net.gepafin.tendermanagement.model.response.BeneficiaryWidgetResponseBean;
|
||||
import net.gepafin.tendermanagement.model.response.Widget1;
|
||||
import net.gepafin.tendermanagement.model.response.SuperAdminWidgetResponseBean;
|
||||
import net.gepafin.tendermanagement.enums.*;
|
||||
import net.gepafin.tendermanagement.model.response.*;
|
||||
import net.gepafin.tendermanagement.repositories.*;
|
||||
import net.gepafin.tendermanagement.service.CompanyService;
|
||||
import net.gepafin.tendermanagement.util.Validator;
|
||||
import net.gepafin.tendermanagement.web.rest.api.errors.CustomValidationException;
|
||||
import net.gepafin.tendermanagement.web.rest.api.errors.ForbiddenAccessException;
|
||||
import net.gepafin.tendermanagement.web.rest.api.errors.Status;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.PageRequest;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.math.RoundingMode;
|
||||
import java.util.*;
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.LocalTime;
|
||||
import java.util.List;
|
||||
import java.util.List;
|
||||
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Component
|
||||
@@ -57,13 +55,18 @@ public class DashboardDao {
|
||||
private ApplicationEvaluationRepository applicationEvaluationRepository;
|
||||
|
||||
@Autowired
|
||||
private UserActionsRepository userActionsRepository;
|
||||
private ApplicationAmendmentRequestRepository applicationAmendmentRequestRepository;
|
||||
|
||||
@Autowired
|
||||
private AssignedApplicationsRepository assignedApplicationsRepository;
|
||||
@Autowired
|
||||
private Validator validator;
|
||||
|
||||
public SuperAdminWidgetResponseBean getDashboardWidget(UserEntity requestedUserEntity) {
|
||||
SuperAdminWidgetResponseBean widgetResponseBean = new SuperAdminWidgetResponseBean();
|
||||
widgetResponseBean.setWidget1(createWidget1(requestedUserEntity));
|
||||
Map<String, Object> widgetBars =getStatistics(requestedUserEntity);
|
||||
widgetResponseBean.setWidgetBars(widgetBars);
|
||||
Map<String, Object> widgetBars = getStatistics(requestedUserEntity);
|
||||
widgetResponseBean.setWidgetBars(widgetBars);
|
||||
return widgetResponseBean;
|
||||
}
|
||||
|
||||
@@ -76,8 +79,8 @@ public class DashboardDao {
|
||||
setSubmittedApplications(widget1, requestedUserEntity);
|
||||
setDraftApplications(widget1, requestedUserEntity);
|
||||
setNumberOfCompanies(widget1, requestedUserEntity);
|
||||
setAmountRequested(widget1,requestedUserEntity);
|
||||
setAmountAccepted(widget1,requestedUserEntity);
|
||||
setAmountRequested(widget1, requestedUserEntity);
|
||||
setAmountAccepted(widget1, requestedUserEntity);
|
||||
return widget1;
|
||||
}
|
||||
|
||||
@@ -195,7 +198,8 @@ public class DashboardDao {
|
||||
|
||||
return stats;
|
||||
}
|
||||
// public Page<UserActionEntity> getUserAction(UserEntity requestedUserEntity){
|
||||
|
||||
// public Page<UserActionEntity> getUserAction(UserEntity requestedUserEntity){
|
||||
// Pageable pageable = PageRequest.of(0, 20); // Get the first 20 records
|
||||
// List<String> roles=List.of(RoleStatusEnum.ROLE_PRE_INSTRUCTOR.getValue(),RoleStatusEnum.ROLE_GEPAFIN_OPERATOR.getValue(),RoleStatusEnum.ROLE_INSTRUCTOR_MANAGER.getValue());
|
||||
// Page<UserActionEntity> userActionEntities=userActionsRepository.findActionsByRoleNamesAndHubId(roles,requestedUserEntity.getHub().getId(),pageable);
|
||||
@@ -250,14 +254,15 @@ public class DashboardDao {
|
||||
|
||||
if (Boolean.FALSE.equals(applicationIds.isEmpty())) {
|
||||
BigDecimal averageTime = applicationEvaluationRepository.findAverageEvaluationTimeByApplicationIds(applicationIds);
|
||||
responseBean.setEvaluationAverageTime(averageTime != null ? averageTime : BigDecimal.ZERO);
|
||||
responseBean.setEvaluationAverageTime(averageTime != null ? averageTime.setScale(2, RoundingMode.HALF_UP) : BigDecimal.ZERO);
|
||||
}
|
||||
LocalDate twoDaysLater = LocalDate.now().plusDays(2);
|
||||
|
||||
List<String> statusList = Arrays.asList(ApplicationEvaluationStatusTypeEnum.OPEN.getValue(), ApplicationEvaluationStatusTypeEnum.SOCCORSO.getValue());
|
||||
Long dueApplications = applicationEvaluationRepository.countDueApplicationsBetween(
|
||||
applicationIds,
|
||||
LocalDate.now(),
|
||||
twoDaysLater
|
||||
twoDaysLater,
|
||||
statusList
|
||||
);
|
||||
|
||||
if (dueApplications != null) {
|
||||
@@ -265,5 +270,351 @@ public class DashboardDao {
|
||||
}
|
||||
}
|
||||
|
||||
private AmendmentWidgetResponseBean initializeAmendmentResponseBean() {
|
||||
return AmendmentWidgetResponseBean.builder()
|
||||
.totalAmendments(0L)
|
||||
.waitingForResponseAmendments(0L)
|
||||
.responseReceivedAmendments(0L)
|
||||
.averageResponseDays(BigDecimal.ZERO)
|
||||
.expiringRequestsIn48Hours(0L)
|
||||
.expiredAmendments(0L)
|
||||
.build();
|
||||
}
|
||||
|
||||
public AmendmentWidgetResponseBean getAmendmentDetails(UserEntity userEntity) {
|
||||
AmendmentWidgetResponseBean amendmentWidgetResponseBean = initializeAmendmentResponseBean();
|
||||
|
||||
Long hubId = userEntity.getHub().getId();
|
||||
List<Long> applicationIds = getApplicationIdsForUserOrHub(userEntity, hubId, null);
|
||||
setAmendmentCounts(applicationIds, amendmentWidgetResponseBean, hubId);
|
||||
calculateExpiringRequestsIn48Hours(applicationIds, amendmentWidgetResponseBean, hubId);
|
||||
calculateAverageResponseDays(applicationIds, amendmentWidgetResponseBean, hubId);
|
||||
return amendmentWidgetResponseBean;
|
||||
}
|
||||
|
||||
public List<Long> getApplicationIdsForUserOrHub(UserEntity userEntity, Long hubId, Long userId) {
|
||||
if (userId != null) {
|
||||
return assignedApplicationsRepository.findApplicationIdsByUserIdAndIsDeletedFalse(userId);
|
||||
} else if (validator.checkIsPreInstructor()) {
|
||||
return assignedApplicationsRepository.findApplicationIdsByUserIdAndIsDeletedFalse(userEntity.getId());
|
||||
} else {
|
||||
return applicationRepository.findApplicationIdsByHubId(hubId);
|
||||
}
|
||||
}
|
||||
|
||||
private void setAmendmentCounts(List<Long> applicationIds, AmendmentWidgetResponseBean responseBean, Long hubId) {
|
||||
|
||||
Long totalAmendment = applicationAmendmentRequestRepository.countAmendmentsByApplicationIds(applicationIds);
|
||||
if (totalAmendment != null) {
|
||||
responseBean.setTotalAmendments(totalAmendment);
|
||||
}
|
||||
|
||||
Long awaitingAmendments = applicationAmendmentRequestRepository.countAmendmentsByApplicationIdsAndStatus(
|
||||
applicationIds, ApplicationAmendmentRequestEnum.AWAITING.getValue());
|
||||
if (awaitingAmendments != null) {
|
||||
responseBean.setWaitingForResponseAmendments(awaitingAmendments);
|
||||
}
|
||||
Long responseRecievedAmendments = applicationAmendmentRequestRepository.countAmendmentsByApplicationIdsAndStatus(
|
||||
applicationIds, ApplicationAmendmentRequestEnum.RESPONSE_RECEIVED.getValue());
|
||||
if (responseRecievedAmendments != null) {
|
||||
responseBean.setResponseReceivedAmendments(responseRecievedAmendments);
|
||||
}
|
||||
Long expiredAmendments = applicationAmendmentRequestRepository.countAmendmentsByApplicationIdsAndStatus(
|
||||
applicationIds, ApplicationAmendmentRequestEnum.EXPIRED.getValue());
|
||||
if (expiredAmendments != null) {
|
||||
responseBean.setExpiredAmendments(expiredAmendments);
|
||||
}
|
||||
}
|
||||
|
||||
private void calculateExpiringRequestsIn48Hours(List<Long> applicationIds, AmendmentWidgetResponseBean responseBean, Long hubId) {
|
||||
|
||||
// Define the statuses to filter
|
||||
List<String> statuses = List.of(
|
||||
ApplicationAmendmentRequestEnum.AWAITING.getValue(),
|
||||
ApplicationAmendmentRequestEnum.RESPONSE_RECEIVED.getValue()
|
||||
);
|
||||
|
||||
LocalDateTime twoDaysLater = LocalDateTime.now().plusDays(2);
|
||||
|
||||
Long expiringRequestsIn48Hours = applicationAmendmentRequestRepository.countExpiringRequestsIn48Hours(
|
||||
applicationIds,
|
||||
statuses,
|
||||
LocalDateTime.now(),
|
||||
twoDaysLater
|
||||
);
|
||||
|
||||
if (expiringRequestsIn48Hours != null) {
|
||||
responseBean.setExpiringRequestsIn48Hours(expiringRequestsIn48Hours);
|
||||
}
|
||||
}
|
||||
|
||||
private void calculateAverageResponseDays(List<Long> applicationIds, AmendmentWidgetResponseBean responseBean, Long hubId) {
|
||||
|
||||
if (!applicationIds.isEmpty()) {
|
||||
BigDecimal averageResponseDays = applicationAmendmentRequestRepository
|
||||
.findAverageResponseDaysByApplicationIdsAndStatus(
|
||||
applicationIds,
|
||||
ApplicationAmendmentRequestEnum.CLOSE.getValue()
|
||||
);
|
||||
|
||||
responseBean.setAverageResponseDays(averageResponseDays);
|
||||
} else {
|
||||
responseBean.setAverageResponseDays(BigDecimal.ZERO);
|
||||
}
|
||||
}
|
||||
|
||||
public AssignedApplicationWidgetResponseBean getApplicationDetailsForEvaluation(UserEntity userEntity) {
|
||||
Long userId = userEntity.getId();
|
||||
Long hubId = userEntity.getHub().getId();
|
||||
|
||||
Object[] results;
|
||||
List<Long> applicationIds;
|
||||
if (validator.checkIsPreInstructor()) {
|
||||
results = assignedApplicationsRepository.countAssignedApplicationsWithStatus(userId, hubId);
|
||||
applicationIds = assignedApplicationsRepository.findApplicationIdsByUserIdAndHubIdAndIsDeletedFalse(userId, hubId);
|
||||
} else {
|
||||
results = assignedApplicationsRepository.countAssignedApplicationsForHub(hubId);
|
||||
applicationIds = assignedApplicationsRepository.findApplicationIdsByHubId(hubId);
|
||||
}
|
||||
AssignedApplicationWidgetResponseBean response = convertToResponse(results);
|
||||
calculateEvaluationAvgTimeForAssignedApplication(response, applicationIds);
|
||||
return response;
|
||||
}
|
||||
|
||||
private void calculateEvaluationAvgTimeForAssignedApplication(AssignedApplicationWidgetResponseBean response, List<Long> applicationIds) {
|
||||
if (applicationIds == null || applicationIds.isEmpty()) {
|
||||
response.setAverageEvaluationDays(BigDecimal.ZERO);
|
||||
response.setNumberOfApplicationExpiringIn48Hours(0L);
|
||||
return;
|
||||
}
|
||||
|
||||
BigDecimal averageTime = applicationEvaluationRepository.findAverageEvaluationTimeByApplicationIds(applicationIds);
|
||||
response.setAverageEvaluationDays(averageTime != null ? averageTime.setScale(2, RoundingMode.HALF_UP) : BigDecimal.ZERO);
|
||||
|
||||
LocalDate today = LocalDate.now();
|
||||
LocalDate twoDaysLater = today.plusDays(2);
|
||||
List<String> statusList = Arrays.asList(ApplicationEvaluationStatusTypeEnum.OPEN.getValue(), ApplicationEvaluationStatusTypeEnum.SOCCORSO.getValue());
|
||||
Long dueApplications = applicationEvaluationRepository.countDueApplicationsBetween(
|
||||
applicationIds, today, twoDaysLater, statusList
|
||||
);
|
||||
response.setNumberOfApplicationExpiringIn48Hours(dueApplications != null ? dueApplications : 0L);
|
||||
}
|
||||
|
||||
private AssignedApplicationWidgetResponseBean convertToResponse(Object[] results) {
|
||||
AssignedApplicationWidgetResponseBean response = new AssignedApplicationWidgetResponseBean();
|
||||
|
||||
Object[] data = (Object[]) results[0];
|
||||
|
||||
response.setNumberOfAssignedApplication(data[0] instanceof Number ? ((Number) data[0]).longValue() : 0L);
|
||||
response.setNumberOfApplicationInAmendmentState(data[1] instanceof Number ? ((Number) data[1]).longValue() : 0L);
|
||||
response.setNumberOfApplicationInOpenState(data[2] instanceof Number ? ((Number) data[2]).longValue() : 0L);
|
||||
response.setNumberOfApplicationInCloseState(data[3] instanceof Number ? ((Number) data[3]).longValue() : 0L);
|
||||
|
||||
return response;
|
||||
}
|
||||
|
||||
public static List<String> getStatusList() {
|
||||
return List.of(
|
||||
ApplicationStatusTypeEnum.SUBMIT.getValue(),
|
||||
ApplicationStatusTypeEnum.EVALUATION.getValue(),
|
||||
ApplicationStatusTypeEnum.APPROVED.getValue(),
|
||||
ApplicationStatusTypeEnum.REJECTED.getValue(),
|
||||
ApplicationStatusTypeEnum.SOCCORSO.getValue(),
|
||||
ApplicationStatusTypeEnum.APPOINTMENT.getValue(),
|
||||
ApplicationStatusTypeEnum.NDG.getValue(),
|
||||
ApplicationStatusTypeEnum.ADMISSIBLE.getValue()
|
||||
);
|
||||
}
|
||||
|
||||
public BeneficiaryStatisticsResponseBean getStatisticsPageForBeneficiary(UserEntity userEntity, CompanyEntity company) {
|
||||
BeneficiaryStatisticsResponseBean widgetResponseBean = initializeBeneficiaryStatisticsBean();
|
||||
UserWithCompanyEntity userWithCompanyEntity = companyService.getUserWithCompany(userEntity.getId(), company.getId());
|
||||
Long hubId = userEntity.getHub().getId();
|
||||
List<String> statusList = getStatusList();
|
||||
Long submittedApplication = applicationRepository.countSubmittedApplicationsByHubIdAndUserId(hubId, userEntity.getId(), userWithCompanyEntity.getId(), statusList);
|
||||
Long approvedApplication = getApplicationCountByStatus(hubId, userEntity.getId(), userWithCompanyEntity.getId(), ApplicationStatusTypeEnum.APPROVED);
|
||||
BigDecimal successRate = getSuccessRate(hubId, userEntity.getId(), userWithCompanyEntity.getId());
|
||||
BigDecimal totalAmountRequested = applicationRepository.sumAmountRequestedByHubIdAndUserId(hubId, userEntity.getId(), userWithCompanyEntity.getId());
|
||||
|
||||
updateApplicationWidget(widgetResponseBean.getApplicationWidget(), submittedApplication, approvedApplication, successRate, totalAmountRequested);
|
||||
|
||||
Map<String, Object> widgetBars = getApplicationStatistics(userEntity, userWithCompanyEntity.getId());
|
||||
widgetResponseBean.setApplicationWidgetBars(widgetBars);
|
||||
return widgetResponseBean;
|
||||
}
|
||||
|
||||
private BeneficiaryStatisticsResponseBean initializeBeneficiaryStatisticsBean() {
|
||||
return BeneficiaryStatisticsResponseBean.builder()
|
||||
.applicationWidget(ApplicationWidget.builder()
|
||||
.submittedApplication(0L)
|
||||
.approvedApplication(0L)
|
||||
.successRate(BigDecimal.ZERO)
|
||||
.totalAmountFinanced(BigDecimal.ZERO)
|
||||
.build())
|
||||
.build();
|
||||
}
|
||||
|
||||
private Long getApplicationCountByStatus(Long hubId, Long userId, Long userWithCompanyId, ApplicationStatusTypeEnum status) {
|
||||
return applicationRepository.countSubmittedApplicationsByHubIdAndUserIdAndStatus(hubId, userId, userWithCompanyId, status.getValue());
|
||||
}
|
||||
|
||||
private BigDecimal getSuccessRate(Long hubId, Long userId, Long userWithCompanyId) {
|
||||
return applicationRepository.findSuccessRateByHubIdAndUserIdAndUserWithCompanyId(hubId, userId, userWithCompanyId);
|
||||
}
|
||||
|
||||
private void updateApplicationWidget(ApplicationWidget applicationWidget, Long submittedApplication, Long approvedApplication, BigDecimal successRate, BigDecimal totalAmountRequested) {
|
||||
applicationWidget.setSubmittedApplication(submittedApplication != null ? submittedApplication : 0L);
|
||||
applicationWidget.setApprovedApplication(approvedApplication != null ? approvedApplication : 0L);
|
||||
applicationWidget.setSuccessRate(successRate != null ? successRate : BigDecimal.ZERO);
|
||||
applicationWidget.setTotalAmountFinanced(totalAmountRequested != null ? totalAmountRequested : BigDecimal.ZERO);
|
||||
}
|
||||
|
||||
public Map<String, Object> getApplicationStatistics(UserEntity requestedUser, Long userWithCompanyId) {
|
||||
Map<String, Object> stats = new HashMap<>();
|
||||
|
||||
Map<String, Long> statusData = new HashMap<>();
|
||||
for (ApplicationStatusTypeEnum status : ApplicationStatusTypeEnum.values()) {
|
||||
statusData.put(status.name(), 0L);
|
||||
}
|
||||
|
||||
// Get applications per status
|
||||
List<Object[]> applicationsByStatus = applicationRepository.findApplicationsByStatusAndUserIdAndUserWithCompanyId(
|
||||
requestedUser.getHub().getId(),
|
||||
requestedUser.getId(),
|
||||
userWithCompanyId
|
||||
);
|
||||
|
||||
applicationsByStatus.forEach(result -> {
|
||||
String status = (String) result[0];
|
||||
Long count = (Long) result[1];
|
||||
statusData.put(status, count);
|
||||
});
|
||||
|
||||
List<Map<String, Object>> statusList = statusData.entrySet().stream().map(entry -> {
|
||||
Map<String, Object> statusMap = new HashMap<>();
|
||||
statusMap.put(GepafinConstant.STATUS, entry.getKey());
|
||||
statusMap.put(GepafinConstant.NUMBER_OF_APPLICATION, entry.getValue());
|
||||
return statusMap;
|
||||
}).collect(Collectors.toList());
|
||||
|
||||
stats.put(GepafinConstant.APPLICATION_PER_STATUS, statusList);
|
||||
|
||||
|
||||
// Requested VS Approved Amounts
|
||||
List<Object[]> requestedVsApprovedAmounts = applicationRepository.findRequestedVsApprovedAmountsPerMonth(
|
||||
requestedUser.getHub().getId(),
|
||||
requestedUser.getId(),
|
||||
userWithCompanyId
|
||||
);
|
||||
|
||||
stats.put(GepafinConstant.REQUESTED_VS_APPROVED_AMOUNTS, requestedVsApprovedAmounts.stream().map(result -> {
|
||||
Map<String, Object> data = new HashMap<>();
|
||||
data.put(GepafinConstant.MONTH, result[0]);
|
||||
data.put(GepafinConstant.TOTAL_REQUESTED, result[1]!= null ? result[1] : 0L);
|
||||
data.put(GepafinConstant.TOTAL_APPROVED, result[2] != null ? result[2] : 0L);
|
||||
return data;
|
||||
}).toList());
|
||||
return stats;
|
||||
}
|
||||
private PreInstructorWidgetResponseBean initializeDashboardPreInstructorResponseBean() {
|
||||
return PreInstructorWidgetResponseBean.builder()
|
||||
.assignedApplication(ApplicationToConsider.builder()
|
||||
.totalAssignedApplication(0L)
|
||||
.additionalApplicationPercentage(BigDecimal.ZERO)
|
||||
.build())
|
||||
.evaluatedApplication(EvaluatedApplication.builder()
|
||||
.evaluatedApplication(0L)
|
||||
.dailyAverage(BigDecimal.ZERO)
|
||||
.build())
|
||||
.averageEvaluationDays(AverageEvaluationTime.builder()
|
||||
.averageEvlauationDaysRating(BigDecimal.ZERO)
|
||||
.timeDifferenceFromAverage(BigDecimal.ZERO)
|
||||
.build())
|
||||
.amendmentInProgress(RescueInstructorInProgress.builder()
|
||||
.totalAmendmentInProgress(0L)
|
||||
.expiringToday(0L)
|
||||
.build())
|
||||
.build();
|
||||
}
|
||||
public PreInstructorWidgetResponseBean getDashboardWidgetForPreInstructor(HttpServletRequest request, Long userId) {
|
||||
UserEntity userEntity = 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);
|
||||
if (validator.checkIsInstructorManager() && !userEntity.getId().equals(userId)) {
|
||||
throw new ForbiddenAccessException(Status.FORBIDDEN,
|
||||
Translator.toLocale(GepafinConstant.PERMISSION_DENIED));
|
||||
}
|
||||
}
|
||||
PreInstructorWidgetResponseBean preInstructorWidgetResponseBean = initializeDashboardPreInstructorResponseBean();
|
||||
Long hubId = userEntity.getHub().getId();
|
||||
List<Long> applicationIds = getApplicationIdsForUserOrHub(userEntity, hubId,userId);
|
||||
setPreInstructorWidgets(applicationIds, preInstructorWidgetResponseBean,hubId);
|
||||
calculateAverageEvaluationTime(applicationIds, preInstructorWidgetResponseBean, hubId);
|
||||
return preInstructorWidgetResponseBean;
|
||||
}
|
||||
private void setPreInstructorWidgets(List<Long> applicationIds, PreInstructorWidgetResponseBean responseBean,Long hubId) {
|
||||
List<String> assignedApplicationStatus = Arrays.asList(AssignedApplicationEnum.AWAITING.getValue(), AssignedApplicationEnum.OPEN.getValue());
|
||||
Long totalAssignedApplications = assignedApplicationsRepository.countAssignedApplicationsByApplicationIds(applicationIds,assignedApplicationStatus);
|
||||
if (totalAssignedApplications != null) {
|
||||
responseBean.getAssignedApplication().setTotalAssignedApplication(totalAssignedApplications);
|
||||
}
|
||||
LocalDateTime yesterday = LocalDateTime.now().minusDays(1);
|
||||
|
||||
Long newApplicationsAddedYesterday = assignedApplicationsRepository.countApplicationsAddedYesterdayForHub(applicationIds, hubId, yesterday,assignedApplicationStatus);
|
||||
if (newApplicationsAddedYesterday != null && totalAssignedApplications != null && totalAssignedApplications > 0) {
|
||||
BigDecimal percentageAdded = BigDecimal.valueOf(newApplicationsAddedYesterday)
|
||||
.divide(BigDecimal.valueOf(totalAssignedApplications), 4, RoundingMode.HALF_UP)
|
||||
.multiply(BigDecimal.valueOf(100));
|
||||
responseBean.getAssignedApplication().setAdditionalApplicationPercentage(percentageAdded.setScale(2, RoundingMode.HALF_UP));
|
||||
}
|
||||
|
||||
List<String> statuses = Arrays.asList(ApplicationStatusTypeEnum.APPROVED.getValue(), ApplicationStatusTypeEnum.REJECTED.getValue());
|
||||
LocalDateTime sevenDaysAgo = LocalDateTime.now().minusDays(7);
|
||||
Long evaluatedApplication = assignedApplicationsRepository.countEvaluatedApplicationsInLast7Days(applicationIds, statuses, sevenDaysAgo);
|
||||
if (evaluatedApplication != null) {
|
||||
responseBean.getEvaluatedApplication().setEvaluatedApplication(evaluatedApplication);
|
||||
|
||||
BigDecimal dailyAverage = assignedApplicationsRepository.countDailyAverageEvaluatedApplicationsInLast7Days(applicationIds, statuses, sevenDaysAgo);
|
||||
if (dailyAverage != null) {
|
||||
responseBean.getEvaluatedApplication().setDailyAverage(dailyAverage.setScale(2, RoundingMode.HALF_UP)); // Rounded to 2 decimal places
|
||||
}
|
||||
}
|
||||
List<String> amendmentStatus =Arrays.asList( ApplicationAmendmentRequestEnum.AWAITING.getValue(), ApplicationAmendmentRequestEnum.RESPONSE_RECEIVED.getValue());
|
||||
Long rescueInstructorsInProgress = applicationAmendmentRequestRepository.countAmendmentsByApplicationIds(applicationIds,amendmentStatus);
|
||||
if (rescueInstructorsInProgress != null) {
|
||||
responseBean.getAmendmentInProgress().setTotalAmendmentInProgress(rescueInstructorsInProgress);
|
||||
}
|
||||
calculateExpiringRescueInstructorsToday(applicationIds,responseBean);
|
||||
|
||||
}
|
||||
private void calculateExpiringRescueInstructorsToday(List<Long> applicationIds, PreInstructorWidgetResponseBean responseBean) {
|
||||
List<String> statuses =Arrays.asList( ApplicationAmendmentRequestEnum.AWAITING.getValue(), ApplicationAmendmentRequestEnum.RESPONSE_RECEIVED.getValue());
|
||||
|
||||
LocalDateTime startOfDay = LocalDateTime.now().toLocalDate().atStartOfDay();
|
||||
|
||||
LocalDateTime endOfDay = startOfDay.plusDays(1).minusNanos(1);
|
||||
|
||||
Long expiringToday = applicationAmendmentRequestRepository.countAmendmentsExpiringToday(applicationIds, statuses, startOfDay, endOfDay);
|
||||
|
||||
if (expiringToday != null) {
|
||||
responseBean.getAmendmentInProgress().setExpiringToday(expiringToday);
|
||||
}
|
||||
}
|
||||
|
||||
private void calculateAverageEvaluationTime(List<Long> applicationIds, PreInstructorWidgetResponseBean responseBean, Long hubId) {
|
||||
|
||||
if (Boolean.FALSE.equals(applicationIds.isEmpty())) {
|
||||
BigDecimal averageTime = applicationEvaluationRepository.findAverageEvaluationTimeByApplicationIds(applicationIds);
|
||||
responseBean.getAverageEvaluationDays().setAverageEvlauationDaysRating(
|
||||
averageTime != null ? averageTime.setScale(2, RoundingMode.HALF_UP) : BigDecimal.ZERO.setScale(2, RoundingMode.HALF_UP)
|
||||
);
|
||||
|
||||
//
|
||||
// BigDecimal timeDifference = applicationEvaluationRepository.findTimeDifferenceFromAverage(applicationIds);
|
||||
// responseBean.getAverageEvaluationTime().setTimeDifferenceFromAverage(timeDifference != null ? timeDifference : BigDecimal.ZERO);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -265,7 +265,7 @@ public class EmailNotificationDao {
|
||||
bodyPlaceholders.put("{{protocol_number}}", applicationEntity.getProtocol().getProtocolNumber().toString());
|
||||
bodyPlaceholders.put("{{protocol_date}}", DateTimeUtil.formatCreatedDate(applicationEntity.getProtocol().getCreatedDate()));
|
||||
bodyPlaceholders.put("{{protocol_time}}", DateTimeUtil.parseLocalTimeToString(applicationEntity.getProtocol().getTime(), GepafinConstant.HH_MM_SS));
|
||||
bodyPlaceholders.put("{{form_text}}", applicationEvaluationEntity.getNote());
|
||||
bodyPlaceholders.put("{{form_text}}", applicationEvaluationEntity.getMotivation());
|
||||
|
||||
sendEmail(applicationEntity, SystemEmailTemplatesEntity.SystemEmailTemplatesEntityTypeEnum.INADMISSIBILITY_TEMPLATE, bodyPlaceholders, null,null);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,170 @@
|
||||
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.*;
|
||||
import net.gepafin.tendermanagement.enums.VersionActionTypeEnum;
|
||||
import net.gepafin.tendermanagement.model.request.*;
|
||||
import net.gepafin.tendermanagement.model.response.ContentResponseBean;
|
||||
import net.gepafin.tendermanagement.model.response.EvaluationFormResponseBean;
|
||||
import net.gepafin.tendermanagement.repositories.*;
|
||||
import net.gepafin.tendermanagement.service.EvaluationCriteriaService;
|
||||
import net.gepafin.tendermanagement.util.DateTimeUtil;
|
||||
import net.gepafin.tendermanagement.util.LoggingUtil;
|
||||
import net.gepafin.tendermanagement.util.Utils;
|
||||
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.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
|
||||
@Component
|
||||
public class EvaluationFormDao {
|
||||
|
||||
@Autowired
|
||||
private EvaluationFormRepository evaluationFormRepository;
|
||||
|
||||
@Autowired
|
||||
private CallDao callDao;
|
||||
|
||||
@Autowired
|
||||
private VatCheckDao vatCheckDao;
|
||||
|
||||
@Autowired
|
||||
private CallRepository callRepository;
|
||||
|
||||
@Autowired
|
||||
private Validator validator;
|
||||
|
||||
@Autowired
|
||||
private CriteriaFormFieldRepository criteriaFormFieldRepository;
|
||||
|
||||
@Autowired
|
||||
private EvaluationCriteriaService evaluationCriteriaService;
|
||||
|
||||
@Autowired
|
||||
private LoggingUtil loggingUtil;
|
||||
|
||||
@Autowired
|
||||
private HttpServletRequest request;
|
||||
|
||||
public EvaluationFormEntity saveEvaluationFormEntity(EvaluationFormEntity evaluationFormEntity){
|
||||
evaluationFormEntity= evaluationFormRepository.save(evaluationFormEntity);
|
||||
return evaluationFormEntity;
|
||||
}
|
||||
|
||||
public EvaluationFormEntity convertEvaluationFormRequestToEvaluationFormEntity(CallEntity callEntity, EvaluationFormRequest formRequest) {
|
||||
|
||||
EvaluationFormEntity evaluationFormEntity = new EvaluationFormEntity();
|
||||
evaluationFormEntity.setCall(callEntity);
|
||||
evaluationFormEntity.setLabel(formRequest.getLabel());
|
||||
evaluationFormEntity.setContent(setContentResponseBean(formRequest.getContent()));
|
||||
evaluationFormEntity.setIsDeleted(false);
|
||||
evaluationFormEntity = saveEvaluationFormEntity(evaluationFormEntity);
|
||||
|
||||
/** This code is responsible for adding a version history log for the "Create form" operation. **/
|
||||
loggingUtil.addVersionHistory(VersionHistoryRequest.builder().request(request).actionType(VersionActionTypeEnum.INSERT).oldData(null).newData(evaluationFormEntity).build());
|
||||
|
||||
return evaluationFormEntity;
|
||||
}
|
||||
|
||||
public EvaluationFormResponseBean convertEvaluationFormEntityToEvaluationFormResponseBean(EvaluationFormEntity formEntity) {
|
||||
EvaluationFormResponseBean evaluationFormResponseBean =new EvaluationFormResponseBean();
|
||||
evaluationFormResponseBean.setId(formEntity.getId());
|
||||
evaluationFormResponseBean.setContent(setContent(formEntity));
|
||||
evaluationFormResponseBean.setLabel(formEntity.getLabel());
|
||||
evaluationFormResponseBean.setCallId(formEntity.getCall().getId());
|
||||
evaluationFormResponseBean.setCallStatus(formEntity.getCall().getStatus());
|
||||
return evaluationFormResponseBean;
|
||||
}
|
||||
|
||||
private List<ContentResponseBean> setContent(EvaluationFormEntity formEntity) {
|
||||
List<ContentResponseBean> contentList = Utils.convertJsonStringToList(formEntity.getContent(),
|
||||
ContentResponseBean.class);
|
||||
return contentList;
|
||||
}
|
||||
|
||||
public EvaluationFormResponseBean createEvaluationForm(CallEntity callEntity, EvaluationFormRequest formRequest) {
|
||||
|
||||
validateEvaluationForm(formRequest);
|
||||
EvaluationFormEntity formEntity = convertEvaluationFormRequestToEvaluationFormEntity(callEntity, formRequest);
|
||||
return convertEvaluationFormEntityToEvaluationFormResponseBean(formEntity);
|
||||
}
|
||||
|
||||
public void validateEvaluationForm(EvaluationFormRequest formRequest){
|
||||
if(formRequest.getContent()==null || formRequest.getLabel()==null ){
|
||||
throw new CustomValidationException(Status.VALIDATION_ERROR, Translator.toLocale(GepafinConstant.REQUIRED_PARAMETER_NOT_FOUND_FOR_FORM));
|
||||
}
|
||||
}
|
||||
public EvaluationFormResponseBean updateEvaluationForm(UserEntity user, Long formId, EvaluationFormRequest formRequest) {
|
||||
EvaluationFormEntity evaluationFormEntity = validateForm(formId);
|
||||
//cloned for old form data
|
||||
EvaluationFormEntity oldFormData = Utils.getClonedEntityForData(evaluationFormEntity);
|
||||
|
||||
Utils.setIfUpdated(evaluationFormEntity::getLabel, evaluationFormEntity::setLabel, formRequest.getLabel());
|
||||
Utils.setIfUpdated(evaluationFormEntity::getContent, evaluationFormEntity::setContent, setContentResponseBean(formRequest.getContent()));
|
||||
evaluationFormEntity.setUpdatedDate(DateTimeUtil.DateServerToUTC(LocalDateTime.now()));
|
||||
evaluationFormEntity = saveEvaluationFormEntity(evaluationFormEntity);
|
||||
|
||||
/** This code is responsible for adding a version history log for the "Update form data" operation. **/
|
||||
loggingUtil.addVersionHistory(VersionHistoryRequest.builder().request(request).actionType(VersionActionTypeEnum.UPDATE).oldData(oldFormData).newData(evaluationFormEntity).build());
|
||||
return convertEvaluationFormEntityToEvaluationFormResponseBean(evaluationFormEntity);
|
||||
|
||||
}
|
||||
|
||||
public EvaluationFormEntity validateForm(Long formId) {
|
||||
EvaluationFormEntity evaluationFormEntity = evaluationFormRepository.findByIdAndIsDeletedFalse(formId);
|
||||
if (evaluationFormEntity == null) {
|
||||
throw new ResourceNotFoundException(
|
||||
Status.NOT_FOUND,
|
||||
Translator.toLocale(GepafinConstant.EVALUATION_FORM_NOT_FOUND)
|
||||
);
|
||||
}
|
||||
return evaluationFormEntity;
|
||||
}
|
||||
|
||||
|
||||
public EvaluationFormResponseBean getEvaluationFormById(UserEntity user, Long formId) {
|
||||
EvaluationFormEntity evaluationFormEntity = validateForm(formId);
|
||||
validator.validateUserWithCall(user, evaluationFormEntity.getCall().getId());
|
||||
return convertEvaluationFormEntityToEvaluationFormResponseBean(evaluationFormEntity);
|
||||
}
|
||||
public void deleteEvaluationForm(UserEntity user, Long formId){
|
||||
EvaluationFormEntity evaluationFormEntity = validateForm(formId);
|
||||
EvaluationFormEntity clonedData = Utils.getClonedEntityForData(evaluationFormEntity);
|
||||
validator.validateUserWithCall(user, evaluationFormEntity.getCall().getId());
|
||||
evaluationFormEntity.setIsDeleted(Boolean.TRUE);
|
||||
evaluationFormEntity = saveEvaluationFormEntity(evaluationFormEntity);
|
||||
/** This code is responsible for adding a version history log for the "soft deleting evaluation from field" operation. **/
|
||||
loggingUtil.addVersionHistory(VersionHistoryRequest.builder().request(request).actionType(VersionActionTypeEnum.SOFT_DELETE).oldData(clonedData).newData(evaluationFormEntity).build());
|
||||
|
||||
|
||||
}
|
||||
public EvaluationFormResponseBean getEvaluationFormByCallId(CallEntity callEntity) {
|
||||
if (callEntity == null) {
|
||||
throw new CustomValidationException(Status.VALIDATION_ERROR,
|
||||
Translator.toLocale(GepafinConstant.CALL_NOT_FOUND));
|
||||
}
|
||||
|
||||
EvaluationFormEntity formEntity = evaluationFormRepository
|
||||
.findByCallIdAndIsDeletedFalse(callEntity.getId());
|
||||
if(formEntity!=null)
|
||||
return convertEvaluationFormEntityToEvaluationFormResponseBean(formEntity);
|
||||
else return null;
|
||||
}
|
||||
|
||||
|
||||
public String setContentResponseBean(List<ContentRequestBean> contentRequestBeans){
|
||||
String stringContentRequest = Utils.convertListToJsonString(contentRequestBeans);
|
||||
List<ContentRequestBean> cloneContentRequestBeans = Utils.convertJsonStringToList(stringContentRequest, ContentRequestBean.class);
|
||||
cloneContentRequestBeans.forEach(data->data.setCriteria(null));
|
||||
return Utils.convertListToJsonString(cloneContentRequestBeans);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -305,7 +305,7 @@ public class FlowFormDao {
|
||||
Long totalFormSteps = calculateTotalSteps(flowEdgesList);
|
||||
Long currentStep = calculateCurrentStep(flowEdgesList, formEntity);
|
||||
nextOrPreviousFormResponse.setTotalFormSteps(totalFormSteps);
|
||||
completedSteps = getCompletedSteps(applicationEntity);
|
||||
completedSteps = getCompletedSteps(applicationEntity, false);
|
||||
nextOrPreviousFormResponse.setCompletedSteps(Long.valueOf(completedSteps));
|
||||
nextOrPreviousFormResponse.setCurrentStep(currentStep);
|
||||
if(applicationEntity.getProtocol() != null) {
|
||||
@@ -318,13 +318,13 @@ public class FlowFormDao {
|
||||
return nextOrPreviousFormResponse;
|
||||
}
|
||||
|
||||
public Integer getCompletedSteps(ApplicationEntity applicationEntity) {
|
||||
public Integer getCompletedSteps(ApplicationEntity applicationEntity, Boolean isSendValidationError) {
|
||||
Integer completedSteps=0;
|
||||
List<ApplicationFormEntity> applicationFormList = applicationFormRepository.findByApplicationId(applicationEntity.getId());
|
||||
List<ApplicationFormFieldEntity> applicationFormFieldEntities=new ArrayList<>();
|
||||
for (ApplicationFormEntity applicationFormEntity:applicationFormList){
|
||||
applicationFormFieldEntities=applicationFormFieldRepository.findByApplicationFormId(applicationFormEntity.getId());
|
||||
Boolean isCompleted=formDao.validateCompletedSteps(applicationFormFieldEntities, applicationEntity, applicationFormEntity.getForm());
|
||||
Boolean isCompleted=formDao.validateCompletedSteps(applicationFormFieldEntities, applicationEntity, applicationFormEntity.getForm(), isSendValidationError);
|
||||
if(Boolean.TRUE.equals(isCompleted)){
|
||||
completedSteps++;
|
||||
}
|
||||
@@ -361,7 +361,7 @@ public class FlowFormDao {
|
||||
FormEntity currentFormEntity = applicationFormList.get(applicationFormList.size() - 1).getForm();
|
||||
|
||||
for (ApplicationFormEntity applicationFormEntity : applicationFormList) {
|
||||
Boolean isCompleted = formDao.validateCompletedSteps(applicationFormFieldRepository.findByApplicationFormId(applicationFormEntity.getId()), applicationEntity, applicationFormEntity.getForm());
|
||||
Boolean isCompleted = formDao.validateCompletedSteps(applicationFormFieldRepository.findByApplicationFormId(applicationFormEntity.getId()), applicationEntity, applicationFormEntity.getForm(), false);
|
||||
if (Boolean.FALSE.equals(isCompleted)) {
|
||||
return applicationFormEntity.getForm().getId();
|
||||
}
|
||||
|
||||
@@ -1,9 +1,12 @@
|
||||
package net.gepafin.tendermanagement.dao;
|
||||
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import net.gepafin.tendermanagement.config.Translator;
|
||||
import net.gepafin.tendermanagement.constants.GepafinConstant;
|
||||
import net.gepafin.tendermanagement.entities.*;
|
||||
import net.gepafin.tendermanagement.enums.CallStatusEnum;
|
||||
import net.gepafin.tendermanagement.enums.VersionActionTypeEnum;
|
||||
import net.gepafin.tendermanagement.model.request.*;
|
||||
import net.gepafin.tendermanagement.model.response.ContentResponseBean;
|
||||
@@ -35,6 +38,8 @@ import java.util.stream.Collectors;
|
||||
@Component
|
||||
public class FormDao {
|
||||
|
||||
private final Logger log = LoggerFactory.getLogger(FormDao.class);
|
||||
|
||||
@Autowired
|
||||
private FormRepository formRepository;
|
||||
|
||||
@@ -55,13 +60,13 @@ public class FormDao {
|
||||
|
||||
@Autowired
|
||||
private CallRepository callRepository;
|
||||
|
||||
|
||||
@Autowired
|
||||
private Validator validator;
|
||||
|
||||
@Autowired
|
||||
private CriteriaFormFieldRepository criteriaFormFieldRepository;
|
||||
|
||||
|
||||
@Autowired
|
||||
private EvaluationCriteriaService evaluationCriteriaService;
|
||||
|
||||
@@ -118,6 +123,10 @@ public class FormDao {
|
||||
//cloned entity for old call data.
|
||||
CallEntity oldCallData = Utils.getClonedEntityForData(callEntity);
|
||||
|
||||
if(callEntity.getStatus().equals(CallStatusEnum.PUBLISH.getValue())) {
|
||||
throw new CustomValidationException(Status.VALIDATION_ERROR,
|
||||
Translator.toLocale(GepafinConstant.PUBLISHED_CALL_NOT_UPDATE));
|
||||
}
|
||||
List<FlowDataEntity> flowDataEntities = flowDataRepository.findByCallId(callEntity.getId());
|
||||
List<FlowEdgesEntity> flowEdgesEntities = flowEdgesRepository.findByCallId(callEntity.getId());
|
||||
if (Boolean.FALSE.equals(flowDataEntities.isEmpty() || flowDataEntities == null) || Boolean.FALSE.equals(flowEdgesEntities.isEmpty() || flowEdgesEntities == null)) {
|
||||
@@ -144,7 +153,7 @@ public class FormDao {
|
||||
validateAndSaveCriteriaFormField(callEntity, formEntity, formRequest.getContent());
|
||||
return convertFormEntityToFormResponseBean(formEntity);
|
||||
}
|
||||
|
||||
|
||||
private void validateAndSaveCriteriaFormField(CallEntity callEntity, FormEntity formEntity,
|
||||
List<ContentRequestBean> contentResponseBeans) {
|
||||
|
||||
@@ -198,8 +207,9 @@ public class FormDao {
|
||||
String formFieldId,Long evaluationCriteriaId) {
|
||||
EvaluationCriteriaEntity evaluationCriteria = evaluationCriteriaService.validateEvaluationCriteria(evaluationCriteriaId);
|
||||
if (Boolean.FALSE.equals(evaluationCriteria.getCall().getId().equals(callEntity.getId()))) {
|
||||
throw new CustomValidationException(Status.VALIDATION_ERROR,
|
||||
Translator.toLocale(GepafinConstant.EVALUATIONCRITERIA_INVALID));
|
||||
log.info("This evaluation criterion does not belong to the current call. Expected Call ID = {}, Found Call ID = {}",
|
||||
callEntity.getId(), evaluationCriteria.getCall().getId());
|
||||
return;
|
||||
}
|
||||
CriteriaFormFieldEntity criteriaFormField = new CriteriaFormFieldEntity();
|
||||
criteriaFormField.setCallId(callEntity.getId());
|
||||
@@ -211,7 +221,7 @@ public class FormDao {
|
||||
|
||||
/** This code is responsible for adding a version history log for the "creating criteria form field" operation. **/
|
||||
loggingUtil.addVersionHistory(VersionHistoryRequest.builder().request(request).actionType(VersionActionTypeEnum.INSERT).oldData(null).newData(criteriaFormField).build());
|
||||
|
||||
|
||||
}
|
||||
|
||||
public void validateForm(FormRequest formRequest){
|
||||
@@ -397,9 +407,9 @@ public class FormDao {
|
||||
FieldValidator validator = FieldValidator.create();
|
||||
formResponseBean.getContent().forEach(contentResponseBean -> {
|
||||
String fieldId = contentResponseBean.getId();
|
||||
String value = (String) formFieldMap.get(fieldId);
|
||||
String fieldLabel=contentResponseBean.getLabel();
|
||||
|
||||
Object object=formFieldMap.get(fieldId);
|
||||
String value =Utils.convertToStringForFormFieldValue(object);
|
||||
if(value == null && isApplicationFormExist) {
|
||||
return;
|
||||
}
|
||||
@@ -408,7 +418,7 @@ public class FormDao {
|
||||
.minLength(value, fieldValidatorBean.getMinLength(), fieldLabel) // Only applies if minLength is not null
|
||||
.maxLength(value, fieldValidatorBean.getMaxLength(), fieldLabel) // Only applies if maxLength is not null
|
||||
.matchesPattern(value, fieldValidatorBean.getPattern(), fieldLabel) // Only applies if pattern is present
|
||||
.validateCustom(value, fieldValidatorBean.getCustom(), fieldLabel); // Add the custom validation here
|
||||
.validateCustom(value, fieldValidatorBean.getCustom(), fieldLabel,contentResponseBean); // Add the custom validation here
|
||||
if (fieldValidatorBean.getCustom() != null && fieldValidatorBean.getCustom().equals(GepafinConstant.IS_PIVA)) {
|
||||
String error = validateVatNumber(value, fieldValidatorBean.getCustom(), fieldLabel);
|
||||
if(error != null) {
|
||||
@@ -428,11 +438,14 @@ public class FormDao {
|
||||
for (Object value : list) {
|
||||
setFormFieldMap(fieldId, formFieldMap, value);
|
||||
}
|
||||
}
|
||||
}else if (list.stream().allMatch(item -> item instanceof Map<?, ?> map &&
|
||||
map.keySet().stream().allMatch(String.class::isInstance))) {
|
||||
if (fieldValue != null) {
|
||||
formFieldMap.put(fieldId, fieldValue);
|
||||
}
|
||||
} else setFormFieldMap(fieldId, formFieldMap, fieldValue);
|
||||
}
|
||||
else setFormFieldMap(fieldId, formFieldMap, fieldValue);
|
||||
}
|
||||
|
||||
private void setFormFieldMap(String fieldId, Map<String, Object> formFieldMap, Object value) {
|
||||
if (value instanceof String) {
|
||||
if(value !=null && Boolean.FALSE.equals(StringUtils.isEmpty((String)value))) {
|
||||
@@ -448,12 +461,13 @@ public class FormDao {
|
||||
return false;
|
||||
}
|
||||
|
||||
public Boolean validateCompletedSteps(List<ApplicationFormFieldEntity> applicationFormFieldEntityList, ApplicationEntity applicationEntity, FormEntity formEntity) {
|
||||
public Boolean validateCompletedSteps(List<ApplicationFormFieldEntity> applicationFormFieldEntityList, ApplicationEntity applicationEntity, FormEntity formEntity,
|
||||
Boolean isSendValidationError) {
|
||||
Map<String, Object> formFieldMap = new LinkedHashMap<String, Object>();
|
||||
for(ApplicationFormFieldEntity applicationFormFieldEntity:applicationFormFieldEntityList) {
|
||||
formFieldMap.put(applicationFormFieldEntity.getFieldId(),applicationFormFieldEntity.getFieldValue());
|
||||
}
|
||||
|
||||
|
||||
FormResponseBean formResponseBean = convertFormEntityToFormResponseBean(formEntity);
|
||||
FieldValidator validator = FieldValidator.create();
|
||||
formResponseBean.getContent().forEach(contentResponseBean -> {
|
||||
@@ -461,14 +475,29 @@ public class FormDao {
|
||||
String value = (String) formFieldMap.get(fieldId);
|
||||
|
||||
FieldValidatorBean fieldValidatorBean = Utils.convertSourceObjectToDestinationObject(contentResponseBean.getValidators(), FieldValidatorBean.class);
|
||||
validator
|
||||
.isRequired(value,fieldValidatorBean.getIsRequired(),fieldId);
|
||||
String fieldValue = getFieldValue(contentResponseBean);
|
||||
|
||||
validator.isRequired(value, fieldValidatorBean.getIsRequired(), fieldValue)
|
||||
.validateCustomTableValidation(value,fieldValidatorBean.getCustom(),fieldValue,contentResponseBean);
|
||||
});
|
||||
if (validator.hasErrors()) {
|
||||
return false; // Validation failed, return false
|
||||
if (Boolean.TRUE.equals(isSendValidationError)) {
|
||||
validator.validate();
|
||||
}
|
||||
return true;
|
||||
return !validator.hasErrors();
|
||||
}
|
||||
|
||||
private String getFieldValue(ContentResponseBean contentResponseBean) {
|
||||
// Use Optional with pattern matching for type checks
|
||||
return contentResponseBean.getSettings().stream().filter(setting -> "label".equals(setting.getName()) && setting.getValue() != null)
|
||||
.map(setting -> {
|
||||
if (setting.getValue() instanceof String value) {
|
||||
return value.trim();
|
||||
} else {
|
||||
return String.valueOf(setting.getValue()).trim();
|
||||
}
|
||||
}).filter(value -> !value.isEmpty()).findFirst().orElse(contentResponseBean.getId());
|
||||
}
|
||||
|
||||
public String validateVatNumber(String value,String customRule,String fieldId){
|
||||
String error=null;
|
||||
|
||||
|
||||
@@ -209,6 +209,20 @@ public class NotificationDao {
|
||||
}
|
||||
}
|
||||
|
||||
public void sendNotificationToInstructorManager(Map<String, String> placeHolders, ApplicationEvaluationEntity applicationEvaluationEntity, NotificationTypeEnum notificationTypeEnum) {
|
||||
|
||||
List<UserEntity> userEntities=userRepository.findByRoleEntity_RoleTypeAndHubId(RoleStatusEnum.ROLE_INSTRUCTOR_MANAGER.getValue(),applicationEvaluationEntity.getAssignedApplicationsEntity().getApplication().getHubId());
|
||||
for (UserEntity user:userEntities) {
|
||||
Long instructorId=user.getId();
|
||||
ApplicationEntity application = applicationService.validateApplication(applicationEvaluationEntity.getApplicationId());
|
||||
if (instructorId != null) {
|
||||
NotificationReq notificationreq = createNotificationReq(notificationTypeEnum.getValue(), placeHolders, instructorId, application.getUserWithCompany(),
|
||||
null);
|
||||
sendNotification(notificationreq);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public List<Long> getAllCompanyIdsForUser(Long userId) {
|
||||
|
||||
return userWithCompanyRepository.findActiveCompanyIdsByUserId(userId);
|
||||
|
||||
@@ -152,6 +152,31 @@ public class PdfDao {
|
||||
// Create value cell with rounded corners
|
||||
PdfPTable valueTable = new PdfPTable(1);
|
||||
valueTable.setWidthPercentage(100);
|
||||
|
||||
|
||||
Object finalValue = value;
|
||||
List<Object> criteriaObject = (List<Object>) contentResponseBean.getSettings().stream()
|
||||
.filter(setting -> GepafinConstant.CRITERIA_TABLE_COLUMNS.equals(setting.getName()))
|
||||
.findFirst()
|
||||
.map(setting -> {
|
||||
try {
|
||||
// Assuming setting.getValue() contains the JSON string or object
|
||||
return PdfUtils.extractRows(finalValue);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("Error extracting rows from setting value", e);
|
||||
}
|
||||
})
|
||||
.orElse(null);
|
||||
|
||||
|
||||
// Update value if criteriaObject is not null
|
||||
if (criteriaObject != null) {
|
||||
value = criteriaObject;
|
||||
}
|
||||
|
||||
|
||||
// Update value if criteriaObject is not null
|
||||
|
||||
if (value instanceof List<?>) {
|
||||
// Further check if the list contains Strings
|
||||
List<?> list = (List<?>) value;
|
||||
@@ -181,11 +206,10 @@ public class PdfDao {
|
||||
document.add(valueTable);
|
||||
}
|
||||
else if (!list.isEmpty() && list.get(0) instanceof Map<?, ?>) {
|
||||
Object object = value;
|
||||
String stringvalue = Utils.convertToString(object);
|
||||
List<Map<String, Object>> fieldValueList = Utils.convertJsonStringIntoJsonList(stringvalue);
|
||||
|
||||
document = createPdfTable(fieldValueList, document, contentResponseBean);
|
||||
Object object = value;
|
||||
String stringvalue = Utils.convertToString(object);
|
||||
List<Map<String, Object>> fieldValueList = Utils.convertJsonStringIntoJsonList(stringvalue);
|
||||
document = createPdfTable(fieldValueList, document, contentResponseBean);
|
||||
}
|
||||
}
|
||||
else {
|
||||
@@ -231,27 +255,29 @@ public class PdfDao {
|
||||
document.add(valueTable);
|
||||
}
|
||||
else {
|
||||
String fieldValue1= (String) value;
|
||||
if(Utils.isValidDateString(fieldValue1)){
|
||||
fieldValue1=Utils.formatDateString(String.valueOf(value));
|
||||
}
|
||||
if(Boolean.TRUE.equals(Utils.isItalianFormattedAmount(fieldValue)) ){
|
||||
fieldValue= String.valueOf(Utils.convertToItalianFormat(fieldValue));
|
||||
}
|
||||
if (value instanceof String) {
|
||||
String fieldValue1 = (String) value;
|
||||
if (Utils.isValidDateString(fieldValue1)) {
|
||||
fieldValue1 = Utils.formatDateString(String.valueOf(value));
|
||||
}
|
||||
if(contentResponseBean.getName().equals("numberinput") && Boolean.TRUE.equals(Utils.isNumeric(fieldValue))){
|
||||
fieldValue1=Utils.convertToItalianFormat(fieldValue);
|
||||
}
|
||||
// PdfPCell valueCell = new PdfPCell(new Phrase(fieldValue1, valueFont));
|
||||
PdfPCell valueCell = PdfUtils.htmlToPdfPCell(fieldValue1, valueFont);
|
||||
valueCell.setMinimumHeight(30f); // Set a fixed height for the cell
|
||||
valueCell.setPaddingLeft(10f); // Adjust left padding as needed
|
||||
valueCell.setPaddingTop(0f); // Remove padding from top to allow vertical centering
|
||||
valueCell.setPaddingBottom(6f);
|
||||
valueCell.setPaddingLeft(leftMargin); // Increase left margin for value
|
||||
valueCell.setBorder(Rectangle.NO_BORDER); // Remove border for value cell
|
||||
valueCell.setVerticalAlignment(Element.ALIGN_MIDDLE);
|
||||
valueCell.setHorizontalAlignment(Element.ALIGN_LEFT);
|
||||
valueCell.setCellEvent(new RoundedCorners()); // Apply rounded corners
|
||||
valueTable.addCell(valueCell);
|
||||
document.add(valueTable);
|
||||
}
|
||||
PdfPCell valueCell = PdfUtils.htmlToPdfPCell(fieldValue1, valueFont);
|
||||
valueCell.setMinimumHeight(30f); // Set a fixed height for the cell
|
||||
valueCell.setPaddingLeft(10f); // Adjust left padding as needed
|
||||
valueCell.setPaddingTop(0f); // Remove padding from top to allow vertical centering
|
||||
valueCell.setPaddingBottom(6f);
|
||||
valueCell.setPaddingLeft(leftMargin); // Increase left margin for value
|
||||
valueCell.setBorder(Rectangle.NO_BORDER); // Remove border for value cell
|
||||
valueCell.setVerticalAlignment(Element.ALIGN_MIDDLE);
|
||||
valueCell.setHorizontalAlignment(Element.ALIGN_LEFT);
|
||||
valueCell.setCellEvent(new RoundedCorners()); // Apply rounded corners
|
||||
valueTable.addCell(valueCell);
|
||||
document.add(valueTable);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
document.add(new Paragraph("\n")); // Add line break after each value
|
||||
@@ -264,11 +290,12 @@ public class PdfDao {
|
||||
Map<String, Boolean> formulaEnabledMap = new HashMap<>();
|
||||
Map<String, String> formulaTypeMap = new HashMap<>();
|
||||
Map<String, String> fieldTypeMap = new HashMap<>();
|
||||
Map<String, String> totalMap = new HashMap<>();
|
||||
Font lightGrayFont = FontFactory.getFont(FontFactory.HELVETICA, 12, Font.NORMAL, new BaseColor(110, 110, 110)); // Light gray
|
||||
|
||||
|
||||
contentResponseBean.getSettings().stream()
|
||||
.filter(setting -> "table_columns".equals(setting.getName())) // Check for "table_columns"
|
||||
.filter(setting -> "table_columns".equals(setting.getName()) || "criteria_table_columns".equals(setting.getName())) // Check for "table_columns"
|
||||
.map(SettingResponseBean::getValue)
|
||||
.filter(Objects::nonNull) // Ensure value is not null
|
||||
.filter(settingValue -> settingValue instanceof Map) // Ensure value is a Map
|
||||
@@ -283,7 +310,7 @@ public class PdfDao {
|
||||
Boolean isFormulaEnabled = (Boolean) fieldData.get("enableFormula");
|
||||
String formulaType = (String) fieldData.get("lastRowFormula");
|
||||
String fieldType = (String) fieldData.get("fieldtype"); // Get the field type (e.g., numeric)
|
||||
|
||||
String total= (String) fieldData.get("lastRowText");
|
||||
if (fieldName != null && fieldDataValue != null) {
|
||||
stateFieldMap.put(fieldName, fieldDataValue);
|
||||
}
|
||||
@@ -297,6 +324,9 @@ public class PdfDao {
|
||||
if (fieldType != null) {
|
||||
fieldTypeMap.put(fieldName, fieldType); // Store the fieldType in the map
|
||||
}
|
||||
if(total!=null){
|
||||
totalMap.put(fieldName,total);
|
||||
}
|
||||
});
|
||||
|
||||
PdfPTable table = new PdfPTable(stateFieldMap.size()); // Number of columns equals the number of map entries
|
||||
@@ -340,13 +370,17 @@ public class PdfDao {
|
||||
for (String key : orderedKeys) {
|
||||
if (stateFieldMap.containsKey(key)) { // Only add data cell if key is in stateFieldMap
|
||||
Object value = row.getOrDefault(key, ""); // Fetch value or use empty string if key not present
|
||||
String fieldValue= (String) value;
|
||||
if(Boolean.TRUE.equals(Utils.isItalianFormattedAmount(fieldValue)) ){
|
||||
fieldValue= String.valueOf(Utils.convertToItalianFormat(fieldValue));
|
||||
}
|
||||
// String fieldValue= (String) value;
|
||||
String fieldValue = value != null ? value.toString() : "";
|
||||
// if(Boolean.TRUE.equals(Utils.isItalianFormattedAmount(fieldValue)) ){
|
||||
//// fieldValue= String.valueOf(Utils.convertToItalianFormat(fieldValue));
|
||||
// }
|
||||
if (Boolean.TRUE.equals(formulaEnabledMap.get(key)) && Boolean.TRUE.equals(GepafinConstant.NUMERIC.equalsIgnoreCase(fieldTypeMap.get(key)))) {
|
||||
calculateValue(key, fieldValue, formulaTypeMap, columnSums);
|
||||
}
|
||||
if(Boolean.TRUE.equals(Utils.isNumeric(fieldValue))){
|
||||
fieldValue=Utils.convertToItalianFormat(fieldValue);
|
||||
}
|
||||
|
||||
PdfPCell dataCell = PdfUtils.htmlToPdfPCell(fieldValue != null ? fieldValue : "", textFont);
|
||||
dataCell.setBackgroundColor(new BaseColor(239, 243, 248)); // Light blue for the cell
|
||||
@@ -396,14 +430,19 @@ public class PdfDao {
|
||||
table.addCell(emptyCell);
|
||||
}
|
||||
} else {
|
||||
PdfPCell emptyCell = new PdfPCell(new Phrase(""));
|
||||
String total=null;
|
||||
if (totalMap.containsKey(key)) {
|
||||
total=totalMap.getOrDefault(key, "");
|
||||
}
|
||||
PdfPCell emptyCell = new PdfPCell(new Phrase(total,lightGrayFont));
|
||||
emptyCell.setPaddingTop(8f);
|
||||
emptyCell.setPaddingLeft(8f);
|
||||
emptyCell.setBackgroundColor(new BaseColor(239, 243, 248));
|
||||
table.addCell(emptyCell);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
// Add the last table to the document
|
||||
document.add(table);
|
||||
|
||||
@@ -414,7 +453,7 @@ public class PdfDao {
|
||||
try {
|
||||
if (Boolean.FALSE.equals(StringUtils.isEmpty(fieldValue))) {
|
||||
// Use Locale.ITALY to parse the number with the Italian format (comma as decimal separator)
|
||||
NumberFormat format = NumberFormat.getInstance(Locale.ITALY);
|
||||
NumberFormat format = NumberFormat.getInstance(Locale.ENGLISH);
|
||||
Number number = format.parse(fieldValue); // Parse the fieldValue as a number
|
||||
double numericValue = number.doubleValue(); // Convert the parsed number to double
|
||||
|
||||
|
||||
@@ -33,10 +33,10 @@ public class SystemEmailTemplatesDao {
|
||||
public SystemEmailTemplateResponse retrieveTemplate(SystemEmailTemplatesEntityTypeEnum type, HubEntity hub, Locale language) {
|
||||
SystemEmailTemplatesEntity dbSystemEmailTemplatesEntity = null;
|
||||
if(hub != null){
|
||||
// dbSystemEmailTemplatesEntity = systemEmailTemplatesRespository
|
||||
// .findByTypeAndCallId(type.getValue(), call.getId());
|
||||
dbSystemEmailTemplatesEntity = systemEmailTemplatesRespository
|
||||
.findByTypeAndHubEntityId(type.getValue(), hub.getId());
|
||||
}
|
||||
if(dbSystemEmailTemplatesEntity == null) {
|
||||
if(dbSystemEmailTemplatesEntity == null){
|
||||
dbSystemEmailTemplatesEntity = systemEmailTemplatesRespository
|
||||
.findByType(type.getValue());
|
||||
}
|
||||
|
||||
@@ -24,6 +24,7 @@ import net.gepafin.tendermanagement.util.LoggingUtil;
|
||||
import net.gepafin.tendermanagement.util.Utils;
|
||||
import net.gepafin.tendermanagement.util.Validator;
|
||||
import net.gepafin.tendermanagement.web.rest.api.errors.CustomValidationException;
|
||||
import net.gepafin.tendermanagement.web.rest.api.errors.ForbiddenAccessException;
|
||||
import net.gepafin.tendermanagement.web.rest.api.errors.ResourceNotFoundException;
|
||||
import net.gepafin.tendermanagement.web.rest.api.errors.Status;
|
||||
|
||||
@@ -622,7 +623,6 @@ public class UserDao {
|
||||
Specification<UserEntity> spec = search(userPaginationRequestBean,userEntity);
|
||||
Page<UserEntity> entityPage = userRepository.findAll(spec, PageRequest.of(pageNo - 1, pageLimit));
|
||||
|
||||
|
||||
List<UserResponseBean> applicationResponses = entityPage.getContent().stream()
|
||||
.map(user -> {
|
||||
UserResponseBean response = convertUserEntityToUserResponse(user);
|
||||
@@ -753,4 +753,54 @@ public class UserDao {
|
||||
return predicates;
|
||||
|
||||
}
|
||||
|
||||
public UserResponseBean updateUserDetails(HttpServletRequest request , Long userId, UpdateUserReqForBeneficiary userReq){
|
||||
log.info("Updating user by beneficiary with ID: {}", userId);
|
||||
UserEntity userEntity = validator.validateUserId(request, userId);
|
||||
|
||||
UserEntity oldUserEntity = Utils.getClonedEntityForData(userEntity);
|
||||
log.info("Current user details: {}", userEntity);
|
||||
log.info("New user details: {}", userReq);
|
||||
|
||||
HubEntity hubEntity = hubService.valdateHub(userEntity.getHub().getId());
|
||||
String beneficiaryRoleType = RoleStatusEnum.ROLE_BENEFICIARY.getValue();
|
||||
|
||||
if (validator.checkIsBeneficiary()) {
|
||||
// Validate if the new email already exists for another beneficiary in the same hub
|
||||
boolean emailExistsForBeneficiary = userRepository.existsByEmailIgnoreCaseForBeneficiaries(
|
||||
userReq.getEmail(), hubEntity.getUniqueUuid(), beneficiaryRoleType);
|
||||
|
||||
if (emailExistsForBeneficiary) {
|
||||
throw new CustomValidationException(Status.VALIDATION_ERROR,
|
||||
Translator.toLocale(GepafinConstant.EMAIL_ALREADY_EXISTS));
|
||||
}
|
||||
|
||||
setIfUpdated(userEntity::getEmail,userEntity::setEmail,userReq.getEmail()); // Only update email if role is beneficiary
|
||||
}
|
||||
|
||||
BeneficiaryEntity oldBeneficiaryEntity = null;
|
||||
|
||||
if(userEntity.getBeneficiary()!=null) {
|
||||
oldBeneficiaryEntity = Utils.getClonedEntityForData(userEntity.getBeneficiary());
|
||||
setIfUpdated(userEntity.getBeneficiary()::getFirstName, userEntity.getBeneficiary()::setFirstName, userReq.getFirstName());
|
||||
setIfUpdated(userEntity.getBeneficiary()::getLastName, userEntity.getBeneficiary()::setLastName, userReq.getLastName());
|
||||
setIfUpdated(userEntity.getBeneficiary()::getOrganization, userEntity.getBeneficiary()::setOrganization, userReq.getOrganization());
|
||||
setIfUpdated(userEntity.getBeneficiary()::getAddress, userEntity.getBeneficiary()::setAddress, userReq.getAddress());
|
||||
setIfUpdated(userEntity.getBeneficiary()::getPhoneNumber, userEntity.getBeneficiary()::setPhoneNumber, userReq.getPhoneNumber());
|
||||
setIfUpdated(userEntity.getBeneficiary()::getDateOfBirth, userEntity.getBeneficiary()::setDateOfBirth, userReq.getDateOfBirth());
|
||||
setIfUpdated(userEntity.getBeneficiary()::getCity, userEntity.getBeneficiary()::setCity, userReq.getCity());
|
||||
setIfUpdated(userEntity.getBeneficiary()::getCountry, userEntity.getBeneficiary()::setCountry, userReq.getCountry());
|
||||
|
||||
/** This code is responsible for adding a version history log for the "Update beneficiary details " operation **/
|
||||
loggingUtil.addVersionHistory(VersionHistoryRequest.builder().request(request).actionType(VersionActionTypeEnum.INSERT).oldData(oldBeneficiaryEntity).newData(userEntity.getBeneficiary()).build());
|
||||
}
|
||||
|
||||
userEntity = userRepository.save(userEntity);
|
||||
|
||||
/** This code is responsible for adding a version history log for the "Update user details by beneficiary" operation **/
|
||||
loggingUtil.addVersionHistory(VersionHistoryRequest.builder().request(request).actionType(VersionActionTypeEnum.INSERT).oldData(oldUserEntity).newData(userEntity).build());
|
||||
|
||||
return convertUserEntityToUserResponse(userEntity);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user