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.notifications;
20  
21  import org.apache.commons.lang3.tuple.Pair;
22  import org.apache.syncope.client.console.panels.MultilevelPanel;
23  import org.apache.syncope.client.console.rest.TaskRestClient;
24  import org.apache.syncope.client.console.tasks.NotificationMailBodyDetails;
25  import org.apache.syncope.client.console.tasks.NotificationTaskDirectoryPanel;
26  import org.apache.syncope.client.console.tasks.TaskExecutionDetails;
27  import org.apache.syncope.client.console.wicket.markup.html.bootstrap.dialog.BaseModal;
28  import org.apache.syncope.client.ui.commons.panels.ModalPanel;
29  import org.apache.syncope.common.lib.to.NotificationTaskTO;
30  import org.apache.syncope.common.lib.types.AnyTypeKind;
31  import org.apache.syncope.common.lib.types.MailTemplateFormat;
32  import org.apache.wicket.PageReference;
33  import org.apache.wicket.ajax.AjaxRequestTarget;
34  import org.apache.wicket.markup.html.panel.Panel;
35  import org.apache.wicket.model.Model;
36  import org.apache.wicket.model.StringResourceModel;
37  import org.apache.wicket.spring.injection.annot.SpringBean;
38  
39  public class NotificationTasks extends Panel implements ModalPanel {
40  
41      private static final long serialVersionUID = 1066124171682570083L;
42  
43      @SpringBean
44      protected TaskRestClient taskRestClient;
45  
46      public NotificationTasks(
47              final AnyTypeKind anyTypeKind,
48              final String entityKey,
49              final PageReference pageReference) {
50  
51          this(null, anyTypeKind, entityKey, pageReference);
52      }
53  
54      public NotificationTasks(
55              final String notification,
56              final PageReference pageReference) {
57          this(notification, null, null, pageReference);
58      }
59  
60      private NotificationTasks(
61              final String notification,
62              final AnyTypeKind anyTypeKind,
63              final String entityKey,
64              final PageReference pageRef) {
65          super(BaseModal.CONTENT_ID);
66  
67          final MultilevelPanel mlp = new MultilevelPanel("tasks");
68          add(mlp);
69  
70          mlp.setFirstLevel(
71                  new NotificationTaskDirectoryPanel(taskRestClient, notification, anyTypeKind, entityKey, mlp, pageRef) {
72  
73              private static final long serialVersionUID = -2195387360323687302L;
74  
75              @Override
76              protected void viewTaskExecs(final NotificationTaskTO taskTO, final AjaxRequestTarget target) {
77                  mlp.next(
78                          new StringResourceModel("task.view", this, new Model<>(Pair.of(null, taskTO))).getObject(),
79                          new TaskExecutionDetails<>(taskTO, pageRef), target);
80              }
81  
82              @Override
83              protected void viewMailBody(
84                      final MailTemplateFormat format, final String content, final AjaxRequestTarget target) {
85  
86                  mlp.next(
87                          new StringResourceModel("content", this).setParameters(format.name()).getObject(),
88                          new NotificationMailBodyDetails(content), target);
89              }
90          });
91      }
92  }