diff --git a/src/main/java/net/gepafin/tendermanagement/constants/GepafinConstant.java b/src/main/java/net/gepafin/tendermanagement/constants/GepafinConstant.java index 38d8bb1a..05d0e343 100644 --- a/src/main/java/net/gepafin/tendermanagement/constants/GepafinConstant.java +++ b/src/main/java/net/gepafin/tendermanagement/constants/GepafinConstant.java @@ -241,5 +241,7 @@ public class GepafinConstant { public static final String HUB_DELETE_SUCCESS = "hub_delete_success"; public static final String HUB_NOT_FOUND = "hub_not_found"; public static final String EVALUATIONCRITERIA_INVALID = "evaluationCriteria.invalid"; + public static final String APPLICATION_NOT_IN_DRAFT_STATUS="application.not.in.draft.status"; + public static final String APPLICATION_ALREADY_ASSIGNED="application.already.assigned"; } diff --git a/src/main/java/net/gepafin/tendermanagement/dao/ApplicationDao.java b/src/main/java/net/gepafin/tendermanagement/dao/ApplicationDao.java index 0537d703..e358e6e6 100644 --- a/src/main/java/net/gepafin/tendermanagement/dao/ApplicationDao.java +++ b/src/main/java/net/gepafin/tendermanagement/dao/ApplicationDao.java @@ -595,25 +595,8 @@ public class ApplicationDao { if(Boolean.TRUE.equals(applicationEntity.getStatus().equals(status.getValue()))){ throw new CustomValidationException(Status.BAD_REQUEST,Translator.toLocale(GepafinConstant.APPLICATION_ALREADY_IN_PREVIOUS_STATUS)); } - if (status.equals(ApplicationStatusTypeEnum.SUBMIT)) { + if (status.equals(ApplicationStatusTypeEnum.SUBMIT) && Boolean.TRUE.equals(applicationEntity.getStatus().equals(ApplicationStatusTypeEnum.READY.getValue()))) { callService.validatePublishedCall(applicationEntity.getCall().getId()); -// CallEntity callEntity = applicationEntity.getCall(); -// Long initialFormId = callEntity.getInitialForm(); -// Long finalFormId = callEntity.getFinalForm(); -//// if (initialFormId == null || finalFormId == null) { -//// throw new CustomValidationException(Status.BAD_REQUEST, Translator.toLocale(GepafinConstant.APPLICATION_IS_INCOMPLETE_MSG)); -//// } -// ApplicationFormEntity initialApplicationForm = applicationFormRepository.findByApplicationIdAndFormId(applicationEntity.getId(), initialFormId); -// ApplicationFormEntity finalApplicationForm = applicationFormRepository.findByApplicationIdAndFormId(applicationEntity.getId(), finalFormId); -// if (initialApplicationForm == null || finalApplicationForm == null) { -// throw new CustomValidationException(Status.BAD_REQUEST, Translator.toLocale(GepafinConstant.APPLICATION_IS_INCOMPLETE_MSG)); -// } - List flowEdgesList = flowEdgesRepository.findByCallId(applicationEntity.getCall().getId()); - Long totalSteps=flowFormDao.calculateTotalSteps(flowEdgesList); - Integer completedSteps=flowFormDao.getCompletedSteps(applicationEntity); - if (totalSteps.intValue() != completedSteps) { - throw new CustomValidationException(Status.BAD_REQUEST, Translator.toLocale(GepafinConstant.APPLICATION_IS_INCOMPLETE_MSG)); - } Long protocolNumber = getProtocolNumber(userEntity.getHub()); ProtocolEntity protocolEntity = createProtocolEntity(applicationEntity,protocolNumber, userEntity.getHub().getId()); applicationEntity.setProtocol(protocolEntity); @@ -622,11 +605,10 @@ public class ApplicationDao { applicationEntity = saveApplicationEntity(applicationEntity); sendMailToUserAndCompany(userEntity, applicationEntity); sendMailTodefaultSystemAndGepafin(userEntity, applicationEntity); - } else { applicationEntity.setStatus(status.getValue()); applicationEntity = saveApplicationEntity(applicationEntity); } - + return getApplicationResponse(applicationEntity); } @@ -798,8 +780,9 @@ public class ApplicationDao { ApplicationSignedDocumentEntity applicationSignedDocument = applicationSignedDocumentRepository .findByApplicationIdAndStatus(applicationId, ApplicationSignedDocumentStatusEnum.ACTIVE.getValue()); if (applicationSignedDocument != null) { - applicationSignedDocument.setStatus(ApplicationSignedDocumentStatusEnum.INACTIVE.getValue()); - applicationSignedDocumentRepository.save(applicationSignedDocument); + throw new CustomValidationException(Status.BAD_REQUEST,Translator.toLocale(GepafinConstant.APPLICATION_ALREADY_ASSIGNED)); +// applicationSignedDocument.setStatus(ApplicationSignedDocumentStatusEnum.INACTIVE.getValue()); +// applicationSignedDocumentRepository.save(applicationSignedDocument); } UploadFileOnAmazonS3Response uploadFileOnAmazonS3 = amazonS3Service.uploadFileOnAmazonS3(signedDocumentS3Folder, file); @@ -809,6 +792,8 @@ public class ApplicationDao { applicationSignedDocument.setFilePath(uploadFileOnAmazonS3.getFilePath()); applicationSignedDocument.setStatus(ApplicationSignedDocumentStatusEnum.ACTIVE.getValue()); applicationSignedDocumentRepository.save(applicationSignedDocument); + applicationEntity.setStatus(ApplicationStatusTypeEnum.READY.getValue()); + applicationRepository.save(applicationEntity); return convertApplicationSignedDocumentToApplicationSignedDocumentResponse(applicationSignedDocument); } @@ -865,4 +850,24 @@ public class ApplicationDao { applicationSignedDocument.setStatus(ApplicationSignedDocumentStatusEnum.INACTIVE.getValue()); applicationSignedDocumentRepository.save(applicationSignedDocument); } + + public ApplicationResponse validateApplication(HttpServletRequest request, Long applicationId) { + ApplicationEntity applicationEntity = validateApplication(applicationId); + UserEntity userEntity = userService.validateUser(applicationEntity.getUserId()); + validator.validateUserWithCompany(request, applicationEntity.getCompany().getId()); + if (Boolean.FALSE.equals(ApplicationStatusTypeEnum.DRAFT.getValue().equals(applicationEntity.getStatus()))) { + throw new CustomValidationException(Status.BAD_REQUEST, Translator.toLocale(GepafinConstant.APPLICATION_NOT_IN_DRAFT_STATUS)); + } + List flowEdgesList = flowEdgesRepository.findByCallId(applicationEntity.getCall().getId()); + Long totalSteps=flowFormDao.calculateTotalSteps(flowEdgesList); + Integer completedSteps=flowFormDao.getCompletedSteps(applicationEntity); + if (totalSteps.intValue() != completedSteps) { + throw new CustomValidationException(Status.BAD_REQUEST, Translator.toLocale(GepafinConstant.APPLICATION_IS_INCOMPLETE_MSG)); + } + + applicationEntity.setStatus(ApplicationStatusTypeEnum.AWAIT.getValue()); + applicationEntity = saveApplicationEntity(applicationEntity); + return getApplicationResponse(applicationEntity); + } + } diff --git a/src/main/java/net/gepafin/tendermanagement/dao/PdfDao.java b/src/main/java/net/gepafin/tendermanagement/dao/PdfDao.java index 6fa9b56a..18d3bf1e 100644 --- a/src/main/java/net/gepafin/tendermanagement/dao/PdfDao.java +++ b/src/main/java/net/gepafin/tendermanagement/dao/PdfDao.java @@ -75,42 +75,6 @@ public class PdfDao { addColoredLines(writer,document,greyColor); document.add(new Paragraph(" ")); - // Application ID section (Centered) -// pageEvent.setTotalPages(writer.getPageNumber()); - String protocolNumber="XX00"; - if(applicationEntity.getProtocol()!=null) { - protocolNumber= String.valueOf(applicationEntity.getProtocol().getProtocolNumber()); - } - Paragraph appId = new Paragraph("ID domanda :" +protocolNumber); - appId.setAlignment(Element.ALIGN_RIGHT); - document.add(appId); - - document.add(new Paragraph(" ")); - - addColoredLines(writer,document,greenColor); - document.add(new Paragraph(" ")); - document.add(new Paragraph("\n")); // Add line break -// String companyName= companyEntity.getCompanyName(); -// String vatNumber=companyEntity.getVatNumber(); -// String address=companyEntity.getAddress(); -// // Section: Dati Anagrafici Azienda -// document.add(new Paragraph("Dati Anagrafici Azienda", sectionFont)); -// addLabelValuePair(document, "Codice ATECO", "SEZIONE C “ATTIVITÀ MANUFATTURIERE”", regularFont); -// addLabelValuePair(document, "Ragione Sociale", companyName, regularFont); -// addLabelValuePair(document, "Partita IVA", vatNumber, regularFont); -// addLabelValuePair(document, "Indirizzo sede Legale", address, regularFont); -// -// document.add(new Paragraph("\n")); // Add line break -// -// // Section: Domanda presentata da -// document.add(new Paragraph("Domanda presentata da:", sectionFont)); -// addLabelValuePair(document, "Nome e cognome", userEntity.getBeneficiary().getFirstName()+" "+userEntity.getBeneficiary().getLastName(), regularFont); -// addLabelValuePair(document, "Codice fiscale", userEntity.getBeneficiary().getCodiceFiscale(), regularFont); -// addLabelValuePair(document, "Telefono", userEntity.getBeneficiary().getPhoneNumber(), regularFont); -// addLabelValuePair(document, "Email", userEntity.getBeneficiary().getEmail(), regularFont); -// addLabelValuePair(document, "Con il titolo di", "Rappresentante legale", regularFont); - document.add(new Paragraph(" ")); - ApplicationGetResponseBean applicationGetResponseBean=applicationDao.getApplicationByFormId(request, applicationId, null); for(FormApplicationResponse formApplicationResponse: applicationGetResponseBean.getForm()) { document.add(new Paragraph(formApplicationResponse.getLabel(),sectionFont)); diff --git a/src/main/java/net/gepafin/tendermanagement/enums/ApplicationStatusTypeEnum.java b/src/main/java/net/gepafin/tendermanagement/enums/ApplicationStatusTypeEnum.java index 08b436c8..80420c15 100644 --- a/src/main/java/net/gepafin/tendermanagement/enums/ApplicationStatusTypeEnum.java +++ b/src/main/java/net/gepafin/tendermanagement/enums/ApplicationStatusTypeEnum.java @@ -6,6 +6,8 @@ public enum ApplicationStatusTypeEnum { DRAFT("DRAFT"), SUBMIT("SUBMIT"), + AWAIT("AWAIT"), + READY("READY"), DISCARD("DISCARD"); private String value; diff --git a/src/main/java/net/gepafin/tendermanagement/service/ApplicationService.java b/src/main/java/net/gepafin/tendermanagement/service/ApplicationService.java index 2d914b64..b17ead39 100644 --- a/src/main/java/net/gepafin/tendermanagement/service/ApplicationService.java +++ b/src/main/java/net/gepafin/tendermanagement/service/ApplicationService.java @@ -40,4 +40,6 @@ public interface ApplicationService { public void deleteSignedDocument(HttpServletRequest request, Long applicationId); + public ApplicationResponse validateApplication(HttpServletRequest request, Long applicationId); + } diff --git a/src/main/java/net/gepafin/tendermanagement/service/impl/ApplicationServiceImpl.java b/src/main/java/net/gepafin/tendermanagement/service/impl/ApplicationServiceImpl.java index 382f5372..9324a3e5 100644 --- a/src/main/java/net/gepafin/tendermanagement/service/impl/ApplicationServiceImpl.java +++ b/src/main/java/net/gepafin/tendermanagement/service/impl/ApplicationServiceImpl.java @@ -109,5 +109,11 @@ public class ApplicationServiceImpl implements ApplicationService { public void deleteSignedDocument(HttpServletRequest request, Long applicationId) { applicationDao.deleteSignedDocument(request, applicationId); } - + + @Override + @Transactional(rollbackFor = Exception.class) + public ApplicationResponse validateApplication(HttpServletRequest request, Long applicationId) { + return applicationDao.validateApplication(request, applicationId); + + } } diff --git a/src/main/java/net/gepafin/tendermanagement/web/rest/api/ApplicationApi.java b/src/main/java/net/gepafin/tendermanagement/web/rest/api/ApplicationApi.java index e3be06c7..05ad1ba4 100644 --- a/src/main/java/net/gepafin/tendermanagement/web/rest/api/ApplicationApi.java +++ b/src/main/java/net/gepafin/tendermanagement/web/rest/api/ApplicationApi.java @@ -175,17 +175,30 @@ public interface ApplicationApi { ResponseEntity> getSignedDocument(HttpServletRequest request, @Parameter(description = "The applicationId id", required = true) @PathVariable("applicationId") Long applicationId); - @Operation(summary = "Api to delete signed document", 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 = "{applicationId}/signedDocument", produces = "application/json") - ResponseEntity> deleteSignedDocument(HttpServletRequest request, - @Parameter(description = "The applicationId id", required = true) @PathVariable("applicationId") Long applicationId); - - +// @Operation(summary = "Api to delete signed document", 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 = "{applicationId}/signedDocument", produces = "application/json") +// ResponseEntity> deleteSignedDocument(HttpServletRequest request, +// @Parameter(description = "The applicationId id", required = true) @PathVariable("applicationId") Long applicationId); + + @Operation(summary = "Api to validate application", + 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 = "/{applicationId}/validate", produces = { "application/json" }) + ResponseEntity> validateApplication(HttpServletRequest request, + @Parameter(description = "The application id", required = true) @PathVariable("applicationId") Long applicationId); + + } diff --git a/src/main/java/net/gepafin/tendermanagement/web/rest/api/impl/ApplicationApiController.java b/src/main/java/net/gepafin/tendermanagement/web/rest/api/impl/ApplicationApiController.java index f6e6d1e5..4880a059 100644 --- a/src/main/java/net/gepafin/tendermanagement/web/rest/api/impl/ApplicationApiController.java +++ b/src/main/java/net/gepafin/tendermanagement/web/rest/api/impl/ApplicationApiController.java @@ -133,13 +133,20 @@ public class ApplicationApiController implements ApplicationApi { .body(new Response<>(response, Status.SUCCESS, Translator.toLocale(GepafinConstant.GET_SIGNED_DOCUMENT_FILE_SUCCESS))); } +// @Override +// public ResponseEntity> deleteSignedDocument(HttpServletRequest request, +// Long applicationId) { +// applicationService.deleteSignedDocument(request, applicationId); +// log.info("delete signed document applicationId: {}", applicationId); +// return ResponseEntity.status(HttpStatus.OK) +// .body(new Response<>(null, Status.SUCCESS, Translator.toLocale(GepafinConstant.DELETE_SIGNED_DOCUMENT_FILE_SUCCESS))); +// } + @Override - public ResponseEntity> deleteSignedDocument(HttpServletRequest request, - Long applicationId) { - applicationService.deleteSignedDocument(request, applicationId); - log.info("delete signed document applicationId: {}", applicationId); + public ResponseEntity> validateApplication(HttpServletRequest request, Long applicationId) { + ApplicationResponse applicationResponse = applicationService.validateApplication(request, applicationId); return ResponseEntity.status(HttpStatus.OK) - .body(new Response<>(null, Status.SUCCESS, Translator.toLocale(GepafinConstant.DELETE_SIGNED_DOCUMENT_FILE_SUCCESS))); + .body(new Response<>(applicationResponse, Status.SUCCESS, Translator.toLocale(GepafinConstant.APPLICATION_STATUS_UPDATED_SUCCESSFULLY))); } - + } diff --git a/src/main/resources/message_en.properties b/src/main/resources/message_en.properties index ff04a9bf..cf6f0f92 100644 --- a/src/main/resources/message_en.properties +++ b/src/main/resources/message_en.properties @@ -264,5 +264,8 @@ hub_get_all_success=Hubs retrieved successfully hub_delete_success=Hub deleted successfully hub_not_found=Hub not found +application.not.in.draft.status=Application is not in DRAFT status. +application.already.assigned=Application is already assigned. + diff --git a/src/main/resources/message_it.properties b/src/main/resources/message_it.properties index af60bf21..1dbb12f9 100644 --- a/src/main/resources/message_it.properties +++ b/src/main/resources/message_it.properties @@ -259,4 +259,7 @@ hub_update_success=Hub aggiornato con successo hub_get_success=Hub recuperato con successo hub_get_all_success=Hub recuperati con successo hub_delete_success=Hub eliminato con successo -hub_not_found=Hub non trovato \ No newline at end of file +hub_not_found=Hub non trovato + +application.not.in.draft.status=La domanda non in stato DRAFT. +application.already.assigned=L'applicazione gi assegnata. \ No newline at end of file