Skip to content

Commit

Permalink
KAZOO-5132: call filter_undefined from from_list/1 and from_list_recu…
Browse files Browse the repository at this point in the history
…rsive/1 (2600hz#3782)

* KAZOO-5132: always filter_undefined in kz_json:from_list functions

* KAZOO-5132: introduce kz_csv:json_to_iolist/2

* introduce BASE_HEADERS to provisioner_util

* KAZOO-5132: replace calls to from_list then filter_undefined with just from_list

* KAZOO-5132: make apis for some reason

* KAZOO-5132: fix Dialyzer warnings

* KAZOO-5132: fix rebase artefacts
  • Loading branch information
fenollp authored and k-anderson committed Jun 2, 2017
1 parent e99cf91 commit 8f1c685
Show file tree
Hide file tree
Showing 72 changed files with 1,186 additions and 1,127 deletions.
21 changes: 10 additions & 11 deletions applications/acdc/src/acdc_agent_fsm.erl
Original file line number Diff line number Diff line change
Expand Up @@ -1857,17 +1857,16 @@ notify(Url, Method, Key, #state{account_id=AccountId
}) ->
kz_util:put_callid(kapps_call:call_id(MemberCall)),
Data = kz_json:from_list(
props:filter_undefined(
[{<<"account_id">>, AccountId}
,{<<"agent_id">>, AgentId}
,{<<"agent_call_id">>, AgentCallId}
,{<<"queue_id">>, QueueId}
,{<<"member_call_id">>, kapps_call:call_id(MemberCall)}
,{<<"caller_id_name">>, kapps_call:caller_id_name(MemberCall)}
,{<<"caller_id_number">>, kapps_call:caller_id_number(MemberCall)}
,{<<"call_state">>, Key}
,{<<"now">>, kz_time:current_tstamp()}
])),
[{<<"account_id">>, AccountId}
,{<<"agent_id">>, AgentId}
,{<<"agent_call_id">>, AgentCallId}
,{<<"queue_id">>, QueueId}
,{<<"member_call_id">>, kapps_call:call_id(MemberCall)}
,{<<"caller_id_name">>, kapps_call:caller_id_name(MemberCall)}
,{<<"caller_id_number">>, kapps_call:caller_id_number(MemberCall)}
,{<<"call_state">>, Key}
,{<<"now">>, kz_time:current_tstamp()}
]),
notify(Url, Method, Data).

