This result checker is a default result checker and is used to check results in SAP data sources.
package com.sybase.sap;
import java.util.AbstractMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import com.sap.mw.jco.JCO;
import com.sybase.sup.sap.SAPResultChecker;
import com.sybase.vader.utils.logging.SybLogger;
public class DefaultSAPResultCheck implements SAPResultChecker
{
private static Set<String> nonErrorMessages;
static
{
nonErrorMessages = new HashSet<String>();
nonErrorMessages.add("No data found");
nonErrorMessages.add("Data was not found for the document");
}
public Map.Entry<Boolean, String> checkReturn(JCO.Function f)
{
JCO.Record returnStructure = null;
JCO.ParameterList jpl = f.getExportParameterList();
String msg = null;
boolean success = true;
if ( jpl != null )
{
try
{
returnStructure = jpl.getStructure("RETURN");
if ( returnStructure != null )
{
String type = returnStructure.getString("TYPE");
// generally TYPE is S for success, I for informational,
// or empty
if ( !(type.equals("") || type.equals("S") || type.equals("I")) )
{
String message = returnStructure.getString("MESSAGE");
/*UWPLogger.LogWarning*/
SybLogger.warn("SapUtils.execute: TYPE: <<" + type + ">>, MESSAGE: <<" + message + ">>");
if ( !type.equals("W") && !nonErrorMessages.contains(message) )
{
success = false;
msg = "TYPE: <<" + type + ">>, MESSAGE: <<" + message + ">>";
}
else
{
msg = "TYPE: <<" + type + ">>, MESSAGE: <<" + message + ">>";
}
}
else
{
if (SybLogger.isDebugEnabled())
{
String message = returnStructure.getString("MESSAGE");
SybLogger.debug("SapUtils.execute: TYPE: <<" + type + ">>, MESSAGE: <<" + message + ">>");
}
}
}
}
catch (Exception e)
{
/*
if (UWPLogger.isTrace())
UWPLogger.LogTrace
*/
SybLogger.debug("SapUtils::execute: Unable to retrieve RETURN structure - Will try to retrieve RETURN table next.", e);
}
}
// if there is no RETURN structure, look for RETURN table
if ( returnStructure == null )
{
jpl = f.getTableParameterList();
if ( jpl != null )
{
try
{
StringBuilder retMessage = new StringBuilder();
JCO.Table returnTable = jpl.getTable("RETURN");
for (int i = 0; i < returnTable.getNumRows(); i++)
{
returnTable.setRow(i);
String type = returnTable.getString("TYPE");
// generally TYPE is S for success, I for
// informational, or empty
if ( !(type.equals("") || type.equals("S") || type.equals("I")) )
{
String message = returnTable.getString("MESSAGE");
/*UWPLogger.LogWarning*/ SybLogger.warn("SapUtils.execute[" + i + "]: TYPE: <<" + type + ">>, MESSAGE: <<"
+ message + ">>");
if ( !type.equals("W") && !nonErrorMessages.contains(message) )
{
success = false;
retMessage
.append("[" + i + "]TYPE: <<" + type + ">>, MESSAGE: <<" + message + ">>");
}
else
{
retMessage
.append("[" + i + "]TYPE: <<" + type + ">>, MESSAGE: <<" + message + ">>");
}
}
else
{
if (SybLogger.isDebugEnabled())
{
String message = returnTable.getString("MESSAGE");
SybLogger.debug("SapUtils.execute[" + i + "]: TYPE: <<" + type + ">>, MESSAGE: <<" + message + ">>");
}
}
}
if( retMessage.length() > 0 )
{
msg = retMessage.toString();
}
}
catch (Exception e)
{
/*UWPLogger.LogWarning*/ SybLogger.warn("SapUtils::execute: error in execution while retrieving RETURN table: ", e);
success = false;
msg = e.toString();
}
}
}
return new CheckReturnMapEntry<Boolean, String>(success, msg);
}
class CheckReturnMapEntry<Boolean, String> extends java.util.AbstractMap.SimpleImmutableEntry<Boolean, String> {
public CheckReturnMapEntry(Boolean success, String msg) {
super(success, msg);
}
}
}