Skip to content

Commit

Permalink
[SELC-5803] feat: added new API for PSPs Import (#463)
Browse files Browse the repository at this point in the history
  • Loading branch information
gianmarcoplutino authored Oct 30, 2024
1 parent 4ab1f42 commit 30d07a8
Show file tree
Hide file tree
Showing 10 changed files with 3,508 additions and 2,600 deletions.
4,296 changes: 2,392 additions & 1,904 deletions src/main/docs/openapi/api-selfcare-onboarding-docs.json

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import it.pagopa.selfcare.external_api.mapper.OnboardingResourceMapper;
import it.pagopa.selfcare.external_api.mapper.RelationshipMapper;
import it.pagopa.selfcare.external_api.model.onboarding.OnboardingImportDto;
import it.pagopa.selfcare.external_api.model.onboarding.OnboardingImportProductDto;
import it.pagopa.selfcare.external_api.model.onboarding.OnboardingInstitutionUsersRequest;
import it.pagopa.selfcare.external_api.model.onboarding.OnboardingProductDto;
import it.pagopa.selfcare.external_api.model.user.RelationshipInfo;
Expand All @@ -41,95 +42,157 @@
@Api(tags = "Onboarding")
public class OnboardingV2Controller {

private final OnboardingService onboardingService;
private final OnboardingResourceMapper onboardingResourceMapper;
private final OnboardingService onboardingService;
private final OnboardingResourceMapper onboardingResourceMapper;

@Autowired
public OnboardingV2Controller(
OnboardingService onboardingService, OnboardingResourceMapper onboardingResourceMapper) {
this.onboardingService = onboardingService;
this.onboardingResourceMapper = onboardingResourceMapper;
}

@Autowired
public OnboardingV2Controller(OnboardingService onboardingService,
OnboardingResourceMapper onboardingResourceMapper) {
this.onboardingService = onboardingService;
this.onboardingResourceMapper = onboardingResourceMapper;
}
@Tag(name = "internal-v1")
@ApiResponse(
responseCode = "403",
description = "Forbidden",
content = {
@Content(
mediaType = APPLICATION_PROBLEM_JSON_VALUE,
schema = @Schema(implementation = Problem.class))
})
@PostMapping
@ResponseStatus(HttpStatus.CREATED)
@ApiOperation(value = "", notes = "${swagger.onboarding.institutions.api.onboarding.subunit}")
public void onboarding(@RequestBody @Valid OnboardingProductDto request) {
log.trace("onboarding start");
log.debug("onboarding request = {}", request);
onboardingService.autoApprovalOnboardingProductV2(onboardingResourceMapper.toEntity(request));
log.trace("onboarding end");
}

@Tag(name = "internal-v1")
@ApiResponse(
responseCode = "403",
description = "Forbidden",
content = {
@Content(
mediaType = APPLICATION_PROBLEM_JSON_VALUE,
schema = @Schema(implementation = Problem.class))
})
@PostMapping(value = "/import")
@ResponseStatus(HttpStatus.CREATED)
@ApiOperation(value = "", notes = "${swagger.onboarding.institutions.api.onboarding.import}")
public void onboardingImport(@RequestBody @Valid OnboardingImportProductDto request) {
log.trace("onboardingImport start");
log.debug("onboardingImport request = {}", request);
onboardingService.autoApprovalOnboardingImportProductV2(
onboardingResourceMapper.toEntity(request));
log.trace("onboardingImport end");
}

@Tag(name = "internal-v1")
@ApiResponse(responseCode = "403",
@ApiResponses(
value = {
@ApiResponse(
responseCode = "409",
description = "Conflict",
content = {
@Content(
mediaType = APPLICATION_PROBLEM_JSON_VALUE,
schema = @Schema(implementation = Problem.class))
}),
@ApiResponse(
responseCode = "403",
description = "Forbidden",
content = {
@Content(mediaType = APPLICATION_PROBLEM_JSON_VALUE,
schema = @Schema(implementation = Problem.class))
@Content(
mediaType = APPLICATION_PROBLEM_JSON_VALUE,
schema = @Schema(implementation = Problem.class))
})
@PostMapping
@ResponseStatus(HttpStatus.CREATED)
@ApiOperation(value = "", notes = "${swagger.onboarding.institutions.api.onboarding.subunit}")
public void onboarding(@RequestBody @Valid OnboardingProductDto request) {
log.trace("onboarding start");
log.debug("onboarding request = {}", request);
onboardingService.autoApprovalOnboardingProductV2(onboardingResourceMapper.toEntity(request));
log.trace("onboarding end");
}

@ApiResponses(value = {
@ApiResponse(responseCode = "409",
description = "Conflict",
content = {
@Content(mediaType = APPLICATION_PROBLEM_JSON_VALUE,
schema = @Schema(implementation = Problem.class))
}),
@ApiResponse(responseCode = "403",
description = "Forbidden",
content = {
@Content(mediaType = APPLICATION_PROBLEM_JSON_VALUE,
schema = @Schema(implementation = Problem.class))
})
})
@PostMapping(value = "/{externalInstitutionId}")
@ResponseStatus(HttpStatus.CREATED)
@ApiOperation(value = "", notes = "${swagger.external_api.onboarding.api.onboardingOldContract}")
public void oldContractOnboarding(@ApiParam("${swagger.external_api.institutions.model.externalId}")
@PathVariable("externalInstitutionId")
String externalInstitutionId,
@RequestBody
@Valid
OnboardingImportDto request) {
log.trace("oldContractonboarding start");
log.debug("oldContractonboarding institutionId = {}, request = {}", externalInstitutionId, request);
if (request.getImportContract().getOnboardingDate().compareTo(OffsetDateTime.now()) > 0) {
throw new ValidationException("Invalid onboarding date: the onboarding date must be prior to the current date.");
}
onboardingService.oldContractOnboardingV2(OnboardingMapperCustom.toOnboardingData(externalInstitutionId, request));
log.trace("oldContractonboarding end");
}

/**
* The function persist user on registry if not exists and add relation with institution-product
*
* @param request OnboardingInstitutionUsersRequest
* @return no content
* * Code: 204, Message: successful operation
* * Code: 404, Message: Not found, DataType: Problem
* * Code: 400, Message: Invalid request, DataType: Problem
*/
@ResponseStatus(HttpStatus.OK)
@Tag(name = "internal-v1")
@Tag(name = "support")
@Tag(name = "Onboarding")
@ApiOperation(value = "${swagger.mscore.onboarding.users}", notes = "${swagger.mscore.onboarding.users}")

@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "OK", content = @Content(array = @ArraySchema(schema = @Schema(implementation = RelationshipResult.class)), mediaType = "application/json")),
@ApiResponse(responseCode = "400", description = "Bad Request", content = @Content(schema = @Schema(implementation = Problem.class), mediaType = "application/problem+json")),
@ApiResponse(responseCode = "401", description = "Unauthorized", content = @Content(schema = @Schema(implementation = Problem.class), mediaType = "application/problem+json")),
@ApiResponse(responseCode = "403", description = "Forbidden", content = @Content(schema = @Schema(implementation = Problem.class), mediaType = "application/problem+json")),
@ApiResponse(responseCode = "404", description = "Not Found", content = @Content(schema = @Schema(implementation = Problem.class), mediaType = "application/problem+json"))
})
@PostMapping(value = "/users")
public ResponseEntity<List<RelationshipResult>> onboardingInstitutionUsers(@RequestBody @Valid OnboardingInstitutionUsersRequest request,
Authentication authentication) {
SelfCareUser selfCareUser = (SelfCareUser) authentication.getPrincipal();
List<RelationshipInfo> response = onboardingService.onboardingUsers(onboardingResourceMapper.toOnboardingUsersRequest(request), selfCareUser.getUserName(), selfCareUser.getSurname());
return ResponseEntity.ok().body(RelationshipMapper.toRelationshipResultList(response));
})
@PostMapping(value = "/{externalInstitutionId}")
@ResponseStatus(HttpStatus.CREATED)
@ApiOperation(value = "", notes = "${swagger.external_api.onboarding.api.onboardingOldContract}")
public void oldContractOnboarding(
@ApiParam("${swagger.external_api.institutions.model.externalId}")
@PathVariable("externalInstitutionId")
String externalInstitutionId,
@RequestBody @Valid OnboardingImportDto request) {
log.trace("oldContractonboarding start");
log.debug(
"oldContractonboarding institutionId = {}, request = {}", externalInstitutionId, request);
if (request.getImportContract().getOnboardingDate().compareTo(OffsetDateTime.now()) > 0) {
throw new ValidationException(
"Invalid onboarding date: the onboarding date must be prior to the current date.");
}
onboardingService.oldContractOnboardingV2(
OnboardingMapperCustom.toOnboardingData(externalInstitutionId, request));
log.trace("oldContractonboarding end");
}

/**
* The function persist user on registry if not exists and add relation with institution-product
*
* @param request OnboardingInstitutionUsersRequest
* @return no content * Code: 204, Message: successful operation * Code: 404, Message: Not found,
* DataType: Problem * Code: 400, Message: Invalid request, DataType: Problem
*/
@ResponseStatus(HttpStatus.OK)
@Tag(name = "internal-v1")
@Tag(name = "support")
@Tag(name = "Onboarding")
@ApiOperation(
value = "${swagger.mscore.onboarding.users}",
notes = "${swagger.mscore.onboarding.users}")
@ApiResponses(
value = {
@ApiResponse(
responseCode = "200",
description = "OK",
content =
@Content(
array =
@ArraySchema(schema = @Schema(implementation = RelationshipResult.class)),
mediaType = "application/json")),
@ApiResponse(
responseCode = "400",
description = "Bad Request",
content =
@Content(
schema = @Schema(implementation = Problem.class),
mediaType = "application/problem+json")),
@ApiResponse(
responseCode = "401",
description = "Unauthorized",
content =
@Content(
schema = @Schema(implementation = Problem.class),
mediaType = "application/problem+json")),
@ApiResponse(
responseCode = "403",
description = "Forbidden",
content =
@Content(
schema = @Schema(implementation = Problem.class),
mediaType = "application/problem+json")),
@ApiResponse(
responseCode = "404",
description = "Not Found",
content =
@Content(
schema = @Schema(implementation = Problem.class),
mediaType = "application/problem+json"))
})
@PostMapping(value = "/users")
public ResponseEntity<List<RelationshipResult>> onboardingInstitutionUsers(
@RequestBody @Valid OnboardingInstitutionUsersRequest request,
Authentication authentication) {
SelfCareUser selfCareUser = (SelfCareUser) authentication.getPrincipal();
List<RelationshipInfo> response =
onboardingService.onboardingUsers(
onboardingResourceMapper.toOnboardingUsersRequest(request),
selfCareUser.getUserName(),
selfCareUser.getSurname());
return ResponseEntity.ok().body(RelationshipMapper.toRelationshipResultList(response));
}
}
Loading

0 comments on commit 30d07a8

Please sign in to comment.