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 */ 016package org.kuali.ole.select.service.impl; 017 018import org.kuali.ole.select.businessobject.BibInfoBean; 019import org.kuali.ole.select.service.BibInfoService; 020import org.kuali.ole.select.service.BibInfoWrapperService; 021import org.kuali.ole.sys.context.SpringContext; 022 023import java.util.ArrayList; 024import java.util.HashMap; 025import java.util.List; 026import java.util.Map; 027 028public class BibInfoWrapperServiceImpl implements BibInfoWrapperService { 029 030 private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(BibInfoWrapperServiceImpl.class); 031 protected BibInfoService bibInfoService; 032 033 @Override 034 public boolean isBibInfoExists(BibInfoBean bibInfoBean) throws Exception { 035 HashMap map = convertBibInfoBeanToMap(bibInfoBean); 036 boolean isExists = bibInfoService.isExists(map); 037 038 return isExists; 039 } 040 041 @Override 042 public String insertBibInfo(BibInfoBean bibInfoBean) throws Exception { 043 LOG.debug("###########inside BibInfoWrapperServiceImpl insertBibInfo###########"); 044 String titleId = bibInfoService.save(bibInfoBean); 045 return titleId; 046 } 047 048 @Override 049 public String insertBibInfo(BibInfoBean bibInfoBean, HashMap dataMap) throws Exception { 050 LOG.debug("###########inside BibInfoWrapperServiceImpl insertBibInfo###########"); 051 String titleId = bibInfoService.save(bibInfoBean, dataMap); 052 return titleId; 053 } 054 055 @Override 056 public BibInfoBean getBibInfo(HashMap<String, String> dataMap) throws Exception { 057 BibInfoBean bibInfoBean = bibInfoService.retrieveFromDocStore(dataMap); 058 return bibInfoBean; 059 } 060 061 @Override 062 public List<String> searchBibInfo(BibInfoBean bibInfoBean, int noOfRecords) throws Exception { 063 HashMap map = convertBibInfoBeanToMap(bibInfoBean); 064 List<BibInfoBean> bibInfoList = bibInfoService.search(map, noOfRecords); 065 List<String> titleIdList = new ArrayList<String>(); 066 for (int i = 0; i < bibInfoList.size(); i++) { 067 titleIdList.add(bibInfoList.get(i).getTitleId()); 068 } 069 return titleIdList; 070 } 071 072 @Override 073 public String getDocStoreResponse(HashMap<String, String> dataMap) throws Exception { 074 return bibInfoService.getDocStoreResponse(dataMap); 075 } 076 077 @Override 078 public List searchBibInfo(Map map) throws Exception { 079 return bibInfoService.search(map); 080 } 081 082 @Override 083 public List<BibInfoBean> searchBibInfo(BibInfoBean bibInfoBean) throws Exception { 084 return bibInfoService.searchBibInfo(bibInfoBean); 085 } 086 087 @Override 088 public String generateXMLStringForIngest(BibInfoBean bibInfoBean, HashMap dataMap) throws Exception { 089 return bibInfoService.generateXMLStringForIngest(bibInfoBean, dataMap); 090 } 091 092 @Override 093 public String getDocSearchResponse(BibInfoBean bibInfoBean) throws Exception { 094 return bibInfoService.getDocSearchResponse(bibInfoBean); 095 } 096 097 @Override 098 public String getTitleIdByMarcXMLFileProcessing(BibInfoBean bibInfoBean, HashMap<String, String> dataMap) throws Exception { 099 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}