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 java.util.stream.Collectors;
23  import org.apache.syncope.client.console.rest.WAConfigRestClient;
24  import org.apache.syncope.client.console.wicket.markup.html.bootstrap.dialog.BaseModal;
25  import org.apache.syncope.client.ui.commons.wizards.AjaxWizard;
26  import org.apache.syncope.common.lib.Attr;
27  import org.apache.syncope.common.lib.to.PlainSchemaTO;
28  import org.apache.syncope.common.lib.types.AttrSchemaType;
29  import org.apache.wicket.PageReference;
30  import org.apache.wicket.extensions.wizard.WizardModel;
31  import org.apache.wicket.spring.injection.annot.SpringBean;
32  
33  public class WAConfigModalPanel extends AbstractModalPanel<Attr> {
34  
35      private static final long serialVersionUID = 1690738212977L;
36  
37      protected static ConfParam toConfParam(final Attr attr) {
38          ConfParam param = new ConfParam();
39          param.setSchema(attr.getSchema());
40          param.getValues().addAll(attr.getValues());
41          return param;
42      }
43  
44      protected static Attr toAttr(final ConfParam confParam) {
45          Attr attr = new Attr.Builder(confParam.getSchema()).build();
46          attr.getValues().addAll(
47                  confParam.getValues().stream().map(Serializable::toString).collect(Collectors.toList()));
48          return attr;
49      }
50  
51      @SpringBean
52      protected WAConfigRestClient waConfigRestClient;
53  
54      protected final ParametersWizardPanel.ParametersForm form;
55  
56      public WAConfigModalPanel(
57              final BaseModal<Attr> modal,
58              final Attr attr,
59              final AjaxWizard.Mode mode,
60              final PageReference pageRef) {
61  
62          super(modal, pageRef);
63  
64          PlainSchemaTO schema = new PlainSchemaTO();
65          schema.setType(AttrSchemaType.String);
66          schema.setMandatoryCondition("true");
67          schema.setMultivalue(false);
68  
69          form = new ParametersWizardPanel.ParametersForm(schema, toConfParam(attr));
70  
71          add(new ParametersWizardPanel(form, null, pageRef) {
72  
73              private static final long serialVersionUID = -1469319240177117600L;
74  
75              @Override
76              protected WizardModel buildModelSteps(final ParametersForm modelObject, final WizardModel wizardModel) {
77                  wizardModel.add(new ParametersWizardAttrStep(mode, modelObject));
78                  return wizardModel;
79              }
80  
81              @Override
82              protected Serializable onApplyInternal(final ParametersWizardPanel.ParametersForm modelObject) {
83                  modelObject.getParam().setMultivalue(modelObject.getSchema().isMultivalue());
84                  try {
85                      waConfigRestClient.set(toAttr(modelObject.getParam()));
86                  } catch (Exception e) {
87                      LOG.error("While setting {}", modelObject.getParam(), e);
88                      throw e;
89                  }
90                  return modelObject.getParam();
91              }
92          }.build("waConfigWizardPanel", mode));
93      }
94  
95      @Override
96      public final Attr getItem() {
97          return toAttr(form.getParam());
98      }
99  }