001package org.kuali.ole.serviceimpl; 002 003import org.kuali.ole.OleSRUConstants; 004import org.kuali.ole.bo.diagnostics.OleSRUDiagnostic; 005import org.kuali.ole.bo.diagnostics.OleSRUDiagnostics; 006import org.kuali.ole.handler.OleSRUDiagnosticsHandler; 007import org.kuali.ole.service.OleDiagnosticsService; 008import org.kuali.rice.core.api.config.property.Config; 009import org.kuali.rice.core.api.config.property.ConfigContext; 010import org.slf4j.Logger; 011import org.slf4j.LoggerFactory; 012 013import java.util.ArrayList; 014import java.util.List; 015 016/** 017 * Created with IntelliJ IDEA. 018 * User: ? 019 * Date: 7/9/12 020 * Time: 6:14 PM 021 * To change this template use File | Settings | File Templates. 022 */ 023public class OleDiagnosticsServiceImpl implements OleDiagnosticsService { 024 025 private Logger LOG = LoggerFactory.getLogger(this.getClass()); 026 027 public OleSRUDiagnosticsHandler oleSRUDiagnosticsHandler; 028 private Config currentContextConfig; 029 030 public OleDiagnosticsServiceImpl() { 031 oleSRUDiagnosticsHandler = new OleSRUDiagnosticsHandler(); 032 } 033 034 /** 035 * this method will return the diagnostic response(error response) 036 * 037 * @param errorMessage 038 * @return xml as a OleSRUDiagnostics 039 */ 040 public OleSRUDiagnostics getDiagnosticResponse(String errorMessage) { 041 LOG.info("Inside getDiagnosticResponse Method"); 042 OleSRUDiagnostic oleSRUDiagnostic = new OleSRUDiagnostic(); 043 if(!errorMessage.equals("")){ 044 oleSRUDiagnostic.setMessage(errorMessage); 045 if(errorMessage.equals(getCurrentContextConfig().getProperty(OleSRUConstants.INVALID_OPERATION_TYPE))){ 046 oleSRUDiagnostic.setUri("info:srw/diagnostic/1/4"); 047 oleSRUDiagnostic.setDetails(OleSRUConstants.OPERATION_TYPE); 048 }else if(errorMessage.equals(getCurrentContextConfig().getProperty(OleSRUConstants.INVALID_RECORD_PACKING))){ 049 oleSRUDiagnostic.setUri("info:srw/diagnostic/1/71"); 050 oleSRUDiagnostic.setDetails(OleSRUConstants.RECORD_PACKING); 051 }else if(errorMessage.equals(getCurrentContextConfig().getProperty(OleSRUConstants.INVALID_RECORD_SCHEMA))){ 052 oleSRUDiagnostic.setUri("info:srw/diagnostic/1/66"); 053 oleSRUDiagnostic.setDetails(OleSRUConstants.RECORD_SCHEMA); 054 }else if(errorMessage.equals(getCurrentContextConfig().getProperty(OleSRUConstants.INVALID_QUERY_DIAGNOSTIC_MSG))){ 055 oleSRUDiagnostic.setUri("info:srw/diagnostic/1/10"); 056 oleSRUDiagnostic.setDetails(OleSRUConstants.QUERY); 057 }else if(errorMessage.equals("Local Id Value Should be a Number")){ 058 oleSRUDiagnostic.setUri("info:srw/diagnostic/1/8"); 059 oleSRUDiagnostic.setDetails(OleSRUConstants.QUERY); 060 }else if(errorMessage.equals(getCurrentContextConfig().getProperty(OleSRUConstants.SERVER_DIAGNOSTIC_MSG))){ 061 oleSRUDiagnostic.setUri("info:srw/diagnostic/1/2"); 062 }else if(errorMessage.equals(getCurrentContextConfig().getProperty(OleSRUConstants.START_RECORD_UNMATCH))){ 063 oleSRUDiagnostic.setUri("info:srw/diagnostic/1/61"); 064 oleSRUDiagnostic.setDetails(OleSRUConstants.START_RECORD); 065 } else if(errorMessage.equals(getCurrentContextConfig().getProperty(OleSRUConstants.NORECORDS_DIAGNOSTIC_MSG))){ 066 oleSRUDiagnostic.setUri("info:srw/diagnostic/1/65"); 067 // oleSRUDiagnostic.setDetails(OleSRUConstants.START_RECORD); 068 } 069 } 070 OleSRUDiagnostics oleSRUDiagnostics = new OleSRUDiagnostics(); 071 List<OleSRUDiagnostic> oleSRUDiagnosticList = new ArrayList<OleSRUDiagnostic>(); 072 oleSRUDiagnosticList.add(oleSRUDiagnostic); 073 oleSRUDiagnostics.setOleSRUDiagnosticList(oleSRUDiagnosticList); 074 return oleSRUDiagnostics; 075 } 076 077 private Config getCurrentContextConfig() { 078 if (null == currentContextConfig) { 079 currentContextConfig = ConfigContext.getCurrentContextConfig(); 080 } 081 return currentContextConfig; 082 } 083 084 public void setCurrentContextConfig(Config currentContextConfig) { 085 this.currentContextConfig = currentContextConfig; 086 } 087}