Fixed exception when removing triggers and actions. issue 52

This commit is contained in:
Ziver Koc 2017-04-19 17:27:21 +02:00
parent f069aa69e6
commit 1f7889e4f1
2 changed files with 26 additions and 0 deletions

View file

@ -83,6 +83,8 @@ public class TriggerHttpPage extends HalHttpPage {
trigger.save(db); // will save all sub beans also
break;
case "remove_trigger":
if (flow == null)
flow = TriggerFlow.getTriggerFlow(db, trigger);
flow.removeTrigger(trigger);
trigger.delete(db);
break;
@ -104,6 +106,8 @@ public class TriggerHttpPage extends HalHttpPage {
action.save(db); // will save all sub beans also
break;
case "remove_action":
if (flow == null)
flow = TriggerFlow.getTriggerFlow(db, action);
flow.removeAction(action);
action.delete(db);
break;

View file

@ -3,6 +3,7 @@ package se.hal.struct;
import zutil.db.DBConnection;
import zutil.db.bean.DBBean;
import zutil.db.bean.DBBeanSQLResultHandler;
import zutil.db.handler.SimpleSQLResult;
import zutil.log.LogUtil;
import java.sql.PreparedStatement;
@ -33,6 +34,27 @@ public class TriggerFlow extends DBBean {
public static TriggerFlow getTriggerFlow(DBConnection db, int id) throws SQLException {
return DBBean.load(db, TriggerFlow.class, id);
}
/**
* Looks up the parent TriggerFlow for the specified Trigger
*/
public static TriggerFlow getTriggerFlow(DBConnection db, Trigger trigger) throws SQLException {
return getParentFlow(db, "trigger", trigger);
}
/**
* Looks up the parent TriggerFlow for the specified Action
*/
public static TriggerFlow getTriggerFlow(DBConnection db, Action action) throws SQLException {
return getParentFlow(db, "action", action);
}
private static TriggerFlow getParentFlow(DBConnection db, String table, DBBean subObj) throws SQLException {
if (subObj.getId() == null)
return null;
Integer flowId = db.exec("SELECT flow_id FROM "+table+" WHERE id=="+subObj.getId(),
new SimpleSQLResult<Integer>());
if (flowId == null)
return null;
return TriggerFlow.getTriggerFlow(db, flowId);
}