001/*
002 * Copyright 2012 The Kuali Foundation.
003 *
004 * Licensed under the Educational Community License, Version 1.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/ecl1.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 */
016package org.kuali.ole.select.service.impl;
017
018import org.kuali.ole.OleEditorResponseHandler;
019import org.kuali.ole.OleOrderRecordHandler;
020import org.kuali.ole.OleOrderRecords;
021import org.kuali.ole.batch.bo.OLEBatchProcessJobDetailsBo;
022import org.kuali.ole.pojo.OleEditorResponse;
023import org.kuali.ole.select.businessobject.OleDocstoreResponse;
024import org.kuali.ole.select.businessobject.OlePaymentMethod;
025import org.kuali.ole.select.service.OleExposedWebService;
026import org.kuali.ole.select.service.OleReqPOLoadTransactionsService;
027import org.kuali.ole.sys.context.SpringContext;
028import org.kuali.rice.krad.service.BusinessObjectService;
029
030import java.util.HashMap;
031import java.util.List;
032
033public class OleExposedWebServiceImpl implements OleExposedWebService {
034
035    private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(OleExposedWebService.class);
036    private OleReqPOLoadTransactionsService oleReqPOLoadTransactionsService;
037
038    @Override
039    public void createReqAndPO(String oleOrderRecordXMLContent, OLEBatchProcessJobDetailsBo job) {
040        try {
041            OleOrderRecordHandler oleOrderRecordHandler = new OleOrderRecordHandler();
042            if (LOG.isDebugEnabled()) {
043                LOG.debug("oleOrderRecordXMLContent----------->" + oleOrderRecordXMLContent);
044            }
045            OleOrderRecords oleOrderRecords = oleOrderRecordHandler.fromXML(oleOrderRecordXMLContent);
046            OleReqPOLoadTransactionsService oleReqPOLoadTransactionsService = getOleReqPOLoadTransactionsService();
047            List reqList = oleReqPOLoadTransactionsService.saveRequisitionDocument(oleOrderRecords, job);
048            oleReqPOLoadTransactionsService.createAcquisitionDocument(reqList, oleOrderRecords, job);
049        } catch (Exception e) {
050            LOG.error("Exception while creating Req & PO"+e.getMessage());
051            throw new RuntimeException(e);
052        }
053    }
054
055    public OleReqPOLoadTransactionsService getOleReqPOLoadTransactionsService() {
056        return oleReqPOLoadTransactionsService;
057    }
058
059    public void setOleReqPOLoadTransactionsService(OleReqPOLoadTransactionsService oleReqPOLoadTransactionsService) {
060        this.oleReqPOLoadTransactionsService = oleReqPOLoadTransactionsService;
061    }
062
063    @Override
064    public void addDoctoreResponse(String docstoreResponse) {
065        HashMap<String, OleEditorResponse> docstoreResponses = new HashMap<String, OleEditorResponse>();
066        OleEditorResponseHandler oleEditorResponseHandler = new OleEditorResponseHandler();
067        OleEditorResponse oleEditorResponse = oleEditorResponseHandler.fromXML(docstoreResponse);
068        docstoreResponses.put(oleEditorResponse.getTokenId(), oleEditorResponse);
069
070        OleDocstoreResponse.getInstance().setDocstoreResponse(docstoreResponses);
071        if (LOG.isDebugEnabled()) {
072            LOG.debug("#########OleDocstoreResponse##########" + OleDocstoreResponse.getInstance().getDocstoreResponse().toString());
073        }
074    }
075
076    @Override
077    public String getPaymentMethod() {
078
079        StringBuffer paymentMethodbuffer = new StringBuffer();
080        BusinessObjectService businessObjectService = SpringContext.getBean(BusinessObjectService.class);
081        List<OlePaymentMethod> olePaymentMethods = (List<OlePaymentMethod>) businessObjectService.findAll(OlePaymentMethod.class);
082        if (olePaymentMethods != null && olePaymentMethods.size() > 0) {
083            for (int i = 0; i < olePaymentMethods.size(); i++) {
084                paymentMethodbuffer.append(olePaymentMethods.get(i).getPaymentMethod() + ",");
085            }
086
087        }
088        return paymentMethodbuffer.toString();
089    }
090
091}