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:
parent
32b7640889
commit
23c5094192
|
@ -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
|
||||
;
|
|
@ -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
|
||||
;
|
|
@ -13,6 +13,8 @@
|
|||
*****************************************************************************/
|
||||
package org.adempiere.base.event;
|
||||
|
||||
import java.util.StringTokenizer;
|
||||
|
||||
import org.compiere.model.I_C_Location;
|
||||
import org.compiere.model.MAddressValidation;
|
||||
import org.compiere.model.MLocation;
|
||||
|
@ -36,16 +38,33 @@ public class AddressValidationEventHandler extends AbstractEventHandler {
|
|||
if (po.get_TableName().equals(I_C_Location.Table_Name))
|
||||
{
|
||||
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;
|
||||
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());
|
||||
StringTokenizer st = new StringTokenizer(addressValidation, ";");
|
||||
while (st.hasMoreTokens())
|
||||
{
|
||||
String token = st.nextToken().trim();
|
||||
if (token.equals(location.getCountry().getCountryCode().trim()))
|
||||
{
|
||||
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());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,11 +14,13 @@
|
|||
package org.adempiere.process;
|
||||
|
||||
import java.sql.Timestamp;
|
||||
import java.util.StringTokenizer;
|
||||
import java.util.logging.Level;
|
||||
|
||||
import org.adempiere.exceptions.AdempiereException;
|
||||
import org.compiere.model.MAddressTransaction;
|
||||
import org.compiere.model.MLocation;
|
||||
import org.compiere.model.MSysConfig;
|
||||
import org.compiere.process.ProcessInfoLog;
|
||||
import org.compiere.process.ProcessInfoParameter;
|
||||
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));
|
||||
|
||||
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);
|
||||
m_location.saveEx();
|
||||
|
||||
|
|
|
@ -23,6 +23,7 @@ import java.awt.GridBagLayout;
|
|||
import java.awt.Insets;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
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 */
|
||||
private Object[] header = null;
|
||||
|
@ -225,6 +226,7 @@ public class VLocationDialog extends CDialog
|
|||
private CButton btnOnline = new CButton();
|
||||
private CTextArea txtResult = new CTextArea(3, 30);
|
||||
private CCheckBox cbxValid = new CCheckBox();
|
||||
private ArrayList<String> enabledCountryList = new ArrayList<String>();
|
||||
//END
|
||||
|
||||
/**
|
||||
|
@ -404,7 +406,19 @@ public class VLocationDialog extends CDialog
|
|||
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);
|
||||
|
||||
|
@ -426,6 +440,23 @@ public class VLocationDialog extends CDialog
|
|||
cbxValid.setSelected(m_location.isValid());
|
||||
|
||||
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
|
||||
|
@ -519,7 +550,25 @@ public class VLocationDialog extends CDialog
|
|||
m_location.setCountry(c);
|
||||
|
||||
initLocation();
|
||||
fCountry.requestFocus(); // allows to use Keyboard selection
|
||||
|
||||
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
|
||||
inCountryAction = false;
|
||||
}
|
||||
// Region Changed
|
||||
|
|
|
@ -21,6 +21,7 @@
|
|||
|
||||
package org.adempiere.webui.window;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
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;";
|
||||
/** Logger */
|
||||
private static CLogger log = CLogger.getCLogger(WLocationDialog.class);
|
||||
|
@ -147,6 +149,7 @@ public class WLocationDialog extends Window implements EventListener<Event>
|
|||
private Button btnOnline;
|
||||
private Textbox txtResult;
|
||||
private Checkbox cbxValid;
|
||||
private ArrayList<String> enabledCountryList = new ArrayList<String>();
|
||||
|
||||
private GridField m_GridField = null;
|
||||
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)
|
||||
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();
|
||||
vbox.appendChild(grid);
|
||||
|
@ -423,6 +438,23 @@ public class WLocationDialog extends Window implements EventListener<Event>
|
|||
cell.appendChild(btnOnline);
|
||||
cell.setAlign("right");
|
||||
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");
|
||||
|
@ -798,6 +830,24 @@ public class WLocationDialog extends Window implements EventListener<Event>
|
|||
m_location.setCity(null);
|
||||
// refresh
|
||||
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;
|
||||
lstCountry.focus();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue