View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.apache.syncope.client.console.rest;
20  
21  import java.io.InputStream;
22  import java.util.ArrayList;
23  import java.util.stream.Collectors;
24  import javax.ws.rs.core.Response;
25  import org.apache.cxf.jaxrs.client.Client;
26  import org.apache.cxf.jaxrs.client.WebClient;
27  import org.apache.syncope.common.lib.to.ProvisioningReport;
28  import org.apache.syncope.common.lib.to.PullTaskTO;
29  import org.apache.syncope.common.lib.to.PushTaskTO;
30  import org.apache.syncope.common.lib.to.ReconStatus;
31  import org.apache.syncope.common.rest.api.RESTHeaders;
32  import org.apache.syncope.common.rest.api.beans.AnyQuery;
33  import org.apache.syncope.common.rest.api.beans.CSVPullSpec;
34  import org.apache.syncope.common.rest.api.beans.CSVPushSpec;
35  import org.apache.syncope.common.rest.api.beans.ReconQuery;
36  import org.apache.syncope.common.rest.api.service.ReconciliationService;
37  
38  public class ReconciliationRestClient extends BaseRestClient {
39  
40      private static final long serialVersionUID = -3161863874876938094L;
41  
42      public ReconStatus status(final ReconQuery reconQuery) {
43          return getService(ReconciliationService.class).status(reconQuery);
44      }
45  
46      public void push(final ReconQuery reconQuery, final PushTaskTO pushTask) {
47          getService(ReconciliationService.class).push(reconQuery, pushTask);
48      }
49  
50      public void pull(final ReconQuery reconQuery, final PullTaskTO pullTask) {
51          getService(ReconciliationService.class).pull(reconQuery, pullTask);
52      }
53  
54      public Response push(final AnyQuery anyQuery, final CSVPushSpec spec) {
55          ReconciliationService service = getService(ReconciliationService.class);
56          Client client = WebClient.client(service);
57          client.accept(RESTHeaders.TEXT_CSV);
58  
59          Response response = service.push(anyQuery, spec);
60  
61          resetClient(ReconciliationService.class);
62  
63          return response;
64      }
65  
66      public ArrayList<ProvisioningReport> pull(final CSVPullSpec spec, final InputStream csv) {
67          ReconciliationService service = getService(ReconciliationService.class);
68          Client client = WebClient.client(service);
69          client.type(RESTHeaders.TEXT_CSV);
70  
71          ArrayList<ProvisioningReport> result = service.pull(spec, csv).stream().
72                  collect(Collectors.toCollection(ArrayList::new));
73  
74          resetClient(ReconciliationService.class);
75  
76          return result;
77      }
78  }