Merge pull request #83 from Kitzanos/feature/GEPAFINBE-82
GEPFINBE-82 (Changes in get evaluation api -Updated the response for criteria mapped fields)
This commit is contained in:
@@ -1,6 +1,9 @@
|
|||||||
package net.gepafin.tendermanagement.dao;
|
package net.gepafin.tendermanagement.dao;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
import com.fasterxml.jackson.core.type.TypeReference;
|
import com.fasterxml.jackson.core.type.TypeReference;
|
||||||
|
import com.fasterxml.jackson.databind.JsonNode;
|
||||||
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import net.gepafin.tendermanagement.config.Translator;
|
import net.gepafin.tendermanagement.config.Translator;
|
||||||
import net.gepafin.tendermanagement.constants.GepafinConstant;
|
import net.gepafin.tendermanagement.constants.GepafinConstant;
|
||||||
import net.gepafin.tendermanagement.entities.*;
|
import net.gepafin.tendermanagement.entities.*;
|
||||||
@@ -24,6 +27,7 @@ import java.util.*;
|
|||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import static net.gepafin.tendermanagement.util.Utils.setIfUpdated;
|
import static net.gepafin.tendermanagement.util.Utils.setIfUpdated;
|
||||||
|
import static org.apache.commons.lang3.StringUtils.isNumeric;
|
||||||
|
|
||||||
@Component
|
@Component
|
||||||
public class ApplicationEvaluationDao {
|
public class ApplicationEvaluationDao {
|
||||||
@@ -48,7 +52,6 @@ public class ApplicationEvaluationDao {
|
|||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private FormRepository formRepository;
|
private FormRepository formRepository;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private CallTargetAudienceChecklistRepository callTargetAudienceChecklistRepository;
|
private CallTargetAudienceChecklistRepository callTargetAudienceChecklistRepository;
|
||||||
|
|
||||||
@@ -163,10 +166,8 @@ public class ApplicationEvaluationDao {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private List<CriteriaMappedField> getMappedFieldsForCriteria(Long evaluationCriteriaId, Long applicationId) {
|
private List<CriteriaMappedField> getMappedFieldsForCriteria(Long evaluationCriteriaId, Long applicationId) {
|
||||||
|
|
||||||
List<CriteriaFormFieldEntity> criteriaFormFields = criteriaFormFieldRepository.findByEvaluationCriteriaIdAndIsDeletedFalse(evaluationCriteriaId);
|
List<CriteriaFormFieldEntity> criteriaFormFields = criteriaFormFieldRepository.findByEvaluationCriteriaIdAndIsDeletedFalse(evaluationCriteriaId);
|
||||||
List<CriteriaMappedField> mappedFields = new ArrayList<>();
|
List<CriteriaMappedField> mappedFields = new ArrayList<>();
|
||||||
|
|
||||||
Set<String> uniqueFieldIds = new HashSet<>();
|
Set<String> uniqueFieldIds = new HashSet<>();
|
||||||
|
|
||||||
List<ApplicationFormEntity> applicationForms = applicationFormRepository.findByApplicationId(applicationId);
|
List<ApplicationFormEntity> applicationForms = applicationFormRepository.findByApplicationId(applicationId);
|
||||||
@@ -178,28 +179,31 @@ public class ApplicationEvaluationDao {
|
|||||||
CriteriaMappedField mappedField = new CriteriaMappedField();
|
CriteriaMappedField mappedField = new CriteriaMappedField();
|
||||||
mappedField.setId(formFieldId);
|
mappedField.setId(formFieldId);
|
||||||
|
|
||||||
FormEntity formEntity = formRepository.findById(formField.getFormId()).orElse(null);
|
FormEntity formEntity = getFormEntity(formField.getFormId());
|
||||||
if (formEntity != null) {
|
if (formEntity != null) {
|
||||||
List<ContentResponseBean> contentBeans = Utils.convertJsonStringToList(formEntity.getContent(), ContentResponseBean.class);
|
List<ContentResponseBean> contentBeans = Utils.convertJsonStringToList(formEntity.getContent(), ContentResponseBean.class);
|
||||||
contentBeans.stream().filter(contentBean -> contentBean.getId().equals(formFieldId)).findFirst().ifPresent(contentBean -> {
|
contentBeans.stream()
|
||||||
String label = contentBean.getLabel();
|
.filter(contentBean -> contentBean.getId().equals(formFieldId))
|
||||||
if (contentBean.getSettings() != null) {
|
.findFirst()
|
||||||
for (SettingResponseBean setting : contentBean.getSettings()) {
|
.ifPresent(contentBean -> {
|
||||||
if ("label".equals(setting.getName())) {
|
mappedField.setFieldLabel(getLabelForField(contentBean));
|
||||||
label = setting.getValue() != null ? setting.getValue().toString() : label;
|
switch (contentBean.getName()) {
|
||||||
break;
|
case "fileupload":
|
||||||
|
mapFileFieldDetails(mappedField, formFieldId, applicationForm.getId(), applicationId);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case "checkboxes":
|
||||||
|
populateOptionFieldsAsFieldValue(mappedField, formFieldId, applicationForm, applicationId, contentBean);
|
||||||
|
break;
|
||||||
|
case "paragraph":
|
||||||
|
handleParagraphField(applicationId, formField, contentBean, mappedField);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
populateOptionFieldsAsFieldValue(mappedField, formFieldId, applicationForm, applicationId, contentBean);
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
}
|
|
||||||
mappedField.setFieldLabel(label);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Optional<ApplicationFormFieldEntity> formFieldEntityOptional = applicationFormFieldRepository.findByFieldIdAndApplicationFormIdAndApplicationFormApplicationId(
|
|
||||||
formFieldId, applicationForm.getId(), applicationId);
|
|
||||||
|
|
||||||
formFieldEntityOptional.ifPresent(field -> mappedField.setFieldValue(field.getFieldValue()));
|
|
||||||
|
|
||||||
mappedFields.add(mappedField);
|
mappedFields.add(mappedField);
|
||||||
uniqueFieldIds.add(formFieldId);
|
uniqueFieldIds.add(formFieldId);
|
||||||
}
|
}
|
||||||
@@ -208,6 +212,58 @@ public class ApplicationEvaluationDao {
|
|||||||
return mappedFields;
|
return mappedFields;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private FormEntity getFormEntity(Long formId) {
|
||||||
|
return formRepository.findById(formId).orElse(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getLabelForField(ContentResponseBean contentBean) {
|
||||||
|
String label = contentBean.getLabel();
|
||||||
|
if (contentBean.getSettings() != null) {
|
||||||
|
for (SettingResponseBean setting : contentBean.getSettings()) {
|
||||||
|
if ("label".equals(setting.getName())) {
|
||||||
|
label = setting.getValue() != null ? setting.getValue().toString() : label;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return label;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void mapFileFieldDetails(CriteriaMappedField mappedField, String formFieldId, Long applicationFormId, Long applicationId) {
|
||||||
|
Optional<ApplicationFormFieldEntity> formFieldEntityOptional = applicationFormFieldRepository
|
||||||
|
.findByFieldIdAndApplicationFormIdAndApplicationFormApplicationId(formFieldId, applicationFormId, applicationId);
|
||||||
|
|
||||||
|
if (formFieldEntityOptional.isPresent()) {
|
||||||
|
String[] documentIds = formFieldEntityOptional.get().getFieldValue().split(",");
|
||||||
|
List<DocumentResponseBean> documentResponseBeans = new ArrayList<>();
|
||||||
|
|
||||||
|
for (String docId : documentIds) {
|
||||||
|
Long documentId = Long.valueOf(docId.trim());
|
||||||
|
documentRepository.findByIdAndNotDeleted(documentId).ifPresent(documentEntity -> {
|
||||||
|
DocumentResponseBean responseBean = new DocumentResponseBean();
|
||||||
|
responseBean.setId(documentEntity.getId());
|
||||||
|
responseBean.setName(documentEntity.getFileName());
|
||||||
|
responseBean.setType(DocumentTypeEnum.valueOf(documentEntity.getType()));
|
||||||
|
responseBean.setSource(DocumentSourceTypeEnum.valueOf(documentEntity.getSource()));
|
||||||
|
responseBean.setSourceId(documentEntity.getSourceId());
|
||||||
|
responseBean.setFilePath(documentEntity.getFilePath());
|
||||||
|
responseBean.setCreatedDate(documentEntity.getCreatedDate());
|
||||||
|
responseBean.setUpdatedDate(documentEntity.getUpdatedDate());
|
||||||
|
documentResponseBeans.add(responseBean);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
mappedField.setFieldValue(documentResponseBeans);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private void mapNonFileFieldDetails(CriteriaMappedField mappedField, String formFieldId, Long applicationFormId, Long applicationId) {
|
||||||
|
applicationFormFieldRepository
|
||||||
|
.findByFieldIdAndApplicationFormIdAndApplicationFormApplicationId(formFieldId, applicationFormId, applicationId)
|
||||||
|
.ifPresent(field -> mappedField.setFieldValue(field.getFieldValue()));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
private void setChecklistResponses(ApplicationEvaluationEntity entity, ApplicationEvaluationResponse response, List<CallTargetAudienceChecklistEntity> checklistEntities) {
|
private void setChecklistResponses(ApplicationEvaluationEntity entity, ApplicationEvaluationResponse response, List<CallTargetAudienceChecklistEntity> checklistEntities) {
|
||||||
|
|
||||||
List<ChecklistResponse> checklistResponsesFromEntity = entity.getChecklist() != null ?
|
List<ChecklistResponse> checklistResponsesFromEntity = entity.getChecklist() != null ?
|
||||||
@@ -562,57 +618,23 @@ public class ApplicationEvaluationDao {
|
|||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setCriteriaResponses(ApplicationEvaluationEntity entity, Long applicationId, ApplicationEvaluationResponse response,
|
private void setCriteriaResponses(ApplicationEvaluationEntity entity, Long applicationId,
|
||||||
List<EvaluationCriteriaEntity> evaluationCriterias) {
|
ApplicationEvaluationResponse response,
|
||||||
|
List<EvaluationCriteriaEntity> evaluationCriterias) {
|
||||||
|
|
||||||
List<CriteriaResponse> criteriaResponses = entity.getCriteria() != null ? Utils.convertJsonToList(entity.getCriteria(), new TypeReference<List<CriteriaResponse>>() {
|
List<CriteriaResponse> criteriaResponses = getInitialCriteriaResponses(entity, applicationId);
|
||||||
}) : getCriteriaResponse(applicationId);
|
|
||||||
|
|
||||||
criteriaResponses.forEach(criteriaResponse -> {
|
criteriaResponses.forEach(criteriaResponse -> {
|
||||||
EvaluationCriteriaEntity matchingEvaluationCriteria = evaluationCriterias.stream()
|
EvaluationCriteriaEntity matchingEvaluationCriteria =
|
||||||
.filter(evaluationCriteria -> evaluationCriteria.getId().equals(criteriaResponse.getId())).findFirst().orElse(null);
|
findMatchingEvaluationCriteria(criteriaResponse, evaluationCriterias);
|
||||||
|
|
||||||
List<ApplicationFormEntity> applicationForms = applicationFormRepository.findByApplicationId(applicationId);
|
|
||||||
Map<String, CriteriaMappedField> mappedFieldMap = new HashMap<>();
|
|
||||||
|
|
||||||
if (matchingEvaluationCriteria != null) {
|
if (matchingEvaluationCriteria != null) {
|
||||||
|
List<ApplicationFormEntity> applicationForms = applicationFormRepository.findByApplicationId(applicationId);
|
||||||
|
Map<String, CriteriaMappedField> mappedFieldMap = populateMappedFields(
|
||||||
|
matchingEvaluationCriteria, applicationForms, applicationId);
|
||||||
|
|
||||||
criteriaResponse.setLabel(matchingEvaluationCriteria.getLookupData().getValue());
|
criteriaResponse.setLabel(matchingEvaluationCriteria.getLookupData().getValue());
|
||||||
criteriaResponse.setMaxScore(matchingEvaluationCriteria.getScore());
|
criteriaResponse.setMaxScore(matchingEvaluationCriteria.getScore());
|
||||||
|
|
||||||
List<CriteriaFormFieldEntity> criteriaFormFields = criteriaFormFieldRepository.findByEvaluationCriteriaIdAndIsDeletedFalse(matchingEvaluationCriteria.getId());
|
|
||||||
|
|
||||||
for (ApplicationFormEntity applicationForm : applicationForms) {
|
|
||||||
for (CriteriaFormFieldEntity criteriaFormField : criteriaFormFields) {
|
|
||||||
String formFieldId = criteriaFormField.getFormFieldId();
|
|
||||||
if (!mappedFieldMap.containsKey(formFieldId)) {
|
|
||||||
CriteriaMappedField mappedField = new CriteriaMappedField();
|
|
||||||
mappedField.setId(formFieldId);
|
|
||||||
FormEntity formEntity = formRepository.findById(criteriaFormField.getFormId()).orElse(null);
|
|
||||||
|
|
||||||
if (formEntity != null) {
|
|
||||||
List<ContentResponseBean> contentResponseBeans = Utils.convertJsonStringToList(formEntity.getContent(), ContentResponseBean.class);
|
|
||||||
contentResponseBeans.stream().filter(bean -> bean.getId().equals(formFieldId)).findFirst().ifPresent(contentResponseBean -> {
|
|
||||||
String label = contentResponseBean.getLabel();
|
|
||||||
if (contentResponseBean.getSettings() != null) {
|
|
||||||
for (SettingResponseBean setting : contentResponseBean.getSettings()) {
|
|
||||||
if ("label".equals(setting.getName())) {
|
|
||||||
label = setting.getValue() != null ? setting.getValue().toString() : label;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
mappedField.setFieldLabel(label);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
Optional<ApplicationFormFieldEntity> formFieldEntityOptional =
|
|
||||||
applicationFormFieldRepository.findByFieldIdAndApplicationFormIdAndApplicationFormApplicationId(
|
|
||||||
formFieldId, applicationForm.getId(), applicationId);
|
|
||||||
|
|
||||||
formFieldEntityOptional.ifPresent(formField -> mappedField.setFieldValue(formField.getFieldValue()));
|
|
||||||
mappedFieldMap.put(formFieldId, mappedField);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
criteriaResponse.setCriteriaMappedFields(new ArrayList<>(mappedFieldMap.values()));
|
criteriaResponse.setCriteriaMappedFields(new ArrayList<>(mappedFieldMap.values()));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -620,6 +642,159 @@ public class ApplicationEvaluationDao {
|
|||||||
response.setCriteria(criteriaResponses);
|
response.setCriteria(criteriaResponses);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private List<CriteriaResponse> getInitialCriteriaResponses(ApplicationEvaluationEntity entity, Long applicationId) {
|
||||||
|
return entity.getCriteria() != null
|
||||||
|
? Utils.convertJsonToList(entity.getCriteria(), new TypeReference<List<CriteriaResponse>>() {})
|
||||||
|
: getCriteriaResponse(applicationId);
|
||||||
|
}
|
||||||
|
|
||||||
|
private EvaluationCriteriaEntity findMatchingEvaluationCriteria(CriteriaResponse criteriaResponse,
|
||||||
|
List<EvaluationCriteriaEntity> evaluationCriterias) {
|
||||||
|
return evaluationCriterias.stream()
|
||||||
|
.filter(evaluationCriteria -> evaluationCriteria.getId().equals(criteriaResponse.getId()))
|
||||||
|
.findFirst()
|
||||||
|
.orElse(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
private Map<String, CriteriaMappedField> populateMappedFields(EvaluationCriteriaEntity matchingEvaluationCriteria,
|
||||||
|
List<ApplicationFormEntity> applicationForms,
|
||||||
|
Long applicationId) {
|
||||||
|
Map<String, CriteriaMappedField> mappedFieldMap = new HashMap<>();
|
||||||
|
List<CriteriaFormFieldEntity> criteriaFormFields = criteriaFormFieldRepository
|
||||||
|
.findByEvaluationCriteriaIdAndIsDeletedFalse(matchingEvaluationCriteria.getId());
|
||||||
|
|
||||||
|
for (ApplicationFormEntity applicationForm : applicationForms) {
|
||||||
|
for (CriteriaFormFieldEntity criteriaFormField : criteriaFormFields) {
|
||||||
|
String formFieldId = criteriaFormField.getFormFieldId();
|
||||||
|
if (!mappedFieldMap.containsKey(formFieldId)) {
|
||||||
|
CriteriaMappedField mappedField = new CriteriaMappedField();
|
||||||
|
populateMappedField(mappedField, formFieldId, criteriaFormField, applicationForm, applicationId);
|
||||||
|
mappedFieldMap.put(formFieldId, mappedField);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return mappedFieldMap;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void populateMappedField(CriteriaMappedField mappedField, String formFieldId,
|
||||||
|
CriteriaFormFieldEntity criteriaFormField,
|
||||||
|
ApplicationFormEntity applicationForm, Long applicationId) {
|
||||||
|
mappedField.setId(formFieldId);
|
||||||
|
formRepository.findById(criteriaFormField.getFormId()).ifPresent(formEntity -> {
|
||||||
|
List<ContentResponseBean> contentResponseBeans = Utils.convertJsonStringToList(formEntity.getContent(), ContentResponseBean.class);
|
||||||
|
contentResponseBeans.stream().filter(bean -> bean.getId().equals(formFieldId)).findFirst().ifPresent(contentResponseBean -> {
|
||||||
|
String label = getLabel(contentResponseBean);
|
||||||
|
mappedField.setFieldLabel(label);
|
||||||
|
switch (contentResponseBean.getName()) {
|
||||||
|
case "fileupload":
|
||||||
|
populateFileDetailsAsFieldValue(mappedField, formFieldId, applicationForm, applicationId);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case "checkboxes":
|
||||||
|
populateOptionFieldsAsFieldValue(mappedField, formFieldId, applicationForm, applicationId, contentResponseBean);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case "paragraph":
|
||||||
|
handleParagraphField(applicationId, criteriaFormField, contentResponseBean, mappedField);
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
populateOptionFieldsAsFieldValue(mappedField, formFieldId, applicationForm, applicationId, contentResponseBean);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private void populateFileDetailsAsFieldValue(CriteriaMappedField mappedField, String formFieldId,
|
||||||
|
ApplicationFormEntity applicationForm, Long applicationId) {
|
||||||
|
applicationFormFieldRepository.findByFieldIdAndApplicationFormIdAndApplicationFormApplicationId(
|
||||||
|
formFieldId, applicationForm.getId(), applicationId)
|
||||||
|
.ifPresent(formField -> {
|
||||||
|
if (formField.getFieldValue() != null) {
|
||||||
|
List<DocumentResponseBean> documentResponseBeans = new ArrayList<>();
|
||||||
|
for (String docId : formField.getFieldValue().split(",")) {
|
||||||
|
Long documentId = Long.valueOf(docId.trim());
|
||||||
|
documentRepository.findByIdAndNotDeleted(documentId).ifPresent(documentEntity -> {
|
||||||
|
DocumentResponseBean responseBean = createDocumentResponseBean(documentEntity);
|
||||||
|
documentResponseBeans.add(responseBean);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
// Set the list of DocumentResponseBean directly
|
||||||
|
mappedField.setFieldValue(documentResponseBeans);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getLabel(ContentResponseBean contentResponseBean) {
|
||||||
|
String label = contentResponseBean.getLabel();
|
||||||
|
if (contentResponseBean.getSettings() != null) {
|
||||||
|
for (SettingResponseBean setting : contentResponseBean.getSettings()) {
|
||||||
|
if ("label".equals(setting.getName())) {
|
||||||
|
label = setting.getValue() != null ? setting.getValue().toString() : label;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return label;
|
||||||
|
}
|
||||||
|
private void populateOptionFieldsAsFieldValue(CriteriaMappedField mappedField, String formFieldId, ApplicationFormEntity applicationForm, Long applicationId, ContentResponseBean contentBean) {
|
||||||
|
ObjectMapper objectMapper = new ObjectMapper();
|
||||||
|
findFormFieldValue(applicationId, formFieldId).ifPresent(formField -> {
|
||||||
|
Object value = formField.getFieldValue();
|
||||||
|
List<String> labels = new ArrayList<>();
|
||||||
|
if (value instanceof String) {
|
||||||
|
String fieldValue = (String) value;
|
||||||
|
if (fieldValue.contains(",")) {
|
||||||
|
try {
|
||||||
|
List<?> parsedValue = objectMapper.readValue(fieldValue, new TypeReference<List<?>>() {});
|
||||||
|
parsedValue.forEach(item -> addLabelToList(labels, item, contentBean));
|
||||||
|
} catch (JsonProcessingException e) {
|
||||||
|
|
||||||
|
String[] fallbackValues = fieldValue.split(",");
|
||||||
|
for (String item : fallbackValues) {
|
||||||
|
addLabelToList(labels, item.trim(), contentBean);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
mappedField.setFieldValue(!labels.isEmpty() ? labels : null);
|
||||||
|
} else {
|
||||||
|
|
||||||
|
addLabelToList(labels, fieldValue.trim(), contentBean);
|
||||||
|
mappedField.setFieldValue(!labels.isEmpty() ? labels.get(0) : null);
|
||||||
|
}
|
||||||
|
} else if (value instanceof List<?>) {
|
||||||
|
|
||||||
|
List<?> parsedValue = (List<?>) value;
|
||||||
|
parsedValue.forEach(item -> addLabelToList(labels, item, contentBean));
|
||||||
|
mappedField.setFieldValue(!labels.isEmpty() ? labels : null);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private void addLabelToList(List<String> labels, Object item, ContentResponseBean contentBean) {
|
||||||
|
if (item instanceof String) {
|
||||||
|
Object label = PdfDao.findLabelInOptions(contentBean.getSettings(), item);
|
||||||
|
if (label != null) {
|
||||||
|
labels.add(label.toString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private DocumentResponseBean createDocumentResponseBean(DocumentEntity documentEntity) {
|
||||||
|
DocumentResponseBean responseBean = new DocumentResponseBean();
|
||||||
|
responseBean.setId(documentEntity.getId());
|
||||||
|
responseBean.setName(documentEntity.getFileName());
|
||||||
|
responseBean.setType(DocumentTypeEnum.valueOf(documentEntity.getType()));
|
||||||
|
responseBean.setSource(DocumentSourceTypeEnum.valueOf(documentEntity.getSource()));
|
||||||
|
responseBean.setSourceId(documentEntity.getSourceId());
|
||||||
|
responseBean.setFilePath(documentEntity.getFilePath());
|
||||||
|
responseBean.setCreatedDate(documentEntity.getCreatedDate());
|
||||||
|
responseBean.setUpdatedDate(documentEntity.getUpdatedDate());
|
||||||
|
return responseBean;
|
||||||
|
}
|
||||||
|
|
||||||
private void setChecklistResponses(ApplicationEvaluationEntity entity, Long applicationId, ApplicationEvaluationResponse response,
|
private void setChecklistResponses(ApplicationEvaluationEntity entity, Long applicationId, ApplicationEvaluationResponse response,
|
||||||
List<CallTargetAudienceChecklistEntity> checklistEntities) {
|
List<CallTargetAudienceChecklistEntity> checklistEntities) {
|
||||||
|
|
||||||
@@ -693,8 +868,6 @@ public class ApplicationEvaluationDao {
|
|||||||
|
|
||||||
fieldResponse.setFileDetail(documentResponseBeans);
|
fieldResponse.setFileDetail(documentResponseBeans);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Mark this field ID as processed to prevent duplicates
|
|
||||||
processedFieldIds.add(fieldResponse.getId());
|
processedFieldIds.add(fieldResponse.getId());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -721,65 +894,212 @@ public class ApplicationEvaluationDao {
|
|||||||
response.setEvaluationDate(application.getSubmissionDate() != null ? application.getSubmissionDate().plusDays(30) : null);
|
response.setEvaluationDate(application.getSubmissionDate() != null ? application.getSubmissionDate().plusDays(30) : null);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
private Optional<ApplicationFormFieldEntity> findFormFieldValue(Long applicationId, String formFieldId) {
|
||||||
|
return applicationFormRepository.findByApplicationId(applicationId).stream()
|
||||||
|
.flatMap(applicationForm -> applicationFormFieldRepository.findByFieldIdAndApplicationFormIdAndApplicationFormApplicationId(
|
||||||
|
formFieldId, applicationForm.getId(), applicationId).stream())
|
||||||
|
.findFirst();
|
||||||
|
}
|
||||||
|
|
||||||
List<CriteriaResponse> getCriteriaResponse(Long applicationId) {
|
List<CriteriaResponse> getCriteriaResponse(Long applicationId) {
|
||||||
|
CallEntity call = getCallEntityByApplicationId(applicationId);
|
||||||
|
List<EvaluationCriteriaEntity> evaluationCriterias = getEvaluationCriterias(call);
|
||||||
|
|
||||||
CallEntity call = callRepository.findCallEntityByApplicationId(applicationId);
|
return evaluationCriterias.stream()
|
||||||
List<EvaluationCriteriaEntity> evaluationCriterias = evaluationCriteriaRepository.findByCallId(call.getId());
|
.map(criteria -> buildCriteriaResponse(applicationId, criteria))
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
}
|
||||||
|
|
||||||
List<CriteriaResponse> criteriaResponses = evaluationCriterias.stream().map(criteria -> {
|
private CallEntity getCallEntityByApplicationId(Long applicationId) {
|
||||||
CriteriaResponse response = new CriteriaResponse();
|
return callRepository.findCallEntityByApplicationId(applicationId);
|
||||||
response.setId(criteria.getId());
|
}
|
||||||
response.setLabel(criteria.getLookupData().getValue());
|
|
||||||
response.setScore(null);
|
|
||||||
response.setMaxScore(criteria.getScore());
|
|
||||||
response.setValid(null);
|
|
||||||
|
|
||||||
List<CriteriaFormFieldEntity> criteriaFormFields = criteriaFormFieldRepository.findByEvaluationCriteriaIdAndIsDeletedFalse(criteria.getId());
|
private List<EvaluationCriteriaEntity> getEvaluationCriterias(CallEntity call) {
|
||||||
|
return evaluationCriteriaRepository.findByCallId(call.getId());
|
||||||
|
}
|
||||||
|
|
||||||
List<CriteriaMappedField> mappedFields = new ArrayList<>();
|
private CriteriaResponse buildCriteriaResponse(Long applicationId, EvaluationCriteriaEntity criteria) {
|
||||||
Set<String> processedFormFieldIds = new HashSet<>();
|
CriteriaResponse response = new CriteriaResponse();
|
||||||
|
response.setId(criteria.getId());
|
||||||
|
response.setLabel(criteria.getLookupData().getValue());
|
||||||
|
response.setScore(null);
|
||||||
|
response.setMaxScore(criteria.getScore());
|
||||||
|
response.setValid(null);
|
||||||
|
|
||||||
for (CriteriaFormFieldEntity criteriaFormField : criteriaFormFields) {
|
List<CriteriaMappedField> mappedFields = getMappedFields(applicationId, criteria);
|
||||||
if (processedFormFieldIds.contains(criteriaFormField.getFormFieldId())) {
|
response.setCriteriaMappedFields(mappedFields);
|
||||||
continue;
|
return response;
|
||||||
}
|
}
|
||||||
|
|
||||||
CriteriaMappedField mappedField = new CriteriaMappedField();
|
private List<CriteriaMappedField> getMappedFields(Long applicationId, EvaluationCriteriaEntity criteria) {
|
||||||
mappedField.setId(criteriaFormField.getFormFieldId());
|
List<CriteriaFormFieldEntity> criteriaFormFields = getCriteriaFormFields(criteria);
|
||||||
|
|
||||||
FormEntity formEntity = formRepository.findById(criteriaFormField.getFormId()).orElse(null);
|
List<CriteriaMappedField> mappedFields = new ArrayList<>();
|
||||||
if (formEntity != null) {
|
Set<String> processedFormFieldIds = new HashSet<>();
|
||||||
List<ContentResponseBean> contentResponseBeans = Utils.convertJsonStringToList(formEntity.getContent(), ContentResponseBean.class);
|
|
||||||
contentResponseBeans.stream().filter(bean -> bean.getId().equals(criteriaFormField.getFormFieldId())).findFirst().ifPresent(contentResponseBean -> {
|
|
||||||
String label = contentResponseBean.getLabel();
|
|
||||||
if (contentResponseBean.getSettings() != null) {
|
|
||||||
for (SettingResponseBean setting : contentResponseBean.getSettings()) {
|
|
||||||
if ("label".equals(setting.getName())) {
|
|
||||||
label = setting.getValue() != null ? setting.getValue().toString() : label;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
mappedField.setFieldLabel(label);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
applicationFormRepository.findByApplicationId(applicationId).stream().flatMap(
|
for (CriteriaFormFieldEntity criteriaFormField : criteriaFormFields) {
|
||||||
applicationForm -> applicationFormFieldRepository.findByFieldIdAndApplicationFormIdAndApplicationFormApplicationId(criteriaFormField.getFormFieldId(),
|
if (processedFormFieldIds.contains(criteriaFormField.getFormFieldId())) {
|
||||||
applicationForm.getId(), applicationId).stream()).findFirst().ifPresent(formField -> mappedField.setFieldValue(formField.getFieldValue()));
|
continue;
|
||||||
|
|
||||||
mappedFields.add(mappedField);
|
|
||||||
processedFormFieldIds.add(criteriaFormField.getFormFieldId());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
response.setCriteriaMappedFields(mappedFields);
|
CriteriaMappedField mappedField = mapField(applicationId, criteriaFormField);
|
||||||
return response;
|
mappedFields.add(mappedField);
|
||||||
}).collect(Collectors.toList());
|
processedFormFieldIds.add(criteriaFormField.getFormFieldId());
|
||||||
|
}
|
||||||
|
|
||||||
return criteriaResponses;
|
return mappedFields;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private List<CriteriaFormFieldEntity> getCriteriaFormFields(EvaluationCriteriaEntity criteria) {
|
||||||
|
return criteriaFormFieldRepository.findByEvaluationCriteriaIdAndIsDeletedFalse(criteria.getId());
|
||||||
|
}
|
||||||
|
|
||||||
|
private CriteriaMappedField mapField(Long applicationId, CriteriaFormFieldEntity criteriaFormField) {
|
||||||
|
CriteriaMappedField mappedField = new CriteriaMappedField();
|
||||||
|
mappedField.setId(criteriaFormField.getFormFieldId());
|
||||||
|
|
||||||
|
FormEntity formEntity = formRepository.findById(criteriaFormField.getFormId()).orElse(null);
|
||||||
|
if (formEntity != null) {
|
||||||
|
List<ContentResponseBean> contentResponseBeans = Utils.convertJsonStringToList(formEntity.getContent(), ContentResponseBean.class);
|
||||||
|
contentResponseBeans.stream()
|
||||||
|
.filter(bean -> bean.getId().equals(criteriaFormField.getFormFieldId()))
|
||||||
|
.findFirst()
|
||||||
|
.ifPresent(contentResponseBean -> processFieldValue(applicationId, criteriaFormField, contentResponseBean, mappedField));
|
||||||
|
}
|
||||||
|
|
||||||
|
return mappedField;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void processFieldValue(Long applicationId, CriteriaFormFieldEntity criteriaFormField, ContentResponseBean contentResponseBean, CriteriaMappedField mappedField) {
|
||||||
|
String label = getLabelFromSettings(contentResponseBean);
|
||||||
|
|
||||||
|
mappedField.setFieldLabel(label);
|
||||||
|
|
||||||
|
boolean isCheckbox = "checkboxes".equals(contentResponseBean.getName());
|
||||||
|
boolean isFileUpload = "fileupload".equals(contentResponseBean.getName());
|
||||||
|
boolean isParagraph = "paragraph".equals(contentResponseBean.getName());
|
||||||
|
|
||||||
|
if (isFileUpload) {
|
||||||
|
handleFileUpload(applicationId, criteriaFormField, mappedField);
|
||||||
|
} else if (isCheckbox) {
|
||||||
|
handleCheckbox(applicationId, criteriaFormField, contentResponseBean, mappedField);
|
||||||
|
}
|
||||||
|
else if (isParagraph) {
|
||||||
|
handleParagraphField(applicationId, criteriaFormField, contentResponseBean, mappedField);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
handleOtherFields(applicationId, criteriaFormField, contentResponseBean, mappedField);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private void handleParagraphField(Long applicationId, CriteriaFormFieldEntity criteriaFormField, ContentResponseBean contentResponseBean, CriteriaMappedField mappedField) {
|
||||||
|
findFormFieldValue(applicationId, criteriaFormField.getFormFieldId()).ifPresent(formField -> {
|
||||||
|
String paragraph = contentResponseBean.getSettings().stream()
|
||||||
|
.filter(setting -> "text".equals(setting.getName()))
|
||||||
|
.map(SettingResponseBean::getValue)
|
||||||
|
.map(Object::toString)
|
||||||
|
.findFirst()
|
||||||
|
.orElse(null);
|
||||||
|
if (paragraph != null) {
|
||||||
|
mappedField.setFieldValue(paragraph.trim());
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getLabelFromSettings(ContentResponseBean contentResponseBean) {
|
||||||
|
String label = contentResponseBean.getLabel();
|
||||||
|
if (contentResponseBean.getSettings() != null) {
|
||||||
|
for (SettingResponseBean setting : contentResponseBean.getSettings()) {
|
||||||
|
if ("label".equals(setting.getName())) {
|
||||||
|
label = setting.getValue() != null ? setting.getValue().toString() : label;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return label;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void handleFileUpload(Long applicationId, CriteriaFormFieldEntity criteriaFormField, CriteriaMappedField mappedField) {
|
||||||
|
List<DocumentResponseBean> documentResponseBeans = new ArrayList<>();
|
||||||
|
findFormFieldValue(applicationId, criteriaFormField.getFormFieldId()).ifPresent(formField -> {
|
||||||
|
String fieldValue = formField.getFieldValue();
|
||||||
|
if (fieldValue != null) {
|
||||||
|
String[] fieldValues = fieldValue.split(",");
|
||||||
|
for (String value : fieldValues) {
|
||||||
|
Long documentId = Long.valueOf(value.trim());
|
||||||
|
documentRepository.findByIdAndNotDeleted(documentId).ifPresent(documentEntity -> {
|
||||||
|
DocumentResponseBean responseBean = mapDocumentEntityToResponse(documentEntity);
|
||||||
|
documentResponseBeans.add(responseBean);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
mappedField.setFieldValue(!documentResponseBeans.isEmpty() ? documentResponseBeans : null);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private DocumentResponseBean mapDocumentEntityToResponse(DocumentEntity documentEntity) {
|
||||||
|
DocumentResponseBean responseBean = new DocumentResponseBean();
|
||||||
|
responseBean.setId(documentEntity.getId());
|
||||||
|
responseBean.setName(documentEntity.getFileName());
|
||||||
|
responseBean.setType(DocumentTypeEnum.valueOf(documentEntity.getType()));
|
||||||
|
responseBean.setSource(DocumentSourceTypeEnum.valueOf(documentEntity.getSource()));
|
||||||
|
responseBean.setSourceId(documentEntity.getSourceId());
|
||||||
|
responseBean.setFilePath(documentEntity.getFilePath());
|
||||||
|
responseBean.setCreatedDate(documentEntity.getCreatedDate());
|
||||||
|
responseBean.setUpdatedDate(documentEntity.getUpdatedDate());
|
||||||
|
return responseBean;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void handleCheckbox(Long applicationId, CriteriaFormFieldEntity criteriaFormField, ContentResponseBean contentResponseBean, CriteriaMappedField mappedField) {
|
||||||
|
ObjectMapper objectMapper = new ObjectMapper();
|
||||||
|
findFormFieldValue(applicationId, criteriaFormField.getFormFieldId()).ifPresent(formField -> {
|
||||||
|
Object value = formField.getFieldValue();
|
||||||
|
List<String> labels = new ArrayList<>();
|
||||||
|
|
||||||
|
if (value instanceof String) {
|
||||||
|
List<?> parsedValue = parseJsonValue((String) value, objectMapper);
|
||||||
|
addLabelsFromParsedValues(parsedValue, contentResponseBean, labels);
|
||||||
|
} else if (value instanceof List<?>) {
|
||||||
|
List<?> parsedValue = (List<?>) value;
|
||||||
|
addLabelsFromParsedValues(parsedValue, contentResponseBean, labels);
|
||||||
|
}
|
||||||
|
|
||||||
|
mappedField.setFieldValue(!labels.isEmpty() ? (labels.size() == 1 ? labels.get(0) : labels) : null);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<?> parseJsonValue(String value, ObjectMapper objectMapper) {
|
||||||
|
try {
|
||||||
|
return objectMapper.readValue(value, new TypeReference<List<?>>() {});
|
||||||
|
} catch (JsonProcessingException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void addLabelsFromParsedValues(List<?> parsedValue, ContentResponseBean contentResponseBean, List<String> labels) {
|
||||||
|
for (Object item : parsedValue) {
|
||||||
|
if (item instanceof String) {
|
||||||
|
Object label = PdfDao.findLabelInOptions(contentResponseBean.getSettings(), item);
|
||||||
|
if (label != null) {
|
||||||
|
labels.add(label.toString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void handleOtherFields(Long applicationId, CriteriaFormFieldEntity criteriaFormField, ContentResponseBean contentResponseBean, CriteriaMappedField mappedField) {
|
||||||
|
findFormFieldValue(applicationId, criteriaFormField.getFormFieldId()).ifPresent(formField -> {
|
||||||
|
String fieldValue = formField.getFieldValue() != null ? formField.getFieldValue().trim() : null;
|
||||||
|
Object label = PdfDao.findLabelInOptions(contentResponseBean.getSettings(), fieldValue);
|
||||||
|
if (label != null) {
|
||||||
|
mappedField.setFieldValue(fieldValue != null && !fieldValue.isEmpty() && !fieldValue.contains(",")
|
||||||
|
? label.toString()
|
||||||
|
: Arrays.asList(label.toString()));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
List<ChecklistResponse> getChecklistResponse(Long applicationId) {
|
List<ChecklistResponse> getChecklistResponse(Long applicationId) {
|
||||||
|
|
||||||
CallEntity call = callRepository.findCallEntityByApplicationId(applicationId);
|
CallEntity call = callRepository.findCallEntityByApplicationId(applicationId);
|
||||||
@@ -852,8 +1172,6 @@ public class ApplicationEvaluationDao {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fieldResponse.setFileDetail(documentResponseBeans);
|
fieldResponse.setFileDetail(documentResponseBeans);
|
||||||
|
|
||||||
// Now add fieldResponse to the list
|
|
||||||
fieldResponses.add(fieldResponse);
|
fieldResponses.add(fieldResponse);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,10 +1,11 @@
|
|||||||
package net.gepafin.tendermanagement.model.response;
|
package net.gepafin.tendermanagement.model.response;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
public class CriteriaMappedField {
|
public class CriteriaMappedField {
|
||||||
private String id;
|
private String id;
|
||||||
private String fieldLabel;
|
private String fieldLabel;
|
||||||
private String fieldValue;
|
private Object fieldValue;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user