View Javadoc
1   /*
2    * The Kuali Financial System, a comprehensive financial management system for higher education.
3    * 
4    * Copyright 2005-2014 The Kuali Foundation
5    * 
6    * This program is free software: you can redistribute it and/or modify
7    * it under the terms of the GNU Affero General Public License as
8    * published by the Free Software Foundation, either version 3 of the
9    * License, or (at your option) any later version.
10   * 
11   * This program is distributed in the hope that it will be useful,
12   * but WITHOUT ANY WARRANTY; without even the implied warranty of
13   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14   * GNU Affero General Public License for more details.
15   * 
16   * You should have received a copy of the GNU Affero General Public License
17   * along with this program.  If not, see <http://www.gnu.org/licenses/>.
18   */
19  package org.kuali.kfs.sys.batch;
20  
21  import java.util.ArrayList;
22  import java.util.List;
23  
24  import org.apache.log4j.Logger;
25  import org.kuali.rice.core.api.datetime.DateTimeService;
26  import org.kuali.rice.coreservice.framework.parameter.ParameterService;
27  import org.springframework.beans.factory.BeanNameAware;
28  import org.springframework.beans.factory.InitializingBean;
29  
30  public abstract class AbstractStep extends InitiateDirectoryBase implements Step, BeanNameAware, InitializingBean, InitiateDirectory{
31  
32      private static final Logger LOG = Logger.getLogger(AbstractStep.class);
33  
34      protected String name;
35      protected ParameterService parameterService;
36      protected DateTimeService dateTimeService;
37      protected BatchInputFileType batchInputFileType = null;
38  
39      protected boolean interrupted = false;
40  
41      /**
42       * Initialization  after bean properties are instantiate,
43       *
44       * @see org.springframework.beans.factory.InitializingBean#afterPropertiesSet()
45       */
46      @Override
47      public void afterPropertiesSet() throws Exception {
48          //prepare the directories by using the required directory list
49          prepareDirectories(getRequiredDirectoryNames());
50      }
51  
52      /**
53       * By default it should use batchInpeutFile (single file) directory path as the required directory name.
54       *
55       * Subclasses should override this function to provide any custom required directory list.
56       *
57       * @see org.kuali.kfs.sys.batch.service.InitiateDirectoryInterface#getRequiredDirectoryNames()
58       */
59      @Override
60      public List<String> getRequiredDirectoryNames() {
61          List<String> requiredDirectoryList = new ArrayList<String>();
62          if (batchInputFileType != null){
63              LOG.info(batchInputFileType.getClass().getName() + " ==> " + batchInputFileType.getDirectoryPath());
64              requiredDirectoryList.add(batchInputFileType.getDirectoryPath());
65          }
66          return requiredDirectoryList;
67      }
68  
69      /**
70       * Sets the bean name
71       *
72       * @param name String that contains the bean name
73       * @see org.springframework.beans.factory.BeanNameAware#setBeanName(java.lang.String)
74       */
75      @Override
76      public void setBeanName(String name) {
77          this.name = name;
78      }
79  
80      /**
81       * Gets the name attribute.
82       *
83       * @return Returns the name.
84       */
85      @Override
86      public String getName() {
87          return name;
88      }
89  
90      protected ParameterService getParameterService() {
91          return parameterService;
92      }
93  
94      public void setParameterService(ParameterService parameterService) {
95          this.parameterService = parameterService;
96      }
97  
98      /**
99       * Gets the dateTimeService attribute.
100      *
101      * @return Returns the dateTimeService.
102      */
103     protected DateTimeService getDateTimeService() {
104         return dateTimeService;
105     }
106 
107     /**
108      * Sets the dateTimeService attribute value.
109      *
110      * @param dateTimeService The dateTimeService to set.
111      */
112     public void setDateTimeService(DateTimeService dateTimeService) {
113         this.dateTimeService = dateTimeService;
114     }
115 
116     /**
117      * Returns the boolean value of the interrupted flag
118      *
119      * @return boolean
120      * @see org.kuali.kfs.sys.batch.Step#isInterrupted()
121      */
122     @Override
123     public boolean isInterrupted() {
124         return interrupted;
125     }
126 
127     public BatchInputFileType getBatchInputFileType() {
128         return batchInputFileType;
129     }
130 
131     public void setBatchInputFileType(BatchInputFileType batchInputFileType) {
132         this.batchInputFileType = batchInputFileType;
133     }
134 
135 
136     /**
137      * Sets the interruped flag
138      *
139      * @param interrupted
140      * @see org.kuali.kfs.sys.batch.Step#setInterrupted(boolean)
141      */
142     @Override
143     public void setInterrupted(boolean interrupted) {
144         this.interrupted = interrupted;
145     }
146 
147     /**
148      * Initializes the interrupted flag
149      *
150      * @see org.kuali.kfs.sys.batch.Step#interrupt()
151      */
152     @Override
153     public void interrupt() {
154         this.interrupted = true;
155     }
156 }