-spec notify(ne_binary(), 'get' | 'post', kz_json:object()) -> 'ok'.
Expand Down
3 changes: 1 addition & 2 deletions applications/acdc/src/acdc_agent_stats.erl
Original file line number Diff line number Diff line change
Expand Up @@ -393,8 +393,7 @@ status_stat_to_doc(#status_stat{id=Id
,{<<"caller_id_name">>, CIDName}
,{<<"caller_id_number">>, CIDNum}
],
kz_doc:update_pvt_parameters(
kz_json:from_list(props:filter_undefined(Prop))
kz_doc:update_pvt_parameters(kz_json:from_list(Prop)
,acdc_stats_util:db_name(AccountId)
,[{'account_id', AccountId}
,{'type', <<"status_stat">>}
Expand Down
92 changes: 44 additions & 48 deletions applications/acdc/src/acdc_stats.erl
Original file line number Diff line number Diff line change
Expand Up @@ -692,31 +692,30 @@ call_stat_to_doc(#call_stat{id=Id
,caller_id_number=CallerIdNumber
,caller_priority=CallerPriority
}) ->
kz_doc:update_pvt_parameters(
kz_json:from_list(
props:filter_undefined(
[{<<"_id">>, Id}
,{<<"call_id">>, CallId}
,{<<"queue_id">>, QueueId}
,{<<"agent_id">>, AgentId}
,{<<"entered_timestamp">>, EnteredT}
,{<<"abandoned_timestamp">>, AbandonedT}
,{<<"handled_timestamp">>, HandledT}
,{<<"processed_timestamp">>, ProcessedT}
,{<<"hung_up_by">>, HungUpBy}
,{<<"abandoned_reason">>, AbandonedR}
,{<<"misses">>, misses_to_docs(Misses)}
,{<<"status">>, Status}
,{<<"caller_id_name">>, CallerIdName}
,{<<"caller_id_number">>, CallerIdNumber}
,{<<"caller_priority">>, CallerPriority}
,{<<"wait_time">>, wait_time(EnteredT, AbandonedT, HandledT)}
,{<<"talk_time">>, talk_time(HandledT, ProcessedT)}
]))
kz_doc:update_pvt_parameters(kz_json:from_list(
[{<<"_id">>, Id}
,{<<"call_id">>, CallId}
,{<<"queue_id">>, QueueId}
,{<<"agent_id">>, AgentId}
,{<<"entered_timestamp">>, EnteredT}
,{<<"abandoned_timestamp">>, AbandonedT}
,{<<"handled_timestamp">>, HandledT}
,{<<"processed_timestamp">>, ProcessedT}
,{<<"hung_up_by">>, HungUpBy}
,{<<"abandoned_reason">>, AbandonedR}
,{<<"misses">>, misses_to_docs(Misses)}
,{<<"status">>, Status}
,{<<"caller_id_name">>, CallerIdName}
,{<<"caller_id_number">>, CallerIdNumber}
,{<<"caller_priority">>, CallerPriority}
,{<<"wait_time">>, wait_time(EnteredT, AbandonedT, HandledT)}
,{<<"talk_time">>, talk_time(HandledT, ProcessedT)}
])
,acdc_stats_util:db_name(AccountId)
,[{'account_id', AccountId}
,{'type', <<"call_stat">>}
]).
]
).

-spec call_stat_to_json(call_stat()) -> kz_json:object().
call_stat_to_json(#call_stat{id=Id
Expand All @@ -736,25 +735,24 @@ call_stat_to_json(#call_stat{id=Id
,caller_id_number=CallerIdNumber
}) ->
kz_json:from_list(
props:filter_undefined(
[{<<"Id">>, Id}
,{<<"Call-ID">>, CallId}
,{<<"Queue-ID">>, QueueId}
,{<<"Agent-ID">>, AgentId}
,{<<"Account-ID">>, AccountId}
,{<<"Entered-Timestamp">>, EnteredT}
,{<<"Abandoned-Timestamp">>, AbandonedT}
,{<<"Handled-Timestamp">>, HandledT}
,{<<"Processed-Timestamp">>, ProcessedT}
,{<<"Hung-Up-By">>, HungUpBy}
,{<<"Abandoned-Reason">>, AbandonedR}
,{<<"Misses">>, misses_to_docs(Misses)}
,{<<"Status">>, Status}
,{<<"Caller-ID-Name">>, CallerIdName}
,{<<"Caller-ID-Number">>, CallerIdNumber}
,{<<"Wait-Time">>, wait_time(EnteredT, AbandonedT, HandledT)}
,{<<"Talk-Time">>, talk_time(HandledT, ProcessedT)}
])).
[{<<"Id">>, Id}
,{<<"Call-ID">>, CallId}
,{<<"Queue-ID">>, QueueId}
,{<<"Agent-ID">>, AgentId}
,{<<"Account-ID">>, AccountId}
,{<<"Entered-Timestamp">>, EnteredT}
,{<<"Abandoned-Timestamp">>, AbandonedT}
,{<<"Handled-Timestamp">>, HandledT}
,{<<"Processed-Timestamp">>, ProcessedT}
,{<<"Hung-Up-By">>, HungUpBy}
,{<<"Abandoned-Reason">>, AbandonedR}
,{<<"Misses">>, misses_to_docs(Misses)}
,{<<"Status">>, Status}
,{<<"Caller-ID-Name">>, CallerIdName}
,{<<"Caller-ID-Number">>, CallerIdNumber}
,{<<"Wait-Time">>, wait_time(EnteredT, AbandonedT, HandledT)}
,{<<"Talk-Time">>, talk_time(HandledT, ProcessedT)}
]).

wait_time(E, _, H) when is_integer(E), is_integer(H) -> H - E;
wait_time(E, A, _) when is_integer(E), is_integer(A) -> A - E;
Expand Down Expand Up @@ -830,11 +828,10 @@ handle_missed_stat(JObj, Props) ->

-spec create_miss(kz_json:object()) -> agent_miss().
create_miss(JObj) ->
#agent_miss{
agent_id = kz_json:get_value(<<"Agent-ID">>, JObj)
#agent_miss{agent_id = kz_json:get_value(<<"Agent-ID">>, JObj)
,miss_reason = kz_json:get_value(<<"Miss-Reason">>, JObj)
,miss_timestamp = kz_json:get_value(<<"Miss-Timestamp">>, JObj)
}.
}.

-spec handle_abandoned_stat(kz_json:object(), kz_proplist()) -> 'ok'.
handle_abandoned_stat(JObj, Props) ->
Expand Down Expand Up @@ -909,8 +906,7 @@ create_call_stat(Id, JObj, Props) ->
}
}).

