Advertisement
Guest User

SGR

a guest
Jan 16th, 2019
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 6.17 KB | None | 0 0
  1.  @ApiOperation(
  2.             value = "Check consent for customer",
  3.             response = SystemGatewayCheckConsentForCustomerResponse.class,
  4.             authorizations = @Authorization(value = "Authorization")
  5.     )
  6.     @ApiResponses({
  7.             @ApiResponse(code = 404, message = "Customer not found", response = SwaggerErrorResponse.class),
  8.             @ApiResponse(code = 204, message = "Customer has no matching consent", response = SwaggerErrorResponse.class)})
  9.     @RequestMapping(
  10.             produces = MediaType.APPLICATION_JSON_VALUE,
  11.             value = "/customer/{customerId}/consents",
  12.             method = RequestMethod.POST
  13.     )
  14.     public ResponseEntity<SystemGatewayCheckConsentForCustomerResponse> checkConsentForCustomer(
  15.             @PathVariable String customerId,
  16.             @RequestBody final SystemGatewayRequestConsent systemGatewayRequestConsents
  17.     ){
  18.         SystemGatewayCheckConsentForCustomerResponse systemGatewayCheckConsentForCustomerResponse = new SystemGatewayCheckConsentForCustomerResponse();
  19.  
  20.         if(customerRepository.readCustomer(customerId).getCustomer() == null){
  21.             return ResponseEntity
  22.                     .status(HttpStatus.NOT_FOUND)
  23.                     .body(systemGatewayCheckConsentForCustomerResponse);
  24.         }
  25.         Customer customer = customerRepository.readCustomer(customerId).getCustomer();
  26.  
  27.         systemGatewayCheckConsentForCustomerResponse.setCustomerId(customerId);
  28.         systemGatewayCheckConsentForCustomerResponse.setBeneficiary(systemGatewayRequestConsents.getBeneficiary());
  29.  
  30.         if(systemGatewayRequestConsents.getRequestId() != null && !systemGatewayRequestConsents.getRequestId().isEmpty()){
  31.             systemGatewayCheckConsentForCustomerResponse.setRequestId(systemGatewayRequestConsents.getRequestId());
  32.         }
  33.  
  34.         List<SystemGatewayResponseConsent> responseConsents = new ArrayList<>();
  35.         List<SystemGatewayRequestPurposeAndChannelForConsent> consents = systemGatewayRequestConsents.getConsents();
  36.         for(SystemGatewayRequestPurposeAndChannelForConsent consent : consents) {
  37.             String purposeRequest = consent.getPurpose();
  38.             String channelRequest = consent.getChannel();
  39.             SystemGatewayResponseConsent responseConsent = new SystemGatewayResponseConsent();
  40.             ConsentDocumentInformationGetResponse consentDocumentInformationGetResponse = consentDocumentInformationRepository.getConsentInformationFiltered(customerId, CustomerStatus.active, systemGatewayRequestConsents.getBeneficiary(), channelRequest, purposeRequest);
  41.             List<ConsentDocumentInformation> consentDocumentInformations = consentDocumentInformationGetResponse.getConsentDocumentInformationList();
  42.  
  43.             for (ConsentDocumentInformation consentDocumentInformation : consentDocumentInformations)
  44.             {
  45.                 List<ConsentDocumentInformationGrant> consentDocumentInformationGrants = consentDocumentInformation.getGrants();
  46.                 for (ConsentDocumentInformationGrant consentDocumentInformationGrant : consentDocumentInformationGrants)
  47.                 {
  48.                     if (consentDocumentInformationGrant.getChannel().equals(channelRequest))
  49.                     {
  50.                         if (channelRequest.equals("letter"))
  51.                         {
  52.                             responseConsent.setPurpose(purposeRequest);
  53.                             responseConsent.setChannel(channelRequest);
  54.                             responseConsent.setClusterType("address");
  55.                             Address address = customer.getAddresses().get(0);
  56.                             address.setGdpr(null);
  57.                             responseConsent.setData(address);
  58.                             responseConsents.add(responseConsent);
  59.                         } else if (channelRequest.equals("phone"))
  60.                         {
  61.                             responseConsent.setPurpose(purposeRequest);
  62.                             responseConsent.setChannel(channelRequest);
  63.                             responseConsent.setClusterType("phone");
  64.                             Phone phone = customer.getPhones().get(0);
  65.                             phone.setGdpr(null);
  66.                             responseConsent.setData(phone);
  67.                             responseConsents.add(responseConsent);
  68.                         } else if (channelRequest.equals("email"))
  69.                         {
  70.                             responseConsent.setPurpose(purposeRequest);
  71.                             responseConsent.setChannel(channelRequest);
  72.                             responseConsent.setClusterType("email");
  73.                             Email email = customer.getEmails().get(0);
  74.                             email.setGdpr(null);
  75.                             responseConsent.setData(email);
  76.                             responseConsents.add(responseConsent);
  77.                         } else if(channelRequest.equals("vehicleRelation"))
  78.                         {
  79.                             responseConsent.setPurpose(purposeRequest);
  80.                             responseConsent.setChannel(channelRequest);
  81.                             responseConsent.setClusterType("vehicleRelation");
  82.                             VehicleRelation vehicleRelation = customer.getVehicleRelations().get(0);
  83.                             vehicleRelation.setGdpr(null);
  84.                             responseConsent.setData(vehicleRelation);
  85.                             responseConsents.add(responseConsent);
  86.                         }
  87.                     }
  88.                 }
  89.             }
  90.         }
  91.         if(responseConsents.size() > 0) {
  92.             systemGatewayCheckConsentForCustomerResponse.setConsents(responseConsents);
  93.             return ResponseEntity
  94.                     .status(HttpStatus.OK)
  95.                     .body(systemGatewayCheckConsentForCustomerResponse);
  96.         }
  97.  
  98.         SystemGatewayCheckConsentForCustomerResponse systemGatewayCheckConsentForCustomerResponseEmpty = new SystemGatewayCheckConsentForCustomerResponse();
  99.         return ResponseEntity
  100.                 .status(HttpStatus.NO_CONTENT)
  101.                 .body(systemGatewayCheckConsentForCustomerResponseEmpty);
  102.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement