View Javadoc

1   package org.kuali.ole.ingest.function;
2   
3   //import org.kuali.incubator.SolrRequestReponseHandler;
4   
5   import org.apache.log4j.Logger;
6   import org.kuali.ole.DataCarrierService;
7   import org.kuali.ole.OLEConstants;
8   import org.kuali.ole.editor.service.DiscoveryHelperService;
9   import org.kuali.ole.ingest.ISBNUtil;
10  import org.kuali.rice.core.api.resourceloader.GlobalResourceLoader;
11  import org.kuali.rice.krms.framework.engine.Function;
12  
13  import java.util.ArrayList;
14  import java.util.List;
15  
16  /**
17   * ISBNFunction takes the request,normalize tha isbn and sets the bibRecordFromSOLRResponse into dataCarrierService
18   */
19  public class ISBNFunction implements Function {
20  
21      private DiscoveryHelperService discoveryHelperService;
22      private static final Logger LOG = Logger.getLogger(ISBNFunction.class);
23  
24      /**
25       *  This method takes the request and normalize the isbn and  sets the bibRecordFromSOLRResponse into dataCarrierService.
26       * @param arguments
27       * @return  Object
28       */
29      @Override
30      public Object invoke(Object... arguments) {
31          LOG.info(" -----------------> inside isbn function ------------> ");
32          DataCarrierService dataCarrierService = GlobalResourceLoader.getService(OLEConstants.DATA_CARRIER_SERVICE);
33          String existingDocstoreField = (String)(arguments[0]);
34          String isbn = (String)(arguments[1]);
35          String normalizedISBN = null;
36          try {
37              normalizedISBN = new ISBNUtil().normalizeISBN(isbn);
38          } catch (Exception e) {
39              System.out.println(e.getMessage());
40          }
41          List list = getDiscoveryHelperService().getResponseFromSOLR(existingDocstoreField, normalizedISBN);
42          LOG.info(" ---------------> list.size ------------> " + list.size());
43          if(list.size() >= 1){
44              LOG.info(" inside if condition of list --------------------> ");
45              dataCarrierService.addData(OLEConstants.BIB_INFO_LIST_FROM_SOLR_RESPONSE, list);
46              return true;
47          }
48          return false;
49      }
50  
51      /**
52       *  Gets the discoveryHelperService instances
53       * @return  DiscoveryHelperService
54       */
55      public DiscoveryHelperService getDiscoveryHelperService() {
56          if (null == discoveryHelperService) {
57              discoveryHelperService = new DiscoveryHelperService();
58          }
59          return discoveryHelperService;
60      }
61  
62      /**
63       *   Sets the discoveryHelperService attribute value.
64       * @param discoveryHelperService
65       */
66      public void setDiscoveryHelperService(DiscoveryHelperService discoveryHelperService) {
67          this.discoveryHelperService = discoveryHelperService;
68      }
69  }