iotagent-node-lib 2.17.0 → 2.20.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 (347) hide show
  1. package/.github/workflows/ci.yml +17 -2
  2. package/.nyc_output/76bc24ff-5fac-4b5a-997d-de2799342eb0.json +1 -0
  3. package/.nyc_output/processinfo/76bc24ff-5fac-4b5a-997d-de2799342eb0.json +1 -0
  4. package/.nyc_output/processinfo/index.json +1 -1
  5. package/CHANGES_NEXT_RELEASE +1 -0
  6. package/README.md +3 -54
  7. package/doc/advanced-topics.md +121 -85
  8. package/doc/api.md +52 -52
  9. package/doc/development.md +13 -6
  10. package/doc/expressionLanguage.md +514 -312
  11. package/doc/installationguide.md +66 -64
  12. package/doc/usermanual.md +48 -16
  13. package/docker/Mosquitto/Dockerfile +1 -0
  14. package/docker/Mosquitto/README.md +1 -0
  15. package/docker/Mosquitto/startMosquitto.sh +9 -4
  16. package/lib/commonConfig.js +1 -14
  17. package/lib/errors.js +0 -16
  18. package/lib/fiware-iotagent-lib.js +4 -2
  19. package/lib/jexlTranformsMap.js +13 -2
  20. package/lib/model/Device.js +4 -1
  21. package/lib/model/Group.js +19 -1
  22. package/lib/plugins/attributeAlias.js +6 -13
  23. package/lib/plugins/bidirectionalData.js +1 -21
  24. package/lib/plugins/expressionParser.js +7 -6
  25. package/lib/plugins/expressionPlugin.js +11 -25
  26. package/lib/plugins/jexlParser.js +8 -4
  27. package/lib/plugins/multiEntity.js +54 -145
  28. package/lib/plugins/pluginUtils.js +12 -48
  29. package/lib/plugins/timestampProcessPlugin.js +1 -46
  30. package/lib/request-shim.js +111 -0
  31. package/lib/services/common/domain.js +6 -2
  32. package/lib/services/common/genericMiddleware.js +6 -2
  33. package/lib/services/common/iotManagerService.js +1 -1
  34. package/lib/services/common/securityServiceKeystone.js +1 -1
  35. package/lib/services/common/securityServiceOAuth2.js +3 -2
  36. package/lib/services/devices/deviceRegistryMongoDB.js +2 -0
  37. package/lib/services/devices/deviceService.js +2 -5
  38. package/lib/services/devices/devices-NGSI-LD.js +1 -1
  39. package/lib/services/devices/devices-NGSI-v2.js +4 -8
  40. package/lib/services/devices/registrationUtils.js +1 -134
  41. package/lib/services/ngsi/entities-NGSI-LD.js +205 -124
  42. package/lib/services/ngsi/entities-NGSI-v2.js +109 -15
  43. package/lib/services/ngsi/ngsiService.js +4 -6
  44. package/lib/services/ngsi/ngsiUtils.js +0 -36
  45. package/lib/services/ngsi/subscriptionService.js +1 -4
  46. package/lib/services/northBound/contextServer-NGSI-LD.js +7 -2
  47. package/lib/services/northBound/contextServer-NGSI-v2.js +24 -12
  48. package/lib/services/northBound/contextServer.js +1 -4
  49. package/lib/services/northBound/contextServerUtils.js +0 -81
  50. package/lib/services/northBound/deviceProvisioningServer.js +31 -7
  51. package/lib/services/northBound/northboundServer.js +2 -0
  52. package/lib/services/northBound/restUtils.js +1 -38
  53. package/lib/templates/updateDevice.json +4 -0
  54. package/lib/templates/updateDeviceLax.json +4 -0
  55. package/package.json +10 -16
  56. package/test/tools/utils.js +2 -0
  57. package/test/unit/examples/groupProvisioningRequests/multipleGroupsCreation.json +1 -1
  58. package/test/unit/expressions/jexlExpression-test.js +44 -5
  59. package/test/unit/general/contextBrokerKeystoneSecurityAccess-test.js +19 -66
  60. package/test/unit/general/deviceService-test.js +11 -27
  61. package/test/unit/general/loglevel-api_test.js +6 -11
  62. package/test/unit/general/startup-test.js +2 -1
  63. package/test/unit/memoryRegistry/deviceRegistryMemory_test.js +8 -16
  64. package/test/unit/mongodb/mongodb-group-registry-test.js +1 -1
  65. package/test/unit/mongodb/mongodb-registry-test.js +38 -114
  66. package/test/unit/ngsi-ld/examples/contextRequests/createMinimumProvisionedDevice.json +0 -7
  67. package/test/unit/ngsi-ld/examples/contextRequests/createProvisionedDevice.json +0 -7
  68. package/test/unit/ngsi-ld/examples/contextRequests/createProvisionedDeviceMultientity.json +0 -7
  69. package/test/unit/ngsi-ld/examples/contextRequests/createProvisionedDeviceWithGroupAndStatic.json +0 -14
  70. package/test/unit/ngsi-ld/examples/contextRequests/createProvisionedDeviceWithGroupAndStatic2.json +0 -14
  71. package/test/unit/ngsi-ld/examples/contextRequests/createProvisionedDeviceWithGroupAndStatic3.json +1 -15
  72. package/test/unit/ngsi-ld/examples/contextRequests/createTimeInstantMinimumDevice.json +0 -7
  73. package/test/unit/ngsi-ld/examples/contextRequests/updateContextAliasPlugin6.json +0 -7
  74. package/test/unit/ngsi-ld/examples/contextRequests/updateContextAutocast5.json +0 -7
  75. package/test/unit/ngsi-ld/examples/contextRequests/updateContextExpressionPlugin12a.json +7 -0
  76. package/test/unit/ngsi-ld/examples/contextRequests/updateContextExpressionPlugin13.json +13 -13
  77. package/test/unit/ngsi-ld/examples/contextRequests/updateContextExpressionPlugin16.json +0 -7
  78. package/test/unit/ngsi-ld/examples/contextRequests/updateContextExpressionPlugin17.json +0 -7
  79. package/test/unit/ngsi-ld/examples/contextRequests/updateContextExpressionPlugin1a.json +18 -0
  80. package/test/unit/ngsi-ld/examples/contextRequests/updateContextExpressionPlugin29.json +18 -0
  81. package/test/unit/ngsi-ld/examples/contextRequests/updateContextExpressionPlugin31.json +15 -0
  82. package/test/unit/ngsi-ld/examples/contextRequests/updateContextExpressionPlugin32.json +17 -0
  83. package/test/unit/ngsi-ld/examples/contextRequests/updateContextExpressionPlugin33.json +18 -0
  84. package/test/unit/ngsi-ld/examples/contextRequests/updateContextExpressionPlugin34.json +17 -0
  85. package/test/unit/ngsi-ld/examples/contextRequests/updateContextExpressionPlugin4a.json +36 -0
  86. package/test/unit/ngsi-ld/examples/contextRequests/updateContextExpressionPlugin5.json +0 -7
  87. package/test/unit/ngsi-ld/examples/contextRequests/updateContextExpressionPlugin7.json +16 -16
  88. package/test/unit/ngsi-ld/examples/contextRequests/updateContextExpressionPlugin8a.json +18 -0
  89. package/test/unit/ngsi-ld/examples/contextRequests/updateContextGeoproperties3.json +0 -7
  90. package/test/unit/ngsi-ld/examples/contextRequests/updateContextMultientityPlugin15.json +25 -0
  91. package/test/unit/ngsi-ld/examples/contextRequests/updateContextMultientityTimestampPlugin1.json +6 -6
  92. package/test/unit/ngsi-ld/examples/contextRequests/updateContextMultientityTimestampPlugin2.json +3 -3
  93. package/test/unit/ngsi-ld/examples/contextRequests/updateProvisionActiveAttributes1.json +0 -7
  94. package/test/unit/ngsi-ld/examples/contextRequests/updateProvisionCommands1.json +0 -7
  95. package/test/unit/ngsi-ld/examples/contextRequests/updateProvisionDeviceStatic.json +0 -7
  96. package/test/unit/ngsi-ld/examples/contextRequests/updateProvisionMinimumDevice.json +0 -7
  97. package/test/unit/ngsi-ld/expressions/jexlBasedTransformations-test.js +1018 -0
  98. package/test/unit/ngsi-ld/general/contextBrokerOAuthSecurityAccess-test.js +2 -2
  99. package/test/unit/ngsi-ld/general/deviceService-test.js +1 -1
  100. package/test/unit/ngsi-ld/general/https-support-test.js +2 -1
  101. package/test/unit/ngsi-ld/general/iotam-autoregistration-test.js +2 -1
  102. package/test/unit/ngsi-ld/general/startup-test.js +1 -0
  103. package/test/unit/ngsi-ld/lazyAndCommands/active-devices-attribute-update-test.js +3 -1
  104. package/test/unit/ngsi-ld/lazyAndCommands/command-test.js +2 -1
  105. package/test/unit/ngsi-ld/lazyAndCommands/lazy-devices-test.js +2 -6
  106. package/test/unit/ngsi-ld/lazyAndCommands/polling-commands-test.js +2 -1
  107. package/test/unit/ngsi-ld/ngsiService/active-devices-test.js +1 -0
  108. package/test/unit/ngsi-ld/ngsiService/autocast-test.js +1 -0
  109. package/test/unit/ngsi-ld/ngsiService/geoproperties-test.js +1 -0
  110. package/test/unit/ngsi-ld/ngsiService/subscriptions-test.js +4 -3
  111. package/test/unit/ngsi-ld/plugins/alias-plugin_test.js +1 -0
  112. package/test/unit/ngsi-ld/plugins/bidirectional-plugin_test.js +3 -2
  113. package/test/unit/ngsi-ld/plugins/multientity-plugin_test.js +61 -0
  114. package/test/unit/ngsi-ld/provisioning/device-provisioning-api_test.js +2 -1
  115. package/test/unit/ngsi-ld/provisioning/device-registration_test.js +3 -2
  116. package/test/unit/ngsi-ld/provisioning/device-update-registration_test.js +1 -0
  117. package/test/unit/ngsi-ld/provisioning/listProvisionedDevices-test.js +42 -54
  118. package/test/unit/ngsi-ld/provisioning/provisionDeviceMultientity-test.js +2 -1
  119. package/test/unit/ngsi-ld/provisioning/removeProvisionedDevice-test.js +4 -4
  120. package/test/unit/ngsi-ld/provisioning/singleConfigurationMode-test.js +3 -5
  121. package/test/unit/ngsi-ld/provisioning/updateProvisionedDevices-test.js +12 -18
  122. package/test/unit/ngsi-mixed/provisioning/ngsi-versioning-test.js +3 -1
  123. package/test/unit/ngsiv2/examples/contextAvailabilityRequests/registerIoTAgent3.json +19 -0
  124. package/test/unit/ngsiv2/examples/contextAvailabilityRequests/registerIoTAgent5.json +19 -0
  125. package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin17.json +1 -1
  126. package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin29.json +22 -0
  127. package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin30.json +6 -0
  128. package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin31.json +18 -0
  129. package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin32.json +16 -0
  130. package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin33.json +22 -0
  131. package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin34.json +12 -0
  132. package/test/unit/ngsiv2/examples/contextRequests/updateContextMiddleware1.json +10 -0
  133. package/test/unit/ngsiv2/examples/contextRequests/updateContextMiddleware2.json +10 -0
  134. package/test/unit/ngsiv2/examples/contextRequests/updateContextMultientityPlugin11.json +13 -0
  135. package/test/unit/ngsiv2/examples/contextRequests/updateContextMultientityPlugin12.json +33 -0
  136. package/test/unit/ngsiv2/examples/contextRequests/updateContextMultientityPlugin13.json +33 -0
  137. package/test/unit/ngsiv2/examples/contextRequests/updateContextMultientityPlugin14.json +33 -0
  138. package/test/unit/ngsiv2/examples/contextRequests/updateContextMultientityPlugin15.json +25 -0
  139. package/test/unit/ngsiv2/examples/contextRequests/updateContextMultientityPlugin16.json +25 -0
  140. package/test/unit/ngsiv2/examples/contextRequests/updateContextMultientityTimestampPlugin1.json +6 -6
  141. package/test/unit/ngsiv2/examples/contextRequests/updateContextMultientityTimestampPlugin2.json +3 -3
  142. package/test/unit/{examples → ngsiv2/examples}/contextRequests/updateProvisionDevice.json +0 -0
  143. package/test/unit/ngsiv2/expressions/expressionBasedTransformations-test.js +37 -4
  144. package/test/unit/ngsiv2/expressions/jexlBasedTransformations-test.js +598 -0
  145. package/test/unit/ngsiv2/general/contextBrokerOAuthSecurityAccess-test.js +3 -2
  146. package/test/unit/ngsiv2/general/deviceService-test.js +9 -8
  147. package/test/unit/ngsiv2/general/https-support-test.js +2 -1
  148. package/test/unit/ngsiv2/general/iotam-autoregistration-test.js +2 -1
  149. package/test/unit/ngsiv2/general/startup-test.js +1 -0
  150. package/test/unit/ngsiv2/lazyAndCommands/active-devices-attribute-update-test.js +3 -1
  151. package/test/unit/ngsiv2/lazyAndCommands/command-test.js +2 -1
  152. package/test/unit/ngsiv2/lazyAndCommands/lazy-devices-test.js +287 -15
  153. package/test/unit/ngsiv2/lazyAndCommands/polling-commands-test.js +3 -1
  154. package/test/unit/ngsiv2/ngsiService/active-devices-test.js +88 -0
  155. package/test/unit/{ngsiService → ngsiv2/ngsiService}/queryDeviceInformationInCb-test.js +20 -49
  156. package/test/unit/ngsiv2/ngsiService/subscriptions-test.js +4 -3
  157. package/test/unit/ngsiv2/plugins/bidirectional-plugin_test.js +3 -2
  158. package/test/unit/ngsiv2/plugins/multientity-plugin_test.js +526 -0
  159. package/test/unit/{plugins → ngsiv2/plugins}/translation-inPlugins_test.js +21 -21
  160. package/test/unit/{provisioning → ngsiv2/provisioning}/device-group-api-test.js +19 -50
  161. package/test/unit/{provisioning/device-group-utils_test.js → ngsiv2/provisioning/device-group-utils-test.js} +5 -4
  162. package/test/unit/ngsiv2/provisioning/device-provisioning-api_test.js +2 -1
  163. package/test/unit/ngsiv2/provisioning/device-registration_test.js +3 -2
  164. package/test/unit/ngsiv2/provisioning/device-update-registration_test.js +4 -3
  165. package/test/unit/ngsiv2/provisioning/listProvisionedDevices-test.js +42 -53
  166. package/test/unit/ngsiv2/provisioning/provisionDeviceMultientity-test.js +2 -1
  167. package/test/unit/ngsiv2/provisioning/removeProvisionedDevice-test.js +4 -4
  168. package/test/unit/ngsiv2/provisioning/singleConfigurationMode-test.js +3 -4
  169. package/test/unit/ngsiv2/provisioning/updateProvisionedDevices-test.js +14 -20
  170. package/test/unit/plugins/capture-configuration-inPlugins_test.js +3 -1
  171. package/test/unit/plugins/capture-provision-inPlugins_test.js +8 -18
  172. package/.eslintcache +0 -1
  173. package/.nyc_output/dca24ca1-851e-490c-9d34-8d13b3330297.json +0 -1
  174. package/.nyc_output/processinfo/dca24ca1-851e-490c-9d34-8d13b3330297.json +0 -1
  175. package/bin/agentConsole.js +0 -257
  176. package/bin/iotAgentTester.js +0 -44
  177. package/lib/command/commandLine.js +0 -918
  178. package/lib/command/migration.js +0 -176
  179. package/lib/services/devices/devices-NGSI-v1.js +0 -310
  180. package/lib/services/ngsi/entities-NGSI-v1.js +0 -299
  181. package/lib/services/ngsi/subscription-NGSI-v1.js +0 -234
  182. package/lib/services/northBound/contextServer-NGSI-v1.js +0 -526
  183. package/lib/templates/notificationTemplateNgsi1.json +0 -75
  184. package/lib/templates/updateContextNgsi1.json +0 -50
  185. package/test/unit/examples/contextAvailabilityRequests/registerIoTAgent1.json +0 -21
  186. package/test/unit/examples/contextAvailabilityRequests/registerIoTAgent2.json +0 -21
  187. package/test/unit/examples/contextAvailabilityRequests/registerIoTAgent3.json +0 -25
  188. package/test/unit/examples/contextAvailabilityRequests/registerIoTAgent4.json +0 -22
  189. package/test/unit/examples/contextAvailabilityRequests/registerIoTAgentAttributeUpdates.json +0 -16
  190. package/test/unit/examples/contextAvailabilityRequests/registerIoTAgentCommands.json +0 -21
  191. package/test/unit/examples/contextAvailabilityRequests/registerNewDevice1.json +0 -21
  192. package/test/unit/examples/contextAvailabilityRequests/registerNewDevice2.json +0 -21
  193. package/test/unit/examples/contextAvailabilityRequests/registerProvisionedDevice.json +0 -25
  194. package/test/unit/examples/contextAvailabilityRequests/registerProvisionedDevice2.json +0 -21
  195. package/test/unit/examples/contextAvailabilityRequests/registerProvisionedDeviceWithGroup.json +0 -33
  196. package/test/unit/examples/contextAvailabilityRequests/registerProvisionedDeviceWithGroup2.json +0 -33
  197. package/test/unit/examples/contextAvailabilityRequests/unregisterDevice1.json +0 -22
  198. package/test/unit/examples/contextAvailabilityRequests/unregisterDevice3.json +0 -26
  199. package/test/unit/examples/contextAvailabilityRequests/unregisterProvisionedDevice.json +0 -26
  200. package/test/unit/examples/contextAvailabilityRequests/updateCommands1.json +0 -22
  201. package/test/unit/examples/contextAvailabilityRequests/updateIoTAgent1.json +0 -22
  202. package/test/unit/examples/contextAvailabilityRequests/updateIoTAgent2.json +0 -26
  203. package/test/unit/examples/contextAvailabilityRequests/updateIoTAgent3.json +0 -26
  204. package/test/unit/examples/contextAvailabilityResponses/registerIoTAgent1Failed.json +0 -8
  205. package/test/unit/examples/contextAvailabilityResponses/registerIoTAgent1Success.json +0 -4
  206. package/test/unit/examples/contextAvailabilityResponses/registerNewDevice1Success.json +0 -4
  207. package/test/unit/examples/contextAvailabilityResponses/registerNewDevice2Success.json +0 -4
  208. package/test/unit/examples/contextAvailabilityResponses/registerProvisionedDeviceSuccess.json +0 -4
  209. package/test/unit/examples/contextAvailabilityResponses/unregisterDevice1Failed.json +0 -8
  210. package/test/unit/examples/contextAvailabilityResponses/unregisterDevice1Success.json +0 -4
  211. package/test/unit/examples/contextAvailabilityResponses/updateCommands1Success.json +0 -4
  212. package/test/unit/examples/contextAvailabilityResponses/updateIoTAgent1Success.json +0 -6
  213. package/test/unit/examples/contextProviderResponses/queryInformationResponse.json +0 -22
  214. package/test/unit/examples/contextProviderResponses/queryInformationResponseEmptyAttributes.json +0 -22
  215. package/test/unit/examples/contextProviderResponses/queryInformationStaticAttributesResponse.json +0 -27
  216. package/test/unit/examples/contextProviderResponses/updateInformationResponse.json +0 -22
  217. package/test/unit/examples/contextProviderResponses/updateInformationResponse2.json +0 -22
  218. package/test/unit/examples/contextRequests/contextSubscriptionRequest.json +0 -20
  219. package/test/unit/examples/contextRequests/contextSubscriptionRequest2.json +0 -20
  220. package/test/unit/examples/contextRequests/createBidirectionalDevice.json +0 -17
  221. package/test/unit/examples/contextRequests/createDatetimeProvisionedDevice.json +0 -17
  222. package/test/unit/examples/contextRequests/createGeopointProvisionedDevice.json +0 -17
  223. package/test/unit/examples/contextRequests/createMinimumProvisionedDevice.json +0 -17
  224. package/test/unit/examples/contextRequests/createProvisionedDevice.json +0 -32
  225. package/test/unit/examples/contextRequests/createProvisionedDeviceMultientity.json +0 -32
  226. package/test/unit/examples/contextRequests/createProvisionedDeviceWithGroup.json +0 -47
  227. package/test/unit/examples/contextRequests/createProvisionedDeviceWithGroupAndStatic.json +0 -52
  228. package/test/unit/examples/contextRequests/createProvisionedDeviceWithGroupAndStatic2.json +0 -52
  229. package/test/unit/examples/contextRequests/createTimeinstantDevice.json +0 -17
  230. package/test/unit/examples/contextRequests/queryContext1.json +0 -13
  231. package/test/unit/examples/contextRequests/queryContext2.json +0 -13
  232. package/test/unit/examples/contextRequests/queryContextAliasPlugin1.json +0 -10
  233. package/test/unit/examples/contextRequests/queryContextCompressTimestamp1.json +0 -13
  234. package/test/unit/examples/contextRequests/updateActiveAttributes.json +0 -32
  235. package/test/unit/examples/contextRequests/updateContext1.json +0 -22
  236. package/test/unit/examples/contextRequests/updateContext2.json +0 -22
  237. package/test/unit/examples/contextRequests/updateContext3.json +0 -17
  238. package/test/unit/examples/contextRequests/updateContext3WithStatic.json +0 -22
  239. package/test/unit/examples/contextRequests/updateContext4.json +0 -22
  240. package/test/unit/examples/contextRequests/updateContext5.json +0 -19
  241. package/test/unit/examples/contextRequests/updateContextAliasPlugin.json +0 -22
  242. package/test/unit/examples/contextRequests/updateContextAliasPlugin2.json +0 -17
  243. package/test/unit/examples/contextRequests/updateContextAppendMode.json +0 -22
  244. package/test/unit/examples/contextRequests/updateContextCommandError.json +0 -22
  245. package/test/unit/examples/contextRequests/updateContextCommandExpired.json +0 -22
  246. package/test/unit/examples/contextRequests/updateContextCommandFinish.json +0 -22
  247. package/test/unit/examples/contextRequests/updateContextCommandStatus.json +0 -17
  248. package/test/unit/examples/contextRequests/updateContextCompressTimestamp1.json +0 -22
  249. package/test/unit/examples/contextRequests/updateContextCompressTimestamp2.json +0 -29
  250. package/test/unit/examples/contextRequests/updateContextExpressionPlugin1.json +0 -17
  251. package/test/unit/examples/contextRequests/updateContextExpressionPlugin10.json +0 -17
  252. package/test/unit/examples/contextRequests/updateContextExpressionPlugin2.json +0 -27
  253. package/test/unit/examples/contextRequests/updateContextExpressionPlugin3.json +0 -17
  254. package/test/unit/examples/contextRequests/updateContextExpressionPlugin4.json +0 -17
  255. package/test/unit/examples/contextRequests/updateContextExpressionPlugin5.json +0 -27
  256. package/test/unit/examples/contextRequests/updateContextExpressionPlugin6.json +0 -17
  257. package/test/unit/examples/contextRequests/updateContextExpressionPlugin7.json +0 -27
  258. package/test/unit/examples/contextRequests/updateContextExpressionPlugin8.json +0 -22
  259. package/test/unit/examples/contextRequests/updateContextExpressionPlugin9.json +0 -27
  260. package/test/unit/examples/contextRequests/updateContextMiddleware1.json +0 -22
  261. package/test/unit/examples/contextRequests/updateContextMultiEntityPlugin3.json +0 -35
  262. package/test/unit/examples/contextRequests/updateContextMultientityPlugin1.json +0 -30
  263. package/test/unit/examples/contextRequests/updateContextMultientityPlugin2.json +0 -30
  264. package/test/unit/examples/contextRequests/updateContextProcessTimestamp1.json +0 -29
  265. package/test/unit/examples/contextRequests/updateContextStaticAttributes.json +0 -22
  266. package/test/unit/examples/contextRequests/updateContextTimestamp.json +0 -41
  267. package/test/unit/examples/contextRequests/updateContextTimestampOverride.json +0 -22
  268. package/test/unit/examples/contextRequests/updateContextTimestampOverrideWithoutMilis.json +0 -22
  269. package/test/unit/examples/contextRequests/updateContextTimestampTimezone.json +0 -41
  270. package/test/unit/examples/contextRequests/updateProvisionActiveAttributes1.json +0 -17
  271. package/test/unit/examples/contextRequests/updateProvisionCommands1.json +0 -27
  272. package/test/unit/examples/contextRequests/updateProvisionDeviceStatic.json +0 -38
  273. package/test/unit/examples/contextRequests/updateProvisionMinimumDevice.json +0 -17
  274. package/test/unit/examples/contextResponses/contextSubscriptionRequest2Success.json +0 -7
  275. package/test/unit/examples/contextResponses/contextSubscriptionRequestSuccess.json +0 -7
  276. package/test/unit/examples/contextResponses/createBidirectionalDeviceSuccess.json +0 -22
  277. package/test/unit/examples/contextResponses/createDatetimeProvisionedDeviceSuccess.json +0 -22
  278. package/test/unit/examples/contextResponses/createGeopointProvisionedDeviceSuccess.json +0 -22
  279. package/test/unit/examples/contextResponses/createProvisionedDeviceSuccess.json +0 -22
  280. package/test/unit/examples/contextResponses/createTimeinstantSuccess.json +0 -22
  281. package/test/unit/examples/contextResponses/queryContext1Success.json +0 -27
  282. package/test/unit/examples/contextResponses/queryContext2Error.json +0 -7
  283. package/test/unit/examples/contextResponses/queryContext2UnknownError.json +0 -6
  284. package/test/unit/examples/contextResponses/queryContext3Error.json +0 -34
  285. package/test/unit/examples/contextResponses/queryContextAliasPlugin1Success.json +0 -27
  286. package/test/unit/examples/contextResponses/queryContextCompressTimestamp1Success.json +0 -27
  287. package/test/unit/examples/contextResponses/updateActiveAttributesSuccess.json +0 -42
  288. package/test/unit/examples/contextResponses/updateContext1Failed.json +0 -7
  289. package/test/unit/examples/contextResponses/updateContext1Success.json +0 -27
  290. package/test/unit/examples/contextResponses/updateContext2Failed.json +0 -35
  291. package/test/unit/examples/contextResponses/updateContextAliasPlugin2Success.json +0 -27
  292. package/test/unit/examples/contextResponses/updateContextAliasPluginSuccess.json +0 -27
  293. package/test/unit/examples/contextResponses/updateContextCommandFinishSuccess.json +0 -27
  294. package/test/unit/examples/contextResponses/updateContextCommandStatusSuccess.json +0 -22
  295. package/test/unit/examples/contextResponses/updateContextCompressTimestamp1Success.json +0 -27
  296. package/test/unit/examples/contextResponses/updateContextCompressTimestamp2Success.json +0 -34
  297. package/test/unit/examples/contextResponses/updateContextEvents1Success.json +0 -27
  298. package/test/unit/examples/contextResponses/updateContextExpressionPlugin1Success.json +0 -22
  299. package/test/unit/examples/contextResponses/updateContextExpressionPlugin2Success.json +0 -22
  300. package/test/unit/examples/contextResponses/updateContextExpressionPlugin3Success.json +0 -22
  301. package/test/unit/examples/contextResponses/updateContextExpressionPlugin5Success.json +0 -32
  302. package/test/unit/examples/contextResponses/updateContextMultientityPlugin1Success.json +0 -40
  303. package/test/unit/examples/contextResponses/updateContextMultientityPlugin2Success.json +0 -40
  304. package/test/unit/examples/contextResponses/updateContextMultientityPlugin3Success.json +0 -40
  305. package/test/unit/examples/contextResponses/updateContextProcessTimestamp1Success.json +0 -27
  306. package/test/unit/examples/contextResponses/updateProvisionActiveAttributes1Success.json +0 -22
  307. package/test/unit/examples/contextResponses/updateProvisionCommands1Success.json +0 -32
  308. package/test/unit/examples/contextResponses/updateProvisionMinimumDeviceSuccess.json +0 -22
  309. package/test/unit/examples/subscriptionRequests/bidirectionalNotification.json +0 -24
  310. package/test/unit/examples/subscriptionRequests/bidirectionalSubscriptionRemove.json +0 -3
  311. package/test/unit/examples/subscriptionRequests/bidirectionalSubscriptionRequest.json +0 -22
  312. package/test/unit/examples/subscriptionRequests/errorNotification.json +0 -24
  313. package/test/unit/examples/subscriptionRequests/simpleNotification.json +0 -24
  314. package/test/unit/examples/subscriptionRequests/simpleSubscriptionRemove.json +0 -3
  315. package/test/unit/examples/subscriptionRequests/simpleSubscriptionRequest.json +0 -19
  316. package/test/unit/examples/subscriptionRequests/simpleSubscriptionRequest1.json +0 -19
  317. package/test/unit/examples/subscriptionResponses/bidirectionalSubscriptionSuccess.json +0 -6
  318. package/test/unit/examples/subscriptionResponses/simpleSubscriptionSuccess.json +0 -6
  319. package/test/unit/expressions/expressionBasedTransformations-test.js +0 -328
  320. package/test/unit/expressions/expressionCombinedTransformations-test.js +0 -306
  321. package/test/unit/expressions/jexlBasedTransformations-test.js +0 -334
  322. package/test/unit/general/contextBrokerOAuthSecurityAccess-test.js +0 -902
  323. package/test/unit/general/https-support-test.js +0 -286
  324. package/test/unit/general/iotam-autoregistration-test.js +0 -368
  325. package/test/unit/general/migration-test.js +0 -256
  326. package/test/unit/lazyAndCommands/active-devices-attribute-update-test.js +0 -168
  327. package/test/unit/lazyAndCommands/command-test.js +0 -341
  328. package/test/unit/lazyAndCommands/lazy-devices-test.js +0 -878
  329. package/test/unit/lazyAndCommands/polling-commands-test.js +0 -421
  330. package/test/unit/ngsi-ld/examples/contextRequests/updateContextExpressionPlugin20.json +0 -25
  331. package/test/unit/ngsiService/active-devices-test.js +0 -692
  332. package/test/unit/ngsiService/staticAttributes-test.js +0 -148
  333. package/test/unit/ngsiService/subscriptions-test.js +0 -345
  334. package/test/unit/plugins/alias-plugin_test.js +0 -158
  335. package/test/unit/plugins/bidirectional-plugin_test.js +0 -564
  336. package/test/unit/plugins/compress-timestamp-plugin_test.js +0 -257
  337. package/test/unit/plugins/event-plugin_test.js +0 -119
  338. package/test/unit/plugins/multientity-plugin_test.js +0 -248
  339. package/test/unit/plugins/timestamp-processing-plugin_test.js +0 -119
  340. package/test/unit/provisioning/device-provisioning-api_test.js +0 -748
  341. package/test/unit/provisioning/device-registration_test.js +0 -432
  342. package/test/unit/provisioning/device-update-registration_test.js +0 -326
  343. package/test/unit/provisioning/listProvisionedDevices-test.js +0 -488
  344. package/test/unit/provisioning/provisionDeviceMultientity-test.js +0 -123
  345. package/test/unit/provisioning/removeProvisionedDevice-test.js +0 -244
  346. package/test/unit/provisioning/singleConfigurationMode-test.js +0 -346
  347. package/test/unit/provisioning/updateProvisionedDevices-test.js +0 -436
