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 org.apache.syncope.client.console.SyncopeConsoleSession;
22  import org.apache.syncope.client.console.pages.BasePage;
23  import org.apache.syncope.client.console.rest.SecurityQuestionRestClient;
24  import org.apache.syncope.client.console.wicket.markup.html.bootstrap.dialog.BaseModal;
25  import org.apache.syncope.client.ui.commons.Constants;
26  import org.apache.syncope.common.lib.to.SecurityQuestionTO;
27  import org.apache.wicket.PageReference;
28  import org.apache.wicket.ajax.AjaxRequestTarget;
29  import org.apache.wicket.spring.injection.annot.SpringBean;
30  
31  public class SecurityQuestionsModalPanel extends AbstractModalPanel<SecurityQuestionTO> {
32  
33      private static final long serialVersionUID = 4024126489500665435L;
34  
35      @SpringBean
36      protected SecurityQuestionRestClient securityQuestionRestClient;
37  
38      protected final SecurityQuestionTO securityQuestionTO;
39  
40      public SecurityQuestionsModalPanel(
41              final BaseModal<SecurityQuestionTO> modal,
42              final SecurityQuestionTO securityQuestionTO,
43              final PageReference pageRef) {
44  
45          super(modal, pageRef);
46          this.securityQuestionTO = securityQuestionTO;
47          add(new SecurityQuestionDetailsPanel("securityQuestionDetailsPanel", getItem()));
48      }
49  
50      @Override
51      public final SecurityQuestionTO getItem() {
52          return this.securityQuestionTO;
53      }
54  
55      @Override
56      public void onSubmit(final AjaxRequestTarget target) {
57          try {
58              if (securityQuestionTO.getKey() == null) {
59                  securityQuestionRestClient.create(securityQuestionTO);
60              } else {
61                  securityQuestionRestClient.update(securityQuestionTO);
62              }
63  
64              SyncopeConsoleSession.get().success(getString(Constants.OPERATION_SUCCEEDED));
65              modal.close(target);
66          } catch (Exception e) {
67              LOG.error("While creating or updating {}", securityQuestionTO, e);
68              SyncopeConsoleSession.get().onException(e);
69          }
70          ((BasePage) pageRef.getPage()).getNotificationPanel().refresh(target);
71      }
72  }