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.tasks;
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.panels.StartAtTogglePanel;
24  import org.apache.syncope.client.console.rest.TaskRestClient;
25  import org.apache.syncope.client.ui.commons.Constants;
26  import org.apache.syncope.common.lib.SyncopeClientException;
27  import org.apache.wicket.PageReference;
28  import org.apache.wicket.ajax.AjaxRequestTarget;
29  import org.apache.wicket.ajax.markup.html.form.AjaxSubmitLink;
30  import org.apache.wicket.markup.html.WebMarkupContainer;
31  import org.apache.wicket.spring.injection.annot.SpringBean;
32  
33  public class TaskStartAtTogglePanel extends StartAtTogglePanel {
34  
35      private static final long serialVersionUID = -3195479265440591519L;
36  
37      @SpringBean
38      protected TaskRestClient taskRestClient;
39  
40      public TaskStartAtTogglePanel(final WebMarkupContainer container, final PageReference pageRef) {
41          super(container, pageRef);
42  
43          form.add(new AjaxSubmitLink("dryRun", form) {
44  
45              private static final long serialVersionUID = -7978723352517770644L;
46  
47              @Override
48              protected void onSubmit(final AjaxRequestTarget target) {
49                  try {
50                      taskRestClient.startExecution(key, startAtDateModel.getObject(), true);
51                      SyncopeConsoleSession.get().success(getString(Constants.OPERATION_SUCCEEDED));
52                      toggle(target, false);
53                      target.add(container);
54                  } catch (SyncopeClientException e) {
55                      SyncopeConsoleSession.get().onException(e);
56                      LOG.error("While running task {}", key, e);
57                  }
58                  ((BasePage) pageRef.getPage()).getNotificationPanel().refresh(target);
59              }
60  
61              @Override
62              protected void onError(final AjaxRequestTarget target) {
63                  ((BasePage) pageRef.getPage()).getNotificationPanel().refresh(target);
64              }
65          });
66      }
67  
68      @Override
69      protected TaskRestClient getRestClient() {
70          return taskRestClient;
71      }
72  }