imperituroard 1.0.3 → 1.0.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5264f8d3d00a73980d4de22a91b93c49ccd65904
4
- data.tar.gz: a165a821f4ea118ca20916f6ca512aa4d1f4b173
3
+ metadata.gz: 64ac99c5a41209df78fa5f319ec47a51cb28b05b
4
+ data.tar.gz: 004ea48aa310c5d3159ffa8f93b6451f6105fe0a
5
5
  SHA512:
6
- metadata.gz: e8d44ca288a3ebadc98ebd0ad7844e781c1ca3085c4df144113f9cd61a349915f71565daeeaa460437d4b6da545a40f7577c488bc7f4f6ca09230dafacc535b1
7
- data.tar.gz: 1161e315402988d67d08cb63d0c7660412a24d2826172e5d23c38f81d1fa876c84cfef2f56b83754a7f8ff3cbc1d45e2cdd1415b6cc96abb8c8a9a8a5c15739f
6
+ metadata.gz: 97de046b4032c0751a046c4e1f57cbaffafd63936e53bfa08bcca6dc7216b6a5f73dcf1a68715c9a0a21b4f4ff5e1c116b3fabe0f450a264962543e68b6055b3
7
+ data.tar.gz: 62ad29d69a43d0b0574c5249ac6777bc153a10472b9cce01298a80e27c8c956b6776aa86eef9d558d87acd1d260d5f7ca66428fa12ac8cfead71aab7fb0a7383
@@ -154,24 +154,21 @@ class IotFunctions_2
154
154
  model_data[:body]["model"]
155
155
  )
156
156
  if resss[:code]=="200"
157
-
158
157
  if resss[:body].key?("error_code") && resss[:body]["error_code"] != 200
159
158
  not_processed_list.append({:imei => aaa["imei"], :error => resss})
160
159
  else
161
160
  s1 = aaa
162
161
  s1[:huadata] = resss
163
162
  s1[:created] = DateTime.now
163
+ s1[:type] = s1["device_type"]
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
@@ -686,9 +679,7 @@ class IotFunctions_2
686
679
  else
687
680
  resp_out = {:code => 509, :result => "Input data invalid"}
688
681
  end
689
-
690
682
  end
691
-
692
683
  rescue
693
684
  resp_out = {:code => 507, :result => "Unknown SDK error"}
694
685
  end
@@ -971,136 +962,159 @@ class IotFunctions_2
971
962
  inp_login = soapgw_params["autorization"]["login"]
972
963
  inp_dev_list = soapgw_params["datalist"]
973
964
 
974
- inp_dev_list.each do |curr_dev|
975
- begin
976
- if curr_dev["imei"] != [] && curr_dev["imei"] != nil && curr_dev["imei"] != ""
977
- list_checked = mongo_client.check_imei_exists([curr_dev["imei"].to_i])
978
- if list_checked[:code] == 200 && list_checked[:body][:exists] != [] && list_checked[:body][:not_exists] == []
979
-
980
- #step1 checking permission for writing for imei list
981
- prof_name1 = mongo_client.get_profile_name_from_imei(curr_dev["imei"].to_i)
982
- if prof_name1[:code] == 200
983
-
984
- if curr_dev["new_profile"] != "nil" && curr_dev["new_profile"] != "null" && curr_dev["new_profile"] != "empty"
985
- prof_new_id = mongo_client.get_profile_universal(curr_dev["new_profile"])["profile_id"]
986
- else
987
- prof_new_id = prof_name1[:body]["profile_id"]
988
- end
989
-
990
-
991
- if curr_dev["new_type"] != "nil" && curr_dev["new_type"] != "null" && curr_dev["new_type"] != "empty"
992
- type_new_pr = curr_dev["new_type"]
993
- else
994
- type_new_pr = prof_name1[:imei_info][:body][0]["device_type"]
995
- end
996
-
965
+ thr13set = Thread.new do
966
+ inp_dev_list.each do |curr_dev|
967
+ begin
968
+ if curr_dev["imei"] != [] && curr_dev["imei"] != nil && curr_dev["imei"] != ""
969
+ list_checked = mongo_client.check_imei_exists([curr_dev["imei"].to_i])
970
+ if list_checked[:code] == 200 && list_checked[:body][:exists] != [] && list_checked[:body][:not_exists] == []
971
+
972
+ #step1 checking permission for writing for imei list
973
+ prof_name1 = mongo_client.get_profile_name_from_imei(curr_dev["imei"].to_i)
974
+ p prof_name1
975
+ p "prof_name1"
976
+ if prof_name1[:code] == 200
977
+
978
+ if curr_dev["new_profile"] != "nil" && curr_dev["new_profile"] != "null" && curr_dev["new_profile"] != "empty" && curr_dev["new_profile"] != "nill"
979
+ prof_new_id = mongo_client.get_profile_universal(curr_dev["new_profile"])["profile_id"]
980
+ else
981
+ prof_new_id = prof_name1[:body]["profile_id"]
982
+ end
997
983
 
998
- get_login_info = mongo_client.check_login_prof_perm_id_one(inp_login, prof_name1[:body]["profile_id"])
999
- if get_login_info[:code] == 200
1000
- get_login_info_new = mongo_client.check_login_prof_perm_id_one(inp_login, prof_new_id)
1001
- if get_login_info_new[:code] == 200
1002
- cur_comp1 = mongo_client.compare_profiles(prof_name1[:body]["profile_id"], prof_new_id)
1003
- cur_comp2 = mongo_client.compare_device_types(prof_name1[:imei_info][:body][0]["device_type"], type_new_pr)
984
+ if curr_dev["new_type"] != "nil" && curr_dev["new_type"] != "null" && curr_dev["new_type"] != "empty" && curr_dev["new_type"] != "nill"
985
+ type_new_pr = curr_dev["new_type"]
986
+ else
987
+ type_new_pr = prof_name1[:imei_info][:body][0]["device_type"]
988
+ end
1004
989
 
1005
- if cur_comp1[:is_the_same] && cur_comp2[:is_the_same]
1006
- #the same. Nothing to do
1007
- processed_list.append(curr_dev)
1008
- ########
1009
- else
1010
- credentials_old = mongo_client.get_iot_oceanconn_credent_2(prof_name1[:body]["profile"])
1011
- credentials_new = mongo_client.get_iot_oceanconn_credent_2(prof_new_id)
1012
- #########
1013
- if credentials_old[:code] == 200 && credentials_new[:code] == 200
1014
- imei_data = mongo_client.get_imei_info_from_db([curr_dev["imei"].to_i])
1015
- if imei_data[:body] != []
1016
- ans = {}
1017
- if imei_data[:body][0]["huadata"]["body"]["deviceId"] != nil
1018
- model_data = mongo_client.get_device_type_info_universal(type_new_pr)
1019
- #####all checks completed. then process data#####
1020
- 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"])
1021
-
1022
- if ans_old[:code].to_i == 200 || ans_old[:code].to_i == 202 || ans_old[:code].to_i == 204
1023
- begin
1024
- resss = hua_aceanconnect_connector.add_new_device_on_huawei(credentials_new[:body][:app_id],
1025
- credentials_new[:body][:secret],
1026
- curr_dev["imei"].to_i,
1027
- curr_dev["imei"].to_s,
1028
- prof_name1[:body]["description"],
1029
- model_data[:body]["device_type"],
1030
- curr_dev["new_profile"],
1031
- model_data[:body]["ManufacturerID"],
1032
- model_data[:body]["ManufacturerNAME"],
1033
- model_data[:body]["model"]
1034
- )
1035
- if resss[:code]=="200"
1036
- if resss[:body].key?("error_code") && resss[:body]["error_code"] != 200
1037
- not_processed_list.append({:imei => curr_dev["imei"], :error => resss})
1038
- else
1039
- new_id_iot = resss[:body]
1040
- new_profile_id = prof_new_id
1041
- now_date = DateTime.now
1042
- #finished success. update database
1043
- attribute = {profile: new_profile_id, device_type: model_data[:body]["model"], huadata: {body: new_id_iot}, updated: now_date}
1044
- answ_mongo = mongo_client.modify_attr_mongo_universal(curr_dev["imei"].to_i, attribute)
1045
- if answ_mongo[:code] != 200
1046
- not_processed_list.append({:imei => curr_dev["imei"], :error => "Critical error. Mongo not updated", :mongo_err => answ_mongo})
990
+ p type_new_pr
991
+ p prof_new_id
992
+ p "st111111"
993
+
994
+ get_login_info = mongo_client.check_login_prof_perm_id_one(inp_login, prof_name1[:body]["profile_id"])
995
+ p get_login_info
996
+ p "get_login_info"
997
+ if get_login_info[:code] == 200
998
+ get_login_info_new = mongo_client.check_login_prof_perm_id_one(inp_login, prof_new_id)
999
+ p get_login_info_new
1000
+ p "get_login_info_new"
1001
+ if get_login_info_new[:code] == 200
1002
+ cur_comp1 = mongo_client.compare_profiles(prof_name1[:body]["profile_id"], prof_new_id)
1003
+ p cur_comp1
1004
+ p "cur_comp1"
1005
+ cur_comp2 = mongo_client.compare_device_types(prof_name1[:imei_info][:body][0]["type"], type_new_pr)
1006
+
1007
+
1008
+ p cur_comp2
1009
+ p "cur_comp2"
1010
+
1011
+ if cur_comp1[:is_the_same] && cur_comp2[:is_the_same]
1012
+ #the same. Nothing to do
1013
+ processed_list.append(curr_dev)
1014
+ ########
1015
+ else
1016
+ credentials_old = mongo_client.get_iot_oceanconn_credent_2(prof_name1[:body]["profile"])
1017
+ credentials_new = mongo_client.get_iot_oceanconn_credent_2(prof_new_id)
1018
+ p credentials_new
1019
+ p "credentials_new"
1020
+ #########
1021
+ if credentials_old[:code] == 200 && credentials_new[:code] == 200
1022
+ imei_data = mongo_client.get_imei_info_from_db([curr_dev["imei"].to_i])
1023
+ p imei_data
1024
+ p "imei_data"
1025
+ if imei_data[:body] != []
1026
+ ans = {}
1027
+ if imei_data[:body][0]["huadata"]["body"]["deviceId"] != nil
1028
+ model_data = mongo_client.get_device_type_info_universal(type_new_pr)
1029
+ p model_data
1030
+ p "model_data"
1031
+ #####all checks completed. then process data#####
1032
+ 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"])
1033
+
1034
+
1035
+ if ans_old[:code].to_i == 200 || ans_old[:code].to_i == 202 || ans_old[:code].to_i == 204
1036
+ begin
1037
+ resss = hua_aceanconnect_connector.add_new_device_on_huawei(credentials_new[:body][:app_id],
1038
+ credentials_new[:body][:secret],
1039
+ curr_dev["imei"].to_i,
1040
+ curr_dev["imei"].to_s,
1041
+ prof_name1[:body]["description"],
1042
+ model_data[:body]["device_type"],
1043
+ curr_dev["new_profile"],
1044
+ model_data[:body]["ManufacturerID"],
1045
+ model_data[:body]["ManufacturerNAME"],
1046
+ model_data[:body]["model"]
1047
+ )
1048
+ if resss[:code] == "200"
1049
+ if resss[:body].key?("error_code") && resss[:body]["error_code"] != 200
1050
+ not_processed_list.append({:imei => curr_dev["imei"], :error => resss})
1047
1051
  else
