Zolf
asked on
Sending Java Exception error to client
Hi there,
I have this piece of code where on the server I check the quantity in the database and then make a decision to either go ahead with the db operation if quantity is availabe or else to cancel the transaction and show error to the client. But for some reason I get this error when the quantity is not available. Please help.
Here is the method where I check,
Error I get is
I have this piece of code where on the server I check the quantity in the database and then make a decision to either go ahead with the db operation if quantity is availabe or else to cancel the transaction and show error to the client. But for some reason I get this error when the quantity is not available. Please help.
public Future<Void> add(final SendToCompanyFromContractmfg data)
{
final Promise<Void> added = Promise.promise();
anAsyncAction_1(data).onComplete(handler -> {
anAsyncAction_2(data).onComplete(handler_1 -> {
getFProductProfileByID(data.getProduct().toString()).onComplete(handler_2 -> {
checkAvialableMfgInventory(data, handler_2.result()).onComplete(handler_3 -> {
if(handler_3.failed())
{
LOG.debug(" handler_3.failed() "+handler_3.cause());
added.fail(handler_3.cause());
return;
}
else
{
LOG.debug(" Successful!! "+handler_3.result());
added.complete();
}
});
});
});
});
return added.future();
}
Here is the method where I check,
private Future<Boolean> checkAvialableMfgInventory(SendToCompanyFromContractmfg data, JsonArray result)
{
// TODO Auto-generated method stub
final Promise<Boolean> checkAvailable = Promise.promise();
LOG.debug("DATA: " + data);
LOG.debug("Result " + result.encodePrettily());
final JsonArray params = new JsonArray()
.add(data.getProduct())
.add(data.getContractmfg());
LOG.debug("params: " + params.encodePrettily());
String sql = "select z.id, x.productid as product, t.rawmaterialid, z.quantity as quantity, sum(inv.quantity) as sum_quantity, inv.contractmfgid\r\n" +
"from finishproductprofile as z\r\n" +
"inner join product as x on z.productid = x.productid\r\n" +
"inner join raw_material as t on t.rawmaterialid = z.rawmaterialid\r\n" +
"inner join inventory_rawmaterial_contractmfg as inv on inv.rawmaterialid = t.rawmaterialid\r\n" +
"where z.productid = ? and inv.contractmfgid = ? " +
"group by z.id,\r\n" +
"x.productid,\r\n" +
"t.rawmaterialid,\r\n" +
"z.quantity,\r\n" +
"inv.contractmfgid";
sqlClient.queryWithParams(sql, params, ar ->
{
LOG.debug(sql);
if (ar.failed())
{
// Forward error
LOG.error("GET - checkAvialableMfgInventory failed! "+ar.cause());
checkAvailable.fail(ar.cause());
return;
}
if (ar.result().getNumRows() < 1)
{
LOG.error("GET - checkAvialableMfgInventory not found! ");
checkAvailable.complete();
return;
}
// Return result
LOG.debug("ar.result().getNumRows() - "+ar.result().getNumRows());
final List<JsonObject> rows = ar.result().getRows();
//LOG.debug("GET - checkAvialableMfgInventory - "+rows.get(0));
LOG.debug("rows: " + rows);
final JsonArray records = new JsonArray();
rows.forEach(records::add);
LOG.debug("records " + records);
LOG.debug("records " + records.size());
for (int i = 0; i < records.size(); i++)
{
Double qty = records.getJsonObject(i).getDouble("quantity");
Double total = (data.getQty() * qty);
Integer availableQty = records.getJsonObject(i).getInteger("sum_quantity");
LOG.debug("rawmaterial qty: " + qty+" Total qty: " + total);
LOG.debug("availableQty: " + availableQty);
if(availableQty > total)
{
LOG.debug("GOOD TO GO");
}
else
{
LOG.debug("NOT Enough Available Qty!!");
checkAvailable.fail(new IllegalStateException("Not enough quantity available for this transaction"));
return;
}
}
checkAvailable.complete(true);
});
return checkAvailable.future();
}
Error I get is
13:33:36.076 [vert.x-eventloop-thread-2] DEBUG com.dao.SendToCompanyFromContractmfgDAO - availableQty: 335
13:33:36.076 [vert.x-eventloop-thread-2] DEBUG com.dao.SendToCompanyFromContractmfgDAO - GOOD TO GO
13:33:36.076 [vert.x-eventloop-thread-2] DEBUG com.dao.SendToCompanyFromContractmfgDAO - rawmaterial qty: 6.0 Total qty: 60.0
13:33:36.076 [vert.x-eventloop-thread-2] DEBUG com.dao.SendToCompanyFromContractmfgDAO - availableQty: 40
13:33:36.076 [vert.x-eventloop-thread-2] DEBUG com.dao.SendToCompanyFromContractmfgDAO - NOT Enough Available Qty!!
13:33:36.076 [vert.x-eventloop-thread-2] DEBUG com.dao.SendToCompanyFromContractmfgDAO - handler_3.failed() java.lang.IllegalStateException: Not enough quantity available for this transaction
13:33:36.076 [vert.x-eventloop-thread-2] ERROR com.erp.HTTPServerVerticle - ERROR from server: java.lang.IllegalStateException: Not enough quantity available for this transaction
13:33:36.077 [vert.x-eventloop-thread-2] ERROR com.hakimman.erp.HTTPServerVerticle - Failed:
java.lang.IllegalStateException: Not enough quantity available for this transaction
at com.dao.SendToCompanyFromContractmfgDAO.lambda$3(SendToCompanyFromContractmfgDAO.java:180) ~[classes/:?]
at io.vertx.ext.jdbc.impl.JDBCClientImpl.lambda$null$1(JDBCClientImpl.java:175) ~[vertx-jdbc-client-3.9.3.jar:3.9.3]
at io.vertx.core.impl.ContextImpl.executeTask(ContextImpl.java:366) ~[vertx-core-3.9.3.jar:3.9.3]
at io.vertx.core.impl.EventLoopContext.lambda$executeAsync$0(EventLoopContext.java:38) ~[vertx-core-3.9.3.jar:3.9.3]
at io.netty.util.concurrent.AbstractEventExecutor.safeExecute(AbstractEventExecutor.java:164) [netty-common-4.1.49.Final.jar:4.1.49.Final]
at io.netty.util.concurrent.SingleThreadEventExecutor.runAllTasks(SingleThreadEventExecutor.java:472) [netty-common-4.1.49.Final.jar:4.1.49.Final]
at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:500) [netty-transport-4.1.49.Final.jar:4.1.49.Final]
at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:989) [netty-common-4.1.49.Final.jar:4.1.49.Final]
at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74) [netty-common-4.1.49.Final.jar:4.1.49.Final]
at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30) [netty-common-4.1.49.Final.jar:4.1.49.Final]
at java.lang.Thread.run(Unknown Source) [?:1.8.0_111]
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER