Skip to content
Snippets Groups Projects
Commit 7000cb6d authored by Johannes Hörmann's avatar Johannes Hörmann
Browse files

First version of Address/Communication validation webservice

parent 3e402491
No related branches found
No related tags found
No related merge requests found
<?xml version="1.0" encoding="UTF-8"?>
<process xmlns="http://www.adito.de/2018/ao/Model" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" VERSION="1.2.1" xsi:schemaLocation="http://www.adito.de/2018/ao/Model adito://models/xsd/process/1.2.1">
<name>AddressValidation_lib</name>
<majorModelMode>DISTRIBUTED</majorModelMode>
<process>%aditoprj%/process/AddressValidation_lib/process.js</process>
<variants>
<element>LIBRARY</element>
</variants>
</process>
import("system.vars");
import("system.neon");
import("system.net");
import("system.util");
import("system.logging");
function AddressValidationType(pKey, pParamName)
{
this.key = pKey;
this.paramName = pParamName;
}
AddressValidationType.get = function(pKey)
{
if (!this._cache)
this._cache = {
TYPE_ZIP: new AddressValidationType("TYPE_ZIP", "zip"),
TYPE_CITY: new AddressValidationType("TYPE_CITY", "city")
}
if (pKey)
return this._cache[pKey];
return this._cache;
}
/**
* Class containing utility functions for address validation
* do not create an instance of this
*
* @class
*/
function AddressValidationUtils() {}
AddressValidationUtils.validate = function(pValue, pType, pCountry)
{
// TODO: Options for url, user, pw
var userName = "Admin";
var pw = "a";
// get AddressValidationType-Object if it is only the key
if (typeof pType == "string")
pType = AddressValidationType.get(pType);
if (pValue && pType)
{
var parameters = {};
if (pCountry)
{
parameters.country = pCountry;
}
parameters[pType.paramName] = pValue;
var url = "https://services.aditosoftware.local/services/rest/ws_checkAddress";
var actionType = "GET";
var ret = JSON.parse(net.callRestWebserviceBasicAuth(url, actionType, parameters, null, null, "text/plain", "text/plain", util.DATA_TEXT, util.DATA_TEXT, userName, pw, true));
if (ret.hasHttpSuccessStatusCode)
{
return JSON.parse(ret.body).map(function(pAddress)
{
var data = pAddress[0];
return [
JSON.stringify(data),
pAddress[1],
data.zip,
data.city,
data.country,
data.district,
data.region,
data.state,
data[pType.paramName]
]
});
}
else
{
// error handling
}
}
return [];
}
AddressValidationUtils.setFields = function()
{
var data = JSON.parse(vars.get("$this.value"));
_setField("$field.ZIP", data.zip);
_setField("$field.COUNTRY", data.country);
_setField("$field.CITY", data.city);
_setField("$field.DISTRICT", data.district);
_setField("$field.REGION", data.region);
_setField("$field.STATE", data.state);
function _setField(pField, pValue)
{
if (pValue)
neon.setFieldValue(pField, pValue);
}
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment