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
017 package org.kuali.kfs.module.purap.document.service.impl;
018
019 import java.util.Collection;
020 import java.util.Iterator;
021
022 import org.kuali.kfs.module.purap.PurapConstants;
023 import org.kuali.kfs.module.purap.document.PurchaseOrderDocument;
024 import org.kuali.kfs.module.purap.document.service.FaxBatchDocumentsService;
025 import org.kuali.kfs.module.purap.document.service.FaxService;
026 import org.kuali.kfs.module.purap.document.service.PurapService;
027 import org.kuali.kfs.module.purap.document.service.PurchaseOrderService;
028 import org.kuali.kfs.sys.context.SpringContext;
029 import org.kuali.rice.kew.exception.WorkflowException;
030 import org.kuali.rice.kns.service.DateTimeService;
031 import org.kuali.rice.kns.service.DocumentService;
032 import org.kuali.rice.kns.util.GlobalVariables;
033
034 public class FaxBatchDocumentsServiceImpl implements FaxBatchDocumentsService {
035 private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(FaxBatchDocumentsServiceImpl.class);
036
037 private PurchaseOrderService purchaseOrderService;
038 private FaxService faxService;
039 private PurapService purapService;
040 private DateTimeService dateTimeService;
041
042 /**
043 * Faxes pending documents. Currently only PO documents set to Pending Fax
044 * Status inside workflow.
045 *
046 * @return Collection of ServiceError objects
047 */
048 public boolean faxPendingPurchaseOrders() {
049
050 Collection<PurchaseOrderDocument> pendingPOs = purchaseOrderService.getPendingPurchaseOrderFaxes();
051 boolean result = true;
052
053 for (Iterator<PurchaseOrderDocument> iter = pendingPOs.iterator(); iter.hasNext();) {
054
055 PurchaseOrderDocument po = iter.next();
056
057 if (!po.getDocumentHeader().hasWorkflowDocument()){
058 try {
059 po = (PurchaseOrderDocument)SpringContext.getBean(DocumentService.class).getByDocumentHeaderId(po.getDocumentNumber());
060 }
061 catch (WorkflowException e) {
062 throw new RuntimeException(e);
063 }
064 }
065
066 GlobalVariables.getMessageMap().clear();
067 faxService.faxPurchaseOrderPdf(po,false);
068
069 if (GlobalVariables.getMessageMap().isEmpty()){
070 po.setStatusCode(PurapConstants.PurchaseOrderStatuses.OPEN);
071 po.setPurchaseOrderInitialOpenTimestamp(dateTimeService.getCurrentTimestamp());
072 po.setPurchaseOrderLastTransmitTimestamp(dateTimeService.getCurrentTimestamp());
073 purapService.saveDocumentNoValidation(po);
074 }else{
075 result = false;
076 }
077 }
078
079 return result;
080 }
081
082 public void setPurchaseOrderService(PurchaseOrderService purchaseOrderService) {
083 this.purchaseOrderService = purchaseOrderService;
084 }
085
086 public void setFaxService(FaxService faxService) {
087 this.faxService = faxService;
088 }
089
090 public void setPurapService(PurapService purapService) {
091 this.purapService = purapService;
092 }
093
094 public void setDateTimeService(DateTimeService dateTimeService) {
095 this.dateTimeService = dateTimeService;
096 }
097
098 }