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.status;
20  
21  import java.util.Optional;
22  import org.apache.commons.lang3.tuple.Pair;
23  import org.apache.syncope.client.console.panels.RemoteObjectPanel;
24  import org.apache.syncope.client.console.wizards.any.ConnObjectPanel;
25  import org.apache.syncope.client.ui.commons.Constants;
26  import org.apache.syncope.common.lib.to.ConnObject;
27  import org.apache.syncope.common.lib.to.ReconStatus;
28  import org.apache.wicket.model.IModel;
29  import org.apache.wicket.model.Model;
30  import org.apache.wicket.model.ResourceModel;
31  import org.apache.wicket.spring.injection.annot.SpringBean;
32  
33  public class LinkedAccountStatusPanel extends RemoteObjectPanel {
34  
35      private static final long serialVersionUID = 7662852503618434902L;
36  
37      @SpringBean
38      protected ReconStatusUtils reconStatusUtils;
39  
40      protected final String resource;
41  
42      protected final String anyTypeKey;
43  
44      protected final String connObjectKeyValue;
45  
46      public LinkedAccountStatusPanel(
47              final String resource,
48              final String anyTypeKey,
49              final String connObjectKeyValue) {
50  
51          this.resource = resource;
52          this.anyTypeKey = anyTypeKey;
53          this.connObjectKeyValue = connObjectKeyValue;
54  
55          add(new ConnObjectPanel(
56                  REMOTE_OBJECT_PANEL_ID,
57                  Pair.<IModel<?>, IModel<?>>of(Model.of(Constants.SYNCOPE), new ResourceModel("resource")),
58                  getConnObjectTOs(),
59                  false));
60      }
61  
62      @Override
63      protected Pair<ConnObject, ConnObject> getConnObjectTOs() {
64          Optional<ReconStatus> status = reconStatusUtils.getReconStatus(anyTypeKey, connObjectKeyValue, resource);
65  
66          return status.map(reconStatus -> Pair.of(reconStatus.getOnSyncope(), reconStatus.getOnResource())).orElse(null);
67      }
68  }