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.handler.OleSRUDiagnosticsHandler;
7 import org.kuali.ole.service.OleDiagnosticsService;
8 import org.kuali.rice.core.api.config.property.Config;
9 import org.kuali.rice.core.api.config.property.ConfigContext;
10 import org.slf4j.Logger;
11 import org.slf4j.LoggerFactory;
12
13 import java.util.ArrayList;
14 import java.util.List;
15
16
17
18
19
20
21
22
23 public class OleDiagnosticsServiceImpl implements OleDiagnosticsService {
24
25 private Logger LOG = LoggerFactory.getLogger(this.getClass());
26
27 public OleSRUDiagnosticsHandler oleSRUDiagnosticsHandler;
28 private Config currentContextConfig;
29
30 public OleDiagnosticsServiceImpl() {
31 oleSRUDiagnosticsHandler = new OleSRUDiagnosticsHandler();
32 }
33
34
35
36
37
38
39
40 public OleSRUDiagnostics getDiagnosticResponse(String errorMessage) {
41 LOG.info("Inside getDiagnosticResponse Method");
42 OleSRUDiagnostic oleSRUDiagnostic = new OleSRUDiagnostic();
43 if(!errorMessage.equals("")){
44 oleSRUDiagnostic.setMessage(errorMessage);
45 if(errorMessage.equals(getCurrentContextConfig().getProperty(OleSRUConstants.INVALID_OperationType))){
46 oleSRUDiagnostic.setUri("info:srw/diagnostic/1/4");
47 oleSRUDiagnostic.setDetails(OleSRUConstants.OperationType);
48 }else if(errorMessage.equals(getCurrentContextConfig().getProperty(OleSRUConstants.INVALID_RECORD_PACKING))){
49 oleSRUDiagnostic.setUri("info:srw/diagnostic/1/71");
50 oleSRUDiagnostic.setDetails(OleSRUConstants.RECORD_PACKING);
51 }else if(errorMessage.equals(getCurrentContextConfig().getProperty(OleSRUConstants.INVALID_RECORD_SCHEMA))){
52 oleSRUDiagnostic.setUri("info:srw/diagnostic/1/66");
53 oleSRUDiagnostic.setDetails(OleSRUConstants.RECORD_SCHEMA);
54 }else if(errorMessage.equals(getCurrentContextConfig().getProperty(OleSRUConstants.INVALID_QUERY_DIAGNOSTIC_MSG))){
55 oleSRUDiagnostic.setUri("info:srw/diagnostic/1/10");
56 oleSRUDiagnostic.setDetails(OleSRUConstants.QUERY);
57 }else if(errorMessage.equals("Local Id Value Should be a Number")){
58 oleSRUDiagnostic.setUri("info:srw/diagnostic/1/8");
59 oleSRUDiagnostic.setDetails(OleSRUConstants.QUERY);
60 }else if(errorMessage.equals(getCurrentContextConfig().getProperty(OleSRUConstants.SERVER_DIAGNOSTIC_MSG))){
61 oleSRUDiagnostic.setUri("info:srw/diagnostic/1/2");
62 }else if(errorMessage.equals(getCurrentContextConfig().getProperty(OleSRUConstants.START_RECORD_UNMATCH))){
63 oleSRUDiagnostic.setUri("info:srw/diagnostic/1/61");
64 oleSRUDiagnostic.setDetails(OleSRUConstants.START_RECORD);
65 } else if(errorMessage.equals(getCurrentContextConfig().getProperty(OleSRUConstants.NORECORDS_DIAGNOSTIC_MSG))){
66 oleSRUDiagnostic.setUri("info:srw/diagnostic/1/65");
67
68 }
69 }
70 OleSRUDiagnostics oleSRUDiagnostics = new OleSRUDiagnostics();
71 List<OleSRUDiagnostic> oleSRUDiagnosticList = new ArrayList<OleSRUDiagnostic>();
72 oleSRUDiagnosticList.add(oleSRUDiagnostic);
73 oleSRUDiagnostics.setOleSRUDiagnosticList(oleSRUDiagnosticList);
74 return oleSRUDiagnostics;
75 }
76
77 private Config getCurrentContextConfig() {
78 if (null == currentContextConfig) {
79 currentContextConfig = ConfigContext.getCurrentContextConfig();
80 }
81 return currentContextConfig;
82 }
83
84 public void setCurrentContextConfig(Config currentContextConfig) {
85 this.currentContextConfig = currentContextConfig;
86 }
87 }