imperituroard 1.0.1 → 1.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.idea/runConfigurations/version.xml +21 -0
- data/lib/imperituroard.rb +7 -0
- data/lib/imperituroard/projects/iot.rb +173 -147
- data/lib/imperituroard/projects/iot/hua_oceanconnect_adapter.rb +107 -22
- data/lib/imperituroard/projects/iot/internal_functions.rb +8 -0
- data/lib/imperituroard/projects/iot/mongoconnector.rb +28 -13
- data/lib/imperituroard/version.rb +2 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4f4aba43e40c3e31b5d3336e6dd8233ced0fdc47
|
4
|
+
data.tar.gz: 14a08ce0ee5ee4af6f0af163c4eb148e1c18274b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bbb81cd14c71ebe0693054322a33f8ad93096cada10528eb7665d8f822ec53430f42f81ccbaeb632bc7f41441509fda8dc2d0b69b54de6cdea11abe5034ac306
|
7
|
+
data.tar.gz: 6d9f3d756baaa25e8eacbb630822b1c26449d677caaa3dc0d47e8c79c1e514dfe6321c5370922f7b41da86ca466437f03ee1f2d45fffca990a73a4941053feff
|
@@ -0,0 +1,21 @@
|
|
1
|
+
<component name="ProjectRunConfigurationManager">
|
2
|
+
<configuration default="false" name="version" type="RubyRunConfigurationType" factoryName="Ruby">
|
3
|
+
<module name="imperituroard" />
|
4
|
+
<RUBY_RUN_CONFIG NAME="RUBY_ARGS" VALUE="-e $stdout.sync=true;$stderr.sync=true;load($0=ARGV.shift)" />
|
5
|
+
<RUBY_RUN_CONFIG NAME="WORK DIR" VALUE="$MODULE_DIR$/lib/imperituroard" />
|
6
|
+
<RUBY_RUN_CONFIG NAME="SHOULD_USE_SDK" VALUE="false" />
|
7
|
+
<RUBY_RUN_CONFIG NAME="ALTERN_SDK_NAME" VALUE="" />
|
8
|
+
<RUBY_RUN_CONFIG NAME="myPassParentEnvs" VALUE="true" />
|
9
|
+
<envs />
|
10
|
+
<EXTENSION ID="BundlerRunConfigurationExtension" bundleExecEnabled="true" />
|
11
|
+
<EXTENSION ID="JRubyRunConfigurationExtension" NailgunExecEnabled="false" />
|
12
|
+
<EXTENSION ID="RubyCoverageRunConfigurationExtension" enabled="false" sample_coverage="true" track_test_folders="true" runner="rcov">
|
13
|
+
<COVERAGE_PATTERN ENABLED="true">
|
14
|
+
<PATTERN REGEXPS="/.rvm/" INCLUDED="false" />
|
15
|
+
</COVERAGE_PATTERN>
|
16
|
+
</EXTENSION>
|
17
|
+
<RUBY_RUN_CONFIG NAME="SCRIPT_PATH" VALUE="$MODULE_DIR$/lib/imperituroard/version.rb" />
|
18
|
+
<RUBY_RUN_CONFIG NAME="SCRIPT_ARGS" VALUE="" />
|
19
|
+
<method />
|
20
|
+
</configuration>
|
21
|
+
</component>
|
data/lib/imperituroard.rb
CHANGED
@@ -33,6 +33,7 @@ require 'net/http'
|
|
33
33
|
require 'uri'
|
34
34
|
|
35
35
|
module Imperituroard
|
36
|
+
|
36
37
|
class Error < StandardError;
|
37
38
|
end
|
38
39
|
|
@@ -42,6 +43,7 @@ module Imperituroard
|
|
42
43
|
def hhh(jjj)
|
43
44
|
p jjj
|
44
45
|
end
|
46
|
+
|
45
47
|
# Your code goes here...
|
46
48
|
end
|
47
49
|
|
@@ -239,6 +241,11 @@ class Iot
|
|
239
241
|
iot_connector.get_available_types_2(login, real_ip, remote_ip)
|
240
242
|
end
|
241
243
|
|
244
|
+
#9-1 get available types for login and profile
|
245
|
+
def get_available_types2(login, profile, real_ip, remote_ip)
|
246
|
+
iot_connector.get_available_types2_2(login, profile, real_ip, remote_ip)
|
247
|
+
end
|
248
|
+
|
242
249
|
#10 get info for device type
|
243
250
|
def get_info_data_type(type, real_ip, remote_ip)
|
244
251
|
iot_connector.get_info_data_type_2(type, real_ip, remote_ip)
|
@@ -115,10 +115,9 @@ class IotFunctions_2
|
|
115
115
|
end
|
116
116
|
end
|
117
117
|
|
118
|
-
|
119
118
|
begin
|
120
119
|
added_on_iot_platf = []
|
121
|
-
if for_insert!=[]
|
120
|
+
if for_insert != []
|
122
121
|
##Logic for IOT Platform connection###
|
123
122
|
|
124
123
|
|
@@ -141,7 +140,7 @@ class IotFunctions_2
|
|
141
140
|
|
142
141
|
#get {"model"=>"BGT_PPMC", "ManufacturerID"=>"unknown", "ManufacturerNAME"=>"unknown", "device_type"=>"unknown"}
|
143
142
|
#from database
|
144
|
-
model_data = mongo_client.
|
143
|
+
model_data = mongo_client.get_device_type_info_universal(aaa["device_type"])
|
145
144
|
resss = hua_aceanconnect_connector.add_new_device_on_huawei(credentials[:body][:app_id],
|
146
145
|
credentials[:body][:secret],
|
147
146
|
aaa["imei"],
|
@@ -154,7 +153,6 @@ class IotFunctions_2
|
|
154
153
|
model_data[:body]["model"]
|
155
154
|
)
|
156
155
|
if resss[:code]=="200"
|
157
|
-
|
158
156
|
if resss[:body].key?("error_code") && resss[:body]["error_code"] != 200
|
159
157
|
not_processed_list.append({:imei => aaa["imei"], :error => resss})
|
160
158
|
else
|
@@ -163,15 +161,12 @@ class IotFunctions_2
|
|
163
161
|
s1[:created] = DateTime.now
|
164
162
|
added_on_iot_platf.append(s1)
|
165
163
|
end
|
166
|
-
|
167
164
|
else
|
168
165
|
not_processed_list.append({:imei => aaa["imei"], :error => resss})
|
169
166
|
end
|
170
167
|
rescue
|
171
168
|
not_processed_list.append({:imei => aaa["imei"], :error => "Unknown error with insertion imei on IOT platform"})
|
172
169
|
end
|
173
|
-
|
174
|
-
|
175
170
|
#########end iot platform logic#######
|
176
171
|
|
177
172
|
else
|
@@ -187,16 +182,12 @@ class IotFunctions_2
|
|
187
182
|
else
|
188
183
|
resp_out = {:code => 202, :result => "Empty list. Nothing for insertion", :body => {:imei_processed => added_on_iot_platf, :error_list => not_processed_list}}
|
189
184
|
end
|
190
|
-
|
191
|
-
|
192
185
|
else
|
193
186
|
resp_out = {:code => 202, :result => "Nothing for insertion", :body => {:imei_processed => added_on_iot_platf, :error_list => not_processed_list}}
|
194
|
-
|
195
187
|
end
|
196
188
|
rescue
|
197
189
|
resp_out = {:code => 505, :result => "Error with database communication"}
|
198
190
|
end
|
199
|
-
|
200
191
|
else
|
201
192
|
resp_out = {:code => 509, :result => "Input data invalid"}
|
202
193
|
end
|
@@ -206,9 +197,7 @@ class IotFunctions_2
|
|
206
197
|
end
|
207
198
|
thr1.join
|
208
199
|
|
209
|
-
|
210
200
|
resp_out[:body][:tosoapgw] = internal_func.iot_create_dev_soapgw_answer(input_json, resp_out)
|
211
|
-
|
212
201
|
mongo_client.audit_logger("add_device_to_profile", remote_ip, input_json, resp_out, real_ip)
|
213
202
|
resp_out
|
214
203
|
end
|
@@ -228,16 +217,16 @@ class IotFunctions_2
|
|
228
217
|
resp_out = {}
|
229
218
|
begin
|
230
219
|
thr2 = Thread.new do
|
231
|
-
if add_functions_connector.check_input_2(login, imei_list)[:code]==200
|
220
|
+
if add_functions_connector.check_input_2(login, imei_list)[:code] == 200
|
232
221
|
|
233
222
|
for t in imei_list
|
234
223
|
prof_name1 = mongo_client.get_profile_name_from_imei(t)
|
235
|
-
if prof_name1[:code]==200
|
224
|
+
if prof_name1[:code] == 200
|
236
225
|
begin
|
237
226
|
permiss1 = mongo_client.check_login_profile_permiss(login, prof_name1[:body]["profile"])
|
238
227
|
p "permiss1"
|
239
228
|
p permiss1
|
240
|
-
if permiss1[:code]==200
|
229
|
+
if permiss1[:code] == 200
|
241
230
|
ime_list_approved.append(t)
|
242
231
|
else
|
243
232
|
ime_list_notapproved.append({:imei => t, :error => permiss1})
|
@@ -467,12 +456,12 @@ class IotFunctions_2
|
|
467
456
|
begin
|
468
457
|
thr4 = Thread.new do
|
469
458
|
|
470
|
-
if add_functions_connector.check_input_4(login, imei)[:code]==200
|
459
|
+
if add_functions_connector.check_input_4(login, imei)[:code] == 200
|
471
460
|
|
472
461
|
prof_name = mongo_client.get_profile_name_from_imei(imei)
|
473
|
-
if prof_name[:code]==200
|
462
|
+
if prof_name[:code] == 200
|
474
463
|
permiss = mongo_client.check_login_profile_permiss(login, prof_name[:body]["profile"])
|
475
|
-
if permiss[:code]==200
|
464
|
+
if permiss[:code] == 200
|
476
465
|
|
477
466
|
##Logic for IOT Platform connection###
|
478
467
|
|
@@ -486,17 +475,17 @@ class IotFunctions_2
|
|
486
475
|
|
487
476
|
resp = {}
|
488
477
|
|
489
|
-
if credentials[:code]==200
|
478
|
+
if credentials[:code] == 200
|
490
479
|
|
491
480
|
imei_data = mongo_client.get_imei_info_from_db([imei])
|
492
|
-
if imei_data[:body]!=[]
|
481
|
+
if imei_data[:body] != []
|
493
482
|
ans = {}
|
494
483
|
if imei_data[:body][0]["huadata"]["body"]["deviceId"] != nil
|
495
484
|
ans = hua_aceanconnect_connector.remove_one_device_from_iot(credentials[:body][:app_id], credentials[:body][:secret], imei_data[:body][0]["huadata"]["body"]["deviceId"])
|
496
485
|
else
|
497
486
|
ans = {:code => "204", :result => "Not processed by iot platform. deviceId not found in mongoDB"}
|
498
487
|
end
|
499
|
-
if ans[:code]=="204" or ans[:code]=="200"
|
488
|
+
if ans[:code] == "204" or ans[:code] == "200"
|
500
489
|
resp = mongo_client.device_remove_single_mongo(imei)
|
501
490
|
else
|
502
491
|
resp = {:code => 500, :result => "Unknown IOT platform error", :body => ans}
|
@@ -580,10 +569,8 @@ class IotFunctions_2
|
|
580
569
|
imei_data = mongo_client.get_imei_info_from_db([p[:imei]])
|
581
570
|
if imei_data[:body]!=[]
|
582
571
|
ans = hua_aceanconnect_connector.modify_location_iot(credentials[:body][:app_id], credentials[:body][:secret], imei_data[:body][0]["huadata"]["body"]["deviceId"], p[:address])
|
583
|
-
|
584
572
|
internal_func.printer_texter({:function => "device_add_address Step2", :ans => ans, :descrition => "answer from hua IOT", :input => {:did => imei_data[:body][0]["huadata"]["body"]["deviceId"], :appid => credentials[:body][:app_id], :secret => credentials[:body][:secret], :address => p[:address]}}, "debug")
|
585
573
|
end
|
586
|
-
|
587
574
|
end
|
588
575
|
|
589
576
|
#########end iot platform logic#######
|
@@ -658,7 +645,7 @@ class IotFunctions_2
|
|
658
645
|
if attr["profile"].is_a? Integer
|
659
646
|
p "Ok"
|
660
647
|
else
|
661
|
-
p new = mongo_client.
|
648
|
+
p new = mongo_client.get_profile_universal(attr["profile"])
|
662
649
|
attr["profile"] = new["profile_id"]
|
663
650
|
end
|
664
651
|
end
|
@@ -686,9 +673,7 @@ class IotFunctions_2
|
|
686
673
|
else
|
687
674
|
resp_out = {:code => 509, :result => "Input data invalid"}
|
688
675
|
end
|
689
|
-
|
690
676
|
end
|
691
|
-
|
692
677
|
rescue
|
693
678
|
resp_out = {:code => 507, :result => "Unknown SDK error"}
|
694
679
|
end
|
@@ -745,6 +730,7 @@ class IotFunctions_2
|
|
745
730
|
permit_profiles = login_info[:body]["permit_profiles"]
|
746
731
|
permit_types = login_info[:body]["permit_types"]
|
747
732
|
data_from_mongo = mongo_client.get_profile_list_by_id(permit_profiles)
|
733
|
+
p data_from_mongo
|
748
734
|
|
749
735
|
for ff in data_from_mongo
|
750
736
|
data_processed.append({:profile_id => ff["profile_id"],
|
@@ -849,33 +835,47 @@ class IotFunctions_2
|
|
849
835
|
data_processed = []
|
850
836
|
data_soapgw = []
|
851
837
|
login_info = mongo_client.get_login_inf2_select(login)
|
838
|
+
prof_data = mongo_client.get_profile_universal(profile)
|
852
839
|
if login_info[:code]==200
|
853
840
|
|
854
841
|
permit_profiles = login_info[:body]["permit_profiles"]
|
855
842
|
permit_types = login_info[:body]["permit_types"]
|
843
|
+
perm_tp_prof = prof_data["permit_types"]
|
844
|
+
|
845
|
+
if permit_profiles.include?(prof_data["profile_id"])
|
846
|
+
res_types_permitted = internal_func.compare_dict(permit_types, perm_tp_prof)
|
847
|
+
data_from_mongo = mongo_client.get_type_list_by_id(res_types_permitted)
|
848
|
+
|
849
|
+
for ff in data_from_mongo
|
850
|
+
data_processed.append({:type_id => ff["type_id"],
|
851
|
+
:description => ff["description"],
|
852
|
+
:note => ff["note"],
|
853
|
+
:form => ff["form"],
|
854
|
+
:ManufacturerID => ff["ManufacturerID"],
|
855
|
+
:ManufacturerNAME => ff["ManufacturerNAME"],
|
856
|
+
:device_type => ff["device_type"],
|
857
|
+
:model => ff["model"],
|
858
|
+
:info => ff["info"]
|
859
|
+
})
|
860
|
+
data_soapgw.append({:name => ff["model"], :form => ff["form"], :description => ff["description"], :type_id => ff["type_id"]})
|
861
|
+
end
|
856
862
|
|
857
|
-
|
863
|
+
tosoapgw = {:code => 200,
|
864
|
+
:result => "Request completed successfully",
|
865
|
+
:types => data_soapgw
|
866
|
+
}
|
858
867
|
|
859
|
-
|
860
|
-
|
861
|
-
|
862
|
-
|
863
|
-
|
864
|
-
|
865
|
-
|
866
|
-
|
867
|
-
:model => ff["model"],
|
868
|
-
:info => ff["info"]
|
869
|
-
})
|
870
|
-
data_soapgw.append({:name => ff["model"], :form => ff["form"], :description => ff["description"], :type_id => ff["type_id"]})
|
868
|
+
resp_out = {:code => 200, :result => "Request completed successfully", :body => {:data => data_processed, :tosoapgw => tosoapgw}}
|
869
|
+
|
870
|
+
else
|
871
|
+
tosoapgw = {:code => 700,
|
872
|
+
:result => "Profile not permitted",
|
873
|
+
:types => data_soapgw
|
874
|
+
}
|
875
|
+
resp_out = {:code => 700, :result => "Profile not permitted", :body => {:tosoapgw => tosoapgw}}
|
871
876
|
end
|
872
877
|
|
873
|
-
tosoapgw = {:code => 200,
|
874
|
-
:result => "Request completed successfully",
|
875
|
-
:types => data_soapgw
|
876
|
-
}
|
877
878
|
|
878
|
-
resp_out = {:code => 200, :result => "Request completed successfully", :body => {:data => data_processed, :tosoapgw => tosoapgw}}
|
879
879
|
else
|
880
880
|
tosoapgw = {:code => login_info[:code],
|
881
881
|
:result => login_info[:result],
|
@@ -939,6 +939,8 @@ class IotFunctions_2
|
|
939
939
|
mon_answer = mongo_client.get_profile_name_by_id(profile)
|
940
940
|
end
|
941
941
|
|
942
|
+
p mon_answer
|
943
|
+
|
942
944
|
if mon_answer != {} && mon_answer != []
|
943
945
|
output_answ = {:code => 200, :result => "Request completed successfully", :body => {:data => {:info => mon_answer["info"],
|
944
946
|
:profile => mon_answer["profile"],
|
@@ -952,7 +954,6 @@ class IotFunctions_2
|
|
952
954
|
end
|
953
955
|
mongo_client.audit_logger("get_info_data_profile_2", remote_ip, input_params, output_answ, real_ip)
|
954
956
|
output_answ
|
955
|
-
|
956
957
|
end
|
957
958
|
|
958
959
|
|
@@ -971,138 +972,163 @@ class IotFunctions_2
|
|
971
972
|
inp_login = soapgw_params["autorization"]["login"]
|
972
973
|
inp_dev_list = soapgw_params["datalist"]
|
973
974
|
|
974
|
-
|
975
|
-
|
976
|
-
|
977
|
-
|
978
|
-
|
979
|
-
|
980
|
-
|
981
|
-
|
982
|
-
|
983
|
-
|
984
|
-
|
985
|
-
|
986
|
-
|
987
|
-
|
988
|
-
|
989
|
-
|
990
|
-
|
991
|
-
|
992
|
-
|
993
|
-
p cur_comp1
|
994
|
-
p cur_comp2
|
995
|
-
if cur_comp1[:is_the_same] && cur_comp2[:is_the_same]
|
996
|
-
#the same. Nothing to do
|
997
|
-
processed_list.append(curr_dev)
|
998
|
-
########
|
999
|
-
else
|
1000
|
-
|
1001
|
-
credentials_old = mongo_client.get_iot_oceanconn_credent_2(prof_name1[:body]["profile"])
|
1002
|
-
credentials_new = mongo_client.get_iot_oceanconn_credent_2(prof_new_id)
|
1003
|
-
#########
|
1004
|
-
if credentials_old[:code] == 200 && credentials_new[:code] == 200
|
1005
|
-
imei_data = mongo_client.get_imei_info_from_db([curr_dev["imei"].to_i])
|
1006
|
-
if imei_data[:body] != []
|
1007
|
-
ans = {}
|
1008
|
-
if imei_data[:body][0]["huadata"]["body"]["deviceId"] != nil
|
1009
|
-
|
1010
|
-
model_data = mongo_client.get_device_type_info_universal(curr_dev["new_type"])
|
1011
|
-
|
1012
|
-
#####all checks completed. then process data#####
|
1013
|
-
ans_old = hua_aceanconnect_connector.remove_one_device_from_iot(credentials_old[:body][:app_id], credentials_old[:body][:secret], imei_data[:body][0]["huadata"]["body"]["deviceId"])
|
1014
|
-
|
1015
|
-
if ans_old[:code].to_i == 200 || ans_old[:code].to_i == 202 || ans_old[:code].to_i == 204
|
1016
|
-
begin
|
1017
|
-
resss = hua_aceanconnect_connector.add_new_device_on_huawei(credentials_new[:body][:app_id],
|
1018
|
-
credentials_new[:body][:secret],
|
1019
|
-
curr_dev["imei"].to_i,
|
1020
|
-
curr_dev["imei"].to_s,
|
1021
|
-
prof_name1[:body]["description"],
|
1022
|
-
model_data[:body]["device_type"],
|
1023
|
-
curr_dev["new_profile"],
|
1024
|
-
model_data[:body]["ManufacturerID"],
|
1025
|
-
model_data[:body]["ManufacturerNAME"],
|
1026
|
-
model_data[:body]["model"]
|
1027
|
-
)
|
1028
|
-
|
1029
|
-
if resss[:code]=="200"
|
1030
|
-
|
1031
|
-
if resss[:body].key?("error_code") && resss[:body]["error_code"] != 200
|
1032
|
-
not_processed_list.append({:imei => curr_dev["imei"], :error => resss})
|
1033
|
-
else
|
1034
|
-
new_id_iot = resss[:body]
|
1035
|
-
new_profile_id = prof_new_id
|
1036
|
-
now_date = DateTime.now
|
1037
|
-
#finished success. update database
|
1038
|
-
attribute = {profile: new_profile_id, device_type: model_data[:body]["model"], huadata: {body: new_id_iot}, updated: now_date}
|
975
|
+
thr13set = Thread.new do
|
976
|
+
inp_dev_list.each do |curr_dev|
|
977
|
+
begin
|
978
|
+
if curr_dev["imei"] != [] && curr_dev["imei"] != nil && curr_dev["imei"] != ""
|
979
|
+
list_checked = mongo_client.check_imei_exists([curr_dev["imei"].to_i])
|
980
|
+
if list_checked[:code] == 200 && list_checked[:body][:exists] != [] && list_checked[:body][:not_exists] == []
|
981
|
+
|
982
|
+
#step1 checking permission for writing for imei list
|
983
|
+
prof_name1 = mongo_client.get_profile_name_from_imei(curr_dev["imei"].to_i)
|
984
|
+
p prof_name1
|
985
|
+
p "prof_name1"
|
986
|
+
if prof_name1[:code] == 200
|
987
|
+
|
988
|
+
if curr_dev["new_profile"] != "nil" && curr_dev["new_profile"] != "null" && curr_dev["new_profile"] != "empty" && curr_dev["new_profile"] != "nill"
|
989
|
+
prof_new_id = mongo_client.get_profile_universal(curr_dev["new_profile"])["profile_id"]
|
990
|
+
else
|
991
|
+
prof_new_id = prof_name1[:body]["profile_id"]
|
992
|
+
end
|
1039
993
|
|
1040
|
-
|
994
|
+
if curr_dev["new_type"] != "nil" && curr_dev["new_type"] != "null" && curr_dev["new_type"] != "empty" && curr_dev["new_type"] != "nill"
|
995
|
+
type_new_pr = curr_dev["new_type"]
|
996
|
+
else
|
997
|
+
type_new_pr = prof_name1[:imei_info][:body][0]["device_type"]
|
998
|
+
end
|
1041
999
|
|
1042
|
-
|
1043
|
-
|
1000
|
+
p type_new_pr
|
1001
|
+
p prof_new_id
|
1002
|
+
p "st111111"
|
1003
|
+
|
1004
|
+
get_login_info = mongo_client.check_login_prof_perm_id_one(inp_login, prof_name1[:body]["profile_id"])
|
1005
|
+
p get_login_info
|
1006
|
+
p "get_login_info"
|
1007
|
+
if get_login_info[:code] == 200
|
1008
|
+
get_login_info_new = mongo_client.check_login_prof_perm_id_one(inp_login, prof_new_id)
|
1009
|
+
p get_login_info_new
|
1010
|
+
p "get_login_info_new"
|
1011
|
+
if get_login_info_new[:code] == 200
|
1012
|
+
cur_comp1 = mongo_client.compare_profiles(prof_name1[:body]["profile_id"], prof_new_id)
|
1013
|
+
p cur_comp1
|
1014
|
+
p "cur_comp1"
|
1015
|
+
cur_comp2 = mongo_client.compare_device_types(prof_name1[:imei_info][:body][0]["device_type"], type_new_pr)
|
1016
|
+
|
1017
|
+
|
1018
|
+
p cur_comp2
|
1019
|
+
p "cur_comp2"
|
1020
|
+
|
1021
|
+
if cur_comp1[:is_the_same] && cur_comp2[:is_the_same]
|
1022
|
+
#the same. Nothing to do
|
1023
|
+
processed_list.append(curr_dev)
|
1024
|
+
########
|
1025
|
+
else
|
1026
|
+
credentials_old = mongo_client.get_iot_oceanconn_credent_2(prof_name1[:body]["profile"])
|
1027
|
+
credentials_new = mongo_client.get_iot_oceanconn_credent_2(prof_new_id)
|
1028
|
+
p credentials_new
|
1029
|
+
p "credentials_new"
|
1030
|
+
#########
|
1031
|
+
if credentials_old[:code] == 200 && credentials_new[:code] == 200
|
1032
|
+
imei_data = mongo_client.get_imei_info_from_db([curr_dev["imei"].to_i])
|
1033
|
+
p imei_data
|
1034
|
+
p "imei_data"
|
1035
|
+
if imei_data[:body] != []
|
1036
|
+
ans = {}
|
1037
|
+
if imei_data[:body][0]["huadata"]["body"]["deviceId"] != nil
|
1038
|
+
model_data = mongo_client.get_device_type_info_universal(type_new_pr)
|
1039
|
+
p model_data
|
1040
|
+
p "model_data"
|
1041
|
+
#####all checks completed. then process data#####
|
1042
|
+
ans_old = hua_aceanconnect_connector.remove_one_device_from_iot(credentials_old[:body][:app_id], credentials_old[:body][:secret], imei_data[:body][0]["huadata"]["body"]["deviceId"])
|
1043
|
+
|
1044
|
+
|
1045
|
+
if ans_old[:code].to_i == 200 || ans_old[:code].to_i == 202 || ans_old[:code].to_i == 204
|
1046
|
+
begin
|
1047
|
+
resss = hua_aceanconnect_connector.add_new_device_on_huawei(credentials_new[:body][:app_id],
|
1048
|
+
credentials_new[:body][:secret],
|
1049
|
+
curr_dev["imei"].to_i,
|
1050
|
+
curr_dev["imei"].to_s,
|
1051
|
+
prof_name1[:body]["description"],
|
1052
|
+
model_data[:body]["device_type"],
|
1053
|
+
curr_dev["new_profile"],
|
1054
|
+
model_data[:body]["ManufacturerID"],
|
1055
|
+
model_data[:body]["ManufacturerNAME"],
|
1056
|
+
model_data[:body]["model"]
|
1057
|
+
)
|
1058
|
+
if resss[:code] == "200"
|
1059
|
+
if resss[:body].key?("error_code") && resss[:body]["error_code"] != 200
|
1060
|
+
not_processed_list.append({:imei => curr_dev["imei"], :error => resss})
|
1044
1061
|
else
|
1045
|
-
|
1062
|
+
new_id_iot = resss[:body]
|
1063
|
+
new_profile_id = prof_new_id
|
1064
|
+
now_date = DateTime.now
|
1065
|
+
#finished success. update database
|
1066
|
+
attribute = {profile: new_profile_id, device_type: model_data[:body]["model"], huadata: {body: new_id_iot}, updated: now_date}
|
1067
|
+
answ_mongo = mongo_client.modify_attr_mongo_universal(curr_dev["imei"].to_i, attribute)
|
1068
|
+
if answ_mongo[:code] != 200
|
1069
|
+
not_processed_list.append({:imei => curr_dev["imei"], :error => "Critical error. Mongo not updated", :mongo_err => answ_mongo})
|
1070
|
+
else
|
1071
|
+
processed_list.append(curr_dev)
|
1072
|
+
end
|
1046
1073
|
end
|
1047
|
-
|
1048
|
-
|
1074
|
+
else
|
1075
|
+
not_processed_list.append({:imei => curr_dev["imei"], :error => resss})
|
1049
1076
|
end
|
1050
|
-
|
1051
|
-
|
1052
|
-
not_processed_list.append({:imei => curr_dev["imei"], :error => resss})
|
1077
|
+
rescue
|
1078
|
+
not_processed_list.append({:imei => curr_dev["imei"], :error => "Unknown error with insertion imei on IOT platform"})
|
1053
1079
|
end
|
1054
|
-
|
1055
|
-
not_processed_list.append({:imei => curr_dev["imei"], :error => "
|
1080
|
+
else
|
1081
|
+
not_processed_list.append({:imei => curr_dev["imei"], :error => "Something wrong with IOT platform"})
|
1056
1082
|
end
|
1083
|
+
else
|
1084
|
+
not_processed_list.append({:imei => curr_dev["imei"], :error => "Not processed by iot platform. deviceId not found in mongoDB"})
|
1057
1085
|
end
|
1058
1086
|
else
|
1059
|
-
not_processed_list.append({:imei => curr_dev["imei"], :error => "
|
1087
|
+
not_processed_list.append({:imei => curr_dev["imei"], :error => "Failed to get info from database"})
|
1060
1088
|
end
|
1061
1089
|
else
|
1062
|
-
not_processed_list.append({:imei => curr_dev["imei"], :error => "Failed to get
|
1090
|
+
not_processed_list.append({:imei => curr_dev["imei"], :error => "Failed to get credentials from database"})
|
1063
1091
|
end
|
1064
|
-
else
|
1065
|
-
not_processed_list.append({:imei => curr_dev["imei"], :error => "Failed to get credentials from database"})
|
1066
1092
|
end
|
1093
|
+
else
|
1094
|
+
not_processed_list.append({:imei => curr_dev["imei"], :error => "New profile modification not permitted"})
|
1067
1095
|
end
|
1068
1096
|
else
|
1069
|
-
not_processed_list.append({:imei => curr_dev["imei"], :error => "
|
1097
|
+
not_processed_list.append({:imei => curr_dev["imei"], :error => "Old profile modification not permitted"})
|
1070
1098
|
end
|
1071
1099
|
else
|
1072
|
-
not_processed_list.append({:imei => curr_dev["imei"], :error => "
|
1100
|
+
not_processed_list.append({:imei => curr_dev["imei"], :error => "Unknown current profile"})
|
1073
1101
|
end
|
1074
1102
|
else
|
1075
|
-
not_processed_list.append({:imei => curr_dev["imei"], :error => "
|
1103
|
+
not_processed_list.append({:imei => curr_dev["imei"], :error => "Device not exists"})
|
1076
1104
|
end
|
1077
1105
|
else
|
1078
|
-
not_processed_list.append({:imei => curr_dev["imei"], :error => "
|
1106
|
+
not_processed_list.append({:imei => curr_dev["imei"], :error => "IMEI can't be nil"})
|
1079
1107
|
end
|
1080
|
-
|
1081
|
-
not_processed_list.append({:imei => curr_dev["imei"], :error => "
|
1108
|
+
rescue
|
1109
|
+
not_processed_list.append({:imei => curr_dev["imei"], :error => "Unknown SDK error"})
|
1082
1110
|
end
|
1083
|
-
rescue
|
1084
|
-
not_processed_list.append({:imei => curr_dev["imei"], :error => "Unknown SDK error"})
|
1085
|
-
end
|
1086
1111
|
|
1087
|
-
|
1112
|
+
end
|
1088
1113
|
|
1089
|
-
|
1090
|
-
|
1091
|
-
|
1092
|
-
|
1114
|
+
err_li = []
|
1115
|
+
if not_processed_list.length > 0
|
1116
|
+
not_processed_list.each do |err_l|
|
1117
|
+
err_li.append({:failedimei => err_l[:imei]})
|
1118
|
+
end
|
1093
1119
|
end
|
1094
|
-
end
|
1095
1120
|
|
1096
|
-
|
1097
|
-
|
1098
|
-
|
1099
|
-
|
1121
|
+
if processed_list.length > 0
|
1122
|
+
answ_to_soapgw = {:code => 200, :result => "Success", :body => {:processednum => processed_list.length, :failednum => not_processed_list.length, :deviceserr => err_li}}
|
1123
|
+
else
|
1124
|
+
answ_to_soapgw = {:code => 202, :result => "Nothing done", :body => {:processednum => 0, :failednum => not_processed_list.length, :deviceserr => err_li}}
|
1125
|
+
end
|
1100
1126
|
end
|
1127
|
+
thr13set.join
|
1101
1128
|
|
1102
|
-
output_answ = {:code => 200, :result => "Success", :body => {:to_soap_gw =>
|
1129
|
+
output_answ = {:code => 200, :result => "Success", :body => {:to_soap_gw => answ_to_soapgw, :not_processed_list => not_processed_list, :processed_list => processed_list}}
|
1103
1130
|
mongo_client.audit_logger("set_data_replace_2", remote_ip, input_params, output_answ, real_ip)
|
1104
1131
|
output_answ
|
1105
|
-
|
1106
1132
|
end
|
1107
1133
|
|
1108
1134
|
|
@@ -74,6 +74,12 @@ class HuaIot
|
|
74
74
|
request.body = URI.encode_www_form(data)
|
75
75
|
res = https.request(request)
|
76
76
|
out_resp = {:code => res.code, :message => res.message, :body => JSON.parse(res.body.to_s)}
|
77
|
+
fff = {:func => "get_token",
|
78
|
+
:iot_fun => "",
|
79
|
+
:req_header => {:content_type => 'application/x-www-form-urlencoded',
|
80
|
+
:platform => "Huawei oceanconnect"
|
81
|
+
}}
|
82
|
+
client_iot_mongo.audit_iot_logger(fff, url_string, data, out_resp)
|
77
83
|
rescue
|
78
84
|
out_resp = {:code => 500, :message => "failed get token"}
|
79
85
|
end
|
@@ -106,6 +112,11 @@ class HuaIot
|
|
106
112
|
request.body = URI.encode_www_form(data)
|
107
113
|
res = https.request(request)
|
108
114
|
out_resp = {:code => res.code, :message => res.message, :body => JSON.parse(res.body.to_s)}
|
115
|
+
fff = {:func => "token_logout",
|
116
|
+
:iot_fun => "logout",
|
117
|
+
:platform => "Huawei oceanconnect"
|
118
|
+
}
|
119
|
+
client_iot_mongo.audit_iot_logger(fff, url_string, data, out_resp)
|
109
120
|
rescue
|
110
121
|
out_resp = {:code => 500, :message => "failed logout token"}
|
111
122
|
end
|
@@ -116,6 +127,7 @@ class HuaIot
|
|
116
127
|
|
117
128
|
#Registering a Directly Connected Device (Verification Code Mode) (V2)
|
118
129
|
def dev_register_verif_code_mode(app_id, secret, node_id)
|
130
|
+
out_resp = {}
|
119
131
|
token = get_token(app_id, secret)[:body]["accessToken"]
|
120
132
|
path = "/iocm/app/reg/v1.1.0/deviceCredentials?appId=" + app_id
|
121
133
|
url_string = "https://" + platformip + ":" + platformport + path
|
@@ -129,10 +141,17 @@ class HuaIot
|
|
129
141
|
request.content_type = 'application/json'
|
130
142
|
request['Authorization'] = 'Bearer ' + token
|
131
143
|
request['app_key'] = app_id
|
132
|
-
|
144
|
+
data = {nodeId: node_id}
|
145
|
+
request.body = data.to_json
|
133
146
|
res = https.request(request)
|
134
|
-
|
135
|
-
|
147
|
+
out_resp = {:code => res.code, :message => res.message, :body => JSON.parse(res.body.to_s)}
|
148
|
+
fff = {:func => "dev_register_verif_code_mode",
|
149
|
+
:iot_fun => "Registering a Directly Connected Device (Verification Code Mode) (V2)",
|
150
|
+
:req_header => {:content_type => 'application/json',
|
151
|
+
:platform => "Huawei oceanconnect"
|
152
|
+
}}
|
153
|
+
client_iot_mongo.audit_iot_logger(fff, url_string, data, out_resp)
|
154
|
+
out_resp
|
136
155
|
end
|
137
156
|
|
138
157
|
#2.2.4 Registering a Directly Connected Device (Password Mode) (V2)
|
@@ -168,7 +187,8 @@ class HuaIot
|
|
168
187
|
:iot_fun => "2.2.4",
|
169
188
|
:req_header => {:authorization => 'Bearer ' + token,
|
170
189
|
:content_type => 'application/json',
|
171
|
-
:app_key => app_id
|
190
|
+
:app_key => app_id,
|
191
|
+
:platform => "Huawei oceanconnect"
|
172
192
|
}}
|
173
193
|
client_iot_mongo.audit_iot_logger(fff, url_string, data_out, out_resp)
|
174
194
|
out_resp
|
@@ -191,13 +211,21 @@ class HuaIot
|
|
191
211
|
request.content_type = 'application/json'
|
192
212
|
request['Authorization'] = 'Bearer ' + token
|
193
213
|
request['app_key'] = app_id
|
194
|
-
|
214
|
+
data = {deviceInfo: attr_list}
|
215
|
+
data_out = data.to_json
|
195
216
|
internal_func.printer_texter({:procedure => "dev_register_passw_code_mode2", :data => {:body => data_out, :url => url_string}}, "debug")
|
196
217
|
request.body = data_out
|
197
218
|
res = https.request(request)
|
198
219
|
p res.body.to_s
|
199
220
|
out_resp = {:code => res.code, :message => res.message, :body => JSON.parse(res.body.to_s)}
|
200
|
-
|
221
|
+
fff = {:func => "dev_reg_passw_code_mode2_2",
|
222
|
+
:iot_fun => "2.2.4",
|
223
|
+
:req_header => {:content_type => 'application/json',
|
224
|
+
:authorization => 'Bearer ' + token,
|
225
|
+
:app_key => app_id,
|
226
|
+
:platform => "Huawei oceanconnect"
|
227
|
+
}}
|
228
|
+
client_iot_mongo.audit_iot_logger(fff, url_string, data, out_resp)
|
201
229
|
out_resp
|
202
230
|
end
|
203
231
|
|
@@ -220,26 +248,22 @@ class HuaIot
|
|
220
248
|
request['Authorization'] = 'Bearer ' + token
|
221
249
|
request['app_key'] = app_id
|
222
250
|
res = https.request(request)
|
223
|
-
p "res.code"
|
224
|
-
p res.code
|
225
|
-
p res.body
|
226
251
|
if res.body != nil
|
227
252
|
out_resp = {:code => res.code, :message => res.message, :body => {:answ => JSON.parse(res.body.to_s)}}
|
228
253
|
else
|
229
254
|
out_resp = {:code => res.code, :message => res.message, :body => {:answ => "no data"}}
|
230
255
|
end
|
231
|
-
|
232
256
|
fff = {:func => "dev_delete",
|
233
257
|
:iot_fun => "2.2.12",
|
234
258
|
:req_header => {:authorization => 'Bearer ' + token,
|
235
259
|
:content_type => 'application/json',
|
236
|
-
:app_key => app_id
|
260
|
+
:app_key => app_id,
|
261
|
+
:platform => "Huawei oceanconnect"
|
237
262
|
}}
|
238
263
|
client_iot_mongo.audit_iot_logger(fff, url_string, "Delete", out_resp)
|
239
264
|
rescue
|
240
265
|
out_resp = {:code => 500, :message => "dev_delete: Unknown IOT error"}
|
241
266
|
end
|
242
|
-
p out_resp
|
243
267
|
out_resp
|
244
268
|
end
|
245
269
|
|
@@ -271,6 +295,7 @@ class HuaIot
|
|
271
295
|
|
272
296
|
#2.2.14 Querying Device Activation Status
|
273
297
|
def querying_device_activ_status(app_id, secret, device_id)
|
298
|
+
output_ans = {}
|
274
299
|
token = get_token(app_id, secret)[:body]["accessToken"]
|
275
300
|
path = "/iocm/app/reg/v1.1.0/devices/" + device_id + "?app_Id=" + app_id
|
276
301
|
url_string = "https://" + platformip + ":" + platformport + path
|
@@ -285,12 +310,22 @@ class HuaIot
|
|
285
310
|
request['Authorization'] = 'Bearer ' + token
|
286
311
|
request['app_key'] = app_id
|
287
312
|
res = https.request(request)
|
288
|
-
{:code => res.code, :message => res.message, :body => JSON.parse(res.body.to_s)}
|
313
|
+
output_ans = {:code => res.code, :message => res.message, :body => JSON.parse(res.body.to_s)}
|
314
|
+
fff = {:func => "querying_device_activ_status",
|
315
|
+
:iot_fun => "2.2.14",
|
316
|
+
:req_header => {:content_type => 'application/json',
|
317
|
+
:authorization => 'Bearer ' + token,
|
318
|
+
:app_key => app_id,
|
319
|
+
:platform => "Huawei oceanconnect"
|
320
|
+
}}
|
321
|
+
client_iot_mongo.audit_iot_logger(fff, url_string, data, output_ans)
|
322
|
+
output_ans
|
289
323
|
end
|
290
324
|
|
291
325
|
|
292
326
|
#2.9.1 Querying Information About a Device
|
293
327
|
def querying_device_info(app_id, secret, device_id)
|
328
|
+
out_resp = {}
|
294
329
|
token = get_token(app_id, secret)[:body]["accessToken"]
|
295
330
|
path = "/iocm/app/dm/v1.1.0/devices/" + device_id + "?app_Id=" + app_id
|
296
331
|
url_string = "https://" + platformip + ":" + platformport + path
|
@@ -305,11 +340,21 @@ class HuaIot
|
|
305
340
|
request['Authorization'] = 'Bearer ' + token
|
306
341
|
request['app_key'] = app_id
|
307
342
|
res = https.request(request)
|
308
|
-
{:code => res.code, :message => res.message, :body => JSON.parse(res.body.to_s)}
|
343
|
+
out_resp = {:code => res.code, :message => res.message, :body => JSON.parse(res.body.to_s)}
|
344
|
+
fff = {:func => "querying_device_info",
|
345
|
+
:iot_fun => "2.9.1",
|
346
|
+
:req_header => {:authorization => 'Bearer ' + token,
|
347
|
+
:content_type => 'application/json',
|
348
|
+
:app_key => app_id,
|
349
|
+
:platform => "Huawei oceanconnect"
|
350
|
+
}}
|
351
|
+
client_iot_mongo.audit_iot_logger(fff, url_string, "Get", out_resp)
|
352
|
+
out_resp
|
309
353
|
end
|
310
354
|
|
311
355
|
#2.9.6 Querying Directly Connected Devices and Their Mounted Devices in Batches
|
312
356
|
def querying_device_direct_conn(app_id, secret, dev_list)
|
357
|
+
output_str = {}
|
313
358
|
token = get_token(app_id, secret)[:body]["accessToken"]
|
314
359
|
path = "/iocm/app/dm/v1.1.0/queryDevicesByIds"
|
315
360
|
url_string = "https://" + platformip + ":" + platformport + path
|
@@ -323,14 +368,25 @@ class HuaIot
|
|
323
368
|
request.content_type = 'application/json'
|
324
369
|
request['Authorization'] = 'Bearer ' + token
|
325
370
|
request['app_key'] = app_id
|
326
|
-
|
371
|
+
req_body = {deviceIds: dev_list}
|
372
|
+
request.body = req_body.to_json
|
327
373
|
res = https.request(request)
|
328
|
-
{:code => res.code, :message => res.message, :body => JSON.parse(res.body.to_s)}
|
374
|
+
output_str = {:code => res.code, :message => res.message, :body => JSON.parse(res.body.to_s)}
|
375
|
+
fff = {:func => "querying_device_direct_conn",
|
376
|
+
:iot_fun => "2.9.6",
|
377
|
+
:req_header => {:authorization => 'Bearer ' + token,
|
378
|
+
:content_type => 'application/json',
|
379
|
+
:app_key => app_id,
|
380
|
+
:platform => "Huawei oceanconnect"
|
381
|
+
}}
|
382
|
+
client_iot_mongo.audit_iot_logger(fff, url_string, req_body, output_str)
|
383
|
+
output_str
|
329
384
|
end
|
330
385
|
|
331
386
|
|
332
387
|
#2.9.19 Querying the Complete Device Type List of All Device Capabilities
|
333
388
|
def querying_device_type_list(app_id, secret)
|
389
|
+
output_ans = {}
|
334
390
|
token = get_token(app_id, secret)[:body]["accessToken"]
|
335
391
|
path = "/iocm/app/profile/v1.1.0/allDeviceTypes"
|
336
392
|
url_string = "https://" + platformip + ":" + platformport + path
|
@@ -345,13 +401,24 @@ class HuaIot
|
|
345
401
|
request['Authorization'] = 'Bearer ' + token
|
346
402
|
request['app_key'] = app_id
|
347
403
|
res = https.request(request)
|
348
|
-
{:code => res.code, :message => res.message, :body => JSON.parse(res.body.to_s)}
|
404
|
+
output_ans = {:code => res.code, :message => res.message, :body => JSON.parse(res.body.to_s)}
|
405
|
+
|
406
|
+
fff = {:func => "querying_device_type_list",
|
407
|
+
:iot_fun => "2.9.19",
|
408
|
+
:req_header => {:content_type => 'application/json',
|
409
|
+
:authorization => 'Bearer ' + token,
|
410
|
+
:app_key => app_id,
|
411
|
+
:platform => "Huawei oceanconnect"
|
412
|
+
}}
|
413
|
+
client_iot_mongo.audit_iot_logger(fff, url_string, "Get", output_ans)
|
414
|
+
output_ans
|
415
|
+
|
349
416
|
end
|
350
417
|
|
351
418
|
|
352
419
|
#2.9.6 Querying Directly Connected Devices and Their Mounted Devices in Batches
|
353
420
|
def quer_dev_direct_conn_batches(app_id, dev_list, token)
|
354
|
-
|
421
|
+
output_ans = {}
|
355
422
|
path = "/iocm/app/dm/v1.1.0/queryDevicesByIds"
|
356
423
|
url_string = "https://" + platformip + ":" + platformport + path
|
357
424
|
p url_string
|
@@ -365,10 +432,19 @@ class HuaIot
|
|
365
432
|
request.content_type = 'application/json'
|
366
433
|
request['Authorization'] = 'Bearer ' + token
|
367
434
|
request['app_key'] = app_id
|
368
|
-
|
435
|
+
data = {deviceIds: dev_list}
|
436
|
+
request.body = data.to_json
|
369
437
|
res = https.request(request)
|
370
|
-
{:code => res.code, :message => res.message, :body => JSON.parse(res.body.to_s)}
|
371
|
-
|
438
|
+
output_ans = {:code => res.code, :message => res.message, :body => JSON.parse(res.body.to_s)}
|
439
|
+
fff = {:func => "quer_dev_direct_conn_batches",
|
440
|
+
:iot_fun => "2.9.6",
|
441
|
+
:req_header => {:content_type => 'application/json',
|
442
|
+
:authorization => 'Bearer ' + token,
|
443
|
+
:app_key => app_id,
|
444
|
+
:platform => "Huawei oceanconnect"
|
445
|
+
}}
|
446
|
+
client_iot_mongo.audit_iot_logger(fff, url_string, data, output_ans)
|
447
|
+
output_ans
|
372
448
|
end
|
373
449
|
|
374
450
|
|
@@ -390,7 +466,8 @@ class HuaIot
|
|
390
466
|
request.content_type = 'application/json'
|
391
467
|
request['Authorization'] = 'Bearer ' + token
|
392
468
|
request['app_key'] = app_id
|
393
|
-
|
469
|
+
req_b = {location: address}
|
470
|
+
request.body = req_b.to_json
|
394
471
|
res = https.request(request)
|
395
472
|
p res.code
|
396
473
|
p res.body
|
@@ -399,6 +476,14 @@ class HuaIot
|
|
399
476
|
else
|
400
477
|
out_resp = {:code => res.code, :message => res.message, :body => {:answ => "no data"}}
|
401
478
|
end
|
479
|
+
fff = {:func => "dev_modify_location_v2",
|
480
|
+
:iot_fun => "2.2.11",
|
481
|
+
:req_header => {:authorization => 'Bearer ' + token,
|
482
|
+
:content_type => 'application/json',
|
483
|
+
:app_key => app_id,
|
484
|
+
:platform => "Huawei oceanconnect"
|
485
|
+
}}
|
486
|
+
client_iot_mongo.audit_iot_logger(fff, url_string, req_b, out_resp)
|
402
487
|
rescue
|
403
488
|
out_resp = {:code => 500, :message => "dev_modify_location_v2: Unknown IOT error"}
|
404
489
|
end
|
@@ -155,6 +155,14 @@ class InternalFunc
|
|
155
155
|
answer
|
156
156
|
end
|
157
157
|
|
158
|
+
#compare dictionaries
|
159
|
+
def compare_dict(dict1, dict2)
|
160
|
+
v1 = dict1 - dict2
|
161
|
+
v2 = dict2 - dict1
|
162
|
+
v3 = dict2 + dict1
|
163
|
+
v3.uniq - v2.uniq - v1.uniq
|
164
|
+
end
|
165
|
+
|
158
166
|
def test()
|
159
167
|
p "eeeeeeeeeeeeeeeeeeeeeeee"
|
160
168
|
end
|
@@ -194,7 +194,7 @@ class MongoIot
|
|
194
194
|
begin
|
195
195
|
result_ps = []
|
196
196
|
collection = client[:device_profiles]
|
197
|
-
collection.find({"profile_id" => profile_id}).each {|row|
|
197
|
+
collection.find({"profile_id" => profile_id.to_i}).each {|row|
|
198
198
|
result_ps.append(row)
|
199
199
|
}
|
200
200
|
result_ps[0]
|
@@ -238,7 +238,7 @@ class MongoIot
|
|
238
238
|
begin
|
239
239
|
result_ps = []
|
240
240
|
collection = client[:device_types]
|
241
|
-
collection.find({"type_id" => type_id}).each {|row|
|
241
|
+
collection.find({"type_id" => type_id.to_i}).each {|row|
|
242
242
|
result_ps.append(row)
|
243
243
|
}
|
244
244
|
result_ps[0]
|
@@ -260,19 +260,20 @@ class MongoIot
|
|
260
260
|
end
|
261
261
|
end
|
262
262
|
|
263
|
+
#universal procedure. might be profile id or name
|
263
264
|
def check_login_profile_permiss(login, profile)
|
264
265
|
out_resp = {}
|
265
266
|
get_login_info = get_profiles_by_login(login)
|
266
|
-
if get_login_info[:code]==200
|
267
|
-
dst_profile =
|
268
|
-
access=1
|
269
|
-
if get_login_info[:body]!=[]
|
270
|
-
if dst_profile!=[]
|
267
|
+
if get_login_info[:code] == 200
|
268
|
+
dst_profile = get_profile_universal(profile)
|
269
|
+
access = 1
|
270
|
+
if get_login_info[:body] != []
|
271
|
+
if dst_profile != []
|
271
272
|
for j in get_login_info[:body]
|
272
|
-
if j["profile_id"].to_i==dst_profile["profile_id"].to_i
|
273
|
-
access=0
|
273
|
+
if j["profile_id"].to_i == dst_profile["profile_id"].to_i
|
274
|
+
access = 0
|
274
275
|
end
|
275
|
-
if access==0
|
276
|
+
if access == 0
|
276
277
|
out_resp = {:code => 200, :result => "check_login_profile_permiss: Permission granted"}
|
277
278
|
else
|
278
279
|
out_resp = {:code => 400, :result => "check_login_profile_permiss: Access denied. This incident will be reported."}
|
@@ -292,13 +293,15 @@ class MongoIot
|
|
292
293
|
end
|
293
294
|
|
294
295
|
|
296
|
+
#universal procedure. You can use profile id or profile name as profile_id (string or int)
|
295
297
|
def check_login_prof_perm_id_one(login, profile_id)
|
296
298
|
out_resp = {}
|
297
299
|
get_login_info = get_profiles_by_login(login)
|
300
|
+
profile_data = self.get_profile_universal(profile_id)
|
298
301
|
access=1
|
299
302
|
if get_login_info[:body]!=[]
|
300
303
|
for j in get_login_info[:body]
|
301
|
-
if j["profile_id"].to_i==profile_id
|
304
|
+
if j["profile_id"].to_i==profile_data["profile_id"]
|
302
305
|
access=0
|
303
306
|
end
|
304
307
|
if access==0
|
@@ -340,7 +343,7 @@ class MongoIot
|
|
340
343
|
description: "test imei",
|
341
344
|
note: "second description",
|
342
345
|
profile: 0,
|
343
|
-
|
346
|
+
device_type: 0,
|
344
347
|
address: "unknown"
|
345
348
|
}
|
346
349
|
result = collection.insert_one(l)
|
@@ -363,7 +366,7 @@ class MongoIot
|
|
363
366
|
description: "test imei",
|
364
367
|
note: "second description",
|
365
368
|
profile: 0,
|
366
|
-
|
369
|
+
device_type: 0,
|
367
370
|
address: "unknown"
|
368
371
|
}
|
369
372
|
result = collection.insert_one(l)
|
@@ -501,6 +504,7 @@ class MongoIot
|
|
501
504
|
|
502
505
|
|
503
506
|
#function for get iot platform credentials from profile
|
507
|
+
#universal procedure. use profile or profile id
|
504
508
|
def get_iot_oceanconn_credent_2(profile)
|
505
509
|
out_resp = {}
|
506
510
|
begin
|
@@ -548,6 +552,7 @@ class MongoIot
|
|
548
552
|
out_resp
|
549
553
|
end
|
550
554
|
|
555
|
+
#universal procedure. Use id or name
|
551
556
|
def get_device_type_info_universal(device_model)
|
552
557
|
out_resp = {}
|
553
558
|
begin
|
@@ -632,6 +637,9 @@ class MongoIot
|
|
632
637
|
out_answ = {}
|
633
638
|
tp1 = internal_func.if_digit_or_string(type1)
|
634
639
|
tp2 = internal_func.if_digit_or_string(type2)
|
640
|
+
p tp1
|
641
|
+
p tp2
|
642
|
+
p "tp"
|
635
643
|
|
636
644
|
if tp1[:body][:string] == tp2[:body][:string] && tp1[:body][:string] == false
|
637
645
|
if type1.to_i == type2.to_i
|
@@ -648,6 +656,7 @@ class MongoIot
|
|
648
656
|
else
|
649
657
|
tp1_data = {}
|
650
658
|
tp2_data = {}
|
659
|
+
p "gggggggg"
|
651
660
|
if tp1[:body][:string]
|
652
661
|
tp1_data = self.get_type_by_name(type1)
|
653
662
|
else
|
@@ -660,6 +669,11 @@ class MongoIot
|
|
660
669
|
tp2_data = self.get_type_by_id(type2.to_i)
|
661
670
|
end
|
662
671
|
|
672
|
+
p tp1_data
|
673
|
+
p tp2_data
|
674
|
+
p type1
|
675
|
+
p type2
|
676
|
+
|
663
677
|
if tp1_data["type_id"] == tp2_data["type_id"]
|
664
678
|
out_answ = {:code => 200, :result => "compare_device_types: profiles are the same", :is_the_same => true, :data_type => "different"}
|
665
679
|
else
|
@@ -670,6 +684,7 @@ class MongoIot
|
|
670
684
|
end
|
671
685
|
|
672
686
|
|
687
|
+
#universal procedure. put there profile name or id in string or int
|
673
688
|
def get_profile_universal(profile)
|
674
689
|
inn = internal_func.if_digit_or_string(profile)
|
675
690
|
out = {}
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: imperituroard
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dzmitry Buynovskiy
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-06-
|
11
|
+
date: 2020-06-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -187,6 +187,7 @@ extra_rdoc_files: []
|
|
187
187
|
files:
|
188
188
|
- ".gitignore"
|
189
189
|
- ".idea/runConfigurations/hua_oceanconnect_adapter.xml"
|
190
|
+
- ".idea/runConfigurations/version.xml"
|
190
191
|
- ".ruby-gemset"
|
191
192
|
- ".ruby-version"
|
192
193
|
- ".travis.yml"
|