imperituroard 1.0.2 → 1.0.8
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 +176 -147
- data/lib/imperituroard/projects/iot/hua_oceanconnect_adapter.rb +96 -19
- data/lib/imperituroard/projects/iot/internal_functions.rb +8 -0
- data/lib/imperituroard/projects/iot/mongoconnector.rb +33 -18
- 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: 5e7e99efd1a73f476d513d802842f3f0433cd5be
|
4
|
+
data.tar.gz: 760abd30d5d6ea6419c0f4195c08b9dca3d73537
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6f8d0903a392cf44f300612e621ea34647cf5158c67dbd2f0fa75c7470e867e48a3d94b0676f666ed50ea6e9b40d6702467ac9a05ea9737831fe9cf024e8903f
|
7
|
+
data.tar.gz: 24741e66dc260aaef273175b302f840a89b4ffb7b25395e73bc1d087661f89cd54130e7c49076d4572c782a4a574adfff19c495f099ce1ac044c004d435c78dd
|
@@ -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,9 @@ 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"])
|
144
|
+
p model_data
|
145
|
+
p "model_data"
|
145
146
|
resss = hua_aceanconnect_connector.add_new_device_on_huawei(credentials[:body][:app_id],
|
146
147
|
credentials[:body][:secret],
|
147
148
|
aaa["imei"],
|
@@ -154,7 +155,6 @@ class IotFunctions_2
|
|
154
155
|
model_data[:body]["model"]
|
155
156
|
)
|
156
157
|
if resss[:code]=="200"
|
157
|
-
|
158
158
|
if resss[:body].key?("error_code") && resss[:body]["error_code"] != 200
|
159
159
|
not_processed_list.append({:imei => aaa["imei"], :error => resss})
|
160
160
|
else
|
@@ -163,15 +163,12 @@ class IotFunctions_2
|
|
163
163
|
s1[:created] = DateTime.now
|
164
164
|
added_on_iot_platf.append(s1)
|
165
165
|
end
|
166
|
-
|
167
166
|
else
|
168
167
|
not_processed_list.append({:imei => aaa["imei"], :error => resss})
|
169
168
|
end
|
170
169
|
rescue
|
171
170
|
not_processed_list.append({:imei => aaa["imei"], :error => "Unknown error with insertion imei on IOT platform"})
|
172
171
|
end
|
173
|
-
|
174
|
-
|
175
172
|
#########end iot platform logic#######
|
176
173
|
|
177
174
|
else
|
@@ -187,16 +184,12 @@ class IotFunctions_2
|
|
187
184
|
else
|
188
185
|
resp_out = {:code => 202, :result => "Empty list. Nothing for insertion", :body => {:imei_processed => added_on_iot_platf, :error_list => not_processed_list}}
|
189
186
|
end
|
190
|
-
|
191
|
-
|
192
187
|
else
|
193
188
|
resp_out = {:code => 202, :result => "Nothing for insertion", :body => {:imei_processed => added_on_iot_platf, :error_list => not_processed_list}}
|
194
|
-
|
195
189
|
end
|
196
190
|
rescue
|
197
191
|
resp_out = {:code => 505, :result => "Error with database communication"}
|
198
192
|
end
|
199
|
-
|
200
193
|
else
|
201
194
|
resp_out = {:code => 509, :result => "Input data invalid"}
|
202
195
|
end
|
@@ -206,9 +199,7 @@ class IotFunctions_2
|
|
206
199
|
end
|
207
200
|
thr1.join
|
208
201
|
|
209
|
-
|
210
202
|
resp_out[:body][:tosoapgw] = internal_func.iot_create_dev_soapgw_answer(input_json, resp_out)
|
211
|
-
|
212
203
|
mongo_client.audit_logger("add_device_to_profile", remote_ip, input_json, resp_out, real_ip)
|
213
204
|
resp_out
|
214
205
|
end
|
@@ -228,16 +219,16 @@ class IotFunctions_2
|
|
228
219
|
resp_out = {}
|
229
220
|
begin
|
230
221
|
thr2 = Thread.new do
|
231
|
-
if add_functions_connector.check_input_2(login, imei_list)[:code]==200
|
222
|
+
if add_functions_connector.check_input_2(login, imei_list)[:code] == 200
|
232
223
|
|
233
224
|
for t in imei_list
|
234
225
|
prof_name1 = mongo_client.get_profile_name_from_imei(t)
|
235
|
-
if prof_name1[:code]==200
|
226
|
+
if prof_name1[:code] == 200
|
236
227
|
begin
|
237
228
|
permiss1 = mongo_client.check_login_profile_permiss(login, prof_name1[:body]["profile"])
|
238
229
|
p "permiss1"
|
239
230
|
p permiss1
|
240
|
-
if permiss1[:code]==200
|
231
|
+
if permiss1[:code] == 200
|
241
232
|
ime_list_approved.append(t)
|
242
233
|
else
|
243
234
|
ime_list_notapproved.append({:imei => t, :error => permiss1})
|
@@ -467,12 +458,12 @@ class IotFunctions_2
|
|
467
458
|
begin
|
468
459
|
thr4 = Thread.new do
|
469
460
|
|
470
|
-
if add_functions_connector.check_input_4(login, imei)[:code]==200
|
461
|
+
if add_functions_connector.check_input_4(login, imei)[:code] == 200
|
471
462
|
|
472
463
|
prof_name = mongo_client.get_profile_name_from_imei(imei)
|
473
|
-
if prof_name[:code]==200
|
464
|
+
if prof_name[:code] == 200
|
474
465
|
permiss = mongo_client.check_login_profile_permiss(login, prof_name[:body]["profile"])
|
475
|
-
if permiss[:code]==200
|
466
|
+
if permiss[:code] == 200
|
476
467
|
|
477
468
|
##Logic for IOT Platform connection###
|
478
469
|
|
@@ -486,17 +477,17 @@ class IotFunctions_2
|
|
486
477
|
|
487
478
|
resp = {}
|
488
479
|
|
489
|
-
if credentials[:code]==200
|
480
|
+
if credentials[:code] == 200
|
490
481
|
|
491
482
|
imei_data = mongo_client.get_imei_info_from_db([imei])
|
492
|
-
if imei_data[:body]!=[]
|
483
|
+
if imei_data[:body] != []
|
493
484
|
ans = {}
|
494
485
|
if imei_data[:body][0]["huadata"]["body"]["deviceId"] != nil
|
495
486
|
ans = hua_aceanconnect_connector.remove_one_device_from_iot(credentials[:body][:app_id], credentials[:body][:secret], imei_data[:body][0]["huadata"]["body"]["deviceId"])
|
496
487
|
else
|
497
488
|
ans = {:code => "204", :result => "Not processed by iot platform. deviceId not found in mongoDB"}
|
498
489
|
end
|
499
|
-
if ans[:code]=="204" or ans[:code]=="200"
|
490
|
+
if ans[:code] == "204" or ans[:code] == "200"
|
500
491
|
resp = mongo_client.device_remove_single_mongo(imei)
|
501
492
|
else
|
502
493
|
resp = {:code => 500, :result => "Unknown IOT platform error", :body => ans}
|
@@ -580,10 +571,8 @@ class IotFunctions_2
|
|
580
571
|
imei_data = mongo_client.get_imei_info_from_db([p[:imei]])
|
581
572
|
if imei_data[:body]!=[]
|
582
573
|
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
574
|
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
575
|
end
|
586
|
-
|
587
576
|
end
|
588
577
|
|
589
578
|
#########end iot platform logic#######
|
@@ -658,7 +647,7 @@ class IotFunctions_2
|
|
658
647
|
if attr["profile"].is_a? Integer
|
659
648
|
p "Ok"
|
660
649
|
else
|
661
|
-
p new = mongo_client.
|
650
|
+
p new = mongo_client.get_profile_universal(attr["profile"])
|
662
651
|
attr["profile"] = new["profile_id"]
|
663
652
|
end
|
664
653
|
end
|
@@ -686,9 +675,7 @@ class IotFunctions_2
|
|
686
675
|
else
|
687
676
|
resp_out = {:code => 509, :result => "Input data invalid"}
|
688
677
|
end
|
689
|
-
|
690
678
|
end
|
691
|
-
|
692
679
|
rescue
|
693
680
|
resp_out = {:code => 507, :result => "Unknown SDK error"}
|
694
681
|
end
|
@@ -745,6 +732,7 @@ class IotFunctions_2
|
|
745
732
|
permit_profiles = login_info[:body]["permit_profiles"]
|
746
733
|
permit_types = login_info[:body]["permit_types"]
|
747
734
|
data_from_mongo = mongo_client.get_profile_list_by_id(permit_profiles)
|
735
|
+
p data_from_mongo
|
748
736
|
|
749
737
|
for ff in data_from_mongo
|
750
738
|
data_processed.append({:profile_id => ff["profile_id"],
|
@@ -849,33 +837,47 @@ class IotFunctions_2
|
|
849
837
|
data_processed = []
|
850
838
|
data_soapgw = []
|
851
839
|
login_info = mongo_client.get_login_inf2_select(login)
|
840
|
+
prof_data = mongo_client.get_profile_universal(profile)
|
852
841
|
if login_info[:code]==200
|
853
842
|
|
854
843
|
permit_profiles = login_info[:body]["permit_profiles"]
|
855
844
|
permit_types = login_info[:body]["permit_types"]
|
845
|
+
perm_tp_prof = prof_data["permit_types"]
|
846
|
+
|
847
|
+
if permit_profiles.include?(prof_data["profile_id"])
|
848
|
+
res_types_permitted = internal_func.compare_dict(permit_types, perm_tp_prof)
|
849
|
+
data_from_mongo = mongo_client.get_type_list_by_id(res_types_permitted)
|
850
|
+
|
851
|
+
for ff in data_from_mongo
|
852
|
+
data_processed.append({:type_id => ff["type_id"],
|
853
|
+
:description => ff["description"],
|
854
|
+
:note => ff["note"],
|
855
|
+
:form => ff["form"],
|
856
|
+
:ManufacturerID => ff["ManufacturerID"],
|
857
|
+
:ManufacturerNAME => ff["ManufacturerNAME"],
|
858
|
+
:device_type => ff["device_type"],
|
859
|
+
:model => ff["model"],
|
860
|
+
:info => ff["info"]
|
861
|
+
})
|
862
|
+
data_soapgw.append({:name => ff["model"], :form => ff["form"], :description => ff["description"], :type_id => ff["type_id"]})
|
863
|
+
end
|
856
864
|
|
857
|
-
|
865
|
+
tosoapgw = {:code => 200,
|
866
|
+
:result => "Request completed successfully",
|
867
|
+
:types => data_soapgw
|
868
|
+
}
|
858
869
|
|
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"]})
|
870
|
+
resp_out = {:code => 200, :result => "Request completed successfully", :body => {:data => data_processed, :tosoapgw => tosoapgw}}
|
871
|
+
|
872
|
+
else
|
873
|
+
tosoapgw = {:code => 700,
|
874
|
+
:result => "Profile not permitted",
|
875
|
+
:types => data_soapgw
|
876
|
+
}
|
877
|
+
resp_out = {:code => 700, :result => "Profile not permitted", :body => {:tosoapgw => tosoapgw}}
|
871
878
|
end
|
872
879
|
|
873
|
-
tosoapgw = {:code => 200,
|
874
|
-
:result => "Request completed successfully",
|
875
|
-
:types => data_soapgw
|
876
|
-
}
|
877
880
|
|
878
|
-
resp_out = {:code => 200, :result => "Request completed successfully", :body => {:data => data_processed, :tosoapgw => tosoapgw}}
|
879
881
|
else
|
880
882
|
tosoapgw = {:code => login_info[:code],
|
881
883
|
:result => login_info[:result],
|
@@ -939,6 +941,8 @@ class IotFunctions_2
|
|
939
941
|
mon_answer = mongo_client.get_profile_name_by_id(profile)
|
940
942
|
end
|
941
943
|
|
944
|
+
p mon_answer
|
945
|
+
|
942
946
|
if mon_answer != {} && mon_answer != []
|
943
947
|
output_answ = {:code => 200, :result => "Request completed successfully", :body => {:data => {:info => mon_answer["info"],
|
944
948
|
:profile => mon_answer["profile"],
|
@@ -952,7 +956,6 @@ class IotFunctions_2
|
|
952
956
|
end
|
953
957
|
mongo_client.audit_logger("get_info_data_profile_2", remote_ip, input_params, output_answ, real_ip)
|
954
958
|
output_answ
|
955
|
-
|
956
959
|
end
|
957
960
|
|
958
961
|
|
@@ -971,138 +974,164 @@ class IotFunctions_2
|
|
971
974
|
inp_login = soapgw_params["autorization"]["login"]
|
972
975
|
inp_dev_list = soapgw_params["datalist"]
|
973
976
|
|
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}
|
977
|
+
thr13set = Thread.new do
|
978
|
+
inp_dev_list.each do |curr_dev|
|
979
|
+
begin
|
980
|
+
if curr_dev["imei"] != [] && curr_dev["imei"] != nil && curr_dev["imei"] != ""
|
981
|
+
list_checked = mongo_client.check_imei_exists([curr_dev["imei"].to_i])
|
982
|
+
if list_checked[:code] == 200 && list_checked[:body][:exists] != [] && list_checked[:body][:not_exists] == []
|
983
|
+
|
984
|
+
#step1 checking permission for writing for imei list
|
985
|
+
prof_name1 = mongo_client.get_profile_name_from_imei(curr_dev["imei"].to_i)
|
986
|
+
p prof_name1
|
987
|
+
p "prof_name1"
|
988
|
+
if prof_name1[:code] == 200
|
989
|
+
|
990
|
+
if curr_dev["new_profile"] != "nil" && curr_dev["new_profile"] != "null" && curr_dev["new_profile"] != "empty" && curr_dev["new_profile"] != "nill"
|
991
|
+
prof_new_id = mongo_client.get_profile_universal(curr_dev["new_profile"])["profile_id"]
|
992
|
+
else
|
993
|
+
prof_new_id = prof_name1[:body]["profile_id"]
|
994
|
+
end
|
1039
995
|
|
1040
|
-
|
996
|
+
if curr_dev["new_type"] != "nil" && curr_dev["new_type"] != "null" && curr_dev["new_type"] != "empty" && curr_dev["new_type"] != "nill"
|
997
|
+
type_new_pr = curr_dev["new_type"]
|
998
|
+
else
|
999
|
+
type_new_pr = prof_name1[:imei_info][:body][0]["device_type"]
|
1000
|
+
end
|
1041
1001
|
|
1042
|
-
|
1043
|
-
|
1002
|
+
p type_new_pr
|
1003
|
+
p prof_new_id
|
1004
|
+
p "st111111"
|
1005
|
+
|
1006
|
+
get_login_info = mongo_client.check_login_prof_perm_id_one(inp_login, prof_name1[:body]["profile_id"])
|
1007
|
+
p get_login_info
|
1008
|
+
p "get_login_info"
|
1009
|
+
if get_login_info[:code] == 200
|
1010
|
+
get_login_info_new = mongo_client.check_login_prof_perm_id_one(inp_login, prof_new_id)
|
1011
|
+
p get_login_info_new
|
1012
|
+
p "get_login_info_new"
|
1013
|
+
if get_login_info_new[:code] == 200
|
1014
|
+
cur_comp1 = mongo_client.compare_profiles(prof_name1[:body]["profile_id"], prof_new_id)
|
1015
|
+
p cur_comp1
|
1016
|
+
p "cur_comp1"
|
1017
|
+
cur_comp2 = mongo_client.compare_device_types(prof_name1[:imei_info][:body][0]["device_type"], type_new_pr)
|
1018
|
+
|
1019
|
+
|
1020
|
+
p cur_comp2
|
1021
|
+
p "cur_comp2"
|
1022
|
+
|
1023
|
+
if cur_comp1[:is_the_same] && cur_comp2[:is_the_same]
|
1024
|
+
#the same. Nothing to do
|
1025
|
+
processed_list.append(curr_dev)
|
1026
|
+
########
|
1027
|
+
else
|
1028
|
+
credentials_old = mongo_client.get_iot_oceanconn_credent_2(prof_name1[:body]["profile"])
|
1029
|
+
credentials_new = mongo_client.get_iot_oceanconn_credent_2(prof_new_id)
|
1030
|
+
p credentials_new
|
1031
|
+
p "credentials_new"
|
1032
|
+
#########
|
1033
|
+
if credentials_old[:code] == 200 && credentials_new[:code] == 200
|
1034
|
+
imei_data = mongo_client.get_imei_info_from_db([curr_dev["imei"].to_i])
|
1035
|
+
p imei_data
|
1036
|
+
p "imei_data"
|
1037
|
+
if imei_data[:body] != []
|
1038
|
+
ans = {}
|
1039
|
+
if imei_data[:body][0]["huadata"]["body"]["deviceId"] != nil
|
1040
|
+
model_data = mongo_client.get_device_type_info_universal(type_new_pr)
|
1041
|
+
p model_data
|
1042
|
+
p "model_data"
|
1043
|
+
#####all checks completed. then process data#####
|
1044
|
+
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"])
|
1045
|
+
|
1046
|
+
|
1047
|
+
if ans_old[:code].to_i == 200 || ans_old[:code].to_i == 202 || ans_old[:code].to_i == 204
|
1048
|
+
begin
|
1049
|
+
resss = hua_aceanconnect_connector.add_new_device_on_huawei(credentials_new[:body][:app_id],
|
1050
|
+
credentials_new[:body][:secret],
|
1051
|
+
curr_dev["imei"].to_i,
|
1052
|
+
curr_dev["imei"].to_s,
|
1053
|
+
prof_name1[:body]["description"],
|
1054
|
+
model_data[:body]["device_type"],
|
1055
|
+
curr_dev["new_profile"],
|
1056
|
+
model_data[:body]["ManufacturerID"],
|
1057
|
+
model_data[:body]["ManufacturerNAME"],
|
1058
|
+
model_data[:body]["model"]
|
1059
|
+
)
|
1060
|
+
if resss[:code] == "200"
|
1061
|
+
if resss[:body].key?("error_code") && resss[:body]["error_code"] != 200
|
1062
|
+
not_processed_list.append({:imei => curr_dev["imei"], :error => resss})
|
1044
1063
|
else
|
1045
|
-
|
1064
|
+
p resss
|
1065
|
+
new_id_iot = resss[:body]
|
1066
|
+
new_profile_id = prof_new_id
|
1067
|
+
now_date = DateTime.now
|
1068
|
+
#finished success. update database
|
1069
|
+
attribute = {profile: new_profile_id, device_type: model_data[:body]["model"], huadata: resss, updated: now_date}
|
1070
|
+
answ_mongo = mongo_client.modify_attr_mongo_universal(curr_dev["imei"].to_i, attribute)
|
1071
|
+
if answ_mongo[:code] != 200
|
1072
|
+
not_processed_list.append({:imei => curr_dev["imei"], :error => "Critical error. Mongo not updated", :mongo_err => answ_mongo})
|
1073
|
+
else
|
1074
|
+
processed_list.append(curr_dev)
|
1075
|
+
end
|
1046
1076
|
end
|
1047
|
-
|
1048
|
-
|
1077
|
+
else
|
1078
|
+
not_processed_list.append({:imei => curr_dev["imei"], :error => resss})
|
1049
1079
|
end
|
1050
|
-
|
1051
|
-
|
1052
|
-
not_processed_list.append({:imei => curr_dev["imei"], :error => resss})
|
1080
|
+
rescue
|
1081
|
+
not_processed_list.append({:imei => curr_dev["imei"], :error => "Unknown error with insertion imei on IOT platform"})
|
1053
1082
|
end
|
1054
|
-
|
1055
|
-
not_processed_list.append({:imei => curr_dev["imei"], :error => "
|
1083
|
+
else
|
1084
|
+
not_processed_list.append({:imei => curr_dev["imei"], :error => "Something wrong with IOT platform"})
|
1056
1085
|
end
|
1086
|
+
else
|
1087
|
+
not_processed_list.append({:imei => curr_dev["imei"], :error => "Not processed by iot platform. deviceId not found in mongoDB"})
|
1057
1088
|
end
|
1058
1089
|
else
|
1059
|
-
not_processed_list.append({:imei => curr_dev["imei"], :error => "
|
1090
|
+
not_processed_list.append({:imei => curr_dev["imei"], :error => "Failed to get info from database"})
|
1060
1091
|
end
|
1061
1092
|
else
|
1062
|
-
not_processed_list.append({:imei => curr_dev["imei"], :error => "Failed to get
|
1093
|
+
not_processed_list.append({:imei => curr_dev["imei"], :error => "Failed to get credentials from database"})
|
1063
1094
|
end
|
1064
|
-
else
|
1065
|
-
not_processed_list.append({:imei => curr_dev["imei"], :error => "Failed to get credentials from database"})
|
1066
1095
|
end
|
1096
|
+
else
|
1097
|
+
not_processed_list.append({:imei => curr_dev["imei"], :error => "New profile modification not permitted"})
|
1067
1098
|
end
|
1068
1099
|
else
|
1069
|
-
not_processed_list.append({:imei => curr_dev["imei"], :error => "
|
1100
|
+
not_processed_list.append({:imei => curr_dev["imei"], :error => "Old profile modification not permitted"})
|
1070
1101
|
end
|
1071
1102
|
else
|
1072
|
-
not_processed_list.append({:imei => curr_dev["imei"], :error => "
|
1103
|
+
not_processed_list.append({:imei => curr_dev["imei"], :error => "Unknown current profile"})
|
1073
1104
|
end
|
1074
1105
|
else
|
1075
|
-
not_processed_list.append({:imei => curr_dev["imei"], :error => "
|
1106
|
+
not_processed_list.append({:imei => curr_dev["imei"], :error => "Device not exists"})
|
1076
1107
|
end
|
1077
1108
|
else
|
1078
|
-
not_processed_list.append({:imei => curr_dev["imei"], :error => "
|
1109
|
+
not_processed_list.append({:imei => curr_dev["imei"], :error => "IMEI can't be nil"})
|
1079
1110
|
end
|
1080
|
-
|
1081
|
-
not_processed_list.append({:imei => curr_dev["imei"], :error => "
|
1111
|
+
rescue
|
1112
|
+
not_processed_list.append({:imei => curr_dev["imei"], :error => "Unknown SDK error"})
|
1082
1113
|
end
|
1083
|
-
rescue
|
1084
|
-
not_processed_list.append({:imei => curr_dev["imei"], :error => "Unknown SDK error"})
|
1085
|
-
end
|
1086
1114
|
|
1087
|
-
|
1115
|
+
end
|
1088
1116
|
|
1089
|
-
|
1090
|
-
|
1091
|
-
|
1092
|
-
|
1117
|
+
err_li = []
|
1118
|
+
if not_processed_list.length > 0
|
1119
|
+
not_processed_list.each do |err_l|
|
1120
|
+
err_li.append({:failedimei => err_l[:imei]})
|
1121
|
+
end
|
1093
1122
|
end
|
1094
|
-
end
|
1095
1123
|
|
1096
|
-
|
1097
|
-
|
1098
|
-
|
1099
|
-
|
1124
|
+
if processed_list.length > 0
|
1125
|
+
answ_to_soapgw = {:code => 200, :result => "Success", :body => {:processednum => processed_list.length, :failednum => not_processed_list.length, :deviceserr => err_li}}
|
1126
|
+
else
|
1127
|
+
answ_to_soapgw = {:code => 202, :result => "Nothing done", :body => {:processednum => 0, :failednum => not_processed_list.length, :deviceserr => err_li}}
|
1128
|
+
end
|
1100
1129
|
end
|
1130
|
+
thr13set.join
|
1101
1131
|
|
1102
|
-
output_answ = {:code => 200, :result => "Success", :body => {:to_soap_gw =>
|
1132
|
+
output_answ = {:code => 200, :result => "Success", :body => {:to_soap_gw => answ_to_soapgw, :not_processed_list => not_processed_list, :processed_list => processed_list}}
|
1103
1133
|
mongo_client.audit_logger("set_data_replace_2", remote_ip, input_params, output_answ, real_ip)
|
1104
1134
|
output_answ
|
1105
|
-
|
1106
1135
|
end
|
1107
1136
|
|
1108
1137
|
|
@@ -54,6 +54,9 @@ class HuaIot
|
|
54
54
|
def get_token(app_id, secret)
|
55
55
|
internal_func.printer_texter("get_token: start. Step1, iput: app_id: #{app_id.to_s}, secret: #{secret.to_s}", "debug")
|
56
56
|
out_resp = {}
|
57
|
+
fff = {}
|
58
|
+
data = {}
|
59
|
+
url_string = ""
|
57
60
|
begin
|
58
61
|
path = "/iocm/app/sec/v1.1.0/login"
|
59
62
|
url_string = "https://" + platformip + ":" + platformport + path
|
@@ -73,15 +76,19 @@ class HuaIot
|
|
73
76
|
request.content_type = 'application/x-www-form-urlencoded'
|
74
77
|
request.body = URI.encode_www_form(data)
|
75
78
|
res = https.request(request)
|
79
|
+
p res.code
|
80
|
+
p res.message
|
81
|
+
p res.body.to_s
|
76
82
|
out_resp = {:code => res.code, :message => res.message, :body => JSON.parse(res.body.to_s)}
|
77
83
|
fff = {:func => "get_token",
|
78
84
|
:iot_fun => "",
|
79
|
-
:req_header => {:content_type => 'application/x-www-form-urlencoded'
|
85
|
+
:req_header => {:content_type => 'application/x-www-form-urlencoded',
|
86
|
+
:platform => "Huawei oceanconnect"
|
80
87
|
}}
|
81
|
-
client_iot_mongo.audit_iot_logger(fff, url_string, data, out_resp)
|
82
88
|
rescue
|
83
89
|
out_resp = {:code => 500, :message => "failed get token"}
|
84
90
|
end
|
91
|
+
client_iot_mongo.audit_iot_logger(fff, url_string, data, out_resp)
|
85
92
|
jjj = {:procedure => "get_token", :answ => out_resp}
|
86
93
|
internal_func.printer_texter(jjj, "debug")
|
87
94
|
out_resp
|
@@ -92,6 +99,9 @@ class HuaIot
|
|
92
99
|
|
93
100
|
internal_func.printer_texter("token_logout Step1 token: #{token}", "debug")
|
94
101
|
out_resp = {}
|
102
|
+
fff = {}
|
103
|
+
data = {}
|
104
|
+
url_string = ""
|
95
105
|
begin
|
96
106
|
path = "/iocm/app/sec/v1.1.0/logout"
|
97
107
|
url_string = "https://" + platformip + ":" + platformport + path
|
@@ -112,12 +122,17 @@ class HuaIot
|
|
112
122
|
res = https.request(request)
|
113
123
|
out_resp = {:code => res.code, :message => res.message, :body => JSON.parse(res.body.to_s)}
|
114
124
|
fff = {:func => "token_logout",
|
115
|
-
:iot_fun => "logout"
|
125
|
+
:iot_fun => "logout",
|
126
|
+
:platform => "Huawei oceanconnect"
|
116
127
|
}
|
117
|
-
|
128
|
+
p res.code
|
129
|
+
p res.message
|
130
|
+
p res.body.to_s
|
131
|
+
|
118
132
|
rescue
|
119
133
|
out_resp = {:code => 500, :message => "failed logout token"}
|
120
134
|
end
|
135
|
+
client_iot_mongo.audit_iot_logger(fff, url_string, data, out_resp)
|
121
136
|
jjj = {:procedure => "token_logout", :answ => out_resp}
|
122
137
|
internal_func.printer_texter(jjj, "debug")
|
123
138
|
out_resp
|
@@ -125,6 +140,7 @@ class HuaIot
|
|
125
140
|
|
126
141
|
#Registering a Directly Connected Device (Verification Code Mode) (V2)
|
127
142
|
def dev_register_verif_code_mode(app_id, secret, node_id)
|
143
|
+
out_resp = {}
|
128
144
|
token = get_token(app_id, secret)[:body]["accessToken"]
|
129
145
|
path = "/iocm/app/reg/v1.1.0/deviceCredentials?appId=" + app_id
|
130
146
|
url_string = "https://" + platformip + ":" + platformport + path
|
@@ -138,9 +154,17 @@ class HuaIot
|
|
138
154
|
request.content_type = 'application/json'
|
139
155
|
request['Authorization'] = 'Bearer ' + token
|
140
156
|
request['app_key'] = app_id
|
141
|
-
|
157
|
+
data = {nodeId: node_id}
|
158
|
+
request.body = data.to_json
|
142
159
|
res = https.request(request)
|
143
|
-
{:code => res.code, :message => res.message, :body => JSON.parse(res.body.to_s)}
|
160
|
+
out_resp = {:code => res.code, :message => res.message, :body => JSON.parse(res.body.to_s)}
|
161
|
+
fff = {:func => "dev_register_verif_code_mode",
|
162
|
+
:iot_fun => "Registering a Directly Connected Device (Verification Code Mode) (V2)",
|
163
|
+
:req_header => {:content_type => 'application/json',
|
164
|
+
:platform => "Huawei oceanconnect"
|
165
|
+
}}
|
166
|
+
client_iot_mongo.audit_iot_logger(fff, url_string, data, out_resp)
|
167
|
+
out_resp
|
144
168
|
end
|
145
169
|
|
146
170
|
#2.2.4 Registering a Directly Connected Device (Password Mode) (V2)
|
@@ -176,7 +200,8 @@ class HuaIot
|
|
176
200
|
:iot_fun => "2.2.4",
|
177
201
|
:req_header => {:authorization => 'Bearer ' + token,
|
178
202
|
:content_type => 'application/json',
|
179
|
-
:app_key => app_id
|
203
|
+
:app_key => app_id,
|
204
|
+
:platform => "Huawei oceanconnect"
|
180
205
|
}}
|
181
206
|
client_iot_mongo.audit_iot_logger(fff, url_string, data_out, out_resp)
|
182
207
|
out_resp
|
@@ -199,13 +224,21 @@ class HuaIot
|
|
199
224
|
request.content_type = 'application/json'
|
200
225
|
request['Authorization'] = 'Bearer ' + token
|
201
226
|
request['app_key'] = app_id
|
202
|
-
|
227
|
+
data = {deviceInfo: attr_list}
|
228
|
+
data_out = data.to_json
|
203
229
|
internal_func.printer_texter({:procedure => "dev_register_passw_code_mode2", :data => {:body => data_out, :url => url_string}}, "debug")
|
204
230
|
request.body = data_out
|
205
231
|
res = https.request(request)
|
206
232
|
p res.body.to_s
|
207
233
|
out_resp = {:code => res.code, :message => res.message, :body => JSON.parse(res.body.to_s)}
|
208
|
-
|
234
|
+
fff = {:func => "dev_reg_passw_code_mode2_2",
|
235
|
+
:iot_fun => "2.2.4",
|
236
|
+
:req_header => {:content_type => 'application/json',
|
237
|
+
:authorization => 'Bearer ' + token,
|
238
|
+
:app_key => app_id,
|
239
|
+
:platform => "Huawei oceanconnect"
|
240
|
+
}}
|
241
|
+
client_iot_mongo.audit_iot_logger(fff, url_string, data, out_resp)
|
209
242
|
out_resp
|
210
243
|
end
|
211
244
|
|
@@ -237,7 +270,8 @@ class HuaIot
|
|
237
270
|
:iot_fun => "2.2.12",
|
238
271
|
:req_header => {:authorization => 'Bearer ' + token,
|
239
272
|
:content_type => 'application/json',
|
240
|
-
:app_key => app_id
|
273
|
+
:app_key => app_id,
|
274
|
+
:platform => "Huawei oceanconnect"
|
241
275
|
}}
|
242
276
|
client_iot_mongo.audit_iot_logger(fff, url_string, "Delete", out_resp)
|
243
277
|
rescue
|
@@ -274,6 +308,7 @@ class HuaIot
|
|
274
308
|
|
275
309
|
#2.2.14 Querying Device Activation Status
|
276
310
|
def querying_device_activ_status(app_id, secret, device_id)
|
311
|
+
output_ans = {}
|
277
312
|
token = get_token(app_id, secret)[:body]["accessToken"]
|
278
313
|
path = "/iocm/app/reg/v1.1.0/devices/" + device_id + "?app_Id=" + app_id
|
279
314
|
url_string = "https://" + platformip + ":" + platformport + path
|
@@ -288,12 +323,22 @@ class HuaIot
|
|
288
323
|
request['Authorization'] = 'Bearer ' + token
|
289
324
|
request['app_key'] = app_id
|
290
325
|
res = https.request(request)
|
291
|
-
{:code => res.code, :message => res.message, :body => JSON.parse(res.body.to_s)}
|
326
|
+
output_ans = {:code => res.code, :message => res.message, :body => JSON.parse(res.body.to_s)}
|
327
|
+
fff = {:func => "querying_device_activ_status",
|
328
|
+
:iot_fun => "2.2.14",
|
329
|
+
:req_header => {:content_type => 'application/json',
|
330
|
+
:authorization => 'Bearer ' + token,
|
331
|
+
:app_key => app_id,
|
332
|
+
:platform => "Huawei oceanconnect"
|
333
|
+
}}
|
334
|
+
client_iot_mongo.audit_iot_logger(fff, url_string, data, output_ans)
|
335
|
+
output_ans
|
292
336
|
end
|
293
337
|
|
294
338
|
|
295
339
|
#2.9.1 Querying Information About a Device
|
296
340
|
def querying_device_info(app_id, secret, device_id)
|
341
|
+
out_resp = {}
|
297
342
|
token = get_token(app_id, secret)[:body]["accessToken"]
|
298
343
|
path = "/iocm/app/dm/v1.1.0/devices/" + device_id + "?app_Id=" + app_id
|
299
344
|
url_string = "https://" + platformip + ":" + platformport + path
|
@@ -308,7 +353,16 @@ class HuaIot
|
|
308
353
|
request['Authorization'] = 'Bearer ' + token
|
309
354
|
request['app_key'] = app_id
|
310
355
|
res = https.request(request)
|
311
|
-
{:code => res.code, :message => res.message, :body => JSON.parse(res.body.to_s)}
|
356
|
+
out_resp = {:code => res.code, :message => res.message, :body => JSON.parse(res.body.to_s)}
|
357
|
+
fff = {:func => "querying_device_info",
|
358
|
+
:iot_fun => "2.9.1",
|
359
|
+
:req_header => {:authorization => 'Bearer ' + token,
|
360
|
+
:content_type => 'application/json',
|
361
|
+
:app_key => app_id,
|
362
|
+
:platform => "Huawei oceanconnect"
|
363
|
+
}}
|
364
|
+
client_iot_mongo.audit_iot_logger(fff, url_string, "Get", out_resp)
|
365
|
+
out_resp
|
312
366
|
end
|
313
367
|
|
314
368
|
#2.9.6 Querying Directly Connected Devices and Their Mounted Devices in Batches
|
@@ -335,7 +389,8 @@ class HuaIot
|
|
335
389
|
:iot_fun => "2.9.6",
|
336
390
|
:req_header => {:authorization => 'Bearer ' + token,
|
337
391
|
:content_type => 'application/json',
|
338
|
-
:app_key => app_id
|
392
|
+
:app_key => app_id,
|
393
|
+
:platform => "Huawei oceanconnect"
|
339
394
|
}}
|
340
395
|
client_iot_mongo.audit_iot_logger(fff, url_string, req_body, output_str)
|
341
396
|
output_str
|
@@ -344,6 +399,7 @@ class HuaIot
|
|
344
399
|
|
345
400
|
#2.9.19 Querying the Complete Device Type List of All Device Capabilities
|
346
401
|
def querying_device_type_list(app_id, secret)
|
402
|
+
output_ans = {}
|
347
403
|
token = get_token(app_id, secret)[:body]["accessToken"]
|
348
404
|
path = "/iocm/app/profile/v1.1.0/allDeviceTypes"
|
349
405
|
url_string = "https://" + platformip + ":" + platformport + path
|
@@ -358,13 +414,24 @@ class HuaIot
|
|
358
414
|
request['Authorization'] = 'Bearer ' + token
|
359
415
|
request['app_key'] = app_id
|
360
416
|
res = https.request(request)
|
361
|
-
{:code => res.code, :message => res.message, :body => JSON.parse(res.body.to_s)}
|
417
|
+
output_ans = {:code => res.code, :message => res.message, :body => JSON.parse(res.body.to_s)}
|
418
|
+
|
419
|
+
fff = {:func => "querying_device_type_list",
|
420
|
+
:iot_fun => "2.9.19",
|
421
|
+
:req_header => {:content_type => 'application/json',
|
422
|
+
:authorization => 'Bearer ' + token,
|
423
|
+
:app_key => app_id,
|
424
|
+
:platform => "Huawei oceanconnect"
|
425
|
+
}}
|
426
|
+
client_iot_mongo.audit_iot_logger(fff, url_string, "Get", output_ans)
|
427
|
+
output_ans
|
428
|
+
|
362
429
|
end
|
363
430
|
|
364
431
|
|
365
432
|
#2.9.6 Querying Directly Connected Devices and Their Mounted Devices in Batches
|
366
433
|
def quer_dev_direct_conn_batches(app_id, dev_list, token)
|
367
|
-
|
434
|
+
output_ans = {}
|
368
435
|
path = "/iocm/app/dm/v1.1.0/queryDevicesByIds"
|
369
436
|
url_string = "https://" + platformip + ":" + platformport + path
|
370
437
|
p url_string
|
@@ -378,10 +445,19 @@ class HuaIot
|
|
378
445
|
request.content_type = 'application/json'
|
379
446
|
request['Authorization'] = 'Bearer ' + token
|
380
447
|
request['app_key'] = app_id
|
381
|
-
|
448
|
+
data = {deviceIds: dev_list}
|
449
|
+
request.body = data.to_json
|
382
450
|
res = https.request(request)
|
383
|
-
{:code => res.code, :message => res.message, :body => JSON.parse(res.body.to_s)}
|
384
|
-
|
451
|
+
output_ans = {:code => res.code, :message => res.message, :body => JSON.parse(res.body.to_s)}
|
452
|
+
fff = {:func => "quer_dev_direct_conn_batches",
|
453
|
+
:iot_fun => "2.9.6",
|
454
|
+
:req_header => {:content_type => 'application/json',
|
455
|
+
:authorization => 'Bearer ' + token,
|
456
|
+
:app_key => app_id,
|
457
|
+
:platform => "Huawei oceanconnect"
|
458
|
+
}}
|
459
|
+
client_iot_mongo.audit_iot_logger(fff, url_string, data, output_ans)
|
460
|
+
output_ans
|
385
461
|
end
|
386
462
|
|
387
463
|
|
@@ -417,7 +493,8 @@ class HuaIot
|
|
417
493
|
:iot_fun => "2.2.11",
|
418
494
|
:req_header => {:authorization => 'Bearer ' + token,
|
419
495
|
:content_type => 'application/json',
|
420
|
-
:app_key => app_id
|
496
|
+
:app_key => app_id,
|
497
|
+
:platform => "Huawei oceanconnect"
|
421
498
|
}}
|
422
499
|
client_iot_mongo.audit_iot_logger(fff, url_string, req_b, out_resp)
|
423
500
|
rescue
|
@@ -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
|
@@ -536,7 +540,7 @@ class MongoIot
|
|
536
540
|
result_ps.append(row)
|
537
541
|
}
|
538
542
|
dattaa = result_ps[0]
|
539
|
-
if dattaa!=nil
|
543
|
+
if dattaa != nil
|
540
544
|
out_resp = {:code => 200, :result => "get_device_type_info_by_model: Request completed successfully", :body => dattaa}
|
541
545
|
else
|
542
546
|
out_resp = {:code => 404, :result => "get_device_type_info_by_model: Device info not found", :body => {"model" => device_model, "ManufacturerID" => "unknown", "ManufacturerNAME" => "unknown", "device_type" => "unknown"}}
|
@@ -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
|
@@ -561,9 +566,9 @@ class MongoIot
|
|
561
566
|
}
|
562
567
|
dattaa = result_ps[0]
|
563
568
|
if dattaa!=nil
|
564
|
-
out_resp = {:code => 200, :result => "
|
569
|
+
out_resp = {:code => 200, :result => "get_device_type_info_universal: Request completed successfully", :body => dattaa}
|
565
570
|
else
|
566
|
-
out_resp = {:code => 404, :result => "
|
571
|
+
out_resp = {:code => 404, :result => "get_device_type_info_universal: Device info not found", :body => {"model" => device_model, "ManufacturerID" => "unknown", "ManufacturerNAME" => "unknown", "device_type" => "unknown"}}
|
567
572
|
end
|
568
573
|
else
|
569
574
|
result_ps2 = []
|
@@ -573,9 +578,9 @@ class MongoIot
|
|
573
578
|
}
|
574
579
|
dattaa = result_ps2[0]
|
575
580
|
if dattaa!=nil
|
576
|
-
out_resp = {:code => 200, :result => "
|
581
|
+
out_resp = {:code => 200, :result => "get_device_type_info_universal: Request completed successfully", :body => dattaa}
|
577
582
|
else
|
578
|
-
out_resp = {:code => 404, :result => "
|
583
|
+
out_resp = {:code => 404, :result => "get_device_type_info_universal: Device info not found", :body => {"model" => device_model, "ManufacturerID" => "unknown", "ManufacturerNAME" => "unknown", "device_type" => "unknown"}}
|
579
584
|
end
|
580
585
|
end
|
581
586
|
|
@@ -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.8
|
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-09 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"
|