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