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          Object argument = arguments[0];
34          String existingDocstoreField = (String)((ArrayList) argument).get(0);
35          String isbn = (String)((ArrayList) argument).get(1);
36          String normalizedISBN = null;
37          try {
38              normalizedISBN = new ISBNUtil().normalizeISBN(isbn);
39          } catch (Exception e) {
40              System.out.println(e.getMessage());
41          }
42          List list = getDiscoveryHelperService().getResponseFromSOLR(existingDocstoreField, normalizedISBN);
43          LOG.info(" ---------------> list.size ------------> " + list.size());
44          if(list.size() >= 1){
45              LOG.info(" inside if condition of list --------------------> ");
46              dataCarrierService.addData(OLEConstants.BIB_INFO_LIST_FROM_SOLR_RESPONSE, list);
47              return true;
48          }
49          return false;
50      }
51  
52      /**
53       *  Gets the discoveryHelperService instances
54       * @return  DiscoveryHelperService
55       */
56      public DiscoveryHelperService getDiscoveryHelperService() {
57          if (null == discoveryHelperService) {
58              discoveryHelperService = new DiscoveryHelperService();
59          }
60          return discoveryHelperService;
61      }
62  
63      /**
64       *   Sets the discoveryHelperService attribute value.
65       * @param discoveryHelperService
66       */
67      public void setDiscoveryHelperService(DiscoveryHelperService discoveryHelperService) {
68          this.discoveryHelperService = discoveryHelperService;
69      }
70  }