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

rename AddressValidation_lib to wsValidation_lib, refactor, add phone validation

parent c093ebf1
No related branches found
No related tags found
No related merge requests found
Showing
with 223 additions and 81 deletions
......@@ -30,7 +30,7 @@ switch (tableName)
break;
case "COMMUNICATION":
res = IndexsearchUtils.getAffectedIdValues("CONTACT_ID", infoContainer, function (id){
return db.array(db.COLUMN, ["select ADDRESS.CONTACT_ID from COMMUNICATION where COMMUNICATIONID = ?", [
return db.array(db.COLUMN, ["select COMMUNICATION.CONTACT_ID from COMMUNICATION where COMMUNICATIONID = ?", [
[id, SqlUtils.getSingleColumnType("COMMUNICATION", "COMMUNICATIONID")]
]]);
});
......
......@@ -33,7 +33,7 @@ switch (tableName)
break;
case "COMMUNICATION":
res = IndexsearchUtils.getAffectedIdValues("CONTACT_ID", infoContainer, function (id){
return db.array(db.COLUMN, ["select ADDRESS.CONTACT_ID from COMMUNICATION where COMMUNICATIONID = ?", [
return db.array(db.COLUMN, ["select COMMUNICATION.CONTACT_ID from COMMUNICATION where COMMUNICATIONID = ?", [
[id, SqlUtils.getSingleColumnType("COMMUNICATION", "COMMUNICATIONID")]
]]);
});
......
......@@ -17,12 +17,6 @@
<name>ZipValidaton</name>
<fieldType>DEPENDENCY_IN</fieldType>
<dependencies>
<entityDependency>
<name>1b2e3be5-b3be-42c5-a55f-b892fdfbf21f</name>
<entityName>Communication_entity</entityName>
<fieldName>AddressValidator</fieldName>
<isConsumer v="false" />
</entityDependency>
<entityDependency>
<name>fcfcbebe-260a-4773-a874-9791b4887ae2</name>
<entityName>Address_entity</entityName>
......
import("AddressValidation_lib");
import("WsValidation_lib");
import("system.result");
result.string(AddressValidationType.get().TYPE_CITY.key);
\ No newline at end of file
result.string(WsValidationType.get().TYPE_CITY.key);
\ No newline at end of file
import("AddressValidation_lib");
import("WsValidation_lib");
import("system.result");
result.string(AddressValidationType.get().TYPE_CITY.key);
\ No newline at end of file
import("AddressValidation_lib");
import("WsValidation_lib");
import("system.result");
result.string(AddressValidationType.get().TYPE_ZIP.key);
\ No newline at end of file
result.string(WsValidationType.get().TYPE_ZIP.key);
\ No newline at end of file
import("AddressValidation_lib");
import("WsValidation_lib");
import("system.result");
result.string(AddressValidationType.get().TYPE_ZIP.key);
\ No newline at end of file
import("system.result");
import("AddressValidation_lib");
import("WsValidation_lib");
import("system.vars");
var type = "";
......@@ -20,6 +20,6 @@ if(sysFilter.filter != null) {
if (!filter && vars.exists("$param.CurrentValue_param") && vars.get("$param.CurrentValue_param"))
filter = vars.get("$param.CurrentValue_param");
var foundAddresses = AddressValidationUtils.validate(filter, type, country);
var foundAddresses = WsValidationUtils.validate(filter, type, country);
result.object(foundAddresses);
\ No newline at end of file
import("AddressValidation_lib");
import("WsValidation_lib");
AddressValidationUtils.setFields();
\ No newline at end of file
WsValidationUtils.setAddressFields();
\ No newline at end of file
import("AddressValidation_lib");
import("WsValidation_lib");
AddressValidationUtils.setFields();
\ No newline at end of file
WsValidationUtils.setAddressFields();
\ No newline at end of file
......@@ -208,15 +208,6 @@ Usually this is used for filtering COMMUNICATION-entries by a specified contact
<name>DATE_EDIT</name>
<valueProcess>%aditoprj%/entity/Communication_entity/entityfields/date_edit/valueProcess.js</valueProcess>
</entityField>
<entityConsumer>
<name>AddressValidator</name>
<fieldType>DEPENDENCY_OUT</fieldType>
<dependency>
<name>dependency</name>
<entityName>AddressValidation_entity</entityName>
<fieldName>ZipValidaton</fieldName>
</dependency>
</entityConsumer>
</entityFields>
<recordContainers>
<dbRecordContainer>
......
......@@ -23,5 +23,5 @@ if (fn != null)
additional.countryCode = vars.get("$param.ContactsMainCountry_param");//TODO: try to use users language first and then the companies
var res = fn.call(null, commAddr, additional);
if (res != null)
result.string(res);
result.object(res);
}
\ No newline at end of file
import("system.util");
import("system.net");
import("system.vars");
import("Keyword_lib");
import("KeywordRegistry_basic");
import("WsValidation_lib");
import("system.neon");
import("PostalAddress_lib");
// TODO: put into AddressValidation_lib
import("KeywordRegistry_basic");
import("Keyword_lib");
import("system.vars");
var addr = vars.get("$this.value");
......@@ -19,20 +15,9 @@ if (addr)
switch (commCategory)
{
case "TELEPHONE": // Phone
if(addr.length > 5) // https://services.aditosoftware.local/services/rest/ws_checkPhoneNumber?Number=017666862716&Country=DE
if(addr.length > 5)
{
var url = "https://services.aditosoftware.local/services/rest/ws_checkPhoneNumber";
var actionType = "GET";
var ret = JSON.parse(net.callRestWebserviceBasicAuth(url, actionType, {Number:addr, Country:vars.get("$param.ContactsMainCountry_param")}, null, null, "text/plain", "text/plain", util.DATA_TEXT, util.DATA_TEXT, "Admin", "a", true));
if (ret.hasHttpSuccessStatusCode)
{
neon.setFieldValue("$field.ADDR", ret.body);
}
else
{
// error handling
}
neon.setFieldValue("$field.ADDR", WsValidationUtils.validate(addr, WsValidationType.get().TYPE_PHONE, vars.get("$param.ContactsMainCountry_param")));
}
break;
default:
......
......@@ -22,14 +22,6 @@
<name>dfaa01a1-0b11-4f92-aa18-89f12ebb2db5</name>
<entityField>COUNTRY</entityField>
</neonTableColumn>
<neonTableColumn>
<name>4e5e6a4f-f43e-4861-a912-fb05e576f960</name>
<entityField>ADDRESS</entityField>
</neonTableColumn>
<neonTableColumn>
<name>935bcecf-fdd9-4e82-a53f-3c3082c85340</name>
<entityField>BUILDINGNO</entityField>
</neonTableColumn>
<neonTableColumn>
<name>0336ea99-c4a1-4f39-b5aa-a520a7dcbaab</name>
<entityField>ZIP</entityField>
......@@ -38,10 +30,6 @@
<name>12727b21-0359-4430-a9c2-54eb48e2e864</name>
<entityField>CITY</entityField>
</neonTableColumn>
<neonTableColumn>
<name>af515eed-da89-49dc-ba3a-30958bd4fedd</name>
<entityField>DISTRICT</entityField>
</neonTableColumn>
<neonTableColumn>
<name>29dbb3f5-6f80-4100-aed3-334ac0b9cc48</name>
<entityField>REGION</entityField>
......@@ -50,6 +38,14 @@
<name>aafc58cf-7dbb-42cb-b04c-d0869e58d09a</name>
<entityField>STATE</entityField>
</neonTableColumn>
<neonTableColumn>
<name>4e5e6a4f-f43e-4861-a912-fb05e576f960</name>
<entityField>ADDRESS</entityField>
</neonTableColumn>
<neonTableColumn>
<name>935bcecf-fdd9-4e82-a53f-3c3082c85340</name>
<entityField>BUILDINGNO</entityField>
</neonTableColumn>
<neonTableColumn>
<name>6af52273-25bf-4286-83cc-217aea94ad09</name>
<entityField>ADDRIDENTIFIER</entityField>
......
......@@ -24,10 +24,6 @@
<name>d32d92bf-db7d-443f-b911-6731ea89cf3b</name>
<entityField>COUNTRY</entityField>
</neonTableColumn>
<neonTableColumn>
<name>4035d833-ece7-4562-8acf-51c7a01b8497</name>
<entityField>DISTRICT</entityField>
</neonTableColumn>
<neonTableColumn>
<name>05bb9d3b-0e90-4a1a-bfe8-03b7dab6ed01</name>
<entityField>REGION</entityField>
......
......@@ -20,14 +20,6 @@
<name>435f10b8-b6ef-4187-bffc-fc6104a6130c</name>
<entityField>COUNTRY</entityField>
</neonTableColumn>
<neonTableColumn>
<name>ac71d5eb-7ce7-41a0-91aa-5594f2238788</name>
<entityField>ADDRESS</entityField>
</neonTableColumn>
<neonTableColumn>
<name>61261845-740e-4f4b-a1f8-5e6aeac2deba</name>
<entityField>BUILDINGNO</entityField>
</neonTableColumn>
<neonTableColumn>
<name>c1372a93-cf83-4c55-90e6-3b6b352abebf</name>
<entityField>ZIP</entityField>
......@@ -36,10 +28,6 @@
<name>2e7ba632-36ad-4852-bcca-d75bcf3f7de1</name>
<entityField>CITY</entityField>
</neonTableColumn>
<neonTableColumn>
<name>e25f4140-0772-4417-85f0-41052b413c30</name>
<entityField>DISTRICT</entityField>
</neonTableColumn>
<neonTableColumn>
<name>b62515bf-e89d-44a9-94ff-933766657fe5</name>
<entityField>REGION</entityField>
......@@ -48,6 +36,14 @@
<name>66ae75ca-7a5c-4cf0-b768-6c2900f7b7c6</name>
<entityField>STATE</entityField>
</neonTableColumn>
<neonTableColumn>
<name>ac71d5eb-7ce7-41a0-91aa-5594f2238788</name>
<entityField>ADDRESS</entityField>
</neonTableColumn>
<neonTableColumn>
<name>61261845-740e-4f4b-a1f8-5e6aeac2deba</name>
<entityField>BUILDINGNO</entityField>
</neonTableColumn>
<neonTableColumn>
<name>443b9d7d-dac2-40b2-bb2b-d5e0091877a9</name>
<entityField>ADDRIDENTIFIER</entityField>
......
......@@ -46,5 +46,25 @@
<name>addressValidation.pw</name>
<property>a</property>
</customStringProperty>
<customStringProperty>
<name>addressValidation.countryParamName</name>
<property>country</property>
</customStringProperty>
<customStringProperty>
<name>phoneValidation.url</name>
<property>https://services.aditosoftware.local/services/rest/ws_checkPhoneNumber</property>
</customStringProperty>
<customStringProperty>
<name>phoneValidation.user</name>
<property>Admin</property>
</customStringProperty>
<customStringProperty>
<name>phoneValidation.pw</name>
<property>a</property>
</customStringProperty>
<customStringProperty>
<name>phoneValidation.countryParamName</name>
<property>Country</property>
</customStringProperty>
</customProperties>
</preferences>
<?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>
<name>WsValidation_lib</name>
<majorModelMode>DISTRIBUTED</majorModelMode>
<process>%aditoprj%/process/AddressValidation_lib/process.js</process>
<process>%aditoprj%/process/WsValidation_lib/process.js</process>
<variants>
<element>LIBRARY</element>
</variants>
......
import("system.logging");
import("system.project");
import("system.vars");
import("system.neon");
......@@ -6,49 +5,89 @@ import("system.net");
import("system.util");
/**
* Class used for the address validation types.
* Class used for the webservice 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
* @param {String} pWebserviceName name of the webservice. Used to find the correct webservice configuraation
* @param {Function} pProcessResultCallback function for processing Webservice-result to the return value
*/
function AddressValidationType(pKey, pParamName)
function WsValidationType(pKey, pParamName, pWebserviceName, pProcessResultCallback)
{
this.key = pKey;
this.paramName = pParamName;
this.processResultCallback = pProcessResultCallback;
this.webserviceName = pWebserviceName;
}
/**
* 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
* @return {Object|WsValidationType} object containing all WsValidationTypes or one specific WsValidationType
*/
AddressValidationType.get = function(pKey)
WsValidationType.get = function(pKey)
{
if (!this._cache)
this._cache = {
TYPE_ZIP: new AddressValidationType("TYPE_ZIP", "zip"),
TYPE_CITY: new AddressValidationType("TYPE_CITY", "city")
// Address lookups
TYPE_ZIP: new WsValidationType("TYPE_ZIP", "zip", "addressValidation", _processAddressLookup),
TYPE_CITY: new WsValidationType("TYPE_CITY", "city", "addressValidation", _processAddressLookup),
// Communication validation
TYPE_PHONE: new WsValidationType("TYPE_PHONE", "Number", "phoneValidation", _processCommunicationValidation)
}
if (pKey)
return this._cache[pKey];
return this._cache;
function _processAddressLookup(pWsResult, pValue)
{
// add default result consisting of pValue
var defaultResult = [[{}, pValue]];
defaultResult[0][0][this.paramName] = pValue;
return JSON.parse(pWsResult)
.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[this.paramName]]
})
}
function _processCommunicationValidation(pWsResult, pValue)
{
return pWsResult;
}
}
/**
* Class containing utility functions for address validation
* Class containing utility functions for validation webservices
* It can be used for lookups (like AddressValidation-entity) or onValueChange-formatting/validation like the Communication.ADDR-field.
* do not create an instance of this
*
* @class
*/
function AddressValidationUtils() {}
function WsValidationUtils() {}
/**
* 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 {WsValidationType|String} pType type used for the search. Can be an WsValidationType or the key of the WsValidationType
* @param {String} pCountry needed by the webservice e.g. "DE"
*
* @return {String[][]} [UID,
......@@ -61,16 +100,19 @@ function AddressValidationUtils() {}
* state,
* value (the result. e.g. if pType was ZIP, the value is the found zip)
*/
AddressValidationUtils.validate = function(pValue, pType, pCountry)
WsValidationUtils.validate = function(pValue, pType, pCountry)
{
var userName = project.getPreferenceValue("custom.addressValidation.user");
var pw = project.getPreferenceValue("custom.addressValidation.pw");
var url = project.getPreferenceValue("custom.addressValidation.url");
var actionType = "GET";
// get AddressValidationType-Object if it is only the key
// get WsValidationType-Object if it is only the key
if (typeof pType == "string")
pType = AddressValidationType.get(pType);
pType = WsValidationType.get(pType);
// get configurations for this type
var userName = project.getPreferenceValue("custom." + pType.webserviceName + ".user");
var pw = project.getPreferenceValue("custom." + pType.webserviceName + ".pw");
var url = project.getPreferenceValue("custom." + pType.webserviceName + ".url");
var countryParamName = project.getPreferenceValue("custom." + pType.webserviceName + ".countryParamName");
var actionType = "GET";
if (pValue && pType)
{
......@@ -78,7 +120,7 @@ AddressValidationUtils.validate = function(pValue, pType, pCountry)
var parameters = {};
if (pCountry)
{
parameters.country = pCountry;
parameters[countryParamName] = pCountry;
}
parameters[pType.paramName] = pValue;
......@@ -87,27 +129,8 @@ AddressValidationUtils.validate = function(pValue, pType, pCountry)
if (ret.hasHttpSuccessStatusCode)
{
// 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]
]
});
// different handling of the result per type
return pType.processResultCallback(ret.body, pValue);
}
else
{
......@@ -122,14 +145,14 @@ AddressValidationUtils.validate = function(pValue, pType, pCountry)
/**
* set all address-fields by the value of $this.value, which should contain an object of all values as JSON
*/
AddressValidationUtils.setFields = function()
WsValidationUtils.setAddressFields = 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.DISTRICT", data.district); not needed currently
_setField("$field.REGION", data.region);
_setField("$field.STATE", data.state);
......
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