001/**
002 * Copyright (c) 2010 The Regents of the University of California.
003 * All rights reserved.
004 *
005 * '$Author: tao $'
006 * '$Date: 2010-06-03 16:45:10 -0700 (Thu, 03 Jun 2010) $' 
007 * '$Revision: 24730 $'
008 * 
009 * Permission is hereby granted, without written agreement and without
010 * license or royalty fees, to use, copy, modify, and distribute this
011 * software and its documentation for any purpose, provided that the above
012 * copyright notice and the following two paragraphs appear in all copies
013 * of this software.
014 *
015 * IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY
016 * FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
017 * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF
018 * THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF
019 * SUCH DAMAGE.
020 *
021 * THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
022 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
023 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE
024 * PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE UNIVERSITY OF
025 * CALIFORNIA HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES,
026 * ENHANCEMENTS, OR MODIFICATIONS.
027 *
028 */
029package org.kepler.workflowscheduler.gui;
030
031import javax.swing.JOptionPane;
032
033import org.apache.commons.logging.Log;
034import org.apache.commons.logging.LogFactory;
035
036import edu.ucsb.nceas.schedulerclient.WorkflowSchedulerClient;
037import edu.ucsb.nceas.workflowscheduler.scheduler.WorkflowSchedulerException;
038import ptolemy.actor.gui.TableauFrame;
039
040/**
041 * Represents an action to remove a schedule from a scheduler server.
042 * @author tao
043 *
044 */
045public class RemoveScheduleAction extends SchedulerAbstractAction
046{
047  private static final Log log = LogFactory.getLog(RemoveScheduleAction.class
048      .getName());
049
050  /**
051   * Constructor
052   * @param parent the parent frame of this action
053   * @param scheduleChangeController the GUI controller to handle the schedule change.
054   */
055  public RemoveScheduleAction(TableauFrame parent, WorkflowSchedulerParentPanel schedulerParentPanel,
056                                                          ScheduleChangeController scheduleChangeController)
057  {
058    super(parent, schedulerParentPanel,scheduleChangeController);
059  }
060  
061  /**
062   *Remove a schedule from the scheduler server.
063   */
064  protected void doAction() throws Exception
065  {
066    super.doAction();
067    if(schedule != null)
068    {
069      String sessionID = null;
070      if(authenDomainForSourceKar != null)
071      {
072        sessionID = domainSessionHash.get(authenDomainForSourceKar);
073      }   
074      WorkflowSchedulerClient client = new WorkflowSchedulerClient(schedulerURL, sessionID, authenticationServiceURLForSourceKar);
075      try
076      {
077        //boolean success = client.deleteJob(schedule.getWorkflowJobName(), source.getAuthProtocol()+SLASHCONNECTOR+source.getRepository()+source.getAuthorizationPath());
078        boolean success = client.deleteJob(schedule.getWorkflowJobName());
079        if(!success)
080        {
081          JOptionPane.showMessageDialog(parent, "Failed to delete schedule.", ERROR, JOptionPane.ERROR_MESSAGE);
082        }
083        else
084        {  
085          // make the display change after deleting a schedule
086          if(scheduleChangeController != null)
087          {
088            try
089            {
090              scheduleChangeController.removeSchedule(schedule);
091            }
092            catch(Exception e)
093            {
094              log.error(""+e.getMessage());
095            }
096            
097          }        
098          JOptionPane.showMessageDialog(parent, "Successfully deleted schedule.", "Success", JOptionPane.CLOSED_OPTION);
099        }
100      }
101      catch(WorkflowSchedulerException e)
102      {
103        JOptionPane.showMessageDialog(parent, "Failed to delete schedule:\n"+e.getMessage(), ERROR, JOptionPane.ERROR_MESSAGE);
104        if(e != null && e.getMessage() != null && e.getMessage().indexOf("session" )!=-1 && e.getMessage().indexOf("is not valid")!=-1)
105        {
106          //sessionID = null;
107          domainSessionHash.remove(authenDomainForSourceKar);
108          JOptionPane.showMessageDialog(parent, "The login session id is invalid. Please click \"Delete\" menu item again to delete the schedule", "Info", JOptionPane.CLOSED_OPTION);
109        }
110      }
111    }
112    else
113    {
114      JOptionPane.showMessageDialog(parent, "Couldn't delete the schedule since the selected schedule object is null", ERROR, JOptionPane.ERROR_MESSAGE);
115    }
116    
117  }
118}