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.rest.RealmRestClient;
23  import org.apache.syncope.client.console.wizards.BaseAjaxWizardBuilder;
24  import org.apache.syncope.common.lib.to.ProvisioningResult;
25  import org.apache.syncope.common.lib.to.RealmTO;
26  import org.apache.wicket.PageReference;
27  import org.apache.wicket.behavior.AttributeAppender;
28  import org.apache.wicket.extensions.wizard.WizardModel;
29  import org.apache.wicket.extensions.wizard.WizardStep;
30  
31  public class RealmWizardBuilder extends BaseAjaxWizardBuilder<RealmTO> {
32  
33      private static final long serialVersionUID = 5945391813567245081L;
34  
35      protected final RealmRestClient realmRestClient;
36  
37      protected String parentPath;
38  
39      public RealmWizardBuilder(final RealmRestClient realmRestClient, final PageReference pageRef) {
40          super(new RealmTO(), pageRef);
41          this.realmRestClient = realmRestClient;
42      }
43  
44      @Override
45      protected Serializable onApplyInternal(final RealmTO modelObject) {
46          ProvisioningResult<RealmTO> result;
47          if (modelObject.getKey() == null) {
48              result = realmRestClient.create(this.parentPath, modelObject);
49          } else {
50              result = realmRestClient.update(modelObject);
51          }
52          return result;
53      }
54  
55      @Override
56      protected WizardModel buildModelSteps(final RealmTO modelObject, final WizardModel wizardModel) {
57          wizardModel.add(new Realm(modelObject));
58          return wizardModel;
59      }
60  
61      public static class Realm extends WizardStep {
62  
63          private static final long serialVersionUID = -2123790676338327104L;
64  
65          public Realm(final RealmTO modelObject) {
66              RealmDetails realmDetail = new RealmDetails("details", modelObject);
67              realmDetail.add(new AttributeAppender("style", "overflow-x:hidden;"));
68              add(realmDetail);
69          }
70      }
71  
72      public void setParentPath(final String parentPath) {
73          this.parentPath = parentPath;
74      }
75  }