001/* 
002 * Copyright (c) 2010 The Regents of the University of California.
003 * All rights reserved.
004 *
005 * '$Author: crawl $'
006 * '$Date: 2010-07-23 17:04:30 -0700 (Fri, 23 Jul 2010) $' 
007 * '$Revision: 25146 $'
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 org.kepler.objectmanager.repository.Repository;
032
033/**
034 * A class represents a schedule object.
035 * @author tao
036 *
037 */
038public class Schedule
039{
040  private static final String UNKNOWN = "unknown";
041  private String workflowJobName = null;
042  private String workflowId = null;
043  private String workflowName = null;
044  private String karLSID = null;
045  private String startTimeLabel = UNKNOWN;
046  private String startTime = null;
047  private String startTimeFormat = null;
048  private String startTimeZoneID = null;
049  private String endTimeLabel = UNKNOWN;
050  private String endTime = null;
051  private String endTimeFormat = null;
052  private String endTimeZoneID = null;
053 
054
055  private int interval = NEGTIVEONE;
056  private String intervalUnit = null;
057  private boolean enabled = true;
058  private WorkflowRunEngine workflowRunEngine = null;
059  private Repository workflowRunDestination = null;
060  private Repository workflowLocation = null;
061  public static final String HOUR = "hour";
062  public static final String DAY = "day";
063  public static final String WEEK = "week";
064  public static final String MONTH = "mon";
065  public static final int NEGTIVEONE = -1;
066  
067  
068  /**
069   * Get the label for display the start time. It is only for display
070   * @return the label of the start time.
071   */
072  public String getStartTimeLabel()
073  {
074    return this.startTimeLabel;
075  }
076  
077  /**
078   * Set the start time label for display
079   * @param startTimeLabel the label will be displayed.
080   */
081  public void setStartTimeLabel(String startTimeLabel)
082  {
083    this.startTimeLabel = startTimeLabel;
084  }
085  
086  /**
087   * Get the start time of the schedule
088   * @return the start time
089   */
090  public String getStartTime()
091  {
092    return startTime;
093  }
094  
095  /**
096   * Set the start time of the schedule
097   * @param startTime the start time of the schedule
098   */
099  public void setStartTime(String startTime)
100  {
101    this.startTime = startTime;
102  }
103  
104  /**
105   * Get the format of the start time string
106   * @return the format of start time string. It can be null.
107   */
108  public String getStartTimeFormat()
109  {
110    return this.startTimeFormat;
111  }
112
113  /**
114   * Set the format of start time string.
115   * @param startTimeFormat the specified foramt for the start time string
116   */
117  public void setStartTimeFormat(String startTimeFormat)
118  {
119    this.startTimeFormat = startTimeFormat;
120  }
121
122  /**
123   * Get the time zone id for the start time
124   * @return time zone id of the start time. It can be null
125   */
126  public String getStartTimeZoneID()
127  {
128    return this.startTimeZoneID;
129  }
130
131  /**
132   * Set the time zone id for the start time
133   * @param startTimeZoneID
134   */
135  public void setStartTimeZoneID(String startTimeZoneID)
136  {
137    this.startTimeZoneID = startTimeZoneID;
138  }
139  
140  
141  /**
142   * Get the label for display the end time. It is only for display
143   * @return the label
144   */
145  public String getEndTimeLabel()
146  {
147    return this.endTimeLabel;
148  }
149  
150  /**
151   * Set the label for end time.
152   * @param endTimeLabel
153   */
154  public void setEndTimeLabel(String endTimeLabel)
155  {
156    this.endTimeLabel = endTimeLabel;
157  }
158  /**
159   * Gets the end time of the schedule
160   * @return the end time
161   */
162  public String getEndTime()
163  {
164    return endTime;
165  }
166  
167  /**
168   * Set the end time of the schedule
169   * @param endTime the end time of the schedule
170   */
171  public void setEndTime(String endTime)
172  {
173    this.endTime = endTime;
174  }
175  
176  /**
177   * Get the format of the end time string  
178   * @return the format of the end time string. It can be null
179   */
180  public String getEndTimeFormat()
181  {
182    return this.endTimeFormat;
183  }
184
185  /**
186   * Set the format of the end time string
187   * @param endTimeFormat the format of the end time string.
188   */
189  public void setEndTimeFormat(String endTimeFormat)
190  {
191    this.endTimeFormat = endTimeFormat;
192  }
193
194  /**
195   * Get the time zone id of the end time
196   * @return the time zone id of the end time. It can be null
197   */
198  public String getEndTimeZoneID()
199  {
200    return this.endTimeZoneID;
201  }
202
203  /**
204   * Set the end time zone id.
205   * @param endTimeZoneID the time zone id of the end time.
206   */
207  public void setEndTimeZoneID(String endTimeZoneID)
208  {
209    this.endTimeZoneID = endTimeZoneID;
210  }
211  
212  /**
213   * Get the interval of the schedule
214   * @return the interval
215   */
216  public int getInterval()
217  {
218    return interval;
219  }
220  
221  /**
222   * Set the interval of the schedule
223   * @param interval of the schedule
224   */
225  public void setInterval(String interval) throws NumberFormatException
226  {
227    this.interval = Integer.parseInt(interval);
228  }
229  
230  /**
231   * Get the interval unit
232   * @return the unit of the interval
233   */
234  public String getIntervalUnit()
235  {
236    return intervalUnit;
237  }
238  
239  /**
240   * Set the interval unit
241   * @param intervalUnit the unit of the interval
242   */
243  public void setIntervalUnit(String intervalUnit) throws Exception
244  {
245    if(intervalUnit == null)
246    {
247      throw new Exception("The interval unit couldn't be null");
248    }
249    else if( !intervalUnit.endsWith(HOUR) && !intervalUnit.equals(DAY) && !intervalUnit.equals(WEEK) && !intervalUnit.equals(MONTH))
250    {
251      throw new Exception("The interval unit is "+intervalUnit+" but it should be the one of  \"hour\", \"day\", \"week\" or \"mon\"");
252    }
253    this.intervalUnit = intervalUnit;
254  }
255  
256  /**
257   * If the scheduler is enabled
258   * @return true if it is enabled
259   */
260  public boolean isEnabled()
261  {
262    return enabled;
263  }
264  
265  /**
266   * Set the status of the schedule
267   * @param enabled  true if it is enabled
268   */
269  public void setEnabled(boolean enabled)
270  {
271    this.enabled = enabled;
272  }
273
274  /**
275   * Get the workflow id associated with this schedule
276   * @return the id of the workflow (in slid format)
277   */
278  public String getWorkflowId()
279  {
280    return workflowId;
281  }
282
283  /**
284   * Set the workflwo id to this schedule
285   * @param workflowId
286   */
287  public void setWorkflowId(String workflowId)
288  {
289    this.workflowId = workflowId;
290  }
291
292  /**
293   * Get the workflow name associated with the schedule
294   * @return
295   */
296  public String getWorkflowName()
297  {
298    return workflowName;
299  }
300
301  /**
302   * Set workflow name to this schedule object
303   * @param workflowName
304   */
305  public void setWorkflowName(String workflowName)
306  {
307    this.workflowName = workflowName;
308  }
309
310  /**
311   * Get the kar id associated with the workflow schedule object
312   * @return kar file id in lsid format
313   */
314  public String getKarLSID()
315  {
316    return karLSID;
317  }
318
319  /**
320   * Set the kar file id
321   * @param karId id of the kar file in lsid format
322   */
323  public void setKarLSID(String karLSID)
324  {
325    this.karLSID = karLSID;
326  }
327  
328  /**
329   * If the schedule is valid
330   * @return true if workflowId, workflowName, karId, startTime, endTime and interval unit are not
331   * null and interval is greater than 0.
332   */
333  public boolean isValid()
334  {
335    if(workflowId != null && workflowName != null && karLSID != null && startTime != null && 
336        endTime != null && interval > 0 && intervalUnit != null && workflowJobName != null)
337    {
338      return true;
339    }
340    else
341    {
342      return false;
343    }
344  }
345
346  /**
347   * Get the workflow job name. This the key to identify a schedule
348   * @return
349   */
350  public String getWorkflowJobName()
351  {
352    return workflowJobName;
353  }
354
355  /**
356   * Set the workflow job name
357   * @param workflowJobName
358   */
359  public void setWorkflowJobName(String workflowJobName)
360  {
361    this.workflowJobName = workflowJobName;
362  }
363
364  /**
365   * Get the workflow run engine which will run the workflow
366   */
367  public WorkflowRunEngine getWorkflowRunEngine()
368  {
369    return workflowRunEngine;
370  }
371
372  /**
373   * Set the workflow run engine which will run the workflow
374   * @param workflowRunEngine
375   */
376  public void setWorkflowRunEngine(WorkflowRunEngine workflowRunEngine)
377  {
378    this.workflowRunEngine = workflowRunEngine;
379  }
380
381  /**
382   * Get the destination repository which will store the workflwo run
383   * @return
384   */
385  public Repository getWorkflowRunDestination()
386  {
387    return workflowRunDestination;
388  }
389
390  /**
391   * Set the destination repository which will store the workflow run
392   * @param workflowRunDestination
393   */
394  public void setWorkflowRunDestination(Repository workflowRunDestination)
395  {
396    this.workflowRunDestination = workflowRunDestination;
397  }
398
399  /**
400   * Get the workflow location repository
401   * @return
402   */
403  public Repository getWorkflowLocation()
404  {
405    return workflowLocation;
406  }
407
408  /**
409   * Set the workflow location repository
410   * @param workflowLocation
411   */
412  public void setWorkflowLocation(Repository workflowLocation)
413  {
414    this.workflowLocation = workflowLocation;
415  }
416
417}