use of org.adempiere.pipo.exception.DatabaseAccessException in project adempiere by adempiere.
the class ProcessAccessElementHandler method startElement.
public void startElement(Properties ctx, Element element) throws SAXException {
String elementValue = element.getElementValue();
log.info(elementValue);
int roleid = 0;
int processid = 0;
StringBuffer sqlB = null;
Attributes atts = element.attributes;
if (atts.getValue("rolename") != null) {
String name = atts.getValue("rolename");
sqlB = new StringBuffer("SELECT AD_Role_ID FROM AD_Role WHERE Name= ?");
roleid = DB.getSQLValue(getTrxName(ctx), sqlB.toString(), name);
}
if (atts.getValue("processname") != null) {
String name = atts.getValue("processname");
sqlB = new StringBuffer("SELECT AD_Process_ID FROM AD_Process WHERE Name= ?");
processid = DB.getSQLValue(getTrxName(ctx), sqlB.toString(), name);
}
sqlB = new StringBuffer("SELECT count(*) FROM AD_Process_Access WHERE AD_Role_ID=? and AD_Process_ID=?");
int count = DB.getSQLValue(getTrxName(ctx), sqlB.toString(), roleid, processid);
int AD_Backup_ID = -1;
String Object_Status = null;
if (count > 0) {
Object_Status = "Update";
sqlB = new StringBuffer("UPDATE AD_Process_Access ").append("SET isActive = '" + atts.getValue("isActive")).append("', isReadWrite = '" + atts.getValue("isReadWrite")).append("' WHERE AD_Role_ID = " + roleid).append(" and AD_Process_ID = " + processid);
int no = DB.executeUpdate(sqlB.toString(), getTrxName(ctx));
if (no == -1) {
log.info("Update to process access failed");
throw new DatabaseAccessException("Update to process access failed");
}
} else {
Object_Status = "New";
AD_Backup_ID = 0;
sqlB = new StringBuffer("INSERT INTO AD_Process_Access").append("(AD_Client_ID, AD_Org_ID, CreatedBy, UpdatedBy, ").append("AD_Role_ID, AD_Process_ID, isActive, isReadWrite) ").append("VALUES(").append(" " + Env.getAD_Client_ID(ctx)).append(", " + Env.getAD_Org_ID(ctx)).append(", " + Env.getAD_User_ID(ctx)).append(", " + Env.getAD_User_ID(ctx)).append(", " + roleid).append(", " + processid).append(", '" + atts.getValue("isActive")).append("', '" + atts.getValue("isReadWrite") + "')");
int no = DB.executeUpdate(sqlB.toString(), getTrxName(ctx));
if (no == -1) {
log.info("Insert to process access failed");
throw new DatabaseAccessException("Insert to process access failed");
}
}
}
use of org.adempiere.pipo.exception.DatabaseAccessException in project adempiere by adempiere.
the class ProcessElementHandler method create.
public void create(Properties ctx, TransformerHandler document) throws SAXException {
int AD_Process_ID = Env.getContextAsInt(ctx, "AD_Process_ID");
if (processes.contains(AD_Process_ID))
return;
processes.add(AD_Process_ID);
PackOut packOut = (PackOut) ctx.get("PackOutProcess");
String sqlW = "SELECT AD_Process_ID FROM AD_PROCESS WHERE AD_PROCESS_ID = " + AD_Process_ID;
AttributesImpl atts = new AttributesImpl();
PreparedStatement pstmt1 = null;
pstmt1 = DB.prepareStatement(sqlW, getTrxName(ctx));
try {
ResultSet rs1 = pstmt1.executeQuery();
while (rs1.next()) {
X_AD_Process m_Process = new X_AD_Process(ctx, rs1.getInt("AD_Process_ID"), null);
log.log(Level.INFO, "AD_ReportView_ID: " + m_Process.getAD_Process_ID());
if (m_Process.isReport() && m_Process.getAD_ReportView_ID() > 0) {
packOut.createReportview(m_Process.getAD_ReportView_ID(), document);
}
if (m_Process.isReport() && m_Process.getAD_PrintFormat_ID() > 0) {
packOut.createPrintFormat(m_Process.getAD_PrintFormat_ID(), document);
}
if (m_Process.getAD_Workflow_ID() > 0) {
packOut.createWorkflow(m_Process.getAD_Workflow_ID(), document);
}
if (m_Process.getAD_Form_ID() > 0) {
packOut.createForm(m_Process.getAD_Form_ID(), document);
}
if (m_Process.getAD_Browse_ID() > 0) {
packOut.createBrowse(m_Process.getAD_Browse_ID(), document);
}
createProcessBinding(atts, m_Process);
document.startElement("", "", "process", atts);
// processpara tags
String sqlP = "SELECT * FROM AD_PROCESS_PARA WHERE AD_PROCESS_ID = " + AD_Process_ID + " ORDER BY " + X_AD_Process_Para.COLUMNNAME_SeqNo + "," + X_AD_Process_Para.COLUMNNAME_AD_Process_Para_ID;
PreparedStatement pstmtP = null;
pstmtP = DB.prepareStatement(sqlP, getTrxName(ctx));
try {
ResultSet rsP = pstmtP.executeQuery();
while (rsP.next()) {
if (rsP.getInt("AD_Reference_ID") > 0)
packOut.createReference(rsP.getInt("AD_Reference_ID"), document);
if (rsP.getInt("AD_Reference_Value_ID") > 0)
packOut.createReference(rsP.getInt("AD_Reference_Value_ID"), document);
if (rsP.getInt("AD_Val_Rule_ID") > 0)
packOut.createDynamicRuleValidation(rsP.getInt("AD_Val_Rule_ID"), document);
createProcessPara(ctx, document, rsP.getInt("AD_Process_Para_ID"));
}
rsP.close();
pstmtP.close();
pstmtP = null;
} catch (Exception e) {
log.log(Level.SEVERE, "getProcess_Para", e);
if (e instanceof SAXException)
throw (SAXException) e;
else if (e instanceof SQLException)
throw new DatabaseAccessException("Failed to export process.", e);
else if (e instanceof RuntimeException)
throw (RuntimeException) e;
else
throw new RuntimeException("Failed to export process.", e);
} finally {
try {
if (pstmtP != null)
pstmtP.close();
} catch (Exception e) {
}
pstmtP = null;
}
document.endElement("", "", "process");
}
rs1.close();
pstmt1.close();
pstmt1 = null;
} catch (Exception e) {
log.log(Level.SEVERE, "getProcess", e);
} finally {
try {
if (pstmt1 != null)
pstmt1.close();
} catch (Exception e) {
}
pstmt1 = null;
}
}
use of org.adempiere.pipo.exception.DatabaseAccessException in project adempiere by adempiere.
the class WorkflowAccessElementHandler method startElement.
public void startElement(Properties ctx, Element element) throws SAXException {
String elementValue = element.getElementValue();
log.info(elementValue);
int roleid = 0;
int workflowid = 0;
StringBuffer sqlB = null;
Attributes atts = element.attributes;
if (getStringValue(atts, "rolename") != null) {
String name = atts.getValue("rolename");
sqlB = new StringBuffer("SELECT AD_Role_ID FROM AD_Role WHERE Name= ?");
roleid = DB.getSQLValue(getTrxName(ctx), sqlB.toString(), name);
}
if (getStringValue(atts, "workflowname") != null) {
String name = atts.getValue("workflowname");
sqlB = new StringBuffer("SELECT AD_Workflow_ID FROM AD_Workflow WHERE Name= ?");
workflowid = DB.getSQLValue(getTrxName(ctx), sqlB.toString(), name);
}
sqlB = new StringBuffer("SELECT count(*) FROM AD_Workflow_Access WHERE AD_Role_ID=? and AD_Workflow_ID=?");
int count = DB.getSQLValue(getTrxName(ctx), sqlB.toString(), roleid, workflowid);
int AD_Backup_ID = -1;
String Object_Status = null;
if (count > 0) {
Object_Status = "Update";
sqlB = new StringBuffer("UPDATE AD_Workflow_Access ").append("SET isActive = '" + atts.getValue("isActive")).append("', isReadWrite = '" + atts.getValue("isReadWrite")).append("' WHERE AD_Role_ID = " + roleid).append(" and AD_Workflow_ID = " + workflowid);
int no = DB.executeUpdate(sqlB.toString(), getTrxName(ctx));
if (no == -1) {
log.info("Update to workflow access failed");
throw new DatabaseAccessException("Update to workflow access failed");
}
} else {
Object_Status = "New";
AD_Backup_ID = 0;
sqlB = new StringBuffer("INSERT INTO AD_Workflow_Access").append("(AD_Client_ID, AD_Org_ID, CreatedBy, UpdatedBy, ").append("AD_Role_ID, AD_Workflow_ID, isActive, isReadWrite) ").append("VALUES(").append(" " + Env.getAD_Client_ID(ctx)).append(", " + Env.getAD_Org_ID(ctx)).append(", " + Env.getAD_User_ID(ctx)).append(", " + Env.getAD_User_ID(ctx)).append(", " + roleid).append(", " + workflowid).append(", '" + atts.getValue("isActive")).append("', '" + atts.getValue("isReadWrite") + "')");
int no = DB.executeUpdate(sqlB.toString(), getTrxName(ctx));
if (no == -1) {
log.info("Insert to workflow access failed");
throw new DatabaseAccessException("Insert to workflow access failed");
}
}
}
use of org.adempiere.pipo.exception.DatabaseAccessException in project adempiere by adempiere.
the class ReferenceElementHandler method create.
public void create(Properties ctx, TransformerHandler document) throws SAXException {
int Reference_id = Env.getContextAsInt(ctx, X_AD_Reference.COLUMNNAME_AD_Reference_ID);
if (references.contains(Reference_id))
return;
references.add(Reference_id);
AttributesImpl atts = new AttributesImpl();
String sql = "SELECT * FROM AD_Reference WHERE AD_Reference_ID= " + Reference_id;
PreparedStatement pstmt = null;
pstmt = DB.prepareStatement(sql, getTrxName(ctx));
try {
ResultSet rs = pstmt.executeQuery();
while (rs.next()) {
X_AD_Reference m_Reference = new X_AD_Reference(ctx, rs.getInt("AD_Reference_ID"), null);
createReferenceBinding(atts, m_Reference);
document.startElement("", "", "reference", atts);
if (m_Reference.getValidationType().compareTo("L") == 0) {
String sql1 = "SELECT * FROM AD_Ref_List WHERE AD_Reference_ID= " + Reference_id + " ORDER BY Value, AD_Ref_List_ID";
PreparedStatement pstmt1 = null;
pstmt1 = DB.prepareStatement(sql1, getTrxName(ctx));
try {
ResultSet rs1 = pstmt1.executeQuery();
while (rs1.next()) {
createReferenceList(ctx, document, rs1.getInt("AD_REF_LIST_ID"));
}
rs1.close();
pstmt1.close();
pstmt1 = null;
} catch (Exception e) {
log.log(Level.SEVERE, e.getLocalizedMessage(), e);
if (e instanceof SAXException)
throw (SAXException) e;
else if (e instanceof SQLException)
throw new DatabaseAccessException("Failed to export Reference.", e);
else if (e instanceof RuntimeException)
throw (RuntimeException) e;
else
throw new RuntimeException("Failed to export Reference.", e);
} finally {
try {
if (pstmt1 != null)
pstmt1.close();
} catch (Exception e) {
}
pstmt1 = null;
}
} else if (m_Reference.getValidationType().compareTo("T") == 0) {
String sql1 = "SELECT AD_Reference_ID FROM AD_Ref_Table WHERE AD_Reference_ID = " + Reference_id;
PreparedStatement pstmt1 = null;
pstmt1 = DB.prepareStatement(sql1, getTrxName(ctx));
try {
ResultSet rs1 = pstmt1.executeQuery();
while (rs1.next()) {
createReferenceTable(ctx, document, Reference_id);
}
rs1.close();
pstmt1.close();
pstmt1 = null;
} catch (Exception e) {
log.log(Level.SEVERE, "getRef_Table", e);
} finally {
try {
if (pstmt1 != null)
pstmt1.close();
} catch (Exception e) {
}
pstmt1 = null;
}
}
document.endElement("", "", "reference");
}
rs.close();
pstmt.close();
pstmt = null;
} catch (Exception e) {
log.log(Level.SEVERE, "getRefence", e);
} finally {
try {
if (pstmt != null)
pstmt.close();
} catch (Exception e) {
}
pstmt = null;
}
}
use of org.adempiere.pipo.exception.DatabaseAccessException in project adempiere by adempiere.
the class TaskAccessElementHandler method startElement.
public void startElement(Properties ctx, Element element) throws SAXException {
String elementValue = element.getElementValue();
log.info(elementValue);
int roleid = 0;
int taskid = 0;
StringBuffer sqlB = null;
Attributes atts = element.attributes;
if (getStringValue(atts, "rolename") != null) {
String name = atts.getValue("rolename");
sqlB = new StringBuffer("SELECT AD_Role_ID FROM AD_Role WHERE Name= ?");
roleid = DB.getSQLValue(getTrxName(ctx), sqlB.toString(), name);
}
if (getStringValue(atts, "taskname") != null) {
String name = atts.getValue("taskname");
sqlB = new StringBuffer("SELECT AD_Task_ID FROM AD_Task WHERE Name= ?");
taskid = DB.getSQLValue(getTrxName(ctx), sqlB.toString(), name);
}
sqlB = new StringBuffer("SELECT count(*) FROM AD_Task_Access WHERE AD_Role_ID=? and AD_Task_ID=?");
int count = DB.getSQLValue(getTrxName(ctx), sqlB.toString(), roleid, taskid);
int AD_Backup_ID = -1;
String Object_Status = null;
if (count > 0) {
Object_Status = "Update";
sqlB = new StringBuffer("UPDATE AD_Task_Access ").append("SET isActive = '" + atts.getValue("isActive")).append("', isReadWrite = '" + atts.getValue("isReadWrite")).append("' WHERE AD_Role_ID = " + roleid).append(" and AD_Task_ID = " + taskid);
int no = DB.executeUpdate(sqlB.toString(), getTrxName(ctx));
if (no == -1) {
log.info("Update to task access failed");
throw new DatabaseAccessException("Update to task access failed");
}
} else {
Object_Status = "New";
AD_Backup_ID = 0;
sqlB = new StringBuffer("INSERT INTO AD_Task_Access").append("(AD_Client_ID, AD_Org_ID, CreatedBy, UpdatedBy, ").append("AD_Role_ID, AD_Task_ID, isActive, isReadWrite) ").append("VALUES(").append(" " + Env.getAD_Client_ID(ctx)).append(", " + Env.getAD_Org_ID(ctx)).append(", " + Env.getAD_User_ID(ctx)).append(", " + Env.getAD_User_ID(ctx)).append(", " + roleid).append(", " + taskid).append(", '" + atts.getValue("isActive")).append("', '" + atts.getValue("isReadWrite") + "')");
int no = DB.executeUpdate(sqlB.toString(), getTrxName(ctx));
if (no == -1) {
log.info("Insert to task access failed");
throw new DatabaseAccessException("Insert to task access failed");
}
}
}
Aggregations