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 void onCancelInternal(final ParametersForm modelObject) {
51          //do nothing
52      }
53  
54      @Override
55      protected Serializable onApplyInternal(final ParametersForm modelObject) {
56          modelObject.getParam().setMultivalue(modelObject.getSchema().isMultivalue());
57          try {
58              confParamOps.set(
59                      SyncopeConsoleSession.get().getDomain(),
60                      modelObject.getParam().getSchema(),
61                      modelObject.getParam().valueAsObject());
62          } catch (Exception e) {
63              LOG.error("While setting {}", modelObject.getParam(), e);
64              throw e;
65          }
66          return modelObject.getParam();
67      }
68  
69      public static class ParametersForm implements Serializable {
70  
71          private static final long serialVersionUID = 412294016850871853L;
72  
73          private final PlainSchemaTO schema;
74  
75          private final ConfParam param;
76  
77          public ParametersForm(final PlainSchemaTO schema, final ConfParam param) {
78              this.schema = schema;
79              this.param = param;
80          }
81  
82          public PlainSchemaTO getSchema() {
83              return schema;
84          }
85  
86          public ConfParam getParam() {
87              return param;
88          }
89      }
90  }