iotagent-node-lib 2.15.1 → 2.19.0

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.
Files changed (448) hide show
  1. package/.github/workflows/ci.yml +17 -1
  2. package/.readthedocs.yml +7 -0
  3. package/CHANGES_NEXT_RELEASE +0 -1
  4. package/README.md +1 -0
  5. package/doc/Contribution.md +60 -1
  6. package/doc/advanced-topics.md +136 -14
  7. package/doc/api.md +38 -22
  8. package/doc/apiary/iotagent.apib +1 -3
  9. package/doc/architecture.md +2 -2
  10. package/doc/config-basic-example.js +0 -1
  11. package/doc/deprecated.md +2 -2
  12. package/doc/development.md +13 -6
  13. package/doc/expressionLanguage.md +519 -277
  14. package/doc/getting-started.md +0 -1
  15. package/doc/howto.md +13 -17
  16. package/doc/installationguide.md +67 -69
  17. package/doc/usermanual.md +48 -16
  18. package/docker/Mosquitto/Dockerfile +4 -9
  19. package/docker/Mosquitto/README.md +2 -0
  20. package/docker/Mosquitto/startMosquitto.sh +18 -1
  21. package/lib/command/commandLine.js +1 -1
  22. package/lib/commonConfig.js +5 -14
  23. package/lib/errors.js +0 -16
  24. package/lib/fiware-iotagent-lib.js +5 -0
  25. package/lib/jexlTranformsMap.js +71 -0
  26. package/lib/model/Command.js +1 -1
  27. package/lib/model/Device.js +5 -2
  28. package/lib/model/Group.js +20 -2
  29. package/lib/model/dbConn.js +7 -1
  30. package/lib/plugins/attributeAlias.js +6 -13
  31. package/lib/plugins/bidirectionalData.js +2 -27
  32. package/lib/plugins/expressionParser.js +41 -17
  33. package/lib/plugins/expressionPlugin.js +21 -27
  34. package/lib/plugins/jexlParser.js +71 -67
  35. package/lib/plugins/multiEntity.js +68 -147
  36. package/lib/plugins/pluginUtils.js +12 -48
  37. package/lib/plugins/timestampProcessPlugin.js +1 -46
  38. package/lib/request-shim.js +111 -0
  39. package/lib/services/common/domain.js +2 -2
  40. package/lib/services/common/genericMiddleware.js +6 -2
  41. package/lib/services/common/iotManagerService.js +1 -1
  42. package/lib/services/common/securityServiceKeystone.js +1 -1
  43. package/lib/services/common/securityServiceOAuth2.js +3 -2
  44. package/lib/services/devices/deviceRegistryMongoDB.js +29 -22
  45. package/lib/services/devices/deviceService.js +56 -33
  46. package/lib/services/devices/devices-NGSI-LD.js +42 -14
  47. package/lib/services/devices/devices-NGSI-mixed.js +3 -3
  48. package/lib/services/devices/devices-NGSI-v2.js +48 -24
  49. package/lib/services/devices/registrationUtils.js +1 -134
  50. package/lib/services/groups/groupRegistryMemory.js +2 -0
  51. package/lib/services/groups/groupRegistryMongoDB.js +58 -76
  52. package/lib/services/groups/groupService.js +1 -1
  53. package/lib/services/ngsi/entities-NGSI-LD.js +205 -124
  54. package/lib/services/ngsi/entities-NGSI-v2.js +142 -32
  55. package/lib/services/ngsi/ngsiService.js +4 -6
  56. package/lib/services/ngsi/ngsiUtils.js +0 -21
  57. package/lib/services/ngsi/subscription-NGSI-LD.js +14 -5
  58. package/lib/services/ngsi/subscriptionService.js +1 -4
  59. package/lib/services/northBound/contextServer-NGSI-LD.js +7 -2
  60. package/lib/services/northBound/contextServer-NGSI-v2.js +25 -13
  61. package/lib/services/northBound/contextServer.js +1 -4
  62. package/lib/services/northBound/contextServerUtils.js +0 -81
  63. package/lib/services/northBound/deviceProvisioningServer.js +36 -9
  64. package/lib/services/northBound/northboundServer.js +2 -0
  65. package/lib/services/northBound/restUtils.js +2 -39
  66. package/lib/templates/updateDevice.json +4 -0
  67. package/lib/templates/updateDeviceLax.json +4 -0
  68. package/package.json +13 -13
  69. package/test/tools/utils.js +2 -0
  70. package/test/unit/examples/deviceProvisioningRequests/provisionAnotherDevice.json +1 -1
  71. package/test/unit/examples/deviceProvisioningRequests/provisionDeviceMissingParameters.json +1 -1
  72. package/test/unit/examples/deviceProvisioningRequests/provisionDuplicatedDev.json +1 -1
  73. package/test/unit/examples/deviceProvisioningRequests/provisionFullDevice.json +1 -1
  74. package/test/unit/examples/deviceProvisioningRequests/provisionNewDeviceMalformed1.json +1 -1
  75. package/test/unit/examples/groupProvisioningRequests/multipleGroupsCreation.json +1 -1
  76. package/test/unit/examples/iotamRequests/registrationEmpty.json +1 -1
  77. package/test/unit/examples/iotamRequests/registrationWithGroups.json +2 -2
  78. package/test/unit/examples/iotamRequests/registrationWithGroupsWithoutCB.json +2 -2
  79. package/test/unit/examples/iotamRequests/registrationWithStaticGroups.json +2 -2
  80. package/test/unit/expressions/jexlExpression-test.js +119 -0
  81. package/test/unit/general/config-multi-core-test.js +1 -1
  82. package/test/unit/general/contextBrokerKeystoneSecurityAccess-test.js +30 -77
  83. package/test/unit/general/deviceService-test.js +19 -35
  84. package/test/unit/general/loglevel-api_test.js +8 -13
  85. package/test/unit/general/migration-test.js +1 -0
  86. package/test/unit/general/startup-test.js +3 -2
  87. package/test/unit/general/statistics-persistence_test.js +2 -2
  88. package/test/unit/general/statistics-service_test.js +2 -2
  89. package/test/unit/lazyAndCommands/commandRegistry_test.js +18 -18
  90. package/test/unit/memoryRegistry/deviceRegistryMemory_test.js +16 -24
  91. package/test/unit/mongodb/mongodb-connectionoptions-test.js +2 -2
  92. package/test/unit/mongodb/mongodb-group-registry-test.js +11 -11
  93. package/test/unit/mongodb/mongodb-registry-test.js +55 -131
  94. package/test/unit/ngsi-ld/examples/contextAvailabilityRequests/registerIoTAgent1.json +1 -1
  95. package/test/unit/ngsi-ld/examples/contextAvailabilityRequests/registerIoTAgent2.json +1 -1
  96. package/test/unit/ngsi-ld/examples/contextAvailabilityRequests/registerIoTAgent4.json +1 -1
  97. package/test/unit/ngsi-ld/examples/contextAvailabilityRequests/registerIoTAgentCommands.json +1 -1
  98. package/test/unit/ngsi-ld/examples/contextAvailabilityRequests/registerProvisionedDevice.json +1 -1
  99. package/test/unit/ngsi-ld/examples/contextAvailabilityRequests/registerProvisionedDevice2.json +1 -1
  100. package/test/unit/ngsi-ld/examples/contextAvailabilityRequests/registerProvisionedDeviceWithGroup.json +1 -1
  101. package/test/unit/ngsi-ld/examples/contextAvailabilityRequests/registerProvisionedDeviceWithGroup2.json +1 -1
  102. package/test/unit/ngsi-ld/examples/contextAvailabilityRequests/registerProvisionedDeviceWithGroup3.json +1 -1
  103. package/test/unit/ngsi-ld/examples/contextAvailabilityRequests/updateCommands1.json +1 -1
  104. package/test/unit/ngsi-ld/examples/contextAvailabilityRequests/updateIoTAgent1.json +1 -1
  105. package/test/unit/ngsi-ld/examples/contextAvailabilityRequests/updateIoTAgent2.json +1 -1
  106. package/test/unit/ngsi-ld/examples/contextAvailabilityRequests/updateIoTAgent3.json +1 -1
  107. package/test/unit/ngsi-ld/examples/contextRequests/createMinimumProvisionedDevice.json +0 -7
  108. package/test/unit/ngsi-ld/examples/contextRequests/createProvisionedDevice.json +0 -7
  109. package/test/unit/ngsi-ld/examples/contextRequests/createProvisionedDeviceMultientity.json +0 -7
  110. package/test/unit/ngsi-ld/examples/contextRequests/createProvisionedDeviceWithGroupAndStatic.json +0 -14
  111. package/test/unit/ngsi-ld/examples/contextRequests/createProvisionedDeviceWithGroupAndStatic2.json +0 -14
  112. package/test/unit/ngsi-ld/examples/contextRequests/createProvisionedDeviceWithGroupAndStatic3.json +1 -15
  113. package/test/unit/ngsi-ld/examples/contextRequests/createTimeInstantMinimumDevice.json +0 -7
  114. package/test/unit/ngsi-ld/examples/contextRequests/updateContextAliasPlugin6.json +0 -7
  115. package/test/unit/ngsi-ld/examples/contextRequests/updateContextAutocast5.json +0 -7
  116. package/test/unit/ngsi-ld/examples/contextRequests/updateContextExpressionPlugin12a.json +7 -0
  117. package/test/unit/ngsi-ld/examples/contextRequests/updateContextExpressionPlugin13.json +13 -13
  118. package/test/unit/ngsi-ld/examples/contextRequests/updateContextExpressionPlugin16.json +0 -7
  119. package/test/unit/ngsi-ld/examples/contextRequests/updateContextExpressionPlugin17.json +0 -7
  120. package/test/unit/ngsi-ld/examples/contextRequests/updateContextExpressionPlugin1a.json +18 -0
  121. package/test/unit/ngsi-ld/examples/contextRequests/updateContextExpressionPlugin29.json +18 -0
  122. package/test/unit/ngsi-ld/examples/contextRequests/updateContextExpressionPlugin31.json +15 -0
  123. package/test/unit/ngsi-ld/examples/contextRequests/updateContextExpressionPlugin32.json +17 -0
  124. package/test/unit/ngsi-ld/examples/contextRequests/updateContextExpressionPlugin33.json +18 -0
  125. package/test/unit/ngsi-ld/examples/contextRequests/updateContextExpressionPlugin34.json +17 -0
  126. package/test/unit/ngsi-ld/examples/contextRequests/updateContextExpressionPlugin4a.json +36 -0
  127. package/test/unit/ngsi-ld/examples/contextRequests/updateContextExpressionPlugin5.json +0 -7
  128. package/test/unit/ngsi-ld/examples/contextRequests/updateContextExpressionPlugin7.json +16 -16
  129. package/test/unit/ngsi-ld/examples/contextRequests/updateContextExpressionPlugin8a.json +18 -0
  130. package/test/unit/ngsi-ld/examples/contextRequests/updateContextGeoproperties3.json +0 -7
  131. package/test/unit/ngsi-ld/examples/contextRequests/updateContextMultientityPlugin15.json +25 -0
  132. package/test/unit/ngsi-ld/examples/contextRequests/updateContextMultientityTimestampPlugin1.json +6 -6
  133. package/test/unit/ngsi-ld/examples/contextRequests/updateContextMultientityTimestampPlugin2.json +3 -3
  134. package/test/unit/ngsi-ld/examples/contextRequests/updateProvisionActiveAttributes1.json +0 -7
  135. package/test/unit/ngsi-ld/examples/contextRequests/updateProvisionCommands1.json +0 -7
  136. package/test/unit/ngsi-ld/examples/contextRequests/updateProvisionDeviceStatic.json +0 -7
  137. package/test/unit/ngsi-ld/examples/contextRequests/updateProvisionMinimumDevice.json +0 -7
  138. package/test/unit/ngsi-ld/examples/subscriptionRequests/bidirectionalSubscriptionRequest.json +20 -17
  139. package/test/unit/ngsi-ld/examples/subscriptionRequests/simpleSubscriptionRequest.json +18 -15
  140. package/test/unit/ngsi-ld/examples/subscriptionRequests/simpleSubscriptionRequest2.json +18 -15
  141. package/test/unit/ngsi-ld/expressions/expressionBasedTransformations-test.js +21 -21
  142. package/test/unit/ngsi-ld/expressions/jexlBasedTransformations-test.js +1018 -0
  143. package/test/unit/ngsi-ld/general/config-jsonld-contexts-test.js +2 -2
  144. package/test/unit/ngsi-ld/general/contextBrokerOAuthSecurityAccess-test.js +24 -24
  145. package/test/unit/ngsi-ld/general/deviceService-test.js +7 -7
  146. package/test/unit/ngsi-ld/general/https-support-test.js +14 -13
  147. package/test/unit/ngsi-ld/general/iotam-autoregistration-test.js +8 -7
  148. package/test/unit/ngsi-ld/general/startup-test.js +2 -1
  149. package/test/unit/ngsi-ld/lazyAndCommands/active-devices-attribute-update-test.js +10 -8
  150. package/test/unit/ngsi-ld/lazyAndCommands/command-test.js +11 -12
  151. package/test/unit/ngsi-ld/lazyAndCommands/lazy-devices-test.js +25 -29
  152. package/test/unit/ngsi-ld/lazyAndCommands/polling-commands-test.js +16 -15
  153. package/test/unit/ngsi-ld/ngsiService/active-devices-test.js +18 -17
  154. package/test/unit/ngsi-ld/ngsiService/autocast-test.js +13 -12
  155. package/test/unit/ngsi-ld/ngsiService/geoproperties-test.js +10 -9
  156. package/test/unit/ngsi-ld/ngsiService/staticAttributes-test.js +3 -3
  157. package/test/unit/ngsi-ld/ngsiService/subscriptions-test.js +25 -24
  158. package/test/unit/ngsi-ld/plugins/alias-plugin_test.js +13 -12
  159. package/test/unit/ngsi-ld/plugins/bidirectional-plugin_test.js +27 -26
  160. package/test/unit/ngsi-ld/plugins/compress-timestamp-plugin_test.js +5 -5
  161. package/test/unit/ngsi-ld/plugins/event-plugin_test.js +3 -3
  162. package/test/unit/ngsi-ld/plugins/multientity-plugin_test.js +75 -14
  163. package/test/unit/ngsi-ld/plugins/timestamp-processing-plugin_test.js +3 -3
  164. package/test/unit/ngsi-ld/provisioning/device-provisioning-api_test.js +54 -53
  165. package/test/unit/ngsi-ld/provisioning/device-registration_test.js +20 -19
  166. package/test/unit/ngsi-ld/provisioning/device-update-registration_test.js +23 -22
  167. package/test/unit/ngsi-ld/provisioning/listProvisionedDevices-test.js +58 -70
  168. package/test/unit/ngsi-ld/provisioning/provisionDeviceMultientity-test.js +8 -7
  169. package/test/unit/ngsi-ld/provisioning/removeProvisionedDevice-test.js +19 -19
  170. package/test/unit/ngsi-ld/provisioning/singleConfigurationMode-test.js +18 -20
  171. package/test/unit/ngsi-ld/provisioning/updateProvisionedDevices-test.js +43 -49
  172. package/test/unit/ngsi-mixed/provisioning/ngsi-versioning-test.js +16 -14
  173. package/test/unit/ngsiv2/examples/contextAvailabilityRequests/registerIoTAgent1.json +1 -1
  174. package/test/unit/ngsiv2/examples/contextAvailabilityRequests/registerIoTAgent2.json +1 -1
  175. package/test/unit/ngsiv2/examples/contextAvailabilityRequests/registerIoTAgent3.json +19 -0
  176. package/test/unit/ngsiv2/examples/contextAvailabilityRequests/registerIoTAgent4.json +1 -1
  177. package/test/unit/ngsiv2/examples/contextAvailabilityRequests/registerIoTAgent5.json +19 -0
  178. package/test/unit/ngsiv2/examples/contextAvailabilityRequests/registerIoTAgentCommands.json +1 -1
  179. package/test/unit/ngsiv2/examples/contextAvailabilityRequests/registerProvisionedDevice.json +1 -1
  180. package/test/unit/ngsiv2/examples/contextAvailabilityRequests/registerProvisionedDevice2.json +1 -1
  181. package/test/unit/ngsiv2/examples/contextAvailabilityRequests/registerProvisionedDeviceWithGroup.json +1 -1
  182. package/test/unit/ngsiv2/examples/contextAvailabilityRequests/registerProvisionedDeviceWithGroup2.json +1 -1
  183. package/test/unit/ngsiv2/examples/contextAvailabilityRequests/registerProvisionedDeviceWithGroup3.json +1 -1
  184. package/test/unit/ngsiv2/examples/contextAvailabilityRequests/updateCommands1.json +3 -3
  185. package/test/unit/ngsiv2/examples/contextAvailabilityRequests/updateIoTAgent1.json +3 -3
  186. package/test/unit/ngsiv2/examples/contextAvailabilityRequests/updateIoTAgent2.json +1 -1
  187. package/test/unit/ngsiv2/examples/contextAvailabilityRequests/updateIoTAgent3.json +1 -1
  188. package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin1.json +17 -1
  189. package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin11.json +5 -1
  190. package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin12.json +2 -2
  191. package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin15.json +6 -0
  192. package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin16.json +14 -0
  193. package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin17.json +14 -0
  194. package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin18.json +6 -0
  195. package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin19.json +6 -0
  196. package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin2.json +13 -1
  197. package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin20.json +6 -0
  198. package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin21.json +6 -0
  199. package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin22.json +6 -0
  200. package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin23.json +6 -0
  201. package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin24.json +6 -0
  202. package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin25.json +6 -0
  203. package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin26.json +6 -0
  204. package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin27.json +6 -0
  205. package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin28.json +6 -0
  206. package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin29.json +22 -0
  207. package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin3.json +5 -1
  208. package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin30.json +6 -0
  209. package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin31.json +18 -0
  210. package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin32.json +16 -0
  211. package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin33.json +22 -0
  212. package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin34.json +12 -0
  213. package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin4.json +12 -0
  214. package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin5.json +5 -1
  215. package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin6.json +5 -1
  216. package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin7.json +5 -1
  217. package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin8.json +17 -1
  218. package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin9.json +5 -1
  219. package/test/unit/ngsiv2/examples/contextRequests/updateContextMiddleware1.json +10 -0
  220. package/test/unit/ngsiv2/examples/contextRequests/updateContextMiddleware2.json +10 -0
  221. package/test/unit/ngsiv2/examples/contextRequests/updateContextMultientityPlugin1.json +2 -2
  222. package/test/unit/ngsiv2/examples/contextRequests/updateContextMultientityPlugin10.json +1 -1
  223. package/test/unit/ngsiv2/examples/contextRequests/updateContextMultientityPlugin11.json +13 -0
  224. package/test/unit/ngsiv2/examples/contextRequests/updateContextMultientityPlugin12.json +33 -0
  225. package/test/unit/ngsiv2/examples/contextRequests/updateContextMultientityPlugin13.json +33 -0
  226. package/test/unit/ngsiv2/examples/contextRequests/updateContextMultientityPlugin14.json +33 -0
  227. package/test/unit/ngsiv2/examples/contextRequests/updateContextMultientityPlugin15.json +25 -0
  228. package/test/unit/ngsiv2/examples/contextRequests/updateContextMultientityPlugin16.json +25 -0
  229. package/test/unit/ngsiv2/examples/contextRequests/updateContextMultientityPlugin2.json +2 -2
  230. package/test/unit/ngsiv2/examples/contextRequests/updateContextMultientityPlugin3.json +1 -1
  231. package/test/unit/ngsiv2/examples/contextRequests/updateContextMultientityPlugin4.json +1 -1
  232. package/test/unit/ngsiv2/examples/contextRequests/updateContextMultientityPlugin5.json +1 -1
  233. package/test/unit/ngsiv2/examples/contextRequests/updateContextMultientityPlugin6.json +1 -1
  234. package/test/unit/ngsiv2/examples/contextRequests/updateContextMultientityPlugin7.json +1 -1
  235. package/test/unit/ngsiv2/examples/contextRequests/updateContextMultientityPlugin8.json +2 -2
  236. package/test/unit/ngsiv2/examples/contextRequests/updateContextMultientityPlugin9.json +1 -1
  237. package/test/unit/ngsiv2/examples/contextRequests/updateContextMultientityTimestampPlugin1.json +8 -8
  238. package/test/unit/ngsiv2/examples/contextRequests/updateContextMultientityTimestampPlugin2.json +4 -4
  239. package/test/unit/ngsiv2/examples/contextRequests/updateContextMultientityTimestampPlugin3.json +1 -1
  240. package/test/unit/ngsiv2/examples/contextRequests/updateContextMultientityTimestampPlugin4.json +2 -2
  241. package/test/unit/ngsiv2/examples/contextRequests/updateProvisionDevice.json +20 -0
  242. package/test/unit/ngsiv2/examples/subscriptionRequests/bidirectionalSubscriptionRequest.json +1 -1
  243. package/test/unit/ngsiv2/examples/subscriptionRequests/simpleSubscriptionRequest.json +1 -1
  244. package/test/unit/ngsiv2/examples/subscriptionRequests/simpleSubscriptionRequest2.json +1 -1
  245. package/test/unit/ngsiv2/expressions/expressionBasedTransformations-test.js +93 -60
  246. package/test/unit/ngsiv2/expressions/expressionCombinedTransformations-test.js +16 -16
  247. package/test/unit/ngsiv2/expressions/jexlBasedTransformations-test.js +548 -164
  248. package/test/unit/ngsiv2/general/contextBrokerOAuthSecurityAccess-test.js +34 -33
  249. package/test/unit/ngsiv2/general/deviceService-test.js +15 -14
  250. package/test/unit/ngsiv2/general/https-support-test.js +14 -13
  251. package/test/unit/ngsiv2/general/iotam-autoregistration-test.js +8 -7
  252. package/test/unit/ngsiv2/general/startup-test.js +2 -1
  253. package/test/unit/ngsiv2/lazyAndCommands/active-devices-attribute-update-test.js +9 -7
  254. package/test/unit/ngsiv2/lazyAndCommands/command-test.js +13 -12
  255. package/test/unit/ngsiv2/lazyAndCommands/lazy-devices-test.js +323 -51
  256. package/test/unit/ngsiv2/lazyAndCommands/polling-commands-test.js +22 -20
  257. package/test/unit/ngsiv2/ngsiService/active-devices-test.js +114 -26
  258. package/test/unit/ngsiv2/ngsiService/autocast-test.js +16 -16
  259. package/test/unit/ngsiv2/ngsiService/geoproperties-test.js +39 -38
  260. package/test/unit/{ngsiService → ngsiv2/ngsiService}/queryDeviceInformationInCb-test.js +25 -54
  261. package/test/unit/ngsiv2/ngsiService/staticAttributes-test.js +5 -5
  262. package/test/unit/ngsiv2/ngsiService/subscriptions-test.js +25 -24
  263. package/test/unit/ngsiv2/plugins/alias-plugin_test.js +22 -22
  264. package/test/unit/ngsiv2/plugins/bidirectional-plugin_test.js +27 -26
  265. package/test/unit/ngsiv2/plugins/compress-timestamp-plugin_test.js +7 -7
  266. package/test/unit/ngsiv2/plugins/event-plugin_test.js +4 -4
  267. package/test/unit/ngsiv2/plugins/multientity-plugin_test.js +549 -24
  268. package/test/unit/ngsiv2/plugins/timestamp-processing-plugin_test.js +4 -4
  269. package/test/unit/{plugins → ngsiv2/plugins}/translation-inPlugins_test.js +25 -25
  270. package/test/unit/{provisioning → ngsiv2/provisioning}/device-group-api-test.js +44 -75
  271. package/test/unit/{provisioning/device-group-utils_test.js → ngsiv2/provisioning/device-group-utils-test.js} +15 -14
  272. package/test/unit/ngsiv2/provisioning/device-provisioning-api_test.js +74 -73
  273. package/test/unit/ngsiv2/provisioning/device-registration_test.js +20 -19
  274. package/test/unit/ngsiv2/provisioning/device-update-registration_test.js +30 -29
  275. package/test/unit/ngsiv2/provisioning/listProvisionedDevices-test.js +58 -69
  276. package/test/unit/ngsiv2/provisioning/provisionDeviceMultientity-test.js +8 -7
  277. package/test/unit/ngsiv2/provisioning/removeProvisionedDevice-test.js +19 -19
  278. package/test/unit/ngsiv2/provisioning/singleConfigurationMode-test.js +18 -19
  279. package/test/unit/ngsiv2/provisioning/updateProvisionedDevices-test.js +49 -52
  280. package/test/unit/plugins/capture-configuration-inPlugins_test.js +6 -4
  281. package/test/unit/plugins/capture-provision-inPlugins_test.js +13 -23
  282. package/.nyc_output/016aca19-69bf-4681-9b41-2835c5131681.json +0 -1
  283. package/.nyc_output/processinfo/016aca19-69bf-4681-9b41-2835c5131681.json +0 -1
  284. package/.nyc_output/processinfo/index.json +0 -1
  285. package/lib/services/devices/devices-NGSI-v1.js +0 -293
  286. package/lib/services/devices/registrationUtils.js_avega +0 -589
  287. package/lib/services/ngsi/entities-NGSI-v1.js +0 -300
  288. package/lib/services/ngsi/subscription-NGSI-v1.js +0 -234
  289. package/lib/services/northBound/contextServer-NGSI-v1.js +0 -526
  290. package/lib/templates/notificationTemplateNgsi1.json +0 -75
  291. package/lib/templates/updateContextNgsi1.json +0 -50
  292. package/test/unit/examples/contextAvailabilityRequests/registerIoTAgent1.json +0 -21
  293. package/test/unit/examples/contextAvailabilityRequests/registerIoTAgent2.json +0 -21
  294. package/test/unit/examples/contextAvailabilityRequests/registerIoTAgent3.json +0 -25
  295. package/test/unit/examples/contextAvailabilityRequests/registerIoTAgent4.json +0 -22
  296. package/test/unit/examples/contextAvailabilityRequests/registerIoTAgentAttributeUpdates.json +0 -16
  297. package/test/unit/examples/contextAvailabilityRequests/registerIoTAgentCommands.json +0 -21
  298. package/test/unit/examples/contextAvailabilityRequests/registerNewDevice1.json +0 -21
  299. package/test/unit/examples/contextAvailabilityRequests/registerNewDevice2.json +0 -21
  300. package/test/unit/examples/contextAvailabilityRequests/registerProvisionedDevice.json +0 -25
  301. package/test/unit/examples/contextAvailabilityRequests/registerProvisionedDevice2.json +0 -21
  302. package/test/unit/examples/contextAvailabilityRequests/registerProvisionedDeviceWithGroup.json +0 -33
  303. package/test/unit/examples/contextAvailabilityRequests/registerProvisionedDeviceWithGroup2.json +0 -33
  304. package/test/unit/examples/contextAvailabilityRequests/unregisterDevice1.json +0 -22
  305. package/test/unit/examples/contextAvailabilityRequests/unregisterDevice3.json +0 -26
  306. package/test/unit/examples/contextAvailabilityRequests/unregisterProvisionedDevice.json +0 -26
  307. package/test/unit/examples/contextAvailabilityRequests/updateCommands1.json +0 -22
  308. package/test/unit/examples/contextAvailabilityRequests/updateIoTAgent1.json +0 -22
  309. package/test/unit/examples/contextAvailabilityRequests/updateIoTAgent2.json +0 -26
  310. package/test/unit/examples/contextAvailabilityRequests/updateIoTAgent3.json +0 -22
  311. package/test/unit/examples/contextAvailabilityResponses/registerIoTAgent1Failed.json +0 -8
  312. package/test/unit/examples/contextAvailabilityResponses/registerIoTAgent1Success.json +0 -4
  313. package/test/unit/examples/contextAvailabilityResponses/registerNewDevice1Success.json +0 -4
  314. package/test/unit/examples/contextAvailabilityResponses/registerNewDevice2Success.json +0 -4
  315. package/test/unit/examples/contextAvailabilityResponses/registerProvisionedDeviceSuccess.json +0 -4
  316. package/test/unit/examples/contextAvailabilityResponses/unregisterDevice1Failed.json +0 -8
  317. package/test/unit/examples/contextAvailabilityResponses/unregisterDevice1Success.json +0 -4
  318. package/test/unit/examples/contextAvailabilityResponses/updateCommands1Success.json +0 -4
  319. package/test/unit/examples/contextAvailabilityResponses/updateIoTAgent1Success.json +0 -6
  320. package/test/unit/examples/contextProviderResponses/queryInformationResponse.json +0 -22
  321. package/test/unit/examples/contextProviderResponses/queryInformationResponseEmptyAttributes.json +0 -22
  322. package/test/unit/examples/contextProviderResponses/queryInformationStaticAttributesResponse.json +0 -27
  323. package/test/unit/examples/contextProviderResponses/updateInformationResponse.json +0 -22
  324. package/test/unit/examples/contextProviderResponses/updateInformationResponse2.json +0 -22
  325. package/test/unit/examples/contextRequests/contextSubscriptionRequest.json +0 -20
  326. package/test/unit/examples/contextRequests/contextSubscriptionRequest2.json +0 -20
  327. package/test/unit/examples/contextRequests/createBidirectionalDevice.json +0 -17
  328. package/test/unit/examples/contextRequests/createDatetimeProvisionedDevice.json +0 -17
  329. package/test/unit/examples/contextRequests/createGeopointProvisionedDevice.json +0 -17
  330. package/test/unit/examples/contextRequests/createMinimumProvisionedDevice.json +0 -17
  331. package/test/unit/examples/contextRequests/createProvisionedDevice.json +0 -32
  332. package/test/unit/examples/contextRequests/createProvisionedDeviceMultientity.json +0 -32
  333. package/test/unit/examples/contextRequests/createProvisionedDeviceWithGroup.json +0 -47
  334. package/test/unit/examples/contextRequests/createProvisionedDeviceWithGroupAndStatic.json +0 -52
  335. package/test/unit/examples/contextRequests/createProvisionedDeviceWithGroupAndStatic2.json +0 -52
  336. package/test/unit/examples/contextRequests/createTimeinstantDevice.json +0 -17
  337. package/test/unit/examples/contextRequests/queryContext1.json +0 -13
  338. package/test/unit/examples/contextRequests/queryContext2.json +0 -13
  339. package/test/unit/examples/contextRequests/queryContextAliasPlugin1.json +0 -10
  340. package/test/unit/examples/contextRequests/queryContextCompressTimestamp1.json +0 -13
  341. package/test/unit/examples/contextRequests/updateActiveAttributes.json +0 -11
  342. package/test/unit/examples/contextRequests/updateContext1.json +0 -22
  343. package/test/unit/examples/contextRequests/updateContext2.json +0 -22
  344. package/test/unit/examples/contextRequests/updateContext3.json +0 -17
  345. package/test/unit/examples/contextRequests/updateContext3WithStatic.json +0 -22
  346. package/test/unit/examples/contextRequests/updateContext4.json +0 -22
  347. package/test/unit/examples/contextRequests/updateContext5.json +0 -19
  348. package/test/unit/examples/contextRequests/updateContextAliasPlugin.json +0 -22
  349. package/test/unit/examples/contextRequests/updateContextAliasPlugin2.json +0 -17
  350. package/test/unit/examples/contextRequests/updateContextAppendMode.json +0 -22
  351. package/test/unit/examples/contextRequests/updateContextCommandError.json +0 -22
  352. package/test/unit/examples/contextRequests/updateContextCommandExpired.json +0 -22
  353. package/test/unit/examples/contextRequests/updateContextCommandFinish.json +0 -22
  354. package/test/unit/examples/contextRequests/updateContextCommandStatus.json +0 -17
  355. package/test/unit/examples/contextRequests/updateContextCompressTimestamp1.json +0 -22
  356. package/test/unit/examples/contextRequests/updateContextCompressTimestamp2.json +0 -29
  357. package/test/unit/examples/contextRequests/updateContextExpressionPlugin1.json +0 -17
  358. package/test/unit/examples/contextRequests/updateContextExpressionPlugin2.json +0 -27
  359. package/test/unit/examples/contextRequests/updateContextExpressionPlugin3.json +0 -17
  360. package/test/unit/examples/contextRequests/updateContextExpressionPlugin4.json +0 -17
  361. package/test/unit/examples/contextRequests/updateContextExpressionPlugin5.json +0 -27
  362. package/test/unit/examples/contextRequests/updateContextMiddleware1.json +0 -22
  363. package/test/unit/examples/contextRequests/updateContextMultiEntityPlugin3.json +0 -35
  364. package/test/unit/examples/contextRequests/updateContextMultientityPlugin1.json +0 -30
  365. package/test/unit/examples/contextRequests/updateContextMultientityPlugin2.json +0 -30
  366. package/test/unit/examples/contextRequests/updateContextProcessTimestamp1.json +0 -29
  367. package/test/unit/examples/contextRequests/updateContextStaticAttributes.json +0 -22
  368. package/test/unit/examples/contextRequests/updateContextTimestamp.json +0 -41
  369. package/test/unit/examples/contextRequests/updateContextTimestampOverride.json +0 -22
  370. package/test/unit/examples/contextRequests/updateContextTimestampOverrideWithoutMilis.json +0 -22
  371. package/test/unit/examples/contextRequests/updateContextTimestampTimezone.json +0 -41
  372. package/test/unit/examples/contextRequests/updateProvisionActiveAttributes1.json +0 -17
  373. package/test/unit/examples/contextRequests/updateProvisionCommands1.json +0 -27
  374. package/test/unit/examples/contextRequests/updateProvisionDeviceStatic.json +0 -38
  375. package/test/unit/examples/contextRequests/updateProvisionMinimumDevice.json +0 -17
  376. package/test/unit/examples/contextResponses/contextSubscriptionRequest2Success.json +0 -7
  377. package/test/unit/examples/contextResponses/contextSubscriptionRequestSuccess.json +0 -7
  378. package/test/unit/examples/contextResponses/createBidirectionalDeviceSuccess.json +0 -22
  379. package/test/unit/examples/contextResponses/createDatetimeProvisionedDeviceSuccess.json +0 -22
  380. package/test/unit/examples/contextResponses/createGeopointProvisionedDeviceSuccess.json +0 -22
  381. package/test/unit/examples/contextResponses/createProvisionedDeviceSuccess.json +0 -22
  382. package/test/unit/examples/contextResponses/createTimeinstantSuccess.json +0 -22
  383. package/test/unit/examples/contextResponses/queryContext1Success.json +0 -27
  384. package/test/unit/examples/contextResponses/queryContext2Error.json +0 -7
  385. package/test/unit/examples/contextResponses/queryContext2UnknownError.json +0 -6
  386. package/test/unit/examples/contextResponses/queryContext3Error.json +0 -34
  387. package/test/unit/examples/contextResponses/queryContextAliasPlugin1Success.json +0 -27
  388. package/test/unit/examples/contextResponses/queryContextCompressTimestamp1Success.json +0 -27
  389. package/test/unit/examples/contextResponses/updateActiveAttributesSuccess.json +0 -16
  390. package/test/unit/examples/contextResponses/updateContext1Failed.json +0 -7
  391. package/test/unit/examples/contextResponses/updateContext1Success.json +0 -27
  392. package/test/unit/examples/contextResponses/updateContext2Failed.json +0 -35
  393. package/test/unit/examples/contextResponses/updateContextAliasPlugin2Success.json +0 -27
  394. package/test/unit/examples/contextResponses/updateContextAliasPluginSuccess.json +0 -27
  395. package/test/unit/examples/contextResponses/updateContextCommandFinishSuccess.json +0 -27
  396. package/test/unit/examples/contextResponses/updateContextCommandStatusSuccess.json +0 -22
  397. package/test/unit/examples/contextResponses/updateContextCompressTimestamp1Success.json +0 -27
  398. package/test/unit/examples/contextResponses/updateContextCompressTimestamp2Success.json +0 -34
  399. package/test/unit/examples/contextResponses/updateContextEvents1Success.json +0 -27
  400. package/test/unit/examples/contextResponses/updateContextExpressionPlugin1Success.json +0 -22
  401. package/test/unit/examples/contextResponses/updateContextExpressionPlugin2Success.json +0 -22
  402. package/test/unit/examples/contextResponses/updateContextExpressionPlugin3Success.json +0 -22
  403. package/test/unit/examples/contextResponses/updateContextExpressionPlugin5Success.json +0 -32
  404. package/test/unit/examples/contextResponses/updateContextMultientityPlugin1Success.json +0 -40
  405. package/test/unit/examples/contextResponses/updateContextMultientityPlugin2Success.json +0 -40
  406. package/test/unit/examples/contextResponses/updateContextMultientityPlugin3Success.json +0 -40
  407. package/test/unit/examples/contextResponses/updateContextProcessTimestamp1Success.json +0 -27
  408. package/test/unit/examples/contextResponses/updateProvisionActiveAttributes1Success.json +0 -22
  409. package/test/unit/examples/contextResponses/updateProvisionCommands1Success.json +0 -32
  410. package/test/unit/examples/contextResponses/updateProvisionMinimumDeviceSuccess.json +0 -22
  411. package/test/unit/examples/subscriptionRequests/bidirectionalNotification.json +0 -24
  412. package/test/unit/examples/subscriptionRequests/bidirectionalSubscriptionRemove.json +0 -3
  413. package/test/unit/examples/subscriptionRequests/bidirectionalSubscriptionRequest.json +0 -22
  414. package/test/unit/examples/subscriptionRequests/errorNotification.json +0 -24
  415. package/test/unit/examples/subscriptionRequests/simpleNotification.json +0 -24
  416. package/test/unit/examples/subscriptionRequests/simpleSubscriptionRemove.json +0 -3
  417. package/test/unit/examples/subscriptionRequests/simpleSubscriptionRequest.json +0 -19
  418. package/test/unit/examples/subscriptionRequests/simpleSubscriptionRequest1.json +0 -19
  419. package/test/unit/examples/subscriptionResponses/bidirectionalSubscriptionSuccess.json +0 -6
  420. package/test/unit/examples/subscriptionResponses/simpleSubscriptionSuccess.json +0 -6
  421. package/test/unit/expressions/expressionBasedTransformations-test.js +0 -328
  422. package/test/unit/expressions/expressionCombinedTransformations-test.js +0 -306
  423. package/test/unit/expressions/jexlBasedTransformations-test.js +0 -334
  424. package/test/unit/general/contextBrokerOAuthSecurityAccess-test.js +0 -902
  425. package/test/unit/general/https-support-test.js +0 -286
  426. package/test/unit/general/iotam-autoregistration-test.js +0 -368
  427. package/test/unit/lazyAndCommands/active-devices-attribute-update-test.js +0 -168
  428. package/test/unit/lazyAndCommands/command-test.js +0 -341
  429. package/test/unit/lazyAndCommands/lazy-devices-test.js +0 -878
  430. package/test/unit/lazyAndCommands/polling-commands-test.js +0 -421
  431. package/test/unit/ngsi-ld/examples/contextRequests/updateContextExpressionPlugin20.json +0 -25
  432. package/test/unit/ngsiService/active-devices-test.js +0 -692
  433. package/test/unit/ngsiService/staticAttributes-test.js +0 -148
  434. package/test/unit/ngsiService/subscriptions-test.js +0 -345
  435. package/test/unit/plugins/alias-plugin_test.js +0 -158
  436. package/test/unit/plugins/bidirectional-plugin_test.js +0 -564
  437. package/test/unit/plugins/compress-timestamp-plugin_test.js +0 -257
  438. package/test/unit/plugins/event-plugin_test.js +0 -119
  439. package/test/unit/plugins/multientity-plugin_test.js +0 -248
  440. package/test/unit/plugins/timestamp-processing-plugin_test.js +0 -119
  441. package/test/unit/provisioning/device-provisioning-api_test.js +0 -748
  442. package/test/unit/provisioning/device-registration_test.js +0 -432
  443. package/test/unit/provisioning/device-update-registration_test.js +0 -326
  444. package/test/unit/provisioning/listProvisionedDevices-test.js +0 -488
  445. package/test/unit/provisioning/provisionDeviceMultientity-test.js +0 -123
  446. package/test/unit/provisioning/removeProvisionedDevice-test.js +0 -244
  447. package/test/unit/provisioning/singleConfigurationMode-test.js +0 -346
  448. package/test/unit/provisioning/updateProvisionedDevices-test.js +0 -436
@@ -1,526 +0,0 @@
1
- /*
2
- * Copyright 2020 Telefonica Investigación y Desarrollo, S.A.U
3
- *
4
- * This file is part of fiware-iotagent-lib
5
- *
6
- * fiware-iotagent-lib is free software: you can redistribute it and/or
7
- * modify it under the terms of the GNU Affero General Public License as
8
- * published by the Free Software Foundation, either version 3 of the License,
9
- * or (at your option) any later version.
10
- *
11
- * fiware-iotagent-lib is distributed in the hope that it will be useful,
12
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14
- * See the GNU Affero General Public License for more details.
15
- *
16
- * You should have received a copy of the GNU Affero General Public
17
- * License along with fiware-iotagent-lib.
18
- * If not, see http://www.gnu.org/licenses/.
19
- *
20
- * For those usages not covered by the GNU Affero General Public License
21
- * please contact with::daniel.moranjimenez@telefonica.com
22
- *
23
- * Modified by: Daniel Calvo - ATOS Research & Innovation
24
- * Modified by: Jason Fox - FIWARE Foundation
25
- */
26
-
27
- /* eslint-disable no-useless-escape */
28
- /* eslint-disable no-unused-vars */
29
- /* eslint-disable no-prototype-builtins */
30
- /* eslint-disable consistent-return */
31
-
32
- const async = require('async');
33
- const apply = async.apply;
34
- const logger = require('logops');
35
- const errors = require('../../errors');
36
- const deviceService = require('../devices/deviceService');
37
- const middlewares = require('../common/genericMiddleware');
38
- const _ = require('underscore');
39
- const context = {
40
- op: 'IoTAgentNGSI.ContextServer-v1'
41
- };
42
- const updateContextTemplateNgsi1 = require('../../templates/updateContextNgsi1.json');
43
- const queryContextTemplate = require('../../templates/queryContext.json');
44
- const notificationTemplateNgsi1 = require('../../templates/notificationTemplateNgsi1.json');
45
- const contextServerUtils = require('./contextServerUtils');
46
-
47
- const updatePaths = ['/v1/updateContext', '/NGSI10/updateContext', '//updateContext'];
48
- const queryPaths = ['/v1/queryContext', '/NGSI10/queryContext', '//queryContext'];
49
- /**
50
- * Generate all the update actions corresponding to a update context request using Ngsi1.
51
- * Update actions include updates in attributes and execution of commands. This action will
52
- * be called once per Context Element in the request.
53
- *
54
- * @param {Object} req Update request to generate Actions from
55
- * @param {Object} contextElement Context Element whose actions will be extracted.
56
- */
57
- function generateUpdateActionsNgsi1(req, contextElement, callback) {
58
- function splitUpdates(device, callback) {
59
- let attributes = [];
60
- const commands = [];
61
- let found;
62
-
63
- if (device.commands) {
64
- attributeLoop: for (const i in contextElement.attributes) {
65
- for (const j in device.commands) {
66
- if (contextElement.attributes[i].name === device.commands[j].name) {
67
- commands.push(contextElement.attributes[i]);
68
- found = true;
69
- continue attributeLoop;
70
- }
71
- }
72
-
73
- attributes.push(contextElement.attributes[i]);
74
- }
75
- } else {
76
- attributes = contextElement.attributes;
77
- }
78
-
79
- callback(null, attributes, commands, device);
80
- }
81
-
82
- function createActionsArray(attributes, commands, device, callback) {
83
- const updateActions = [];
84
-
85
- if (contextServerUtils.updateHandler) {
86
- updateActions.push(
87
- async.apply(
88
- contextServerUtils.updateHandler,
89
- contextElement.id,
90
- contextElement.type,
91
- req.headers['fiware-service'],
92
- req.headers['fiware-servicepath'],
93
- attributes
94
- )
95
- );
96
- }
97
-
98
- if (contextServerUtils.commandHandler) {
99
- if (device.polling) {
100
- updateActions.push(
101
- async.apply(
102
- contextServerUtils.pushCommandsToQueue,
103
- device,
104
- contextElement.id,
105
- contextElement.type,
106
- req.headers['fiware-service'],
107
- req.headers['fiware-servicepath'],
108
- contextElement.attributes
109
- )
110
- );
111
- } else {
112
- updateActions.push(
113
- async.apply(
114
- contextServerUtils.commandHandler,
115
- contextElement.id,
116
- contextElement.type,
117
- req.headers['fiware-service'],
118
- req.headers['fiware-servicepath'],
119
- commands
120
- )
121
- );
122
- }
123
- }
124
-
125
- updateActions.push(
126
- async.apply(
127
- contextServerUtils.executeUpdateSideEffects,
128
- device,
129
- contextElement.id,
130
- contextElement.type,
131
- req.headers['fiware-service'],
132
- req.headers['fiware-servicepath'],
133
- contextElement.attributes
134
- )
135
- );
136
-
137
- callback(null, updateActions);
138
- }
139
-
140
- deviceService.getDeviceByName(
141
- contextElement.id,
142
- req.headers['fiware-service'],
143
- req.headers['fiware-servicepath'],
144
- function (error, deviceObj) {
145
- if (error) {
146
- callback(error);
147
- } else {
148
- async.waterfall(
149
- [
150
- apply(deviceService.findConfigurationGroup, deviceObj),
151
- apply(
152
- deviceService.mergeDeviceWithConfiguration,
153
- ['lazy', 'internalAttributes', 'active', 'staticAttributes', 'commands', 'subscriptions'],
154
- [null, null, [], [], [], [], []],
155
- deviceObj
156
- ),
157
- splitUpdates,
158
- createActionsArray
159
- ],
160
- callback
161
- );
162
- }
163
- }
164
- );
165
- }
166
-
167
- /**
168
- * Express middleware to manage incoming UpdateContext requests using NGSIv1.
169
- * As NGSI10 requests can affect multiple entities, for each one of them a call
170
- * to the user update handler function is made.
171
- */
172
- function handleUpdateNgsi1(req, res, next) {
173
- function reduceActions(actions, callback) {
174
- callback(null, _.flatten(actions));
175
- }
176
-
177
- if (contextServerUtils.updateHandler || contextServerUtils.commandHandler) {
178
- logger.debug(context, 'Handling v1 update from [%s]', req.get('host'));
179
- if (req.body) {
180
- logger.debug(context, JSON.stringify(req.body, null, 4));
181
- }
182
-
183
- async.waterfall(
184
- [
185
- apply(async.map, req.body.contextElements, apply(generateUpdateActionsNgsi1, req)),
186
- reduceActions,
187
- async.series
188
- ],
189
- function (error, result) {
190
- if (error) {
191
- logger.debug(context, 'There was an error handling the update action: %s.', error);
192
-
193
- next(error);
194
- } else {
195
- logger.debug(context, 'Update action from [%s] handled successfully.', req.get('host'));
196
- res.status(200).json(contextServerUtils.createUpdateResponse(req, res, result));
197
- }
198
- }
199
- );
200
- } else {
201
- logger.error(context, 'Tried to handle an update request before the update handler was stablished.');
202
-
203
- const errorNotFound = new Error({
204
- message: 'Update handler not found'
205
- });
206
- next(errorNotFound);
207
- }
208
- }
209
-
210
- /**
211
- * Handle queries coming to the IoT Agent via de Context Provider API (as a consequence of a query to a passive
212
- * attribute redirected by the Context Broker).
213
- *
214
- * @param {String} id Entity name of the selected entity in the query.
215
- * @param {String} type Type of the entity.
216
- * @param {String} service Service the device belongs to.
217
- * @param {String} subservice Division inside the service.
218
- * @param {Array} attributes List of attributes to read.
219
- */
220
- function defaultQueryHandlerNgsi1(id, type, service, subservice, attributes, callback) {
221
- const contextElement = {
222
- type,
223
- isPattern: false,
224
- id,
225
- attributes: []
226
- };
227
-
228
- deviceService.getDeviceByName(id, service, subservice, function (error, ngsiDevice) {
229
- if (error) {
230
- callback(error);
231
- } else {
232
- for (let i = 0; i < attributes.length; i++) {
233
- const lazyAttribute = _.findWhere(ngsiDevice.lazy, { name: attributes[i] });
234
- const command = _.findWhere(ngsiDevice.commands, { name: attributes[i] });
235
- let attributeType = 'string';
236
-
237
- if (command) {
238
- attributeType = command.type;
239
- } else if (lazyAttribute) {
240
- attributeType = lazyAttribute.type;
241
- }
242
-
243
- contextElement.attributes.push({
244
- name: attributes[i],
245
- type: attributeType,
246
- value: ''
247
- });
248
- }
249
-
250
- callback(null, contextElement);
251
- }
252
- });
253
- }
254
-
255
- /**
256
- * Express middleware to manage incoming QueryContext requests using NGSIv1.
257
- * As NGSI10 requests can affect multiple entities, for each one of them a call
258
- * to the user query handler function is made.
259
- */
260
- function handleQueryNgsi1(req, res, next) {
261
- function getName(element) {
262
- return element.name;
263
- }
264
-
265
- function addStaticAttributes(attributes, device, contextElement, callback) {
266
- function inAttributes(item) {
267
- return item.name && attributes.indexOf(item.name) >= 0;
268
- }
269
-
270
- if (device.staticAttributes) {
271
- const selectedAttributes = device.staticAttributes.filter(inAttributes);
272
-
273
- if (selectedAttributes.length > 0) {
274
- if (contextElement.attributes) {
275
- contextElement.attributes = contextElement.attributes.concat(selectedAttributes);
276
- } else {
277
- contextElement.attributes = selectedAttributes;
278
- }
279
- }
280
- }
281
-
282
- callback(null, contextElement);
283
- }
284
-
285
- function completeAttributes(attributes, device, callback) {
286
- if (attributes && attributes.length !== 0) {
287
- logger.debug(context, 'Handling received set of attributes: %j', attributes);
288
- callback(null, attributes);
289
- } else if (device.lazy) {
290
- logger.debug(context, 'Handling stored set of attributes: %j', attributes);
291
- callback(null, device.lazy.map(getName));
292
- } else {
293
- logger.debug(context, "Couldn't find any attributes. Handling with null reference");
294
- callback(null, null);
295
- }
296
- }
297
-
298
- function createQueryRequests(attributes, contextEntity, callback) {
299
- let actualHandler;
300
-
301
- if (contextServerUtils.queryHandler) {
302
- actualHandler = contextServerUtils.queryHandler;
303
- } else {
304
- actualHandler = defaultQueryHandlerNgsi1;
305
- }
306
-
307
- async.waterfall(
308
- [
309
- apply(
310
- deviceService.getDeviceByName,
311
- contextEntity.id,
312
- req.headers['fiware-service'],
313
- req.headers['fiware-servicepath']
314
- ),
315
- deviceService.findConfigurationGroup
316
- ],
317
- function handleFindDevice(error, device) {
318
- const executeCompleteAttributes = apply(completeAttributes, attributes, device);
319
- const executeQueryHandler = apply(
320
- actualHandler,
321
- contextEntity.id,
322
- contextEntity.type,
323
- req.headers['fiware-service'],
324
- req.headers['fiware-servicepath']
325
- );
326
- const executeAddStaticAttributes = apply(addStaticAttributes, attributes, device);
327
-
328
- callback(
329
- error,
330
- apply(async.waterfall, [executeCompleteAttributes, executeQueryHandler, executeAddStaticAttributes])
331
- );
332
- }
333
- );
334
- }
335
-
336
- function handleQueryContextRequests(error, result) {
337
- if (error) {
338
- logger.debug(context, 'There was an error handling the query: %s.', error);
339
- next(error);
340
- } else {
341
- logger.debug(context, 'Query from [%s] handled successfully.', req.get('host'));
342
- res.status(200).json(contextServerUtils.createQueryResponse(req, res, result));
343
- }
344
- }
345
-
346
- logger.debug(context, 'Handling query from [%s]', req.get('host'));
347
- if (req.body) {
348
- logger.debug(context, JSON.stringify(req.body, null, 4));
349
- }
350
-
351
- async.waterfall(
352
- [apply(async.map, req.body.entities, apply(createQueryRequests, req.body.attributes)), async.series],
353
- handleQueryContextRequests
354
- );
355
- }
356
-
357
- /**
358
- * Express middleware to manage incoming notification requests using NGSIv1.
359
- *
360
- * @param {Object} req Request that was handled in first place.
361
- * @param {Object} res Response that will be sent.
362
- */
363
- function handleNotificationNgsi1(req, res, next) {
364
- function checkStatus(statusCode, callback) {
365
- if (statusCode.code && statusCode.code === '200') {
366
- callback();
367
- } else {
368
- callback(new errors.NotificationError(statusCode.code));
369
- }
370
- }
371
-
372
- function extractInformation(contextResponse, callback) {
373
- deviceService.getDeviceByName(
374
- contextResponse.contextElement.id,
375
- req.headers['fiware-service'],
376
- req.headers['fiware-servicepath'],
377
- function (error, device) {
378
- if (error) {
379
- callback(error);
380
- } else {
381
- callback(null, device, contextResponse.contextElement.attributes);
382
- }
383
- }
384
- );
385
- }
386
-
387
- function applyNotificationMiddlewares(device, values, callback) {
388
- if (contextServerUtils.notificationMiddlewares.length > 0) {
389
- const firstMiddleware = contextServerUtils.notificationMiddlewares.slice(0, 1)[0];
390
- const rest = contextServerUtils.notificationMiddlewares.slice(1);
391
- const startMiddleware = apply(firstMiddleware, device, values);
392
- const composedMiddlewares = [startMiddleware].concat(rest);
393
-
394
- async.waterfall(composedMiddlewares, callback);
395
- } else {
396
- callback(null, device, values);
397
- }
398
- }
399
-
400
- function createNotificationHandler(contextResponse, callback) {
401
- async.waterfall(
402
- [
403
- apply(checkStatus, contextResponse.statusCode),
404
- apply(extractInformation, contextResponse),
405
- applyNotificationMiddlewares,
406
- contextServerUtils.notificationHandler
407
- ],
408
- callback
409
- );
410
- }
411
-
412
- function handleNotificationRequests(error) {
413
- if (error) {
414
- logger.error(context, 'Error found when processing notification: %j', error);
415
- next(error);
416
- } else {
417
- res.status(200).json({});
418
- }
419
- }
420
-
421
- if (contextServerUtils.notificationHandler) {
422
- logger.debug(context, 'Handling notification from [%s]', req.get('host'));
423
-
424
- async.map(req.body.contextResponses, createNotificationHandler, handleNotificationRequests);
425
- } else {
426
- const errorNotFound = new Error({
427
- message: 'Notification handler not found'
428
- });
429
-
430
- logger.error(context, 'Tried to handle a notification before notification handler was established.');
431
-
432
- next(errorNotFound);
433
- }
434
- }
435
-
436
- /**
437
- * Error handler for NGSIv1 context query requests.
438
- *
439
- * @param {Object} error Incoming error
440
- * @param {Object} req Request that was handled in first place.
441
- * @param {Object} res Response that will be sent.
442
- */
443
- function queryErrorHandlingNgsi1(error, req, res, next) {
444
- let code = 500;
445
-
446
- logger.debug(context, 'Query NGSIv1 error [%s] handling request: %s', error.name, error.message);
447
-
448
- if (error.code && String(error.code).match(/^[2345]\d\d$/)) {
449
- code = error.code;
450
- }
451
-
452
- res.status(code).json({
453
- errorCode: {
454
- code,
455
- reasonPhrase: error.name,
456
- details: error.message.replace(/[<>\"\'=;\(\)]/g, '')
457
- }
458
- });
459
- }
460
-
461
- /**
462
- * Error handler for NGSIv1 update requests.
463
- *
464
- * @param {Object} error Incoming error
465
- * @param {Object} req Request that was handled in first place.
466
- * @param {Object} res Response that will be sent.
467
- */
468
- function updateErrorHandlingNgsi1(error, req, res, next) {
469
- let code = 500;
470
-
471
- logger.debug(context, 'Update NGSIv1 error [%s] handing request: %s', error.name, error.message);
472
-
473
- if (error.code && String(error.code).match(/^[2345]\d\d$/)) {
474
- code = error.code;
475
- }
476
-
477
- res.status(code).json({
478
- contextResponses: [
479
- {
480
- contextElement: req.body,
481
- statusCode: {
482
- code,
483
- reasonPhrase: error.name,
484
- details: error.message.replace(/[<>\"\'=;\(\)]/g, '')
485
- }
486
- }
487
- ]
488
- });
489
- }
490
-
491
- /**
492
- * Load the routes related to context dispatching (NGSI10 calls).
493
- *
494
- * @param {Object} router Express request router object.
495
- */
496
- function loadContextRoutesNGSIv1(router) {
497
- // In a more evolved implementation, more endpoints could be added to queryPathsNgsi2
498
- // according to http://fiware.github.io/specifications/ngsiv2/stable.
499
-
500
- let i;
501
- logger.info(context, 'Loading NGSI-v1 Context server routes');
502
- for (i = 0; i < updatePaths.length; i++) {
503
- router.post(updatePaths[i], [
504
- middlewares.ensureType,
505
- middlewares.validateJson(updateContextTemplateNgsi1),
506
- handleUpdateNgsi1,
507
- updateErrorHandlingNgsi1
508
- ]);
509
- }
510
- for (i = 0; i < queryPaths.length; i++) {
511
- router.post(queryPaths[i], [
512
- middlewares.ensureType,
513
- middlewares.validateJson(queryContextTemplate),
514
- handleQueryNgsi1,
515
- queryErrorHandlingNgsi1
516
- ]);
517
- }
518
- router.post('/notify', [
519
- middlewares.ensureType,
520
- middlewares.validateJson(notificationTemplateNgsi1),
521
- handleNotificationNgsi1,
522
- queryErrorHandlingNgsi1
523
- ]);
524
- }
525
-
526
- exports.loadContextRoutes = loadContextRoutesNGSIv1;
@@ -1,75 +0,0 @@
1
- {
2
- "properties": {
3
- "contextResponses": {
4
- "description": "Content of the notification. List of entities with modified attributes.",
5
- "type": "array",
6
- "items": {
7
- "type": "object",
8
- "properties": {
9
- "contextElement": {
10
- "type": "object",
11
- "required": true,
12
- "properties": {
13
- "attributes": {
14
- "type": "array",
15
- "required": true,
16
- "items": {
17
- "type": "object",
18
- "properties": {
19
- "name": {
20
- "type": "string",
21
- "required": true
22
- },
23
- "type": {
24
- "type": "string",
25
- "required": true
26
- },
27
- "value": {
28
- "type": "string",
29
- "required": true
30
- }
31
- }
32
- }
33
- },
34
- "id": {
35
- "type": "string",
36
- "required": true
37
- },
38
- "type": {
39
- "type": "string",
40
- "required": true
41
- },
42
- "isPattern": {
43
- "type": "string",
44
- "required": true
45
- }
46
- }
47
- },
48
- "statusCode": {
49
- "type": "object",
50
- "required": true,
51
- "properties": {
52
- "code": {
53
- "type": "string",
54
- "required": true
55
- },
56
- "reasonPhrase": {
57
- "type": "string",
58
- "required": true
59
- }
60
- }
61
- }
62
- }
63
- },
64
- "required": true
65
- },
66
- "subscriptionId": {
67
- "type": "string",
68
- "required": true
69
- },
70
- "originator": {
71
- "type": "string",
72
- "required": true
73
- }
74
- }
75
- }
@@ -1,50 +0,0 @@
1
- {
2
- "properties": {
3
- "contextElements": {
4
- "description": "The objects the request is applied to.",
5
- "type": "array",
6
- "items": {
7
- "type": "object",
8
- "properties": {
9
- "type": {
10
- "type": "string",
11
- "required": true
12
- },
13
- "isPattern": {
14
- "type": "string"
15
- },
16
- "id": {
17
- "type": "string",
18
- "required": true
19
- },
20
- "attributes": {
21
- "type": "array",
22
- "required": false,
23
- "items": {
24
- "type": "object",
25
- "properties": {
26
- "name": {
27
- "type": "string",
28
- "required": true
29
- },
30
- "type": {
31
- "type": "string",
32
- "required": true
33
- },
34
- "value": {
35
- "type": "any",
36
- "required": true
37
- }
38
- }
39
- }
40
- }
41
- }
42
- },
43
- "required": true
44
- }
45
- },
46
- "updateAction" : {
47
- "description": "Indicates what kind of update action to perform.",
48
- "type": "string"
49
- }
50
- }
@@ -1,21 +0,0 @@
1
- {
2
- "contextRegistrations": [
3
- {
4
- "entities": [
5
- {
6
- "type": "Light",
7
- "isPattern": "false",
8
- "id": "Light:light1"
9
- }
10
- ],
11
- "attributes": [
12
- {
13
- "name": "temperature",
14
- "type": "centigrades"
15
- }
16
- ],
17
- "providingApplication": "http://smartGondor.com"
18
- }
19
- ],
20
- "duration": "P1M"
21
- }
@@ -1,21 +0,0 @@
1
- {
2
- "contextRegistrations": [
3
- {
4
- "entities": [
5
- {
6
- "type": "Motion",
7
- "isPattern": "false",
8
- "id": "Motion:motion1"
9
- }
10
- ],
11
- "attributes": [
12
- {
13
- "name": "moving",
14
- "type": "Boolean"
15
- }
16
- ],
17
- "providingApplication": "http://smartGondor.com"
18
- }
19
- ],
20
- "duration": "P1M"
21
- }