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.wizards.resources;
20  
21  import java.util.List;
22  import java.util.stream.Collectors;
23  import org.apache.syncope.common.lib.to.ConnIdBundle;
24  import org.apache.syncope.common.lib.to.ConnInstanceTO;
25  import org.apache.syncope.common.lib.types.ConnConfProperty;
26  import org.apache.wicket.model.LoadableDetachableModel;
27  
28  public abstract class ConnectorConfPanel extends AbstractConnConfPanel<ConnInstanceTO> {
29  
30      private static final long serialVersionUID = -2025535531121434050L;
31  
32      private final List<ConnIdBundle> bundles;
33  
34      public ConnectorConfPanel(final ConnInstanceTO connInstanceTO, final List<ConnIdBundle> bundles) {
35          super(connInstanceTO);
36          this.bundles = bundles;
37  
38          model = new LoadableDetachableModel<>() {
39  
40              private static final long serialVersionUID = -2965284931860212687L;
41  
42              @Override
43              protected List<ConnConfProperty> load() {
44                  List<ConnConfProperty> properties = getConnProperties(ConnectorConfPanel.this.modelObject);
45                  ConnectorConfPanel.this.modelObject.getConf().clear();
46  
47                  // re-order properties
48                  properties.sort((o1, o2) -> o1 == null ? -1 : o1.compareTo(o2));
49  
50                  ConnectorConfPanel.this.modelObject.getConf().addAll(properties);
51                  return properties;
52              }
53          };
54  
55          setConfPropertyListView(model, true);
56      }
57  
58      /**
59       * Get available configuration properties.
60       *
61       * @param instance connector instance.
62       * @return configuration properties.
63       */
64      @Override
65      protected final List<ConnConfProperty> getConnProperties(final ConnInstanceTO instance) {
66          return ConnectorWizardBuilder.getBundle(instance, bundles).getProperties().stream().
67                  map(key -> {
68                      ConnConfProperty property = new ConnConfProperty();
69                      property.setSchema(key);
70  
71                      instance.getConf(key.getName()).ifPresent(conf -> {
72                          if (conf.getValues() != null) {
73                              property.getValues().addAll(conf.getValues());
74                              property.setOverridable(conf.isOverridable());
75                          }
76                      });
77  
78                      if (property.getValues().isEmpty() && !key.getDefaultValues().isEmpty()) {
79                          property.getValues().addAll(key.getDefaultValues());
80                      }
81                      return property;
82                  }).collect(Collectors.toList());
83      }
84  }