1048
- processed_list.append(curr_dev)
1052
+ new_id_iot = resss[:body]
1053
+ new_profile_id = prof_new_id
1054
+ now_date = DateTime.now
1055
+ #finished success. update database
1056
+ attribute = {profile: new_profile_id, type: model_data[:body]["model"], huadata: {body: new_id_iot}, updated: now_date}
1057
+ answ_mongo = mongo_client.modify_attr_mongo_universal(curr_dev["imei"].to_i, attribute)
1058
+ if answ_mongo[:code] != 200
1059
+ not_processed_list.append({:imei => curr_dev["imei"], :error => "Critical error. Mongo not updated", :mongo_err => answ_mongo})
1060
+ else
1061
+ processed_list.append(curr_dev)
1062
+ end
1049
1063
  end
1050
- #added_on_iot_platf.append(s1)
1064
+ else
1065
+ not_processed_list.append({:imei => curr_dev["imei"], :error => resss})
1051
1066
  end
1052
- else
1053
- not_processed_list.append({:imei => curr_dev["imei"], :error => resss})
1067
+ rescue
1068
+ not_processed_list.append({:imei => curr_dev["imei"], :error => "Unknown error with insertion imei on IOT platform"})
1054
1069
  end
1055
- rescue
1056
- not_processed_list.append({:imei => curr_dev["imei"], :error => "Unknown error with insertion imei on IOT platform"})
1057
1070
  end
1071
+ else
1072
+ not_processed_list.append({:imei => curr_dev["imei"], :error => "Not processed by iot platform. deviceId not found in mongoDB"})
1058
1073
  end
1059
1074
  else
1060
- not_processed_list.append({:imei => curr_dev["imei"], :error => "Not processed by iot platform. deviceId not found in mongoDB"})
1075
+ not_processed_list.append({:imei => curr_dev["imei"], :error => "Failed to get info from database"})
1061
1076
  end
1062
1077
  else
1063
- not_processed_list.append({:imei => curr_dev["imei"], :error => "Failed to get info from database"})
1078
+ not_processed_list.append({:imei => curr_dev["imei"], :error => "Failed to get credentials from database"})
1064
1079
  end
1065
- else
1066
- not_processed_list.append({:imei => curr_dev["imei"], :error => "Failed to get credentials from database"})
1067
1080
  end
1081
+ else
1082
+ not_processed_list.append({:imei => curr_dev["imei"], :error => "New profile modification not permitted"})
1068
1083
  end
1069
1084
  else
1070
- not_processed_list.append({:imei => curr_dev["imei"], :error => "New profile modification not permitted"})
1085
+ not_processed_list.append({:imei => curr_dev["imei"], :error => "Old profile modification not permitted"})
1071
1086
  end
1072
1087
  else
1073
- not_processed_list.append({:imei => curr_dev["imei"], :error => "Old profile modification not permitted"})
1088
+ not_processed_list.append({:imei => curr_dev["imei"], :error => "Unknown current profile"})
1074
1089
  end
1075
1090
  else
1076
- not_processed_list.append({:imei => curr_dev["imei"], :error => "Unknown current profile"})
1091
+ not_processed_list.append({:imei => curr_dev["imei"], :error => "Device not exists"})
1077
1092
  end
1078
1093
  else
1079
- not_processed_list.append({:imei => curr_dev["imei"], :error => "Device not exists"})
1094
+ not_processed_list.append({:imei => curr_dev["imei"], :error => "IMEI can't be nil"})
1080
1095
  end
1081
- else
1082
- not_processed_list.append({:imei => curr_dev["imei"], :error => "IMEI can't be nil"})
1096
+ rescue
1097
+ not_processed_list.append({:imei => curr_dev["imei"], :error => "Unknown SDK error"})
1083
1098
  end
1084
- rescue
1085
- not_processed_list.append({:imei => curr_dev["imei"], :error => "Unknown SDK error"})
1086
- end
1087
1099
 
1088
- end
1100
+ end
1089
1101
 
1090
- err_li = []
1091
- if not_processed_list.length > 0
1092
- not_processed_list.each do |err_l|
1093
- err_li.append({:failedimei => err_l[:imei]})
1102
+ err_li = []
1103
+ if not_processed_list.length > 0
1104
+ not_processed_list.each do |err_l|
1105
+ err_li.append({:failedimei => err_l[:imei]})
1106
+ end
1094
1107
  end
1095
- end
1096
1108
 
1097
- if processed_list.length > 0
1098
- soap_answ = {:code=>200, :result=>"Success", :body=>{:processednum => processed_list.length, :failednum => not_processed_list.length, :deviceserr => err_li}}
1099
- else
1100
- soap_answ = {:code=>202, :result=>"Nothing done", :body=>{:processednum => 0, :failednum => not_processed_list.length, :deviceserr => err_li}}
1109
+ if processed_list.length > 0
1110
+ answ_to_soapgw = {:code => 200, :result => "Success", :body => {:processednum => processed_list.length, :failednum => not_processed_list.length, :deviceserr => err_li}}
1111
+ else
1112
+ answ_to_soapgw = {:code => 202, :result => "Nothing done", :body => {:processednum => 0, :failednum => not_processed_list.length, :deviceserr => err_li}}
1113
+ end
1101
1114
  end
1115
+ thr13set.join
1102
1116
 
1103
- output_answ = {:code => 200, :result => "Success", :body => {:to_soap_gw => soap_answ, :not_processed_list => not_processed_list, :processed_list => processed_list}}
1117
+ output_answ = {:code => 200, :result => "Success", :body => {:to_soap_gw => answ_to_soapgw, :not_processed_list => not_processed_list, :processed_list => processed_list}}
1104
1118
  mongo_client.audit_logger("set_data_replace_2", remote_ip, input_params, output_answ, real_ip)
1105
1119
  output_answ
1106
1120
  end
@@ -341,6 +341,7 @@ class MongoIot
341
341
  note: "second description",
342
342
  profile: 0,
343
343
  type: 0,
344
+ device_type: 0,
344
345
  address: "unknown"
345
346
  }
346
347
  result = collection.insert_one(l)
@@ -364,6 +365,7 @@ class MongoIot
364
365
  note: "second description",
365
366
  profile: 0,
366
367
  type: 0,
368
+ device_type: 0,
367
369
  address: "unknown"
368
370
  }
369
371
  result = collection.insert_one(l)
@@ -632,6 +634,9 @@ class MongoIot
632
634
  out_answ = {}
633
635
  tp1 = internal_func.if_digit_or_string(type1)
634
636
  tp2 = internal_func.if_digit_or_string(type2)
637
+ p tp1
638
+ p tp2
639
+ p "tp"
635
640
 
636
641
  if tp1[:body][:string] == tp2[:body][:string] && tp1[:body][:string] == false
637
642
  if type1.to_i == type2.to_i
@@ -648,6 +653,7 @@ class MongoIot
648
653
  else
649
654
  tp1_data = {}
650
655
  tp2_data = {}
656
+ p "gggggggg"
651
657
  if tp1[:body][:string]
652
658
  tp1_data = self.get_type_by_name(type1)
653
659
  else
@@ -660,6 +666,11 @@ class MongoIot
660
666
  tp2_data = self.get_type_by_id(type2.to_i)
661
667
  end
662
668
 
669
+ p tp1_data
670
+ p tp2_data
671
+ p type1
672
+ p type2
673
+
663
674
  if tp1_data["type_id"] == tp2_data["type_id"]
664
675
  out_answ = {:code => 200, :result => "compare_device_types: profiles are the same", :is_the_same => true, :data_type => "different"}
665
676
  else
@@ -1,4 +1,4 @@
1
1
  module Imperituroard
2
- VERSION = "1.0.3"
2
+ VERSION = "1.0.4"
3
3
  end
4
4
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: imperituroard
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.3
4
+ version: 1.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dzmitry Buynovskiy