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.commons;
20  
21  import java.io.Serializable;
22  import java.util.Collection;
23  import java.util.List;
24  import java.util.Optional;
25  import java.util.stream.Collectors;
26  import org.apache.commons.lang3.tuple.Pair;
27  import org.apache.commons.lang3.tuple.Triple;
28  import org.apache.syncope.client.console.panels.ListViewPanel;
29  import org.apache.syncope.client.console.status.ReconStatusUtils;
30  import org.apache.syncope.client.console.wicket.markup.html.form.ActionLink;
31  import org.apache.syncope.client.ui.commons.status.ConnObjectWrapper;
32  import org.apache.syncope.common.lib.to.AnyTO;
33  import org.apache.syncope.common.lib.to.ConnObject;
34  import org.apache.syncope.common.lib.types.IdMEntitlement;
35  
36  public class IdMStatusProvider implements StatusProvider {
37  
38      private static final long serialVersionUID = 1875374599950896631L;
39  
40      protected final ReconStatusUtils reconStatusUtils;
41  
42      public IdMStatusProvider(final ReconStatusUtils reconStatusUtils) {
43          this.reconStatusUtils = reconStatusUtils;
44      }
45  
46      @Override
47      public Optional<Pair<ConnObject, ConnObject>> get(
48              final String anyTypeKey, final String connObjectKeyValue, final String resource) {
49  
50          return reconStatusUtils.getReconStatus(anyTypeKey, connObjectKeyValue, resource).
51                  map(status -> Pair.of(status.getOnSyncope(), status.getOnResource()));
52      }
53  
54      @Override
55      public List<Triple<ConnObject, ConnObjectWrapper, String>> get(
56              final AnyTO any, final Collection<String> resources) {
57  
58          return reconStatusUtils.getReconStatuses(
59                  any.getType(), any.getKey(), any.getResources()).stream().
60                  map(status -> Triple.<ConnObject, ConnObjectWrapper, String>of(
61                  status.getRight().getOnSyncope(),
62                  new ConnObjectWrapper(any, status.getLeft(), status.getRight().getOnResource()),
63                  null)).
64                  collect(Collectors.toList());
65      }
66  
67      @Override
68      public <T extends Serializable> void addConnObjectLink(
69              final ListViewPanel.Builder<T> builder,
70              final ActionLink<T> connObjectLink) {
71  
72          builder.addAction(connObjectLink, ActionLink.ActionType.VIEW, IdMEntitlement.RESOURCE_GET_CONNOBJECT);
73      }
74  }