* [ 1637957 ] 2Pack can't import entity types != D, U

* Fixed many issues detected when testing the import of Libero package - now import without any errors except there are some issues in the Libero package itself.

* Performance enhancement.
This commit is contained in:
Heng Sin Low 2007-07-27 04:32:23 +00:00
parent a7e989c81b
commit 54a8771182
23 changed files with 324 additions and 109 deletions

View File

@ -345,31 +345,79 @@ public abstract class AbstractElementHandler implements ElementHandler {
return success;
}
/**
* Get client id
* @param ctx
* @return int
*/
protected int getClientId(Properties ctx) {
return Env.getContextAsInt(ctx, "AD_Client_ID");
}
/**
* Get AD_Package_Imp_ID
* @param ctx
* @return int
*/
protected int getPackageImpId(Properties ctx) {
return Env.getContextAsInt(ctx, "AD_Package_Imp_ID");
}
/**
* Get update system maintained dictionary flag
* @param ctx
* @return update mode
*/
protected String getUpdateMode(Properties ctx) {
return Env.getContext(ctx, "UpdateMode");
}
/**
* Get current transaction name
* @param ctx
* @return transaction name
*/
protected String getTrxName(Properties ctx) {
return Env.getContext(ctx, "TrxName");
}
/**
* Get share document
* @param ctx
* @return TransformerHandler
*/
protected TransformerHandler getDocument(Properties ctx) {
return (TransformerHandler)ctx.get("Document");
}
/**
* Get share document attributes
* @param ctx
* @return AttributesImpl
*/
protected AttributesImpl getDocumentAttributes(Properties ctx) {
return (AttributesImpl)ctx.get("DocumentAttributes");
}
/**
* @param ctx
* @return package directory
*/
protected String getPackageDirectory(Properties ctx) {
return Env.getContext(ctx, "PackageDirectory");
}
}
/**
* Process element by entity type and user setting.
* @param ctx
* @param entityType
* @return boolean
*/
protected boolean isProcessElement(Properties ctx, String entityType) {
if ("D".equals(entityType) || "C".equals(entityType)) {
return "true".equalsIgnoreCase(getUpdateMode(ctx));
} else {
return true;
}
}
}

View File

