44import es .in2 .issuer .application .workflow .CredentialOfferIssuanceWorkflow ;
55import es .in2 .issuer .domain .exception .ParseErrorException ;
66import es .in2 .issuer .domain .exception .PreAuthorizationCodeGetException ;
7+ import es .in2 .issuer .domain .model .dto .CredentialOfferUriResponse ;
78import es .in2 .issuer .domain .model .dto .CustomCredentialOffer ;
89import es .in2 .issuer .domain .model .dto .PreAuthCodeResponse ;
910import es .in2 .issuer .domain .service .*;
@@ -34,22 +35,60 @@ public class CredentialOfferIssuanceWorkflowImpl implements CredentialOfferIssua
3435 private final IssuerApiClientTokenService issuerApiClientTokenService ;
3536
3637 @ Override
37- public Mono <String > buildCredentialOfferUri (String processId , String transactionCode ) {
38+ public Mono <CredentialOfferUriResponse > buildCredentialOfferUri (String processId , String transactionCode ) {
3839 return deferredCredentialMetadataService .validateTransactionCode (transactionCode )
39- .then (deferredCredentialMetadataService .getProcedureIdByTransactionCode (transactionCode ))
40- .flatMap (procedureId -> credentialProcedureService .getCredentialTypeByProcedureId (procedureId )
41- .flatMap (credentialType -> getPreAuthorizationCodeFromIam ()
42- .flatMap (preAuthCodeResponse ->
43- deferredCredentialMetadataService .updateAuthServerNonceByTransactionCode (transactionCode , preAuthCodeResponse .grant ().preAuthorizedCode ())
44- .then (credentialProcedureService .getMandateeEmailFromDecodedCredentialByProcedureId (procedureId ))
45- .flatMap (email -> credentialOfferService .buildCustomCredentialOffer (credentialType , preAuthCodeResponse .grant (),email ,preAuthCodeResponse .pin ())
46- .flatMap (credentialOfferCacheStorageService ::saveCustomCredentialOffer )
47- .flatMap (credentialOfferService ::createCredentialOfferUri ))
40+ .then (Mono .just (transactionCode ))
41+ .flatMap (this ::buildCredentialOfferUriInternal );
42+ }
43+
44+ @ Override
45+ public Mono <CredentialOfferUriResponse > buildNewCredentialOfferUri (String processId , String cTransactionCode ) {
46+ return deferredCredentialMetadataService .validateCTransactionCode (cTransactionCode )
47+ .flatMap (this ::buildCredentialOfferUriInternal );
48+ }
49+
50+ // Add logs to debug the process
51+ private Mono <CredentialOfferUriResponse > buildCredentialOfferUriInternal (String transactionCode ) {
52+ return deferredCredentialMetadataService .getProcedureIdByTransactionCode (transactionCode )
53+ .flatMap (procedureId ->
54+ credentialProcedureService .getCredentialTypeByProcedureId (procedureId )
55+ .flatMap (credentialType ->
56+ getPreAuthorizationCodeFromIam ()
57+ .flatMap (preAuthCodeResponse ->
58+ deferredCredentialMetadataService .updateAuthServerNonceByTransactionCode (
59+ transactionCode ,
60+ preAuthCodeResponse .grant ().preAuthorizedCode ()
61+ )
62+ .then (
63+ credentialProcedureService .getMandateeEmailFromDecodedCredentialByProcedureId (procedureId )
64+ )
65+ .flatMap (email ->
66+ credentialOfferService .buildCustomCredentialOffer (
67+ credentialType ,
68+ preAuthCodeResponse .grant (),
69+ email ,
70+ preAuthCodeResponse .pin ()
71+ )
72+ .flatMap (credentialOfferCacheStorageService ::saveCustomCredentialOffer )
73+ .flatMap (credentialOfferService ::createCredentialOfferUriResponse )
74+ )
75+ )
76+ .flatMap (credentialOfferUri ->
77+ deferredCredentialMetadataService .updateCacheStoreForCTransactionCode (transactionCode )
78+ .flatMap (cTransactionCode ->
79+ Mono .just (
80+ CredentialOfferUriResponse .builder ()
81+ .credentialOfferUri (credentialOfferUri )
82+ .cTransactionCode (cTransactionCode )
83+ .build ()
84+ )
85+ )
4886 )
4987 )
5088 );
5189 }
5290
91+
5392 @ Override
5493 public Mono <CustomCredentialOffer > getCustomCredentialOffer (String nonce ) {
5594 return credentialOfferCacheStorageService .getCustomCredentialOffer (nonce )
@@ -66,27 +105,27 @@ private Mono<PreAuthCodeResponse> getPreAuthorizationCodeFromIam() {
66105 return issuerApiClientTokenService .getClientToken ()
67106 .flatMap (
68107 token ->
69- webClient .commonWebClient ()
70- .get ()
71- .uri (url )
72- .accept (MediaType .APPLICATION_JSON )
73- .header (HttpHeaders .AUTHORIZATION , BEARER_PREFIX + token )
74- .exchangeToMono (response -> {
75- if (response .statusCode ().is4xxClientError () || response .statusCode ().is5xxServerError ()) {
76- return Mono .error (new PreAuthorizationCodeGetException ("There was an error during pre-authorization code retrieval, error: " + response ));
77- } else {
78- log .info ("Pre Authorization code response: {}" , response );
79- return response .bodyToMono (String .class );
80- }
81- })
82- // Parsing response
83- .flatMap (response -> {
84- try {
85- return Mono .just (objectMapper .readValue (response , PreAuthCodeResponse .class ));
86- } catch (com .fasterxml .jackson .core .JsonProcessingException e ) {
87- return Mono .error (new ParseErrorException ("Error parsing JSON response" ));
88- }
89- })
108+ webClient .commonWebClient ()
109+ .get ()
110+ .uri (url )
111+ .accept (MediaType .APPLICATION_JSON )
112+ .header (HttpHeaders .AUTHORIZATION , BEARER_PREFIX + token )
113+ .exchangeToMono (response -> {
114+ if (response .statusCode ().is4xxClientError () || response .statusCode ().is5xxServerError ()) {
115+ return Mono .error (new PreAuthorizationCodeGetException ("There was an error during pre-authorization code retrieval, error: " + response ));
116+ } else {
117+ log .info ("Pre Authorization code response: {}" , response );
118+ return response .bodyToMono (String .class );
119+ }
120+ })
121+ // Parsing response
122+ .flatMap (response -> {
123+ try {
124+ return Mono .just (objectMapper .readValue (response , PreAuthCodeResponse .class ));
125+ } catch (com .fasterxml .jackson .core .JsonProcessingException e ) {
126+ return Mono .error (new ParseErrorException ("Error parsing JSON response" ));
127+ }
128+ })
90129 );
91130 }
92131
0 commit comments