diff --git a/src/main/java/net/gepafin/tendermanagement/constants/GepafinConstant.java b/src/main/java/net/gepafin/tendermanagement/constants/GepafinConstant.java index c5b18460..4157f714 100644 --- a/src/main/java/net/gepafin/tendermanagement/constants/GepafinConstant.java +++ b/src/main/java/net/gepafin/tendermanagement/constants/GepafinConstant.java @@ -251,5 +251,13 @@ public class GepafinConstant { public static final String APPLICATION_NOT_IN_DRAFT_STATUS="application.not.in.draft.status"; public static final String GET_ERROR_S3 = "get.error.s3"; public static final String INVALID_APPLICATION_STATUS = "invalid.application.status"; + + public static final String APPLICATION_DATA_FOR_AMENDMENT_SUCCESS_MSG = "application.data.amendment.success"; + public static final String DELETE_APPLICATION_AMENDMENT_SUCCESS_MSG = "delete.application.amendment.success"; + public static final String CREATE_APPLICATION_DATA_FOR_AMENDMENT_MSG = "create.application.data.amendment.msg"; + public static final String APPLICATION_AMENDMENT_NOT_FOUND_MSG = "application.amendment.not.found"; + public static final String GET_APPLICATION_AMENDMENT_SUCCESS_MSG = "application.amendment.get.success"; + public static final String APPLICATION_AMENDMENT_UPDATE_SUCCESSFULLY_MSG = "application.amendment.update.successfully"; + } diff --git a/src/main/java/net/gepafin/tendermanagement/dao/ApplicationAmendmentRequestDao.java b/src/main/java/net/gepafin/tendermanagement/dao/ApplicationAmendmentRequestDao.java new file mode 100644 index 00000000..8800490e --- /dev/null +++ b/src/main/java/net/gepafin/tendermanagement/dao/ApplicationAmendmentRequestDao.java @@ -0,0 +1,314 @@ +package net.gepafin.tendermanagement.dao; + +import com.fasterxml.jackson.core.type.TypeReference; +import com.fasterxml.jackson.databind.ObjectMapper; +import jakarta.servlet.http.HttpServletRequest; +import net.gepafin.tendermanagement.config.Translator; +import net.gepafin.tendermanagement.constants.GepafinConstant; +import net.gepafin.tendermanagement.entities.*; +import net.gepafin.tendermanagement.model.request.ApplicationAmendmentRequest; +import net.gepafin.tendermanagement.model.request.ApplicationAmendmentRequestBean; +import net.gepafin.tendermanagement.model.request.ApplicationFormFieldRequestBean; +import net.gepafin.tendermanagement.model.response.AmendmentFormFieldResponse; +import net.gepafin.tendermanagement.model.response.ApplicationAmendmentRequestResponse; +import net.gepafin.tendermanagement.repositories.*; +import net.gepafin.tendermanagement.service.ApplicationService; +import net.gepafin.tendermanagement.service.UserService; +import net.gepafin.tendermanagement.util.DateTimeUtil; +import net.gepafin.tendermanagement.web.rest.api.errors.ResourceNotFoundException; +import net.gepafin.tendermanagement.web.rest.api.errors.Status; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +import java.time.LocalDateTime; +import java.util.*; +import java.util.stream.Collectors; + +import static net.gepafin.tendermanagement.util.Utils.log; +import static net.gepafin.tendermanagement.util.Utils.setIfUpdated; + +@Component +public class ApplicationAmendmentRequestDao { + @Autowired + private ApplicationService applicationService; + + @Autowired + private FormRepository formRepository; + + @Autowired + private UserService userService; + + @Autowired + private ApplicationFormRepository applicationFormRepository; + + @Autowired + private ApplicationAmendmentRequestRepository applicationAmendmentRequestRepository; + + @Autowired + private ApplicationFormFieldRepository applicationFormFieldRepository; + + @Autowired + private DocumentRepository documentRepository; + + public List getApplicationDataForAmendment(HttpServletRequest request,Long applicationId){ + log.info("Fetching the application data for the Amendment process {}", applicationId); + ApplicationEntity application = applicationService.validateApplication(applicationId); + String callName = application.getCall().getName(); + Long protocolNumber = (application.getProtocol() != null && application.getProtocol().getProtocolNumber() != null) + ? application.getProtocol().getProtocolNumber() + : null; + + UserEntity userEntity = userService.validateUser(application.getUserId()); + String firstName = userEntity.getBeneficiary() != null ? userEntity.getBeneficiary().getFirstName() : ""; + String lastName = userEntity.getBeneficiary() != null ? userEntity.getBeneficiary().getLastName() : ""; + + String beneficiaryName = (!firstName.isBlank() ? firstName : "") + + (!lastName.isBlank() ? " " + lastName : ""); + + beneficiaryName = beneficiaryName.isBlank() ? "" : beneficiaryName; + + List forms = applicationFormRepository.findByApplicationId(applicationId); + List responses = new ArrayList<>(); + + for (ApplicationFormEntity form : forms) { + String content = form.getForm().getContent(); + List> result = filterByName(content, "fileupload"); + List formFields = getIdAndLabelFromResult(result); + + ApplicationAmendmentRequestResponse response = convertEntityToResponse( + protocolNumber, callName, formFields, beneficiaryName); + + responses.add(response); + } + + return responses; + } + + public List getIdAndLabelFromResult(List> result) { + List formFieldResponses = new ArrayList<>(); + + for (Map item : result) { + AmendmentFormFieldResponse formFieldResponse = new AmendmentFormFieldResponse(); + formFieldResponse.setFieldId((String) item.get("id")); + + // Extract "label" value from the "settings" array + List> settings = (List>) item.get("settings"); + String label = settings.stream() + .filter(setting -> "label".equals(setting.get("name"))) + .map(setting -> (String) setting.get("value")) + .findFirst() + .orElse(""); // Default to empty string if not found + + if (label == null || label.trim().isEmpty()) { + continue; + } + + formFieldResponse.setLabel(label); // Set the label as fieldValue + formFieldResponses.add(formFieldResponse); + } + + return formFieldResponses; + } + + + + private ApplicationAmendmentRequestResponse convertEntityToResponse( + Long protocolNumber, String callName, + List formFields,String beneficiaryName) { + + ApplicationAmendmentRequestResponse response = new ApplicationAmendmentRequestResponse(); + response.setProtocolNumber(protocolNumber); + response.setCallName(callName); + response.setBeneficiaryName(beneficiaryName); + response.setFormFields(formFields); + response.setResponseDays(null); + response.setSendEmail(false); + response.setSendNotification(false); + response.setNote(null); + response.setStartDate(null); + return response; + } + + public static List> filterByName(String content, String target) { + ObjectMapper objectMapper = new ObjectMapper(); + List> filteredList = new ArrayList<>(); + + try { + List> dataList = objectMapper.readValue( + content, new TypeReference>>() {}); + + for (Map data : dataList) { + if (target.equals(data.get("name"))) { + filteredList.add(data); + } + } + } catch (Exception e) { + e.printStackTrace(); + } + + return filteredList; + } + + public ApplicationAmendmentRequestResponse createApplicationAmendmentRequest(Long applicationId, ApplicationAmendmentRequest applicationAmendmentRequest){ + log.info("Submiting application data for amendment Process with details: {}", applicationId); + + ApplicationAmendmentRequestEntity applicationAmendmentRequestEntity = createApplicationAmendmentRequestEntity(applicationAmendmentRequest); + ApplicationAmendmentRequestResponse applicationAmendmentRequestResponse = convertEntityToResponse(applicationAmendmentRequestEntity); + log.info("Application submitted successfully for amendment", applicationAmendmentRequestResponse); + return applicationAmendmentRequestResponse; + } + + public ApplicationAmendmentRequestEntity createApplicationAmendmentRequestEntity(ApplicationAmendmentRequest applicationAmendmentRequest){ + ApplicationAmendmentRequestEntity applicationAmendmentRequestEntity = new ApplicationAmendmentRequestEntity(); + applicationAmendmentRequestEntity.setNote(applicationAmendmentRequest.getNote()); + applicationAmendmentRequestEntity.setResponseDays(applicationAmendmentRequest.getResponseDays()); + + if (applicationAmendmentRequest.getFormFields() != null) { + String fieldIdsString = applicationAmendmentRequest.getFormFields().stream() + .filter(AmendmentFormFieldResponse::isSelected) + .map(AmendmentFormFieldResponse::getFieldId) + .collect(Collectors.joining(",")); + applicationAmendmentRequestEntity.setFormFields(fieldIdsString); + } + + applicationAmendmentRequestEntity.setIsEmail(false); + applicationAmendmentRequestEntity.setIsNotification(false); + ApplicationAmendmentRequestEntity applicationAmendment = saveApplicationAmendmentRequestEntity(applicationAmendmentRequestEntity); + return applicationAmendment; + } + + public ApplicationAmendmentRequestEntity saveApplicationAmendmentRequestEntity(ApplicationAmendmentRequestEntity applicationAmendmentRequestEntity){ + ApplicationAmendmentRequestEntity applicationAmendmentRequest= applicationAmendmentRequestRepository.save(applicationAmendmentRequestEntity); + return applicationAmendmentRequest; + } + + public ApplicationAmendmentRequestResponse convertEntityToResponse(ApplicationAmendmentRequestEntity applicationAmendmentRequestEntity){ + ApplicationAmendmentRequestResponse applicationAmendmentRequestResponse = new ApplicationAmendmentRequestResponse(); + applicationAmendmentRequestResponse.setId(applicationAmendmentRequestEntity.getId()); + Long applicationId = 1L; + ApplicationEntity application = applicationService.validateApplication(applicationId); + applicationAmendmentRequestResponse.setNote(applicationAmendmentRequestEntity.getNote()); + applicationAmendmentRequestResponse.setResponseDays(applicationAmendmentRequestEntity.getResponseDays()); + applicationAmendmentRequestResponse.setStartDate(applicationAmendmentRequestEntity.getCreatedDate()); + applicationAmendmentRequestResponse.setSendEmail(applicationAmendmentRequestEntity.getIsEmail()); + applicationAmendmentRequestResponse.setSendNotification(applicationAmendmentRequestEntity.getIsNotification()); + String callName = application.getCall().getName(); + Long protocolNumber = (application.getProtocol() != null && application.getProtocol().getProtocolNumber() != null) + ? application.getProtocol().getProtocolNumber() + : null; + UserEntity userEntity = userService.validateUser(application.getUserId()); + String firstName = userEntity.getBeneficiary() != null ? userEntity.getBeneficiary().getFirstName() : ""; + String lastName = userEntity.getBeneficiary() != null ? userEntity.getBeneficiary().getLastName() : ""; + + String beneficiaryName = (!firstName.isBlank() ? firstName : "") + + (!lastName.isBlank() ? " " + lastName : ""); + + beneficiaryName = beneficiaryName.isBlank() ? "" : beneficiaryName; + applicationAmendmentRequestResponse.setCallName(callName); + applicationAmendmentRequestResponse.setProtocolNumber(protocolNumber); + applicationAmendmentRequestResponse.setBeneficiaryName(beneficiaryName); + + String formFieldsString = applicationAmendmentRequestEntity.getFormFields(); + List storedFieldIds = (formFieldsString != null) ? Arrays.asList(formFieldsString.split(",")) : Collections.emptyList(); + List applicationForms = applicationFormRepository.findByApplicationId(application.getId()); + List formFields = new ArrayList<>(); + for (ApplicationFormEntity formEntity : applicationForms) { + String content = formEntity.getForm().getContent(); + List> result = filterByName(content, "fileupload"); + + List matchingFields = getIdAndLabelFromResult(result).stream() + .filter(field -> storedFieldIds.contains(field.getFieldId())) + .collect(Collectors.toList()); + formFields.addAll(matchingFields); + } + applicationAmendmentRequestResponse.setFormFields(formFields); + + List formField = formFields.stream() + .map(field -> { + AmendmentFormFieldResponse responseField = new AmendmentFormFieldResponse(); + responseField.setFieldId(field.getFieldId()); + responseField.setLabel(field.getLabel()); + responseField.setSelected(true); + return responseField; + }) + .collect(Collectors.toList()); + + applicationAmendmentRequestResponse.setFormFields(formFields); + + return applicationAmendmentRequestResponse; + } + + public ApplicationAmendmentRequestEntity validateApplicationAmendmentRequest(Long id){ + ApplicationAmendmentRequestEntity applicationAmendmentRequestEntity = applicationAmendmentRequestRepository.findByIdAndIsDeletedFalse(id).orElseThrow(()-> + new ResourceNotFoundException(Status.NOT_FOUND, Translator.toLocale(GepafinConstant.APPLICATION_AMENDMENT_NOT_FOUND_MSG))); + return applicationAmendmentRequestEntity; + } + + public void deleteById(Long id) { + log.info("Deleting assigned application with ID: {}", id); + ApplicationAmendmentRequestEntity applicationAmendmentRequestEntity= validateApplicationAmendmentRequest(id); + applicationAmendmentRequestEntity.setIsDeleted(true); + applicationAmendmentRequestEntity= saveApplicationAmendmentRequestEntity(applicationAmendmentRequestEntity); + log.info(" Application amendment deleted with ID: {}", id); + } + + public ApplicationAmendmentRequestResponse getApplicationAmendmentRequestById(Long id) { + log.info("Fetching application amendment with ID: {}", id); + ApplicationAmendmentRequestEntity applicationAmendmentRequestEntity = validateApplicationAmendmentRequest(id); + ApplicationAmendmentRequestResponse response = convertEntityToResponse(applicationAmendmentRequestEntity); + log.info("Application Amendment fetched successfully by ID: {}", response); + return response; + } + + public List getAllApplicationAmendmentRequest() { + List applicationAmendmentRequestEntities = + applicationAmendmentRequestRepository.findAll(); + + return applicationAmendmentRequestEntities.stream() + .map(this::convertEntityToResponse) + .collect(Collectors.toList()); + } + + + public ApplicationAmendmentRequestResponse updateApplicationAmendment( + Long id, ApplicationAmendmentRequestBean updateRequest) { + + log.info("Updating application amendement with ID: {}", id); + ApplicationAmendmentRequestEntity existingApplicationAmendment = validateApplicationAmendmentRequest(id); + + setIfUpdated(existingApplicationAmendment::getNote, existingApplicationAmendment::setNote, updateRequest.getNote()); + if (updateRequest.getUpdatedFormFields() != null) { + updateApplicationFormFields(existingApplicationAmendment, updateRequest.getUpdatedFormFields()); + } + existingApplicationAmendment.setUpdatedDate(DateTimeUtil.DateServerToUTC(LocalDateTime.now())); + + ApplicationAmendmentRequestEntity updatedApplicationAmendment = saveApplicationAmendmentRequestEntity(existingApplicationAmendment); + ApplicationAmendmentRequestResponse response = convertEntityToResponse(updatedApplicationAmendment); + log.info("Application Amendment updated successfully: {}", response); + return response; + } + + private boolean documentExists(String documentId) { + Long documentIdLong = Long.parseLong(documentId); // Convert to Long + return documentRepository.existsById(documentIdLong); + + } + private void updateApplicationFormFields(ApplicationAmendmentRequestEntity applicationAmendment, ApplicationFormFieldRequestBean updatedFormField) { + List documentIds = Arrays.asList(updatedFormField.getFieldValue().toString().split(",")); + for (String documentId : documentIds) { + if (!documentExists(documentId)) { + log.warn("Document with ID {} does not exist. Skipping update.", documentId); + continue; + } + ApplicationFormFieldEntity formEntity = applicationFormFieldRepository.findByFieldId(updatedFormField.getFieldId()); + + if (formEntity != null) { + formEntity.setFieldValue(updatedFormField.getFieldValue().toString()); + applicationFormFieldRepository.save(formEntity); + log.info("Updated field value for field ID {} with document IDs {}", updatedFormField.getFieldId(), updatedFormField.getFieldValue()); + } else { + log.warn("No ApplicationFormEntity found with field ID {}. Skipping update.", updatedFormField.getFieldId()); + } + } + } +} diff --git a/src/main/java/net/gepafin/tendermanagement/dao/AssignedApplicationsDao.java b/src/main/java/net/gepafin/tendermanagement/dao/AssignedApplicationsDao.java index cfdb31ab..7ec1dbc4 100644 --- a/src/main/java/net/gepafin/tendermanagement/dao/AssignedApplicationsDao.java +++ b/src/main/java/net/gepafin/tendermanagement/dao/AssignedApplicationsDao.java @@ -47,12 +47,6 @@ public class AssignedApplicationsDao { throw new CustomValidationException(Status.BAD_REQUEST, Translator.toLocale(GepafinConstant.APPLICATION_ALREADY_ASSIGNED)); } ApplicationEntity application = applicationService.validateApplication(applicationId); - if (Boolean.FALSE.equals(ApplicationStatusTypeEnum.SUBMIT.equals(application.getStatus()))) { - throw new CustomValidationException( - Status.BAD_REQUEST, - Translator.toLocale(GepafinConstant.INVALID_APPLICATION_STATUS) - ); - } UserEntity user = userService.validateUser(userId); AssignedApplicationsEntity assignment = createAssignmentEntity(application, user.getId(), assignedByUser, assignedApplicationsRequest); AssignedApplicationsResponse assignApplicationToInstructorResponse = convertEntityToResponse(assignment, assignedApplicationsRequest); diff --git a/src/main/java/net/gepafin/tendermanagement/entities/ApplicationAmendmentRequestEntity.java b/src/main/java/net/gepafin/tendermanagement/entities/ApplicationAmendmentRequestEntity.java new file mode 100644 index 00000000..b13792e2 --- /dev/null +++ b/src/main/java/net/gepafin/tendermanagement/entities/ApplicationAmendmentRequestEntity.java @@ -0,0 +1,31 @@ +package net.gepafin.tendermanagement.entities; + +import jakarta.persistence.Column; +import jakarta.persistence.Entity; +import jakarta.persistence.Table; +import lombok.Data; + +@Entity +@Table(name="application_amendment_request") +@Data +public class ApplicationAmendmentRequestEntity extends BaseEntity { + + @Column(name = "NOTE") + private String note; + + @Column(name ="RESPONSE_DAYS") + private Long responseDays; + + @Column(name = "IS_NOTIFICATION") + private Boolean isNotification = false; + + @Column(name = "IS_EMAIL") + private Boolean isEmail=false; + + @Column(name = "FORM_FIELDS") + private String formFields; + + @Column(name="IS_DELETED") + private Boolean isDeleted=false; + +} diff --git a/src/main/java/net/gepafin/tendermanagement/model/request/ApplicationAmendmentRequest.java b/src/main/java/net/gepafin/tendermanagement/model/request/ApplicationAmendmentRequest.java new file mode 100644 index 00000000..0ecf1f00 --- /dev/null +++ b/src/main/java/net/gepafin/tendermanagement/model/request/ApplicationAmendmentRequest.java @@ -0,0 +1,12 @@ +package net.gepafin.tendermanagement.model.request; + +import lombok.Data; +import net.gepafin.tendermanagement.model.response.AmendmentFormFieldResponse; +import java.util.List; + +@Data +public class ApplicationAmendmentRequest { + private String note; + private List formFields; + private Long responseDays; +} diff --git a/src/main/java/net/gepafin/tendermanagement/model/request/ApplicationAmendmentRequestBean.java b/src/main/java/net/gepafin/tendermanagement/model/request/ApplicationAmendmentRequestBean.java new file mode 100644 index 00000000..b845fe0e --- /dev/null +++ b/src/main/java/net/gepafin/tendermanagement/model/request/ApplicationAmendmentRequestBean.java @@ -0,0 +1,9 @@ +package net.gepafin.tendermanagement.model.request; + +import lombok.Data; + +@Data +public class ApplicationAmendmentRequestBean { + private String note; + private ApplicationFormFieldRequestBean updatedFormFields; +} diff --git a/src/main/java/net/gepafin/tendermanagement/model/response/AmendmentFormFieldResponse.java b/src/main/java/net/gepafin/tendermanagement/model/response/AmendmentFormFieldResponse.java new file mode 100644 index 00000000..d3fdda8f --- /dev/null +++ b/src/main/java/net/gepafin/tendermanagement/model/response/AmendmentFormFieldResponse.java @@ -0,0 +1,10 @@ +package net.gepafin.tendermanagement.model.response; + +import lombok.Data; + +@Data +public class AmendmentFormFieldResponse { + private String fieldId; + private String label; + private boolean isSelected = false; +} diff --git a/src/main/java/net/gepafin/tendermanagement/model/response/ApplicationAmendmentRequestResponse.java b/src/main/java/net/gepafin/tendermanagement/model/response/ApplicationAmendmentRequestResponse.java new file mode 100644 index 00000000..7758de10 --- /dev/null +++ b/src/main/java/net/gepafin/tendermanagement/model/response/ApplicationAmendmentRequestResponse.java @@ -0,0 +1,22 @@ +package net.gepafin.tendermanagement.model.response; + +import lombok.Data; + +import java.time.LocalDateTime; +import java.util.List; + +@Data +public class ApplicationAmendmentRequestResponse { + private Long id; + private String note; + private Long responseDays; + private LocalDateTime startDate; + private boolean isSendNotification; + private boolean isSendEmail; + private Long protocolNumber; + private String callName; + private String beneficiaryName; + private List formFields; + private List updatedFormFields; + +} diff --git a/src/main/java/net/gepafin/tendermanagement/repositories/ApplicationAmendmentRequestRepository.java b/src/main/java/net/gepafin/tendermanagement/repositories/ApplicationAmendmentRequestRepository.java new file mode 100644 index 00000000..f1633356 --- /dev/null +++ b/src/main/java/net/gepafin/tendermanagement/repositories/ApplicationAmendmentRequestRepository.java @@ -0,0 +1,10 @@ +package net.gepafin.tendermanagement.repositories; + +import net.gepafin.tendermanagement.entities.ApplicationAmendmentRequestEntity; +import org.springframework.data.jpa.repository.JpaRepository; + +import java.util.Optional; + +public interface ApplicationAmendmentRequestRepository extends JpaRepository { + Optional findByIdAndIsDeletedFalse(Long id); +} diff --git a/src/main/java/net/gepafin/tendermanagement/repositories/ApplicationFormFieldRepository.java b/src/main/java/net/gepafin/tendermanagement/repositories/ApplicationFormFieldRepository.java index 89c70488..44c3cc3e 100644 --- a/src/main/java/net/gepafin/tendermanagement/repositories/ApplicationFormFieldRepository.java +++ b/src/main/java/net/gepafin/tendermanagement/repositories/ApplicationFormFieldRepository.java @@ -24,4 +24,6 @@ public interface ApplicationFormFieldRepository extends JpaRepository findByFieldValueInAndApplicationFormApplicationId( List fieldValue, Long applicationId); + public ApplicationFormFieldEntity findByFieldId(String FieldId); + } diff --git a/src/main/java/net/gepafin/tendermanagement/service/ApplicationAmendmentRequestService.java b/src/main/java/net/gepafin/tendermanagement/service/ApplicationAmendmentRequestService.java new file mode 100644 index 00000000..d32c2a29 --- /dev/null +++ b/src/main/java/net/gepafin/tendermanagement/service/ApplicationAmendmentRequestService.java @@ -0,0 +1,18 @@ +package net.gepafin.tendermanagement.service; + +import jakarta.servlet.http.HttpServletRequest; +import net.gepafin.tendermanagement.model.request.ApplicationAmendmentRequest; +import net.gepafin.tendermanagement.model.request.ApplicationAmendmentRequestBean; +import net.gepafin.tendermanagement.model.response.ApplicationAmendmentRequestResponse; + +import java.util.List; + +public interface ApplicationAmendmentRequestService { + public List getApplicationDataForAmendment(HttpServletRequest request,Long applicationId); + public ApplicationAmendmentRequestResponse createApplicationAmendmentRequest(HttpServletRequest request, Long applicationEvaluationId , ApplicationAmendmentRequest applicationAmendmentRequest); + void deleteApplicationAmendmentRequest(HttpServletRequest request, Long id); + ApplicationAmendmentRequestResponse getApplicationAmendmentRequestById(HttpServletRequest request,Long id); + List getAllApplicationAmendmentRequest(HttpServletRequest request); + ApplicationAmendmentRequestResponse updateApplicationAmendment(HttpServletRequest request, Long id, ApplicationAmendmentRequestBean applicationAmendmentRequestBean); + +} diff --git a/src/main/java/net/gepafin/tendermanagement/service/impl/ApplicationAmendmentRequestServiceImpl.java b/src/main/java/net/gepafin/tendermanagement/service/impl/ApplicationAmendmentRequestServiceImpl.java new file mode 100644 index 00000000..fd190f3d --- /dev/null +++ b/src/main/java/net/gepafin/tendermanagement/service/impl/ApplicationAmendmentRequestServiceImpl.java @@ -0,0 +1,61 @@ +package net.gepafin.tendermanagement.service.impl; + +import jakarta.servlet.http.HttpServletRequest; +import net.gepafin.tendermanagement.dao.ApplicationAmendmentRequestDao; +import net.gepafin.tendermanagement.entities.UserEntity; +import net.gepafin.tendermanagement.model.request.ApplicationAmendmentRequest; +import net.gepafin.tendermanagement.model.request.ApplicationAmendmentRequestBean; +import net.gepafin.tendermanagement.model.response.ApplicationAmendmentRequestResponse; +import net.gepafin.tendermanagement.service.ApplicationAmendmentRequestService; +import net.gepafin.tendermanagement.util.Validator; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.util.List; + +@Service +public class ApplicationAmendmentRequestServiceImpl implements ApplicationAmendmentRequestService { + + @Autowired + private Validator validator; + + @Autowired + private ApplicationAmendmentRequestDao applicationAmendmentRequestDao; + + @Override + public List getApplicationDataForAmendment(HttpServletRequest request, Long applicationId) { + UserEntity user= validator.validateUser(request); + return applicationAmendmentRequestDao.getApplicationDataForAmendment(request,applicationId); + } + + @Override + public ApplicationAmendmentRequestResponse createApplicationAmendmentRequest(HttpServletRequest request, Long applicationEvaluationId , ApplicationAmendmentRequest applicationAmendmentRequest) { + UserEntity user= validator.validateUser(request); + return applicationAmendmentRequestDao.createApplicationAmendmentRequest(applicationEvaluationId,applicationAmendmentRequest); + } + + + + @Override + public void deleteApplicationAmendmentRequest(HttpServletRequest request, Long id) { + applicationAmendmentRequestDao.deleteById(id); + } + + @Override + public ApplicationAmendmentRequestResponse getApplicationAmendmentRequestById(HttpServletRequest request,Long id) { + return applicationAmendmentRequestDao.getApplicationAmendmentRequestById(id); + } + + @Override + public List getAllApplicationAmendmentRequest(HttpServletRequest request) { + return applicationAmendmentRequestDao.getAllApplicationAmendmentRequest(); + } + + @Override + public ApplicationAmendmentRequestResponse updateApplicationAmendment(HttpServletRequest request, Long id, ApplicationAmendmentRequestBean applicationAmendmentRequestBean) { + UserEntity updatedByUser= validator.validateUser(request); + return applicationAmendmentRequestDao.updateApplicationAmendment(id,applicationAmendmentRequestBean); + } + + +} diff --git a/src/main/java/net/gepafin/tendermanagement/web/rest/api/ApplicationAmendmentRequestApi.java b/src/main/java/net/gepafin/tendermanagement/web/rest/api/ApplicationAmendmentRequestApi.java new file mode 100644 index 00000000..5cef3b39 --- /dev/null +++ b/src/main/java/net/gepafin/tendermanagement/web/rest/api/ApplicationAmendmentRequestApi.java @@ -0,0 +1,102 @@ +package net.gepafin.tendermanagement.web.rest.api; + +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.Parameter; +import io.swagger.v3.oas.annotations.media.Content; +import io.swagger.v3.oas.annotations.media.ExampleObject; +import io.swagger.v3.oas.annotations.responses.ApiResponse; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.validation.Valid; +import net.gepafin.tendermanagement.model.request.ApplicationAmendmentRequest; +import net.gepafin.tendermanagement.model.request.ApplicationAmendmentRequestBean; +import net.gepafin.tendermanagement.model.response.ApplicationAmendmentRequestResponse; +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.validation.annotation.Validated; +import org.springframework.web.bind.annotation.*; + +import java.util.List; + +@Validated +public interface ApplicationAmendmentRequestApi { + @Operation(summary = "Api to get application data for the Amendment process", + responses = { + @ApiResponse(responseCode = "200", description = "OK"), + @ApiResponse(responseCode = "404", description = "Not Found", content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, examples = { + @ExampleObject(value = ErrorConstants.NOTFOUND_ERROR_EXAMPLE) })), + @ApiResponse(responseCode = "401", description = "Unauthorized", content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, examples = { + @ExampleObject(value = ErrorConstants.UNAUTHORIZED_ERROR_EXAMPLE) })), + @ApiResponse(responseCode = "400", description = "Bad Request", content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, examples = { + @ExampleObject(value = ErrorConstants.BADREQUEST_ERROR_EXAMPLE) })) }) + @GetMapping(value = "/{applicationId}", produces = "application/json") + ResponseEntity>> getApplicationDataForAmendment(HttpServletRequest request, @Parameter(description = "The application id", required = true) @PathVariable(value = "applicationId", required = true) Long applicationId); + + @Operation(summary = "Api to submit the application data for the Amendment", + responses = { + @ApiResponse(responseCode = "200", description = "OK"), + @ApiResponse(responseCode = "404", description = "Not Found", content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, examples = { + @ExampleObject(value = ErrorConstants.NOTFOUND_ERROR_EXAMPLE) })), + @ApiResponse(responseCode = "401", description = "Unauthorized", content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, examples = { + @ExampleObject(value = ErrorConstants.UNAUTHORIZED_ERROR_EXAMPLE) })), + @ApiResponse(responseCode = "400", description = "Bad Request", content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, examples = { + @ExampleObject(value = ErrorConstants.BADREQUEST_ERROR_EXAMPLE) })) }) + @PostMapping(value = "", produces = "application/json") + ResponseEntity> createApplicationAmendmentRequest(HttpServletRequest request, + @Parameter(description = "Application Evaluation Id", required = true) @RequestParam Long applicationEvaluationId, + @Valid @RequestBody ApplicationAmendmentRequest applicationAmendmentRequest); + + @Operation(summary = "Api to delete application amendment request", + responses = { + @ApiResponse(responseCode = "200", description = "OK"), + @ApiResponse(responseCode = "404", description = "Not Found", content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, examples = { + @ExampleObject(value = ErrorConstants.NOTFOUND_ERROR_EXAMPLE) })), + @ApiResponse(responseCode = "401", description = "Unauthorized", content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, examples = { + @ExampleObject(value = ErrorConstants.UNAUTHORIZED_ERROR_EXAMPLE) })), + @ApiResponse(responseCode = "400", description = "Bad Request", content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, examples = { + @ExampleObject(value = ErrorConstants.BADREQUEST_ERROR_EXAMPLE) })) }) + @DeleteMapping(value = "/{id}") + ResponseEntity> deleteApplicationAmendmentRequest(HttpServletRequest request, + @Parameter(description = "The application Amendment id", required = true) @PathVariable("id") Long id); + + @Operation(summary = "Api to get an application amendment by id", + responses = { + @ApiResponse(responseCode = "200", description = "OK"), + @ApiResponse(responseCode = "404", description = "Not Found", content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, examples = { + @ExampleObject(value = ErrorConstants.NOTFOUND_ERROR_EXAMPLE) })), + @ApiResponse(responseCode = "401", description = "Unauthorized", content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, examples = { + @ExampleObject(value = ErrorConstants.UNAUTHORIZED_ERROR_EXAMPLE) })), + @ApiResponse(responseCode = "400", description = "Bad Request", content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, examples = { + @ExampleObject(value = ErrorConstants.BADREQUEST_ERROR_EXAMPLE) })) }) + @GetMapping(value = "", produces = "application/json") + ResponseEntity> getApplicationAmendmentRequestById(HttpServletRequest request,@Parameter(description = "The application amendment id", required = true) @RequestParam(value = "id", required = true) Long id); + + @Operation(summary = "Api to get all applications amendment request", + responses = { + @ApiResponse(responseCode = "200", description = "OK"), + @ApiResponse(responseCode = "404", description = "Not Found", content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, examples = { + @ExampleObject(value = ErrorConstants.NOTFOUND_ERROR_EXAMPLE) })), + @ApiResponse(responseCode = "401", description = "Unauthorized", content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, examples = { + @ExampleObject(value = ErrorConstants.UNAUTHORIZED_ERROR_EXAMPLE) })), + @ApiResponse(responseCode = "400", description = "Bad Request", content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, examples = { + @ExampleObject(value = ErrorConstants.BADREQUEST_ERROR_EXAMPLE) })) }) + @GetMapping(value = "/getAll", produces = "application/json") + ResponseEntity>> getAllApplicationAmendmentRequest(HttpServletRequest request); + + @Operation(summary = "Api to update application amendment", + responses = { + @ApiResponse(responseCode = "200", description = "OK"), + @ApiResponse(responseCode = "404", description = "Not Found", content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, examples = { + @ExampleObject(value = ErrorConstants.NOTFOUND_ERROR_EXAMPLE) })), + @ApiResponse(responseCode = "401", description = "Unauthorized", content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, examples = { + @ExampleObject(value = ErrorConstants.UNAUTHORIZED_ERROR_EXAMPLE) })), + @ApiResponse(responseCode = "400", description = "Bad Request", content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, examples = { + @ExampleObject(value = ErrorConstants.BADREQUEST_ERROR_EXAMPLE) })) + }) + @PutMapping(value = "/{id}", produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE) + public ResponseEntity> updateApplicationAmendment(HttpServletRequest request, + @Parameter(description = "The Application Amendment id", required = true) @PathVariable("id") Long id, + @Parameter(description = "Assigned Application request object", required = true) @Valid @RequestBody ApplicationAmendmentRequestBean applicationAmendmentRequestBean); + +} diff --git a/src/main/java/net/gepafin/tendermanagement/web/rest/api/impl/ApplicationAmendmentRequestController.java b/src/main/java/net/gepafin/tendermanagement/web/rest/api/impl/ApplicationAmendmentRequestController.java new file mode 100644 index 00000000..a9bb8d8e --- /dev/null +++ b/src/main/java/net/gepafin/tendermanagement/web/rest/api/impl/ApplicationAmendmentRequestController.java @@ -0,0 +1,74 @@ +package net.gepafin.tendermanagement.web.rest.api.impl; + +import jakarta.servlet.http.HttpServletRequest; +import lombok.extern.log4j.Log4j2; +import net.gepafin.tendermanagement.config.Translator; +import net.gepafin.tendermanagement.constants.GepafinConstant; +import net.gepafin.tendermanagement.model.request.ApplicationAmendmentRequest; +import net.gepafin.tendermanagement.model.request.ApplicationAmendmentRequestBean; +import net.gepafin.tendermanagement.model.response.ApplicationAmendmentRequestResponse; +import net.gepafin.tendermanagement.model.util.Response; +import net.gepafin.tendermanagement.service.ApplicationAmendmentRequestService; +import net.gepafin.tendermanagement.web.rest.api.ApplicationAmendmentRequestApi; +import net.gepafin.tendermanagement.web.rest.api.errors.Status; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; +import java.util.List; + +@RestController +@RequestMapping("${openapi.gepafin.base-path:/v1/amendments}") +@Log4j2 +public class ApplicationAmendmentRequestController implements ApplicationAmendmentRequestApi { + + @Autowired + ApplicationAmendmentRequestService applicationAmendmentRequestService; + + @Override + public ResponseEntity>> getApplicationDataForAmendment(HttpServletRequest request, Long applicationId) { + List applicationAmendmentBean = applicationAmendmentRequestService.getApplicationDataForAmendment(request,applicationId); + return ResponseEntity.status(HttpStatus.OK) + .body(new Response<>(applicationAmendmentBean, Status.SUCCESS, Translator.toLocale(GepafinConstant.APPLICATION_DATA_FOR_AMENDMENT_SUCCESS_MSG))); + } + + @Override + public ResponseEntity> createApplicationAmendmentRequest(HttpServletRequest request, Long applicationEvaluationId, ApplicationAmendmentRequest applicationAmendmentRequest) { + ApplicationAmendmentRequestResponse applicationAmendmentRequestResponse = applicationAmendmentRequestService.createApplicationAmendmentRequest(request,applicationEvaluationId,applicationAmendmentRequest); + return ResponseEntity.status(HttpStatus.OK) + .body(new Response<>(applicationAmendmentRequestResponse, Status.SUCCESS, Translator.toLocale(GepafinConstant.CREATE_APPLICATION_DATA_FOR_AMENDMENT_MSG))); + } + + @Override + public ResponseEntity> deleteApplicationAmendmentRequest(HttpServletRequest request, Long id) { + log.info("Delete Application Amendment Request- Application Amendment ID: {}", id); + applicationAmendmentRequestService.deleteApplicationAmendmentRequest(request,id); + return ResponseEntity.status(HttpStatus.OK) + .body(new Response<>(null, Status.SUCCESS, Translator.toLocale(GepafinConstant.DELETE_APPLICATION_AMENDMENT_SUCCESS_MSG))); + } + + @Override + public ResponseEntity> getApplicationAmendmentRequestById(HttpServletRequest request,Long id) { + log.info("Get Application Amendment Request By Id"); + ApplicationAmendmentRequestResponse applicationAmendmentRequestResponse = applicationAmendmentRequestService.getApplicationAmendmentRequestById(request,id); + return ResponseEntity.status(HttpStatus.OK) + .body(new Response<>(applicationAmendmentRequestResponse, Status.SUCCESS, Translator.toLocale(GepafinConstant.GET_APPLICATION_AMENDMENT_SUCCESS_MSG))); + } + + @Override + public ResponseEntity>> getAllApplicationAmendmentRequest(HttpServletRequest request) { + log.info("Get All Applications Amendment Request"); + List applicationAmendmentRequestResponses = applicationAmendmentRequestService.getAllApplicationAmendmentRequest(request); + return ResponseEntity.status(HttpStatus.OK) + .body(new Response<>(applicationAmendmentRequestResponses, Status.SUCCESS, Translator.toLocale(GepafinConstant.GET_APPLICATION_AMENDMENT_SUCCESS_MSG))); + } + + @Override + public ResponseEntity> updateApplicationAmendment(HttpServletRequest request, Long id, ApplicationAmendmentRequestBean applicationAmendmentRequestBean) { + log.info("Update Application Amendment"); + ApplicationAmendmentRequestResponse updateApplicationAmendment = applicationAmendmentRequestService.updateApplicationAmendment(request, id, applicationAmendmentRequestBean); + return ResponseEntity.status(HttpStatus.CREATED) + .body(new Response<>(updateApplicationAmendment, Status.SUCCESS, Translator.toLocale(GepafinConstant.APPLICATION_AMENDMENT_UPDATE_SUCCESSFULLY_MSG))); + } +} diff --git a/src/main/resources/db/changelog/db.changelog-1.0.0.xml b/src/main/resources/db/changelog/db.changelog-1.0.0.xml index 5df3a2b7..83dd126c 100644 --- a/src/main/resources/db/changelog/db.changelog-1.0.0.xml +++ b/src/main/resources/db/changelog/db.changelog-1.0.0.xml @@ -1327,5 +1327,45 @@ referencedTableName="hub" referencedColumnNames="id"/> - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/main/resources/message_en.properties b/src/main/resources/message_en.properties index b92a48f9..4cc3f5f5 100644 --- a/src/main/resources/message_en.properties +++ b/src/main/resources/message_en.properties @@ -276,3 +276,9 @@ assigned.application.get.success=Assigned Application details fetched successful assigned.application.update.successfully=Assigned Application updated successfully. get.error.s3=Failed to fetch the file from S3. invalid.application.status = Invalid Application status. + +application.data.amendment.success = Successfully retrieved the application data for the amendment process. +delete.application.amendment.success = Application Amendment successfully deleted. +application.amendment.not.found = Application Amendment Request not found with the given ID. +application.amendment.get.success = Application Amendment details fetched successfully with given ID. +application.amendment.update.successfully = Application Amendment Updated Successfully. \ No newline at end of file diff --git a/src/main/resources/message_it.properties b/src/main/resources/message_it.properties index 214a198e..3fec3019 100644 --- a/src/main/resources/message_it.properties +++ b/src/main/resources/message_it.properties @@ -271,3 +271,9 @@ hub_not_found=Hub non trovato application.not.in.draft.status=La domanda non � in stato DRAFT. get.error.s3=Impossibile recuperare il file da S3. + +application.data.amendment.success = Recupero riuscito dei dati dell'applicazione per il processo di modifica +delete.application.amendment.success =Emendamento all'applicazione eliminato con successo. +application.amendment.not.found = Richiesta di modifica dell'applicazione non trovata con l'ID indicato. +application.amendment.get.success = Dettagli della modifica dell'applicazione recuperati correttamente con l'ID fornito. +application.amendment.update.successfully = Emendamento all'applicazione aggiornato con successo. \ No newline at end of file