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.List;
22  import org.apache.syncope.client.console.SyncopeConsoleSession;
23  import org.apache.syncope.client.console.commons.AMConstants;
24  import org.apache.syncope.client.console.rest.WAConfigRestClient;
25  import org.apache.syncope.client.console.wicket.markup.html.form.ActionLink;
26  import org.apache.syncope.client.console.wicket.markup.html.form.ActionsPanel;
27  import org.apache.syncope.client.ui.commons.Constants;
28  import org.apache.syncope.client.ui.commons.pages.BaseWebPage;
29  import org.apache.syncope.client.ui.commons.panels.WizardModalPanel;
30  import org.apache.syncope.client.ui.commons.wizards.AbstractModalPanelBuilder;
31  import org.apache.syncope.client.ui.commons.wizards.AjaxWizard;
32  import org.apache.syncope.common.lib.Attr;
33  import org.apache.syncope.common.lib.types.AMEntitlement;
34  import org.apache.wicket.PageReference;
35  import org.apache.wicket.ajax.AjaxRequestTarget;
36  import org.apache.wicket.model.IModel;
37  import org.apache.wicket.model.StringResourceModel;
38  
39  public class WAConfigDirectoryPanel extends AttrListDirectoryPanel {
40  
41      private static final long serialVersionUID = 1538796157345L;
42  
43      public WAConfigDirectoryPanel(final String id, final WAConfigRestClient restClient, final PageReference pageRef) {
44          super(id, restClient, pageRef, true);
45  
46          this.addNewItemPanelBuilder(new AbstractModalPanelBuilder<Attr>(new Attr(), pageRef) {
47  
48              private static final long serialVersionUID = 1995192603527154740L;
49  
50              @Override
51              public WizardModalPanel<Attr> build(final String id, final int index, final AjaxWizard.Mode mode) {
52                  return new WAConfigModalPanel(modal, newModelObject(), mode, pageRef);
53              }
54          }, true);
55  
56          initResultTable();
57      }
58  
59      @Override
60      protected WAConfigProvider dataProvider() {
61          return new WAConfigProvider(rows);
62      }
63  
64      @Override
65      protected String paginatorRowsKey() {
66          return AMConstants.PREF_WACONFIG_PAGINATOR_ROWS;
67      }
68  
69      @Override
70      public ActionsPanel<Attr> getActions(final IModel<Attr> model) {
71          ActionsPanel<Attr> panel = super.getActions(model);
72  
73          panel.add(new ActionLink<>() {
74  
75              private static final long serialVersionUID = -3722207913631435501L;
76  
77              @Override
78              public void onClick(final AjaxRequestTarget target, final Attr ignore) {
79                  target.add(modal);
80                  modal.header(new StringResourceModel("any.edit"));
81                  modal.setContent(new WAConfigModalPanel(modal, model.getObject(), AjaxWizard.Mode.EDIT, pageRef));
82                  modal.show(true);
83              }
84          }, ActionLink.ActionType.EDIT, AMEntitlement.WA_CONFIG_SET);
85  
86          panel.add(new ActionLink<>() {
87  
88              private static final long serialVersionUID = -3722207913631435501L;
89  
90              @Override
91              public void onClick(final AjaxRequestTarget target, final Attr ignore) {
92                  try {
93                      ((WAConfigRestClient) restClient).delete(model.getObject().getSchema());
94  
95                      SyncopeConsoleSession.get().success(getString(Constants.OPERATION_SUCCEEDED));
96                      target.add(container);
97                  } catch (Exception e) {
98                      LOG.error("While deleting {}", model.getObject().getSchema(), e);
99                      SyncopeConsoleSession.get().onException(e);
100                 }
101                 ((BaseWebPage) pageRef.getPage()).getNotificationPanel().refresh(target);
102             }
103         }, ActionLink.ActionType.DELETE, AMEntitlement.WA_CONFIG_DELETE, true);
104 
105         return panel;
106     }
107 
108     protected final class WAConfigProvider extends AttrListProvider {
109 
110         private static final long serialVersionUID = -185944053385660794L;
111 
112         private WAConfigProvider(final int paginatorRows) {
113             super(paginatorRows);
114         }
115 
116         @Override
117         protected List<Attr> list() {
118             return ((WAConfigRestClient) restClient).list();
119         }
120     }
121 }