1 19 package org.openbravo.erpCommon.utility; 20 21 import org.openbravo.data.FieldProvider; 22 import org.apache.log4j.Logger; 23 24 public class ErrorTextParserPOSTGRE extends ErrorTextParser { 25 static Logger log4j = Logger.getLogger(ErrorTextParserPOSTGRE.class); 26 27 public OBError parse() throws Exception { 28 if (getMessage().equals("")) return null; 29 else if (getConnection()==null) return null; 30 OBError myError = null; 31 OBError myCodeError = null; 32 int errorCode = 0; 33 String errorCodeText = ""; 34 String myMessage = getMessage(); 35 if (log4j.isDebugEnabled()) log4j.debug("Message: " + myMessage); 36 int pos = myMessage.indexOf("\""); 38 if (pos != -1) { 39 myMessage = myMessage.substring(pos+1); 40 pos = myMessage.indexOf("\""); 41 if (pos != -1) { 42 myMessage = myMessage.substring(pos+1); 43 pos = myMessage.indexOf("\""); 44 if (pos != -1) { 45 myMessage = myMessage.substring(pos+1); 46 int finalPos = myMessage.indexOf("\""); 47 if (finalPos==-1) finalPos = myMessage.length(); 48 String objectName = myMessage.substring(0, finalPos); 49 if (log4j.isDebugEnabled()) log4j.debug("Object name: " + objectName); 50 pos = objectName.indexOf("."); 51 if (pos!=-1) objectName = objectName.substring(pos+1); 52 if (log4j.isDebugEnabled()) log4j.debug("Object real name: " + objectName); 53 ErrorTextParserPOSTGREData[] constraintData = ErrorTextParserPOSTGREData.select(getConnection(), objectName); 54 if (constraintData!=null && constraintData.length>0) { 56 FieldProvider fldMessage = Utility.locateMessage(getConnection(), constraintData[0].constraintName, getLanguage()); 58 if (fldMessage!=null) { 59 myError = new OBError(); 60 myError.setType((fldMessage.getField("msgtype").equals("E")?"Error":"Warning")); 61 myError.setMessage(fldMessage.getField("msgtext")); 62 return myError; 63 } 64 if (constraintData[0].constraintType.equalsIgnoreCase("C") && !constraintData[0].searchCondition.equals("")) { 66 fldMessage = Utility.locateMessage(getConnection(), constraintData[0].searchCondition, getLanguage()); 68 if (fldMessage!=null) { 69 myError = new OBError(); 70 myError.setType((fldMessage.getField("msgtype").equals("E")?"Error":"Warning")); 71 myError.setMessage(fldMessage.getField("msgtext")); 72 return myError; 73 } else if (!constraintData[0].searchCondition.trim().equals("")) { 74 String searchCond = constraintData[0].searchCondition.trim().toUpperCase(); 75 if (searchCond.endsWith(" IS NOT NULL")) { 76 String columnName = searchCond.substring(0, searchCond.lastIndexOf(" IS NOT NULL")).trim(); 77 columnName = Utility.messageBD(getConnection(), columnName, getLanguage()); 78 String tableName = Utility.messageBD(getConnection(), constraintData[0].tableName, getLanguage()); 79 myError = new OBError(); 80 myError.setType("Error"); 81 myError.setMessage(Utility.messageBD(getConnection(), "NotNullError", getLanguage()) + ": " + tableName + " - " + columnName); 82 return myError; 83 } else if (searchCond.endsWith(" IN ('Y','N')") || searchCond.endsWith(" IN ('Y', 'N')") || searchCond.endsWith(" IN ('N','Y')") || searchCond.endsWith(" IN ('N', 'Y')")) { 84 String columnName = searchCond.substring(0, searchCond.lastIndexOf(" IN (")).trim(); 85 columnName = Utility.messageBD(getConnection(), columnName, getLanguage()); 86 String tableName = Utility.messageBD(getConnection(), constraintData[0].tableName, getLanguage()); 87 myError = new OBError(); 88 myError.setType("Error"); 89 myError.setMessage(Utility.messageBD(getConnection(), "NotYNError", getLanguage()) + ": " + tableName + " - " + columnName); 90 return myError; 91 } 92 } 93 } 95 } 96 } 98 else{ 99 myError = new OBError(); 100 myError.setType("Error"); 101 myError.setMessage(getMessage()); 102 return myError; 103 } 104 } 105 } 106 else{ 107 System.out.println("Error:"+getMessage()); 108 myError = new OBError(); 109 myError.setType("Error"); 110 myError.setMessage(getMessage()); 111 return myError; 112 } 113 if (myCodeError!=null) return myCodeError; 115 else return myError; 116 } 117 } 118 | Popular Tags |