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.policies;
20  
21  import java.util.List;
22  import org.apache.syncope.client.console.rest.PolicyRestClient;
23  import org.apache.syncope.client.console.wicket.markup.html.form.ActionLink;
24  import org.apache.syncope.client.console.wicket.markup.html.form.ActionsPanel;
25  import org.apache.syncope.common.lib.policy.PushPolicyTO;
26  import org.apache.syncope.common.lib.types.IdRepoEntitlement;
27  import org.apache.syncope.common.lib.types.PolicyType;
28  import org.apache.wicket.PageReference;
29  import org.apache.wicket.ajax.AjaxRequestTarget;
30  import org.apache.wicket.authroles.authorization.strategies.role.metadata.MetaDataRoleAuthorizationStrategy;
31  import org.apache.wicket.extensions.markup.html.repeater.data.table.IColumn;
32  import org.apache.wicket.extensions.markup.html.repeater.data.table.PropertyColumn;
33  import org.apache.wicket.model.IModel;
34  import org.apache.wicket.model.Model;
35  import org.apache.wicket.model.StringResourceModel;
36  
37  /**
38   * Push policies page.
39   */
40  public class PushPolicyDirectoryPanel extends PolicyDirectoryPanel<PushPolicyTO> {
41  
42      private static final long serialVersionUID = 4984337552918213290L;
43  
44      public PushPolicyDirectoryPanel(final String id, final PolicyRestClient restClient, final PageReference pageRef) {
45          super(id, restClient, PolicyType.PUSH, pageRef);
46  
47          this.addNewItemPanelBuilder(
48                  new PolicyModalPanelBuilder<>(PolicyType.PUSH, new PushPolicyTO(), modal, restClient, pageRef), true);
49          MetaDataRoleAuthorizationStrategy.authorize(addAjaxLink, RENDER, IdRepoEntitlement.POLICY_CREATE);
50  
51          initResultTable();
52      }
53  
54      @Override
55      protected void addCustomColumnFields(final List<IColumn<PushPolicyTO, String>> columns) {
56          columns.add(new PropertyColumn<>(new StringResourceModel(
57                  "conflictResolutionAction", this), "conflictResolutionAction", "conflictResolutionAction"));
58      }
59  
60      @Override
61      protected void addCustomActions(final ActionsPanel<PushPolicyTO> panel, final IModel<PushPolicyTO> model) {
62          panel.add(new ActionLink<>() {
63  
64              private static final long serialVersionUID = -3722207913631435501L;
65  
66              @Override
67              public void onClick(final AjaxRequestTarget target, final PushPolicyTO ignore) {
68                  target.add(policySpecModal.setContent(
69                          new ProvisioningPolicyModalPanel(model.getObject(), policySpecModal, pageRef)));
70  
71                  policySpecModal.header(new StringResourceModel(
72                          "policy.rules", PushPolicyDirectoryPanel.this, Model.of(model.getObject())));
73  
74                  MetaDataRoleAuthorizationStrategy.authorize(
75                          policySpecModal.getForm(), ENABLE, IdRepoEntitlement.POLICY_UPDATE);
76  
77                  policySpecModal.show(true);
78              }
79          }, ActionLink.ActionType.COMPOSE, IdRepoEntitlement.POLICY_UPDATE);
80      }
81  }