Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @ApiOperation(
- value = "Check consent for customer",
- response = SystemGatewayCheckConsentForCustomerResponse.class,
- authorizations = @Authorization(value = "Authorization")
- )
- @ApiResponses({
- @ApiResponse(code = 404, message = "Customer not found", response = SwaggerErrorResponse.class),
- @ApiResponse(code = 204, message = "Customer has no matching consent", response = SwaggerErrorResponse.class)})
- @RequestMapping(
- produces = MediaType.APPLICATION_JSON_VALUE,
- value = "/customer/{customerId}/consents",
- method = RequestMethod.POST
- )
- public ResponseEntity<SystemGatewayCheckConsentForCustomerResponse> checkConsentForCustomer(
- @PathVariable String customerId,
- @RequestBody final SystemGatewayRequestConsent systemGatewayRequestConsents
- ){
- SystemGatewayCheckConsentForCustomerResponse systemGatewayCheckConsentForCustomerResponse = new SystemGatewayCheckConsentForCustomerResponse();
- if(customerRepository.readCustomer(customerId).getCustomer() == null){
- return ResponseEntity
- .status(HttpStatus.NOT_FOUND)
- .body(systemGatewayCheckConsentForCustomerResponse);
- }
- Customer customer = customerRepository.readCustomer(customerId).getCustomer();
- systemGatewayCheckConsentForCustomerResponse.setCustomerId(customerId);
- systemGatewayCheckConsentForCustomerResponse.setBeneficiary(systemGatewayRequestConsents.getBeneficiary());
- if(systemGatewayRequestConsents.getRequestId() != null && !systemGatewayRequestConsents.getRequestId().isEmpty()){
- systemGatewayCheckConsentForCustomerResponse.setRequestId(systemGatewayRequestConsents.getRequestId());
- }
- List<SystemGatewayResponseConsent> responseConsents = new ArrayList<>();
- List<SystemGatewayRequestPurposeAndChannelForConsent> consents = systemGatewayRequestConsents.getConsents();
- for(SystemGatewayRequestPurposeAndChannelForConsent consent : consents) {
- String purposeRequest = consent.getPurpose();
- String channelRequest = consent.getChannel();
- SystemGatewayResponseConsent responseConsent = new SystemGatewayResponseConsent();
- ConsentDocumentInformationGetResponse consentDocumentInformationGetResponse = consentDocumentInformationRepository.getConsentInformationFiltered(customerId, CustomerStatus.active, systemGatewayRequestConsents.getBeneficiary(), channelRequest, purposeRequest);
- List<ConsentDocumentInformation> consentDocumentInformations = consentDocumentInformationGetResponse.getConsentDocumentInformationList();
- for (ConsentDocumentInformation consentDocumentInformation : consentDocumentInformations)
- {
- List<ConsentDocumentInformationGrant> consentDocumentInformationGrants = consentDocumentInformation.getGrants();
- for (ConsentDocumentInformationGrant consentDocumentInformationGrant : consentDocumentInformationGrants)
- {
- if (consentDocumentInformationGrant.getChannel().equals(channelRequest))
- {
- if (channelRequest.equals("letter"))
- {
- responseConsent.setPurpose(purposeRequest);
- responseConsent.setChannel(channelRequest);
- responseConsent.setClusterType("address");
- Address address = customer.getAddresses().get(0);
- address.setGdpr(null);
- responseConsent.setData(address);
- responseConsents.add(responseConsent);
- } else if (channelRequest.equals("phone"))
- {
- responseConsent.setPurpose(purposeRequest);
- responseConsent.setChannel(channelRequest);
- responseConsent.setClusterType("phone");
- Phone phone = customer.getPhones().get(0);
- phone.setGdpr(null);
- responseConsent.setData(phone);
- responseConsents.add(responseConsent);
- } else if (channelRequest.equals("email"))
- {
- responseConsent.setPurpose(purposeRequest);
- responseConsent.setChannel(channelRequest);
- responseConsent.setClusterType("email");
- Email email = customer.getEmails().get(0);
- email.setGdpr(null);
- responseConsent.setData(email);
- responseConsents.add(responseConsent);
- } else if(channelRequest.equals("vehicleRelation"))
- {
- responseConsent.setPurpose(purposeRequest);
- responseConsent.setChannel(channelRequest);
- responseConsent.setClusterType("vehicleRelation");
- VehicleRelation vehicleRelation = customer.getVehicleRelations().get(0);
- vehicleRelation.setGdpr(null);
- responseConsent.setData(vehicleRelation);
- responseConsents.add(responseConsent);
- }
- }
- }
- }
- }
- if(responseConsents.size() > 0) {
- systemGatewayCheckConsentForCustomerResponse.setConsents(responseConsents);
- return ResponseEntity
- .status(HttpStatus.OK)
- .body(systemGatewayCheckConsentForCustomerResponse);
- }
- SystemGatewayCheckConsentForCustomerResponse systemGatewayCheckConsentForCustomerResponseEmpty = new SystemGatewayCheckConsentForCustomerResponse();
- return ResponseEntity
- .status(HttpStatus.NO_CONTENT)
- .body(systemGatewayCheckConsentForCustomerResponseEmpty);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement