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.panels;
20  
21  import java.io.Serializable;
22  import org.apache.syncope.client.console.SyncopeConsoleSession;
23  import org.apache.syncope.client.console.wizards.BaseAjaxWizardBuilder;
24  import org.apache.syncope.common.keymaster.client.api.ConfParamOps;
25  import org.apache.syncope.common.lib.to.PlainSchemaTO;
26  import org.apache.wicket.PageReference;
27  import org.apache.wicket.extensions.wizard.WizardModel;
28  
29  public class ParametersWizardPanel extends BaseAjaxWizardBuilder<ParametersWizardPanel.ParametersForm> {
30  
31      private static final long serialVersionUID = -2868592590785581481L;
32  
33      private final ConfParamOps confParamOps;
34  
35      public ParametersWizardPanel(
36              final ParametersForm defaultItem, final ConfParamOps confParamOps, final PageReference pageRef) {
37  
38          super(defaultItem, pageRef);
39          this.confParamOps = confParamOps;
40      }
41  
42      @Override
43      protected WizardModel buildModelSteps(final ParametersForm modelObject, final WizardModel wizardModel) {
44          wizardModel.add(new ParametersWizardSchemaStep(mode, modelObject));
45          wizardModel.add(new ParametersWizardAttrStep(mode, modelObject));
46          return wizardModel;
47      }
48  
49      @Override
50      protected Serializable onApplyInternal(final ParametersForm modelObject) {
51          modelObject.getParam().setMultivalue(modelObject.getSchema().isMultivalue());
52          try {
53              confParamOps.set(
54                      SyncopeConsoleSession.get().getDomain(),
55                      modelObject.getParam().getSchema(),
56                      modelObject.getParam().valueAsObject());
57          } catch (Exception e) {
58              LOG.error("While setting {}", modelObject.getParam(), e);
59              throw e;
60          }
61          return modelObject.getParam();
62      }
63  
64      public static class ParametersForm implements Serializable {
65  
66          private static final long serialVersionUID = 412294016850871853L;
67  
68          private final PlainSchemaTO schema;
69  
70          private final ConfParam param;
71  
72          public ParametersForm(final PlainSchemaTO schema, final ConfParam param) {
73              this.schema = schema;
74              this.param = param;
75          }
76  
77          public PlainSchemaTO getSchema() {
78              return schema;
79          }
80  
81          public ConfParam getParam() {
82              return param;
83          }
84      }
85  }