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.util.List;
22  import javax.ws.rs.core.GenericType;
23  import javax.ws.rs.core.Response;
24  import org.apache.syncope.common.lib.request.AnyObjectCR;
25  import org.apache.syncope.common.lib.request.AnyObjectUR;
26  import org.apache.syncope.common.lib.to.AnyObjectTO;
27  import org.apache.syncope.common.lib.to.ProvisioningResult;
28  import org.apache.syncope.common.rest.api.beans.AnyQuery;
29  import org.apache.syncope.common.rest.api.service.AnyObjectService;
30  import org.apache.syncope.common.rest.api.service.AnyService;
31  import org.apache.wicket.extensions.markup.html.repeater.util.SortParam;
32  
33  /**
34   * Console client for invoking Rest any type class services.
35   */
36  public class AnyObjectRestClient extends AbstractAnyRestClient<AnyObjectTO> {
37  
38      private static final long serialVersionUID = -8874495991295283249L;
39  
40      @Override
41      protected Class<? extends AnyService<AnyObjectTO>> getAnyServiceClass() {
42          return AnyObjectService.class;
43      }
44  
45      public ProvisioningResult<AnyObjectTO> create(final AnyObjectCR createReq) {
46          Response response = getService(AnyObjectService.class).create(createReq);
47          return response.readEntity(new GenericType<>() {
48          });
49      }
50  
51      public ProvisioningResult<AnyObjectTO> update(final String etag, final AnyObjectUR updateReq) {
52          ProvisioningResult<AnyObjectTO> result;
53          synchronized (this) {
54              result = getService(etag, AnyObjectService.class).update(updateReq).
55                      readEntity(new GenericType<>() {
56                      });
57              resetClient(getAnyServiceClass());
58          }
59          return result;
60      }
61  
62      @Override
63      public int count(final String realm, final String fiql, final String type) {
64          return getService(AnyObjectService.class).
65                  search(new AnyQuery.Builder().realm(realm).fiql(fiql).page(1).size(0).build()).
66                  getTotalCount();
67      }
68  
69      @Override
70      public List<AnyObjectTO> search(final String realm, final String fiql, final int page, final int size,
71              final SortParam<String> sort,
72              final String type) {
73  
74          return getService(AnyObjectService.class).search(
75                  new AnyQuery.Builder().realm(realm).fiql(fiql).page(page).size(size).
76                          orderBy(toOrderBy(sort)).details(false).build()).getResult();
77      }
78  }