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 @@ ...@@ -11,6 +11,7 @@
<entityField> <entityField>
<name>UID</name> <name>UID</name>
<title>Address</title> <title>Address</title>
<description>UID consists of all fields as JSON. </description>
</entityField> </entityField>
<entityProvider> <entityProvider>
<name>ZipValidaton</name> <name>ZipValidaton</name>
...@@ -74,6 +75,7 @@ ...@@ -74,6 +75,7 @@
</entityField> </entityField>
<entityField> <entityField>
<name>VALUE</name> <name>VALUE</name>
<description>Final value returned</description>
</entityField> </entityField>
<entityProvider> <entityProvider>
<name>CityValidation</name> <name>CityValidation</name>
......
import("system.result"); import("system.result");
import("system.logging");
import("AddressValidation_lib"); import("AddressValidation_lib");
import("system.vars"); import("system.vars");
...@@ -11,7 +10,7 @@ var country = ""; ...@@ -11,7 +10,7 @@ var country = "";
if (vars.exists("$param.Country_param") && vars.get("$param.Country_param")) if (vars.exists("$param.Country_param") && vars.get("$param.Country_param"))
country = vars.get("$param.Country_param"); country = vars.get("$param.Country_param");
// get the value typed by the user
var filter = ""; var filter = "";
var sysFilter = vars.get("$sys.filter"); var sysFilter = vars.get("$sys.filter");
if(sysFilter.filter != null) { if(sysFilter.filter != null) {
...@@ -20,7 +19,4 @@ if(sysFilter.filter != null) { ...@@ -20,7 +19,4 @@ if(sysFilter.filter != null) {
var foundAddresses = AddressValidationUtils.validate(filter, type, country); var foundAddresses = AddressValidationUtils.validate(filter, type, country);
if (filter)
foundAddresses.push([filter, filter, filter, "", "", "", "", "", filter]);
result.object(foundAddresses); result.object(foundAddresses);
\ No newline at end of file
...@@ -38,10 +38,6 @@ ...@@ -38,10 +38,6 @@
<name>12727b21-0359-4430-a9c2-54eb48e2e864</name> <name>12727b21-0359-4430-a9c2-54eb48e2e864</name>
<entityField>CITY</entityField> <entityField>CITY</entityField>
</neonTableColumn> </neonTableColumn>
<neonTableColumn>
<name>6af52273-25bf-4286-83cc-217aea94ad09</name>
<entityField>ADDRIDENTIFIER</entityField>
</neonTableColumn>
<neonTableColumn> <neonTableColumn>
<name>af515eed-da89-49dc-ba3a-30958bd4fedd</name> <name>af515eed-da89-49dc-ba3a-30958bd4fedd</name>
<entityField>DISTRICT</entityField> <entityField>DISTRICT</entityField>
...@@ -54,6 +50,10 @@ ...@@ -54,6 +50,10 @@
<name>aafc58cf-7dbb-42cb-b04c-d0869e58d09a</name> <name>aafc58cf-7dbb-42cb-b04c-d0869e58d09a</name>
<entityField>STATE</entityField> <entityField>STATE</entityField>
</neonTableColumn> </neonTableColumn>
<neonTableColumn>
<name>6af52273-25bf-4286-83cc-217aea94ad09</name>
<entityField>ADDRIDENTIFIER</entityField>
</neonTableColumn>
</columns> </columns>
</titledListViewTemplate> </titledListViewTemplate>
</children> </children>
......
...@@ -13,31 +13,43 @@ ...@@ -13,31 +13,43 @@
<entityField>#ENTITY</entityField> <entityField>#ENTITY</entityField>
<columns> <columns>
<neonTableColumn> <neonTableColumn>
<name>b210372e-dfd3-4cec-bc2e-84b72aebb2b6</name> <name>2aebe24e-875a-4c57-8461-16da46d6f080</name>
<entityField>ADDR_TYPE</entityField> <entityField>ADDR_TYPE</entityField>
</neonTableColumn> </neonTableColumn>
<neonTableColumn> <neonTableColumn>
<name>d8a7a26b-9d7f-44d7-bbb1-b0404d5b8b2f</name> <name>435f10b8-b6ef-4187-bffc-fc6104a6130c</name>
<entityField>COUNTRY</entityField> <entityField>COUNTRY</entityField>
</neonTableColumn> </neonTableColumn>
<neonTableColumn> <neonTableColumn>
<name>c20668f3-6722-4a90-86d6-0d29be06dbe1</name> <name>ac71d5eb-7ce7-41a0-91aa-5594f2238788</name>
<entityField>ADDRESS</entityField> <entityField>ADDRESS</entityField>
</neonTableColumn> </neonTableColumn>
<neonTableColumn> <neonTableColumn>
<name>0eac127d-de3d-4ff0-9ac2-1227b33c854a</name> <name>61261845-740e-4f4b-a1f8-5e6aeac2deba</name>
<entityField>BUILDINGNO</entityField> <entityField>BUILDINGNO</entityField>
</neonTableColumn> </neonTableColumn>
<neonTableColumn> <neonTableColumn>
<name>0eac127d-de3d-aff0-9ac2-1327b33c854a</name> <name>c1372a93-cf83-4c55-90e6-3b6b352abebf</name>
<entityField>ZIP</entityField> <entityField>ZIP</entityField>
</neonTableColumn> </neonTableColumn>
<neonTableColumn> <neonTableColumn>
<name>fafca2d6-c2dd-4b66-b1ff-1d6ba451827b</name> <name>2e7ba632-36ad-4852-bcca-d75bcf3f7de1</name>
<entityField>CITY</entityField> <entityField>CITY</entityField>
</neonTableColumn> </neonTableColumn>
<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> <entityField>ADDRIDENTIFIER</entityField>
</neonTableColumn> </neonTableColumn>
</columns> </columns>
......
...@@ -2,14 +2,25 @@ import("system.vars"); ...@@ -2,14 +2,25 @@ import("system.vars");
import("system.neon"); import("system.neon");
import("system.net"); import("system.net");
import("system.util"); 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) function AddressValidationType(pKey, pParamName)
{ {
this.key = pKey; this.key = pKey;
this.paramName = pParamName; 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) AddressValidationType.get = function(pKey)
{ {
if (!this._cache) if (!this._cache)
...@@ -32,11 +43,29 @@ AddressValidationType.get = function(pKey) ...@@ -32,11 +43,29 @@ AddressValidationType.get = function(pKey)
*/ */
function AddressValidationUtils() {} 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) AddressValidationUtils.validate = function(pValue, pType, pCountry)
{ {
// TODO: Options for url, user, pw // TODO: Options for url, user, pw
var userName = "Admin"; var userName = "Admin";
var pw = "a"; 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 // get AddressValidationType-Object if it is only the key
if (typeof pType == "string") if (typeof pType == "string")
...@@ -44,36 +73,40 @@ AddressValidationUtils.validate = function(pValue, pType, pCountry) ...@@ -44,36 +73,40 @@ AddressValidationUtils.validate = function(pValue, pType, pCountry)
if (pValue && pType) if (pValue && pType)
{ {
// fill params
var parameters = {}; var parameters = {};
if (pCountry) if (pCountry)
{ {
parameters.country = pCountry; parameters.country = pCountry;
} }
parameters[pType.paramName] = pValue; parameters[pType.paramName] = pValue;
var url = "https://services.aditosoftware.local/services/rest/ws_checkAddress"; // call webservice
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)); 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) if (ret.hasHttpSuccessStatusCode)
{ {
return JSON.parse(ret.body).map(function(pAddress) // add default result consisting of pValue
{ var defaultResult = [[{}, pValue]];
var data = pAddress[0]; defaultResult[0][0][pType.paramName] = pValue;
return [
JSON.stringify(data), return JSON.parse(ret.body)
pAddress[1], .concat(defaultResult)
data.zip, .map(function(pAddress)
data.city, {
data.country, var data = pAddress[0];
data.district, return [
data.region, JSON.stringify(data),
data.state, pAddress[1],
data[pType.paramName] data.zip,
] data.city,
}); data.country,
data.district,
data.region,
data.state,
data[pType.paramName]
]
});
} }
else else
{ {
...@@ -85,6 +118,9 @@ AddressValidationUtils.validate = function(pValue, pType, pCountry) ...@@ -85,6 +118,9 @@ AddressValidationUtils.validate = function(pValue, pType, pCountry)
return []; return [];
} }
/**
* set all address-fields by the value of $this.value, which should contain an object of all values as JSON
*/
AddressValidationUtils.setFields = function() AddressValidationUtils.setFields = function()
{ {
var data = JSON.parse(vars.get("$this.value")); 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