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.identityquality.v3.web.rs.service;
35
36 import fr.paris.lutece.plugins.identityquality.v3.web.service.IHttpTransportProvider;
37 import fr.paris.lutece.plugins.identityquality.v3.web.service.IIdentityQualityTransportProvider;
38 import fr.paris.lutece.plugins.identitystore.v3.web.rs.SuspiciousIdentityRequestValidator;
39 import fr.paris.lutece.plugins.identitystore.v3.web.rs.dto.common.RequestAuthor;
40 import fr.paris.lutece.plugins.identitystore.v3.web.rs.dto.crud.SuspiciousIdentityChangeRequest;
41 import fr.paris.lutece.plugins.identitystore.v3.web.rs.dto.crud.SuspiciousIdentityChangeResponse;
42 import fr.paris.lutece.plugins.identitystore.v3.web.rs.dto.crud.SuspiciousIdentityExcludeRequest;
43 import fr.paris.lutece.plugins.identitystore.v3.web.rs.dto.crud.SuspiciousIdentityExcludeResponse;
44 import fr.paris.lutece.plugins.identitystore.v3.web.rs.dto.crud.SuspiciousIdentitySearchRequest;
45 import fr.paris.lutece.plugins.identitystore.v3.web.rs.dto.crud.SuspiciousIdentitySearchResponse;
46 import fr.paris.lutece.plugins.identitystore.v3.web.rs.dto.duplicate.DuplicateRuleSummarySearchResponse;
47 import fr.paris.lutece.plugins.identitystore.v3.web.rs.dto.lock.SuspiciousIdentityLockRequest;
48 import fr.paris.lutece.plugins.identitystore.v3.web.rs.dto.lock.SuspiciousIdentityLockResponse;
49 import fr.paris.lutece.plugins.identitystore.v3.web.rs.dto.search.DuplicateSearchRequest;
50 import fr.paris.lutece.plugins.identitystore.v3.web.rs.dto.search.DuplicateSearchResponse;
51 import fr.paris.lutece.plugins.identitystore.v3.web.rs.util.Constants;
52 import fr.paris.lutece.plugins.identitystore.web.exception.IdentityStoreException;
53
54 import java.util.HashMap;
55 import java.util.Map;
56
57
58
59
60 public class IdentityQualityTransportRest extends AbstractTransportRest implements IIdentityQualityTransportProvider
61 {
62
63 private String _strIdentityStoreQualityEndPoint;
64
65 private String _strIdentityPath;
66
67
68
69
70 public IdentityQualityTransportRest( )
71 {
72 super( new HttpAccessTransport( ) );
73 }
74
75
76
77
78
79
80
81 public IdentityQualityTransportRest( final IHttpTransportProvider httpTransport )
82 {
83 super( httpTransport );
84
85 _strIdentityStoreQualityEndPoint = httpTransport.getApiEndPointUrl( );
86 _strIdentityPath = Constants.CONSTANT_DEFAULT_IDENTITY_PATH;
87 }
88
89
90
91
92
93
94
95 public IdentityQualityTransportRest( final IHttpTransportProvider httpTransport, String strIdentityPath )
96 {
97 super( httpTransport );
98
99 _strIdentityStoreQualityEndPoint = httpTransport.getApiEndPointUrl( );
100 _strIdentityPath = strIdentityPath;
101 }
102
103
104
105
106 @Override
107 public DuplicateRuleSummarySearchResponse getAllDuplicateRules( final String strClientCode, final RequestAuthor author, final Integer priority )
108 throws IdentityStoreException
109 {
110 this.checkCommonHeaders( strClientCode, author );
111
112 final Map<String, String> mapHeadersRequest = new HashMap<>( );
113 mapHeadersRequest.put( Constants.PARAM_CLIENT_CODE, strClientCode );
114 mapHeadersRequest.put( Constants.PARAM_AUTHOR_NAME, author.getName( ) );
115 mapHeadersRequest.put( Constants.PARAM_AUTHOR_TYPE, author.getType( ).name( ) );
116
117 final Map<String, String> mapParams = new HashMap<>( );
118 if ( priority != null )
119 {
120 mapParams.put( Constants.PARAM_RULE_PRIORITY, priority.toString( ) );
121 }
122
123 final String url = _strIdentityStoreQualityEndPoint + _strIdentityPath + Constants.VERSION_PATH_V3 + Constants.QUALITY_PATH + "/" + Constants.RULES_PATH;
124 return _httpTransport.doGet( url, mapParams, mapHeadersRequest, DuplicateRuleSummarySearchResponse.class, _mapper );
125 }
126
127
128
129
130 @Override
131 public SuspiciousIdentityChangeResponse createSuspiciousIdentity( final SuspiciousIdentityChangeRequest request, final String strClientCode,
132 final RequestAuthor author ) throws IdentityStoreException
133 {
134 this.checkCommonHeaders( strClientCode, author );
135 SuspiciousIdentityRequestValidator.instance( ).checkSuspiciousIdentityChange( request );
136 SuspiciousIdentityRequestValidator.instance( ).checkCustomerId( request.getSuspiciousIdentity( ).getCustomerId( ) );
137
138 final Map<String, String> mapHeadersRequest = new HashMap<>( );
139 mapHeadersRequest.put( Constants.PARAM_CLIENT_CODE, strClientCode );
140 mapHeadersRequest.put( Constants.PARAM_AUTHOR_NAME, author.getName( ) );
141 mapHeadersRequest.put( Constants.PARAM_AUTHOR_TYPE, author.getType( ).name( ) );
142
143 final Map<String, String> mapParams = new HashMap<>( );
144
145 final String url = _strIdentityStoreQualityEndPoint + _strIdentityPath + Constants.VERSION_PATH_V3 + Constants.QUALITY_PATH + "/" + Constants.SUSPICIONS_PATH;
146 return _httpTransport.doPostJSON( url, mapParams, mapHeadersRequest, request, SuspiciousIdentityChangeResponse.class, _mapper );
147 }
148
149
150
151
152 @Override
153 public SuspiciousIdentitySearchResponse getSuspiciousIdentities( final SuspiciousIdentitySearchRequest request, final String strClientCode,
154 final RequestAuthor author ) throws IdentityStoreException
155 {
156 this.checkCommonHeaders( strClientCode, author );
157 SuspiciousIdentityRequestValidator.instance( ).checkSuspiciousIdentitySearch( request );
158
159 final Map<String, String> mapHeadersRequest = new HashMap<>( );
160 mapHeadersRequest.put( Constants.PARAM_CLIENT_CODE, strClientCode );
161 mapHeadersRequest.put( Constants.PARAM_AUTHOR_NAME, author.getName( ) );
162 mapHeadersRequest.put( Constants.PARAM_AUTHOR_TYPE, author.getType( ).name( ) );
163
164 final Map<String, String> mapParams = new HashMap<>( );
165
166 final String url = _strIdentityStoreQualityEndPoint + _strIdentityPath + Constants.VERSION_PATH_V3 + Constants.QUALITY_PATH + "/" + Constants.SUSPICIONS_PATH
167 + Constants.SEARCH_IDENTITIES_PATH;
168 return _httpTransport.doPostJSON( url, mapParams, mapHeadersRequest, request, SuspiciousIdentitySearchResponse.class, _mapper );
169 }
170
171
172
173
174 @Override
175 public DuplicateSearchResponse getDuplicates( final String customerId, final String ruleCode, final String strClientCode, final RequestAuthor author )
176 throws IdentityStoreException
177 {
178 this.checkCommonHeaders( strClientCode, author );
179 SuspiciousIdentityRequestValidator.instance( ).checkCustomerId( customerId );
180 SuspiciousIdentityRequestValidator.instance( ).checkRuleCode( ruleCode );
181
182 final Map<String, String> mapHeadersRequest = new HashMap<>( );
183 mapHeadersRequest.put( Constants.PARAM_CLIENT_CODE, strClientCode );
184 mapHeadersRequest.put( Constants.PARAM_AUTHOR_NAME, author.getName( ) );
185 mapHeadersRequest.put( Constants.PARAM_AUTHOR_TYPE, author.getType( ).name( ) );
186
187 final HashMap<String, String> mapParams = new HashMap<>( );
188 mapParams.put( Constants.PARAM_RULE_CODE, ruleCode );
189
190 final String url = _strIdentityStoreQualityEndPoint + _strIdentityPath + Constants.VERSION_PATH_V3 + Constants.QUALITY_PATH + "/" + Constants.DUPLICATE_PATH + "/"
191 + customerId;
192 return _httpTransport.doGet( url, mapParams, mapHeadersRequest, DuplicateSearchResponse.class, _mapper );
193 }
194
195
196
197
198 @Override
199 public DuplicateSearchResponse searchDuplicates( final DuplicateSearchRequest request, final String strClientCode, final RequestAuthor author )
200 throws IdentityStoreException
201 {
202 this.checkCommonHeaders( strClientCode, author );
203 SuspiciousIdentityRequestValidator.instance( ).checkDuplicateSearch( request );
204
205 final Map<String, String> mapHeadersRequest = new HashMap<>( );
206 mapHeadersRequest.put( Constants.PARAM_CLIENT_CODE, strClientCode );
207 mapHeadersRequest.put( Constants.PARAM_AUTHOR_NAME, author.getName( ) );
208 mapHeadersRequest.put( Constants.PARAM_AUTHOR_TYPE, author.getType( ).name( ) );
209
210 final String url = _strIdentityStoreQualityEndPoint + _strIdentityPath + Constants.VERSION_PATH_V3 + Constants.QUALITY_PATH + "/" + Constants.DUPLICATE_PATH
211 + Constants.SEARCH_IDENTITIES_PATH;
212 return _httpTransport.doPostJSON( url, new HashMap<>( ), mapHeadersRequest, request, DuplicateSearchResponse.class, _mapper );
213 }
214
215 @Override
216 public SuspiciousIdentityExcludeResponse excludeIdentities( final SuspiciousIdentityExcludeRequest request, final String strClientCode,
217 final RequestAuthor author ) throws IdentityStoreException
218 {
219 this.checkCommonHeaders( strClientCode, author );
220 SuspiciousIdentityRequestValidator.instance( ).checkSuspiciousIdentityChange( request );
221
222 final Map<String, String> mapHeadersRequest = new HashMap<>( );
223 mapHeadersRequest.put( Constants.PARAM_CLIENT_CODE, strClientCode );
224 mapHeadersRequest.put( Constants.PARAM_AUTHOR_NAME, author.getName( ) );
225 mapHeadersRequest.put( Constants.PARAM_AUTHOR_TYPE, author.getType( ).name( ) );
226
227 final String url = _strIdentityStoreQualityEndPoint + _strIdentityPath + Constants.VERSION_PATH_V3 + Constants.QUALITY_PATH + Constants.EXCLUSION_PATH;
228 return _httpTransport.doPutJSON( url, null, mapHeadersRequest, request, SuspiciousIdentityExcludeResponse.class, _mapper );
229 }
230
231 @Override
232 public SuspiciousIdentityExcludeResponse cancelIdentitiesExclusion( final SuspiciousIdentityExcludeRequest request, final String strClientCode,
233 final RequestAuthor author ) throws IdentityStoreException
234 {
235 this.checkCommonHeaders( strClientCode, author );
236 SuspiciousIdentityRequestValidator.instance( ).checkSuspiciousIdentityChange( request );
237
238 final Map<String, String> mapHeadersRequest = new HashMap<>( );
239 mapHeadersRequest.put( Constants.PARAM_CLIENT_CODE, strClientCode );
240 mapHeadersRequest.put( Constants.PARAM_AUTHOR_NAME, author.getName( ) );
241 mapHeadersRequest.put( Constants.PARAM_AUTHOR_TYPE, author.getType( ).name( ) );
242
243 final String url = _strIdentityStoreQualityEndPoint + _strIdentityPath + Constants.VERSION_PATH_V3 + Constants.QUALITY_PATH + Constants.CANCEL_IDENTITIES_EXCLUSION_PATH;
244 return _httpTransport.doPostJSON( url, null, mapHeadersRequest, request, SuspiciousIdentityExcludeResponse.class, _mapper );
245 }
246
247 @Override
248 public SuspiciousIdentityLockResponse lock( final SuspiciousIdentityLockRequest request, final String strClientCode, final RequestAuthor author )
249 throws IdentityStoreException
250 {
251 this.checkCommonHeaders( strClientCode, author );
252 SuspiciousIdentityRequestValidator.instance( ).checkLockRequest( request );
253
254 final Map<String, String> mapHeadersRequest = new HashMap<>( );
255 mapHeadersRequest.put( Constants.PARAM_CLIENT_CODE, strClientCode );
256 mapHeadersRequest.put( Constants.PARAM_AUTHOR_NAME, author.getName( ) );
257 mapHeadersRequest.put( Constants.PARAM_AUTHOR_TYPE, author.getType( ).name( ) );
258
259 final String url = _strIdentityStoreQualityEndPoint + _strIdentityPath + Constants.VERSION_PATH_V3 + Constants.QUALITY_PATH + "/" + Constants.LOCK_PATH;
260 return _httpTransport.doPostJSON( url, null, mapHeadersRequest, request, SuspiciousIdentityLockResponse.class, _mapper );
261 }
262 }