|
15 | 15 | import it.pagopa.selfcare.external_api.mapper.OnboardingResourceMapper;
|
16 | 16 | import it.pagopa.selfcare.external_api.mapper.RelationshipMapper;
|
17 | 17 | import it.pagopa.selfcare.external_api.model.onboarding.OnboardingImportDto;
|
| 18 | +import it.pagopa.selfcare.external_api.model.onboarding.OnboardingImportProductDto; |
18 | 19 | import it.pagopa.selfcare.external_api.model.onboarding.OnboardingInstitutionUsersRequest;
|
19 | 20 | import it.pagopa.selfcare.external_api.model.onboarding.OnboardingProductDto;
|
20 | 21 | import it.pagopa.selfcare.external_api.model.user.RelationshipInfo;
|
|
41 | 42 | @Api(tags = "Onboarding")
|
42 | 43 | public class OnboardingV2Controller {
|
43 | 44 |
|
44 |
| - private final OnboardingService onboardingService; |
45 |
| - private final OnboardingResourceMapper onboardingResourceMapper; |
| 45 | + private final OnboardingService onboardingService; |
| 46 | + private final OnboardingResourceMapper onboardingResourceMapper; |
46 | 47 |
|
| 48 | + @Autowired |
| 49 | + public OnboardingV2Controller( |
| 50 | + OnboardingService onboardingService, OnboardingResourceMapper onboardingResourceMapper) { |
| 51 | + this.onboardingService = onboardingService; |
| 52 | + this.onboardingResourceMapper = onboardingResourceMapper; |
| 53 | + } |
47 | 54 |
|
48 |
| - @Autowired |
49 |
| - public OnboardingV2Controller(OnboardingService onboardingService, |
50 |
| - OnboardingResourceMapper onboardingResourceMapper) { |
51 |
| - this.onboardingService = onboardingService; |
52 |
| - this.onboardingResourceMapper = onboardingResourceMapper; |
53 |
| - } |
| 55 | + @Tag(name = "internal-v1") |
| 56 | + @ApiResponse( |
| 57 | + responseCode = "403", |
| 58 | + description = "Forbidden", |
| 59 | + content = { |
| 60 | + @Content( |
| 61 | + mediaType = APPLICATION_PROBLEM_JSON_VALUE, |
| 62 | + schema = @Schema(implementation = Problem.class)) |
| 63 | + }) |
| 64 | + @PostMapping |
| 65 | + @ResponseStatus(HttpStatus.CREATED) |
| 66 | + @ApiOperation(value = "", notes = "${swagger.onboarding.institutions.api.onboarding.subunit}") |
| 67 | + public void onboarding(@RequestBody @Valid OnboardingProductDto request) { |
| 68 | + log.trace("onboarding start"); |
| 69 | + log.debug("onboarding request = {}", request); |
| 70 | + onboardingService.autoApprovalOnboardingProductV2(onboardingResourceMapper.toEntity(request)); |
| 71 | + log.trace("onboarding end"); |
| 72 | + } |
54 | 73 |
|
| 74 | + @Tag(name = "internal-v1") |
| 75 | + @ApiResponse( |
| 76 | + responseCode = "403", |
| 77 | + description = "Forbidden", |
| 78 | + content = { |
| 79 | + @Content( |
| 80 | + mediaType = APPLICATION_PROBLEM_JSON_VALUE, |
| 81 | + schema = @Schema(implementation = Problem.class)) |
| 82 | + }) |
| 83 | + @PostMapping(value = "/import") |
| 84 | + @ResponseStatus(HttpStatus.CREATED) |
| 85 | + @ApiOperation(value = "", notes = "${swagger.onboarding.institutions.api.onboarding.import}") |
| 86 | + public void onboardingImport(@RequestBody @Valid OnboardingImportProductDto request) { |
| 87 | + log.trace("onboardingImport start"); |
| 88 | + log.debug("onboardingImport request = {}", request); |
| 89 | + onboardingService.autoApprovalOnboardingImportProductV2( |
| 90 | + onboardingResourceMapper.toEntity(request)); |
| 91 | + log.trace("onboardingImport end"); |
| 92 | + } |
55 | 93 |
|
56 |
| - @Tag(name = "internal-v1") |
57 |
| - @ApiResponse(responseCode = "403", |
| 94 | + @ApiResponses( |
| 95 | + value = { |
| 96 | + @ApiResponse( |
| 97 | + responseCode = "409", |
| 98 | + description = "Conflict", |
| 99 | + content = { |
| 100 | + @Content( |
| 101 | + mediaType = APPLICATION_PROBLEM_JSON_VALUE, |
| 102 | + schema = @Schema(implementation = Problem.class)) |
| 103 | + }), |
| 104 | + @ApiResponse( |
| 105 | + responseCode = "403", |
58 | 106 | description = "Forbidden",
|
59 | 107 | content = {
|
60 |
| - @Content(mediaType = APPLICATION_PROBLEM_JSON_VALUE, |
61 |
| - schema = @Schema(implementation = Problem.class)) |
| 108 | + @Content( |
| 109 | + mediaType = APPLICATION_PROBLEM_JSON_VALUE, |
| 110 | + schema = @Schema(implementation = Problem.class)) |
62 | 111 | })
|
63 |
| - @PostMapping |
64 |
| - @ResponseStatus(HttpStatus.CREATED) |
65 |
| - @ApiOperation(value = "", notes = "${swagger.onboarding.institutions.api.onboarding.subunit}") |
66 |
| - public void onboarding(@RequestBody @Valid OnboardingProductDto request) { |
67 |
| - log.trace("onboarding start"); |
68 |
| - log.debug("onboarding request = {}", request); |
69 |
| - onboardingService.autoApprovalOnboardingProductV2(onboardingResourceMapper.toEntity(request)); |
70 |
| - log.trace("onboarding end"); |
71 |
| - } |
72 |
| - |
73 |
| - @ApiResponses(value = { |
74 |
| - @ApiResponse(responseCode = "409", |
75 |
| - description = "Conflict", |
76 |
| - content = { |
77 |
| - @Content(mediaType = APPLICATION_PROBLEM_JSON_VALUE, |
78 |
| - schema = @Schema(implementation = Problem.class)) |
79 |
| - }), |
80 |
| - @ApiResponse(responseCode = "403", |
81 |
| - description = "Forbidden", |
82 |
| - content = { |
83 |
| - @Content(mediaType = APPLICATION_PROBLEM_JSON_VALUE, |
84 |
| - schema = @Schema(implementation = Problem.class)) |
85 |
| - }) |
86 |
| - }) |
87 |
| - @PostMapping(value = "/{externalInstitutionId}") |
88 |
| - @ResponseStatus(HttpStatus.CREATED) |
89 |
| - @ApiOperation(value = "", notes = "${swagger.external_api.onboarding.api.onboardingOldContract}") |
90 |
| - public void oldContractOnboarding(@ApiParam("${swagger.external_api.institutions.model.externalId}") |
91 |
| - @PathVariable("externalInstitutionId") |
92 |
| - String externalInstitutionId, |
93 |
| - @RequestBody |
94 |
| - @Valid |
95 |
| - OnboardingImportDto request) { |
96 |
| - log.trace("oldContractonboarding start"); |
97 |
| - log.debug("oldContractonboarding institutionId = {}, request = {}", externalInstitutionId, request); |
98 |
| - if (request.getImportContract().getOnboardingDate().compareTo(OffsetDateTime.now()) > 0) { |
99 |
| - throw new ValidationException("Invalid onboarding date: the onboarding date must be prior to the current date."); |
100 |
| - } |
101 |
| - onboardingService.oldContractOnboardingV2(OnboardingMapperCustom.toOnboardingData(externalInstitutionId, request)); |
102 |
| - log.trace("oldContractonboarding end"); |
103 |
| - } |
104 |
| - |
105 |
| - /** |
106 |
| - * The function persist user on registry if not exists and add relation with institution-product |
107 |
| - * |
108 |
| - * @param request OnboardingInstitutionUsersRequest |
109 |
| - * @return no content |
110 |
| - * * Code: 204, Message: successful operation |
111 |
| - * * Code: 404, Message: Not found, DataType: Problem |
112 |
| - * * Code: 400, Message: Invalid request, DataType: Problem |
113 |
| - */ |
114 |
| - @ResponseStatus(HttpStatus.OK) |
115 |
| - @Tag(name = "internal-v1") |
116 |
| - @Tag(name = "support") |
117 |
| - @Tag(name = "Onboarding") |
118 |
| - @ApiOperation(value = "${swagger.mscore.onboarding.users}", notes = "${swagger.mscore.onboarding.users}") |
119 |
| - |
120 |
| - @ApiResponses(value = { |
121 |
| - @ApiResponse(responseCode = "200", description = "OK", content = @Content(array = @ArraySchema(schema = @Schema(implementation = RelationshipResult.class)), mediaType = "application/json")), |
122 |
| - @ApiResponse(responseCode = "400", description = "Bad Request", content = @Content(schema = @Schema(implementation = Problem.class), mediaType = "application/problem+json")), |
123 |
| - @ApiResponse(responseCode = "401", description = "Unauthorized", content = @Content(schema = @Schema(implementation = Problem.class), mediaType = "application/problem+json")), |
124 |
| - @ApiResponse(responseCode = "403", description = "Forbidden", content = @Content(schema = @Schema(implementation = Problem.class), mediaType = "application/problem+json")), |
125 |
| - @ApiResponse(responseCode = "404", description = "Not Found", content = @Content(schema = @Schema(implementation = Problem.class), mediaType = "application/problem+json")) |
126 |
| - }) |
127 |
| - @PostMapping(value = "/users") |
128 |
| - public ResponseEntity<List<RelationshipResult>> onboardingInstitutionUsers(@RequestBody @Valid OnboardingInstitutionUsersRequest request, |
129 |
| - Authentication authentication) { |
130 |
| - SelfCareUser selfCareUser = (SelfCareUser) authentication.getPrincipal(); |
131 |
| - List<RelationshipInfo> response = onboardingService.onboardingUsers(onboardingResourceMapper.toOnboardingUsersRequest(request), selfCareUser.getUserName(), selfCareUser.getSurname()); |
132 |
| - return ResponseEntity.ok().body(RelationshipMapper.toRelationshipResultList(response)); |
| 112 | + }) |
| 113 | + @PostMapping(value = "/{externalInstitutionId}") |
| 114 | + @ResponseStatus(HttpStatus.CREATED) |
| 115 | + @ApiOperation(value = "", notes = "${swagger.external_api.onboarding.api.onboardingOldContract}") |
| 116 | + public void oldContractOnboarding( |
| 117 | + @ApiParam("${swagger.external_api.institutions.model.externalId}") |
| 118 | + @PathVariable("externalInstitutionId") |
| 119 | + String externalInstitutionId, |
| 120 | + @RequestBody @Valid OnboardingImportDto request) { |
| 121 | + log.trace("oldContractonboarding start"); |
| 122 | + log.debug( |
| 123 | + "oldContractonboarding institutionId = {}, request = {}", externalInstitutionId, request); |
| 124 | + if (request.getImportContract().getOnboardingDate().compareTo(OffsetDateTime.now()) > 0) { |
| 125 | + throw new ValidationException( |
| 126 | + "Invalid onboarding date: the onboarding date must be prior to the current date."); |
133 | 127 | }
|
| 128 | + onboardingService.oldContractOnboardingV2( |
| 129 | + OnboardingMapperCustom.toOnboardingData(externalInstitutionId, request)); |
| 130 | + log.trace("oldContractonboarding end"); |
| 131 | + } |
134 | 132 |
|
| 133 | + /** |
| 134 | + * The function persist user on registry if not exists and add relation with institution-product |
| 135 | + * |
| 136 | + * @param request OnboardingInstitutionUsersRequest |
| 137 | + * @return no content * Code: 204, Message: successful operation * Code: 404, Message: Not found, |
| 138 | + * DataType: Problem * Code: 400, Message: Invalid request, DataType: Problem |
| 139 | + */ |
| 140 | + @ResponseStatus(HttpStatus.OK) |
| 141 | + @Tag(name = "internal-v1") |
| 142 | + @Tag(name = "support") |
| 143 | + @Tag(name = "Onboarding") |
| 144 | + @ApiOperation( |
| 145 | + value = "${swagger.mscore.onboarding.users}", |
| 146 | + notes = "${swagger.mscore.onboarding.users}") |
| 147 | + @ApiResponses( |
| 148 | + value = { |
| 149 | + @ApiResponse( |
| 150 | + responseCode = "200", |
| 151 | + description = "OK", |
| 152 | + content = |
| 153 | + @Content( |
| 154 | + array = |
| 155 | + @ArraySchema(schema = @Schema(implementation = RelationshipResult.class)), |
| 156 | + mediaType = "application/json")), |
| 157 | + @ApiResponse( |
| 158 | + responseCode = "400", |
| 159 | + description = "Bad Request", |
| 160 | + content = |
| 161 | + @Content( |
| 162 | + schema = @Schema(implementation = Problem.class), |
| 163 | + mediaType = "application/problem+json")), |
| 164 | + @ApiResponse( |
| 165 | + responseCode = "401", |
| 166 | + description = "Unauthorized", |
| 167 | + content = |
| 168 | + @Content( |
| 169 | + schema = @Schema(implementation = Problem.class), |
| 170 | + mediaType = "application/problem+json")), |
| 171 | + @ApiResponse( |
| 172 | + responseCode = "403", |
| 173 | + description = "Forbidden", |
| 174 | + content = |
| 175 | + @Content( |
| 176 | + schema = @Schema(implementation = Problem.class), |
| 177 | + mediaType = "application/problem+json")), |
| 178 | + @ApiResponse( |
| 179 | + responseCode = "404", |
| 180 | + description = "Not Found", |
| 181 | + content = |
| 182 | + @Content( |
| 183 | + schema = @Schema(implementation = Problem.class), |
| 184 | + mediaType = "application/problem+json")) |
| 185 | + }) |
| 186 | + @PostMapping(value = "/users") |
| 187 | + public ResponseEntity<List<RelationshipResult>> onboardingInstitutionUsers( |
| 188 | + @RequestBody @Valid OnboardingInstitutionUsersRequest request, |
| 189 | + Authentication authentication) { |
| 190 | + SelfCareUser selfCareUser = (SelfCareUser) authentication.getPrincipal(); |
| 191 | + List<RelationshipInfo> response = |
| 192 | + onboardingService.onboardingUsers( |
| 193 | + onboardingResourceMapper.toOnboardingUsersRequest(request), |
| 194 | + selfCareUser.getUserName(), |
| 195 | + selfCareUser.getSurname()); |
| 196 | + return ResponseEntity.ok().body(RelationshipMapper.toRelationshipResultList(response)); |
| 197 | + } |
135 | 198 | }
|
0 commit comments