View Javadoc
1   /*
2    * Copyright (c) 2002-2024, City of Paris
3    * All rights reserved.
4    *
5    * Redistribution and use in source and binary forms, with or without
6    * modification, are permitted provided that the following conditions
7    * are met:
8    *
9    *  1. Redistributions of source code must retain the above copyright notice
10   *     and the following disclaimer.
11   *
12   *  2. Redistributions in binary form must reproduce the above copyright notice
13   *     and the following disclaimer in the documentation and/or other materials
14   *     provided with the distribution.
15   *
16   *  3. Neither the name of 'Mairie de Paris' nor 'Lutece' nor the names of its
17   *     contributors may be used to endorse or promote products derived from
18   *     this software without specific prior written permission.
19   *
20   * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21   * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22   * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23   * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
24   * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25   * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26   * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27   * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28   * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29   * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30   * POSSIBILITY OF SUCH DAMAGE.
31   *
32   * License 1.0
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   * IdentityQualityRestClientService
59   */
60  public class IdentityQualityTransportRest extends AbstractTransportRest implements IIdentityQualityTransportProvider
61  {
62      /** URL for identityStore Quality REST service */
63      private String _strIdentityStoreQualityEndPoint;
64      
65      private String _strIdentityPath;
66  
67      /**
68       * Simple Constructor
69       */
70      public IdentityQualityTransportRest( )
71      {
72          super( new HttpAccessTransport( ) );
73      }
74  
75      /**
76       * Constructor with IHttpTransportProvider parameter
77       *
78       * @param httpTransport
79       *            the provider to use
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       * Constructor with IHttpTransportProvider parameter
91       *
92       * @param httpTransport
93       *            the provider to use
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      * {@inheritDoc }
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      * {@inheritDoc }
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      * {@inheritDoc }
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      * {@inheritDoc }
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      * {@inheritDoc }
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 }