From c1939102c7810e8dc3874fe2598ab3d1e00a8f0e Mon Sep 17 00:00:00 2001 From: nisha Date: Fri, 20 Sep 2024 19:37:47 +0530 Subject: [PATCH] Updated put api of call --- .../constants/GepafinConstant.java | 2 +- .../net/gepafin/tendermanagement/dao/CallDao.java | 12 ++++++++++-- .../net/gepafin/tendermanagement/util/Utils.java | 14 ++++++++++++++ src/main/resources/message_en.properties | 1 + src/main/resources/message_it.properties | 3 ++- 5 files changed, 28 insertions(+), 4 deletions(-) diff --git a/src/main/java/net/gepafin/tendermanagement/constants/GepafinConstant.java b/src/main/java/net/gepafin/tendermanagement/constants/GepafinConstant.java index acf2e124..6fecacdd 100644 --- a/src/main/java/net/gepafin/tendermanagement/constants/GepafinConstant.java +++ b/src/main/java/net/gepafin/tendermanagement/constants/GepafinConstant.java @@ -133,5 +133,5 @@ public class GepafinConstant { public static final String INITAL_AND_FINAL_FORM_CANNOT_NULL="initial.and.final.form.cannot.null"; public static final String APPLICATION_FORM_NOT_FOUND="application.form.not.found"; public static final String UPDATING_FORM_VALUE_IMPACT_ON_FLOW="updating.form.value.impact.on.flow"; - + public static final String FAILED_RETAIN_FIELD="failed.retain.field"; } diff --git a/src/main/java/net/gepafin/tendermanagement/dao/CallDao.java b/src/main/java/net/gepafin/tendermanagement/dao/CallDao.java index 850806fa..1b3f60d0 100644 --- a/src/main/java/net/gepafin/tendermanagement/dao/CallDao.java +++ b/src/main/java/net/gepafin/tendermanagement/dao/CallDao.java @@ -3,12 +3,14 @@ package net.gepafin.tendermanagement.dao; import java.time.LocalDate; import java.time.LocalDateTime; import java.util.ArrayList; +import java.util.Collections; import java.util.List; import java.util.stream.Collectors; import net.gepafin.tendermanagement.enums.DocumentSourceTypeEnum; import net.gepafin.tendermanagement.model.response.*; import net.gepafin.tendermanagement.service.*; +import net.gepafin.tendermanagement.util.Utils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import org.springframework.util.StringUtils; @@ -424,8 +426,14 @@ public class CallDao { public CallResponse updateCallStep1(Long callId, UpdateCallRequestStep1 updateCallRequest, Long userId) { CallEntity callEntity = validateCall(callId); - validateUpdate(callEntity); - UserEntity userEntity = userService.validateUser(userId); + if(Boolean.TRUE.equals(callEntity.getStatus().equals(CallStatusEnum.PUBLISH.getValue()))) { + try { + Utils.retainOnlySpecificFields(updateCallRequest, Collections.singletonList("faq")); + } catch (IllegalAccessException e) { + throw new CustomValidationException(Status.BAD_REQUEST,Translator.toLocale(GepafinConstant.FAILED_RETAIN_FIELD)); + } + } + UserEntity userEntity = userService.validateUser(userId); isValidDateRange(updateCallRequest, callEntity); setIfUpdated(callEntity::getName, callEntity::setName, updateCallRequest.getName()); setIfUpdated(callEntity::getDescriptionShort, callEntity::setDescriptionShort, diff --git a/src/main/java/net/gepafin/tendermanagement/util/Utils.java b/src/main/java/net/gepafin/tendermanagement/util/Utils.java index 5560809f..055fb8e8 100644 --- a/src/main/java/net/gepafin/tendermanagement/util/Utils.java +++ b/src/main/java/net/gepafin/tendermanagement/util/Utils.java @@ -12,6 +12,7 @@ import org.apache.commons.collections4.MapUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import java.lang.reflect.Field; import java.lang.reflect.Type; import java.nio.charset.StandardCharsets; import java.util.Base64; @@ -147,4 +148,17 @@ public class Utils { } return null; } + public static void retainOnlySpecificFields(T requestObject, List retainFields) throws IllegalAccessException { + // Get all declared fields of the request object's class + Field[] fields = requestObject.getClass().getDeclaredFields(); + + for (Field field : fields) { + field.setAccessible(true); // To allow access to private fields + + // Check if the field is in the retainFields list + if (!retainFields.contains(field.getName())) { + field.set(requestObject, null); // Set the field to null if not in the retain list + } + } + } } diff --git a/src/main/resources/message_en.properties b/src/main/resources/message_en.properties index b0449f1e..76fef4eb 100644 --- a/src/main/resources/message_en.properties +++ b/src/main/resources/message_en.properties @@ -168,4 +168,5 @@ call.not.published=Call is not published. application.form.not.found=Application form not found. updating.form.value.impact.on.flow=Updating this value of form {0} can make impact on flow. +failed.retain.field=Failed to retain specific fields. diff --git a/src/main/resources/message_it.properties b/src/main/resources/message_it.properties index 7b464832..c5f4c2c9 100644 --- a/src/main/resources/message_it.properties +++ b/src/main/resources/message_it.properties @@ -162,4 +162,5 @@ action.required=Campo azione obbligatorio. call.not.published=La chiamata non č stata pubblicata. application.form.not.found=Modulo di domanda non trovato. -updating.form.value.impact.on.flow=L'aggiornamento di questo valore del modulo {0} puņ avere un impatto sul flusso. \ No newline at end of file +updating.form.value.impact.on.flow=L'aggiornamento di questo valore del modulo {0} puņ avere un impatto sul flusso. +failed.retain.field=Impossibile conservare campi specifici. \ No newline at end of file