001/*
002 * Copyright (c) 2010 The Regents of the University of California.
003 * All rights reserved.
004 *
005 * '$Author: welker $'
006 * '$Date: 2010-05-06 05:21:26 +0000 (Thu, 06 May 2010) $' 
007 * '$Revision: 24234 $'
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 */
029
030/* A class to receive provenance events. */
031
032/**
033 *  '$Author: welker $'
034 *  '$Date: 2010-05-06 05:21:26 +0000 (Thu, 06 May 2010) $'
035 *  '$Revision: 24234 $'
036 *
037 *  For Details:
038 *  http://www.kepler-project.org
039 *
040 *  Copyright (c) 2009-2010 The Regents of the
041 *  University of California. All rights reserved. Permission is hereby granted,
042 *  without written agreement and without license or royalty fees, to use, copy,
043 *  modify, and distribute this software and its documentation for any purpose,
044 *  provided that the above copyright notice and the following two paragraphs
045 *  appear in all copies of this software. IN NO EVENT SHALL THE UNIVERSITY OF
046 *  CALIFORNIA BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL,
047 *  OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS
048 *  DOCUMENTATION, EVEN IF THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF THE
049 *  POSSIBILITY OF SUCH DAMAGE. THE UNIVERSITY OF CALIFORNIA SPECIFICALLY
050 *  DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
051 *  WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE
052 *  SOFTWARE PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE UNIVERSITY OF
053 *  CALIFORNIA HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES,
054 *  ENHANCEMENTS, OR MODIFICATIONS.
055 */
056
057package org.kepler.workflowrunmanager;
058
059import org.kepler.objectmanager.lsid.KeplerLSID;
060import org.kepler.provenance.Recording;
061import org.kepler.provenance.RecordingException;
062import org.kepler.tagging.TagEvent;
063import org.kepler.util.WorkflowRenameListener;
064import org.kepler.util.WorkflowRun;
065
066import ptolemy.kernel.util.Nameable;
067import ptolemy.kernel.util.NamedObj;
068
069/**
070 * Receive provenance events and update the WorkflowRunManager GUI.
071 * 
072 * @author Daniel Crawl
073 * @version $Id: WorkflowRunManagerRecording.java 21468 2009-11-10 19:26:23Z
074 *          barseghian $
075 */
076
077public class WorkflowRunManagerRecording extends Recording {
078
079        /** Construct a new WorkflowRunManagerRecording. */
080        public WorkflowRunManagerRecording(WorkflowRunManager manager)
081                        throws RecordingException {
082                _workflowRunManager = manager;
083        }
084
085        /**
086         * A workflow was renamed.
087         * 
088         * @param namedObj
089         *            the workflow
090         * @param oldLSID
091         *            the previous LSID
092         * @param newLSID
093         *            the new lsid
094         * @param oldName
095         *            the previous name
096         * @param newName
097         *            the new name
098         * @see WorkflowRenameListener
099         */
100        public void renamedWorkflow(NamedObj namedObj, KeplerLSID oldLSID,
101                        KeplerLSID newLSID, String oldName, String newName) {
102                _workflowRunManager.fireWorkflowRunManagerEvent(WorkflowRunManagerEvent.WORKFLOW_RENAMED, oldLSID, true);
103        }
104
105        /** update WRM table to see a run as it's running. */
106        public void executionStart(KeplerLSID execLSID) {
107                _workflowRunManager.fireWorkflowRunManagerEvent(WorkflowRunManagerEvent.EXECUTION_START, execLSID, true);
108        }
109
110        /** update WRM table after an execution gives an error. */
111        public void executionError(Nameable source, Throwable throwable, KeplerLSID execLSID)
112                        throws RecordingException {
113                _workflowRunManager.fireWorkflowRunManagerEvent(WorkflowRunManagerEvent.EXECUTION_ERROR, execLSID, true);
114        }
115
116        /** update WRM table after an execution finishes. */
117        public void executionStop(KeplerLSID execLSID) {
118                _workflowRunManager.fireWorkflowRunManagerEvent(WorkflowRunManagerEvent.EXECUTION_STOP, execLSID, true);
119        }
120
121        /** update WRM table after an execution has been imported. */
122        public void executionImported(KeplerLSID execLSID) {
123                _workflowRunManager.fireWorkflowRunManagerEvent(WorkflowRunManagerEvent.EXECUTION_IMPORTED, execLSID, true);
124        }
125
126        /** update WRM table after a run tag has been added. */
127        public void tagAdded(TagEvent event) throws RecordingException {
128                NamedObj tagEventSource = event.getSource();
129                if (tagEventSource instanceof WorkflowRun) {
130                        WorkflowRun run = (WorkflowRun)tagEventSource;
131                        KeplerLSID lsid = run.getExecLSID();
132                        _workflowRunManager.fireWorkflowRunManagerEvent(WorkflowRunManagerEvent.TAG_ADDED, lsid, event.isLastEvent());
133                }
134        }
135
136        /** update WRM table after a run tag has been removed. */
137        public void tagRemoved(TagEvent event) throws RecordingException {
138                NamedObj tagEventSource = event.getSource();
139                if (tagEventSource instanceof WorkflowRun) {
140                        WorkflowRun run = (WorkflowRun)tagEventSource;
141                        KeplerLSID lsid = run.getExecLSID();
142                        _workflowRunManager.fireWorkflowRunManagerEvent(WorkflowRunManagerEvent.TAG_REMOVED, lsid, event.isLastEvent());
143                }
144        }
145
146        // ///////////////////////////////////////////////////////////////////////
147        // private variables
148
149        /** The WorkflowRunManager. */
150        private WorkflowRunManager _workflowRunManager;
151
152}