error processing WIP

This commit is contained in:
John Woodlock
2012-05-17 19:28:30 +10:00
parent 3d8439ac98
commit 62ec20112f
@@ -1,7 +1,6 @@
package org.mifosng.platform; package org.mifosng.platform;
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.OutputStream; import java.io.OutputStream;
import java.sql.Connection; import java.sql.Connection;
@@ -15,9 +14,6 @@ import java.util.Map;
import java.util.Set; import java.util.Set;
import javax.sql.DataSource; import javax.sql.DataSource;
import javax.ws.rs.WebApplicationException;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.Status;
import javax.ws.rs.core.StreamingOutput; import javax.ws.rs.core.StreamingOutput;
import org.mifosng.data.AdditionalFieldsSet; import org.mifosng.data.AdditionalFieldsSet;
@@ -43,13 +39,18 @@ public class ReadExtraDataAndReportingServiceImpl implements
private final String reportingMetaDataDB; private final String reportingMetaDataDB;
@Autowired @Autowired
public ReadExtraDataAndReportingServiceImpl(final DataSource dataSource) public ReadExtraDataAndReportingServiceImpl(final DataSource dataSource) {
throws SQLException { try {
this.dataSource = dataSource; this.dataSource = dataSource;
Connection db_connection = dataSource.getConnection(); Connection db_connection = dataSource.getConnection();
this.reportingMetaDataDB = db_connection.getCatalog(); this.reportingMetaDataDB = db_connection.getCatalog();
db_connection.close(); db_connection.close();
db_connection = null; db_connection = null;
} catch (SQLException e) {
throw new PlatformDataIntegrityException("error.msg.sql.error",
"JPWWRONGMSG - " + e.getMessage(), "DataSource: "
+ dataSource);
}
} }
@Override @Override
@@ -59,8 +60,7 @@ public class ReadExtraDataAndReportingServiceImpl implements
return new StreamingOutput() { return new StreamingOutput() {
@Override @Override
public void write(OutputStream out) throws IOException, public void write(OutputStream out) {
WebApplicationException {
try { try {
GenericResultset result = retrieveGenericResultset(name, GenericResultset result = retrieveGenericResultset(name,
@@ -81,7 +81,9 @@ public class ReadExtraDataAndReportingServiceImpl implements
// out.flush(); // out.flush();
// out.close(); // out.close();
} catch (Exception e) { } catch (Exception e) {
throw new WebApplicationException(e); throw new PlatformDataIntegrityException(
"error.msg.exception.error", "JPWWRONGMSG - "
+ e.getMessage());
} }
} }
}; };
@@ -446,8 +448,9 @@ public class ReadExtraDataAndReportingServiceImpl implements
db_statement2.close(); db_statement2.close();
db_statement2 = null; db_statement2 = null;
sql = "select " + selectFieldList + " from `" + type + "` t left join `" + fullDatasetName + "` s on s.id = t.id " sql = "select " + selectFieldList + " from `" + type
+ " where t.id = " + id; + "` t left join `" + fullDatasetName
+ "` s on s.id = t.id " + " where t.id = " + id;
Statement db_statement3 = db_connection.createStatement(); Statement db_statement3 = db_connection.createStatement();
ResultSet rs = db_statement3.executeQuery(sql); ResultSet rs = db_statement3.executeQuery(sql);
@@ -473,7 +476,8 @@ public class ReadExtraDataAndReportingServiceImpl implements
} else { } else {
throw new PlatformResourceNotFoundException( throw new PlatformResourceNotFoundException(
"error.msg.type.value.not.found", "error.msg.type.value.not.found",
"Additional Fields Type: " + type + " Id Not Found for " + id); "Additional Fields Type: " + type
+ " Id Not Found for " + id);
} }
db_statement3.close(); db_statement3.close();
db_statement3 = null; db_statement3 = null;
@@ -544,8 +548,10 @@ public class ReadExtraDataAndReportingServiceImpl implements
db_connection.close(); db_connection.close();
db_connection = null; db_connection = null;
} catch (SQLException e) { } catch (SQLException e) {
logger.info("SQL: " + saveSql + " ERROR: " + e.toString()); throw new PlatformDataIntegrityException("error.msg.sql.error",
throw new InvalidSqlException(e, e.toString()); "JPWWRONGMSG - " + e.getMessage(),
"Additional Fields Type: " + type + " Set: " + set
+ " Id: " + id);
} }
} }
@@ -557,9 +563,10 @@ public class ReadExtraDataAndReportingServiceImpl implements
String transType = queryParams.get("ed_transType"); String transType = queryParams.get("ed_transType");
if (!(transType.equals("E") || transType.equals("A"))) { if (!(transType.equals("E") || transType.equals("A"))) {
errMsg = "transType not E or A - Value is: " + transType; errMsg = "transType not E or A - Value is: " + transType;
logger.info(errMsg); throw new PlatformDataIntegrityException("error.msg.sql.error",
throw new WebApplicationException(Response "JPWWRONGMSG - " + errMsg,
.status(Status.BAD_REQUEST).entity(errMsg).build()); "Additional Fields Full Set Name: " + fullSetName
+ " Id: " + id);
} }
String pValue = ""; String pValue = "";