diff --git a/aliasDefinition/Data_alias/indexsearchgroups/organisation/affectedIds.js b/aliasDefinition/Data_alias/indexsearchgroups/organisation/affectedIds.js index a9593f23e2ddc424480e55bfc8cc81ae03c7f766..3d5f6ab938f0bce2a12aa26736fbf4f24657e158 100644 --- a/aliasDefinition/Data_alias/indexsearchgroups/organisation/affectedIds.js +++ b/aliasDefinition/Data_alias/indexsearchgroups/organisation/affectedIds.js @@ -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")] ]]); }); diff --git a/aliasDefinition/Data_alias/indexsearchgroups/person/affectedIds.js b/aliasDefinition/Data_alias/indexsearchgroups/person/affectedIds.js index d8a51cd604e383035c7b1045fa73c24d1394267c..dcec7271b09b93af609f612ff8c3f69468ec2dc0 100644 --- a/aliasDefinition/Data_alias/indexsearchgroups/person/affectedIds.js +++ b/aliasDefinition/Data_alias/indexsearchgroups/person/affectedIds.js @@ -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")] ]]); }); diff --git a/entity/AddressValidation_entity/AddressValidation_entity.aod b/entity/AddressValidation_entity/AddressValidation_entity.aod index 824e75c1dedc077e9fda247e754b06b3b48c7900..49f5ae6751b33e4082bef472e0697bf28b5829d9 100644 --- a/entity/AddressValidation_entity/AddressValidation_entity.aod +++ b/entity/AddressValidation_entity/AddressValidation_entity.aod @@ -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> diff --git a/entity/AddressValidation_entity/entityfields/cityvalidation/children/type_param/valueProcess.js b/entity/AddressValidation_entity/entityfields/cityvalidation/children/type_param/valueProcess.js index 605d65eb517e3f51c7d9a129c17c0d6e46b79452..1f9eec452781c6cf79d5ed9620ea1f6205fe91b3 100644 --- a/entity/AddressValidation_entity/entityfields/cityvalidation/children/type_param/valueProcess.js +++ b/entity/AddressValidation_entity/entityfields/cityvalidation/children/type_param/valueProcess.js @@ -1,4 +1,4 @@ -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 diff --git a/entity/AddressValidation_entity/entityfields/cityvalidatior/children/type_param/valueProcess.js b/entity/AddressValidation_entity/entityfields/cityvalidatior/children/type_param/valueProcess.js index 605d65eb517e3f51c7d9a129c17c0d6e46b79452..c930ba5500de6db2fd4c5be17e9a82eeaf0bbab8 100644 --- a/entity/AddressValidation_entity/entityfields/cityvalidatior/children/type_param/valueProcess.js +++ b/entity/AddressValidation_entity/entityfields/cityvalidatior/children/type_param/valueProcess.js @@ -1,4 +1,4 @@ -import("AddressValidation_lib"); +import("WsValidation_lib"); import("system.result"); result.string(AddressValidationType.get().TYPE_CITY.key); \ No newline at end of file diff --git a/entity/AddressValidation_entity/entityfields/zipvalidaton/children/type_param/valueProcess.js b/entity/AddressValidation_entity/entityfields/zipvalidaton/children/type_param/valueProcess.js index e980e6dd0b82b651a1025901c43d74fc6be1632d..c7eee1bb589766b9b53cf172226fed90a5da8087 100644 --- a/entity/AddressValidation_entity/entityfields/zipvalidaton/children/type_param/valueProcess.js +++ b/entity/AddressValidation_entity/entityfields/zipvalidaton/children/type_param/valueProcess.js @@ -1,4 +1,4 @@ -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 diff --git a/entity/AddressValidation_entity/entityfields/zipvalidator/children/type_param/valueProcess.js b/entity/AddressValidation_entity/entityfields/zipvalidator/children/type_param/valueProcess.js index e980e6dd0b82b651a1025901c43d74fc6be1632d..7b6b2602657cd575adc7421c172011c6199de1d0 100644 --- a/entity/AddressValidation_entity/entityfields/zipvalidator/children/type_param/valueProcess.js +++ b/entity/AddressValidation_entity/entityfields/zipvalidator/children/type_param/valueProcess.js @@ -1,4 +1,4 @@ -import("AddressValidation_lib"); +import("WsValidation_lib"); import("system.result"); result.string(AddressValidationType.get().TYPE_ZIP.key); \ No newline at end of file diff --git a/entity/AddressValidation_entity/recordcontainers/jdito/contentProcess.js b/entity/AddressValidation_entity/recordcontainers/jdito/contentProcess.js index 513b5ed01505858c06ef875861b18a726acc5560..5b14acb7d11aaa3a32733882bf40ee7e0f4ecb00 100644 --- a/entity/AddressValidation_entity/recordcontainers/jdito/contentProcess.js +++ b/entity/AddressValidation_entity/recordcontainers/jdito/contentProcess.js @@ -1,5 +1,5 @@ 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 diff --git a/entity/Address_entity/entityfields/city/onValueChange.js b/entity/Address_entity/entityfields/city/onValueChange.js index 29bde9d486834bcd1fcd747d5ded932d2fe60196..5634474c9dabbfeec7a11ee3c23680b765030b4a 100644 --- a/entity/Address_entity/entityfields/city/onValueChange.js +++ b/entity/Address_entity/entityfields/city/onValueChange.js @@ -1,3 +1,3 @@ -import("AddressValidation_lib"); +import("WsValidation_lib"); -AddressValidationUtils.setFields(); \ No newline at end of file +WsValidationUtils.setAddressFields(); \ No newline at end of file diff --git a/entity/Address_entity/entityfields/zip/onValueChange.js b/entity/Address_entity/entityfields/zip/onValueChange.js index 29bde9d486834bcd1fcd747d5ded932d2fe60196..5634474c9dabbfeec7a11ee3c23680b765030b4a 100644 --- a/entity/Address_entity/entityfields/zip/onValueChange.js +++ b/entity/Address_entity/entityfields/zip/onValueChange.js @@ -1,3 +1,3 @@ -import("AddressValidation_lib"); +import("WsValidation_lib"); -AddressValidationUtils.setFields(); \ No newline at end of file +WsValidationUtils.setAddressFields(); \ No newline at end of file diff --git a/entity/Communication_entity/Communication_entity.aod b/entity/Communication_entity/Communication_entity.aod index dc93aa2b68f3689d6028ecb7131f699660e22b52..63d8b0811f33eec29498211e6c01bae647cac227 100644 --- a/entity/Communication_entity/Communication_entity.aod +++ b/entity/Communication_entity/Communication_entity.aod @@ -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> diff --git a/entity/Communication_entity/entityfields/addr/onValidation.js b/entity/Communication_entity/entityfields/addr/onValidation.js index 54a9148c82d2064819c16312df0acd1d96e60870..be9753504a1853a1cb01f220b618cddf9615f5ad 100644 --- a/entity/Communication_entity/entityfields/addr/onValidation.js +++ b/entity/Communication_entity/entityfields/addr/onValidation.js @@ -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 diff --git a/entity/Communication_entity/entityfields/addr/onValueChange.js b/entity/Communication_entity/entityfields/addr/onValueChange.js index 61a183ab8b75c224c87b82baa26ea004215e1f95..95fae13ee0276228a3a474b6fbd4ce0510da00af 100644 --- a/entity/Communication_entity/entityfields/addr/onValueChange.js +++ b/entity/Communication_entity/entityfields/addr/onValueChange.js @@ -1,12 +1,8 @@ -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: diff --git a/neonView/AddressList_view/AddressList_view.aod b/neonView/AddressList_view/AddressList_view.aod index 3ef2a83f526949e497254b822cdde3928d6023ae..74236c8433e8fa39c3666e2c1c8f074d1a2495f2 100644 --- a/neonView/AddressList_view/AddressList_view.aod +++ b/neonView/AddressList_view/AddressList_view.aod @@ -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> diff --git a/neonView/AddressValidationLookup_view/AddressValidationLookup_view.aod b/neonView/AddressValidationLookup_view/AddressValidationLookup_view.aod index a0bf44af7ce2d5e9e872e1025e207d724ec1d3b6..faa59a3cf3f1d1e7cd72f5aa03a5562c6c2f1e06 100644 --- a/neonView/AddressValidationLookup_view/AddressValidationLookup_view.aod +++ b/neonView/AddressValidationLookup_view/AddressValidationLookup_view.aod @@ -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> diff --git a/neonView/AdressMultiEdit_view/AdressMultiEdit_view.aod b/neonView/AdressMultiEdit_view/AdressMultiEdit_view.aod index 952afaabcfe9ba63036c4edaaf4fff95348d22ba..7ff9546ade23e1956af0503193b9300ee0168276 100644 --- a/neonView/AdressMultiEdit_view/AdressMultiEdit_view.aod +++ b/neonView/AdressMultiEdit_view/AdressMultiEdit_view.aod @@ -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> diff --git a/preferences/_____PREFERENCES_PROJECT/_____PREFERENCES_PROJECT.aod b/preferences/_____PREFERENCES_PROJECT/_____PREFERENCES_PROJECT.aod index 50084ef32801588ee4d23d333e3b5f433f7aaa0f..19af7688962fc062892620be9b6e15941d362b13 100644 --- a/preferences/_____PREFERENCES_PROJECT/_____PREFERENCES_PROJECT.aod +++ b/preferences/_____PREFERENCES_PROJECT/_____PREFERENCES_PROJECT.aod @@ -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> diff --git a/process/AddressValidation_lib/process.js b/process/AddressValidation_lib/process.js deleted file mode 100644 index 9f0ab520f0b29b8cf434c8549c4ac9b5519712de..0000000000000000000000000000000000000000 --- a/process/AddressValidation_lib/process.js +++ /dev/null @@ -1,141 +0,0 @@ -import("system.logging"); -import("system.project"); -import("system.vars"); -import("system.neon"); -import("system.net"); -import("system.util"); - -/** - * 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) - 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() {} - -/** - * 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) -{ - 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 - if (typeof pType == "string") - pType = AddressValidationType.get(pType); - - if (pValue && pType) - { - // fill params - var parameters = {}; - if (pCountry) - { - parameters.country = pCountry; - } - parameters[pType.paramName] = pValue; - - // 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) - { - // 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 - { - - // error handling - } - } - - 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")); - - _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 diff --git a/process/AddressValidation_lib/AddressValidation_lib.aod b/process/WsValidation_lib/WsValidation_lib.aod similarity index 76% rename from process/AddressValidation_lib/AddressValidation_lib.aod rename to process/WsValidation_lib/WsValidation_lib.aod index d9b312c9ea010874d7543ac38a170160ad71c158..521ca5a4571a2b608f148315da4cb4a1efd6f892 100644 --- a/process/AddressValidation_lib/AddressValidation_lib.aod +++ b/process/WsValidation_lib/WsValidation_lib.aod @@ -1,8 +1,8 @@ <?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> diff --git a/process/WsValidation_lib/process.js b/process/WsValidation_lib/process.js new file mode 100644 index 0000000000000000000000000000000000000000..4cc2f2effeba10f8275ec5e86f604911df2eb994 --- /dev/null +++ b/process/WsValidation_lib/process.js @@ -0,0 +1,164 @@ +import("system.project"); +import("system.vars"); +import("system.neon"); +import("system.net"); +import("system.util"); + +/** + * 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 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|WsValidationType} object containing all WsValidationTypes or one specific WsValidationType + */ +WsValidationType.get = function(pKey) +{ + if (!this._cache) + this._cache = { + // 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 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 WsValidationUtils() {} + +/** + * validate the value with the webservice + * @param {String} pValue to search for + * @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, + * displayName, + * zip, + * city, + * country, + * district, + * region, + * state, + * value (the result. e.g. if pType was ZIP, the value is the found zip) + */ +WsValidationUtils.validate = function(pValue, pType, pCountry) +{ + // get WsValidationType-Object if it is only the key + if (typeof pType == "string") + 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) + { + // fill params + var parameters = {}; + if (pCountry) + { + parameters[countryParamName] = pCountry; + } + parameters[pType.paramName] = pValue; + + // 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) + { + // different handling of the result per type + return pType.processResultCallback(ret.body, pValue); + } + else + { + + // error handling + } + } + + return []; +} + +/** + * set all address-fields by the value of $this.value, which should contain an object of all values as JSON + */ +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); not needed currently + _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