resolved conflicts

This commit is contained in:
rajesh
2024-09-25 20:15:12 +05:30
11 changed files with 121 additions and 17 deletions

View File

@@ -155,10 +155,12 @@ public class GepafinConstant {
public static final String IS_CAP="isCAP";
public static final String IS_CODICE_FISCALE="isCodiceFiscale";
public static final String IS_PIVA="isPIVA";
public static final String FAILED_RETAIN_FIELD="failed.retain.field";
public static final String USER_ALREADY_EXIST_MSG = "user.already.exist.msg";
public static final String TOKEN_VALIDATE_SUCCESS_MGE = "token.validate.success.mge";
public static final String INVALID_REQUEST = "invalid.request";
public static final String CODICE_FISCALE_EXISTS = "codice.fiscale.exists";
public static final String TOTAL_STEPS_NOT_BE_ZERO="total.steps.not.zero";
public static final String COMPLETED_STEPS_NOT_VALID="completed.steps.not.valid";
public static final String FIELD_ID_NOT_FOUND="field.id.not.found";
}

View File

@@ -13,19 +13,23 @@ import net.gepafin.tendermanagement.model.response.*;
import net.gepafin.tendermanagement.repositories.ApplicationFormFieldRepository;
import net.gepafin.tendermanagement.repositories.ApplicationFormRepository;
import net.gepafin.tendermanagement.repositories.ApplicationRepository;
import net.gepafin.tendermanagement.repositories.FlowEdgesRepository;
import net.gepafin.tendermanagement.service.CallService;
import net.gepafin.tendermanagement.service.DocumentService;
import net.gepafin.tendermanagement.service.FormService;
import net.gepafin.tendermanagement.util.DateTimeUtil;
import net.gepafin.tendermanagement.util.FieldValidator;
import net.gepafin.tendermanagement.util.Utils;
import net.gepafin.tendermanagement.web.rest.api.errors.CustomValidationException;
import net.gepafin.tendermanagement.web.rest.api.errors.ResourceNotFoundException;
import net.gepafin.tendermanagement.web.rest.api.errors.Status;
import org.checkerframework.checker.units.qual.A;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.text.MessageFormat;
import java.time.LocalDateTime;
import java.util.*;
import java.util.stream.Collectors;
@@ -56,9 +60,16 @@ public class ApplicationDao {
@Autowired
private CallDao callDao;
@Autowired
private FlowFormDao flowFormDao;
@Autowired
private FlowEdgesRepository flowEdgesRepository;
public ApplicationResponseBean createApplication(ApplicationRequestBean applicationRequestBean, UserEntity userEntity, Long formId,Long applicationId) {
FormEntity formEntity = formService.validateForm(formId);
CallEntity call = callService.validatePublishedCall(formEntity.getCall().getId());
validateFormFields(applicationRequestBean,formEntity);
ApplicationEntity applicationEntity = validateApplication(applicationId);
if(Boolean.TRUE.equals(applicationEntity.getStatus().equals(ApplicationStatusTypeEnum.SUBMIT.getValue()))){
throw new CustomValidationException(Status.BAD_REQUEST,Translator.toLocale(GepafinConstant.APPLICATION_ALREADY_SUBMITTED));
@@ -165,10 +176,9 @@ public class ApplicationDao {
}
public List<ApplicationResponse> getAllApplications(UserEntity userEntity, Long callId) {
RoleStatusEnum roleStatus = RoleStatusEnum.valueOf(userEntity.getRoleEntity().getRoleType());
boolean isBeneficiary = RoleStatusEnum.ROLE_BENEFICIARY.equals(roleStatus);
boolean isBeneficiary = isBeneficiary(userEntity);
log.info("Fetching applications for RoleType: {}", roleStatus);
log.info("Fetching applications for RoleType: {}", userEntity.getRoleEntity().getRoleType());
List<ApplicationResponse> applicationResponses = new ArrayList<>();
if (callId != null) {
@@ -204,7 +214,16 @@ public class ApplicationDao {
private ApplicationResponse getApplicationResponse(ApplicationEntity applicationEntity) {
ApplicationResponse responseBean = new ApplicationResponse();
List<FlowEdgesEntity> flowEdgesList = flowEdgesRepository.findByCallId(applicationEntity.getCall().getId());
Long totalFormSteps = flowFormDao.calculateTotalSteps(flowEdgesList);
List<ApplicationFormEntity> applicationFormList = applicationFormRepository.findByApplicationId(applicationEntity.getId());
Long completedSteps=(Long.valueOf(applicationFormList.size()));
Integer progress=calculateProgress(totalFormSteps,completedSteps);
responseBean.setId(applicationEntity.getId());
responseBean.setProgress(progress);
responseBean.setCallTitle(applicationEntity.getCall().getName());
responseBean.setCallEndDate(applicationEntity.getCall().getEndDate());
responseBean.setModifiedDate(applicationEntity.getCall().getUpdatedDate());
responseBean.setCallId(applicationEntity.getCall().getId());
responseBean.setSubmissionDate(applicationEntity.getSubmissionDate());
responseBean.setStatus(applicationEntity.getStatus());
@@ -267,7 +286,7 @@ public class ApplicationDao {
}
}
Utils.setIfUpdated(applicationFormFieldEntity::getFieldId, applicationFormFieldEntity::setFieldId, applicationFormFieldRequestBean.getFieldId());
Utils.setIfUpdated(applicationFormFieldEntity::getFieldValue, applicationFormFieldEntity::setFieldValue, applicationFormFieldRequestBean.getFieldValue());
applicationFormFieldEntity.setFieldValue(applicationFormFieldRequestBean.getFieldValue());
return applicationFormFieldRepository.save(applicationFormFieldEntity);
}
@@ -333,7 +352,12 @@ public class ApplicationDao {
public ApplicationGetResponseBean getApplicationByFormId( Long applicationId,Long formId, UserEntity userEntity) {
List<FormApplicationResponse> formApplicationResponses = new ArrayList<>();
List<FormEntity> formEntities = new ArrayList<>();
ApplicationEntity applicationEntity = applicationRepository.findById(applicationId)
boolean isBeneficiary = isBeneficiary(userEntity);
ApplicationEntity applicationEntity = isBeneficiary
? applicationRepository.findByIdAndUserIdAndIsDeletedFalse(applicationId,userEntity.getId())
.orElseThrow(() -> new CustomValidationException(Status.BAD_REQUEST, Translator.toLocale(GepafinConstant.APPLICATION_NOT_FOUND_MSG)))
: applicationRepository.findById(applicationId)
.stream().findFirst()
.orElseThrow(() -> new CustomValidationException(Status.BAD_REQUEST, Translator.toLocale(GepafinConstant.APPLICATION_NOT_FOUND_MSG)));
if (formId != null) {
@@ -356,6 +380,12 @@ public class ApplicationDao {
return createApplicationGetResponseBean(applicationEntity, formEntities, formApplicationResponses);
}
private boolean isBeneficiary(UserEntity userEntity) {
RoleStatusEnum roleStatus = RoleStatusEnum.valueOf(userEntity.getRoleEntity().getRoleType());
boolean isBeneficiary = RoleStatusEnum.ROLE_BENEFICIARY.equals(roleStatus);
return isBeneficiary;
}
private void addFormApplication(FormEntity formEntity, ApplicationEntity applicationEntity,
List<FormApplicationResponse> formApplicationResponses) {
FormApplicationResponse formApplicationResponse = processForm(formEntity, applicationEntity);
@@ -451,4 +481,37 @@ public class ApplicationDao {
}
saveApplicationEntity(applicationEntity);
}
public Integer calculateProgress(Long totalSteps, Long completedSteps) {
if (FieldValidator.isNullOrZero(totalSteps)) {
throw new CustomValidationException(Status.BAD_REQUEST,Translator.toLocale(GepafinConstant.TOTAL_STEPS_NOT_BE_ZERO));
}
if (completedSteps < 0 || completedSteps > totalSteps) {
throw new CustomValidationException(Status.BAD_REQUEST,Translator.toLocale(GepafinConstant.COMPLETED_STEPS_NOT_VALID));
}
double progress = ((double) completedSteps / totalSteps) * 100;
return (int) Math.round(progress);
}
public void validateFormFields(ApplicationRequestBean request, FormEntity formEntity) {
List<String> errors=new ArrayList<>();
List<ContentResponseBean> contentResponseBeans=Utils.convertJsonStringToList(formEntity.getContent(),ContentResponseBean.class);
List<ApplicationFormFieldRequestBean> requestFields = request.getFormFields();
Map<String, String> contentMap = contentResponseBeans.stream()
.collect(Collectors.toMap(ContentResponseBean::getId, ContentResponseBean::getLabel)); // Change getLabel() if needed
FieldValidator validator = FieldValidator.create();
for (ApplicationFormFieldRequestBean requestField : requestFields) {
String fieldId = requestField.getFieldId();
if (!contentMap.containsKey(fieldId)) {
validator.addError(MessageFormat.format(Translator.toLocale(GepafinConstant.FIELD_ID_NOT_FOUND), fieldId));
}
}
validator.validate();
}
}

View File

@@ -290,21 +290,31 @@ public class FlowFormDao {
nextOrPreviousFormResponse.setCallTitle(applicationEntity.getCall().getName());
List<FlowEdgesEntity> flowEdgesList = flowEdgesRepository.findByCallId(applicationEntity.getCall().getId());
Long totalFormSteps = 3l;
if (flowEdgesList.size() == 1) {
totalFormSteps = 2l;
Long totalFormSteps = calculateTotalSteps(flowEdgesList);
Long currentStep = calculateCurrentStep(formEntity);
List<ApplicationFormEntity> applicationFormList = applicationFormRepository.findByApplicationId(applicationEntity.getId());
nextOrPreviousFormResponse.setTotalFormSteps(totalFormSteps);
nextOrPreviousFormResponse.setCompletedSteps(Long.valueOf(applicationFormList.size()));
nextOrPreviousFormResponse.setCurrentStep(currentStep);
return nextOrPreviousFormResponse;
}
public Long calculateCurrentStep(FormEntity formEntity) {
Long currentStep = 2l;
if (formEntity.getId().equals(formEntity.getCall().getInitialForm())) {
currentStep = 1l;
} else if (formEntity.getId().equals(formEntity.getCall().getFinalForm())) {
currentStep = 3l;
}
List<ApplicationFormEntity> applicationFormList = applicationFormRepository.findByApplicationId(applicationEntity.getId());
nextOrPreviousFormResponse.setTotalFormSteps(totalFormSteps);
nextOrPreviousFormResponse.setCompletedSteps(Long.valueOf(applicationFormList.size()));
nextOrPreviousFormResponse.setCurrentStep(currentStep);
return nextOrPreviousFormResponse;
return currentStep;
}
public Long calculateTotalSteps(List<FlowEdgesEntity> flowEdgesList) {
Long totalFormSteps = 3l;
if (flowEdgesList.size() == 1) {
totalFormSteps = 2l;
}
return totalFormSteps;
}
private Long getDefaultForm(ApplicationEntity applicationEntity) {

View File

@@ -73,6 +73,7 @@ public class FormDao {
formResponseBean.setContent(Utils.convertJsonStringToList(formEntity.getContent(), ContentResponseBean.class));
formResponseBean.setLabel(formEntity.getLabel());
formResponseBean.setCallId(formEntity.getCall().getId());
formResponseBean.setCallStatus(formEntity.getCall().getStatus());
return formResponseBean;
}
public FormResponseBean createForm(Long callId,FormRequest formRequest){

View File

@@ -13,6 +13,14 @@ public class ApplicationResponse{
private Long callId;
private String callTitle;
private LocalDateTime callEndDate;
private LocalDateTime modifiedDate;
private Integer progress;
private LocalDateTime submissionDate;
private String status;

View File

@@ -9,6 +9,8 @@ public class FormResponseBean {
private Long id;
private String callStatus;
private String label;
private Long callId;

View File

@@ -23,4 +23,7 @@ public interface ApplicationRepository extends JpaRepository<ApplicationEntity,L
public List<ApplicationEntity> findByCallIdAndIsDeletedFalse(Long callId);
public List<ApplicationEntity> findByIsDeletedFalse();
public Optional<ApplicationEntity> findByIdAndUserIdAndIsDeletedFalse(Long id,Long userId);
}

View File

@@ -49,6 +49,7 @@ public interface FormApi {
@ExampleObject(value = ErrorConstants.BADREQUEST_ERROR_EXAMPLE) })) })
@PutMapping(value = "/{formId}",
produces = { "application/json" })
@PreAuthorize("hasRole('ROLE_SUPER_ADMIN')")
ResponseEntity<Response<FormResponseBean>> updateForm(HttpServletRequest request,
@Parameter(description = "The form ID", required = true) @PathVariable("formId") Long formId,
@Parameter(description = "form request object", required = true) @Valid @RequestBody FormRequest formRequest,@Parameter(description = "force delete flow ",required = true)@RequestParam(value = "forceDeleteFlow",required = true)Boolean forceDeleteFlow);
@@ -78,6 +79,7 @@ public interface FormApi {
@ApiResponse(responseCode = "400", description = "Bad Request", content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, examples = {
@ExampleObject(value = ErrorConstants.BADREQUEST_ERROR_EXAMPLE) })) })
@DeleteMapping(value = "/{formId}")
@PreAuthorize("hasRole('ROLE_SUPER_ADMIN')")
ResponseEntity<Response<Void>> deleteForm(HttpServletRequest request,
@Parameter(description = "The form ID", required = true) @PathVariable("formId") Long formId);

View File

@@ -13,6 +13,7 @@ import net.gepafin.tendermanagement.model.util.Response;
import net.gepafin.tendermanagement.web.rest.api.errors.ErrorConstants;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import java.util.List;
@@ -30,6 +31,7 @@ public interface FormFieldApi {
@ExampleObject(value = ErrorConstants.BADREQUEST_ERROR_EXAMPLE) }))
})
@PostMapping(value = "", produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE)
@PreAuthorize("hasRole('ROLE_SUPER_ADMIN')")
public ResponseEntity<Response<FormFieldResponseBean>> createFormField(HttpServletRequest request,
@Parameter(description = "form field request object", required = true)
@Valid @RequestBody FormFieldRequest formFieldRequest);
@@ -46,6 +48,7 @@ public interface FormFieldApi {
@ExampleObject(value = ErrorConstants.BADREQUEST_ERROR_EXAMPLE) })) })
@PutMapping(value = "/{formFieldId}",
produces = { "application/json" })
@PreAuthorize("hasRole('ROLE_SUPER_ADMIN')")
ResponseEntity<Response<FormFieldResponseBean>> updateFormField(HttpServletRequest request,
@Parameter(description = "The form field ID", required = true) @PathVariable("formFieldId") Long formFieldId,
@Parameter(description = "form field request object", required = true) @Valid @RequestBody FormFieldRequest formFieldRequest);
@@ -61,6 +64,7 @@ public interface FormFieldApi {
@ExampleObject(value = ErrorConstants.BADREQUEST_ERROR_EXAMPLE) })) })
@GetMapping(value = "/{formFieldId}",
produces = { "application/json" })
@PreAuthorize("hasRole('ROLE_SUPER_ADMIN')")
ResponseEntity<Response<FormFieldResponseBean>> getFormFieldById(HttpServletRequest request,
@Parameter(description = "The form field ID", required = true) @PathVariable("formFieldId") Long formFieldId);
@@ -75,6 +79,7 @@ public interface FormFieldApi {
@ApiResponse(responseCode = "400", description = "Bad Request", content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, examples = {
@ExampleObject(value = ErrorConstants.BADREQUEST_ERROR_EXAMPLE) })) })
@DeleteMapping(value = "/{formFieldId}")
@PreAuthorize("hasRole('ROLE_SUPER_ADMIN')")
ResponseEntity<Response<Void>> deleteForm(HttpServletRequest request,
@Parameter(description = "The form field ID", required = true) @PathVariable("formFieldId") Long formFieldId);
@@ -89,6 +94,7 @@ public interface FormFieldApi {
@ExampleObject(value = ErrorConstants.BADREQUEST_ERROR_EXAMPLE) })) })
@GetMapping(value = "",
produces = { "application/json" })
@PreAuthorize("hasRole('ROLE_SUPER_ADMIN')")
ResponseEntity<Response<List<FormFieldResponseBean>>> getAllFormField(HttpServletRequest request);
}

