Validate ListMap against JsonNode in Scala

Lengkap Disiarkan Jan 7, 2016 Dibayar semasa penghantaran
Lengkap Dibayar semasa penghantaran

I have a following Scala JsonNode which has API parameters under "arguments".

{"class":"account_services","include_remote_app_inputs":true,"create_version":"3.5","update_version":"6.35","readonly":false,"db_proc":"wapi_symphony.cancel_queued_service_plan","arguments":{"client_no":{"type":"long","length":22,"nullable":false},"auth_key":{"type":"string","length":32,,"nullable":true},"account_number":{"type":"long","length":8,"nullable":false},"plan_no_to_remove":{"nullable":true,"type":{"queued_plan_no":{"type":"long","nullable":true,"create_version":6.13,"alt_required_field":"queued_client_plan_id"},"queued_client_plan_id":{"type":"string","length":100,"nullable":true,"create_version":"6.22","alt_required_field":"queued_plan_no"}}},"remove_all_queued_plan_no":{"type":"string","nullable":true,"create_version":6.13},"remove_terminate_pending":{"type":"string","length":5,,"nullable":true,"create_version":6.15}},"returns":{"error_code":

{"type":"long","nullable":true},"error_msg":{"type":"string","nullable":true}},"functional_groups":{"group1":{"group_no":7,"group_name":"Account Transaction Modification"}}}

I also have a Scala ListMap of the API call

Map(client_no -> 100, auth_key -> ABCDEFG, account_number -> 1859941, plan_no_to_remove -> List(Map(plan_no_to_remove_row -> Map(queued_plan_no -> 1001,

queued_client_plan_id -> ?)), Map(plan_no_to_remove_row -> Map(queued_plan_no -> 1002, queued_client_plan_id -> ?))), remove_all_queued_plan_no -> ?, remove_terminate_pending -> ?, application_id -> ?, application_date -> ?, alt_caller_id -> ?, optional_transaction_qualifiers -> Map(optional_transaction_qualifiers_row -> Map(qualifier_name -> ?, qualifier_value -> ?)))

There are 2 things need to be done.

1. The API parameters are available in the JsonNode under "arguments". I want to remove any extra parameter from the list map which are not present in Json. For example,

Map(client_no -> 100, client_name -> blah, auth_key -> ABCDEFG, account_number -> 1859941, plan_no_to_remove -> List(Map(plan_no_to_remove_row -> Map(queued_plan_no -> 1001, queued_client_plan_id -> ?)), Map(plan_no_to_remove_row -> Map(queued_plan_no -> 1002, queued_client_plan_id -> ?))), remove_all_queued_plan_no -> ?, remove_terminate_pending -> ?, application_id -> ?, application_date -> ?, alt_caller_id -> ?, optional_transaction_qualifiers -> Map(optional_transaction_qualifiers_row -> Map(qualifier_name -> ?, qualifier_value -> ?)))

See in above ListMap, client_name is present but is not a part of JSON arguments. So I want to remove that parameter from the list map. Just one exception, do not remove application_id, application_date, alt_caller_id and optional_transaction_qualifiers.

2. The API parameters that are available in the above JSON under "arguments", has "type" and "nullable" attributes. I want to validate list map against those attributes. For example, client_no has "nullable" set to false. So if the client_no in list map is empty, I want to throw an exception. Similarly,

Map(client_no -> ABC, auth_key -> ABCDEFG, account_number -> 1859941)

client_no has "type" long, and the value of client_no in list map is String (ABC), so in this type mismatch, I want to throw an exception.

I have started something like this.

import [url removed, login to view]

import scala.collection.convert.decorateAsScala._

import [url removed, login to view]

object Validate {

def apply (inMap: ListMap[String,Any], apiParams: JsonNode): (ListMap[String,Any]) = {

var filteredListMap : ListMap[String, Any] = ListMap()

for (map <- inMap) {

}

}

}

Please feel free to continue building like this or use your own style. But please make sure you make use of above imports that I'm using.

Skala

ID Projek: #9254276

Tentang projek

2 cadangan Projek jarak jauh Aktif Jan 17, 2016

Dianugerahkan kepada:

johnykoshy

Hi this is Johny. I am willing to do this work. Do you want the validation as a separate step or as a part of the previous step?

$111 USD dalam sehari
(0 Ulasan)
0.0