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.describe.service.DiscoveryHelperService;
6   import org.kuali.ole.ingest.util.OCLCUtil;
7   import org.kuali.rice.core.api.resourceloader.GlobalResourceLoader;
8   import org.kuali.rice.krms.framework.engine.Function;
9   
10  import java.util.ArrayList;
11  import java.util.List;
12  
13  /**
14   * Created with IntelliJ IDEA.
15   * User: ?
16   * Date: 12/10/12
17   * Time: 1:59 PM
18   * To change this template use File | Settings | File Templates.
19   */
20  public class OCLCFunction implements Function {
21  
22      private DiscoveryHelperService discoveryHelperService;
23      @Override
24      public Object invoke(Object... arguments) {
25          DataCarrierService dataCarrierService = GlobalResourceLoader.getService(OLEConstants.DATA_CARRIER_SERVICE);
26          String existingDocstoreField = (String)(arguments[0]);
27          String oclc = (String)(arguments[1]);
28          if(oclc != null){
29              String normalizedOclc = null;
30              try{
31                  normalizedOclc = new OCLCUtil().normalizedOclc(oclc);
32              }
33              catch (Exception e) {
34                  e.printStackTrace();
35              }
36              List list = getDiscoveryHelperService().getResponseFromSOLR(existingDocstoreField, normalizedOclc);
37              if(list.size() >= 1){
38                  dataCarrierService.addData(OLEConstants.BIB_INFO_LIST_FROM_SOLR_RESPONSE, list);
39                  return true;
40              }
41          }
42          return false;
43      }
44  
45      /**
46       *  Gets the discoveryHelperService instances
47       * @return  DiscoveryHelperService
48       */
49      public DiscoveryHelperService getDiscoveryHelperService() {
50          if (null == discoveryHelperService) {
51              discoveryHelperService = new DiscoveryHelperService();
52          }
53          return discoveryHelperService;
54      }
55  
56      /**
57       *   Sets the discoveryHelperService attribute value.
58       * @param discoveryHelperService
59       */
60      public void setDiscoveryHelperService(DiscoveryHelperService discoveryHelperService) {
61          this.discoveryHelperService = discoveryHelperService;
62      }
63  
64  }