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.GroupFormLayoutInfo;
25  import org.apache.syncope.client.console.rest.GroupRestClient;
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.GroupTO;
29  import org.apache.syncope.common.lib.to.RealmTO;
30  import org.apache.syncope.common.lib.to.TemplatableTO;
31  import org.apache.syncope.common.lib.types.AnyTypeKind;
32  import org.apache.wicket.PageReference;
33  
34  public class GroupTemplateWizardBuilder extends GroupWizardBuilder implements TemplateWizardBuilder<GroupTO> {
35  
36      private static final long serialVersionUID = 6716803168859873877L;
37  
38      protected final TemplatableTO templatable;
39  
40      public GroupTemplateWizardBuilder(
41              final TemplatableTO templatable,
42              final List<String> anyTypeClasses,
43              final GroupFormLayoutInfo formLayoutInfo,
44              final GroupRestClient groupRestClient,
45              final PageReference pageRef) {
46  
47          super(null, anyTypeClasses, formLayoutInfo, groupRestClient, pageRef);
48  
49          this.templatable = templatable;
50  
51          if (templatable.getTemplates().containsKey(AnyTypeKind.GROUP.name())) {
52              setItem(new GroupWrapper(GroupTO.class.cast(templatable.getTemplates().get(AnyTypeKind.GROUP.name()))));
53          } else {
54              GroupTO groupTO = new GroupTO();
55              if (templatable instanceof RealmTO) {
56                  groupTO.setRealm(
57                          String.format("'%s'", RealmsUtils.getFullPath(RealmTO.class.cast(templatable).getFullPath())));
58              }
59              setItem(new GroupWrapper(groupTO));
60          }
61      }
62  
63      @Override
64      protected Optional<Details<GroupTO>> addOptionalDetailsPanel(final AnyWrapper<GroupTO> modelObject) {
65          Optional<Details<GroupTO>> details = super.addOptionalDetailsPanel(modelObject);
66          if (templatable instanceof RealmTO) {
67              details.ifPresent(Details::disableRealmSpecification);
68          }
69          return details;
70      }
71  
72      @Override
73      public AjaxWizard<AnyWrapper<GroupTO>> build(final String id) {
74          return super.build(id, AjaxWizard.Mode.TEMPLATE);
75      }
76  }