diff --git a/base/src/org/compiere/model/X_AD_ReplicationDocument.java b/base/src/org/compiere/model/X_AD_ReplicationDocument.java index 5857d54b05..a85de7db96 100644 --- a/base/src/org/compiere/model/X_AD_ReplicationDocument.java +++ b/base/src/org/compiere/model/X_AD_ReplicationDocument.java @@ -29,7 +29,7 @@ public class X_AD_ReplicationDocument extends PO implements I_AD_ReplicationDocu /** * */ - private static final long serialVersionUID = 20090915L; + private static final long serialVersionUID = 20091124L; /** Standard Constructor */ public X_AD_ReplicationDocument (Properties ctx, int AD_ReplicationDocument_ID, String trxName) @@ -197,6 +197,8 @@ public class X_AD_ReplicationDocument extends PO implements I_AD_ReplicationDocu public static final String REPLICATIONTYPE_Merge = "M"; /** Reference = R */ public static final String REPLICATIONTYPE_Reference = "R"; + /** Broadcast = B */ + public static final String REPLICATIONTYPE_Broadcast = "B"; /** Set Replication Type. @param ReplicationType Type of Data Replication diff --git a/base/src/org/compiere/model/X_AD_ReplicationTable.java b/base/src/org/compiere/model/X_AD_ReplicationTable.java index b66b40b342..fba0f4ac6c 100644 --- a/base/src/org/compiere/model/X_AD_ReplicationTable.java +++ b/base/src/org/compiere/model/X_AD_ReplicationTable.java @@ -30,7 +30,7 @@ public class X_AD_ReplicationTable extends PO implements I_AD_ReplicationTable, /** * */ - private static final long serialVersionUID = 20090915L; + private static final long serialVersionUID = 20091124L; /** Standard Constructor */ public X_AD_ReplicationTable (Properties ctx, int AD_ReplicationTable_ID, String trxName) @@ -207,6 +207,8 @@ public class X_AD_ReplicationTable extends PO implements I_AD_ReplicationTable, public static final String REPLICATIONTYPE_Merge = "M"; /** Reference = R */ public static final String REPLICATIONTYPE_Reference = "R"; + /** Broadcast = B */ + public static final String REPLICATIONTYPE_Broadcast = "B"; /** Set Replication Type. @param ReplicationType Type of Data Replication diff --git a/migration/354a-trunk/oracle/605_FR2712329BroadcastReplication.sql b/migration/354a-trunk/oracle/605_FR2712329BroadcastReplication.sql new file mode 100755 index 0000000000..33b102b5b5 --- /dev/null +++ b/migration/354a-trunk/oracle/605_FR2712329BroadcastReplication.sql @@ -0,0 +1,30 @@ +-- Aug 14, 2009 1:26:52 PM ECT +-- Improve the Application Dictionary +INSERT INTO AD_Ref_List (AD_Client_ID,AD_Org_ID,AD_Ref_List_ID,AD_Reference_ID,Created,CreatedBy,EntityType,IsActive,Name,Updated,UpdatedBy,Value) VALUES (0,0,53503,126,TO_DATE('2009-08-14 13:26:35','YYYY-MM-DD HH24:MI:SS'),100,'EE05','Y','Broadcast',TO_DATE('2009-08-14 13:26:35','YYYY-MM-DD HH24:MI:SS'),100,'B') +; + +-- Aug 14, 2009 1:27:09 PM ECT +-- Improve the Application Dictionary +INSERT INTO AD_Ref_List_Trl (AD_Language,AD_Ref_List_ID, Description,Name, IsTranslated,AD_Client_ID,AD_Org_ID,Created,Createdby,Updated,UpdatedBy) SELECT l.AD_Language,t.AD_Ref_List_ID, t.Description,t.Name, 'N',t.AD_Client_ID,t.AD_Org_ID,t.Created,t.Createdby,t.Updated,t.UpdatedBy FROM AD_Language l, AD_Ref_List t WHERE l.IsActive='Y' AND l.IsSystemLanguage='Y' AND l.IsBaseLanguage='N' AND t.AD_Ref_List_ID=53503 AND EXISTS (SELECT * FROM AD_Ref_List_Trl tt WHERE tt.AD_Language!=l.AD_Language OR tt.AD_Ref_List_ID!=t.AD_Ref_List_ID) +; + +-- Aug 14, 2009 1:27:40 PM ECT +-- Improve the Application Dictionary +UPDATE AD_Ref_List SET Description='Broadcast ->>',Updated=TO_DATE('2009-08-14 13:27:40','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Ref_List_ID=53503 +; + +-- Aug 14, 2009 1:27:40 PM ECT +-- Improve the Application Dictionary +UPDATE AD_Ref_List_Trl SET IsTranslated='N' WHERE AD_Ref_List_ID=53503 +; + +-- Aug 14, 2009 1:38:32 PM ECT +-- Improve the Application Dictionary +UPDATE AD_Ref_List SET Description='Broadcast <<->>',Updated=TO_DATE('2009-08-14 13:38:32','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Ref_List_ID=53503 +; + +-- Aug 14, 2009 1:38:32 PM ECT +-- Improve the Application Dictionary +UPDATE AD_Ref_List_Trl SET IsTranslated='N' WHERE AD_Ref_List_ID=53503 +; + diff --git a/migration/354a-trunk/postgresql/605_FR2712329BroadcastReplication.sql b/migration/354a-trunk/postgresql/605_FR2712329BroadcastReplication.sql new file mode 100755 index 0000000000..de67506607 --- /dev/null +++ b/migration/354a-trunk/postgresql/605_FR2712329BroadcastReplication.sql @@ -0,0 +1,30 @@ +-- Aug 14, 2009 1:27:08 PM ECT +-- Improve the Application Dictionary +INSERT INTO AD_Ref_List (AD_Client_ID,AD_Org_ID,AD_Ref_List_ID,AD_Reference_ID,Created,CreatedBy,EntityType,IsActive,Name,Updated,UpdatedBy,Value) VALUES (0,0,53503,126,TO_TIMESTAMP('2009-08-14 13:26:35','YYYY-MM-DD HH24:MI:SS'),100,'EE05','Y','Broadcast',TO_TIMESTAMP('2009-08-14 13:26:35','YYYY-MM-DD HH24:MI:SS'),100,'B') +; + +-- Aug 14, 2009 1:27:09 PM ECT +-- Improve the Application Dictionary +INSERT INTO AD_Ref_List_Trl (AD_Language,AD_Ref_List_ID, Description,Name, IsTranslated,AD_Client_ID,AD_Org_ID,Created,Createdby,Updated,UpdatedBy) SELECT l.AD_Language,t.AD_Ref_List_ID, t.Description,t.Name, 'N',t.AD_Client_ID,t.AD_Org_ID,t.Created,t.Createdby,t.Updated,t.UpdatedBy FROM AD_Language l, AD_Ref_List t WHERE l.IsActive='Y' AND l.IsSystemLanguage='Y' AND l.IsBaseLanguage='N' AND t.AD_Ref_List_ID=53503 AND EXISTS (SELECT * FROM AD_Ref_List_Trl tt WHERE tt.AD_Language!=l.AD_Language OR tt.AD_Ref_List_ID!=t.AD_Ref_List_ID) +; + +-- Aug 14, 2009 1:27:40 PM ECT +-- Improve the Application Dictionary +UPDATE AD_Ref_List SET Description='Broadcast ->>',Updated=TO_TIMESTAMP('2009-08-14 13:27:40','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Ref_List_ID=53503 +; + +-- Aug 14, 2009 1:27:40 PM ECT +-- Improve the Application Dictionary +UPDATE AD_Ref_List_Trl SET IsTranslated='N' WHERE AD_Ref_List_ID=53503 +; + +-- Aug 14, 2009 1:38:32 PM ECT +-- Improve the Application Dictionary +UPDATE AD_Ref_List SET Description='Broadcast <<->>',Updated=TO_TIMESTAMP('2009-08-14 13:38:32','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Ref_List_ID=53503 +; + +-- Aug 14, 2009 1:38:32 PM ECT +-- Improve the Application Dictionary +UPDATE AD_Ref_List_Trl SET IsTranslated='N' WHERE AD_Ref_List_ID=53503 +; + diff --git a/serverRoot/src/main/server/org/adempiere/server/rpl/imp/ImportHelper.java b/serverRoot/src/main/server/org/adempiere/server/rpl/imp/ImportHelper.java index 970728fd6c..a56cbe3b40 100644 --- a/serverRoot/src/main/server/org/adempiere/server/rpl/imp/ImportHelper.java +++ b/serverRoot/src/main/server/org/adempiere/server/rpl/imp/ImportHelper.java @@ -24,24 +24,23 @@ * - Trifon Trifonov (trifonnt@users.sourceforge.net) * * * * Sponsors: * - * - e-Evolution (http://www.e-evolution.com/) * + * - E-evolution (http://www.e-evolution.com/) * **********************************************************************/ package org.adempiere.server.rpl.imp; import java.math.BigDecimal; -import java.sql.PreparedStatement; -import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Timestamp; import java.text.ParseException; import java.text.SimpleDateFormat; +import java.util.List; import java.util.Properties; -import java.util.logging.Level; import javax.xml.xpath.XPathExpressionException; import org.adempiere.process.rpl.exp.ExportHelper; import org.adempiere.server.rpl.XMLHelper; +import org.compiere.model.I_AD_Client; import org.compiere.model.MClient; import org.compiere.model.MColumn; import org.compiere.model.MEXPFormat; @@ -50,9 +49,9 @@ import org.compiere.model.MReplicationStrategy; import org.compiere.model.MTable; import org.compiere.model.ModelValidator; import org.compiere.model.PO; +import org.compiere.model.Query; import org.compiere.model.X_AD_ReplicationTable; import org.compiere.util.CLogger; -import org.compiere.util.DB; import org.compiere.util.DisplayType; import org.compiere.util.Env; import org.compiere.util.Msg; @@ -65,16 +64,6 @@ import org.w3c.dom.NodeList; * @author Antonio CaƱaveral, e-Evolution *
  • [ 2195016 ] Implementation delete records messages *
  • http://sourceforge.net/tracker/index.php?func=detail&aid=2195016&group_id=176962&atid=879332 - *
  • Otras Modificaciones Posteriores - * @author victor.perez@e-evolution.com, www.e-evolution.com - *
  • BF[2836406] Error when try get ID but do not is the first field - *
  • - * @author michael.judd@akunagroup.com, http://www.akunagroup.com - *
  • BF[2861697] Incorrect string conversion - *
  • https://sourceforge.net/tracker/index.php?func=detail&aid=2861697&group_id=176962&atid=879332 - * @author michael.judd@akunagroup.com, http://www.akunagroup.com - *
  • BF[2863095] Missing DisplayType.Search in ImportHelper - *
  • https://sourceforge.net/tracker/?func=detail&aid=2863095&group_id=176962&atid=879332 */ public class ImportHelper { @@ -96,7 +85,8 @@ public class ImportHelper { /** Context */ private Properties ctx = null; - public ImportHelper(Properties ctx) { + public ImportHelper(Properties ctx) + { this.ctx = ctx; // Construct DateFromat and DateTimeFormat m_dateTimeFormat = DisplayType.getDateFormat(DisplayType.DateTime, Env.getLanguage(ctx)); @@ -115,37 +105,33 @@ public class ImportHelper { public void importXMLDocument(StringBuffer result, Document documentToBeImported, String trxName) throws Exception, SQLException, XPathExpressionException { - //Element rootNode = importedDocument.getFirstChild(); Element rootElement = documentToBeImported.getDocumentElement(); - //NodeList nl = rootElement.getChildNodes(); - // iterate over all address nodes and find the one that has the correct addressee - //for (int i = 0; i < nl.getLength(); i++) { /* */ } // Find which Export format to Load... String AD_Client_Value = null; - //AD_Client_Value = XMLHelper.getString("@AD_Client_Value", rootNode); + AD_Client_Value = rootElement.getAttribute("AD_Client_Value"); log.info("AD_Client_Value = " + AD_Client_Value); - if (AD_Client_Value == null || "".equals(AD_Client_Value)) { + if (AD_Client_Value == null || Util.isEmpty(AD_Client_Value)) + { throw new Exception(Msg.getMsg(ctx, "XMLClientValueMandatory")); } String version = null; version = rootElement.getAttribute("Version"); log.info("Version = " + version); - if (version == null || "".equals(version)) { + if (version == null || Util.isEmpty(version)) + { throw new Exception(Msg.getMsg(ctx, "XMLVersionAttributeMandatory")); } ///Getting Attributes. - - ; - int ReplicationMode = new Integer(rootElement.getAttribute("ReplicationMode")); String ReplicationType = rootElement.getAttribute("ReplicationType"); int ReplicationEvent = new Integer(rootElement.getAttribute("ReplicationEvent")); MClient client = null; client = getAD_ClientByValue(ctx, AD_Client_Value, trxName); - if (client == null) { + if (client == null) + { throw new Exception(Msg.getMsg(ctx, "XMLClientNotFound")); } log.info(client.toString()); @@ -156,40 +142,70 @@ public class ImportHelper { MEXPFormat expFormat = null; expFormat = MEXPFormat.getFormatByValueAD_Client_IDAndVersion(ctx, EXP_Format_Value, client.getAD_Client_ID(), version, trxName); - if (expFormat == null || expFormat.getEXP_Format_ID() == 0) { + if (expFormat == null || expFormat.getEXP_Format_ID() == 0) + { // Fall back to SYSTEM Client. // Try to search Export format defined for SYSTEM Client!!! MClient systemClient = null; systemClient = MClient.get(ctx, 0); - if (systemClient == null) { + if (systemClient == null) + { throw new Exception(Msg.getMsg(ctx, "XMLClientNotFound")); } log.info(systemClient.toString()); expFormat = MEXPFormat.getFormatByValueAD_Client_IDAndVersion(ctx, EXP_Format_Value, systemClient.getAD_Client_ID(), version, trxName); } - if (expFormat == null || expFormat.getEXP_Format_ID() == 0) { + if (expFormat == null || expFormat.getEXP_Format_ID() == 0) + { throw new Exception(Msg.getMsg(ctx, "EXPFormatNotFound")); } log.info("expFormat = " + expFormat.toString()); - PO po = importElement(ctx, result, rootElement, expFormat, trxName); - // Here must invoke other method else we get cycle... + PO po = importElement(ctx, result, rootElement, expFormat, ReplicationType, trxName); + boolean resultSave=false; - if(ReplicationEvent == ModelValidator.TYPE_BEFORE_DELETE || - ReplicationEvent == ModelValidator.TYPE_BEFORE_DELETE_REPLICATION || - ReplicationEvent == ModelValidator.TYPE_DELETE) + + if(po != null) { - resultSave=po.delete(true); - } else { - //TODO: Create a Replication Type "BROADCAST" now we are using MERGE - if(ReplicationType.equals(X_AD_ReplicationTable.REPLICATIONTYPE_Merge)) + // Here must invoke other method else we get cycle... + if (ModelValidator.TYPE_BEFORE_DELETE == ReplicationEvent + || ModelValidator.TYPE_BEFORE_DELETE_REPLICATION == ReplicationEvent + || ModelValidator.TYPE_DELETE == ReplicationEvent) { - resultSave = po.saveReplica(true); - MReplicationStrategy rplStrategy = new MReplicationStrategy(client.getCtx(), client.getAD_ReplicationStrategy_ID(), null); - ExportHelper expHelper = new ExportHelper(client, rplStrategy); - expHelper.exportRecord( po, MReplicationStrategy.REPLICATION_TABLE, X_AD_ReplicationTable.REPLICATIONTYPE_Reference, ModelValidator.TYPE_AFTER_CHANGE); - } else { - resultSave = po.saveReplica(true); + resultSave=po.delete(true); + } + else + { + if(X_AD_ReplicationTable.REPLICATIONTYPE_Broadcast.equals(ReplicationType)) + { + resultSave = po.saveReplica(true); + MReplicationStrategy rplStrategy = new MReplicationStrategy(client.getCtx(), client.getAD_ReplicationStrategy_ID(), null); + ExportHelper expHelper = new ExportHelper(client, rplStrategy); + expHelper.exportRecord( po, + MReplicationStrategy.REPLICATION_TABLE, + X_AD_ReplicationTable.REPLICATIONTYPE_Merge, + ModelValidator.TYPE_AFTER_CHANGE); + } + else if(X_AD_ReplicationTable.REPLICATIONTYPE_Merge.equals(ReplicationType) + || X_AD_ReplicationTable.REPLICATIONTYPE_Reference.equals(ReplicationType)) + { + resultSave = po.saveReplica(true); + } + /*else if (X_AD_ReplicationTable.REPLICATIONTYPE_Reference.equals(ReplicationType)) + { + //Do nothing?? + }*/ + else if(X_AD_ReplicationTable.REPLICATIONTYPE_Local.equals(ReplicationType)) + { + //Do nothing?? + } + else + { + // Replication Type is not one of the possible values...ERROR + throw new Exception(Msg.getMsg(ctx, "EXPReplicationTypeNonValidType")); + } + + } } @@ -222,555 +238,503 @@ public class ImportHelper { */ @SuppressWarnings("unchecked") private PO importElement(Properties ctx, StringBuffer result, Element rootElement, - MEXPFormat expFormat, String trxName) throws Exception, XPathExpressionException + MEXPFormat expFormat, String ReplicationType, String trxName) throws Exception, XPathExpressionException { - // get AD_Table ID from export Format. - int AD_Table_ID = expFormat.getAD_Table_ID(); - - // Load appropriate Model class... - MTable table = MTable.get(ctx, AD_Table_ID); - log.info("Table = " + table); - - int record_ID = 0; - String whereClause=""; - // Find Record_ID by ???Value??? In fact by Columns set as Part Of Unique Index in Export Format! - if(table.getKeyColumns().length == 1) - { - record_ID = getID(ctx, expFormat, rootElement, rootElement.getNodeName(), trxName); - log.info("record_ID = " + record_ID); - }else - { - whereClause = getID(ctx, expFormat, rootElement, rootElement.getNodeName(),trxName,true); - log.info("WHERE = " + whereClause); - } - PO po=null; - if(record_ID>0) - po = table.getPO(record_ID, trxName); - else if(whereClause.length()>0) - po=table.getPO(whereClause, trxName); - else - po = table.getPO(record_ID, trxName); + //Getting the Object for the replicate + PO po = getObjectFromFormat(ctx, expFormat, rootElement, rootElement.getNodeName(), trxName); - if(po==null) + if(po == null) + { throw new Exception(Msg.getMsg(ctx, "Can't Load PO Object")); + } + if(X_AD_ReplicationTable.REPLICATIONTYPE_Reference.equals(ReplicationType)) //If this is just for push and exists we do nothing + { + if(po.get_ID() == 0) + { + return null; + } + } + log.info("PO.toString() = " + po.toString()); - if (po.get_KeyColumns().length < 1) { + if (po.get_KeyColumns().length < 1) + { throw new Exception(Msg.getMsg(ctx, "EDIMultiColumnNotSupported")); } StringBuffer orderBy = new StringBuffer(MEXPFormatLine.COLUMNNAME_IsMandatory).append(" DESC ") - .append(", ").append(MEXPFormatLine.COLUMNNAME_Position) - ; + .append(", ").append(MEXPFormatLine.COLUMNNAME_Position); + MEXPFormatLine[] formatLines = expFormat.getFormatLinesOrderedBy(orderBy.toString()); - if (formatLines == null || formatLines.length < 1) { + if (formatLines == null || formatLines.length < 1) + { throw new Exception(Msg.getMsg(ctx, "EXPFormatNoLines")); } - Object value = null; // Iterate all Export Format Lines (even this marked as part of unique index) // and set value of column! - for (int i = 0; i < formatLines.length; i++) { + for (MEXPFormatLine formatLine : formatLines) + { log.info("=================== Beginnig of Format Line ==============================="); - log.info("formatLines["+i+"]=[" + formatLines[i].toString() + "]"); + log.info("formatLine: [" + formatLine.toString() + "]"); + //Get the value + Object value = getValueFromFormat(formatLine,po,rootElement,result,ReplicationType,trxName); + //Set the value + setReplicaValues(value, formatLine, po, result); + } + return po; + } + + /** + * Get the value from format + * @param line + * @param po + * @param rootElement + * @param result + * @param ReplicationType + * @param trxName + * @return Object with the Value + * @throws Exception + */ + private Object getValueFromFormat(MEXPFormatLine line,PO po,Element rootElement, + StringBuffer result, String ReplicationType, String trxName) throws Exception + { + Object value = null; + + if (MEXPFormatLine.TYPE_XMLElement.equals(line.getType())) + { + // XML Element + value = XMLHelper.getString(line.getValue(), rootElement); + log.info("value=[" + value + "]"); - if (MEXPFormatLine.TYPE_XMLElement.equals(formatLines[i].getType())) { - // XML Element - value = XMLHelper.getString(formatLines[i].getValue(), rootElement); - log.info("value=[" + value + "]"); - - } else if (MEXPFormatLine.TYPE_ReferencedEXPFormat.equals(formatLines[i].getType())) { - // Referenced Export Format -/* - - 0 - - SYSTEM - - - ... - */ + } + else if (MEXPFormatLine.TYPE_ReferencedEXPFormat.equals(line.getType())) + { + // Referenced Export Format + MEXPFormat referencedExpFormat = new MEXPFormat(ctx, line.getEXP_EmbeddedFormat_ID(), trxName); + log.info("referencedExpFormat = " + referencedExpFormat); - MEXPFormat referencedExpFormat = new MEXPFormat(ctx, formatLines[i].getEXP_EmbeddedFormat_ID(), trxName); - log.info("referencedExpFormat = " + referencedExpFormat); - - int refRecord_ID = 0; - // Find Record_ID by ???Value??? In fact by Columns set as Part Of Unique Index in Export Format! - String xPath = null; - //xPath = ""+rootElement.getNodeName() + "/" + formatLines[i].getValue() + ""; // Do not work - xPath = "" + formatLines[i].getValue() + ""; // - - log.info("SEARCH FOR XML Element = " + xPath); - Element referencedNode = XMLHelper.getElement(xPath, rootElement); - - //NodeList nodeList = XMLHelper.getNodeList(xPath, rootElement); - //referencedNode = (Element)nodeList.item(0); - - log.info("referencedNode = " + referencedNode); - if(referencedNode!=null) - { - refRecord_ID = getID(ctx, referencedExpFormat, referencedNode, formatLines[i].getValue(), trxName); - log.info("refRecord_ID = " + refRecord_ID); - value = new Integer(refRecord_ID); - } - else - { - log.info("NULL VALUE FOR " + xPath.toString()); - value=null; - } - log.info("value=[" + value + "]"); - } else if (MEXPFormatLine.TYPE_EmbeddedEXPFormat.equals(formatLines[i].getType())) { - boolean resSave = false; - if (po.get_ID() == 0) { - resSave = po.saveReplica(true); - result.append("ResultSave-MasterPO=").append(resSave).append("; "); - log.info("ResultSave-MasterPO = " + resSave); - } else { - resSave = true; - } - if (resSave) { - // Success in save - } else { - throw new Exception("Failed to save Master PO"); - } - // Embedded Export Format -/* - GardenWorls - ... - ... <-- MUST save Master Record here! Else we can't set orderLine.setC_Order_ID(..) - ... - ... - */ - MEXPFormat referencedExpFormat = new MEXPFormat(ctx, formatLines[i].getEXP_EmbeddedFormat_ID(), trxName); - log.info("embeddedExpFormat = " + referencedExpFormat); - - NodeList nodeList = XMLHelper.getNodeList("/"+rootElement.getNodeName() + "/" + formatLines[i].getValue(), rootElement); - for (int j = 0; j < nodeList.getLength(); j++) { - Element referencedElement = (Element)nodeList.item(j); - log.info("EmbeddedEXPFormat - referencedElement.getNodeName = " + referencedElement.getNodeName()); - - PO embeddedPo = null; - // Import embedded PO - log.info("=== BEGIN RECURSION CALL ==="); - embeddedPo = importElement(ctx, result, referencedElement, referencedExpFormat, trxName); - log.info("embeddedPo = " + embeddedPo); - - //embeddedPo.set_CustomColumn(po.get_KeyColumns()[0], po.get_ID()); - //log.info("embeddedPo.set"+po.get_KeyColumns()[0]+" = [" + po.get_ID()+"]"); - - boolean rSave = embeddedPo.saveReplica(true); - result.append("ResultSave-EmbeddedPO=").append(rSave).append("; "); - } - - } else if (MEXPFormatLine.TYPE_XMLAttribute.equals(formatLines[i].getType())) { - // XML Attribute - value = XMLHelper.getString("@" + formatLines[i].getValue(), rootElement); - log.info("value=[" + value + "]"); - } else { - // Export Format Line is not one of two possible values...ERROR - throw new Exception(Msg.getMsg(ctx, "EXPFormatLineNonValidType")); + int refRecord_ID = 0; + // Find Record_ID by ???Value??? In fact by Columns set as Part Of Unique Index in Export Format! + String xPath = null; + xPath = "" + line.getValue() + ""; + + log.info("Seach for XML Element = " + xPath); + Element referencedNode = XMLHelper.getElement(xPath, rootElement); + + log.info("referencedNode = " + referencedNode); + if(referencedNode!=null) + { + refRecord_ID = getID(ctx, referencedExpFormat, referencedNode, line.getValue(), trxName); + log.info("refRecord_ID = " + refRecord_ID); + value = new Integer(refRecord_ID); } - if (value == null) { - - } else { -/* if (column.getColumnName().equals("AD_Client_ID")) { - //Env.setContext(Env.getCtx(), "#AD_Client_ID", value.toString()); - } - if (column.getColumnName().equals("AD_Org_ID")) { - //Env.setContext(Env.getCtx(), "#AD_Org_ID", value.toString()); - } */ - if ( MEXPFormatLine.TYPE_EmbeddedEXPFormat.equals(formatLines[i].getType()) ) { - // do nothing - } else { - MColumn column = MColumn.get(ctx, formatLines[i].getAD_Column_ID()); - log.info("column=[" + column + "]"); + else + { + log.info("NULL VALUE FOR " + xPath.toString()); + value=null; + } + log.info("value=[" + value + "]"); + } + else if (MEXPFormatLine.TYPE_EmbeddedEXPFormat.equals(line.getType())) + { + boolean resSave = false; + if (po.get_ID() == 0) + { + resSave = po.saveReplica(true); + result.append("ResultSave-MasterPO=").append(resSave).append("; "); + log.info("ResultSave-MasterPO = " + resSave); + } + else + { + resSave = true; + } + + if (!resSave) + { + throw new Exception("Failed to save Master PO"); + } + + // Embedded Export Format It is used for Parent-Son records like Order&OrderLine + MEXPFormat referencedExpFormat = new MEXPFormat(ctx, line.getEXP_EmbeddedFormat_ID(), trxName); + log.info("embeddedExpFormat = " + referencedExpFormat); - // Clazz - Class clazz = DisplayType.getClass(column.getAD_Reference_ID(), true); - // Handle Posted - if (column.getColumnName().equalsIgnoreCase("Posted") - || column.getColumnName().equalsIgnoreCase("Processed") - || column.getColumnName().equalsIgnoreCase("Processing")) + NodeList nodeList = XMLHelper.getNodeList("/"+rootElement.getNodeName() + "/" + line.getValue(), rootElement); + for (int j = 0; j < nodeList.getLength(); j++) + { + Element referencedElement = (Element)nodeList.item(j); + log.info("EmbeddedEXPFormat - referencedElement.getNodeName = " + referencedElement.getNodeName()); + + PO embeddedPo = null; + // Import embedded PO + log.info("=== BEGIN RECURSION CALL ==="); + embeddedPo = importElement(ctx, result, referencedElement, referencedExpFormat,ReplicationType, trxName); + log.info("embeddedPo = " + embeddedPo); + + boolean rSave = embeddedPo.saveReplica(true); + result.append("ResultSave-EmbeddedPO=").append(rSave).append("; "); + } + + } + else if (MEXPFormatLine.TYPE_XMLAttribute.equals(line.getType())) + { + // XML Attribute + value = XMLHelper.getString("@" + line.getValue(), rootElement); + log.info("value=[" + value + "]"); + } + else + { + // Export Format Line is not one of the possible values...ERROR + throw new Exception(Msg.getMsg(ctx, "EXPFormatLineNonValidType")); + } + + return value; + } + + /** + * + * @param value + * @param line + * @param po + * @param result + * @throws Exception + */ + private void setReplicaValues(Object value,MEXPFormatLine line,PO po,StringBuffer result)throws Exception + { + if (value !=null) + { + if (!MEXPFormatLine.TYPE_EmbeddedEXPFormat.equals(line.getType()) ) + { + MColumn column = MColumn.get(ctx, line.getAD_Column_ID()); + log.info("column=[" + column + "]"); + + // Clazz + Class clazz = DisplayType.getClass(column.getAD_Reference_ID(), true); + + // Handle Posted + if (column.getColumnName().equalsIgnoreCase("Posted") + || column.getColumnName().equalsIgnoreCase("Processed") + || column.getColumnName().equalsIgnoreCase("Processing")) + { + clazz = Boolean.class; + } else if (column.getColumnName().equalsIgnoreCase("Record_ID")) + { + clazz = Integer.class; + } else if (column.getColumnName().equalsIgnoreCase("AD_Language") + || column.getColumnName().equalsIgnoreCase("EntityType")) + { + clazz = String.class; + } + log.info("clazz = " + clazz.getName()); + + // Handle Date and Time + value = handleDateTime(value, column, line); + + log.info("formatLinesType = " + line.getType()); + + if (MEXPFormatLine.TYPE_EmbeddedEXPFormat.equals( line.getType() ) ) + { + // DO NOTHING + throw new Exception("We can't be here!!!"); + } else + { + if ( DisplayType.DateTime == column.getAD_Reference_ID() + || DisplayType.Date == column.getAD_Reference_ID()) { - clazz = Boolean.class; - } else if (column.getColumnName().equalsIgnoreCase("Record_ID")) - { - clazz = Integer.class; - } else if (column.getColumnName().equalsIgnoreCase("AD_Language") - || column.getColumnName().equalsIgnoreCase("EntityType")) - { - clazz = String.class; - } - log.info("clazz = " + clazz.getName()); - // Handle Date and Time - value = handleDateTime(value, column, formatLines[i]); - - log.info("formatLinesType = " + formatLines[i].getType()); - if (MEXPFormatLine.TYPE_EmbeddedEXPFormat.equals( formatLines[i].getType() ) ) { - // DO NOTHING - throw new Exception("We can't be here!!!"); - } else { - if (column.getAD_Reference_ID() == DisplayType.DateTime - || column.getAD_Reference_ID() == DisplayType.Date + // + po.set_ValueOfColumn(line.getAD_Column_ID(), value); + log.info("Set value of column ["+column.getColumnName()+"]=["+value+"]"); + } + else if ( DisplayType.isID(column.getAD_Reference_ID()) + || DisplayType.Integer == column.getAD_Reference_ID() ) + { + // + if (! Util.isEmpty(value.toString())) { - // - po.set_ValueOfColumn(formatLines[i].getAD_Column_ID(), value); - log.info("Set value of column ["+column.getColumnName()+"]=["+value+"]"); - } else if (DisplayType.isID(column.getAD_Reference_ID()) - || column.getAD_Reference_ID() == DisplayType.Integer - ) + int intValue = Integer.parseInt(value.toString()); + value = new Integer( intValue ); + }else { - // - if (! Util.isEmpty(value.toString())) - { - int intValue = Integer.parseInt(value.toString()); - value = new Integer( intValue ); - }else - value=null; - log.info("About to set int value of column ["+column.getColumnName()+"]=["+value+"]"); - po.set_ValueOfColumn(formatLines[i].getAD_Column_ID(), value); - log.info("Set int value of column ["+column.getColumnName()+"]=["+value+"]"); - } else if (DisplayType.isNumeric(column.getAD_Reference_ID()) - && column.getAD_Reference_ID() != DisplayType.Integer) - { - // - if (! Util.isEmpty(value.toString())) - { - double doubleValue = Double.parseDouble(value.toString()); - value = new BigDecimal(doubleValue); - }else - value=null; - //value = new Double( doubleValue ); - log.info("About to set BigDecimal value of column ["+column.getColumnName()+"]=["+value+"]"); - po.set_ValueOfColumn(formatLines[i].getAD_Column_ID(), value); - log.info("Set BigDecimal value of column ["+column.getColumnName()+"]=["+value+"]"); - } - else if(column.getAD_Reference_ID() == DisplayType.YesNo) - { - po.set_ValueOfColumn(formatLines[i].getAD_Column_ID(), value); + value=null; } - else { - // - try { + + log.info("About to set int value of column ["+column.getColumnName()+"]=["+value+"]"); + + po.set_ValueOfColumn(line.getAD_Column_ID(), value); + + log.info("Set int value of column ["+column.getColumnName()+"]=["+value+"]"); + + } + else if ( DisplayType.isNumeric(column.getAD_Reference_ID()) + && column.getAD_Reference_ID() != DisplayType.Integer) + { + // + if (!Util.isEmpty(value.toString())) + { + double doubleValue = Double.parseDouble(value.toString()); + value = new BigDecimal(doubleValue); + } + else + { + value=null; + } + //value = new Double( doubleValue ); + + log.info("About to set BigDecimal value of column ["+column.getColumnName()+"]=["+value+"]"); + + po.set_ValueOfColumn(line.getAD_Column_ID(), value); + + log.info("Set BigDecimal value of column ["+column.getColumnName()+"]=["+value+"]"); + } + else if(DisplayType.YesNo == column.getAD_Reference_ID()) + { + po.set_ValueOfColumn(line.getAD_Column_ID(), value); + } + else + { + // + try { log.info("About to set value of column ["+column.getColumnName()+"]=["+value+"]"); + if(clazz == Boolean.class) - po.set_ValueOfColumn(formatLines[i].getAD_Column_ID(), value); + { + po.set_ValueOfColumn(line.getAD_Column_ID(), value); + } else - po.set_ValueOfColumn(formatLines[i].getAD_Column_ID(), clazz.cast(value)); + { + po.set_ValueOfColumn(line.getAD_Column_ID(), clazz.cast(value)); + } + log.info("Set value of column ["+column.getColumnName()+"]=["+value+"]"); - } catch (ClassCastException ex) { + } + catch (ClassCastException ex) + { ex.printStackTrace(); throw new Exception(ex); } - - //po.set_ValueOfColumn(formatLines[i].getAD_Column_ID(), value); - } - result.append(column.getColumnName()).append("=").append(value).append("; "); + } - } - } - - } + result.append(column.getColumnName()).append("=").append(value).append("; "); + }//end else + }//end if TYPE_EmbeddedEXPFormat + }//end if value !=null - return po; } - + public static MClient getAD_ClientByValue(Properties ctx, String value, String trxName) throws SQLException { - MClient result = null; - - StringBuffer sql = new StringBuffer("SELECT AD_Client_ID ") - .append(" FROM ").append(MClient.Table_Name) - .append(" WHERE ").append(MClient.COLUMNNAME_Value).append(" = ?") - // .append(" AND IsActive = ?") - ; - //s_log.info(sql.toString()); - s_log.info("Client_Value =[" + value + "]"); + final String whereClause = I_AD_Client.COLUMNNAME_Value + "= ? "; + MClient result = new Query(ctx,I_AD_Client.Table_Name,whereClause,trxName) + .setParameters(new Object[]{value}) + .firstOnly(); - PreparedStatement pstmt = null; - try { - pstmt = DB.prepareStatement(sql.toString(), trxName); - pstmt.setString(1, value); - ResultSet rs = pstmt.executeQuery(); - if (rs.next()) { - int AD_Client_ID = rs.getInt(1); - s_log.info("AD_Client_ID = " + AD_Client_ID); - result = new MClient(ctx, AD_Client_ID, trxName); - } - rs.close(); - pstmt.close(); - pstmt = null; - } catch (SQLException e) { - s_log.log(Level.SEVERE, sql.toString(), e); - throw e; - } finally { - try { - if (pstmt != null) - pstmt.close(); - pstmt = null; - } catch (Exception e) { - pstmt = null; - } + s_log.info("Client_Value =[" + value + "]"); + if(result != null) + { + s_log.info("AD_Client_ID = " + result.getAD_Client_ID()); } - + return result; } - - private PreparedStatement getIDValues(Properties ctx, MEXPFormat expFormat, Element rootElement, String rootNodeName, String trxName) throws Exception { - if (expFormat == null || rootElement == null || rootNodeName == null) { + /** + * This Method gets the PO record, from the exportFormat + * @param ctx + * @param expFormat + * @param rootElement + * @param rootNodeName + * @param trxName + * @throws Exception + * */ + private PO getObjectFromFormat(Properties ctx, MEXPFormat expFormat, Element rootElement, String rootNodeName, String trxName) throws Exception + { + List values = null; + + if (expFormat == null || rootElement == null || rootNodeName == null) + { throw new IllegalArgumentException("expFormat, rootNode and RootnodeName can't be null!"); } + log.info("expFormat = " + expFormat); log.info("rootNode.getNodeName() = " + rootElement.getNodeName()); log.info("rootNodeName = " + rootNodeName); - if (rootElement.getParentNode() != null) { + + if (rootElement.getParentNode() != null) + { log.info("rootNode.ParentName = " + rootElement.getParentNode().getNodeName()); } - // get AD_Table ID from export Format. - int AD_Table_ID = expFormat.getAD_Table_ID(); - - // Load appropriate Model class... - MTable table = MTable.get(ctx, AD_Table_ID); - log.info("Table = " + table); - - //Select * FROM table.getTableName() WHERE Value or ANY IDENTIFIER column - StringBuffer sql = new StringBuffer("SELECT * ") - .append(" FROM ").append(table.getTableName()) - .append(" WHERE ") - ; // Get list with all Unique columns! MEXPFormatLine[] uniqueFormatLines = expFormat.getUniqueColumns(); - if (uniqueFormatLines == null || uniqueFormatLines.length < 1) { + if (uniqueFormatLines == null || uniqueFormatLines.length < 1) + { throw new Exception(Msg.getMsg(ctx, "EXPFormatLineNoUniqueColumns")); } - Object[] values = new Object[uniqueFormatLines.length]; - for (int i = 0; i < uniqueFormatLines.length; i++) { - log.info("--- iterate unique column with index = ["+i+"]"); - MColumn column = MColumn.get(ctx, uniqueFormatLines[i].getAD_Column_ID()); + + Object[] cols = new Object[uniqueFormatLines.length]; + Object[] params = new Object[uniqueFormatLines.length]; + StringBuffer whereClause= new StringBuffer(""); + int col = 0; + for (MEXPFormatLine uniqueFormatLine : uniqueFormatLines) + { + MColumn column = MColumn.get(ctx, uniqueFormatLine.getAD_Column_ID()); log.info("column = ["+column+"]"); String valuecol=column.getColumnName(); - if (DisplayType.isNumeric(column.getAD_Reference_ID()) - && column.getAD_Reference_ID() != DisplayType.Integer) - { - valuecol="Round("+valuecol+",2)"; - } - if (MEXPFormatLine.TYPE_XMLElement.equals(uniqueFormatLines[i].getType())) { + if (MEXPFormatLine.TYPE_XMLElement.equals(uniqueFormatLine.getType())) + { // XML Element - //values[i] = XMLHelper.getString("/"+rootElement.getNodeName() + "/" + uniqueFormatLines[i].getValue(), rootElement); String xPath = null; - //xPath = "/"+rootNodeName + "/" + uniqueFormatLines[i].getValue(); -- works - //xPath = "/"+ uniqueFormatLines[i].getValue(); // do not work - xPath = ""+ uniqueFormatLines[i].getValue(); + xPath = ""+ uniqueFormatLine.getValue(); + cols[col] = XMLHelper.getString(xPath, rootElement); + log.info("values[" + col + "]=" + cols[col]); - values[i] = XMLHelper.getString(xPath, rootElement); - //log.info("xml PATH =" + rootElement.getNodeName() + "." + xPath ); - log.info("values[" + i + "]=" + values[i]); - - } else if (MEXPFormatLine.TYPE_ReferencedEXPFormat.equals(uniqueFormatLines[i].getType())) { + } + else if (MEXPFormatLine.TYPE_ReferencedEXPFormat.equals(uniqueFormatLine.getType())) + { // Referenced Export Format - log.info("referencedExpFormat.EXP_EmbeddedFormat_ID = " + uniqueFormatLines[i].getEXP_EmbeddedFormat_ID()); - MEXPFormat referencedExpFormat = new MEXPFormat(ctx, uniqueFormatLines[i].getEXP_EmbeddedFormat_ID(), trxName); + log.info("referencedExpFormat.EXP_EmbeddedFormat_ID = " + uniqueFormatLine.getEXP_EmbeddedFormat_ID()); + MEXPFormat referencedExpFormat = new MEXPFormat(ctx, uniqueFormatLine.getEXP_EmbeddedFormat_ID(), trxName); log.info("referencedExpFormat = " + referencedExpFormat); - /* - - - 0 - - SYSTEM - - - ... - - */ + int record_ID = 0; // Find Record_ID by ???Value??? In fact by Columns set as Part Of Unique Index in Export Format! - Element referencedNode = ((Element) rootElement.getElementsByTagName(uniqueFormatLines[i].getValue()).item(0)); + Element referencedNode = ((Element) rootElement.getElementsByTagName(uniqueFormatLine.getValue()).item(0)); log.info("referencedNode = " + referencedNode); - record_ID = getID(ctx, referencedExpFormat, referencedNode, uniqueFormatLines[i].getValue(), trxName); + record_ID = getID(ctx, referencedExpFormat, referencedNode, uniqueFormatLine.getValue(), trxName); log.info("record_ID = " + record_ID); - values[i] = new Integer(record_ID); - } else { + cols[col] = new Integer(record_ID); + } + else + { // Export Format Line is not one of two possible values...ERROR throw new Exception(Msg.getMsg(ctx, "EXPFormatLineNonValidType")); } - if (i == 0) { - sql.append(" ").append(valuecol).append(" = ? "); - } else { - sql.append(" AND ").append(valuecol).append(" = ? "); - } - } - log.info("sql = " + sql.toString()); - - PreparedStatement pstmt = null; - try { - pstmt = DB.prepareStatement (sql.toString(), trxName); - for (int i = 0; i < uniqueFormatLines.length; i++) { - MColumn col = MColumn.get(ctx, uniqueFormatLines[i].getAD_Column_ID()); + if ( DisplayType.DateTime == column.getAD_Reference_ID() + || DisplayType.Date == column.getAD_Reference_ID()) + { - if (col.getAD_Reference_ID() == DisplayType.DateTime - || col.getAD_Reference_ID() == DisplayType.Date) - { - - Timestamp value = (Timestamp)handleDateTime(values[i], col , uniqueFormatLines[i]); - pstmt.setTimestamp(i+1, value); - } - else if(col.getAD_Reference_ID() == DisplayType.String) - { - String value = (String)values[i]; - pstmt.setString(i+1, value); - } - else if (DisplayType.isNumeric(col.getAD_Reference_ID()) - && col.getAD_Reference_ID() != DisplayType.Integer) - { - BigDecimal value = new BigDecimal((String)values[i]); - pstmt.setBigDecimal(i+1, value.setScale(2, BigDecimal.ROUND_HALF_UP)); - } - else if (DisplayType.isID(col.getAD_Reference_ID()) - || col.getAD_Reference_ID() == DisplayType.Integer) - { - String stringValue = (String)values[i].toString(); - int value = Integer.parseInt(stringValue); - pstmt.setInt(i+1, value); - log.info("pstmt.setInt["+(i+1)+"] = [" + value +"]"); - } - else - { - pstmt.setObject(i+1, values[i]); - log.info("pstmt.setObject["+(i+1)+"] = [" + values[i]+"]"); - } - + Timestamp value = (Timestamp)handleDateTime(cols[col], column , uniqueFormatLine); + params[col] = value; + } + else if(column.getAD_Reference_ID() == DisplayType.String) + { + params[col] = (String)cols[col]; + } + else if( DisplayType.Amount == column.getAD_Reference_ID() + || DisplayType.Number == column.getAD_Reference_ID() + || DisplayType.CostPrice == column.getAD_Reference_ID() + || DisplayType.Quantity == column.getAD_Reference_ID()) + { + valuecol="Round("+valuecol+",2)"; + params[col] = new BigDecimal((String)cols[col]).setScale(2, BigDecimal.ROUND_HALF_UP); + } + else + { + params[col] = cols[col]; } - return pstmt; - - } catch (SQLException e) { - s_log.log(Level.SEVERE, sql.toString(), e); - throw e; - } + if (col == 0) { + whereClause.append(" ").append(valuecol).append(" = ? "); + } else { + whereClause.append(" AND ").append(valuecol).append(" = ? "); + } + col++; + } + + Query query = new Query(ctx,MTable.get(ctx, expFormat.getAD_Table_ID()),whereClause.toString(),trxName) + .setParameters(params); + values = query.list(); + + if(values.size()>1)//The Return Object must be always one + { + throw new Exception(Msg.getMsg(ctx, "EXPFormatIncorrectFormatDefinition")); + } + + if(values.size()<=0)//Means that is a new record + { + return MTable.get(ctx, expFormat.getAD_Table_ID()).getPO(0,trxName); + } + + return values.get(0);//Return the first (unique) record. } - public int getID(Properties ctx, MEXPFormat expFormat, Element rootElement, String rootNodeName, String trxName) throws Exception { - int result = 0; - - PreparedStatement pstmt = getIDValues(ctx,expFormat,rootElement,rootNodeName,trxName); - try - { - //We do this, because, what about if the ID is not the first column - //BF[2836406] - int AD_Table_ID = expFormat.getAD_Table_ID(); - MTable table = MTable.get(ctx, AD_Table_ID); - String columns[]=table.getKeyColumns(); // Must be always One - - if(columns==null || columns.length!=1) - { - throw new Exception(Msg.getMsg(ctx, "EXPFormatLineNoUniqueColumns")); - } - - ResultSet rs = pstmt.executeQuery(); - if ( rs.next() ) - { - result = rs.getInt(rs.findColumn(columns[0])); - } - rs.close (); - pstmt.close (); - pstmt = null; - } catch (SQLException e) { - throw e; - } finally { - try { - if (pstmt != null) - { - pstmt.close (); - } - pstmt = null; - } catch (Exception e) { pstmt = null; } - } - log.info("result = " + result); - return result; - } - - public String getID(Properties ctx, MEXPFormat expFormat, Element rootElement,String rootNodeName, String trxName,boolean multikey) throws Exception + /** + * This Method gets the ID value of the current referenced element to put in the imported Object + * Exp: AD_Org_ID of the Product. + * Must be allays one result. + * @param ctx + * @param expFormat + * @param rootElement + * @param rootNodeName + * @param trxName + * @throws Exception + * */ + private int getID(Properties ctx, MEXPFormat expFormat, Element rootElement, String rootNodeName, String trxName) throws Exception { - String result=""; - PreparedStatement pstmt = getIDValues(ctx,expFormat,rootElement,rootNodeName,trxName); - try - { + int record_id = 0; - int AD_Table_ID = expFormat.getAD_Table_ID(); - MTable table = MTable.get(ctx, AD_Table_ID); - String columns[]=table.getKeyColumns(); - //BF[2836406] - if(columns==null || columns.length <= 0) - { - throw new Exception(Msg.getMsg(ctx, "EXPFormatNoIDs")); //TODO Correct Exception Name - } - log.warning("Multiple columns ID. Table = "+ table.getTableName() +" Columns="+ columns); - - ResultSet rs = pstmt.executeQuery(); - if ( rs.next() ) - { - for(String column : columns) - { - result += " AND " + column + " = "+ rs.getInt(rs.findColumn(column)); - } - } - if(result.length()>0) - result = result.substring(4); - - rs.close (); - pstmt.close (); - pstmt = null; - } catch (SQLException e) { - throw e; - } finally { - try { - if (pstmt != null) - { - pstmt.close (); - } - pstmt = null; - } catch (Exception e) { pstmt = null; } + PO po = getObjectFromFormat(ctx,expFormat,rootElement,rootNodeName,trxName); + if (po != null) + { + record_id = po.get_ID(); } - return result; + log.info("record_id = " + record_id); + + return record_id; } - private Object handleDateTime(Object value, MColumn column, MEXPFormatLine formatLine) throws ParseException { + private Object handleDateTime(Object value, MColumn column, MEXPFormatLine formatLine) throws ParseException + { String valueString = null; valueString = value.toString(); // We are sure that value is not null Object result = value; - if (column.getAD_Reference_ID() == DisplayType.Date) { - if (valueString != null) { - if (formatLine.getDateFormat() != null && !"".equals(formatLine.getDateFormat())) { + if (DisplayType.Date == column.getAD_Reference_ID()) + { + if (valueString != null) + { + if (formatLine.getDateFormat() != null && !Util.isEmpty(formatLine.getDateFormat())) + { m_customDateFormat = new SimpleDateFormat( formatLine.getDateFormat() ); // "MM/dd/yyyy"; MM/dd/yyyy hh:mm:ss result = new Timestamp(m_customDateFormat.parse(valueString).getTime()); log.info("Custom Date Format; Parsed value = " + result.toString()); - } else { + } + else + { //result = new Timestamp(m_dateFormat.parse(valueString).getTime()); //log.info("Custom Date Format; Parsed value = " + result.toString()); //NOW Using Standard Japanese Format yyyy-mm-dd hh:mi:ss.mil so don't care about formats.... - if(valueString==null||valueString.length()<=0) + if( valueString == null + || valueString.length() <= 0 ) + { result=null; + } else + { result = Timestamp.valueOf(valueString); + } } } - } else if (column.getAD_Reference_ID() == DisplayType.DateTime) { - if (valueString != null) { - if (formatLine.getDateFormat() != null && !"".equals(formatLine.getDateFormat())) { + } + else if (DisplayType.DateTime == column.getAD_Reference_ID()) + { + if (valueString != null) + { + if (formatLine.getDateFormat() != null && !Util.isEmpty(formatLine.getDateFormat())) + { m_customDateFormat = new SimpleDateFormat( formatLine.getDateFormat() ); // "MM/dd/yyyy" result = new Timestamp(m_customDateFormat.parse(valueString).getTime()); log.info("Custom Date Format; Parsed value = " + result.toString()); - } else { + } + else + { //result = new Timestamp(m_dateTimeFormat.parse(valueString).getTime()); //log.info("Custom Date Format; Parsed value = " + result.toString()); //NOW Using Standard Japanese Format yyyy-mm-dd hh:mi:ss.mil so don't care about formats.... @@ -782,5 +746,4 @@ public class ImportHelper { } return result; } - }