From de9b233f88014e8c8421954e18f0e7ff0f979290 Mon Sep 17 00:00:00 2001 From: Richard Morales Date: Sun, 3 Mar 2013 13:49:06 -0500 Subject: [PATCH] IDEMPIERE-671 AD_ImpFormat.Name unique is wrong - must have AD_Client in the unique index --- .../oracle/201303010917_IDEMPIERE-671.sql | 9 +++++++ .../postgresql/201303010917_IDEMPIERE-671.sql | 9 +++++++ .../src/org/compiere/impexp/ImpFormat.java | 25 ++++++------------- .../org/compiere/apps/form/VFileImport.java | 17 +++++++------ .../webui/apps/form/WFileImport.java | 11 ++++---- 5 files changed, 41 insertions(+), 30 deletions(-) create mode 100644 migration/i1.0a-release/oracle/201303010917_IDEMPIERE-671.sql create mode 100644 migration/i1.0a-release/postgresql/201303010917_IDEMPIERE-671.sql diff --git a/migration/i1.0a-release/oracle/201303010917_IDEMPIERE-671.sql b/migration/i1.0a-release/oracle/201303010917_IDEMPIERE-671.sql new file mode 100644 index 0000000000..43861661da --- /dev/null +++ b/migration/i1.0a-release/oracle/201303010917_IDEMPIERE-671.sql @@ -0,0 +1,9 @@ +DROP INDEX ad_impformat_name +; + +CREATE UNIQUE INDEX ad_impformat_name + ON ad_impformat (ad_client_id, name) +; +SELECT register_migration_script('201303010917_IDEMPIERE-671.sql') FROM dual +; + diff --git a/migration/i1.0a-release/postgresql/201303010917_IDEMPIERE-671.sql b/migration/i1.0a-release/postgresql/201303010917_IDEMPIERE-671.sql new file mode 100644 index 0000000000..43861661da --- /dev/null +++ b/migration/i1.0a-release/postgresql/201303010917_IDEMPIERE-671.sql @@ -0,0 +1,9 @@ +DROP INDEX ad_impformat_name +; + +CREATE UNIQUE INDEX ad_impformat_name + ON ad_impformat (ad_client_id, name) +; +SELECT register_migration_script('201303010917_IDEMPIERE-671.sql') FROM dual +; + diff --git a/org.adempiere.base/src/org/compiere/impexp/ImpFormat.java b/org.adempiere.base/src/org/compiere/impexp/ImpFormat.java index f05f8fa9ed..7fe5ce75a6 100644 --- a/org.adempiere.base/src/org/compiere/impexp/ImpFormat.java +++ b/org.adempiere.base/src/org/compiere/impexp/ImpFormat.java @@ -150,14 +150,7 @@ public final class ImpFormat m_tableUniqueParent = ""; m_tableUniqueChild = ""; - if (m_AD_Table_ID == 311) // I_061_SyncItem - { - m_tableUnique1 = "H_UPC"; // UPC = unique - m_tableUnique2 = "Value"; - m_tableUniqueChild = "H_Commodity1"; // Vendor No may not be unique ! - m_tableUniqueParent = "H_PartnrID"; // Makes it unique - } - else if (m_AD_Table_ID == TABLE_I_PRODUCT) // I_Product + if (m_AD_Table_ID == TABLE_I_PRODUCT) // I_Product { m_tableUnique1 = "UPC"; // UPC = unique m_tableUnique2 = "Value"; @@ -266,26 +259,24 @@ public final class ImpFormat /************************************************************************* * Factory load - * @param name name + * @param Id id * @return Import Format */ - public static ImpFormat load (String name) + public static ImpFormat load (int Id) { - log.config(name); + if (log.isLoggable(Level.CONFIG))log.config(String.valueOf(Id)); ImpFormat retValue = null; - String sql = "SELECT * FROM AD_ImpFormat WHERE Name=?"; - int ID = 0; + String sql = "SELECT * FROM AD_ImpFormat WHERE AD_Impformat_ID=?"; PreparedStatement pstmt = null; ResultSet rs = null; try { pstmt = DB.prepareStatement(sql, null); - pstmt.setString (1, name); + pstmt.setInt (1, Id); rs = pstmt.executeQuery(); if (rs.next()) { - retValue = new ImpFormat (name, rs.getInt("AD_Table_ID"), rs.getString("FormatType")); - ID = rs.getInt ("AD_ImpFormat_ID"); + retValue = new ImpFormat (rs.getString("Name"), rs.getInt("AD_Table_ID"), rs.getString("FormatType")); if (X_AD_ImpFormat.FORMATTYPE_CustomSeparatorChar.equals(rs.getString(I_AD_ImpFormat.COLUMNNAME_FormatType))) { retValue.setSeparatorChar(rs.getString(I_AD_ImpFormat.COLUMNNAME_SeparatorChar)); } @@ -302,7 +293,7 @@ public final class ImpFormat rs = null; pstmt = null; } - loadRows (retValue, ID); + loadRows (retValue, Id); return retValue; } // getFormat diff --git a/org.adempiere.ui.swing/src/org/compiere/apps/form/VFileImport.java b/org.adempiere.ui.swing/src/org/compiere/apps/form/VFileImport.java index a88593eb7b..b4d94ced10 100644 --- a/org.adempiere.ui.swing/src/org/compiere/apps/form/VFileImport.java +++ b/org.adempiere.ui.swing/src/org/compiere/apps/form/VFileImport.java @@ -56,6 +56,7 @@ import org.compiere.util.CLogger; import org.compiere.util.DB; import org.compiere.util.Env; import org.compiere.util.Ini; +import org.compiere.util.KeyNamePair; import org.compiere.util.Msg; @@ -205,8 +206,8 @@ public class VFileImport extends CPanel private void dynInit() { // Load Formats - pickFormat.addItem(s_none); - String sql = MRole.getDefault().addAccessSQL("SELECT Name FROM AD_ImpFormat", "AD_ImpFormat", + pickFormat.addItem(new KeyNamePair(-1,s_none)); + String sql = MRole.getDefault().addAccessSQL("SELECT AD_Impformat_ID,Name FROM AD_ImpFormat WHERE isactive='Y'", "AD_ImpFormat", MRole.SQL_FULLYQUALIFIED, MRole.SQL_RO); PreparedStatement pstmt = null; ResultSet rs = null; @@ -215,7 +216,7 @@ public class VFileImport extends CPanel pstmt = DB.prepareStatement(sql, null); rs = pstmt.executeQuery(); while (rs.next()) - pickFormat.addItem(rs.getString(1)); + pickFormat.addItem(new KeyNamePair(rs.getInt(1),rs.getString(2))); } catch (SQLException e) { @@ -373,13 +374,13 @@ public class VFileImport extends CPanel // clear panel previewPanel.removeAll(); // - String formatName = pickFormat.getSelectedItem().toString(); - if (formatName.equals(s_none)) - return; - m_format = ImpFormat.load (formatName); + KeyNamePair pickFormatKNPair = (KeyNamePair)pickFormat.getSelectedItem(); + if (pickFormatKNPair.getName().equals(s_none)) + return; + m_format = ImpFormat.load (pickFormatKNPair.getKey()); if (m_format == null) { - ADialog.error(m_WindowNo, this, "FileImportNoFormat", formatName); + ADialog.error(m_WindowNo, this, "FileImportNoFormat", pickFormatKNPair.getName()); return; } diff --git a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/apps/form/WFileImport.java b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/apps/form/WFileImport.java index 2a481c4a85..cbf6d2e917 100644 --- a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/apps/form/WFileImport.java +++ b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/apps/form/WFileImport.java @@ -233,7 +233,7 @@ public class WFileImport extends ADForm implements EventListener // Load Formats pickFormat.appendItem(s_none, s_none); - String sql = MRole.getDefault().addAccessSQL("SELECT Name FROM AD_ImpFormat", "AD_ImpFormat", + String sql = MRole.getDefault().addAccessSQL("SELECT Name,AD_Impformat_ID FROM AD_ImpFormat WHERE isactive='Y'", "AD_ImpFormat", MRole.SQL_FULLYQUALIFIED, MRole.SQL_RO); PreparedStatement pstmt = null; ResultSet rs = null; @@ -243,7 +243,7 @@ public class WFileImport extends ADForm implements EventListener rs = pstmt.executeQuery(); while (rs.next()) - pickFormat.appendItem(rs.getString(1), rs.getString(1)); + pickFormat.appendItem(rs.getString(1), rs.getInt(2)); } catch (SQLException e) { @@ -451,12 +451,13 @@ public class WFileImport extends ADForm implements EventListener ListItem listitem = pickFormat.getSelectedItem(); - String formatName = (String)listitem.getValue(); + String formatName = (String)listitem.getLabel(); if (formatName.equals(s_none)) return; - - m_format = ImpFormat.load (formatName); + + int formatId = (Integer)listitem.getValue(); + m_format = ImpFormat.load (formatId); if (m_format == null) {