IDEMPIERE-1286 Improve address validation configuration to support external services - change the address validation system configuration to enable/disable address validation calls by country

This commit is contained in:
Elaine Tan 2013-09-04 17:35:10 +08:00
parent 32b7640889
commit 23c5094192
6 changed files with 180 additions and 13 deletions

View File

@ -0,0 +1,15 @@
SET SQLBLANKLINES ON
SET DEFINE OFF
-- Sep 4, 2013 5:07:27 PM SGT
-- IDEMPIERE-1286 Improve address validation configuration to support external services
UPDATE AD_SysConfig SET Value=' ', Description='Enable address validation by country codes - separated by semicolons',Updated=TO_DATE('2013-09-04 17:07:27','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_SysConfig_ID=200033
;
-- Sep 4, 2013 5:09:23 PM SGT
-- IDEMPIERE-1286 Improve address validation configuration to support external services
INSERT INTO AD_Message (MsgType,MsgText,AD_Message_ID,EntityType,AD_Message_UU,Value,IsActive,Updated,CreatedBy,UpdatedBy,AD_Org_ID,Created,AD_Client_ID) VALUES ('E','Address validation call is not enabled for this country',200226,'D','8ca0038d-ded5-4862-b517-afff6671dfd2','AddressValidationNotEnabledForCountry','Y',TO_DATE('2013-09-04 17:09:22','YYYY-MM-DD HH24:MI:SS'),100,100,0,TO_DATE('2013-09-04 17:09:22','YYYY-MM-DD HH24:MI:SS'),0)
;
SELECT register_migration_script('201309041711_IDEMPIERE-1286.sql') FROM dual
;

View File

@ -0,0 +1,12 @@
-- Sep 4, 2013 5:07:27 PM SGT
-- IDEMPIERE-1286 Improve address validation configuration to support external services
UPDATE AD_SysConfig SET Value=' ', Description='Enable address validation by country codes - separated by semicolons',Updated=TO_TIMESTAMP('2013-09-04 17:07:27','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_SysConfig_ID=200033
;
-- Sep 4, 2013 5:09:23 PM SGT
-- IDEMPIERE-1286 Improve address validation configuration to support external services
INSERT INTO AD_Message (MsgType,MsgText,AD_Message_ID,EntityType,AD_Message_UU,Value,IsActive,Updated,CreatedBy,UpdatedBy,AD_Org_ID,Created,AD_Client_ID) VALUES ('E','Address validation call is not enabled for this country',200226,'D','8ca0038d-ded5-4862-b517-afff6671dfd2','AddressValidationNotEnabledForCountry','Y',TO_TIMESTAMP('2013-09-04 17:09:22','YYYY-MM-DD HH24:MI:SS'),100,100,0,TO_TIMESTAMP('2013-09-04 17:09:22','YYYY-MM-DD HH24:MI:SS'),0)
;
SELECT register_migration_script('201309041711_IDEMPIERE-1286.sql') FROM dual
;

View File

@ -13,6 +13,8 @@
*****************************************************************************/ *****************************************************************************/
package org.adempiere.base.event; package org.adempiere.base.event;
import java.util.StringTokenizer;
import org.compiere.model.I_C_Location; import org.compiere.model.I_C_Location;
import org.compiere.model.MAddressValidation; import org.compiere.model.MAddressValidation;
import org.compiere.model.MLocation; import org.compiere.model.MLocation;
@ -36,16 +38,33 @@ public class AddressValidationEventHandler extends AbstractEventHandler {
if (po.get_TableName().equals(I_C_Location.Table_Name)) if (po.get_TableName().equals(I_C_Location.Table_Name))
{ {
MLocation location = (MLocation) po; MLocation location = (MLocation) po;
if (MSysConfig.getBooleanValue(MSysConfig.ADDRESS_VALIDATION, false, location.getAD_Client_ID()))
String addressValidation = MSysConfig.getValue(MSysConfig.ADDRESS_VALIDATION, null, location.getAD_Client_ID());
boolean isEnabled = false;
if (addressValidation != null && addressValidation.trim().length() > 0 && location.getCountry() != null)
{ {
MAddressValidation validation = null; StringTokenizer st = new StringTokenizer(addressValidation, ";");
if (location.getC_AddressValidation_ID() > 0) while (st.hasMoreTokens())
validation = new MAddressValidation(location.getCtx(), location.getC_AddressValidation_ID(), location.get_TrxName()); {
if (validation == null) String token = st.nextToken().trim();
validation = MAddressValidation.getDefaultAddressValidation(location.getCtx(), location.getAD_Client_ID(), location.getAD_Org_ID(), location.get_TrxName()); if (token.equals(location.getCountry().getCountryCode().trim()))
if (validation != null) {
location.processOnline(validation.getC_AddressValidation_ID()); isEnabled = true;
break;
}
}
} }
if (!isEnabled)
return;
MAddressValidation validation = null;
if (location.getC_AddressValidation_ID() > 0)
validation = new MAddressValidation(location.getCtx(), location.getC_AddressValidation_ID(), location.get_TrxName());
if (validation == null)
validation = MAddressValidation.getDefaultAddressValidation(location.getCtx(), location.getAD_Client_ID(), location.getAD_Org_ID(), location.get_TrxName());
if (validation != null)
location.processOnline(validation.getC_AddressValidation_ID());
} }
} }
} }

