Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- diff --git a/configuration/shared/rpc.tmpl b/configuration/shared/rpc.tmpl
- index b7c625a..62e232a 100644
- --- a/configuration/shared/rpc.tmpl
- +++ b/configuration/shared/rpc.tmpl
- @@ -182,6 +182,13 @@
- method => 'getPersonDetailsRPC',
- encoder => 'Cpanel::JSON::XS',
- },
- + 'service.agent.token.get_device_data' => {
- + state => 'content',
- + type => 'method',
- + subpack => 'Service::Agent::Session_v1_0',
- + method => 'getBrandAndStoreFromDeviceID',
- + encoder => 'Cpanel::JSON::XS',
- + },
- diff --git a/server/generic/Generic/Service/Agent/Applications.pm b/server/generic/Generic/Service/Agent/Applications.pm
- index a08aaa7..eb2a99c 100644
- --- a/server/generic/Generic/Service/Agent/Applications.pm
- +++ b/server/generic/Generic/Service/Agent/Applications.pm
- @@ -24,7 +24,7 @@ sub serviceGet {
- }
- # Parse store id from passed in device id, we will use this to filter the applications returned
- - my $store_info = $self->getBrandAndStoreFromDeviceID($args->{device_id});
- + my $store_info = $self->getBrandAndStoreFromDeviceID({ 'device_id' => $args->{device_id}});
- my $allowed_apps_for_store = $self->_getApplicationsForStoreId({store_id => $store_info->{store_id}});
- diff --git a/server/generic/Generic/Service/Agent/Session_v1_0.pm b/server/generic/Generic/Service/Agent/Session_v1_0.pm
- index c6edde3..d608098 100644
- --- a/server/generic/Generic/Service/Agent/Session_v1_0.pm
- +++ b/server/generic/Generic/Service/Agent/Session_v1_0.pm
- @@ -17,7 +17,9 @@ sub jsonSchemaOutPost
- }
- sub getDeviceDataFromDB {
- - my ( $self, $device_id ) = @_;
- + my ( $self, $args ) = @_;
- + my $device_id = $args->{device_id};
- + my $show_debug = $args->{show_debug};
- my $db = $self->get('DB');
- my $prefix = $db->prefix;
- @@ -36,14 +38,59 @@ sub getDeviceDataFromDB {
- my $agent_config = $self->get('Configuration')->appConfig('agent_api');
- my $gis_brand_mapping = $$agent_config{'%gis_brand_mapping'};
- - return {
- + my $store_info = {
- brand_id => $gis_brand_mapping->{$row[0]},
- store_id => $store_id,
- };
- + if ($show_debug) {
- + $store_info->{data_source} = 'DB Cache';
- + $store_info->{brand_id_raw} = $row[0];
- + }
- + return $store_info;
- +}
- +
- +sub getDeviceDataFromGis {
- + my ( $self, $args ) = @_;
- + my $device_id = $args->{device_id};
- + my $show_debug = $args->{show_debug};
- + my $store_info = {};
- + my $env_config = Generic::Environment::extract(['gis_device_service']);
- + my $agent_config = $self->get('Configuration')->appConfig('agent_api');
- + my $query_url = $env_config->{server_url} . '?serialnumber=' . $device_id;
- + my $req = HTTP::Request->new( 'POST', $query_url);
- + $req->header('Accept' => 'application/json');
- + my $lwp = LWP::UserAgent->new;
- +
- + $req->authorization_basic($env_config->{username}, $env_config->{password});
- + my $res = $lwp->request($req);
- + if ($res->is_success) {
- + my $response = $res->decoded_content((charset => 'utf8'));
- + my $json = $self->get('Util::JSON');
- + $json->fromJson($response);
- + $response = $json->asJson;
- + $store_info->{store_id} = $response->{'mdmRequestOutput'}{'Door'};
- + # GIS returns brands in an invalid format, we need to translate them per OAB-1843
- + my $gis_brand_mapping = $$agent_config{'%gis_brand_mapping'};
- + if ($show_debug) {
- + $store_info->{data_source} = 'GIS Api';
- + $store_info->{brand_id_raw} = $response->{'mdmRequestOutput'}{'Brand'};
- + }
- + $store_info->{brand_id} = $gis_brand_mapping->{$response->{'mdmRequestOutput'}{'Brand'}};
- + } else {
- + my $error_info = "getDeviceDataFromGis error: \nquery_url: " .$query_url."\nbase url: ". $res->base ."\n". $res->code ."\n". $res->message ."
- \n". $res->as_string();
- + $self->rlog->warn($error_info);
- + if ($show_debug) {
- + $store_info->{gis_error} = $error_info;
- + }
- + }
- +
- + return $store_info;
- }
- sub getBrandAndStoreFromDeviceID {
- - my ( $self, $device_id ) = @_;
- + my ( $self, $args ) = @_;
- + my $device_id = $args->{device_id};
- + my $show_debug = $args->{show_debug};
- my $store_info = {};
- # Need to support the old method of getting brand and store directly from the device id
- if (length($device_id) > 20) {
- @@ -52,33 +99,11 @@ sub getBrandAndStoreFromDeviceID {
- $store_info->{brand_id} =~ s/^\s+|\s+$//g;
- } else {
- # First, try to get the data from the DB (cached data from GIS)
- - $store_info = $self->getDeviceDataFromDB($device_id);
- + $store_info = $self->getDeviceDataFromDB({ 'device_id' => $device_id, 'show_debug' => $show_debug});
- unless ($store_info) {
- - my $env_config = Generic::Environment::extract(['gis_device_service']);
- - my $agent_config = $self->get('Configuration')->appConfig('agent_api');
- - my $query_url = $env_config->{server_url} . '?serialnumber=' . $device_id;
- - my $req = HTTP::Request->new( 'POST', $query_url);
- - $req->header('Accept' => 'application/json');
- - my $lwp = LWP::UserAgent->new;
- -
- - $req->authorization_basic($env_config->{username}, $env_config->{password});
- - my $res = $lwp->request($req);
- - if ($res->is_success) {
- - my $response = $res->decoded_content((charset => 'utf8'));
- - my $json = $self->get('Util::JSON');
- - $json->fromJson($response);
- - $response = $json->asJson;
- - $store_info->{store_id} = $response->{'mdmRequestOutput'}{'Door'};
- - # GIS returns brands in an invalid format, we need to translate them per OAB-1843
- - my $gis_brand_mapping = $$agent_config{'%gis_brand_mapping'};
- - $store_info->{brand_id} = $gis_brand_mapping->{$response->{'mdmRequestOutput'}{'Brand'}};
- - } else {
- - my $error_info = "_getBrandAndStoreFromDeviceID error: \nquery_url: " .$query_url."\nbase url: ". $res->base ."\n". $res->code ."\n".
- $res->message ."\n". $res->as_string();
- - $self->rlog->warn($error_info);
- - }
- + $store_info = $self->getDeviceDataFromGis({ 'device_id' => $device_id, 'show_debug' => $show_debug});
- }
- }
- -
- return $store_info;
- }
- diff --git a/server/generic/Generic/Service/Agent/Token.pm b/server/generic/Generic/Service/Agent/Token.pm
- index 2445584..308141d 100644
- --- a/server/generic/Generic/Service/Agent/Token.pm
- +++ b/server/generic/Generic/Service/Agent/Token.pm
- @@ -20,7 +20,7 @@ sub servicePost {
- my $device_id = $args->{'device_id'};
- - my $store_info = $self->getBrandAndStoreFromDeviceID($device_id);
- + my $store_info = $self->getBrandAndStoreFromDeviceID({'device_id' => $device_id});
- # Set up JSON stuff to validate
- my $validation_schema = $self->get( 'JSON::Schema::ValidationObject', {
- diff --git a/server/generic/Generic/Service/CSAPP/Authorize_v1_1.pm b/server/generic/Generic/Service/CSAPP/Authorize_v1_1.pm
- index ad16c38..6b3ba98 100644
- --- a/server/generic/Generic/Service/CSAPP/Authorize_v1_1.pm
- +++ b/server/generic/Generic/Service/CSAPP/Authorize_v1_1.pm
- @@ -118,7 +118,7 @@ sub _servicePostPassword {
- # get info on device_id
- my $device_id = $args->{device_id};
- - my $store_info = $ts->getBrandAndStoreFromDeviceID($device_id);
- + my $store_info = $ts->getBrandAndStoreFromDeviceID({'device_id' => $device_id});
- my $device_id_messaging = '';
- unless ($device_id) {
- diff --git a/sites/shared/admin/protected/omnichannel/hubaccess.tmpl b/sites/shared/admin/protected/omnichannel/hubaccess.tmpl
- index 8347b33..bdf0daf 100644
- --- a/sites/shared/admin/protected/omnichannel/hubaccess.tmpl
- +++ b/sites/shared/admin/protected/omnichannel/hubaccess.tmpl
- @@ -62,6 +62,26 @@
- <div id="store_result" style="height:70px;">
- </div>
- </div>
- +
- +
- + <div id="device_info_container" style="width: 750px; border: 1px solid black; margin-top: 25px; margin-left:auto; margin-right: auto;">
- + <center>
- + <h2>Device Information</h2>
- + <h3>Enter a device id and see the data returned for it</h3>
- + </center>
- + <div id="device_form">
- + <form action="#">
- + <center>
- + Device ID: <input type="text" class="device_id">
- +
- + <input id="device_submit" type="submit" value="Submit">
- + </center>
- + </form>
- + </div>
- + <div id="device_result" style="height:auto; margin-bottom: 15px;">
- + </div>
- + </div>
- +
- </body>
- <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
- <script>
- @@ -137,6 +157,38 @@
- });
- });
- +
- +
- + jQuery('#device_submit').click(function(e) {
- + e.preventDefault();
- + var $deviceId = $('#device_info_container input.device_id').val();
- + var html_placeholder = "<center> Fetching data... </center>";
- + $("#device_result").html(html_placeholder);
- + $.ajax({
- + url: '/rpc/jsonrpc.tmpl?dbgmethod=service.agent.token.get_device_data',
- + dataType: 'json',
- + data: {
- + JSONRPC: JSON.stringify([{
- + method: 'service.agent.token.get_device_data',
- + params: [{
- + device_id: $deviceId,
- + show_debug: 1,
- + }]
- + }]),
- + },
- + success: function(data) {
- + var html_out = "<center> \
- + <div><span style='font-weight: bold;'>Raw Brand Info: </span><span>" + data[0].result.value.brand_id_raw + "</span></div> \
- + <div><span style='font-weight: bold;'>Translated Brand ID: </span><span>" + data[0].result.value.brand_id + "</span></div> \
- + <div><span style='font-weight: bold;'>Store ID: </span><span>" + data[0].result.value.store_id + "</span></div> \
- + <div><span style='font-weight: bold;'>Data Source: </span><span>" + data[0].result.value.data_source + "</span></div> \
- + <div><span style='font-weight: bold;'>GIS Error Info (If applicable): </span><span>" + data[0].result.value.gis_error + "</span></div> \
- + </center>";
- + $("#device_result").html(html_out);
- + }
- +
- + });
- + });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement