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.GroupCR;
25  import org.apache.syncope.common.lib.request.GroupUR;
26  import org.apache.syncope.common.lib.to.GroupTO;
27  import org.apache.syncope.common.lib.to.ProvisioningResult;
28  import org.apache.syncope.common.lib.types.ProvisionAction;
29  import org.apache.syncope.common.rest.api.beans.AnyQuery;
30  import org.apache.syncope.common.rest.api.service.AnyService;
31  import org.apache.syncope.common.rest.api.service.GroupService;
32  import org.apache.wicket.extensions.markup.html.repeater.util.SortParam;
33  
34  /**
35   * Console client for invoking Rest Group's services.
36   */
37  public class GroupRestClient extends AbstractAnyRestClient<GroupTO> {
38  
39      private static final long serialVersionUID = -8549081557283519638L;
40  
41      @Override
42      protected Class<? extends AnyService<GroupTO>> getAnyServiceClass() {
43          return GroupService.class;
44      }
45  
46      public ProvisioningResult<GroupTO> create(final GroupCR groupCR) {
47          Response response = getService(GroupService.class).create(groupCR);
48          return response.readEntity(new GenericType<>() {
49          });
50      }
51  
52      public ProvisioningResult<GroupTO> update(final String etag, final GroupUR updateReq) {
53          ProvisioningResult<GroupTO> result;
54          synchronized (this) {
55              result = getService(etag, GroupService.class).update(updateReq).
56                      readEntity(new GenericType<>() {
57                      });
58              resetClient(getAnyServiceClass());
59          }
60          return result;
61      }
62  
63      @Override
64      public int count(final String realm, final String fiql, final String type) {
65          return getService(GroupService.class).
66                  search(new AnyQuery.Builder().realm(realm).fiql(fiql).page(1).size(0).details(false).build()).
67                  getTotalCount();
68      }
69  
70      @Override
71      public List<GroupTO> search(
72              final String realm,
73              final String fiql,
74              final int page,
75              final int size,
76              final SortParam<String> sort,
77              final String type) {
78  
79          return getService(GroupService.class).
80                  search(new AnyQuery.Builder().realm(realm).fiql(fiql).page(page).size(size).details(false).
81                          orderBy(toOrderBy(sort)).details(false).build()).getResult();
82      }
83  
84      public void provisionMembers(final String key, final ProvisionAction actionType) {
85          getService(GroupService.class).provisionMembers(key, actionType);
86      }
87  }