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.businessobject.BibInfoBean;
19  import org.kuali.ole.select.service.BibInfoService;
20  import org.kuali.ole.select.service.BibInfoWrapperService;
21  import org.kuali.ole.sys.context.SpringContext;
22  
23  import java.util.ArrayList;
24  import java.util.HashMap;
25  import java.util.List;
26  import java.util.Map;
27  
28  public class BibInfoWrapperServiceImpl implements BibInfoWrapperService {
29  
30      private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(BibInfoWrapperServiceImpl.class);
31      protected BibInfoService bibInfoService;
32  
33      @Override
34      public boolean isBibInfoExists(BibInfoBean bibInfoBean) throws Exception {
35          HashMap map = convertBibInfoBeanToMap(bibInfoBean);
36          boolean isExists = bibInfoService.isExists(map);
37  
38          return isExists;
39      }
40  
41      @Override
42      public String insertBibInfo(BibInfoBean bibInfoBean) throws Exception {
43          LOG.debug("###########inside BibInfoWrapperServiceImpl insertBibInfo###########");
44          String titleId = bibInfoService.save(bibInfoBean);
45          return titleId;
46      }
47  
48      @Override
49      public String insertBibInfo(BibInfoBean bibInfoBean, HashMap dataMap) throws Exception {
50          LOG.debug("###########inside BibInfoWrapperServiceImpl insertBibInfo###########");
51          String titleId = bibInfoService.save(bibInfoBean, dataMap);
52          return titleId;
53      }
54  
55      @Override
56      public BibInfoBean getBibInfo(HashMap<String, String> dataMap) throws Exception {
57          BibInfoBean bibInfoBean = bibInfoService.retrieveFromDocStore(dataMap);
58          return bibInfoBean;
59      }
60  
61      @Override
62      public List<String> searchBibInfo(BibInfoBean bibInfoBean, int noOfRecords) throws Exception {
63          HashMap map = convertBibInfoBeanToMap(bibInfoBean);
64          List<BibInfoBean> bibInfoList = bibInfoService.search(map, noOfRecords);
65          List<String> titleIdList = new ArrayList<String>();
66          for (int i = 0; i < bibInfoList.size(); i++) {
67              titleIdList.add(bibInfoList.get(i).getTitleId());
68          }
69          return titleIdList;
70      }
71  
72      @Override
73      public String getDocStoreResponse(HashMap<String, String> dataMap) throws Exception {
74          return bibInfoService.getDocStoreResponse(dataMap);
75      }
76  
77      @Override
78      public List searchBibInfo(Map map) throws Exception {
79          return bibInfoService.search(map);
80      }
81  
82      @Override
83      public List<BibInfoBean> searchBibInfo(BibInfoBean bibInfoBean) throws Exception {
84          return bibInfoService.searchBibInfo(bibInfoBean);
85      }
86  
87      @Override
88      public String generateXMLStringForIngest(BibInfoBean bibInfoBean, HashMap dataMap) throws Exception {
89          return bibInfoService.generateXMLStringForIngest(bibInfoBean, dataMap);
90      }
91  
92      @Override
93      public String getDocSearchResponse(BibInfoBean bibInfoBean) throws Exception {
94          return bibInfoService.getDocSearchResponse(bibInfoBean);
95      }
96  
97      @Override
98      public String getTitleIdByMarcXMLFileProcessing(BibInfoBean bibInfoBean, HashMap<String, String> dataMap) throws Exception {
99          return bibInfoService.getTitleIdByMarcXMLFileProcessing(bibInfoBean, dataMap);
100     }
101 
102     private HashMap convertBibInfoBeanToMap(BibInfoBean bibInfoBean) {
103         HashMap map = new HashMap<String, String>();
104         if (bibInfoBean.getTitleId() != null) {
105             map.put("titleId", bibInfoBean.getTitleId());
106         }
107         if (bibInfoBean.getTitle() != null) {
108             map.put("title", bibInfoBean.getTitle());
109         }
110         if (bibInfoBean.getAuthor() != null) {
111             map.put("author", bibInfoBean.getAuthor());
112         }
113         if (bibInfoBean.getPublisher() != null) {
114             map.put("publisher", bibInfoBean.getPublisher());
115         }
116         if (bibInfoBean.getSubjects() != null) {
117             map.put("subjects", bibInfoBean.getSubjects());
118         }
119         if (bibInfoBean.getCategory() != null) {
120             map.put("category", bibInfoBean.getCategory());
121         }
122         if (bibInfoBean.getPlaceOfPublication() != null) {
123             map.put("placeOfPublication", bibInfoBean.getPlaceOfPublication());
124         }
125         if (bibInfoBean.getYearOfPublication() != null) {
126             map.put("yearOfPublication", bibInfoBean.getYearOfPublication());
127         }
128         if (bibInfoBean.getStandardNumber() != null) {
129             map.put("standardNumber", bibInfoBean.getStandardNumber());
130         }
131         return map;
132     }
133 
134     @Override
135     public boolean isDuplicateRecord(BibInfoBean bibInfoBean) throws Exception {
136         boolean isExists = bibInfoService.isDuplicateRecord(bibInfoBean);
137         return isExists;
138     }
139 
140     public BibInfoService getBibInfoService() {
141         if (bibInfoService == null) {
142             bibInfoService = SpringContext.getBean(BibInfoService.class);
143         }
144         return bibInfoService;
145     }
146 
147     public void setBibInfoService(BibInfoService bibInfoService) {
148         this.bibInfoService = bibInfoService;
149     }
150 }