View File

@@ -188,3 +188,6 @@ application.is.incomplete = The application is incomplete.
token.validate.success=Token validated successfully.
invalid.request=Invalid Request.
codice.fiscale.exists=This codice fiscale is already associated with another user.
total.steps.not.zero=Total steps cannot be zero.
completed.steps.not.valid=Completed steps should be between 0 and total steps.
field.id.not.found=Field ID {0} does not exist in the form structure.

View File

@@ -8,7 +8,7 @@ delete_user_error_msg=Si <20> verificato un errore durante l'eliminazione dell'ut
get_user_success_msg=Utente recuperato con successo.
get_user_error_msg=Si <20> verificato un errore durante il recupero dell'utente.
user.not.active=Utente non attivo. Si prega di contattare il supporto.
user.already.exist.msg=L'utente esiste già per questo codice fiscale.
user.already.exist.msg=L'utente esiste gi<EFBFBD> per questo codice fiscale.
# Role-related messages
role.created.success=Ruolo creato con successo.
role.updated.success=Ruolo aggiornato con successo.
@@ -179,4 +179,8 @@ valid.vat.number=Il numero di partita IVA non <20> valido per il campo {0}.
failed.retain.field=Impossibile conservare campi specifici.
token.validate.success=Token convalidato con successo.
invalid.request=Richiesta non valida.
codice.fiscale.exists=Questo codice fiscale è già associato ad un altro utente.
codice.fiscale.exists=Questo codice fiscale <EFBFBD> gi<EFBFBD> associato ad un altro utente.
total.steps.not.zero=Il totale dei passaggi non pu<70> essere zero.
completed.steps.not.valid=I passaggi completati devono essere compresi tra 0 e il totale dei passaggi.
field.id.not.found=L'ID campo {0} non esiste nella struttura del modulo.