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.any;
20  
21  import java.util.List;
22  import java.util.Optional;
23  import org.apache.syncope.client.console.commons.RealmsUtils;
24  import org.apache.syncope.client.console.layout.AnyObjectFormLayoutInfo;
25  import org.apache.syncope.client.console.rest.AnyObjectRestClient;
26  import org.apache.syncope.client.ui.commons.wizards.AjaxWizard;
27  import org.apache.syncope.client.ui.commons.wizards.any.AnyWrapper;
28  import org.apache.syncope.common.lib.to.AnyObjectTO;
29  import org.apache.syncope.common.lib.to.RealmTO;
30  import org.apache.syncope.common.lib.to.TemplatableTO;
31  import org.apache.wicket.PageReference;
32  
33  public class AnyObjectTemplateWizardBuilder extends AnyObjectWizardBuilder
34          implements TemplateWizardBuilder<AnyObjectTO> {
35  
36      private static final long serialVersionUID = 6716803168859873877L;
37  
38      protected final TemplatableTO templatable;
39  
40      public AnyObjectTemplateWizardBuilder(
41              final TemplatableTO templatable,
42              final String anyType,
43              final List<String> anyTypeClasses,
44              final AnyObjectFormLayoutInfo formLayoutInfo,
45              final AnyObjectRestClient anyObjectRestClient,
46              final PageReference pageRef) {
47  
48          super(null, anyTypeClasses, formLayoutInfo, anyObjectRestClient, pageRef);
49  
50          this.templatable = templatable;
51  
52          if (templatable.getTemplates().containsKey(anyType)) {
53              setItem(new AnyObjectWrapper(AnyObjectTO.class.cast(templatable.getTemplates().get(anyType))));
54          } else {
55              AnyObjectTO anyObjectTO = new AnyObjectTO();
56              anyObjectTO.setType(anyType);
57              if (templatable instanceof RealmTO) {
58                  anyObjectTO.setRealm(
59                          String.format("'%s'", RealmsUtils.getFullPath(RealmTO.class.cast(templatable).getFullPath())));
60              }
61              setItem(new AnyObjectWrapper(anyObjectTO));
62          }
63      }
64  
65      @Override
66      protected Optional<Details<AnyObjectTO>> addOptionalDetailsPanel(final AnyWrapper<AnyObjectTO> modelObject) {
67          Optional<Details<AnyObjectTO>> details = super.addOptionalDetailsPanel(modelObject);
68          if (templatable instanceof RealmTO) {
69              details.ifPresent(Details::disableRealmSpecification);
70          }
71          return details;
72      }
73  
74      @Override
75      public AjaxWizard<AnyWrapper<AnyObjectTO>> build(final String id) {
76          return super.build(id, AjaxWizard.Mode.TEMPLATE);
77      }
78  }