-spec update_call_stat(ne_binary(), kz_proplist(), kz_proplist()) -> 'ok'.
-type updates() :: [{pos_integer(), any()}].
-spec update_call_stat(ne_binary(), updates(), kz_proplist()) -> 'ok'.
update_call_stat(Id, Updates, Props) ->
gen_listener:cast(props:get_value('server', Props)
,{'update_call', Id, Updates}
).
gen_listener:cast(props:get_value('server', Props), {'update_call', Id, Updates}).
23 changes: 11 additions & 12 deletions applications/blackhole/src/bh_context.erl
Original file line number Diff line number Diff line change
Expand Up @@ -96,18 +96,17 @@ from_json(Context, JObj) ->
-spec to_json(context()) -> kz_json:object().
to_json(Context) ->
kz_json:from_list(
props:filter_undefined(
[{<<"auth_token">>, auth_token(Context)}
,{<<"auth_account_id">>, auth_account_id(Context)}
,{<<"bindings">>, bindings(Context)}
,{<<"websocket_session_id">>, websocket_session_id(Context)}
,{<<"timestamp">>, timestamp(Context)}
,{<<"name">>, name(Context)}
,{<<"metadata">>, metadata(Context)}
,{<<"destination">>, destination(Context)}
,{<<"source">>, source(Context)}
,{<<"req_id">>, req_id(Context)}
])).
[{<<"auth_token">>, auth_token(Context)}
,{<<"auth_account_id">>, auth_account_id(Context)}
,{<<"bindings">>, bindings(Context)}
,{<<"websocket_session_id">>, websocket_session_id(Context)}
,{<<"timestamp">>, timestamp(Context)}
,{<<"name">>, name(Context)}
,{<<"metadata">>, metadata(Context)}
,{<<"destination">>, destination(Context)}
,{<<"source">>, source(Context)}
,{<<"req_id">>, req_id(Context)}
]).

