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

refactoiring, documentation AddressValidation_lib

parent 0e976cf1
No related branches found
No related tags found
No related merge requests found
......@@ -11,6 +11,7 @@
<entityField>
<name>UID</name>
<title>Address</title>
<description>UID consists of all fields as JSON. </description>
</entityField>
<entityProvider>
<name>ZipValidaton</name>
......@@ -74,6 +75,7 @@
</entityField>
<entityField>
<name>VALUE</name>
<description>Final value returned</description>
</entityField>
<entityProvider>
<name>CityValidation</name>
......
import("system.result");
import("system.logging");
import("AddressValidation_lib");
import("system.vars");
......@@ -11,7 +10,7 @@ var country = "";
if (vars.exists("$param.Country_param") && vars.get("$param.Country_param"))
country = vars.get("$param.Country_param");
// get the value typed by the user
var filter = "";
var sysFilter = vars.get("$sys.filter");
if(sysFilter.filter != null) {
......@@ -20,7 +19,4 @@ if(sysFilter.filter != null) {
var foundAddresses = AddressValidationUtils.validate(filter, type, country);
if (filter)
foundAddresses.push([filter, filter, filter, "", "", "", "", "", filter]);
result.object(foundAddresses);
\ No newline at end of file
......@@ -38,10 +38,6 @@
<name>12727b21-0359-4430-a9c2-54eb48e2e864</name>
<entityField>CITY</entityField>
</neonTableColumn>
<neonTableColumn>
<name>6af52273-25bf-4286-83cc-217aea94ad09</name>
<entityField>ADDRIDENTIFIER</entityField>
</neonTableColumn>
<neonTableColumn>
<name>af515eed-da89-49dc-ba3a-30958bd4fedd</name>
<entityField>DISTRICT</entityField>
......@@ -54,6 +50,10 @@
<name>aafc58cf-7dbb-42cb-b04c-d0869e58d09a</name>
<entityField>STATE</entityField>
</neonTableColumn>
<neonTableColumn>
<name>6af52273-25bf-4286-83cc-217aea94ad09</name>
<entityField>ADDRIDENTIFIER</entityField>
</neonTableColumn>
</columns>
</titledListViewTemplate>
</children>
......
......@@ -13,31 +13,43 @@
<entityField>#ENTITY</entityField>
<columns>
<neonTableColumn>
<name>b210372e-dfd3-4cec-bc2e-84b72aebb2b6</name>
<name>2aebe24e-875a-4c57-8461-16da46d6f080</name>
<entityField>ADDR_TYPE</entityField>
</neonTableColumn>
<neonTableColumn>
<name>d8a7a26b-9d7f-44d7-bbb1-b0404d5b8b2f</name>
<name>435f10b8-b6ef-4187-bffc-fc6104a6130c</name>
<entityField>COUNTRY</entityField>
</neonTableColumn>
<neonTableColumn>
<name>c20668f3-6722-4a90-86d6-0d29be06dbe1</name>
<name>ac71d5eb-7ce7-41a0-91aa-5594f2238788</name>
<entityField>ADDRESS</entityField>
</neonTableColumn>
<neonTableColumn>
<name>0eac127d-de3d-4ff0-9ac2-1227b33c854a</name>
<name>61261845-740e-4f4b-a1f8-5e6aeac2deba</name>
<entityField>BUILDINGNO</entityField>
</neonTableColumn>
<neonTableColumn>
<name>0eac127d-de3d-aff0-9ac2-1327b33c854a</name>
<name>c1372a93-cf83-4c55-90e6-3b6b352abebf</name>
<entityField>ZIP</entityField>
</neonTableColumn>
<neonTableColumn>
<name>fafca2d6-c2dd-4b66-b1ff-1d6ba451827b</name>
<name>2e7ba632-36ad-4852-bcca-d75bcf3f7de1</name>
<entityField>CITY</entityField>
</neonTableColumn>
<neonTableColumn>
<name>481496b8-d611-4b4a-9c5e-1d28a7136a2d</name>
<name>e25f4140-0772-4417-85f0-41052b413c30</name>
<entityField>DISTRICT</entityField>
</neonTableColumn>
<neonTableColumn>
<name>b62515bf-e89d-44a9-94ff-933766657fe5</name>
<entityField>REGION</entityField>
</neonTableColumn>
<neonTableColumn>
<name>66ae75ca-7a5c-4cf0-b768-6c2900f7b7c6</name>
<entityField>STATE</entityField>
</neonTableColumn>
<neonTableColumn>
<name>443b9d7d-dac2-40b2-bb2b-d5e0091877a9</name>
<entityField>ADDRIDENTIFIER</entityField>
</neonTableColumn>
</columns>
......
......@@ -2,14 +2,25 @@ import("system.vars");
import("system.neon");
import("system.net");
import("system.util");
import("system.logging");
/**
* Class used for the address validation types.
* Do not create new instances anywhere else than inside of the get-function!
* @param {String} pKey the key-name
* @param {String} pParamName name used by the webservice
*/
function AddressValidationType(pKey, pParamName)
{
this.key = pKey;
this.paramName = pParamName;
}
/**
* get all possible validation types or one specific
* @param {String} [pKey=undefined] if provided, this function returns only the validation type with this key
*
* @return {Object|AddressValidationType} object containing all AddressValidationTypes or one specific AddressValidationType
*/
AddressValidationType.get = function(pKey)
{
if (!this._cache)
......@@ -32,11 +43,29 @@ AddressValidationType.get = function(pKey)
*/
function AddressValidationUtils() {}
/**
* validate the value with the webservice
* @param {String} pValue to search for
* @param {AddressValidationType|String} pType type used for the search. Can be an AddressValidationType or the key of the AddressValidationType
* @param {String} pCountry needed by the webservice e.g. "DE"
*
* @return {String[][]} [UID,
* displayName,
* zip,
* city,
* country,
* district,
* region,
* state,
* value (the result. e.g. if pType was ZIP, the value is the found zip)
*/
AddressValidationUtils.validate = function(pValue, pType, pCountry)
{
// TODO: Options for url, user, pw
var userName = "Admin";
var pw = "a";
var url = "https://services.aditosoftware.local/services/rest/ws_checkAddress";
var actionType = "GET";
// get AddressValidationType-Object if it is only the key
if (typeof pType == "string")
......@@ -44,36 +73,40 @@ AddressValidationUtils.validate = function(pValue, pType, pCountry)
if (pValue && pType)
{
// fill params
var parameters = {};
if (pCountry)
{
parameters.country = pCountry;
}
parameters[pType.paramName] = pValue;
var url = "https://services.aditosoftware.local/services/rest/ws_checkAddress";
var actionType = "GET";
// call webservice
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]
]
});
// add default result consisting of pValue
var defaultResult = [[{}, pValue]];
defaultResult[0][0][pType.paramName] = pValue;
return JSON.parse(ret.body)
.concat(defaultResult)
.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
{
......@@ -85,6 +118,9 @@ AddressValidationUtils.validate = function(pValue, pType, pCountry)
return [];
}
/**
* set all address-fields by the value of $this.value, which should contain an object of all values as JSON
*/
AddressValidationUtils.setFields = function()
{
var data = JSON.parse(vars.get("$this.value"));
......
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