Updated criteria response for field ids coming in the mappedField response as value.
This commit is contained in:
@@ -1,6 +1,9 @@
|
||||
package net.gepafin.tendermanagement.dao;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
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.constants.GepafinConstant;
|
||||
import net.gepafin.tendermanagement.entities.*;
|
||||
@@ -49,7 +52,6 @@ public class ApplicationEvaluationDao {
|
||||
|
||||
@Autowired
|
||||
private FormRepository formRepository;
|
||||
|
||||
@Autowired
|
||||
private CallTargetAudienceChecklistRepository callTargetAudienceChecklistRepository;
|
||||
|
||||
@@ -185,11 +187,19 @@ public class ApplicationEvaluationDao {
|
||||
.findFirst()
|
||||
.ifPresent(contentBean -> {
|
||||
mappedField.setFieldLabel(getLabelForField(contentBean));
|
||||
switch (contentBean.getName()) {
|
||||
case "fileupload":
|
||||
mapFileFieldDetails(mappedField, formFieldId, applicationForm.getId(), applicationId);
|
||||
break;
|
||||
|
||||
if ("fileupload".equals(contentBean.getName())) {
|
||||
mapFileFieldDetails(mappedField, formFieldId, applicationForm.getId(), applicationId);
|
||||
} else {
|
||||
mapNonFileFieldDetails(mappedField, formFieldId, applicationForm.getId(), applicationId);
|
||||
case "checkboxes":
|
||||
populateOptionFieldsAsFieldValue(mappedField, formFieldId, applicationForm, applicationId, contentBean);
|
||||
break;
|
||||
case "paragraph":
|
||||
handleParagraphField(applicationId, formField, contentBean, mappedField);
|
||||
break;
|
||||
default:
|
||||
populateOptionFieldsAsFieldValue(mappedField, formFieldId, applicationForm, applicationId, contentBean);
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -676,17 +686,27 @@ public class ApplicationEvaluationDao {
|
||||
contentResponseBeans.stream().filter(bean -> bean.getId().equals(formFieldId)).findFirst().ifPresent(contentResponseBean -> {
|
||||
String label = getLabel(contentResponseBean);
|
||||
mappedField.setFieldLabel(label);
|
||||
if ("fileupload".equals(contentResponseBean.getName())) {
|
||||
populateFileDetailsAsFieldValue(mappedField, formFieldId, applicationForm, applicationId);
|
||||
} else {
|
||||
applicationFormFieldRepository.findByFieldIdAndApplicationFormIdAndApplicationFormApplicationId(
|
||||
formFieldId, applicationForm.getId(), applicationId)
|
||||
.ifPresent(formField -> mappedField.setFieldValue(formField.getFieldValue()));
|
||||
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(
|
||||
@@ -719,6 +739,47 @@ public class ApplicationEvaluationDao {
|
||||
}
|
||||
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) {
|
||||
@@ -807,8 +868,6 @@ public class ApplicationEvaluationDao {
|
||||
|
||||
fieldResponse.setFileDetail(documentResponseBeans);
|
||||
}
|
||||
|
||||
// Mark this field ID as processed to prevent duplicates
|
||||
processedFieldIds.add(fieldResponse.getId());
|
||||
}
|
||||
});
|
||||
@@ -835,99 +894,212 @@ public class ApplicationEvaluationDao {
|
||||
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) {
|
||||
CallEntity call = getCallEntityByApplicationId(applicationId);
|
||||
List<EvaluationCriteriaEntity> evaluationCriterias = getEvaluationCriterias(call);
|
||||
|
||||
CallEntity call = callRepository.findCallEntityByApplicationId(applicationId);
|
||||
List<EvaluationCriteriaEntity> evaluationCriterias = evaluationCriteriaRepository.findByCallId(call.getId());
|
||||
return evaluationCriterias.stream()
|
||||
.map(criteria -> buildCriteriaResponse(applicationId, criteria))
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
List<CriteriaResponse> criteriaResponses = evaluationCriterias.stream().map(criteria -> {
|
||||
CriteriaResponse response = new CriteriaResponse();
|
||||
response.setId(criteria.getId());
|
||||
response.setLabel(criteria.getLookupData().getValue());
|
||||
response.setScore(null);
|
||||
response.setMaxScore(criteria.getScore());
|
||||
response.setValid(null);
|
||||
private CallEntity getCallEntityByApplicationId(Long applicationId) {
|
||||
return callRepository.findCallEntityByApplicationId(applicationId);
|
||||
}
|
||||
|
||||
List<CriteriaFormFieldEntity> criteriaFormFields = criteriaFormFieldRepository.findByEvaluationCriteriaIdAndIsDeletedFalse(criteria.getId());
|
||||
private List<EvaluationCriteriaEntity> getEvaluationCriterias(CallEntity call) {
|
||||
return evaluationCriteriaRepository.findByCallId(call.getId());
|
||||
}
|
||||
|
||||
List<CriteriaMappedField> mappedFields = new ArrayList<>();
|
||||
Set<String> processedFormFieldIds = new HashSet<>();
|
||||
private CriteriaResponse buildCriteriaResponse(Long applicationId, EvaluationCriteriaEntity criteria) {
|
||||
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) {
|
||||
if (processedFormFieldIds.contains(criteriaFormField.getFormFieldId())) {
|
||||
continue;
|
||||
}
|
||||
List<CriteriaMappedField> mappedFields = getMappedFields(applicationId, criteria);
|
||||
response.setCriteriaMappedFields(mappedFields);
|
||||
return response;
|
||||
}
|
||||
|
||||
CriteriaMappedField mappedField = new CriteriaMappedField();
|
||||
mappedField.setId(criteriaFormField.getFormFieldId());
|
||||
private List<CriteriaMappedField> getMappedFields(Long applicationId, EvaluationCriteriaEntity criteria) {
|
||||
List<CriteriaFormFieldEntity> criteriaFormFields = getCriteriaFormFields(criteria);
|
||||
|
||||
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 -> {
|
||||
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);
|
||||
});
|
||||
}
|
||||
List<DocumentResponseBean> documentResponseBeans = new ArrayList<>();
|
||||
applicationFormRepository.findByApplicationId(applicationId).stream()
|
||||
.flatMap(applicationForm -> applicationFormFieldRepository.findByFieldIdAndApplicationFormIdAndApplicationFormApplicationId(
|
||||
criteriaFormField.getFormFieldId(), applicationForm.getId(), applicationId).stream())
|
||||
.findFirst().ifPresent(formField -> {
|
||||
String fieldValue = formField.getFieldValue();
|
||||
if (fieldValue != null) {
|
||||
String[] fieldValues = fieldValue.split(",");
|
||||
for (String value : fieldValues) {
|
||||
String trimmedValue = value.trim();
|
||||
if (isNumeric(trimmedValue)) {
|
||||
Long documentId = Long.valueOf(trimmedValue);
|
||||
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);
|
||||
});
|
||||
} else {
|
||||
mappedField.setFieldValue(trimmedValue);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!documentResponseBeans.isEmpty()) {
|
||||
mappedField.setFieldValue(documentResponseBeans);
|
||||
} else {
|
||||
mappedField.setFieldValue(fieldValue != null ? fieldValue.trim() : null);
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
mappedFields.add(mappedField);
|
||||
processedFormFieldIds.add(criteriaFormField.getFormFieldId());
|
||||
List<CriteriaMappedField> mappedFields = new ArrayList<>();
|
||||
Set<String> processedFormFieldIds = new HashSet<>();
|
||||
|
||||
for (CriteriaFormFieldEntity criteriaFormField : criteriaFormFields) {
|
||||
if (processedFormFieldIds.contains(criteriaFormField.getFormFieldId())) {
|
||||
continue;
|
||||
}
|
||||
|
||||
response.setCriteriaMappedFields(mappedFields);
|
||||
return response;
|
||||
}).collect(Collectors.toList());
|
||||
CriteriaMappedField mappedField = mapField(applicationId, criteriaFormField);
|
||||
mappedFields.add(mappedField);
|
||||
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) {
|
||||
|
||||
CallEntity call = callRepository.findCallEntityByApplicationId(applicationId);
|
||||
|
||||
Reference in New Issue
Block a user