View Javadoc

1   package org.kuali.ole.ingest.function;
2   
3   //import org.kuali.incubator.SolrRequestReponseHandler;
4   import org.kuali.ole.DataCarrierService;
5   import org.kuali.ole.OLEConstants;
6   import org.kuali.ole.editor.service.DiscoveryHelperService;
7   import org.kuali.ole.ingest.ISBNUtil;
8   import org.kuali.ole.ingest.pojo.ProfileTerm;
9   import org.kuali.rice.core.api.resourceloader.GlobalResourceLoader;
10  import org.kuali.rice.krms.framework.engine.Function;
11  
12  import java.util.ArrayList;
13  import java.util.List;
14  
15  /**
16   * Created by IntelliJ IDEA.
17   * User: pvsubrah
18   * Date: 3/28/12
19   * Time: 10:02 AM
20   * To change this template use File | Settings | File Templates.
21   */
22  public class ISBNFunction implements Function {
23  
24      private DiscoveryHelperService discoveryHelperService;
25  
26      /**
27       *  This method takes the request and normalize the isbn and  sets the bibRecordFromSOLRResponse into dataCarrierService.
28       * @param arguments
29       * @return  Object
30       */
31      @Override
32      public Object invoke(Object... arguments) {
33          DataCarrierService dataCarrierService = GlobalResourceLoader.getService(OLEConstants.DATA_CARRIER_SERVICE);
34          Object argument = arguments[0];
35          ProfileTerm profileTerm = (ProfileTerm) ((ArrayList) argument).get(0);
36          String isbn = profileTerm.getIncomingField();
37          String normalizedISBN = null;
38          try {
39              normalizedISBN = new ISBNUtil().normalizeISBN(isbn);
40          } catch (Exception e) {
41              e.printStackTrace();
42          }
43          List list = getDiscoveryHelperService().getResponseFromSOLR(profileTerm.getExistingField(), normalizedISBN);
44          if(list.size() >= 1){
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  }