1 package org.kuali.ole.ingest.function;
2
3
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
17
18
19
20
21
22 public class ISBNFunction implements Function {
23
24 private DiscoveryHelperService discoveryHelperService;
25
26
27
28
29
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
53
54
55 public DiscoveryHelperService getDiscoveryHelperService() {
56 if (null == discoveryHelperService) {
57 discoveryHelperService = new DiscoveryHelperService();
58 }
59 return discoveryHelperService;
60 }
61
62
63
64
65
66 public void setDiscoveryHelperService(DiscoveryHelperService discoveryHelperService) {
67 this.discoveryHelperService = discoveryHelperService;
68 }
69 }