@@ -90,30 +90,19 @@ function update(entity, typeInformation, callback) {
90
90
  return false;
91
91
  }
92
92
 
93
- function processEntityUpdateNgsi1(entity) {
94
- let parser = legacyParser;
95
- if (checkJexl(typeInformation)) {
96
- parser = jexlParser;
97
- }
98
- let expressionAttributes = [];
99
- const ctx = parser.extractContext(entity.attributes);
100
-
101
- if (typeInformation.active) {
102
- expressionAttributes = parser.processExpressionAttributes(typeInformation, typeInformation.active, ctx);
103
- }
104
-
105
- entity.attributes = mergeAttributes(entity.attributes, expressionAttributes);
106
-
107
- return entity;
108
- }
109
-
110
93
  function processEntityUpdateNgsi2(attributes) {
111
94
  let parser = legacyParser;
112
95
  if (checkJexl(typeInformation)) {
113
96
  parser = jexlParser;
114
97
  }
115
98
  let expressionAttributes = [];
116
- const ctx = parser.extractContext(attributes);
99
+ let attributesCtxt = [...attributes]; // just copy
100
+ if (typeInformation.static) {
101
+ typeInformation.static.forEach(function (att) {
102
+ attributesCtxt.push(att);
103
+ });
104
+ }
105
+ const ctx = parser.extractContext(attributesCtxt);
117
106
 
118
107
  if (typeInformation.active) {
119
108
  expressionAttributes = parser.processExpressionAttributes(typeInformation, typeInformation.active, ctx);
@@ -124,13 +113,10 @@ function update(entity, typeInformation, callback) {
124
113
  }
125
114
 
126
115
  try {
127
- if (config.isCurrentNgsi()) {
128
- let attsArray = utils.extractAttributesArrayFromNgsi2Entity(entity);
129
- attsArray = processEntityUpdateNgsi2(attsArray);
130
- entity = utils.createNgsi2Entity(entity.id, entity.type, attsArray, true);
131
- } else {
132
- entity.contextElements = entity.contextElements.map(processEntityUpdateNgsi1);
133
- }
116
+ logger.debug(context, 'expressionPlugin entity %j', entity);
117
+ let attsArray = utils.extractAttributesArrayFromNgsi2Entity(entity);
118
+ attsArray = processEntityUpdateNgsi2(attsArray);
119
+ entity = utils.createNgsi2Entity(entity.id, entity.type, attsArray, true);
134
120
 
135
121
  callback(null, entity, typeInformation);
136
122
  } catch (e) {
@@ -30,9 +30,10 @@
30
30
  const jexl = require('jexl');
31
31
  const errors = require('../errors');
32
32
  const logger = require('logops');
33
+ const fillService = require('../services/common/domain').fillService;
33
34
  const config = require('../commonConfig');
34
35
  const baseTranformsMap = require('../jexlTranformsMap.js').map;
35
- const logContext = {
36
+ let logContext = {
36
37
  op: 'IoTAgentNGSI.JEXL'
37
38
  };
38
39
 
@@ -42,6 +43,8 @@ function parse(expression, context, callback) {
42
43
 
43
44
  try {
44
45
  result = jexl.evalSync(expression, context);
46
+ //avoid undefined result
47
+ result = result !== undefined ? result : null;
45
48
  logger.debug(logContext, 'parse expression "[%j]" over "[%j]" result "[%j]" ', expression, context, result);
46
49
  } catch (e) {
47
50
  error = new errors.InvalidExpression(expression);
@@ -94,9 +97,10 @@ function extractContext(attributeList) {
94
97
  }
95
98
 
96
99
  function applyExpression(expression, context, typeInformation) {
97
- const result = jexl.evalSync(expression, context);
100
+ logContext = fillService(logContext, typeInformation);
101
+ const result = parse(expression, context);
98
102
  logger.debug(logContext, 'applyExpression "[%j]" over "[%j]" result "[%j]" ', expression, context, result);
99
- let expressionResult = result !== undefined ? result : expression;
103
+ const expressionResult = result !== undefined ? result : expression;
100
104
  return expressionResult;
101
105
  }
102
106
 
@@ -118,7 +122,7 @@ function expressionApplier(context, typeInformation) {
118
122
  };
119
123
 
120
124
  /*jshint camelcase: false */
121
- if (config.isCurrentNgsi() && attribute.object_id) {
125
+ if (attribute.object_id) {
122
126
  newAttribute.object_id = attribute.object_id;
123
127
  }
124
128
 
@@ -64,24 +64,6 @@ function hasEntityName(item) {
64
64
  return item.entity_name;
65
65
  }
66
66
 
67
- function ensureEntityId(entityName, originalEntityName) {
68
- // ensure no return null, 0, false, NaN and other invalids entityIDs
69
- return entityName ? entityName : originalEntityName;
70
- }
71
-
72
- /**
73
- * Return a list of all the attributes that don't have a multientity option. It considers NGSIv1.
74
- *
75
- * @param {Array} originalAttrs Array of original attributes coming from the single-entity device.
76
- * @param {Array} meAttributes Array of all the multientity attributes.
77
- * @return {Array} List of all the attrbiutes without multientity flag.
78
- */
79
- function filterOutMultientitiesNgsi1(originalAttrs, meAttributes) {
80
- return originalAttrs.filter(function (item) {
81
- return !_.contains(meAttributes, item.name);
82
- });
83
- }
84
-
85
67
  /**
86
68
  * Return a list of all the attributes that don't have a multientity option. It considers NGSIv2.
87
69
  *
@@ -121,87 +103,30 @@ function filterOutMultientitiesNgsi2(originalAttrs, meAttributes) {
121
103
  return result;
122
104
  }
123
105
 
124
- /**
125
- * Generate new Context Elements for each new Entity, with the attributes of the original entity matching its
126
- * entity_name. It considers Ngsiv1.
127
- *
128
- * @param {Object} entity The original entity
129
- * @param {Array} newEntities List of the new entities that will be generated
130
- * @param {Array} entityTypes Map of the types for each entity ID
131
- * @param {Object} typeInformation Object with all the data about the device type
132
- * @param {Array} multiEntityAttributes List of attributes with multientity option
133
- * @return {Array} List of the new Context Entities
134
- */
135
- function generateNewCEsNgsi1(entity, newEntities, entityTypes, typeInformation, multiEntityAttributes) {
136
- const result = [];
137
- let newEntityAttributes;
138
- let newEntityAttributeNames;
139
- let entityName;
140
- let parser = legacyParser;
141
- if (checkJexl(typeInformation)) {
142
- parser = jexlParser;
143
- }
144
- function filterByEntityName(entityName) {
145
- return function (item) {
146
- return item.entity_name === entityName;
147
- };
148
- }
149
-
150
- function filterByAttributeNames(item) {
151
- return _.contains(newEntityAttributeNames, item.name);
152
- }
153
-
154
- const ctx = parser.extractContext(entity.contextElements[0].attributes);
155
-
156
- for (let i = 0; i < newEntities.length; i++) {
157
- newEntityAttributeNames = _.pluck(multiEntityAttributes.filter(filterByEntityName(newEntities[i])), 'name');
158
-
159
- newEntityAttributes = entity.contextElements[0].attributes.filter(filterByAttributeNames);
160
- // Fix duplicated attributes in entity
161
- newEntityAttributes = _.uniq(newEntityAttributes, JSON.stringify);
162
- if (parser.contextAvailable(newEntities[i], ctx)) {
163
- entityName = parser.applyExpression(newEntities[i], ctx, typeInformation);
164
- }
165
-
166
- result.push({
167
- type: entityTypes[newEntities[i]],
168
- isPattern: 'false',
169
- id: ensureEntityId(entityName, newEntities[i]),
170
- attributes: newEntityAttributes
171
- });
172
- }
173
-
174
- return result;
175
- }
176
-
177
106
  /**
178
107
  * Generate new Context Elements for each new Entity, with the attributes of the original entity matching its
179
108
  * entity_name. It considers Ngsiv2.
180
109
  *
181
110
  * @param {Object} entity The original entity
182
111
  * @param {Array} newEntities List of the new entities that will be generated
183
- * @param {Array} entityTypes Map of the types for each entity ID
184
- * @param {Object} typeInformation Object with all the data about the device type
185
112
  * @param {Array} multiEntityAttributes List of attributes with multientity option
186
113
  * @return {Array} List of the new Context Entities
187
114
  */
188
- function generateNewCEsNgsi2(entity, newEntities, entityTypes, typeInformation, multiEntityAttributes) {
115
+ function generateNewCEsNgsi2(entity, newEntities, multiEntityAttributes) {
189
116
  const result = [];
190
117
  let newEntityAttributes;
191
118
  let newEntityAttributeNames;
192
119
  let newEntityAttributeObjectIds;
193
- let entityName;
194
- let parser = legacyParser;
195
- if (checkJexl(typeInformation)) {
196
- parser = jexlParser;
197
- }
198
- function filterByEntityName(entityName) {
120
+ function filterByEntityNameandType(entityNameType) {
199
121
  return function (item) {
200
- return item.entity_name === entityName;
122
+ return (
123
+ item.entity_name === entityNameType.entity_name &&
124
+ (!item.entity_type || item.entity_type === entityNameType.entity_type)
125
+ );
201
126
  };
202
127
  }
203
128
 
204
- function filterByAttributeObjectIds() {
129
+ function filterByAttributeObjectIds(entity, newEntityAttributeNames, newEntityAttributeObjectIds) {
205
130
  const result = {};
206
131
  for (const att in entity) {
207
132
  if (entity.hasOwnProperty(att)) {
@@ -227,40 +152,44 @@ function generateNewCEsNgsi2(entity, newEntities, entityTypes, typeInformation,
227
152
  return result;
228
153
  }
229
154
 
230
- const attsArray = utils.extractAttributesArrayFromNgsi2Entity(entity);
231
- const ctx = parser.extractContext(attsArray);
232
-
233
155
  for (let i = 0; i < newEntities.length; i++) {
234
- newEntityAttributeNames = _.pluck(multiEntityAttributes.filter(filterByEntityName(newEntities[i])), 'name');
156
+ newEntityAttributeNames = _.pluck(
157
+ multiEntityAttributes.filter(filterByEntityNameandType(newEntities[i])),
158
+ 'name'
159
+ );
235
160
  newEntityAttributeObjectIds = _.pluck(
236
- multiEntityAttributes.filter(filterByEntityName(newEntities[i])),
161
+ multiEntityAttributes.filter(filterByEntityNameandType(newEntities[i])),
237
162
  'object_id'
238
163
  );
239
- newEntityAttributes = filterByAttributeObjectIds();
240
-
241
- if (parser.contextAvailable(newEntities[i], ctx)) {
242
- entityName = parser.applyExpression(newEntities[i], ctx, typeInformation);
243
- }
244
-
245
- newEntityAttributes.type = entityTypes[newEntities[i]];
246
- newEntityAttributes.id = ensureEntityId(entityName, newEntities[i]);
247
-
164
+ newEntityAttributes = filterByAttributeObjectIds(entity, newEntityAttributeNames, newEntityAttributeObjectIds);
165
+ newEntityAttributes.type = newEntities[i].entity_type;
166
+ newEntityAttributes.id = newEntities[i].entity_name;
248
167
  result.push(newEntityAttributes);
249
168
  }
250
-
251
169
  return result;
252
170
  }
253
171
 
254
- function extractTypes(attributeList, defaultType) {
255
- const typeMap = {};
256
-
257
- for (let i = 0; i < attributeList.length; i++) {
258
- typeMap[attributeList[i].entity_name] = attributeList[i].entity_type || defaultType;
172
+ function extractNewEntities(multiEntityAttributes, defaultType) {
173
+ let newEntitieswithDuplicates = multiEntityAttributes.map((elem) => {
174
+ return { entity_name: elem.entity_name, entity_type: elem.entity_type || defaultType };
175
+ });
176
+ let auxOverwriteTree = {};
177
+ for (let entityItem in newEntitieswithDuplicates) {
178
+ if (!auxOverwriteTree[newEntitieswithDuplicates[entityItem].entity_name]) {
179
+ auxOverwriteTree[newEntitieswithDuplicates[entityItem].entity_name] = {};
180
+ }
181
+ auxOverwriteTree[newEntitieswithDuplicates[entityItem].entity_name][
182
+ newEntitieswithDuplicates[entityItem].entity_type
183
+ ] = null;
259
184
  }
260
-
261
- return typeMap;
185
+ let flatNewEntities = [];
186
+ for (let entityItem in auxOverwriteTree) {
187
+ for (let typeItem in auxOverwriteTree[entityItem]) {
188
+ flatNewEntities.push({ entity_name: entityItem, entity_type: typeItem });
189
+ }
190
+ }
191
+ return flatNewEntities;
262
192
  }
263
-
264
193
  /**
265
194
  * Propagates the same timestamp used in entity to entities. This is needed given that timestamp processing
266
195
  * plugin runs before multientity plugin, so we could have issues as the one described here:
@@ -295,44 +224,32 @@ function propagateTimestamp(entity, entities) {
295
224
  });
296
225
  }
297
226
 
298
- function updateAttributeNgsi1(entity, typeInformation, callback) {
299
- if (typeInformation.active) {
300
- const multiEntityAttributes = typeInformation.active.filter(hasEntityName);
301
- const newEntities = _.uniq(_.pluck(multiEntityAttributes, 'entity_name'));
302
- const attributesList = _.pluck(multiEntityAttributes, 'name');
303
- const entityTypes = extractTypes(multiEntityAttributes, entity.contextElements[0].type);
304
- const resultAttributes = filterOutMultientitiesNgsi1(entity.contextElements[0].attributes, attributesList);
305
-
306
- entity.contextElements = entity.contextElements.concat(
307
- generateNewCEsNgsi1(entity, newEntities, entityTypes, typeInformation, multiEntityAttributes)
308
- );
309
-
310
- entity.contextElements[0].attributes = resultAttributes;
227
+ function updateAttribute(entity, typeInformation, callback) {
228
+ let parser = legacyParser;
229
+ if (checkJexl(typeInformation)) {
230
+ parser = jexlParser;
311
231
  }
232
+ const attsArray = utils.extractAttributesArrayFromNgsi2Entity(entity);
233
+ const ctx = parser.extractContext(attsArray);
312
234
 
313
- callback(null, entity, typeInformation);
314
- }
315
-
316
- function updateAttributeNgsi2(entity, typeInformation, callback) {
317
- let entities = [];
318
- entities.push(entity);
235
+ let entities = [entity];
319
236
  if (typeInformation.active) {
320
237
  const multiEntityAttributes = typeInformation.active.filter(hasEntityName);
321
- const newEntities = _.uniq(_.pluck(multiEntityAttributes, 'entity_name'));
322
- const entityTypes = extractTypes(multiEntityAttributes, typeInformation.type);
323
- let resultAttributes;
238
+ for (let i in multiEntityAttributes) {
239
+ if (parser.contextAvailable(multiEntityAttributes[i].entity_name, ctx)) {
240
+ let entityName = parser.applyExpression(multiEntityAttributes[i].entity_name, ctx, typeInformation);
241
+ // An entity_name could not be null, but a result or expression could be null
242
+ if (entityName !== null) {
243
+ multiEntityAttributes[i].entity_name = entityName;
244
+ }
245
+ }
246
+ }
247
+ const newEntities = extractNewEntities(multiEntityAttributes, typeInformation.type);
324
248
 
325
249
  if (multiEntityAttributes.length > 0) {
326
- resultAttributes = filterOutMultientitiesNgsi2(entity, multiEntityAttributes);
327
- const newCes = generateNewCEsNgsi2(
328
- entity,
329
- newEntities,
330
- entityTypes,
331
- typeInformation,
332
- multiEntityAttributes
333
- );
334
- entities = entities.concat(newCes);
335
- entities[0] = resultAttributes;
250
+ let resultAttributes = filterOutMultientitiesNgsi2(entity, multiEntityAttributes);
251
+ const newCes = generateNewCEsNgsi2(entity, newEntities, multiEntityAttributes);
252
+ entities = [resultAttributes].concat(newCes);
336
253
  propagateTimestamp(entity, entities);
337
254
  } else {
338
255
  entities = entity;
@@ -341,12 +258,4 @@ function updateAttributeNgsi2(entity, typeInformation, callback) {
341
258
  callback(null, entities, typeInformation);
342
259
  }
343
260
 
344
- function updateAttribute(entity, typeInformation, callback) {
345
- if (config.isCurrentNgsi()) {
346
- updateAttributeNgsi2(entity, typeInformation, callback);
347
- } else {
348
- updateAttributeNgsi1(entity, typeInformation, callback);
349
- }
350
- }
351
-
352
261
  exports.update = updateAttribute;
@@ -23,8 +23,6 @@
23
23
  * Modified by: Daniel Calvo - ATOS Research & Innovation
24
24
  */
25
25
 
26
- const config = require('../commonConfig');
27
-
28
26
  /**
29
27
  * Creates an array of attributes from an entity
30
28
  * @param {Object} entity
@@ -66,8 +64,6 @@ function extractAttributesArrayFromNgsi2Entity(entity) {
66
64
  */
67
65
  function createNgsi2Entity(id, type, attsArray, withObjectId) {
68
66
  const entity = {};
69
- entity.id = id;
70
- entity.type = type;
71
67
  for (let i = 0; i < attsArray.length; i++) {
72
68
  /*jshint camelcase: false */
73
69
  if (entity[attsArray[i].name] && withObjectId && attsArray[i].object_id) {
@@ -93,7 +89,8 @@ function createNgsi2Entity(id, type, attsArray, withObjectId) {
93
89
  }
94
90
  }
95
91
  }
96
-
92
+ entity.id = id;
93
+ entity.type = type;
97
94
  return entity;
98
95
  }
99
96
 
@@ -102,24 +99,15 @@ function createProcessAttribute(fn, attributeType) {
102
99
  if (attribute.type && attribute.type === attributeType) {
103
100
  attribute.value = fn(attribute.value);
104
101
  }
105
- if (config.isCurrentNgsi()) {
106
- // This code is backwards compatible to process metadata in the older NGSIv1-style (array)
107
- // as well as supporting the newer NGSIv2-style (object). The redundant Array Check can be
108
- // therefore be removed if/when NGSIv1 support is removed from the library.
109
- if (Array.isArray(attribute.metadata)) {
110
- attribute.metadata = attribute.metadata.map(createProcessAttribute(fn, attributeType));
111
- } else if (attribute.metadata) {
112
- Object.keys(attribute.metadata).forEach(function (key) {
113
- const entry = attribute.metadata[key];
114
- if (entry.type === 'DateTime') {
115
- entry.value = fn(entry.value);
116
- }
117
- });
118
- }
119
- } else if (attribute.metadatas) {
120
- attribute.metadatas = attribute.metadatas.map(createProcessAttribute(fn, attributeType));
121
- }
122
102
 
103
+ if (attribute.metadata) {
104
+ Object.keys(attribute.metadata).forEach(function (key) {
105
+ const entry = attribute.metadata[key];
106
+ if (entry.type === 'DateTime') {
107
+ entry.value = fn(entry.value);
108
+ }
109
+ });
110
+ }
123
111
  return attribute;
124
112
  };
125
113
  }
@@ -135,12 +123,6 @@ function createProcessAttribute(fn, attributeType) {
135
123
 
136
124
  function createUpdateFilter(fn, attributeType) {
137
125
  return function update(entity, typeInformation, callback) {
138
- function processEntityUpdateNgsi1(entity) {
139
- entity.attributes = entity.attributes.map(createProcessAttribute(fn, attributeType));
140
-
141
- return entity;
142
- }
143
-
144
126
  function processEntityUpdateNgsi2(entity) {
145
127
  let attsArray = extractAttributesArrayFromNgsi2Entity(entity);
146
128
  attsArray = attsArray.map(createProcessAttribute(fn, attributeType));
@@ -148,12 +130,7 @@ function createUpdateFilter(fn, attributeType) {
148
130
  return entity;
149
131
  }
150
132
 
151
- if (config.isCurrentNgsi()) {
152
- entity = processEntityUpdateNgsi2(entity);
153
- } else {
154
- entity.contextElements = entity.contextElements.map(processEntityUpdateNgsi1);
155
- }
156
-
133
+ entity = processEntityUpdateNgsi2(entity);
157
134
  callback(null, entity, typeInformation);
158
135
  };
159
136
  }
@@ -168,14 +145,6 @@ function createUpdateFilter(fn, attributeType) {
168
145
  */
169
146
  function createQueryFilter(fn, attributeType) {
170
147
  return function query(entity, typeInformation, callback) {
171
- function processEntityQueryNgsi1(entity) {
172
- entity.contextElement.attributes = entity.contextElement.attributes.map(
173
- createProcessAttribute(fn, attributeType)
174
- );
175
-
176
- return entity;
177
- }
178
-
179
148
  function processEntityQueryNgsi2(entity) {
180
149
  let attsArray = extractAttributesArrayFromNgsi2Entity(entity);
181
150
  attsArray = attsArray.map(createProcessAttribute(fn, attributeType));
@@ -183,12 +152,7 @@ function createQueryFilter(fn, attributeType) {
183
152
  return entity;
184
153
  }
185
154
 
186
- if (config.isCurrentNgsi()) {
187
- entity = processEntityQueryNgsi2(entity);
188
- } else {
189
- entity.contextResponses = entity.contextResponses.map(processEntityQueryNgsi1);
190
- }
191
-
155
+ entity = processEntityQueryNgsi2(entity);
192
156
  callback(null, entity, typeInformation);
193
157
  };
194
158
  }
@@ -31,7 +31,6 @@ const logger = require('logops');
31
31
  const context = {
32
32
  op: 'IoTAgentNGSI.TimestampProcessPlugin'
33
33
  };
34
- const config = require('../commonConfig');
35
34
  const utils = require('./pluginUtils');
36
35
 
37
36
  /**
@@ -84,57 +83,13 @@ function updatePluginNgsi2(entity, entityType, callback) {
84
83
  }
85
84
  }
86
85
 
87
- /**
88
- * Looks for Thinking Thing modules and parses them, updating the entity (NGSIv1) with the transformed value.
89
- *
90
- * @param {Object} entity NGSI Entity as it would have been sent before the plugin.
91
- */
92
- function updatePluginNgsi1(entity, entityType, callback) {
93
- let timestamp;
94
-
95
- function insertMetadata(element) {
96
- if (element.name !== constants.TIMESTAMP_ATTRIBUTE) {
97
- element.metadatas = [
98
- {
99
- name: constants.TIMESTAMP_ATTRIBUTE,
100
- type: constants.TIMESTAMP_TYPE,
101
- value: timestamp.value
102
- }
103
- ];
104
- }
105
-
106
- return element;
107
- }
108
-
109
- if (entity.contextElements && entity.contextElements[0] && entity.contextElements[0].attributes) {
110
- for (const i in entity.contextElements[0].attributes) {
111
- if (entity.contextElements[0].attributes[i].name === constants.TIMESTAMP_ATTRIBUTE) {
112
- timestamp = entity.contextElements[0].attributes[i];
113
- }
114
- }
115
-
116
- if (timestamp) {
117
- entity.contextElements[0].attributes = entity.contextElements[0].attributes.map(insertMetadata);
118
- }
119
-
120
- callback(null, entity, entityType);
121
- } else {
122
- logger.error(context, 'Bad payload received while processing timestamps');
123
- callback(new errors.WrongSyntax(entity));
124
- }
125
- }
126
-
127
86
  /**
128
87
  * Looks for Thinking Thing modules and parses them, updating the entity with the transformed value.
129
88
  *
130
89
  * @param {Object} entity NGSI Entity as it would have been sent before the plugin.
131
90
  */
132
91
  function updatePlugin(entity, entityType, callback) {
133
- if (config.isCurrentNgsi()) {
134
- updatePluginNgsi2(entity, entityType, callback);
135
- } else {
136
- updatePluginNgsi1(entity, entityType, callback);
137
- }
92
+ updatePluginNgsi2(entity, entityType, callback);
138
93
  }
139
94
 
140
95
  exports.update = updatePlugin;
@@ -0,0 +1,111 @@
1
+ /*
2
+ * Copyright 2014 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
+
24
+ const got = require('got');
25
+ const logger = require('logops');
26
+ const context = {
27
+ op: 'IoTAgentNGSI.Request'
28
+ };
29
+
30
+ /**
31
+ * Transform the "request" options into "got" options and add additional "got" defaults
32
+ *
33
+ * The following options are currently exposed:
34
+ * - `method` - HTTP Method
35
+ * - `searchParams` - query string params
36
+ * - `qs` - alias for query string params
37
+ * - `headers`
38
+ * - `responseType` - either `text` or `json`. `json` is the default
39
+ * - `json` - a supplied JSON object as the request body
40
+ * - `body` - any ASCII text as the request body
41
+ * - `url` - the request URL
42
+ * - `uri` - alternative alias for the request URL.
43
+ *
44
+ * @param {Object} options Original definition of the request using the request library
45
+ * @return {Object} Updated definition of the request using the got library
46
+ *
47
+ */
48
+ function getOptions(options) {
49
+ const httpOptions = {
50
+ method: options.method,
51
+ searchParams: options.searchParams || options.qs,
52
+ headers: options.headers,
53
+ throwHttpErrors: options.throwHttpErrors || false,
54
+ retry: options.retry || 0,
55
+ responseType: options.responseType || 'json'
56
+ };
57
+
58
+ // got library is not properly documented, so it is not clear which takes precedence
59
+ // among body, json and form (see https://stackoverflow.com/q/70754880/1485926).
60
+ // Thus, we are enforcing our own precedence with the "else if" chain below.
61
+ // Behaviour is consistent with the one described at usermanual.md#iotagentlibrequest
62
+
63
+ if (options.method === 'GET' || options.method === 'HEAD' || options.method === 'OPTIONS') {
64
+ // Do nothing - Never add a body
65
+ } else if (options.body) {
66
+ // body takes precedence over json or form
67
+ httpOptions.body = options.body;
68
+ } else if (options.json) {
69
+ // json takes precedence over form
70
+ httpOptions.json = options.json;
71
+ } else if (options.form) {
72
+ // Note that we don't consider 'form' part of the function API (check usermanual.md#iotagentlibrequest)
73
+ // but we are preparing the code anyway as a safe measure
74
+ httpOptions.form = options.form;
75
+ }
76
+
77
+ return httpOptions;
78
+ }
79
+
80
+ /*
81
+ *
82
+ * Make a direct HTTP request using the underlying request library
83
+ * (currently [got](https://github.com/sindresorhus/got)),
84
+ *
85
+ * This function mimics the interface of the obsolete request library and switches
86
+ * back from promises to callbacks to avoid re-writing large chunks of code.
87
+ * This centralizes all HTTP requests in a single location and is useful
88
+ * when creating agents which use an HTTP transport for their southbound
89
+ * commands, and removes the need for the custom IoT Agent to import its own
90
+ * additonal request library.
91
+ *
92
+ * @param {Object} options Definition of the request .
93
+ * @param {Function} callback The callback function.
94
+ *
95
+ */
96
+
97
+ function request(options, callback) {
98
+ const httpOptions = getOptions(options);
99
+ logger.debug(context, 'Options: %s', JSON.stringify(options, null, 4));
100
+ got(options.url || options.uri, httpOptions)
101
+ .then((response) => {
102
+ logger.debug(context, 'Response %s', JSON.stringify(response.body, null, 4));
103
+ return callback(null, response, response.body);
104
+ })
105
+ .catch((error) => {
106
+ logger.debug(context, 'Error: %s', JSON.stringify(error, null, 4));
107
+ return callback(error);
108
+ });
109
+ }
110
+
111
+ module.exports = request;
@@ -47,6 +47,8 @@ function cleanDomain(domainToClean) {
47
47
  delete domainToClean.from;
48
48
  delete domainToClean.op;
49
49
  delete domainToClean.path;
50
+ delete domainToClean.service;
51
+ delete domainToClean.subservice;
50
52
  domainToClean.exit();
51
53
  }
52
54
 
@@ -139,8 +141,10 @@ function ensureSouthboundTransaction(context, callback) {
139
141
  reqDomain.corr = reqDomain.trans;
140
142
  }
141
143
 
142
- if (context && context.op) {
143
- reqDomain.op = context.op;
144
+ if (context) {
145
+ if (context.op) {
146
+ reqDomain.op = context.op;
147
+ }
144
148
 
145
149
  if (context.srv) {
146
150
  reqDomain.service = context.srv;