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.select.service.impl;
17  
18  import org.kuali.ole.select.OleSelectConstant;
19  import org.kuali.ole.select.businessobject.BibInfoBean;
20  import org.kuali.ole.select.service.BibInfoWrapperService;
21  import org.kuali.ole.select.service.DocStoreService;
22  import org.kuali.ole.sys.context.SpringContext;
23  
24  import java.util.HashMap;
25  
26  public class DocStoreServiceImpl implements DocStoreService {
27      protected static org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(DocStoreServiceImpl.class);
28      private BibInfoBean bibInfoBean;
29      private BibInfoWrapperService bibInfoWrapperService;
30      private BibInfoServiceImpl bibInfoServiceImpl;
31  
32      private BibInfoBean getBibInfoBean() {
33          bibInfoBean = new BibInfoBean();
34          return bibInfoBean;
35      }
36  
37      public String search(String title, String author, String typeOfStandardNumber, String standardNumber) throws Exception {
38          String response = null;
39          BibInfoBean bibInfoBean = getBibInfoBean();
40          HashMap dataMap = new HashMap();
41          bibInfoBean = buildBibInfoBean(title, author, typeOfStandardNumber, standardNumber);
42          BibInfoWrapperService docStore = getBibInfoWrapperService();
43          response = docStore.getDocSearchResponse(bibInfoBean);
44          if (LOG.isDebugEnabled())
45              LOG.debug("docstore search response------------->" + response);
46          return response;
47      }
48  
49      public String ingest(String title, String author, String typeOfStandardNumber, String standardNumber) throws Exception {
50          String response = null;
51          BibInfoBean bibInfoBean = getBibInfoBean();
52          HashMap dataMap = new HashMap();
53          bibInfoBean = buildBibInfoBean(title, author, typeOfStandardNumber, standardNumber);
54          BibInfoWrapperService docStore = getBibInfoWrapperService();
55          String xmlString = docStore.generateXMLStringForIngest(bibInfoBean, dataMap);
56          dataMap.put(OleSelectConstant.DOCSTORE_REQUEST_XMLSTRING, xmlString);
57          response = docStore.getDocStoreResponse(dataMap);
58          if (LOG.isDebugEnabled())
59              LOG.debug("docstore ingest response------------->" + response);
60          return response;
61      }
62  
63      public String save(String bibMarcXmlString) throws Exception {
64          BibInfoBean bibInfoBean = getBibInfoBean();
65          bibInfoBean.setDocStoreOperation(OleSelectConstant.DOCSTORE_OPERATION_WEBFORM);
66          HashMap<String, String> dataMap = new HashMap<String, String>();
67          dataMap.put(OleSelectConstant.BIB_MARC_XMLSTRING, bibMarcXmlString);
68          BibInfoWrapperService docStore = getBibInfoWrapperService();
69          String titleId = docStore.generateXMLStringForIngest(bibInfoBean, dataMap);
70          return titleId;
71      }
72  
73      private BibInfoBean buildBibInfoBean(String title, String author, String typeOfStandardNumber, String standardNumber) throws Exception {
74          bibInfoBean.setTitle(title);
75          bibInfoBean.setAuthor(author);
76          bibInfoBean.setTypeOfStandardNumber(typeOfStandardNumber);
77          bibInfoBean.setStandardNumber(standardNumber);
78          return bibInfoBean;
79      }
80  
81      private BibInfoWrapperService getBibInfoWrapperService() {
82          if (null == bibInfoWrapperService) {
83              bibInfoWrapperService = SpringContext.getBean(BibInfoWrapperServiceImpl.class);
84          }
85          return bibInfoWrapperService;
86      }
87  }