001    /*
002     * Copyright 2011 The Kuali Foundation.
003     * 
004     * Licensed under the Educational Community License, Version 2.0 (the "License");
005     * you may not use this file except in compliance with the License.
006     * You may obtain a copy of the License at
007     * 
008     * http://www.opensource.org/licenses/ecl2.php
009     * 
010     * Unless required by applicable law or agreed to in writing, software
011     * distributed under the License is distributed on an "AS IS" BASIS,
012     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013     * See the License for the specific language governing permissions and
014     * limitations under the License.
015     */
016    package org.kuali.kfs.sys.batch;
017    
018    import java.util.ArrayList;
019    import java.util.HashMap;
020    import java.util.List;
021    import java.util.Map;
022    
023    import org.kuali.kfs.sys.batch.service.SchedulerService;
024    import org.quartz.JobDetail;
025    import org.springframework.beans.factory.BeanNameAware;
026    
027    public class JobDescriptor implements BeanNameAware {
028        private String name;
029        private String namespaceCode;
030        private String group;
031        private Map<String, String> dependencies;
032        private List<Step> steps;
033        private SchedulerService schedulerService;
034        private boolean durable = true;
035    
036        public JobDescriptor() {
037            dependencies = new HashMap();
038            steps = new ArrayList();
039        }
040    
041        public JobDescriptor(String name, String group, Step step, boolean durable) {
042            this();
043            this.name = name;
044            this.group = group;
045            this.durable = durable;
046            steps.add(step);
047        }
048    
049        /**
050         * @see org.springframework.beans.factory.BeanNameAware#setBeanName(java.lang.String)
051         */
052        public void setBeanName(String name) {
053            this.name = name;
054        }
055    
056        /**
057         * Constructs a non-volatile, durable, non-recoverable JobDetail w/ org.kuali.kfs.sys.batch.Job as the job class and the specified
058         * name and group from this instance. Also adds status=Pending to the JobDataMap, if this is a scheduled job.
059         * 
060         * @return the org.quartz.JobDetail corresponding to this instance
061         */
062        public JobDetail getJobDetail() {
063            return new JobDetail(name, group, Job.class, false, durable, false);
064        }
065    
066        /**
067         * Sets the group attribute value.
068         * 
069         * @param group The group to set.
070         */
071        public void setGroup(String group) {
072            this.group = group;
073        }
074    
075        /**
076         * Sets the dependencies attribute value.
077         * 
078         * @param dependencies The dependencies to set.
079         */
080        public void setDependencies(Map<String, String> dependencies) {
081            this.dependencies = dependencies;
082        }
083    
084        /**
085         * Gets the dependencies attribute.
086         * 
087         * @return Returns the dependencies.
088         */
089        public Map<String, String> getDependencies() {
090            return dependencies;
091        }
092    
093        /**
094         * Sets the steps attribute value.
095         * 
096         * @param steps The steps to set.
097         */
098        public void setSteps(List<Step> steps) {
099            this.steps = steps;
100        }
101    
102        /**
103         * Gets the steps attribute.
104         * 
105         * @return Returns the steps.
106         */
107        public List<Step> getSteps() {
108            return steps;
109        }
110    
111        /**
112         * Sets the schedulerService attribute value.
113         * 
114         * @param schedulerService The schedulerService to set.
115         */
116        public void setSchedulerService(SchedulerService schedulerService) {
117            this.schedulerService = schedulerService;
118        }
119    
120        public String getGroup() {
121            return group;
122        }
123    
124        public String getName() {
125            return name;
126        }
127    
128        public SchedulerService getSchedulerService() {
129            return schedulerService;
130        }
131    
132        public boolean isDurable() {
133            return durable;
134        }
135    
136        public void setDurable(boolean durable) {
137            this.durable = durable;
138        }
139    
140        /**
141         * Gets the namespaceCode attribute. 
142         * @return Returns the namespaceCode.
143         */
144        public String getNamespaceCode() {
145            return namespaceCode;
146        }
147    
148        /**
149         * Sets the namespaceCode attribute value.
150         * @param namespaceCode The namespaceCode to set.
151         */
152        public void setNamespaceCode(String namespaceCode) {
153            this.namespaceCode = namespaceCode;
154        }
155    
156    }