%%--------------------------------------------------------------------
%% @public
Expand Down
12 changes: 5 additions & 7 deletions applications/call_inspector/src/analyzers/ci_analysis.erl
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,11 @@ reason(#ci_analysis{reason=Reason}) ->
-spec to_json(analysis()) -> kz_json:object().
to_json(#ci_analysis{}=Analysis) ->
kz_json:from_list(
props:filter_undefined(
[{<<"originate_type">>, originate_type(Analysis)}
,{<<"terminate_type">>, terminate_type(Analysis)}
,{<<"failure_location">>, failure_location(Analysis)}
,{<<"reason">>, reason(Analysis)}
])
).
[{<<"originate_type">>, originate_type(Analysis)}
,{<<"terminate_type">>, terminate_type(Analysis)}
,{<<"failure_location">>, failure_location(Analysis)}
,{<<"reason">>, reason(Analysis)}
]).

-spec is_analysis(any()) -> boolean().
is_analysis(#ci_analysis{}) -> 'true';
Expand Down
38 changes: 19 additions & 19 deletions applications/callflow/src/cf_singular_call_hooks.erl
Original file line number Diff line number Diff line change
Expand Up @@ -81,14 +81,14 @@ send_init_hook(Call) ->
lager:debug("Inception: ~s", [get_inception(Call)]),
lager:debug("================", []),

Prop = [{<<"Event">>, <<"init">>}
,{<<"Call-ID">>, kapps_call:call_id(Call)}
,{<<"To">>, knm_converters:normalize(kapps_call:to_user(Call))}
,{<<"From">>, knm_converters:normalize(kapps_call:caller_id_number(Call))}
,{<<"Inception">>, get_inception(Call)}
],

JObj = kz_json:from_list(props:filter_undefined(Prop)),
JObj = kz_json:from_list(
[{<<"Event">>, <<"init">>}
,{<<"Call-ID">>, kapps_call:call_id(Call)}
,{<<"To">>, knm_converters:normalize(kapps_call:to_user(Call))}
,{<<"From">>, knm_converters:normalize(kapps_call:caller_id_number(Call))}
,{<<"Inception">>, get_inception(Call)}
]),

URI = binary_to_list(get_hook_url()),

case kz_http:post(URI
Expand Down Expand Up @@ -134,17 +134,17 @@ send_end_hook(Call, Event) ->
_ -> kapps_call:custom_channel_var(<<"Bridge-ID">>, Call)
end,

Prop = [{<<"Event">>, <<"destroy">>}
,{<<"Call-ID">>, CallID}
,{<<"To">>, knm_converters:normalize(kapps_call:to_user(Call))}
,{<<"From">>, knm_converters:normalize(kapps_call:caller_id_number(Call))}
,{<<"Inception">>, get_inception(Call)}
,{<<"Duration-Seconds">>, kz_json:get_value(<<"Duration-Seconds">>, Event)}
,{<<"Hangup-Cause">>, kz_json:get_value(<<"Hangup-Cause">>, Event)}
,{<<"Disposition">>, kz_json:get_value(<<"Disposition">>, Event)}
],

JObj = kz_json:from_list(props:filter_undefined(Prop)),
JObj = kz_json:from_list(
[{<<"Event">>, <<"destroy">>}
,{<<"Call-ID">>, CallID}
,{<<"To">>, knm_converters:normalize(kapps_call:to_user(Call))}
,{<<"From">>, knm_converters:normalize(kapps_call:caller_id_number(Call))}
,{<<"Inception">>, get_inception(Call)}
,{<<"Duration-Seconds">>, kz_json:get_value(<<"Duration-Seconds">>, Event)}
,{<<"Hangup-Cause">>, kz_json:get_value(<<"Hangup-Cause">>, Event)}
,{<<"Disposition">>, kz_json:get_value(<<"Disposition">>, Event)}
]),

URI = binary_to_list(get_hook_url()),

case kz_http:post(URI
Expand Down
35 changes: 17 additions & 18 deletions applications/callflow/src/module/cf_park.erl
Original file line number Diff line number Diff line change
Expand Up @@ -263,24 +263,23 @@ create_slot(ParkerCallId, PresenceType, Call) ->
User = kapps_call:request_user(Call),
Realm = kapps_call:account_realm(Call),
kz_json:from_list(
props:filter_undefined(
[{<<"Call-ID">>, CallId}
,{<<"Slot-Call-ID">>, SlotCallId}
,{<<"Switch-URI">>, kapps_call:switch_uri(Call)}
,{<<"From-Tag">>, kapps_call:from_tag(Call)}
,{<<"To-Tag">>, kapps_call:to_tag(Call)}
,{<<"Parker-Call-ID">>, ParkerCallId}
,{<<"Ringback-ID">>, RingbackId}
,{<<"Presence-User">>, User}
,{<<"Presence-Realm">>, Realm}
,{<<"Presence-ID">>, <<User/binary, "@", Realm/binary>>}
,{<<"Node">>, kapps_call:switch_nodename(Call)}
,{<<"CID-Number">>, kapps_call:caller_id_number(Call)}
,{<<"CID-Name">>, kapps_call:caller_id_name(Call)}
,{<<"CID-URI">>, kapps_call:from(Call)}
,{<<"Hold-Media">>, kz_attributes:moh_attributes(RingbackId, <<"media_id">>, Call)}
,{?PRESENCE_TYPE_KEY, PresenceType}
])).
[{<<"Call-ID">>, CallId}
,{<<"Slot-Call-ID">>, SlotCallId}
,{<<"Switch-URI">>, kapps_call:switch_uri(Call)}
,{<<"From-Tag">>, kapps_call:from_tag(Call)}
,{<<"To-Tag">>, kapps_call:to_tag(Call)}
,{<<"Parker-Call-ID">>, ParkerCallId}
,{<<"Ringback-ID">>, RingbackId}
,{<<"Presence-User">>, User}
,{<<"Presence-Realm">>, Realm}
,{<<"Presence-ID">>, <<User/binary, "@", Realm/binary>>}
,{<<"Node">>, kapps_call:switch_nodename(Call)}
,{<<"CID-Number">>, kapps_call:caller_id_number(Call)}
,{<<"CID-Name">>, kapps_call:caller_id_name(Call)}
,{<<"CID-URI">>, kapps_call:from(Call)}
,{<<"Hold-Media">>, kz_attributes:moh_attributes(RingbackId, <<"media_id">>, Call)}
,{?PRESENCE_TYPE_KEY, PresenceType}
]).

%%--------------------------------------------------------------------
%% @private
Expand Down
4 changes: 2 additions & 2 deletions applications/callflow/src/module/cf_webhook.erl
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,14 @@ format_call_data(Call) ->
kz_json:recursive_to_proplist(kz_json:normalize_jobj(JObj, RemoveKeys, [])).

-spec set_hook(kz_json:object(), kz_proplist()) -> kz_proplist().
set_hook(Data, CallJObj) ->
set_hook(Data, CallProps) ->
Now = calendar:datetime_to_gregorian_seconds(calendar:local_time()),
props:filter_undefined(
[{<<"_id">>, kz_term:to_binary(Now)}
,{<<"uri">>, kz_json:get_ne_binary_value(<<"uri">>, Data)}
,{<<"hook">>, <<"callflow">>}
,{<<"http_verb">>, kz_json:get_ne_binary_value(<<"http_verb">>, Data)}
,{<<"retries">>, kz_json:get_integer_value(<<"retries">>, Data)}
,{<<"pvt_account_id">>, props:get_ne_binary_value(<<"account_id">>, CallJObj)}
,{<<"pvt_account_id">>, props:get_ne_binary_value(<<"account_id">>, CallProps)}
,{<<"custom_data">>, kz_json:get_json_value(<<"custom_data">>, Data)}
]).
Loading

0 comments on commit 8f1c685

Please sign in to comment.