View Javadoc
1   package org.kuali.ole.ingest.function;
2   
3   import org.kuali.ole.DataCarrierService;
4   import org.kuali.ole.OLEConstants;
5   import org.kuali.ole.docstore.common.client.DocstoreClientLocator;
6   import org.kuali.ole.docstore.common.document.content.enums.DocType;
7   import org.kuali.ole.docstore.common.search.SearchParams;
8   import org.kuali.ole.docstore.common.search.SearchResponse;
9   import org.kuali.ole.docstore.common.search.SearchResult;
10  import org.kuali.ole.docstore.common.search.SearchResultField;
11  import org.kuali.ole.ingest.util.OCLCUtil;
12  import org.kuali.ole.sys.context.SpringContext;
13  import org.kuali.rice.core.api.resourceloader.GlobalResourceLoader;
14  import org.kuali.rice.krms.framework.engine.Function;
15  
16  import java.util.ArrayList;
17  import java.util.HashMap;
18  import java.util.List;
19  
20  /**
21   * Created with IntelliJ IDEA.
22   * User: ?
23   * Date: 12/10/12
24   * Time: 1:59 PM
25   * To change this template use File | Settings | File Templates.
26   */
27  public class OCLCFunction implements Function {
28  
29      private DocstoreClientLocator docstoreClientLocator;
30  
31      @Override
32      public Object invoke(Object... arguments) {
33          DataCarrierService dataCarrierService = GlobalResourceLoader.getService(OLEConstants.DATA_CARRIER_SERVICE);
34          String existingDocstoreField = (String)(arguments[0]);
35          String oclc = (String)(arguments[1]);
36          if(oclc != null){
37              String normalizedOclc = null;
38              try{
39                  normalizedOclc = new OCLCUtil().normalizedOclc(oclc);
40              }
41              catch (Exception e) {
42                  e.printStackTrace();
43              }
44            //  List list = getDiscoveryHelperService().getResponseFromSOLR(existingDocstoreField, normalizedOclc);
45  
46              List list=new ArrayList<>();
47              SearchParams searchParams=new  SearchParams();
48              searchParams.getSearchConditions().add(searchParams.buildSearchCondition("", searchParams.buildSearchField(DocType.BIB.getCode(),"035a",normalizedOclc), "AND"));
49              searchParams.getSearchResultFields().add(searchParams.buildSearchResultField("bibliographic", "bibIdentifier"));
50              try {
51                  SearchResponse searchResponse = getDocstoreClientLocator().getDocstoreClient().search(searchParams);
52                  List<SearchResult>  searchResults=searchResponse.getSearchResults();
53                  if(searchResults.size() >=1){
54                      for (SearchResult searchResult:searchResults){
55                          HashMap<String, Object> bibMap=new HashMap<>();
56                          for(SearchResultField searchResultField:searchResult.getSearchResultFields()){
57                              if(searchResultField.getFieldValue()!=null && !searchResultField.getFieldValue().isEmpty() && searchResultField.getFieldName().equalsIgnoreCase("bibIdentifier") ){
58                                  bibMap.put(OLEConstants.BIB_UNIQUE_ID,searchResultField.getFieldValue());
59                              }
60                          }
61                          list.add(bibMap);
62                      }
63                  }
64              }catch(Exception ex){
65                  throw new RuntimeException(ex);
66  
67              }
68              if(list.size() >= 1){
69                  dataCarrierService.addData(OLEConstants.BIB_INFO_LIST_FROM_SOLR_RESPONSE, list);
70                  return true;
71              }
72          }
73          return false;
74      }
75  
76  
77      public DocstoreClientLocator getDocstoreClientLocator() {
78          if (null == docstoreClientLocator) {
79              return  SpringContext.getBean(DocstoreClientLocator.class);
80          }
81          return docstoreClientLocator;
82      }
83  
84      public void setDocstoreClientLocator(DocstoreClientLocator docstoreClientLocator) {
85          this.docstoreClientLocator = docstoreClientLocator;
86      }
87  
88  }