1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34 package fr.paris.lutece.plugins.quotientfamille.dataclient;
35
36 import fr.paris.lutece.plugins.quotientfamille.service.RedirectUtils;
37 import fr.paris.lutece.plugins.quotientfamille.web.FranceConnectSampleApp;
38 import fr.paris.lutece.plugins.franceconnect.oidc.Token;
39 import fr.paris.lutece.plugins.franceconnect.oidc.dataclient.AbstractDataClient;
40 import fr.paris.lutece.plugins.franceconnect.service.MapperService;
41 import fr.paris.lutece.portal.service.util.AppLogService;
42
43 import java.io.IOException;
44
45 import javax.servlet.http.HttpServletRequest;
46 import javax.servlet.http.HttpServletResponse;
47
48 import org.apache.commons.lang.StringUtils;
49
50
51
52
53 public class RevenuDataClient extends AbstractDataClient
54 {
55
56
57
58 private String _strDataServerUriOs1;
59 private String _strDataServerUriOs2;
60
61 public String getDataServerUriOs1( )
62 {
63 return _strDataServerUriOs1;
64 }
65
66 public void setDataServerUriOs1( String strDataServerUri )
67 {
68 _strDataServerUriOs1 = strDataServerUri;
69 }
70
71 public String getDataServerUriOs2( )
72 {
73 return _strDataServerUriOs2;
74 }
75
76 public void setDataServerUriOs2( String strDataServerUri )
77 {
78 _strDataServerUriOs2 = strDataServerUri;
79 }
80
81 public static final String ATTRIBUTE_QUOTIENTFAMILIAL = "quotientfamille-dc-userrevenu";
82 public static final String ATTRIBUTE_ADDRESSEFISCALE = "quotientfamille-dc-useraddresse";
83
84 @Override
85
86 public synchronized void handleToken( Token token, HttpServletRequest request, HttpServletResponse response )
87 {
88 try
89 {
90
91 setDataServerUri( getDataServerUriOs1( ) );
92 String data = getData( token );
93 if ( StringUtils.isNotEmpty( data ) ) {
94 UserRevenu userRevenu = MapperService.parse( data, UserRevenu.class );
95 request.getSession( true ).setAttribute(ATTRIBUTE_QUOTIENTFAMILIAL, userRevenu.getQuotientfamilial() );
96 }
97 setDataServerUri( getDataServerUriOs2( ) );
98 data = getData( token );
99 if ( StringUtils.isNotEmpty( data ) ) {
100 UserAddresseFiscale userAdresseFiscale = MapperService.parse( data, UserAddresseFiscale.class );
101 request.getSession( true ).setAttribute(ATTRIBUTE_ADDRESSEFISCALE, userAdresseFiscale.getAft() );
102 }
103 String strRedirectUrl = RedirectUtils.getViewUrl( request, FranceConnectSampleApp.VIEW_DEMARCHE_ETAPE2 );
104 response.sendRedirect( strRedirectUrl );
105 }
106 catch ( IOException ex )
107 {
108 AppLogService.error( "Error DataClient Revenu : " + ex.getMessage( ), ex );
109 }
110 }
111 }