Updated put api of call

This commit is contained in:
nisha
2024-09-20 19:37:47 +05:30
parent 79603a0c0d
commit c1939102c7
5 changed files with 28 additions and 4 deletions

View File

@@ -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";
}

View File

@@ -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,

View File

@@ -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 <T> void retainOnlySpecificFields(T requestObject, List<T> 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
}
}
}
}

View File

@@ -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.

View File

@@ -163,3 +163,4 @@ call.not.published=La chiamata non
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.
failed.retain.field=Impossibile conservare campi specifici.