1 package org.kuali.ole.serviceimpl;
2
3 import org.kuali.ole.OleSRUConstants;
4 import org.kuali.ole.bo.diagnostics.OleSRUDiagnostic;
5 import org.kuali.ole.bo.diagnostics.OleSRUDiagnostics;
6 import org.kuali.ole.bo.serachRetrieve.OleSRUSearchRetrieveResponse;
7 import org.kuali.ole.handler.OleSRUOpacXMLResponseHandler;
8 import org.kuali.ole.service.OLESRUService;
9 import org.kuali.ole.service.OleSRUWebService;
10 import org.kuali.rice.core.api.config.property.ConfigContext;
11
12 import java.util.ArrayList;
13 import java.util.HashMap;
14 import java.util.List;
15 import java.util.Map;
16
17
18
19
20
21
22
23
24 public class OLESRUServiceImpl implements OLESRUService {
25
26
27 @Override
28 public String getDetails(String operation, String query, String version, String startRecord, String maximumRecords, String recordPacking, String recordSchema,String sortKeys,String recordXPath,String resultSetTTL,String styleSheet) {
29
30 int startRecords = -1;
31
32 if (startRecord != null && !"".equals(startRecord)) {
33 startRecords = Integer.parseInt(startRecord);
34 } else if (startRecord == null) {
35 startRecords = -1;
36 }
37 String xml="";
38
39 OleSRUWebService oleSRUWebService = new OleSRUWebServiceImpl();
40 Map requestMap = getReqParameters(operation,query,version,startRecord,maximumRecords,recordPacking,recordSchema,sortKeys,recordXPath,resultSetTTL,styleSheet);
41 OleSRUSearchRetrieveResponse oleSRUSearchRetrieveResponse = new OleSRUSearchRetrieveResponse();
42 oleSRUSearchRetrieveResponse.setVersion(version);
43 oleSRUSearchRetrieveResponse.setNumberOfRecords(new Long(0));
44 if (startRecords == 0 || operation==null || version==null || query==null || !version.equals(OleSRUConstants.SRU_VERSION)) {
45 OleSRUDiagnostics oleSRUDiagnostics = new OleSRUDiagnostics();
46 List<OleSRUDiagnostic> oleSRUDiagnosticList = new ArrayList<OleSRUDiagnostic>();
47 OleSRUDiagnostic oleSRUDiagnostic;
48 oleSRUDiagnostic = new OleSRUDiagnostic();
49
50 if(startRecords == 0){
51 oleSRUDiagnostic.setUri("info:srw/diagnostic/1/6");
52 oleSRUDiagnostic.setDetails(ConfigContext.getCurrentContextConfig().getProperty(OleSRUConstants.UN_SUPPORTED_PARAM_VALUE));
53 oleSRUDiagnostic.setMessage(OleSRUConstants.START_RECORD);
54 }
55 if(operation==null){
56 oleSRUDiagnostic.setUri("info:srw/diagnostic/1/7");
57 oleSRUDiagnostic.setDetails(ConfigContext.getCurrentContextConfig().getProperty(OleSRUConstants.MANDATORY));
58 oleSRUDiagnostic.setMessage(OleSRUConstants.OPERATION_TYPE);
59 }
60 if(version==null){
61 oleSRUDiagnostic.setUri("info:srw/diagnostic/1/7");
62 oleSRUDiagnostic.setDetails(ConfigContext.getCurrentContextConfig().getProperty(OleSRUConstants.MANDATORY));
63
64 if(oleSRUDiagnostic.getMessage()!=null)
65 oleSRUDiagnostic.setMessage(oleSRUDiagnostic.getMessage()+","+OleSRUConstants.VERSION);
66 else
67 oleSRUDiagnostic.setMessage(OleSRUConstants.VERSION);
68 }
69 if(query==null){
70 oleSRUDiagnostic.setUri("info:srw/diagnostic/1/7");
71 oleSRUDiagnostic.setDetails(ConfigContext.getCurrentContextConfig().getProperty(OleSRUConstants.MANDATORY));
72 if(oleSRUDiagnostic.getMessage()!=null)
73 oleSRUDiagnostic.setMessage(oleSRUDiagnostic.getMessage()+","+OleSRUConstants.QUERY);
74 else
75 oleSRUDiagnostic.setMessage(OleSRUConstants.QUERY);
76 }
77 if(version!=null && !version.equals(OleSRUConstants.SRU_VERSION)){
78 oleSRUDiagnostic.setUri("info:srw/diagnostic/1/5");
79 oleSRUDiagnostic.setDetails(version+" "+ConfigContext.getCurrentContextConfig().getProperty(OleSRUConstants.UNSUPPORT_VERSION));
80 if(oleSRUDiagnostic.getMessage()!=null) {
81 oleSRUSearchRetrieveResponse.setVersion((OleSRUConstants.SRU_VERSION));
82 oleSRUDiagnostic.setMessage(oleSRUDiagnostic.getMessage()+","+OleSRUConstants.SRU_VERSION);
83 }else{
84 oleSRUSearchRetrieveResponse.setVersion((OleSRUConstants.SRU_VERSION));
85 oleSRUDiagnostic.setMessage("Supported "+OleSRUConstants.VERSION + ":"+OleSRUConstants.SRU_VERSION);
86 }
87 }
88 oleSRUDiagnosticList.add(oleSRUDiagnostic);
89
90 oleSRUDiagnostics.setOleSRUDiagnosticList(oleSRUDiagnosticList);
91 oleSRUSearchRetrieveResponse.setOleSRUDiagnostics(oleSRUDiagnostics);
92 OleSRUOpacXMLResponseHandler oleSRUOpacXMLResponseHandler = new OleSRUOpacXMLResponseHandler();
93 return oleSRUOpacXMLResponseHandler.toXML(oleSRUSearchRetrieveResponse,recordSchema);
94 } else {
95 return oleSRUWebService.getOleSRUResponse(requestMap);
96 }
97
98 }
99
100 public Map getReqParameters(String operation, String query, String version, String startRecord, String maximumRecords, String recordPacking, String recordSchema,String sortKeys,String recordXPath,String resultSetTTL,String styleSheet) {
101 HashMap reqParamMap = new HashMap();
102 reqParamMap.put(OleSRUConstants.OPERATION_TYPE, operation);
103 reqParamMap.put(OleSRUConstants.VERSION, version);
104 if (query != null) {
105 if (query.startsWith("cql.serverChoice")) {
106 String[] querySplit = query.split("=");
107 query = querySplit[1];
108 }
109 reqParamMap.put(OleSRUConstants.QUERY, query);
110 }
111 if (startRecord != null && !"".equals(startRecord) ){
112 int startRecords = Integer.parseInt(startRecord);
113 reqParamMap.put(OleSRUConstants.START_RECORD, startRecords - 1);
114 } else
115 reqParamMap.put(OleSRUConstants.START_RECORD, Integer.parseInt(ConfigContext.getCurrentContextConfig().getProperty(OleSRUConstants.STARTRECORD)));
116
117 if (maximumRecords != null && !"".equals(maximumRecords)) {
118 int maxRecord = Integer.parseInt(maximumRecords);
119 reqParamMap.put(OleSRUConstants.MAXIMUM_RECORDS, maxRecord);
120
121 } else
122 reqParamMap.put(OleSRUConstants.MAXIMUM_RECORDS, Integer.parseInt(ConfigContext.getCurrentContextConfig().getProperty(OleSRUConstants.MAXRECORD)));
123
124 if (recordPacking != null && !"".equals(recordPacking)) {
125 reqParamMap.put(OleSRUConstants.RECORD_PACKING, recordPacking);
126 } else
127 reqParamMap.put(OleSRUConstants.RECORD_PACKING, OleSRUConstants.RECORD_PACK_XML);
128
129 if (sortKeys != null && !"".equals(sortKeys)) {
130 reqParamMap.put(OleSRUConstants.SORTKEYS, sortKeys);
131 } else
132 reqParamMap.put(OleSRUConstants.SORTKEYS, OleSRUConstants.TITLE_SORT_KEYS);
133
134 if (styleSheet != null) {
135 reqParamMap.put(OleSRUConstants.STYLE_SHEET, styleSheet);
136 }
137
138 if (recordSchema != null && !"".equals(recordSchema)) {
139 if (OleSRUConstants.DC_RECORD_SCHEMA.equals((recordSchema)))
140 reqParamMap.put(OleSRUConstants.RECORD_SCHEMA, OleSRUConstants.DC_RECORD_SCHEMA);
141 else if (OleSRUConstants.MARC_RECORD_SCHEMA.equals((recordSchema))) {
142 reqParamMap.put(OleSRUConstants.RECORD_SCHEMA, OleSRUConstants.MARC_RECORD_SCHEMA);
143 } else
144 reqParamMap.put(OleSRUConstants.RECORD_SCHEMA,recordSchema);
145 } else {
146 reqParamMap.put(OleSRUConstants.RECORD_SCHEMA, OleSRUConstants.MARC_RECORD_SCHEMA);
147
148
149 }
150 return reqParamMap;
151
152 }
153
154
155
156 }