View File

@ -14,11 +14,13 @@
package org.adempiere.process; package org.adempiere.process;
import java.sql.Timestamp; import java.sql.Timestamp;
import java.util.StringTokenizer;
import java.util.logging.Level; import java.util.logging.Level;
import org.adempiere.exceptions.AdempiereException; import org.adempiere.exceptions.AdempiereException;
import org.compiere.model.MAddressTransaction; import org.compiere.model.MAddressTransaction;
import org.compiere.model.MLocation; import org.compiere.model.MLocation;
import org.compiere.model.MSysConfig;
import org.compiere.process.ProcessInfoLog; import org.compiere.process.ProcessInfoLog;
import org.compiere.process.ProcessInfoParameter; import org.compiere.process.ProcessInfoParameter;
import org.compiere.process.SvrProcess; import org.compiere.process.SvrProcess;
@ -57,6 +59,26 @@ public class ValidateAddressProcess extends SvrProcess
throw new AdempiereException(Msg.getMsg(Env.getCtx(), "FillMandatory") + Msg.getElement(Env.getCtx(), MAddressTransaction.COLUMNNAME_C_AddressValidation_ID)); throw new AdempiereException(Msg.getMsg(Env.getCtx(), "FillMandatory") + Msg.getElement(Env.getCtx(), MAddressTransaction.COLUMNNAME_C_AddressValidation_ID));
MLocation m_location = new MLocation(getCtx(), getRecord_ID(), get_TrxName()); MLocation m_location = new MLocation(getCtx(), getRecord_ID(), get_TrxName());
String addressValidation = MSysConfig.getValue(MSysConfig.ADDRESS_VALIDATION, null, m_location.getAD_Client_ID());
boolean isEnabled = false;
if (addressValidation != null && addressValidation.trim().length() > 0 && m_location.getCountry() != null)
{
StringTokenizer st = new StringTokenizer(addressValidation, ";");
while (st.hasMoreTokens())
{
String token = st.nextToken().trim();
if (token.equals(m_location.getCountry().getCountryCode().trim()))
{
isEnabled = true;
break;
}
}
}
if (!isEnabled)
throw new AdempiereException(Msg.getMsg(Env.getCtx(), "AddressValidationNotEnabledForCountry"));
boolean ok = m_location.processOnline(p_C_AddressValidation_ID); boolean ok = m_location.processOnline(p_C_AddressValidation_ID);
m_location.saveEx(); m_location.saveEx();

View File

