Done ticket GEPAFINBE-223 & GEPAFINBE-224
This commit is contained in:
@@ -557,25 +557,69 @@ public class ApplicationDao {
|
||||
VersionActionTypeEnum actionType = VersionActionTypeEnum.INSERT;
|
||||
List<ContentResponseBean> contentResponseBeans = formDao.convertFormEntityToFormResponseBean(formEntity).getContent();
|
||||
|
||||
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);
|
||||
log.info("Set amountRequested to {} for Application ID: {}", amountRequested, applicationFormEntity.getApplication().getId());
|
||||
} catch (NumberFormatException e) {
|
||||
log.error("Invalid number format for requested amount: {}", fieldValue, e);
|
||||
throw new IllegalArgumentException("Field value is not a valid number: " + fieldValue, e);
|
||||
}
|
||||
}
|
||||
});
|
||||
// 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);
|
||||
// log.info("Set amountRequested to {} for Application ID: {}", amountRequested, applicationFormEntity.getApplication().getId());
|
||||
// } catch (NumberFormatException e) {
|
||||
// log.error("Invalid number format for requested amount: {}", fieldValue, e);
|
||||
// throw new IllegalArgumentException("Field value is not a valid number: " + fieldValue, e);
|
||||
// }
|
||||
// }
|
||||
// });
|
||||
|
||||
contentResponseBeans.stream()
|
||||
.filter(content -> content.getId().toString().equals(applicationFormFieldRequestBean.getFieldId()))
|
||||
.findFirst()
|
||||
.ifPresent(content -> {
|
||||
Object fieldValue = applicationFormFieldRequestBean.getFieldValue();
|
||||
if (fieldValue == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Convert settings list to a map
|
||||
Map<String, Object> settingMap = content.getSettings().stream()
|
||||
.collect(Collectors.toMap(SettingResponseBean::getName, SettingResponseBean::getValue, (v1, v2) -> v1));
|
||||
|
||||
String fieldType = content.getName();
|
||||
|
||||
// Define handlers for different (fieldType + settingName) combinations
|
||||
Map<String, Runnable> handlers = new HashMap<>();
|
||||
|
||||
// Add handler for isRequestedAmount
|
||||
if ("numberinput".equals(fieldType) && Boolean.TRUE.equals(settingMap.get("isRequestedAmount"))) {
|
||||
handlers.put("isRequestedAmount", () -> {
|
||||
try {
|
||||
BigDecimal amountRequested = new BigDecimal(fieldValue.toString());
|
||||
applicationFormEntity.getApplication().setAmountRequested(amountRequested);
|
||||
log.info("Set amountRequested to {} for Application ID: {}", amountRequested, applicationFormEntity.getApplication().getId());
|
||||
} catch (NumberFormatException e) {
|
||||
log.error("Invalid number format for requested amount: {}", fieldValue, e);
|
||||
throw new IllegalArgumentException("Field value is not a valid number: " + fieldValue, e);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// Add handler for isPecEmail
|
||||
if ("textinput".equals(fieldType) && Boolean.TRUE.equals(settingMap.get("isPecEmail"))) {
|
||||
handlers.put("isPecEmail", () -> {
|
||||
applicationFormEntity.getApplication().setPecEmail(fieldValue.toString());
|
||||
log.info("Set PEC to {} for Application ID: {}", fieldValue, applicationFormEntity.getApplication().getId());
|
||||
});
|
||||
}
|
||||
|
||||
// Run all applicable handlers
|
||||
handlers.values().forEach(Runnable::run);
|
||||
});
|
||||
|
||||
|
||||
ApplicationFormFieldEntity oldApplicationFormFieldData = null;
|
||||
|
||||
Reference in New Issue
Block a user