View Javadoc
1   /*
2    * Copyright 2011 The Kuali Foundation
3    * 
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    * 
8    * http://www.opensource.org/licenses/ecl2.php
9    * 
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.kuali.ole.sys.batch;
17  
18  import java.util.ArrayList;
19  import java.util.List;
20  
21  import org.apache.log4j.Logger;
22  import org.kuali.rice.core.api.datetime.DateTimeService;
23  import org.kuali.rice.coreservice.framework.parameter.ParameterService;
24  import org.springframework.beans.factory.BeanNameAware;
25  import org.springframework.beans.factory.InitializingBean;
26  
27  public abstract class AbstractStep extends InitiateDirectoryBase implements Step, BeanNameAware, InitializingBean, InitiateDirectory{
28    
29      private static final Logger LOG = Logger.getLogger(AbstractStep.class);
30      
31      protected String name;
32      protected ParameterService parameterService;
33      protected DateTimeService dateTimeService;
34      protected BatchInputFileType batchInputFileType = null;
35      
36      protected boolean interrupted = false;
37  
38      /**
39       * Initialization  after bean properties are instantiate, 
40       * 
41       * @see org.springframework.beans.factory.InitializingBean#afterPropertiesSet()
42       */
43      @Override
44      public void afterPropertiesSet() throws Exception {
45          //prepare the directories by using the required directory list
46          prepareDirectories(getRequiredDirectoryNames());
47      }
48  
49      /**
50       * By default it should use batchInpeutFile (single file) directory path as the required directory name. 
51       * 
52       * Subclasses should override this function to provide any custom required directory list.
53       * 
54       * @see org.kuali.ole.sys.batch.service.InitiateDirectoryInterface#getRequiredDirectoryNames()
55       */
56      @Override
57      public List<String> getRequiredDirectoryNames() {
58          List<String> requiredDirectoryList = new ArrayList<String>();
59          if (batchInputFileType != null){
60              LOG.info(batchInputFileType.getClass().getName() + " ==> " + batchInputFileType.getDirectoryPath());
61              requiredDirectoryList.add(batchInputFileType.getDirectoryPath());
62          }
63          return requiredDirectoryList;
64      }
65  
66      /**
67       * Sets the bean name
68       * 
69       * @param name String that contains the bean name
70       * @see org.springframework.beans.factory.BeanNameAware#setBeanName(java.lang.String)
71       */
72      @Override
73      public void setBeanName(String name) {
74          this.name = name;
75      }
76  
77      /**
78       * Gets the name attribute.
79       * 
80       * @return Returns the name.
81       */
82      @Override
83      public String getName() {
84          return name;
85      }
86  
87      protected ParameterService getParameterService() {
88          return parameterService;
89      }
90  
91      public void setParameterService(ParameterService parameterService) {
92          this.parameterService = parameterService;
93      }
94  
95      /**
96       * Gets the dateTimeService attribute.
97       * 
98       * @return Returns the dateTimeService.
99       */
100     protected DateTimeService getDateTimeService() {
101         return dateTimeService;
102     }
103 
104     /**
105      * Sets the dateTimeService attribute value.
106      * 
107      * @param dateTimeService The dateTimeService to set.
108      */
109     public void setDateTimeService(DateTimeService dateTimeService) {
110         this.dateTimeService = dateTimeService;
111     }
112     
113     /**
114      * Returns the boolean value of the interrupted flag
115      * 
116      * @return boolean
117      * @see org.kuali.ole.sys.batch.Step#isInterrupted()
118      */
119     @Override
120     public boolean isInterrupted() {
121         return interrupted;
122     }
123 
124     public BatchInputFileType getBatchInputFileType() {
125         return batchInputFileType;
126     }
127 
128     public void setBatchInputFileType(BatchInputFileType batchInputFileType) {
129         this.batchInputFileType = batchInputFileType;
130     }
131     
132     
133     /**
134      * Sets the interruped flag
135      * 
136      * @param interrupted
137      * @see org.kuali.ole.sys.batch.Step#setInterrupted(boolean)
138      */
139     @Override
140     public void setInterrupted(boolean interrupted) {
141         this.interrupted = interrupted;
142     }
143 
144     /**
145      * Initializes the interrupted flag
146      * 
147      * @see org.kuali.ole.sys.batch.Step#interrupt()
148      */
149     @Override
150     public void interrupt() {
151         this.interrupted = true;
152     }
153 }