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.util.ArrayList;
22  import java.util.List;
23  import org.apache.syncope.client.ui.commons.markup.html.form.AjaxTextFieldPanel;
24  import org.apache.syncope.client.ui.commons.wicket.markup.html.bootstrap.tabs.Accordion;
25  import org.apache.syncope.common.lib.scim.SCIMConf;
26  import org.apache.syncope.common.lib.scim.SCIMEnterpriseUserConf;
27  import org.apache.syncope.common.lib.scim.SCIMManagerConf;
28  import org.apache.wicket.extensions.markup.html.tabs.AbstractTab;
29  import org.apache.wicket.markup.html.WebMarkupContainer;
30  import org.apache.wicket.markup.html.basic.Label;
31  import org.apache.wicket.model.Model;
32  import org.apache.wicket.model.PropertyModel;
33  import org.slf4j.Logger;
34  import org.slf4j.LoggerFactory;
35  
36  public class SCIMConfEnterpriseUserPanel extends SCIMConfTabPanel {
37  
38      protected static final Logger LOG = LoggerFactory.getLogger(SCIMConfEnterpriseUserPanel.class);
39  
40      private static final long serialVersionUID = -4183306437598820588L;
41  
42      private final SCIMEnterpriseUserConf scimEnterpriseUserConf;
43  
44      public SCIMConfEnterpriseUserPanel(final String id, final SCIMConf scimConf) {
45          super(id);
46  
47          if (scimConf.getEnterpriseUserConf() == null) {
48              scimConf.setEnterpriseUserConf(new SCIMEnterpriseUserConf());
49          }
50          if (scimConf.getEnterpriseUserConf().getManager() == null) {
51              scimConf.getEnterpriseUserConf().setManager(new SCIMManagerConf());
52          }
53          scimEnterpriseUserConf = scimConf.getEnterpriseUserConf();
54  
55          AjaxTextFieldPanel costCenterPanel =
56                  new AjaxTextFieldPanel("costCenter", "costCenter",
57                          new PropertyModel<>("costCenter", "costCenter") {
58  
59                      private static final long serialVersionUID = -6427731218492117883L;
60  
61                      @Override
62                      public String getObject() {
63                          return scimEnterpriseUserConf.getCostCenter();
64                      }
65  
66                      @Override
67                      public void setObject(final String object) {
68                          scimEnterpriseUserConf.setCostCenter(object);
69                      }
70                  });
71          costCenterPanel.setChoices(userPlainSchemas.getObject());
72  
73          AjaxTextFieldPanel departmentPanel =
74                  new AjaxTextFieldPanel("department", "department",
75                          new PropertyModel<>("department", "department") {
76  
77                      private static final long serialVersionUID = -6427731218492117883L;
78  
79                      @Override
80                      public String getObject() {
81                          return scimEnterpriseUserConf.getDepartment();
82                      }
83  
84                      @Override
85                      public void setObject(final String object) {
86                          scimEnterpriseUserConf.setDepartment(object);
87                      }
88                  });
89          departmentPanel.setChoices(userPlainSchemas.getObject());
90  
91          AjaxTextFieldPanel divisionPanel =
92                  new AjaxTextFieldPanel("division", "division",
93                          new PropertyModel<>("division", "division") {
94  
95                      private static final long serialVersionUID = -6427731218492117883L;
96  
97                      @Override
98                      public String getObject() {
99                          return scimEnterpriseUserConf.getDivision();
100                     }
101 
102                     @Override
103                     public void setObject(final String object) {
104                         scimEnterpriseUserConf.setDivision(object);
105                     }
106                 });
107         divisionPanel.setChoices(userPlainSchemas.getObject());
108 
109         AjaxTextFieldPanel employeeNumberPanel =
110                 new AjaxTextFieldPanel("employeeNumber", "employeeNumber",
111                         new PropertyModel<>("employeeNumber", "employeeNumber") {
112 
113                     private static final long serialVersionUID = -6427731218492117883L;
114 
115                     @Override
116                     public String getObject() {
117                         return scimEnterpriseUserConf.getEmployeeNumber();
118                     }
119 
120                     @Override
121                     public void setObject(final String object) {
122                         scimEnterpriseUserConf.setEmployeeNumber(object);
123                     }
124                 });
125         employeeNumberPanel.setChoices(userPlainSchemas.getObject());
126 
127         AjaxTextFieldPanel organizationPanel =
128                 new AjaxTextFieldPanel("organization", "organization",
129                         new PropertyModel<>("organization", "organization") {
130 
131                     private static final long serialVersionUID = -6427731218492117883L;
132 
133                     @Override
134                     public String getObject() {
135                         return scimEnterpriseUserConf.getOrganization();
136                     }
137 
138                     @Override
139                     public void setObject(final String object) {
140                         scimEnterpriseUserConf.setOrganization(object);
141                     }
142                 });
143         organizationPanel.setChoices(userPlainSchemas.getObject());
144 
145         // manager
146         buildManagerAccordion();
147 
148         add(costCenterPanel);
149         add(departmentPanel);
150         add(divisionPanel);
151         add(employeeNumberPanel);
152         add(organizationPanel);
153     }
154 
155     private void buildManagerAccordion() {
156         Accordion accordion = new Accordion("managerAccordion",
157                 List.of(new AbstractTab(Model.of("manager")) {
158 
159                     private static final long serialVersionUID = -5861786415855103549L;
160 
161                     @Override
162                     public WebMarkupContainer getPanel(final String panelId) {
163                         return buildNameAccordionContent(panelId);
164                     }
165 
166                 }), Model.of(-1)); // accordion closed at beginning
167         add(accordion.setOutputMarkupId(true));
168     }
169 
170     private SCIMConfAccordionContainer buildNameAccordionContent(final String panelId) {
171         List<AjaxTextFieldPanel> panelList = new ArrayList<>();
172 
173         AjaxTextFieldPanel managerKeyPanel =
174                 new AjaxTextFieldPanel("accordionContent", "manager.key",
175                         new PropertyModel<>(scimEnterpriseUserConf.getManager(), "accordionContent") {
176 
177                     private static final long serialVersionUID = -6427731218492117883L;
178 
179                     @Override
180                     public String getObject() {
181                         return scimEnterpriseUserConf.getManager().getKey();
182                     }
183 
184                     @Override
185                     public void setObject(final String object) {
186                         scimEnterpriseUserConf.getManager().setKey(object);
187                     }
188                 });
189         managerKeyPanel.setChoices(userPlainSchemas.getObject());
190 
191         AjaxTextFieldPanel managerDisplaNamePanel =
192                 new AjaxTextFieldPanel("accordionContent", "manager.displayName",
193                         new PropertyModel<>(scimEnterpriseUserConf.getManager(), "accordionContent") {
194 
195                     private static final long serialVersionUID = -6427731218492117883L;
196 
197                     @Override
198                     public String getObject() {
199                         return scimEnterpriseUserConf.getManager().getDisplayName();
200                     }
201 
202                     @Override
203                     public void setObject(final String object) {
204                         scimEnterpriseUserConf.getManager().setDisplayName(object);
205                     }
206                 });
207         managerDisplaNamePanel.setChoices(userPlainSchemas.getObject());
208 
209         panelList.add(managerKeyPanel);
210         panelList.add(managerDisplaNamePanel);
211 
212         add(new Label("managerLabel", Model.of("manager")));
213 
214         return new SCIMConfAccordionContainer(panelId, panelList);
215     }
216 }