@ -23,6 +23,7 @@ import java.awt.GridBagLayout;
import java.awt.Insets; import java.awt.Insets;
import java.awt.event.ActionEvent; import java.awt.event.ActionEvent;
import java.awt.event.ActionListener; import java.awt.event.ActionListener;
import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.Iterator; import java.util.Iterator;
import java.util.Set; import java.util.Set;
@ -91,7 +92,7 @@ public class VLocationDialog extends CDialog
/** /**
* *
*/ */
private static final long serialVersionUID = -5279612834653363233L; private static final long serialVersionUID = 8870275797513554720L;
/** Lookup result header */ /** Lookup result header */
private Object[] header = null; private Object[] header = null;
@ -225,6 +226,7 @@ public class VLocationDialog extends CDialog
private CButton btnOnline = new CButton(); private CButton btnOnline = new CButton();
private CTextArea txtResult = new CTextArea(3, 30); private CTextArea txtResult = new CTextArea(3, 30);
private CCheckBox cbxValid = new CCheckBox(); private CCheckBox cbxValid = new CCheckBox();
private ArrayList<String> enabledCountryList = new ArrayList<String>();
//END //END
/** /**
@ -404,7 +406,19 @@ public class VLocationDialog extends CDialog
fCountry.setSelectedItem(country); fCountry.setSelectedItem(country);
} }
if (MSysConfig.getBooleanValue(MSysConfig.ADDRESS_VALIDATION, false, Env.getAD_Client_ID(Env.getCtx()))) String addressValidation = MSysConfig.getValue(MSysConfig.ADDRESS_VALIDATION, null, Env.getAD_Client_ID(Env.getCtx()));
enabledCountryList.clear();
if (addressValidation != null && addressValidation.trim().length() > 0)
{
st = new StringTokenizer(addressValidation, ";");
while (st.hasMoreTokens())
{
String token = st.nextToken().trim();
enabledCountryList.add(token);
}
}
if (enabledCountryList.size() > 0)
{ {
addLine(line++, new CLabel(Msg.getElement(Env.getCtx(), "C_AddressValidation_ID")), lstAddressValidation); addLine(line++, new CLabel(Msg.getElement(Env.getCtx(), "C_AddressValidation_ID")), lstAddressValidation);
@ -426,6 +440,23 @@ public class VLocationDialog extends CDialog
cbxValid.setSelected(m_location.isValid()); cbxValid.setSelected(m_location.isValid());
addLine(line++, new JLabel(), btnOnline); addLine(line++, new JLabel(), btnOnline);
if (!enabledCountryList.isEmpty())
{
boolean isEnabled = false;
if (m_location.getCountry() != null)
{
for (String enabledCountry : enabledCountryList)
{
if (enabledCountry.equals(m_location.getCountry().getCountryCode().trim()))
{
isEnabled = true;
break;
}
}
}
btnOnline.setEnabled(isEnabled);
}
} }
// Update UI // Update UI
@ -519,6 +550,24 @@ public class VLocationDialog extends CDialog
m_location.setCountry(c); m_location.setCountry(c);
initLocation(); initLocation();
if (!enabledCountryList.isEmpty())
{
boolean isEnabled = false;
if (c != null)
{
for (String enabledCountry : enabledCountryList)
{
if (enabledCountry.equals(c.getCountryCode().trim()))
{
isEnabled = true;
break;
}
}
}
btnOnline.setEnabled(isEnabled);
}
fCountry.requestFocus(); // allows to use Keyboard selection fCountry.requestFocus(); // allows to use Keyboard selection
inCountryAction = false; inCountryAction = false;
} }

View File

@ -21,6 +21,7 @@
package org.adempiere.webui.window; package org.adempiere.webui.window;
import java.util.ArrayList;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.StringTokenizer; import java.util.StringTokenizer;
@ -88,7 +89,8 @@ public class WLocationDialog extends Window implements EventListener<Event>
/** /**
* *
*/ */
private static final long serialVersionUID = -6213326035184139513L; private static final long serialVersionUID = 5368065537791919302L;
private static final String LABEL_STYLE = "white-space: nowrap;"; private static final String LABEL_STYLE = "white-space: nowrap;";
/** Logger */ /** Logger */
private static CLogger log = CLogger.getCLogger(WLocationDialog.class); private static CLogger log = CLogger.getCLogger(WLocationDialog.class);
@ -147,6 +149,7 @@ public class WLocationDialog extends Window implements EventListener<Event>
private Button btnOnline; private Button btnOnline;
private Textbox txtResult; private Textbox txtResult;
private Checkbox cbxValid; private Checkbox cbxValid;
private ArrayList<String> enabledCountryList = new ArrayList<String>();
private GridField m_GridField = null; private GridField m_GridField = null;
private boolean onSaveError = false; private boolean onSaveError = false;
@ -380,7 +383,19 @@ public class WLocationDialog extends Window implements EventListener<Event>
if (MLocation.LOCATION_MAPS_URL_PREFIX != null || MLocation.LOCATION_MAPS_ROUTE_PREFIX != null) if (MLocation.LOCATION_MAPS_URL_PREFIX != null || MLocation.LOCATION_MAPS_ROUTE_PREFIX != null)
vbox.appendChild(pnlLinks); vbox.appendChild(pnlLinks);
if (MSysConfig.getBooleanValue(MSysConfig.ADDRESS_VALIDATION, false, Env.getAD_Client_ID(Env.getCtx()))) String addressValidation = MSysConfig.getValue(MSysConfig.ADDRESS_VALIDATION, null, Env.getAD_Client_ID(Env.getCtx()));
enabledCountryList.clear();
if (addressValidation != null && addressValidation.trim().length() > 0)
{
StringTokenizer st = new StringTokenizer(addressValidation, ";");
while (st.hasMoreTokens())
{
String token = st.nextToken().trim();
enabledCountryList.add(token);
}
}
if (enabledCountryList.size() > 0)
{ {
Grid grid = GridFactory.newGridLayout(); Grid grid = GridFactory.newGridLayout();
vbox.appendChild(grid); vbox.appendChild(grid);
@ -423,6 +438,23 @@ public class WLocationDialog extends Window implements EventListener<Event>
cell.appendChild(btnOnline); cell.appendChild(btnOnline);
cell.setAlign("right"); cell.setAlign("right");
row.appendChild(cell); row.appendChild(cell);
if (!enabledCountryList.isEmpty())
{
boolean isEnabled = false;
if (m_location.getCountry() != null)
{
for (String enabledCountry : enabledCountryList)
{
if (enabledCountry.equals(m_location.getCountry().getCountryCode().trim()))
{
isEnabled = true;
break;
}
}
}
btnOnline.setEnabled(isEnabled);
}
} }
vbox.setVflex("1"); vbox.setVflex("1");
@ -798,6 +830,24 @@ public class WLocationDialog extends Window implements EventListener<Event>
m_location.setCity(null); m_location.setCity(null);
// refresh // refresh
initLocation(); initLocation();
if (!enabledCountryList.isEmpty())
{
boolean isEnabled = false;
if (c != null)
{
for (String enabledCountry : enabledCountryList)
{
if (enabledCountry.equals(c.getCountryCode().trim()))
{
isEnabled = true;
break;
}
}
}
btnOnline.setEnabled(isEnabled);
}
inCountryAction = false; inCountryAction = false;
lstCountry.focus(); lstCountry.focus();
} }