View Javadoc
1   /*
2    * Licensed to The Apereo Foundation under one or more contributor license
3    * agreements. See the NOTICE file distributed with this work for additional
4    * information regarding copyright ownership.
5    *
6    *
7    * The Apereo Foundation licenses this file to you under the Educational
8    * Community License, Version 2.0 (the "License"); you may not use this file
9    * except in compliance with the License. You may obtain a copy of the License
10   * at:
11   *
12   *   http://opensource.org/licenses/ecl2.txt
13   *
14   * Unless required by applicable law or agreed to in writing, software
15   * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
16   * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
17   * License for the specific language governing permissions and limitations under
18   * the License.
19   *
20   */
21  
22  package org.opencastproject.workflow.api;
23  
24  import org.opencastproject.util.NotFoundException;
25  
26  import java.util.Date;
27  import java.util.List;
28  
29  /**
30   * API that defines persistent storage of workflows
31   *
32   */
33  public interface WorkflowServiceDatabase {
34  
35    /**
36     * Gets a single workflow by its identifier.
37     *
38     * @param workflowId
39     *          the series identifier
40     * @return the {@link WorkflowInstance} for this workflow
41     * @throws NotFoundException
42     *           if there is no workflow with this identifier
43     * @throws WorkflowDatabaseException
44     *           if there is a problem communicating with the underlying data store
45     */
46    WorkflowInstance getWorkflow(long workflowId) throws NotFoundException, WorkflowDatabaseException;
47  
48    /**
49     * Gets a single workflow by its identifier
50     *
51     * @param workflowId
52     *          the series identifier
53     * @return the {@link WorkflowInstance} for this workflow
54     * @throws NotFoundException
55     *           if there is no workflow with this identifier
56     * @throws WorkflowDatabaseException
57     *           if there is a problem communicating with the underlying data store
58     */
59    WorkflowInstance getWorkflow(long workflowId, String orgId) throws NotFoundException, WorkflowDatabaseException;
60  
61    /**
62     * Gets workflow instances for current organization.
63     *
64     * @param limit
65     *          max number of workflows to be returned
66     * @param offset
67     *          only return workflows from this point onwards
68     * @return list of all {@link WorkflowInstance}s
69     * @throws WorkflowDatabaseException
70     *           if there is a problem communicating with the underlying data store
71     */
72    List<WorkflowInstance> getWorkflowInstances(int limit, int offset) throws WorkflowDatabaseException;
73  
74    /**
75     * Gets all workflow instances previous to the specified date
76     *
77     * @param state Only returns workflows currently in the given state
78     * @param dateCreated Only returns workflows created prior to the given date
79     * @return list of the {@link WorkflowInstance}s
80     * @throws WorkflowDatabaseException
81     */
82    List<WorkflowInstance> getWorkflowInstancesForCleanup(WorkflowInstance.WorkflowState state, Date dateCreated)
83            throws WorkflowDatabaseException;
84  
85    /**
86     * Gets the amount of workflow instances.
87     *
88     * @param state Only counts workflows currently in the given state
89     * @return Amount of workflow instances
90     * @throws WorkflowDatabaseException
91     */
92    long countWorkflows(WorkflowInstance.WorkflowState state) throws WorkflowDatabaseException;
93  
94    /**
95     * Gets workflow index data for all events.
96     * Selects only workflow id, state, mediapackage id and organization id
97     *
98     * @param limit
99     *          max number of data objects to be returned
100    * @param offset
101    *          only return data from this point onwards
102    * @return list of {@link WorkflowIndexData}s
103    * @throws WorkflowDatabaseException
104    *           if there is a problem communicating with the underlying data store
105    */
106   List<WorkflowIndexData> getWorkflowIndexData(int limit, int offset) throws WorkflowDatabaseException;
107 
108   /**
109    * Returns the number of events workflows have been run on.
110    *
111    * @return the number of latest workflows
112    * @throws WorkflowDatabaseException
113    *           if there is a problem communicating with the underlying data store
114    */
115   int countMediaPackages() throws WorkflowDatabaseException;
116 
117   /**
118    * Gets all workflow instances for a mediapackage.
119    *
120    * @param mediaPackageId
121    *          the media package id
122    * @return list of all {@link WorkflowInstance}s for the given mediapackage id
123    * @throws WorkflowDatabaseException
124    *           if there is a problem communicating with the underlying data store
125    */
126   List<WorkflowInstance> getWorkflowInstancesByMediaPackage(String mediaPackageId) throws WorkflowDatabaseException;
127 
128   /**
129    * Gets all workflow instances that are currently running on the mediapackage.
130    *
131    * @param mediaPackageId
132    *          the mediapackage id
133    * @return list of all {@link WorkflowInstance}s for the given mediapackage id
134    * @throws WorkflowDatabaseException
135    *           if there is a problem communicating with the underlying data store
136    */
137   List<WorkflowInstance> getRunningWorkflowInstancesByMediaPackage(String mediaPackageId) throws WorkflowDatabaseException;
138 
139   /**
140    * Returns true if the media package with the given identifier currently has a workflow running on it.
141    *
142    * @param mediaPackageId
143    *          the media package identifier
144    * @return true, if a workflow is running; false otherwise
145    * @throws WorkflowDatabaseException
146    *           if there is a problem communicating with the underlying data store
147    */
148   boolean mediaPackageHasActiveWorkflows(String mediaPackageId) throws WorkflowDatabaseException;
149 
150   /**
151    * Returns true there are still workflows running that were created by the user with the given identifier.
152    *
153    * @param userId
154    *          the user identifier
155    * @return true, if a workflow is running; false otherwise
156    * @throws WorkflowDatabaseException
157    *           if there is a problem communicating with the underlying data store
158    */
159   boolean userHasActiveWorkflows(String userId) throws WorkflowDatabaseException;
160 
161   /**
162    * Updates a single workflow.
163    *
164    * @param instance
165    *          the workflow instance
166    * @throws WorkflowDatabaseException
167    *           if there is a problem communicating with the underlying data store
168    */
169   void updateInDatabase(WorkflowInstance instance) throws WorkflowDatabaseException;
170 
171   /**
172    * Removes a single workflow.
173    *
174    * @param instance
175    *          the workflow instance
176    * @throws WorkflowDatabaseException
177    *           if there is a problem communicating with the underlying data store
178    */
179   void removeFromDatabase(WorkflowInstance instance) throws WorkflowDatabaseException;
180 }