use of org.xml.sax.Attributes in project adempiere by adempiere.
the class SQLStatementElementHandler method startElement.
public void startElement(Properties ctx, Element element) throws SAXException {
String elementValue = element.getElementValue();
int AD_Backup_ID = -1;
String Object_Status = null;
log.info(elementValue);
Attributes atts = element.attributes;
String DBType = atts.getValue("DBType");
String sql = atts.getValue("statement").trim();
if (sql.endsWith(";"))
sql = sql.substring(0, sql.length() - 1);
PreparedStatement pstmt = DB.prepareStatement(sql, getTrxName(ctx));
try {
if (DBType.equals("ALL")) {
int n = pstmt.executeUpdate();
log.info("Executed SQL Statement: " + atts.getValue("statement"));
} else if (DB.isOracle() == true && DBType.equals("Oracle")) {
pstmt.executeUpdate();
log.info("Executed SQL Statement for Oracle: " + atts.getValue("statement"));
} else if (DB.isPostgreSQL() && (DBType.equals("Postgres") || // backward compatibility with old packages developed by hand
DBType.equals("PostgreSQL"))) {
// Avoid convert layer - command specific for postgresql
//
// pstmt = DB.prepareStatement(sql, null);
// pstmt.executeUpdate();
//
Connection m_con = DB.getConnectionRW(true);
try {
Statement stmt = m_con.createStatement();
int n = stmt.executeUpdate(atts.getValue("statement"));
log.info("Executed SQL Statement for PostgreSQL: " + atts.getValue("statement"));
// Postgres needs to commit DDL statements
if (m_con != null && !m_con.getAutoCommit())
m_con.commit();
stmt.close();
} finally {
m_con.close();
}
}
pstmt.close();
} catch (Exception e) {
log.log(Level.SEVERE, "SQLSatement", e);
}
}
use of org.xml.sax.Attributes in project adempiere by adempiere.
the class TabElementHandler method startElement.
public void startElement(Properties ctx, Element element) throws SAXException {
String elementValue = element.getElementValue();
Attributes atts = element.attributes;
log.info(elementValue + " " + atts.getValue("ADTabNameID"));
String entitytype = atts.getValue("EntityType");
if (isProcessElement(ctx, entitytype)) {
if (element.parent != null && element.parent.getElementValue().equals("window") && element.parent.defer) {
element.defer = true;
return;
}
String name = atts.getValue("ADTabNameID");
int tableid = get_IDWithColumn(ctx, "AD_Table", "TableName", atts.getValue("ADTableNameID"));
if (tableid <= 0) {
element.defer = true;
return;
}
int windowid = 0;
if (element.parent != null && element.parent.getElementValue().equals("window") && element.parent.recordId > 0) {
windowid = element.parent.recordId;
} else {
windowid = get_ID(ctx, "AD_Window", atts.getValue("ADWindowNameID"));
if (element.parent != null && element.parent.getElementValue().equals("window") && windowid > 0) {
element.parent.recordId = windowid;
}
}
if (windowid <= 0) {
element.defer = true;
return;
}
StringBuffer sqlB = new StringBuffer("select AD_Tab_ID from AD_Tab where AD_Window_ID = " + windowid + " and Name = '" + name + "'" + " and AD_Table_ID = ?");
int id = DB.getSQLValue(getTrxName(ctx), sqlB.toString(), tableid);
MTab m_Tab = new MTab(ctx, id, getTrxName(ctx));
if (id <= 0 && atts.getValue("AD_Tab_ID") != null && Integer.parseInt(atts.getValue("AD_Tab_ID")) <= PackOut.MAX_OFFICIAL_ID)
m_Tab.setAD_Tab_ID(Integer.parseInt(atts.getValue("AD_Tab_ID")));
int AD_Backup_ID = -1;
String Object_Status = null;
if (id > 0) {
AD_Backup_ID = copyRecord(ctx, "AD_Tab", m_Tab);
Object_Status = "Update";
} else {
Object_Status = "New";
AD_Backup_ID = 0;
}
sqlB = null;
m_Tab.setName(name);
id = 0;
if (getStringValue(atts, "ADColumnSortYesNoNameID") != null) {
name = atts.getValue("ADColumnSortYesNoNameID");
id = get_IDWithMasterAndColumn(ctx, "AD_Column", "ColumnName", name, MTable.Table_Name, get_IDWithColumn(ctx, MTable.Table_Name, MTable.COLUMNNAME_TableName, atts.getValue("ADTableNameID")));
m_Tab.setAD_ColumnSortYesNo_ID(id);
}
if (getStringValue(atts, "ADColumnSortOrderNameID") != null) {
name = atts.getValue("ADColumnSortOrderNameID");
id = get_IDWithMasterAndColumn(ctx, "AD_Column", "ColumnName", name, MTable.Table_Name, get_IDWithColumn(ctx, MTable.Table_Name, MTable.COLUMNNAME_TableName, atts.getValue("ADTableNameID")));
m_Tab.setAD_ColumnSortOrder_ID(id);
}
if (getStringValue(atts, "ADImageNameID") != null) {
name = atts.getValue("ADImageNameID");
id = get_IDWithColumn(ctx, "AD_Image", "Name", name);
m_Tab.setAD_Image_ID(id);
}
if (getStringValue(atts, "ADProcessNameID") != null) {
name = atts.getValue("ADProcessNameID");
if (name != null && name.trim().length() > 0) {
id = get_IDWithColumn(ctx, "AD_Process", "Name", name);
if (id <= 0) {
element.defer = true;
element.unresolved = "AD_Process: " + name;
return;
}
m_Tab.setAD_Process_ID(id);
}
}
if (getStringValue(atts, "ADTableNameID") != null) {
name = atts.getValue("ADTableNameID");
id = get_IDWithColumn(ctx, "AD_Table", "TableName", name);
m_Tab.setAD_Table_ID(id);
}
if (getStringValue(atts, "ADColumnNameID") != null) {
name = atts.getValue("ADColumnNameID");
id = get_IDWithMasterAndColumn(ctx, "AD_Column", "ColumnName", atts.getValue("ADColumnNameID"), "AD_Table", m_Tab.getAD_Table_ID());
if (id <= 0) /** TODO Check PackOut Version -- 005 */
{
id = get_IDWithMasterAndColumn(ctx, "AD_Column", "Name", atts.getValue("ADColumnNameID"), "AD_Table", m_Tab.getAD_Table_ID());
}
m_Tab.setAD_Column_ID(id);
if (id <= 0) {
log.warning("@NotFound@ @AD_Column_ID@ - @Name@:" + name + ", @AD_Table_ID@:" + atts.getValue("ADTableNameID"));
}
}
m_Tab.setAD_Window_ID(windowid);
if (getStringValue(atts, "IncludedTabNameID") != null) {
name = atts.getValue("IncludedTabNameID");
id = get_IDWithColumn(ctx, "AD_Tab", "Name", name);
m_Tab.setIncluded_Tab_ID(id);
}
m_Tab.setCommitWarning(atts.getValue("CommitWarning"));
m_Tab.setDescription(getStringValue(atts, "Description"));
m_Tab.setEntityType(atts.getValue("EntityType"));
m_Tab.setHasTree(Boolean.valueOf(atts.getValue("isHasTree")).booleanValue());
m_Tab.setHelp(getStringValue(atts, "Help"));
m_Tab.setIsActive(atts.getValue("isActive") != null ? Boolean.valueOf(atts.getValue("isActive")).booleanValue() : true);
m_Tab.setImportFields(atts.getValue("ImportFields"));
m_Tab.setIsInfoTab(Boolean.valueOf(atts.getValue("isInfoTab")).booleanValue());
m_Tab.setIsReadOnly(Boolean.valueOf(atts.getValue("isReadOnly")).booleanValue());
m_Tab.setIsSingleRow(Boolean.valueOf(atts.getValue("isSingleRow")).booleanValue());
m_Tab.setIsSortTab(Boolean.valueOf(atts.getValue("isSortTab")).booleanValue());
m_Tab.setIsTranslationTab(Boolean.valueOf(atts.getValue("IsTranslationTab")).booleanValue());
m_Tab.setName(atts.getValue("Name"));
m_Tab.setOrderByClause(getStringValue(atts, "OrderByClause"));
m_Tab.setProcessing(false);
m_Tab.setSeqNo(Integer.parseInt(atts.getValue("SeqNo")));
m_Tab.setTabLevel(Integer.parseInt(atts.getValue("TabLevel")));
m_Tab.setWhereClause(getStringValue(atts, "WhereClause"));
if (getStringValue(atts, "ReadOnlyLogic") != null) {
m_Tab.setReadOnlyLogic(atts.getValue("ReadOnlyLogic"));
}
if (getStringValue(atts, "DisplayLogic") != null) {
m_Tab.setDisplayLogic(atts.getValue("DisplayLogic"));
}
if (getStringValue(atts, "isInsertRecord") != null) {
m_Tab.setIsInsertRecord(Boolean.valueOf(atts.getValue("isInsertRecord")).booleanValue());
}
if (getStringValue(atts, "isAdvancedTab") != null) {
m_Tab.setIsAdvancedTab(Boolean.valueOf(atts.getValue("isAdvancedTab")).booleanValue());
}
if (m_Tab.save(getTrxName(ctx)) == true) {
record_log(ctx, 1, m_Tab.getName(), "Tab", m_Tab.get_ID(), AD_Backup_ID, Object_Status, "AD_Tab", get_IDWithColumn(ctx, "AD_Table", "TableName", "AD_Tab"));
element.recordId = m_Tab.getAD_Tab_ID();
} else {
record_log(ctx, 0, m_Tab.getName(), "Tab", m_Tab.get_ID(), AD_Backup_ID, Object_Status, "AD_Tab", get_IDWithColumn(ctx, "AD_Table", "TableName", "AD_Tab"));
throw new POSaveFailedException("Tab");
}
} else {
element.skip = true;
}
}
use of org.xml.sax.Attributes in project adempiere by adempiere.
the class WorkflowNodeNextConditionElementHandler method startElement.
public void startElement(Properties ctx, Element element) throws SAXException {
Attributes atts = element.attributes;
String entitytype = atts.getValue("EntityType");
log.info("entitytype " + atts.getValue("EntityType"));
if (isProcessElement(ctx, entitytype)) {
if (element.parent != null && element.parent.skip) {
element.skip = true;
return;
}
String workflowName = atts.getValue("ADWorkflowNameID");
int workflowId = get_IDWithColumn(ctx, "AD_Workflow", "name", workflowName);
if (workflowId <= 0) {
element.defer = true;
element.unresolved = "AD_Workflow: " + workflowName;
return;
}
String workflowNodeName = atts.getValue("ADWorkflowNodeNameID");
String workflowNodeNextName = atts.getValue("ADWorkflowNodeNextNameID");
StringBuffer sqlB = new StringBuffer("SELECT ad_wf_node_id FROM AD_WF_Node WHERE AD_Workflow_ID=? and Name =?");
int wfNodeId = DB.getSQLValue(getTrxName(ctx), sqlB.toString(), workflowId, workflowNodeName);
if (wfNodeId <= 0) {
element.unresolved = "AD_WF_Node=" + workflowNodeName;
element.defer = true;
return;
}
int wfNodeNextId = DB.getSQLValue(getTrxName(ctx), sqlB.toString(), workflowId, workflowNodeNextName);
if (wfNodeNextId <= 0) {
element.unresolved = "AD_WF_Node=" + workflowNodeNextName;
element.defer = true;
return;
}
String columnName = atts.getValue("ADColumnNameID");
int tableId = DB.getSQLValue(getTrxName(ctx), "SELECT AD_Table_ID FROM AD_Workflow WHERE AD_Workflow_ID=?", workflowId);
int columnId = get_IDWithMasterAndColumn(ctx, "AD_Column", "ColumnName", columnName, "AD_Table", tableId);
if (columnId <= 0 && tableId > 0 && columnName != null && columnName.length() > 0) {
element.unresolved = "AD_Column=" + columnName;
element.defer = true;
return;
}
sqlB = new StringBuffer("SELECT ad_wf_nodenext_id FROM AD_WF_NodeNext WHERE ad_wf_node_id =? and ad_wf_next_id =?");
int wfNodeNextTablePKId = DB.getSQLValue(getTrxName(ctx), sqlB.toString(), wfNodeId, wfNodeNextId);
sqlB = new StringBuffer("SELECT ad_wf_nextcondition_id FROM AD_WF_NextCondition WHERE ad_wf_nodenext_id =?");
int id = DB.getSQLValue(getTrxName(ctx), sqlB.toString(), wfNodeNextTablePKId);
MWFNextCondition m_WFNodeNextCondition = new MWFNextCondition(ctx, id, getTrxName(ctx));
int AD_Backup_ID = -1;
String Object_Status = null;
if (id <= 0 && atts.getValue("AD_WF_NextCondition_ID") != null && Integer.parseInt(atts.getValue("AD_WF_NextCondition_ID")) <= PackOut.MAX_OFFICIAL_ID)
m_WFNodeNextCondition.setAD_WF_NextCondition_ID(Integer.parseInt(atts.getValue("AD_WF_NextCondition_ID")));
if (id > 0) {
AD_Backup_ID = copyRecord(ctx, "AD_WF_NextCondition", m_WFNodeNextCondition);
Object_Status = "Update";
} else {
Object_Status = "New";
AD_Backup_ID = 0;
}
m_WFNodeNextCondition.setAD_WF_NodeNext_ID(wfNodeNextTablePKId);
m_WFNodeNextCondition.setIsActive(atts.getValue("isActive") != null ? Boolean.valueOf(atts.getValue("isActive")).booleanValue() : true);
m_WFNodeNextCondition.setAD_WF_NodeNext_ID(wfNodeNextTablePKId);
m_WFNodeNextCondition.setSeqNo(Integer.valueOf(atts.getValue("SeqNo")));
m_WFNodeNextCondition.setEntityType(atts.getValue("EntityType"));
m_WFNodeNextCondition.setAndOr(atts.getValue("AndOr"));
m_WFNodeNextCondition.setOperation(atts.getValue("Operation"));
m_WFNodeNextCondition.setValue(atts.getValue("Value"));
m_WFNodeNextCondition.setValue2(atts.getValue("Value2"));
m_WFNodeNextCondition.setAD_Column_ID(columnId);
log.info("about to execute m_WFNodeNextCondition.save");
if (m_WFNodeNextCondition.save(getTrxName(ctx)) == true) {
log.info("m_WFNodeNextCondition save success");
record_log(ctx, 1, String.valueOf(m_WFNodeNextCondition.get_ID()), "WFNextCondition", m_WFNodeNextCondition.get_ID(), AD_Backup_ID, Object_Status, "AD_WF_NextCondition", get_IDWithColumn(ctx, "AD_Table", "TableName", "AD_WF_NextCondition"));
} else {
log.info("m_WFNodeNextCondition save failure");
record_log(ctx, 0, String.valueOf(m_WFNodeNextCondition.get_ID()), "WFNextCondition", m_WFNodeNextCondition.get_ID(), AD_Backup_ID, Object_Status, "AD_WF_NextCondition", get_IDWithColumn(ctx, "AD_Table", "TableName", "AD_WF_NextCondition"));
throw new POSaveFailedException("WorkflowNodeNextCondition");
}
} else {
element.skip = true;
}
}
use of org.xml.sax.Attributes in project adempiere by adempiere.
the class WorkflowElementHandler method startElement.
public void startElement(Properties ctx, Element element) throws SAXException {
Attributes atts = element.attributes;
String elementValue = element.getElementValue();
log.info(elementValue + " " + atts.getValue("Name"));
String entitytype = atts.getValue("EntityType");
log.info("entitytype " + atts.getValue("EntityType"));
if (isProcessElement(ctx, entitytype)) {
String workflowName = atts.getValue("Name");
int id = get_IDWithColumn(ctx, "AD_Workflow", "name", workflowName);
if (id > 0 && workflows.contains(id)) {
element.skip = true;
return;
}
MWorkflow m_Workflow = new MWorkflow(ctx, id, getTrxName(ctx));
int AD_Backup_ID = -1;
String Object_Status = null;
if (id <= 0 && atts.getValue("AD_Workflow_ID") != null && Integer.parseInt(atts.getValue("AD_Workflow_ID")) <= PackOut.MAX_OFFICIAL_ID)
m_Workflow.setAD_Workflow_ID(Integer.parseInt(atts.getValue("AD_Workflow_ID")));
if (id > 0) {
AD_Backup_ID = copyRecord(ctx, "AD_Workflow", m_Workflow);
Object_Status = "Update";
} else {
Object_Status = "New";
AD_Backup_ID = 0;
}
String name = atts.getValue("ADTableNameID");
if (name != null && name.trim().length() > 0) {
id = get_IDWithColumn(ctx, "AD_Table", "TableName", name);
if (id <= 0) {
element.defer = true;
element.unresolved = "AD_Table: " + name;
return;
}
m_Workflow.setAD_Table_ID(id);
}
name = atts.getValue("ADWorkflowResponsibleNameID");
if (name != null && name.trim().length() > 0) {
id = get_IDWithColumn(ctx, "AD_WF_Responsible", "Name", name);
if (id <= 0) {
element.defer = true;
element.unresolved = "AD_WF_Responsible: " + name;
return;
}
m_Workflow.setAD_WF_Responsible_ID(id);
}
name = atts.getValue("ADWorkflowProcessorNameID");
if (name != null && name.trim().length() > 0) {
id = get_IDWithColumn(ctx, "AD_WorkflowProcessor", "Name", name);
if (id <= 0) {
element.defer = true;
element.unresolved = "AD_WorkflowProcessor: " + name;
return;
}
m_Workflow.setAD_WorkflowProcessor_ID(id);
}
m_Workflow.setValue(atts.getValue("Value"));
m_Workflow.setName(workflowName);
m_Workflow.setIsBetaFunctionality(Boolean.valueOf(atts.getValue("isBetaFunctionality")).booleanValue());
m_Workflow.setAccessLevel(atts.getValue("AccessLevel"));
m_Workflow.setDescription(getStringValue(atts, "Description"));
m_Workflow.setHelp(getStringValue(atts, "Help"));
m_Workflow.setDurationUnit(getStringValue(atts, "DurationUnit"));
m_Workflow.setAuthor(getStringValue(atts, "Author"));
if (getStringValue(atts, "Version") != null)
m_Workflow.setVersion(Integer.valueOf(atts.getValue("Version")));
if (getStringValue(atts, "Priority") != null)
m_Workflow.setPriority(Integer.valueOf(atts.getValue("Priority")));
if (getStringValue(atts, "Limit") != null)
m_Workflow.setLimit(Integer.valueOf(atts.getValue("Limit")));
if (getStringValue(atts, "Duration") != null)
m_Workflow.setDuration(Integer.valueOf(atts.getValue("Duration")));
if (getStringValue(atts, "Cost") != null)
m_Workflow.setCost(new BigDecimal(atts.getValue("Cost")));
m_Workflow.setWorkingTime(Integer.valueOf(atts.getValue("WorkingTime")));
m_Workflow.setWaitingTime(Integer.valueOf(atts.getValue("WaitingTime")));
m_Workflow.setPublishStatus(atts.getValue("PublishStatus"));
m_Workflow.setWorkflowType(atts.getValue("WorkflowType"));
m_Workflow.setDocValueLogic(getStringValue(atts, "DocValueLogic"));
m_Workflow.setIsValid(atts.getValue("isValid") != null ? Boolean.valueOf(atts.getValue("isValid")).booleanValue() : true);
m_Workflow.setEntityType(atts.getValue("EntityType"));
m_Workflow.setAD_WF_Node_ID(-1);
log.info("about to execute m_Workflow.save");
if (m_Workflow.save(getTrxName(ctx)) == true) {
log.info("m_Workflow save success");
record_log(ctx, 1, m_Workflow.getName(), "Workflow", m_Workflow.get_ID(), AD_Backup_ID, Object_Status, "AD_Workflow", get_IDWithColumn(ctx, "AD_Table", "TableName", "AD_Workflow"));
workflows.add(m_Workflow.getAD_Workflow_ID());
element.recordId = m_Workflow.getAD_Workflow_ID();
} else {
log.info("m_Workflow save failure");
record_log(ctx, 0, m_Workflow.getName(), "Workflow", m_Workflow.get_ID(), AD_Backup_ID, Object_Status, "AD_Workflow", get_IDWithColumn(ctx, "AD_Table", "TableName", "AD_Workflow"));
throw new POSaveFailedException("MWorkflow");
}
} else {
element.skip = true;
}
}
use of org.xml.sax.Attributes in project adempiere by adempiere.
the class WorkflowElementHandler method endElement.
/**
* @param ctx
* @param element
*/
public void endElement(Properties ctx, Element element) throws SAXException {
if (!element.defer && !element.skip && element.recordId > 0) {
Attributes atts = element.attributes;
//set start node
String name = atts.getValue("ADWorkflowNodeNameID");
if (name != null && name.trim().length() > 0) {
MWorkflow m_Workflow = new MWorkflow(ctx, element.recordId, getTrxName(ctx));
int id = get_IDWithMasterAndColumn(ctx, "AD_WF_Node", "Name", name, "AD_Workflow", m_Workflow.getAD_Workflow_ID());
if (id <= 0) {
log.warning("Failed to resolve start node reference for workflow element. Workflow=" + m_Workflow.getName() + " StartNode=" + name);
return;
}
m_Workflow.setAD_WF_Node_ID(id);
if (m_Workflow.save(getTrxName(ctx)) == true) {
log.info("m_Workflow update success");
record_log(ctx, 1, m_Workflow.getName(), "Workflow", m_Workflow.get_ID(), 0, "Update", "AD_Workflow", get_IDWithColumn(ctx, "AD_Table", "TableName", "AD_Workflow"));
workflows.add(m_Workflow.getAD_Workflow_ID());
element.recordId = m_Workflow.getAD_Workflow_ID();
} else {
log.info("m_Workflow update fail");
record_log(ctx, 0, m_Workflow.getName(), "Workflow", m_Workflow.get_ID(), 0, "Update", "AD_Workflow", get_IDWithColumn(ctx, "AD_Table", "TableName", "AD_Workflow"));
throw new POSaveFailedException("MWorkflow");
}
}
}
}
Aggregations