@ -36,6 +36,12 @@ public class Element {
public Element parent;
//resolved db recordid, store for reference by child element
public int recordId = 0;
//unresolved dependency
public String unresolved = "";
//number of pass
public int pass = 1;
//skip this node
public boolean skip = false;
/**
* @param uri

View File

@ -650,8 +650,8 @@ public class PackInHandler extends DefaultHandler {
handler.endElement(m_ctx, e);
if (e.defer)
defer.add(new DeferEntry(e, false));
else
log.info("Processed: " + e.getElementValue() + " - " + e.attributes.getValue(0));
else if (!e.skip)
System.out.println("Processed: " + e.getElementValue() + " - " + e.attributes.getValue(0));
}
} // endElement
@ -673,7 +673,11 @@ public class PackInHandler extends DefaultHandler {
List<DeferEntry> tmp = new ArrayList<DeferEntry>(defer);
defer.clear();
for (DeferEntry d : tmp) {
d.element.defer = false;
if (d.startElement) {
d.element.defer = false;
d.element.unresolved = "";
d.element.pass++;
}
ElementHandler handler = handlers.get(d.element.getElementValue());
if (handler != null) {
if (d.startElement)
@ -683,14 +687,23 @@ public class PackInHandler extends DefaultHandler {
}
if (d.element.defer)
defer.add(d);
else if (!d.startElement)
System.out.println("Processed: " + d.element.getElementValue() + " - "
+ d.element.attributes.getValue(0));
}
int endSize = defer.size();
if (startSize == endSize) break;
} while (defer.size() > 0);
if (defer.size() > 0) {
//TODO
throw new RuntimeException("Failed to resolve dependency for " + defer.size() + " elements.");
int count = 0;
for (DeferEntry d : defer) {
if (d.startElement) {
count++;
System.out.println("Unresolved: " + d.element.getElementValue() + " - " + d.element.attributes.getValue(0) + ", " + d.element.unresolved);
}
}
throw new RuntimeException("Failed to resolve dependency for " + count + " elements.");
}
}

View File

@ -50,7 +50,7 @@ public class ColumnElementHandler extends AbstractElementHandler {
log.info(elementValue + " " + atts.getValue("ColumnName"));
int success = 0;
String entitytype = atts.getValue("EntityType");
if (entitytype.equals("U") || (entitytype.equals("D") && getUpdateMode(ctx).equals("true"))) {
if (isProcessElement(ctx, entitytype)) {
if (element.parent != null && element.parent.getElementValue().equals("table") &&
element.parent.defer) {
element.defer = true;
@ -257,6 +257,8 @@ public class ColumnElementHandler extends AbstractElementHandler {
throw new DatabaseAccessException("Failed to create column or related constraint for " + m_Column.getColumnName());
}
}
} else {
element.skip = true;
}
}

View File

@ -40,7 +40,7 @@ public class DynValRuleElementHandler extends AbstractElementHandler {
Attributes atts = element.attributes;
log.info(elementValue+" "+atts.getValue("Name"));
String entitytype = atts.getValue("EntityType");
if (entitytype.equals("U") || (entitytype.equals("D") && getUpdateMode(ctx).equals("true"))) {
if (isProcessElement(ctx, entitytype)) {
String name = atts.getValue("Name");
int id = get_IDWithColumn(ctx, "AD_Val_Rule", "name", name);
@ -67,6 +67,8 @@ public class DynValRuleElementHandler extends AbstractElementHandler {
else{
record_log (ctx, 0, m_ValRule.getName(),"Task", m_ValRule.get_ID(),AD_Backup_ID, Object_Status,"AD_Val_Rule",get_IDWithColumn(ctx, "AD_Val_Rule", "Name", "AD_Val_Rule"));
}
} else {
element.skip = true;
}
}

View File

@ -41,8 +41,7 @@ public class FieldElementHandler extends AbstractElementHandler {
Attributes atts = element.attributes;
log.info(elementValue + " " + atts.getValue("Name"));
String entitytype = atts.getValue("EntityType");
if (entitytype.equals("U")
|| (entitytype.equals("D") && getUpdateMode(ctx).equals("true"))) {
if (isProcessElement(ctx, entitytype)) {
if (element.parent != null && element.parent.getElementValue().equals("tab") &&
element.parent.defer) {
element.defer = true;
@ -159,7 +158,8 @@ public class FieldElementHandler extends AbstractElementHandler {
element.defer = true;
return;
}
} else {
element.skip = true;
}
}

View File

@ -38,7 +38,7 @@ public class FormElementHandler extends AbstractElementHandler {
log.info(elementValue+" "+atts.getValue("ADFormNameID"));
String entitytype = atts.getValue("EntityType");
if (entitytype.equals("U") || (entitytype.equals("D") && getUpdateMode(ctx).equals("true"))) {
if (isProcessElement(ctx, entitytype)) {
String name = atts.getValue("ADFormNameID");
int id = get_ID(ctx, "AD_Form", name);
MForm m_Form = new MForm(ctx, id, getTrxName(ctx));
@ -67,6 +67,8 @@ public class FormElementHandler extends AbstractElementHandler {
else{
record_log (ctx, 0, m_Form.getName(),"Form", m_Form.get_ID(),AD_Backup_ID, Object_Status,"AD_Form",get_IDWithColumn(ctx, "AD_Table", "TableName", "AD_Form"));
}
} else {
element.skip = true;
}
}

View File

@ -41,7 +41,7 @@ public class MessageElementHandler extends AbstractElementHandler {
Attributes atts = element.attributes;
log.info(elementValue+" "+atts.getValue("Value"));
String entitytype = atts.getValue("EntityType");
if (entitytype.equals("U") || (entitytype.equals("D") && getUpdateMode(ctx).equals("true"))) {
if (isProcessElement(ctx, entitytype)) {
String value = atts.getValue("Value");
int id = get_IDWithColumn(ctx, "AD_Message", "value", value);
@ -68,6 +68,8 @@ public class MessageElementHandler extends AbstractElementHandler {
else{
record_log (ctx, 0, m_Message.getValue(),"Message", m_Message.get_ID(),AD_Backup_ID, Object_Status,"AD_Message",get_IDWithColumn(ctx, "AD_Message", "value", "AD_Message"));
}
} else {
element.skip = true;
}
}

View File

@ -49,7 +49,7 @@ public class ProcessElementHandler extends AbstractElementHandler {
log.info(elementValue + " " + atts.getValue("Name"));
int id = 0;
String entitytype = atts.getValue("EntityType");
if (entitytype.equals("U") || (entitytype.equals("D") && getUpdateMode(ctx).equals("true"))) {
if (isProcessElement(ctx, entitytype)) {
String name = atts.getValue("Name");
// Get New process.
@ -77,6 +77,7 @@ public class ProcessElementHandler extends AbstractElementHandler {
id = get_IDWithColumn(ctx, "AD_Workflow", "Name", name);
if (id <= 0) {
element.defer = true;
element.unresolved = "AD_Workflow: " + name;
return;
}
m_Process.setAD_Workflow_ID(id);
@ -86,20 +87,32 @@ public class ProcessElementHandler extends AbstractElementHandler {
if (name != null && name.trim().length() > 0) {
id = get_IDWithColumn(ctx, "AD_PrintFormat", "Name", name);
if (id <= 0) {
element.defer = true;
return;
if (element.pass == 1) {
element.defer = true;
element.unresolved = "AD_PrintFormat: " + name;
return;
} else {
log.warning("AD_PrintFormat: " + name + " not found for Process: " + m_Process.getName());
}
}
m_Process.setAD_PrintFormat_ID(id);
if (id > 0)
m_Process.setAD_PrintFormat_ID(id);
}
name = atts.getValue("ADReportViewNameID");
if (name != null && name.trim().length() > 0) {
id = get_IDWithColumn(ctx, "AD_ReportView", "Name", name);
if (id <= 0) {
element.defer = true;
return;
if (element.pass == 1) {
element.defer = true;
element.unresolved = "AD_ReportView: " + name;
return;
} else {
log.warning("AD_ReportView: " + name + " not found for Process: " + m_Process.getName());
}
}
m_Process.setAD_ReportView_ID(id);
if (id > 0)
m_Process.setAD_ReportView_ID(id);
}
m_Process.setAccessLevel(atts.getValue("AccessLevel"));
@ -136,6 +149,8 @@ public class ProcessElementHandler extends AbstractElementHandler {
"AD_Process"));
throw new POSaveFailedException("Process");
}
} else {
element.skip = true;
}
}

View File

@ -23,6 +23,7 @@ import javax.xml.transform.sax.TransformerHandler;
import org.adempiere.pipo.AbstractElementHandler;
import org.adempiere.pipo.Element;
import org.adempiere.pipo.exception.POSaveFailedException;
import org.compiere.model.X_AD_Element;
import org.compiere.model.X_AD_Process_Para;
import org.compiere.util.DB;
import org.compiere.util.Env;
@ -39,7 +40,7 @@ public class ProcessParaElementHandler extends AbstractElementHandler {
log.info(elementValue + " " + atts.getValue("Name"));
String entitytype = atts.getValue("EntityType");
if (entitytype.equals("U") || (entitytype.equals("D") && getUpdateMode(ctx).equals("true"))) {
if (isProcessElement(ctx, entitytype)) {
String name = atts.getValue("Name");
int id = get_IDWithMaster(ctx, "AD_Process_Para", name,
@ -61,18 +62,45 @@ public class ProcessParaElementHandler extends AbstractElementHandler {
id = get_IDWithColumn(ctx, "AD_Process", "Name", name);
if (id <= 0) {
element.defer = true;
element.unresolved = "AD_Process: " + name;
return;
}
m_Process_para.setAD_Process_ID(id);
m_Process_para.setColumnName(atts.getValue("ColumnName"));
m_Process_para.setEntityType(atts.getValue("EntityType"));
m_Process_para.setName(atts.getValue("Name"));
name = atts.getValue("ADElementNameID");
if (name != null && name.trim().length() > 0) {
id = get_IDWithColumn(ctx, "AD_Element", "Name", name);
if (id <= 0) {
element.defer = true;
return;
// Setup Element
X_AD_Element adElement = new X_AD_Element(ctx, id, getTrxName(ctx));
if (adElement.getAD_Element_ID() == 0) {
String columnName = m_Process_para.getColumnName();
id = get_IDWithColumn(ctx, "AD_Element", "ColumnName", columnName);
if ( id > 0 ) {
adElement = new X_AD_Element(ctx, id, getTrxName(ctx));
} else {
adElement.setColumnName(columnName);
adElement.setEntityType(m_Process_para.getEntityType());
adElement.setPrintName(name);
adElement.setName(m_Process_para.getName());
if (adElement.save(getTrxName(ctx)) == true) {
record_log(ctx, 1, m_Process_para.getName(), "Element", adElement
.getAD_Element_ID(), AD_Backup_ID, "New",
"AD_Element", get_IDWithColumn(ctx, "AD_Table",
"TableName", "AD_Element"));
} else {
record_log(ctx, 0, m_Process_para.getName(), "Element", adElement
.getAD_Element_ID(), AD_Backup_ID, "New",
"AD_Element", get_IDWithColumn(ctx, "AD_Table",
"TableName", "AD_Element"));
}
}
}
m_Process_para.setAD_Element_ID(id);
m_Process_para.setAD_Element_ID(adElement.getAD_Element_ID());
}
name = atts.getValue("ADReferenceNameID");
@ -80,6 +108,7 @@ public class ProcessParaElementHandler extends AbstractElementHandler {
id = get_IDWithColumn(ctx, "AD_Reference", "Name", name);
if (id <= 0) {
element.defer = true;
element.unresolved = "AD_Reference: " + name;
return;
}
m_Process_para.setAD_Reference_ID(id);
@ -90,6 +119,7 @@ public class ProcessParaElementHandler extends AbstractElementHandler {
id = get_IDWithColumn(ctx, "AD_Reference", "Name", name);
if (id <= 0) {
element.defer = true;
element.unresolved = "AD_Reference: " + name;
return;
}
m_Process_para.setAD_Reference_Value_ID(id);
@ -100,24 +130,24 @@ public class ProcessParaElementHandler extends AbstractElementHandler {
id = get_IDWithColumn(ctx, "AD_Val_Rule", "Name", name);
if (id <= 0) {
element.defer = true;
element.unresolved = "AD_Val_Rule: " +name;
return;
}
m_Process_para.setAD_Val_Rule_ID(id);
}
m_Process_para.setColumnName(atts.getValue("ColumnName"));
m_Process_para.setDefaultValue(atts.getValue("DefaultValue"));
m_Process_para.setDefaultValue2(atts.getValue("DefaultValue2"));
m_Process_para.setDescription(atts.getValue("Description")
.replaceAll("'", "''").replaceAll(",", ""));
m_Process_para.setEntityType(atts.getValue("EntityType"));
m_Process_para.setHelp(atts.getValue("Help").replaceAll("'", "''")
.replaceAll(",", ""));
m_Process_para
.setIsActive(atts.getValue("isActive") != null ? Boolean
.valueOf(atts.getValue("isActive")).booleanValue()
: true);
m_Process_para.setName(atts.getValue("Name"));
m_Process_para.setVFormat(atts.getValue("VFormat"));
m_Process_para.setValueMax(atts.getValue("ValueMax"));
m_Process_para.setValueMin(atts.getValue("ValueMin"));
@ -142,6 +172,8 @@ public class ProcessParaElementHandler extends AbstractElementHandler {
"TableName", "AD_Process_para"));
throw new POSaveFailedException("ProcessPara");
}
} else {
element.skip = true;
}
}

View File

@ -58,8 +58,7 @@ public class ReferenceElementHandler extends AbstractElementHandler {
String entitytype = atts.getValue("EntityType");
String name = atts.getValue("name");
if (entitytype.compareTo("U") == 0 || entitytype.compareTo("D") == 0
&& getUpdateMode(ctx).compareTo("true") == 0) {
if (isProcessElement(ctx, entitytype)) {
int id = get_ID(ctx, "AD_Reference", name);
X_AD_Reference m_Reference = new X_AD_Reference(ctx, id,
@ -68,6 +67,7 @@ public class ReferenceElementHandler extends AbstractElementHandler {
AD_Backup_ID = copyRecord(ctx, "AD_Reference", m_Reference);
Object_Status = "Update";
if (references.contains(id)) {
element.skip = true;
return;
}
} else {
@ -99,6 +99,8 @@ public class ReferenceElementHandler extends AbstractElementHandler {
"TableName", "AD_Reference"));
throw new POSaveFailedException("Reference");
}
} else {
element.skip = true;
}
}

View File

@ -41,7 +41,11 @@ public class ReferenceListElementHandler extends AbstractElementHandler {
log.info(elementValue + " " + atts.getValue("Name"));
// TODO: Solve for date issues with valuefrom valueto
String entitytype = atts.getValue("EntityType");
if (entitytype.equals("U") || (entitytype.equals("D") && getUpdateMode(ctx).equals("true"))) {
if (isProcessElement(ctx, entitytype)) {
if (element.parent != null && element.parent.skip) {
element.skip = true;
return;
}
String name = atts.getValue("Name");
String value = atts.getValue("Value");
int AD_Reference_ID = get_IDWithColumn(ctx, "AD_Reference", "Name",
@ -77,6 +81,8 @@ public class ReferenceListElementHandler extends AbstractElementHandler {
"TableName", "AD_Ref_List"));
throw new POSaveFailedException("ReferenceList");
}
} else {
element.skip = true;
}
}

View File

@ -48,7 +48,12 @@ public class ReferenceTableElementHandler extends AbstractElementHandler {
Attributes atts = element.attributes;
String entitytype = atts.getValue("EntityType");
String name = atts.getValue("ADRefenceNameID");
if (entitytype.equals("U") || (entitytype.equals("D") && getUpdateMode(ctx).equals("true"))) {
if (isProcessElement(ctx, entitytype)) {
if (element.parent != null && element.parent.skip) {
element.skip = true;
return;
}
StringBuffer sqlB = new StringBuffer(
"SELECT AD_Reference_ID FROM AD_Reference WHERE Name= ?");
int id = DB.getSQLValue(getTrxName(ctx), sqlB.toString(), name);
@ -181,6 +186,8 @@ public class ReferenceTableElementHandler extends AbstractElementHandler {
throw new POSaveFailedException("ReferenceTable");
}
}
} else {
element.skip = true;
}
}

View File

@ -44,7 +44,7 @@ public class ReportViewColElementHandler extends AbstractElementHandler {
String entitytype = atts.getValue("EntityType");
String name = atts.getValue("ADReportViewColID");
if (entitytype.equals("U") || (entitytype.equals("D") && getUpdateMode(ctx).equals("true"))) {
if (isProcessElement(ctx, entitytype)) {
int id = get_ID(ctx, "AD_Reportview_Col", name);
X_AD_ReportView_Col m_Reportview_Col = new X_AD_ReportView_Col(ctx,
id, getTrxName(ctx));
@ -95,6 +95,8 @@ public class ReportViewColElementHandler extends AbstractElementHandler {
"AD_Reportview_Col"));
throw new POSaveFailedException("ReportViewCol");
}
} else {
element.skip = true;
}
}

View File

@ -46,7 +46,7 @@ public class TabElementHandler extends AbstractElementHandler {
Attributes atts = element.attributes;
log.info(elementValue+" "+atts.getValue("ADTabNameID"));
String entitytype = atts.getValue("EntityType");
if (entitytype.equals("U") || (entitytype.equals("D") && getUpdateMode(ctx).equals("true"))) {
if (isProcessElement(ctx, entitytype)) {
if (element.parent != null && element.parent.getElementValue().equals("window")
&& element.parent.defer) {
element.defer = true;
@ -168,8 +168,9 @@ public class TabElementHandler extends AbstractElementHandler {
} 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;
}
}

View File

@ -52,7 +52,7 @@ public class TableElementHandler extends AbstractElementHandler {
log.info(elementValue+" "+atts.getValue("ADTableNameID"));
String entitytype = atts.getValue("EntityType");
if (entitytype.equals("U") || entitytype.equals("D") && getUpdateMode(ctx).equals("true")) {
if (isProcessElement(ctx, entitytype)) {
String tableName = atts.getValue("ADTableNameID");
int id = packIn.getTableId(tableName);
@ -117,6 +117,8 @@ public class TableElementHandler extends AbstractElementHandler {
record_log (ctx, 0, m_Table.getName(),"Table", m_Table.get_ID(),AD_Backup_ID, Object_Status,"AD_Table",get_IDWithColumn(ctx, "AD_Table", "TableName", "AD_Table"));
throw new POSaveFailedException("Table");
}
} else {
element.skip = true;
}
}

View File

@ -39,8 +39,7 @@ public class TaskElementHandler extends AbstractElementHandler {
Attributes atts = element.attributes;
log.info(elementValue + " " + atts.getValue("ADTaskNameID"));
String entitytype = atts.getValue("EntityType");
if (entitytype.equals("U")
|| (entitytype.equals("D") && getUpdateMode(ctx).equals("true"))) {
if (isProcessElement(ctx, entitytype)) {
String name = atts.getValue("ADTaskNameID");
int id = get_ID(ctx, "AD_Task", name);
MTask m_Task = new MTask(ctx, id, getTrxName(ctx));
@ -75,6 +74,8 @@ public class TaskElementHandler extends AbstractElementHandler {
"AD_Task"));
throw new POSaveFailedException("Task");
}
} else {
element.skip = true;
}
}

View File

@ -55,7 +55,7 @@ public class WindowElementHandler extends AbstractElementHandler {
Attributes atts = element.attributes;
log.info(elementValue + " " + atts.getValue("Name"));
String entitytype = atts.getValue("EntityType");
if (entitytype.equals("U") || (entitytype.equals("D") && getUpdateMode(ctx).equals("true"))) {
if (isProcessElement(ctx, entitytype)) {
String name = atts.getValue("Name");
int id = get_ID(ctx, "AD_Window", name);
if (id > 0 && windows.contains(id)) {
@ -132,6 +132,8 @@ public class WindowElementHandler extends AbstractElementHandler {
"AD_Window"));
throw new POSaveFailedException("Window");
}
} else {
element.skip = true;
}
}

View File

@ -44,7 +44,7 @@ public class WorkbenchElementHandler extends AbstractElementHandler {
log.info(elementValue+" "+atts.getValue("ADWorkbenchNameID"));
String entitytype = atts.getValue("EntityType");
String name = atts.getValue("ADWorkbenchNameID");
if (entitytype.compareTo("U") == 0 || entitytype.compareTo("D") == 0 && getUpdateMode(ctx).compareTo("true") == 0 ) {
if (isProcessElement(ctx, entitytype)) {
int id = get_ID(ctx, "AD_Workbench", name);
X_AD_Workbench m_Workbench = new X_AD_Workbench(ctx, id, getTrxName(ctx));
if (id > 0){
@ -71,6 +71,8 @@ public class WorkbenchElementHandler extends AbstractElementHandler {
else{
record_log (ctx, 0, m_Workbench.getName(),"Workbench", m_Workbench.get_ID(),AD_Backup_ID, Object_Status,"AD_Workbench",get_IDWithColumn(ctx, "AD_Table", "TableName", "AD_Workbench"));
}
} else {
element.skip = true;
}
}

View File

@ -19,6 +19,8 @@ package org.adempiere.pipo.handler;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;
import java.util.logging.Level;
@ -45,6 +47,8 @@ public class WorkflowElementHandler extends AbstractElementHandler {
private WorkflowNodeElementHandler nodeHandler = new WorkflowNodeElementHandler();
private WorkflowNodeNextElementHandler nodeNextHandler = new WorkflowNodeNextElementHandler();
private WorkflowNodeNextConditionElementHandler nextConditionHandler = new WorkflowNodeNextConditionElementHandler();
private List<Integer> workflows = new ArrayList<Integer>();
public void startElement(Properties ctx, Element element)
throws SAXException {
@ -54,13 +58,15 @@ public class WorkflowElementHandler extends AbstractElementHandler {
String entitytype = atts.getValue("EntityType");
log.info("entitytype " + atts.getValue("EntityType"));
if (entitytype.equals("U") || (entitytype.equals("D")
&& getUpdateMode(ctx).equals("true"))) {
log.info("entitytype is a U or D");
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;
@ -78,6 +84,7 @@ public class WorkflowElementHandler extends AbstractElementHandler {
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);
@ -88,6 +95,7 @@ public class WorkflowElementHandler extends AbstractElementHandler {
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);
@ -99,6 +107,7 @@ public class WorkflowElementHandler extends AbstractElementHandler {
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);
@ -137,6 +146,8 @@ public class WorkflowElementHandler extends AbstractElementHandler {
.get_ID(), AD_Backup_ID, Object_Status, "AD_Workflow",
get_IDWithColumn(ctx, "AD_Workflow", "Name",
"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
@ -146,7 +157,7 @@ public class WorkflowElementHandler extends AbstractElementHandler {
throw new POSaveFailedException("MWorkflow");
}
} else {
log.info("entitytype is not a U or D");
element.skip = true;
}
}
@ -285,9 +296,10 @@ public class WorkflowElementHandler extends AbstractElementHandler {
atts.addAttribute("", "", "Name", "CDATA",
(m_Workflow.getName() != null ? m_Workflow.getName() : ""));
if (m_Workflow.getAD_Table_ID() > 0) {
sql = "SELECT Name FROM AD_Table WHERE AD_Table_ID=?";
sql = "SELECT TableName FROM AD_Table WHERE AD_Table_ID=?";
name = DB.getSQLValueString(null, sql, m_Workflow.getAD_Table_ID());
atts.addAttribute("", "", "ADTableNameID", "CDATA", name);
atts.addAttribute("", "", "ADTableNameID", "CDATA",
(name != null ? name : ""));
} else
atts.addAttribute("", "", "ADTableNameID", "CDATA", "");
@ -295,26 +307,30 @@ public class WorkflowElementHandler extends AbstractElementHandler {
sql = "SELECT Name FROM AD_WF_Node WHERE AD_WF_Node_ID=?";
name = DB.getSQLValueString(null, sql, m_Workflow
.getAD_WF_Node_ID());
atts.addAttribute("", "", "ADWorkflowNodeNameID", "CDATA", name);
atts.addAttribute("", "", "ADWorkflowNodeNameID", "CDATA",
(name != null ? name : ""));
} else
atts.addAttribute("", "", "ADWorkflowNodeNameID", "CDATA", "");
if (m_Workflow.getAD_WF_Responsible_ID() > 0) {
sql = "SELECT Name FROM AD_WF_Responsible WHERE AD_WF_Responsible_ID=?";
name = DB.getSQLValueString(null, sql, m_Workflow
.getAD_WF_Responsible_ID());
atts.addAttribute("", "", "ADWorkflowResponsibleNameID", "CDATA",
name);
(name != null ? name : ""));
} else
atts.addAttribute("", "", "ADWorkflowResponsibleNameID", "CDATA",
"");
if (m_Workflow.getAD_WorkflowProcessor_ID() > 0) {
sql = "SELECT Name FROM AD_WorkflowProcessor_ID WHERE AD_WorkflowProcessor_ID=?";
name = DB.getSQLValueString(null, sql, m_Workflow
.getAD_WorkflowProcessor_ID());
atts.addAttribute("", "", "ADWorkflowProcessorNameID", "CDATA",
name);
(name != null ? name : ""));
} else
atts.addAttribute("", "", "ADWorkflowProcessorNameID", "CDATA", "");
atts.addAttribute("", "", "AccessLevel", "CDATA", (m_Workflow
.getAccessLevel() != null ? m_Workflow.getAccessLevel() : ""));
atts

View File

@ -27,7 +27,6 @@ import org.adempiere.pipo.exception.POSaveFailedException;
import org.compiere.model.X_AD_WF_Node;
import org.compiere.util.DB;
import org.compiere.util.Env;
import org.compiere.wf.MWFNode;
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.AttributesImpl;
@ -42,19 +41,35 @@ public class WorkflowNodeElementHandler extends AbstractElementHandler {
String entitytype = atts.getValue("EntityType");
log.info("entitytype " + atts.getValue("EntityType"));
if (entitytype.equals("U") || entitytype.equals("D")
&& getUpdateMode(ctx).equals("true")) {
log.info("entitytype is a U or D");
String workflowName = atts.getValue("ADWorkflowNameID");
int workflowId = get_IDWithColumn(ctx, "AD_Workflow", "name",
workflowName);
if (workflowId <= 0) {
if (isProcessElement(ctx, entitytype)) {
if (element.parent != null && element.parent.skip) {
element.skip = true;
return;
}
if (element.parent != null && element.parent.getElementValue().equals("workflow")
&& element.parent.defer) {
element.defer = true;
return;
}
int workflowId = 0;
String workflowName = atts.getValue("ADWorkflowNameID");
if (element.parent != null && element.parent.getElementValue().equals("workflow")
&& element.parent.recordId > 0)
workflowId = element.parent.recordId;
else {
workflowId = get_IDWithColumn(ctx, "AD_Workflow", "name",
workflowName);
if (workflowId <= 0) {
element.defer = true;
element.unresolved = "AD_Workflow: " + workflowName;
return;
}
else if (element.parent != null && element.parent.getElementValue().equals("workflow"))
element.parent.recordId = workflowId;
}
String workflowNodeName = atts.getValue("Name");
String workflowNodeName = atts.getValue("Name").trim();
StringBuffer sqlB = new StringBuffer(
"SELECT ad_wf_node_id FROM AD_WF_Node WHERE AD_Workflow_ID=? and Name =?");
@ -62,7 +77,7 @@ public class WorkflowNodeElementHandler extends AbstractElementHandler {
int id = DB.getSQLValue(getTrxName(ctx), sqlB.toString(),
workflowId, workflowNodeName);
MWFNode m_WFNode = new MWFNode(ctx, id, getTrxName(ctx));
X_AD_WF_Node m_WFNode = new X_AD_WF_Node(ctx, id, getTrxName(ctx));
int AD_Backup_ID = -1;
String Object_Status = null;
if (id > 0) {
@ -80,6 +95,7 @@ public class WorkflowNodeElementHandler extends AbstractElementHandler {
id = get_IDWithColumn(ctx, "AD_Process", "Name", name);
if (id <= 0) {
element.defer = true;
element.unresolved = "AD_Process: " + name;
return;
}
m_WFNode.setAD_Process_ID(id);
@ -90,6 +106,7 @@ public class WorkflowNodeElementHandler extends AbstractElementHandler {
id = get_IDWithColumn(ctx, "AD_Form", "Name", name);
if (id <= 0) {
element.defer = true;
element.unresolved = "AD_Form: " + name;
return;
}
m_WFNode.setAD_Form_ID(id);
@ -98,11 +115,14 @@ public class WorkflowNodeElementHandler extends AbstractElementHandler {
name = atts.getValue("ADWorkflowResponsibleNameID");
if (name != null && name.trim().length() > 0) {
id = get_IDWithColumn(ctx, "AD_WF_Responsible", "Name", name);
//TODO: export and import of ad_wf_responsible
/*
if (id <= 0) {
element.defer = true;
return;
}
m_WFNode.setAD_WF_Responsible_ID(id);
}*/
if (id > 0)
m_WFNode.setAD_WF_Responsible_ID(id);
}
name = atts.getValue("ADWindowNameID");
@ -110,6 +130,7 @@ public class WorkflowNodeElementHandler extends AbstractElementHandler {
id = get_IDWithColumn(ctx, "AD_Window", "Name", name);
if (id <= 0) {
element.defer = true;
element.unresolved = "AD_Window: " + name;
return;
}
m_WFNode.setAD_Window_ID(id);
@ -118,21 +139,27 @@ public class WorkflowNodeElementHandler extends AbstractElementHandler {
name = atts.getValue("ADImageNameID");
if (name != null && name.trim().length() > 0) {
id = get_IDWithColumn(ctx, "AD_Image", "Name", name);
//TODO: export and import of ad_image
/*
if (id <= 0) {
element.defer = true;
return;
}
m_WFNode.setAD_Image_ID(id);
}*/
if (id > 0)
m_WFNode.setAD_Image_ID(id);
}
name = atts.getValue("ADWorkflowBlockNameID");
if (name != null && name.trim().length() > 0) {
id = get_IDWithColumn(ctx, "AD_WF_Block", "Name", name);
//TODO: export and import of ad_workflow_block
/*
if (id <= 0) {
element.defer = true;
return;
}
m_WFNode.setAD_WF_Block_ID(id);
}*/
if (id > 0)
m_WFNode.setAD_WF_Block_ID(id);
}
/*
* FIXME: Do we need TaskName ? if
@ -158,17 +185,17 @@ public class WorkflowNodeElementHandler extends AbstractElementHandler {
m_WFNode.setCost(new BigDecimal(atts.getValue("Cost")));
m_WFNode.setDuration(Integer.valueOf(atts.getValue("Duration")));
m_WFNode.setPriority(Integer.valueOf(atts.getValue("Priority")));
// FIXME: Failing for some reason on a ""
// m_WFNode.setStartMode(atts.getValue("StartMode"));
// FIXME: Failing for some reason on a ""
// m_WFNode.setSubflowExecution(atts.getValue("SubflowExecution"));
String startMode = atts.getValue("StartMode");
m_WFNode.setStartMode(("".equals(startMode) ? null : startMode));
String subFlowExecution = atts.getValue("SubflowExecution");
m_WFNode.setSubflowExecution(("".equals(subFlowExecution) ? null : subFlowExecution));
m_WFNode.setIsCentrallyMaintained(Boolean.valueOf(
atts.getValue("IsCentrallyMaintained")).booleanValue());
m_WFNode.setDynPriorityChange(new BigDecimal(atts
.getValue("DynPriorityChange")));
// m_WFNode.setAccessLevel (atts.getValue("AccessLevel"));
// FIXME: Failing for some reason on a ""
// m_WFNode.setDynPriorityUnit (atts.getValue("DynPriorityUnit"));
String dynPriorityUnit = atts.getValue("DynPriorityUnit");
m_WFNode.setDynPriorityUnit (("".equals(dynPriorityUnit) ? null : dynPriorityUnit));
m_WFNode.setIsActive(atts.getValue("isActive") != null ? Boolean
.valueOf(atts.getValue("isActive")).booleanValue() : true);
// log.info("in3");
@ -189,8 +216,7 @@ public class WorkflowNodeElementHandler extends AbstractElementHandler {
throw new POSaveFailedException("WorkflowNode");
}
} else {
log.info("entitytype is not a U or D");
element.skip = true;
}
}
@ -230,47 +256,59 @@ public class WorkflowNodeElementHandler extends AbstractElementHandler {
if (m_WF_Node.getAD_Window_ID() > 0) {
sql = "SELECT Name FROM AD_Window WHERE AD_Window_ID=?";
name = DB.getSQLValueString(null, sql, m_WF_Node.getAD_Window_ID());
}
if (name != null)
atts.addAttribute("", "", "ADWindowNameID", "CDATA", name);
else
if (name != null)
atts.addAttribute("", "", "ADWindowNameID", "CDATA", name);
else
atts.addAttribute("", "", "ADWindowNameID", "CDATA", "");
} else {
atts.addAttribute("", "", "ADWindowNameID", "CDATA", "");
}
if (m_WF_Node.getAD_Task_ID() > 0) {
sql = "SELECT Name FROM AD_Task WHERE AD_Task_ID=?";
name = DB.getSQLValueString(null, sql, m_WF_Node.getAD_Task_ID());
}
if (name != null)
atts.addAttribute("", "", "ADTaskNameID", "CDATA", name);
else
if (name != null)
atts.addAttribute("", "", "ADTaskNameID", "CDATA", name);
else
atts.addAttribute("", "", "ADTaskNameID", "CDATA", "");
} else {
atts.addAttribute("", "", "ADTaskNameID", "CDATA", "");
}
if (m_WF_Node.getAD_Process_ID() > 0) {
sql = "SELECT Name FROM AD_Process WHERE AD_Process_ID=?";
name = DB
.getSQLValueString(null, sql, m_WF_Node.getAD_Process_ID());
atts.addAttribute("", "", "ADProcessNameID", "CDATA", name);
atts.addAttribute("", "", "ADProcessNameID", "CDATA",
(name != null ? name : ""));
} else
atts.addAttribute("", "", "ADProcessNameID", "CDATA", "");
if (m_WF_Node.getAD_Form_ID() > 0) {
sql = "SELECT Name FROM AD_Form WHERE AD_Form_ID=?";
name = DB.getSQLValueString(null, sql, m_WF_Node.getAD_Form_ID());
atts.addAttribute("", "", "ADFormNameID", "CDATA", name);
atts.addAttribute("", "", "ADFormNameID", "CDATA",
(name != null ? name : ""));
} else
atts.addAttribute("", "", "ADFormNameID", "CDATA", "");
if (m_WF_Node.getAD_WF_Block_ID() > 0) {
sql = "SELECT Name FROM AD_WF_Block WHERE AD_WF_Block_ID=?";
name = DB.getSQLValueString(null, sql, m_WF_Node
.getAD_WF_Block_ID());
atts.addAttribute("", "", "ADWorkflowBlockNameID", "CDATA", name);
atts.addAttribute("", "", "ADWorkflowBlockNameID", "CDATA",
(name != null ? name : ""));
} else
atts.addAttribute("", "", "ADWorkflowBlockNameID", "CDATA", "");
if (m_WF_Node.getAD_WF_Responsible_ID() > 0) {
sql = "SELECT Name FROM AD_WF_Responsible WHERE AD_WF_Responsible_ID=?";
name = DB.getSQLValueString(null, sql, m_WF_Node
.getAD_WF_Responsible_ID());
atts.addAttribute("", "", "ADWorkflowResponsibleNameID", "CDATA",
name);
(name != null ? name : ""));
} else
atts.addAttribute("", "", "ADWorkflowResponsibleNameID", "CDATA",
"");
@ -278,17 +316,22 @@ public class WorkflowNodeElementHandler extends AbstractElementHandler {
if (m_WF_Node.getAD_Image_ID() > 0) {
sql = "SELECT Name FROM AD_Image WHERE AD_Image_ID=?";
name = DB.getSQLValueString(null, sql, m_WF_Node.getAD_Image_ID());
}
if (name != null)
atts.addAttribute("", "", "ADImageNameID", "CDATA", name);
else
if (name != null)
atts.addAttribute("", "", "ADImageNameID", "CDATA", name);
else
atts.addAttribute("", "", "ADImageNameID", "CDATA", "");
} else {
atts.addAttribute("", "", "ADImageNameID", "CDATA", "");
}
if (m_WF_Node.getAD_Column_ID() > 0) {
sql = "SELECT ColumnName FROM AD_Column WHERE AD_Column_ID=?";
name = DB.getSQLValueString(null, sql, m_WF_Node.getAD_Column_ID());
atts.addAttribute("", "", "ADColumnNameID", "CDATA", name);
atts.addAttribute("", "", "ADColumnNameID", "CDATA",
(name != null ? name : ""));
} else
atts.addAttribute("", "", "ADColumnNameID", "CDATA", "");
atts.addAttribute("", "", "isActive", "CDATA",
(m_WF_Node.isActive() == true ? "true" : "false"));
atts.addAttribute("", "", "Description", "CDATA", (m_WF_Node

View File

@ -40,10 +40,12 @@ public class WorkflowNodeNextConditionElementHandler extends
String entitytype = atts.getValue("EntityType");
log.info("entitytype " + atts.getValue("EntityType"));
if (entitytype.equals("U") || entitytype.equals("D")
&& getUpdateMode(ctx).equals("true")) {
log.info("entitytype is a U or D");
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",
@ -152,8 +154,7 @@ public class WorkflowNodeNextConditionElementHandler extends
throw new POSaveFailedException("WorkflowNodeNextCondition");
}
} else {
log.info("entitytype is not a U or D");
element.skip = true;
}
}

View File

@ -39,29 +39,38 @@ public class WorkflowNodeNextElementHandler extends AbstractElementHandler {
String entitytype = atts.getValue("EntityType");
log.info("entitytype "+atts.getValue("EntityType"));
if (entitytype.equals("U") || entitytype.equals("D") && getUpdateMode(ctx).equals("true")) {
log.info("entitytype is a U or D");
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");
String workflowNodeName = atts.getValue("ADWorkflowNodeNameID").trim();
String workflowNodeNextName = atts.getValue("ADWorkflowNodeNextNameID").trim();
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.defer = true;
element.unresolved = "AD_WF_Node: " + workflowNodeName;
return;
}
int wfNodeNextId = DB.getSQLValue(getTrxName(ctx),sqlB.toString(),workflowId,workflowNodeNextName);
if (wfNodeNextId <= 0) {
element.defer = true;
element.unresolved = "AD_WF_Node: " + workflowNodeNextName;
return;
}
sqlB = new StringBuffer ("SELECT ad_wf_nodenext_id FROM AD_WF_NodeNext WHERE ad_wf_node_id =? and ad_wf_next_id =?");
@ -97,8 +106,7 @@ public class WorkflowNodeNextElementHandler extends AbstractElementHandler {
throw new POSaveFailedException("WorkflowNodeNext");
}
} else {
log.info("entitytype is not a U or D");
element.skip = true;
}
}