001/*
002 * The Kuali Financial System, a comprehensive financial management system for higher education.
003 * 
004 * Copyright 2005-2014 The Kuali Foundation
005 * 
006 * This program is free software: you can redistribute it and/or modify
007 * it under the terms of the GNU Affero General Public License as
008 * published by the Free Software Foundation, either version 3 of the
009 * License, or (at your option) any later version.
010 * 
011 * This program is distributed in the hope that it will be useful,
012 * but WITHOUT ANY WARRANTY; without even the implied warranty of
013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
014 * GNU Affero General Public License for more details.
015 * 
016 * You should have received a copy of the GNU Affero General Public License
017 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
018 */
019package org.kuali.kfs.module.purap.batch;
020
021import java.util.Date;
022
023import org.kuali.kfs.module.purap.document.service.PurchaseOrderService;
024import org.kuali.kfs.sys.batch.AbstractStep;
025import org.kuali.kfs.sys.context.SpringContext;
026import org.kuali.rice.core.api.datetime.DateTimeService;
027
028/**
029 * Step used to auto approve purchase orders that meet a certain criteria
030 */
031public class AutoCloseRecurringOrdersStep extends AbstractStep {
032    private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(AutoCloseRecurringOrdersStep.class);
033    
034    private PurchaseOrderService purchaseOrderService;
035
036    public AutoCloseRecurringOrdersStep() {
037        super();
038    }
039
040    /**
041     * Calls service method to approve recurring purchase orders
042     * 
043     * @see org.kuali.kfs.sys.batch.Step#execute(String, Date)
044     */
045    public boolean execute(String jobName, Date jobRunDate) throws InterruptedException {
046        return purchaseOrderService.autoCloseRecurringOrders();
047    }
048
049    /**
050     * Invoke execute method
051     * 
052     * @return
053     * @throws InterruptedException
054     */
055    public boolean execute() throws InterruptedException {
056        try {
057            return execute(null, SpringContext.getBean(DateTimeService.class).getCurrentDate());
058        }
059        catch (InterruptedException e) {
060            LOG.error("Exception occured executing step", e);
061            throw e;
062        }
063        catch (RuntimeException e) {
064            LOG.error("Exception occured executing step", e);
065            throw e;
066        }
067    }
068
069    public void setPurchaseOrderService(PurchaseOrderService purchaseOrderService) {
070        this.purchaseOrderService = purchaseOrderService;
071    }
072
073
074
075}