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.
- package/.github/workflows/ci.yml +17 -1
- package/.readthedocs.yml +7 -0
- package/CHANGES_NEXT_RELEASE +0 -1
- package/README.md +1 -0
- package/doc/Contribution.md +60 -1
- package/doc/advanced-topics.md +136 -14
- package/doc/api.md +38 -22
- package/doc/apiary/iotagent.apib +1 -3
- package/doc/architecture.md +2 -2
- package/doc/config-basic-example.js +0 -1
- package/doc/deprecated.md +2 -2
- package/doc/development.md +13 -6
- package/doc/expressionLanguage.md +519 -277
- package/doc/getting-started.md +0 -1
- package/doc/howto.md +13 -17
- package/doc/installationguide.md +67 -69
- package/doc/usermanual.md +48 -16
- package/docker/Mosquitto/Dockerfile +4 -9
- package/docker/Mosquitto/README.md +2 -0
- package/docker/Mosquitto/startMosquitto.sh +18 -1
- package/lib/command/commandLine.js +1 -1
- package/lib/commonConfig.js +5 -14
- package/lib/errors.js +0 -16
- package/lib/fiware-iotagent-lib.js +5 -0
- package/lib/jexlTranformsMap.js +71 -0
- package/lib/model/Command.js +1 -1
- package/lib/model/Device.js +5 -2
- package/lib/model/Group.js +20 -2
- package/lib/model/dbConn.js +7 -1
- package/lib/plugins/attributeAlias.js +6 -13
- package/lib/plugins/bidirectionalData.js +2 -27
- package/lib/plugins/expressionParser.js +41 -17
- package/lib/plugins/expressionPlugin.js +21 -27
- package/lib/plugins/jexlParser.js +71 -67
- package/lib/plugins/multiEntity.js +68 -147
- package/lib/plugins/pluginUtils.js +12 -48
- package/lib/plugins/timestampProcessPlugin.js +1 -46
- package/lib/request-shim.js +111 -0
- package/lib/services/common/domain.js +2 -2
- package/lib/services/common/genericMiddleware.js +6 -2
- package/lib/services/common/iotManagerService.js +1 -1
- package/lib/services/common/securityServiceKeystone.js +1 -1
- package/lib/services/common/securityServiceOAuth2.js +3 -2
- package/lib/services/devices/deviceRegistryMongoDB.js +29 -22
- package/lib/services/devices/deviceService.js +56 -33
- package/lib/services/devices/devices-NGSI-LD.js +42 -14
- package/lib/services/devices/devices-NGSI-mixed.js +3 -3
- package/lib/services/devices/devices-NGSI-v2.js +48 -24
- package/lib/services/devices/registrationUtils.js +1 -134
- package/lib/services/groups/groupRegistryMemory.js +2 -0
- package/lib/services/groups/groupRegistryMongoDB.js +58 -76
- package/lib/services/groups/groupService.js +1 -1
- package/lib/services/ngsi/entities-NGSI-LD.js +205 -124
- package/lib/services/ngsi/entities-NGSI-v2.js +142 -32
- package/lib/services/ngsi/ngsiService.js +4 -6
- package/lib/services/ngsi/ngsiUtils.js +0 -21
- package/lib/services/ngsi/subscription-NGSI-LD.js +14 -5
- package/lib/services/ngsi/subscriptionService.js +1 -4
- package/lib/services/northBound/contextServer-NGSI-LD.js +7 -2
- package/lib/services/northBound/contextServer-NGSI-v2.js +25 -13
- package/lib/services/northBound/contextServer.js +1 -4
- package/lib/services/northBound/contextServerUtils.js +0 -81
- package/lib/services/northBound/deviceProvisioningServer.js +36 -9
- package/lib/services/northBound/northboundServer.js +2 -0
- package/lib/services/northBound/restUtils.js +2 -39
- package/lib/templates/updateDevice.json +4 -0
- package/lib/templates/updateDeviceLax.json +4 -0
- package/package.json +13 -13
- package/test/tools/utils.js +2 -0
- package/test/unit/examples/deviceProvisioningRequests/provisionAnotherDevice.json +1 -1
- package/test/unit/examples/deviceProvisioningRequests/provisionDeviceMissingParameters.json +1 -1
- package/test/unit/examples/deviceProvisioningRequests/provisionDuplicatedDev.json +1 -1
- package/test/unit/examples/deviceProvisioningRequests/provisionFullDevice.json +1 -1
- package/test/unit/examples/deviceProvisioningRequests/provisionNewDeviceMalformed1.json +1 -1
- package/test/unit/examples/groupProvisioningRequests/multipleGroupsCreation.json +1 -1
- package/test/unit/examples/iotamRequests/registrationEmpty.json +1 -1
- package/test/unit/examples/iotamRequests/registrationWithGroups.json +2 -2
- package/test/unit/examples/iotamRequests/registrationWithGroupsWithoutCB.json +2 -2
- package/test/unit/examples/iotamRequests/registrationWithStaticGroups.json +2 -2
- package/test/unit/expressions/jexlExpression-test.js +119 -0
- package/test/unit/general/config-multi-core-test.js +1 -1
- package/test/unit/general/contextBrokerKeystoneSecurityAccess-test.js +30 -77
- package/test/unit/general/deviceService-test.js +19 -35
- package/test/unit/general/loglevel-api_test.js +8 -13
- package/test/unit/general/migration-test.js +1 -0
- package/test/unit/general/startup-test.js +3 -2
- package/test/unit/general/statistics-persistence_test.js +2 -2
- package/test/unit/general/statistics-service_test.js +2 -2
- package/test/unit/lazyAndCommands/commandRegistry_test.js +18 -18
- package/test/unit/memoryRegistry/deviceRegistryMemory_test.js +16 -24
- package/test/unit/mongodb/mongodb-connectionoptions-test.js +2 -2
- package/test/unit/mongodb/mongodb-group-registry-test.js +11 -11
- package/test/unit/mongodb/mongodb-registry-test.js +55 -131
- package/test/unit/ngsi-ld/examples/contextAvailabilityRequests/registerIoTAgent1.json +1 -1
- package/test/unit/ngsi-ld/examples/contextAvailabilityRequests/registerIoTAgent2.json +1 -1
- package/test/unit/ngsi-ld/examples/contextAvailabilityRequests/registerIoTAgent4.json +1 -1
- package/test/unit/ngsi-ld/examples/contextAvailabilityRequests/registerIoTAgentCommands.json +1 -1
- package/test/unit/ngsi-ld/examples/contextAvailabilityRequests/registerProvisionedDevice.json +1 -1
- package/test/unit/ngsi-ld/examples/contextAvailabilityRequests/registerProvisionedDevice2.json +1 -1
- package/test/unit/ngsi-ld/examples/contextAvailabilityRequests/registerProvisionedDeviceWithGroup.json +1 -1
- package/test/unit/ngsi-ld/examples/contextAvailabilityRequests/registerProvisionedDeviceWithGroup2.json +1 -1
- package/test/unit/ngsi-ld/examples/contextAvailabilityRequests/registerProvisionedDeviceWithGroup3.json +1 -1
- package/test/unit/ngsi-ld/examples/contextAvailabilityRequests/updateCommands1.json +1 -1
- package/test/unit/ngsi-ld/examples/contextAvailabilityRequests/updateIoTAgent1.json +1 -1
- package/test/unit/ngsi-ld/examples/contextAvailabilityRequests/updateIoTAgent2.json +1 -1
- package/test/unit/ngsi-ld/examples/contextAvailabilityRequests/updateIoTAgent3.json +1 -1
- package/test/unit/ngsi-ld/examples/contextRequests/createMinimumProvisionedDevice.json +0 -7
- package/test/unit/ngsi-ld/examples/contextRequests/createProvisionedDevice.json +0 -7
- package/test/unit/ngsi-ld/examples/contextRequests/createProvisionedDeviceMultientity.json +0 -7
- package/test/unit/ngsi-ld/examples/contextRequests/createProvisionedDeviceWithGroupAndStatic.json +0 -14
- package/test/unit/ngsi-ld/examples/contextRequests/createProvisionedDeviceWithGroupAndStatic2.json +0 -14
- package/test/unit/ngsi-ld/examples/contextRequests/createProvisionedDeviceWithGroupAndStatic3.json +1 -15
- package/test/unit/ngsi-ld/examples/contextRequests/createTimeInstantMinimumDevice.json +0 -7
- package/test/unit/ngsi-ld/examples/contextRequests/updateContextAliasPlugin6.json +0 -7
- package/test/unit/ngsi-ld/examples/contextRequests/updateContextAutocast5.json +0 -7
- package/test/unit/ngsi-ld/examples/contextRequests/updateContextExpressionPlugin12a.json +7 -0
- package/test/unit/ngsi-ld/examples/contextRequests/updateContextExpressionPlugin13.json +13 -13
- package/test/unit/ngsi-ld/examples/contextRequests/updateContextExpressionPlugin16.json +0 -7
- package/test/unit/ngsi-ld/examples/contextRequests/updateContextExpressionPlugin17.json +0 -7
- package/test/unit/ngsi-ld/examples/contextRequests/updateContextExpressionPlugin1a.json +18 -0
- package/test/unit/ngsi-ld/examples/contextRequests/updateContextExpressionPlugin29.json +18 -0
- package/test/unit/ngsi-ld/examples/contextRequests/updateContextExpressionPlugin31.json +15 -0
- package/test/unit/ngsi-ld/examples/contextRequests/updateContextExpressionPlugin32.json +17 -0
- package/test/unit/ngsi-ld/examples/contextRequests/updateContextExpressionPlugin33.json +18 -0
- package/test/unit/ngsi-ld/examples/contextRequests/updateContextExpressionPlugin34.json +17 -0
- package/test/unit/ngsi-ld/examples/contextRequests/updateContextExpressionPlugin4a.json +36 -0
- package/test/unit/ngsi-ld/examples/contextRequests/updateContextExpressionPlugin5.json +0 -7
- package/test/unit/ngsi-ld/examples/contextRequests/updateContextExpressionPlugin7.json +16 -16
- package/test/unit/ngsi-ld/examples/contextRequests/updateContextExpressionPlugin8a.json +18 -0
- package/test/unit/ngsi-ld/examples/contextRequests/updateContextGeoproperties3.json +0 -7
- package/test/unit/ngsi-ld/examples/contextRequests/updateContextMultientityPlugin15.json +25 -0
- package/test/unit/ngsi-ld/examples/contextRequests/updateContextMultientityTimestampPlugin1.json +6 -6
- package/test/unit/ngsi-ld/examples/contextRequests/updateContextMultientityTimestampPlugin2.json +3 -3
- package/test/unit/ngsi-ld/examples/contextRequests/updateProvisionActiveAttributes1.json +0 -7
- package/test/unit/ngsi-ld/examples/contextRequests/updateProvisionCommands1.json +0 -7
- package/test/unit/ngsi-ld/examples/contextRequests/updateProvisionDeviceStatic.json +0 -7
- package/test/unit/ngsi-ld/examples/contextRequests/updateProvisionMinimumDevice.json +0 -7
- package/test/unit/ngsi-ld/examples/subscriptionRequests/bidirectionalSubscriptionRequest.json +20 -17
- package/test/unit/ngsi-ld/examples/subscriptionRequests/simpleSubscriptionRequest.json +18 -15
- package/test/unit/ngsi-ld/examples/subscriptionRequests/simpleSubscriptionRequest2.json +18 -15
- package/test/unit/ngsi-ld/expressions/expressionBasedTransformations-test.js +21 -21
- package/test/unit/ngsi-ld/expressions/jexlBasedTransformations-test.js +1018 -0
- package/test/unit/ngsi-ld/general/config-jsonld-contexts-test.js +2 -2
- package/test/unit/ngsi-ld/general/contextBrokerOAuthSecurityAccess-test.js +24 -24
- package/test/unit/ngsi-ld/general/deviceService-test.js +7 -7
- package/test/unit/ngsi-ld/general/https-support-test.js +14 -13
- package/test/unit/ngsi-ld/general/iotam-autoregistration-test.js +8 -7
- package/test/unit/ngsi-ld/general/startup-test.js +2 -1
- package/test/unit/ngsi-ld/lazyAndCommands/active-devices-attribute-update-test.js +10 -8
- package/test/unit/ngsi-ld/lazyAndCommands/command-test.js +11 -12
- package/test/unit/ngsi-ld/lazyAndCommands/lazy-devices-test.js +25 -29
- package/test/unit/ngsi-ld/lazyAndCommands/polling-commands-test.js +16 -15
- package/test/unit/ngsi-ld/ngsiService/active-devices-test.js +18 -17
- package/test/unit/ngsi-ld/ngsiService/autocast-test.js +13 -12
- package/test/unit/ngsi-ld/ngsiService/geoproperties-test.js +10 -9
- package/test/unit/ngsi-ld/ngsiService/staticAttributes-test.js +3 -3
- package/test/unit/ngsi-ld/ngsiService/subscriptions-test.js +25 -24
- package/test/unit/ngsi-ld/plugins/alias-plugin_test.js +13 -12
- package/test/unit/ngsi-ld/plugins/bidirectional-plugin_test.js +27 -26
- package/test/unit/ngsi-ld/plugins/compress-timestamp-plugin_test.js +5 -5
- package/test/unit/ngsi-ld/plugins/event-plugin_test.js +3 -3
- package/test/unit/ngsi-ld/plugins/multientity-plugin_test.js +75 -14
- package/test/unit/ngsi-ld/plugins/timestamp-processing-plugin_test.js +3 -3
- package/test/unit/ngsi-ld/provisioning/device-provisioning-api_test.js +54 -53
- package/test/unit/ngsi-ld/provisioning/device-registration_test.js +20 -19
- package/test/unit/ngsi-ld/provisioning/device-update-registration_test.js +23 -22
- package/test/unit/ngsi-ld/provisioning/listProvisionedDevices-test.js +58 -70
- package/test/unit/ngsi-ld/provisioning/provisionDeviceMultientity-test.js +8 -7
- package/test/unit/ngsi-ld/provisioning/removeProvisionedDevice-test.js +19 -19
- package/test/unit/ngsi-ld/provisioning/singleConfigurationMode-test.js +18 -20
- package/test/unit/ngsi-ld/provisioning/updateProvisionedDevices-test.js +43 -49
- package/test/unit/ngsi-mixed/provisioning/ngsi-versioning-test.js +16 -14
- package/test/unit/ngsiv2/examples/contextAvailabilityRequests/registerIoTAgent1.json +1 -1
- package/test/unit/ngsiv2/examples/contextAvailabilityRequests/registerIoTAgent2.json +1 -1
- package/test/unit/ngsiv2/examples/contextAvailabilityRequests/registerIoTAgent3.json +19 -0
- package/test/unit/ngsiv2/examples/contextAvailabilityRequests/registerIoTAgent4.json +1 -1
- package/test/unit/ngsiv2/examples/contextAvailabilityRequests/registerIoTAgent5.json +19 -0
- package/test/unit/ngsiv2/examples/contextAvailabilityRequests/registerIoTAgentCommands.json +1 -1
- package/test/unit/ngsiv2/examples/contextAvailabilityRequests/registerProvisionedDevice.json +1 -1
- package/test/unit/ngsiv2/examples/contextAvailabilityRequests/registerProvisionedDevice2.json +1 -1
- package/test/unit/ngsiv2/examples/contextAvailabilityRequests/registerProvisionedDeviceWithGroup.json +1 -1
- package/test/unit/ngsiv2/examples/contextAvailabilityRequests/registerProvisionedDeviceWithGroup2.json +1 -1
- package/test/unit/ngsiv2/examples/contextAvailabilityRequests/registerProvisionedDeviceWithGroup3.json +1 -1
- package/test/unit/ngsiv2/examples/contextAvailabilityRequests/updateCommands1.json +3 -3
- package/test/unit/ngsiv2/examples/contextAvailabilityRequests/updateIoTAgent1.json +3 -3
- package/test/unit/ngsiv2/examples/contextAvailabilityRequests/updateIoTAgent2.json +1 -1
- package/test/unit/ngsiv2/examples/contextAvailabilityRequests/updateIoTAgent3.json +1 -1
- package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin1.json +17 -1
- package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin11.json +5 -1
- package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin12.json +2 -2
- package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin15.json +6 -0
- package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin16.json +14 -0
- package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin17.json +14 -0
- package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin18.json +6 -0
- package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin19.json +6 -0
- package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin2.json +13 -1
- package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin20.json +6 -0
- package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin21.json +6 -0
- package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin22.json +6 -0
- package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin23.json +6 -0
- package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin24.json +6 -0
- package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin25.json +6 -0
- package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin26.json +6 -0
- package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin27.json +6 -0
- package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin28.json +6 -0
- package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin29.json +22 -0
- package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin3.json +5 -1
- package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin30.json +6 -0
- package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin31.json +18 -0
- package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin32.json +16 -0
- package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin33.json +22 -0
- package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin34.json +12 -0
- package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin4.json +12 -0
- package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin5.json +5 -1
- package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin6.json +5 -1
- package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin7.json +5 -1
- package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin8.json +17 -1
- package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin9.json +5 -1
- package/test/unit/ngsiv2/examples/contextRequests/updateContextMiddleware1.json +10 -0
- package/test/unit/ngsiv2/examples/contextRequests/updateContextMiddleware2.json +10 -0
- package/test/unit/ngsiv2/examples/contextRequests/updateContextMultientityPlugin1.json +2 -2
- package/test/unit/ngsiv2/examples/contextRequests/updateContextMultientityPlugin10.json +1 -1
- package/test/unit/ngsiv2/examples/contextRequests/updateContextMultientityPlugin11.json +13 -0
- package/test/unit/ngsiv2/examples/contextRequests/updateContextMultientityPlugin12.json +33 -0
- package/test/unit/ngsiv2/examples/contextRequests/updateContextMultientityPlugin13.json +33 -0
- package/test/unit/ngsiv2/examples/contextRequests/updateContextMultientityPlugin14.json +33 -0
- package/test/unit/ngsiv2/examples/contextRequests/updateContextMultientityPlugin15.json +25 -0
- package/test/unit/ngsiv2/examples/contextRequests/updateContextMultientityPlugin16.json +25 -0
- package/test/unit/ngsiv2/examples/contextRequests/updateContextMultientityPlugin2.json +2 -2
- package/test/unit/ngsiv2/examples/contextRequests/updateContextMultientityPlugin3.json +1 -1
- package/test/unit/ngsiv2/examples/contextRequests/updateContextMultientityPlugin4.json +1 -1
- package/test/unit/ngsiv2/examples/contextRequests/updateContextMultientityPlugin5.json +1 -1
- package/test/unit/ngsiv2/examples/contextRequests/updateContextMultientityPlugin6.json +1 -1
- package/test/unit/ngsiv2/examples/contextRequests/updateContextMultientityPlugin7.json +1 -1
- package/test/unit/ngsiv2/examples/contextRequests/updateContextMultientityPlugin8.json +2 -2
- package/test/unit/ngsiv2/examples/contextRequests/updateContextMultientityPlugin9.json +1 -1
- package/test/unit/ngsiv2/examples/contextRequests/updateContextMultientityTimestampPlugin1.json +8 -8
- package/test/unit/ngsiv2/examples/contextRequests/updateContextMultientityTimestampPlugin2.json +4 -4
- package/test/unit/ngsiv2/examples/contextRequests/updateContextMultientityTimestampPlugin3.json +1 -1
- package/test/unit/ngsiv2/examples/contextRequests/updateContextMultientityTimestampPlugin4.json +2 -2
- package/test/unit/ngsiv2/examples/contextRequests/updateProvisionDevice.json +20 -0
- package/test/unit/ngsiv2/examples/subscriptionRequests/bidirectionalSubscriptionRequest.json +1 -1
- package/test/unit/ngsiv2/examples/subscriptionRequests/simpleSubscriptionRequest.json +1 -1
- package/test/unit/ngsiv2/examples/subscriptionRequests/simpleSubscriptionRequest2.json +1 -1
- package/test/unit/ngsiv2/expressions/expressionBasedTransformations-test.js +93 -60
- package/test/unit/ngsiv2/expressions/expressionCombinedTransformations-test.js +16 -16
- package/test/unit/ngsiv2/expressions/jexlBasedTransformations-test.js +548 -164
- package/test/unit/ngsiv2/general/contextBrokerOAuthSecurityAccess-test.js +34 -33
- package/test/unit/ngsiv2/general/deviceService-test.js +15 -14
- package/test/unit/ngsiv2/general/https-support-test.js +14 -13
- package/test/unit/ngsiv2/general/iotam-autoregistration-test.js +8 -7
- package/test/unit/ngsiv2/general/startup-test.js +2 -1
- package/test/unit/ngsiv2/lazyAndCommands/active-devices-attribute-update-test.js +9 -7
- package/test/unit/ngsiv2/lazyAndCommands/command-test.js +13 -12
- package/test/unit/ngsiv2/lazyAndCommands/lazy-devices-test.js +323 -51
- package/test/unit/ngsiv2/lazyAndCommands/polling-commands-test.js +22 -20
- package/test/unit/ngsiv2/ngsiService/active-devices-test.js +114 -26
- package/test/unit/ngsiv2/ngsiService/autocast-test.js +16 -16
- package/test/unit/ngsiv2/ngsiService/geoproperties-test.js +39 -38
- package/test/unit/{ngsiService → ngsiv2/ngsiService}/queryDeviceInformationInCb-test.js +25 -54
- package/test/unit/ngsiv2/ngsiService/staticAttributes-test.js +5 -5
- package/test/unit/ngsiv2/ngsiService/subscriptions-test.js +25 -24
- package/test/unit/ngsiv2/plugins/alias-plugin_test.js +22 -22
- package/test/unit/ngsiv2/plugins/bidirectional-plugin_test.js +27 -26
- package/test/unit/ngsiv2/plugins/compress-timestamp-plugin_test.js +7 -7
- package/test/unit/ngsiv2/plugins/event-plugin_test.js +4 -4
- package/test/unit/ngsiv2/plugins/multientity-plugin_test.js +549 -24
- package/test/unit/ngsiv2/plugins/timestamp-processing-plugin_test.js +4 -4
- package/test/unit/{plugins → ngsiv2/plugins}/translation-inPlugins_test.js +25 -25
- package/test/unit/{provisioning → ngsiv2/provisioning}/device-group-api-test.js +44 -75
- package/test/unit/{provisioning/device-group-utils_test.js → ngsiv2/provisioning/device-group-utils-test.js} +15 -14
- package/test/unit/ngsiv2/provisioning/device-provisioning-api_test.js +74 -73
- package/test/unit/ngsiv2/provisioning/device-registration_test.js +20 -19
- package/test/unit/ngsiv2/provisioning/device-update-registration_test.js +30 -29
- package/test/unit/ngsiv2/provisioning/listProvisionedDevices-test.js +58 -69
- package/test/unit/ngsiv2/provisioning/provisionDeviceMultientity-test.js +8 -7
- package/test/unit/ngsiv2/provisioning/removeProvisionedDevice-test.js +19 -19
- package/test/unit/ngsiv2/provisioning/singleConfigurationMode-test.js +18 -19
- package/test/unit/ngsiv2/provisioning/updateProvisionedDevices-test.js +49 -52
- package/test/unit/plugins/capture-configuration-inPlugins_test.js +6 -4
- package/test/unit/plugins/capture-provision-inPlugins_test.js +13 -23
- package/.nyc_output/016aca19-69bf-4681-9b41-2835c5131681.json +0 -1
- package/.nyc_output/processinfo/016aca19-69bf-4681-9b41-2835c5131681.json +0 -1
- package/.nyc_output/processinfo/index.json +0 -1
- package/lib/services/devices/devices-NGSI-v1.js +0 -293
- package/lib/services/devices/registrationUtils.js_avega +0 -589
- package/lib/services/ngsi/entities-NGSI-v1.js +0 -300
- package/lib/services/ngsi/subscription-NGSI-v1.js +0 -234
- package/lib/services/northBound/contextServer-NGSI-v1.js +0 -526
- package/lib/templates/notificationTemplateNgsi1.json +0 -75
- package/lib/templates/updateContextNgsi1.json +0 -50
- package/test/unit/examples/contextAvailabilityRequests/registerIoTAgent1.json +0 -21
- package/test/unit/examples/contextAvailabilityRequests/registerIoTAgent2.json +0 -21
- package/test/unit/examples/contextAvailabilityRequests/registerIoTAgent3.json +0 -25
- package/test/unit/examples/contextAvailabilityRequests/registerIoTAgent4.json +0 -22
- package/test/unit/examples/contextAvailabilityRequests/registerIoTAgentAttributeUpdates.json +0 -16
- package/test/unit/examples/contextAvailabilityRequests/registerIoTAgentCommands.json +0 -21
- package/test/unit/examples/contextAvailabilityRequests/registerNewDevice1.json +0 -21
- package/test/unit/examples/contextAvailabilityRequests/registerNewDevice2.json +0 -21
- package/test/unit/examples/contextAvailabilityRequests/registerProvisionedDevice.json +0 -25
- package/test/unit/examples/contextAvailabilityRequests/registerProvisionedDevice2.json +0 -21
- package/test/unit/examples/contextAvailabilityRequests/registerProvisionedDeviceWithGroup.json +0 -33
- package/test/unit/examples/contextAvailabilityRequests/registerProvisionedDeviceWithGroup2.json +0 -33
- package/test/unit/examples/contextAvailabilityRequests/unregisterDevice1.json +0 -22
- package/test/unit/examples/contextAvailabilityRequests/unregisterDevice3.json +0 -26
- package/test/unit/examples/contextAvailabilityRequests/unregisterProvisionedDevice.json +0 -26
- package/test/unit/examples/contextAvailabilityRequests/updateCommands1.json +0 -22
- package/test/unit/examples/contextAvailabilityRequests/updateIoTAgent1.json +0 -22
- package/test/unit/examples/contextAvailabilityRequests/updateIoTAgent2.json +0 -26
- package/test/unit/examples/contextAvailabilityRequests/updateIoTAgent3.json +0 -22
- package/test/unit/examples/contextAvailabilityResponses/registerIoTAgent1Failed.json +0 -8
- package/test/unit/examples/contextAvailabilityResponses/registerIoTAgent1Success.json +0 -4
- package/test/unit/examples/contextAvailabilityResponses/registerNewDevice1Success.json +0 -4
- package/test/unit/examples/contextAvailabilityResponses/registerNewDevice2Success.json +0 -4
- package/test/unit/examples/contextAvailabilityResponses/registerProvisionedDeviceSuccess.json +0 -4
- package/test/unit/examples/contextAvailabilityResponses/unregisterDevice1Failed.json +0 -8
- package/test/unit/examples/contextAvailabilityResponses/unregisterDevice1Success.json +0 -4
- package/test/unit/examples/contextAvailabilityResponses/updateCommands1Success.json +0 -4
- package/test/unit/examples/contextAvailabilityResponses/updateIoTAgent1Success.json +0 -6
- package/test/unit/examples/contextProviderResponses/queryInformationResponse.json +0 -22
- package/test/unit/examples/contextProviderResponses/queryInformationResponseEmptyAttributes.json +0 -22
- package/test/unit/examples/contextProviderResponses/queryInformationStaticAttributesResponse.json +0 -27
- package/test/unit/examples/contextProviderResponses/updateInformationResponse.json +0 -22
- package/test/unit/examples/contextProviderResponses/updateInformationResponse2.json +0 -22
- package/test/unit/examples/contextRequests/contextSubscriptionRequest.json +0 -20
- package/test/unit/examples/contextRequests/contextSubscriptionRequest2.json +0 -20
- package/test/unit/examples/contextRequests/createBidirectionalDevice.json +0 -17
- package/test/unit/examples/contextRequests/createDatetimeProvisionedDevice.json +0 -17
- package/test/unit/examples/contextRequests/createGeopointProvisionedDevice.json +0 -17
- package/test/unit/examples/contextRequests/createMinimumProvisionedDevice.json +0 -17
- package/test/unit/examples/contextRequests/createProvisionedDevice.json +0 -32
- package/test/unit/examples/contextRequests/createProvisionedDeviceMultientity.json +0 -32
- package/test/unit/examples/contextRequests/createProvisionedDeviceWithGroup.json +0 -47
- package/test/unit/examples/contextRequests/createProvisionedDeviceWithGroupAndStatic.json +0 -52
- package/test/unit/examples/contextRequests/createProvisionedDeviceWithGroupAndStatic2.json +0 -52
- package/test/unit/examples/contextRequests/createTimeinstantDevice.json +0 -17
- package/test/unit/examples/contextRequests/queryContext1.json +0 -13
- package/test/unit/examples/contextRequests/queryContext2.json +0 -13
- package/test/unit/examples/contextRequests/queryContextAliasPlugin1.json +0 -10
- package/test/unit/examples/contextRequests/queryContextCompressTimestamp1.json +0 -13
- package/test/unit/examples/contextRequests/updateActiveAttributes.json +0 -11
- package/test/unit/examples/contextRequests/updateContext1.json +0 -22
- package/test/unit/examples/contextRequests/updateContext2.json +0 -22
- package/test/unit/examples/contextRequests/updateContext3.json +0 -17
- package/test/unit/examples/contextRequests/updateContext3WithStatic.json +0 -22
- package/test/unit/examples/contextRequests/updateContext4.json +0 -22
- package/test/unit/examples/contextRequests/updateContext5.json +0 -19
- package/test/unit/examples/contextRequests/updateContextAliasPlugin.json +0 -22
- package/test/unit/examples/contextRequests/updateContextAliasPlugin2.json +0 -17
- package/test/unit/examples/contextRequests/updateContextAppendMode.json +0 -22
- package/test/unit/examples/contextRequests/updateContextCommandError.json +0 -22
- package/test/unit/examples/contextRequests/updateContextCommandExpired.json +0 -22
- package/test/unit/examples/contextRequests/updateContextCommandFinish.json +0 -22
- package/test/unit/examples/contextRequests/updateContextCommandStatus.json +0 -17
- package/test/unit/examples/contextRequests/updateContextCompressTimestamp1.json +0 -22
- package/test/unit/examples/contextRequests/updateContextCompressTimestamp2.json +0 -29
- package/test/unit/examples/contextRequests/updateContextExpressionPlugin1.json +0 -17
- package/test/unit/examples/contextRequests/updateContextExpressionPlugin2.json +0 -27
- package/test/unit/examples/contextRequests/updateContextExpressionPlugin3.json +0 -17
- package/test/unit/examples/contextRequests/updateContextExpressionPlugin4.json +0 -17
- package/test/unit/examples/contextRequests/updateContextExpressionPlugin5.json +0 -27
- package/test/unit/examples/contextRequests/updateContextMiddleware1.json +0 -22
- package/test/unit/examples/contextRequests/updateContextMultiEntityPlugin3.json +0 -35
- package/test/unit/examples/contextRequests/updateContextMultientityPlugin1.json +0 -30
- package/test/unit/examples/contextRequests/updateContextMultientityPlugin2.json +0 -30
- package/test/unit/examples/contextRequests/updateContextProcessTimestamp1.json +0 -29
- package/test/unit/examples/contextRequests/updateContextStaticAttributes.json +0 -22
- package/test/unit/examples/contextRequests/updateContextTimestamp.json +0 -41
- package/test/unit/examples/contextRequests/updateContextTimestampOverride.json +0 -22
- package/test/unit/examples/contextRequests/updateContextTimestampOverrideWithoutMilis.json +0 -22
- package/test/unit/examples/contextRequests/updateContextTimestampTimezone.json +0 -41
- package/test/unit/examples/contextRequests/updateProvisionActiveAttributes1.json +0 -17
- package/test/unit/examples/contextRequests/updateProvisionCommands1.json +0 -27
- package/test/unit/examples/contextRequests/updateProvisionDeviceStatic.json +0 -38
- package/test/unit/examples/contextRequests/updateProvisionMinimumDevice.json +0 -17
- package/test/unit/examples/contextResponses/contextSubscriptionRequest2Success.json +0 -7
- package/test/unit/examples/contextResponses/contextSubscriptionRequestSuccess.json +0 -7
- package/test/unit/examples/contextResponses/createBidirectionalDeviceSuccess.json +0 -22
- package/test/unit/examples/contextResponses/createDatetimeProvisionedDeviceSuccess.json +0 -22
- package/test/unit/examples/contextResponses/createGeopointProvisionedDeviceSuccess.json +0 -22
- package/test/unit/examples/contextResponses/createProvisionedDeviceSuccess.json +0 -22
- package/test/unit/examples/contextResponses/createTimeinstantSuccess.json +0 -22
- package/test/unit/examples/contextResponses/queryContext1Success.json +0 -27
- package/test/unit/examples/contextResponses/queryContext2Error.json +0 -7
- package/test/unit/examples/contextResponses/queryContext2UnknownError.json +0 -6
- package/test/unit/examples/contextResponses/queryContext3Error.json +0 -34
- package/test/unit/examples/contextResponses/queryContextAliasPlugin1Success.json +0 -27
- package/test/unit/examples/contextResponses/queryContextCompressTimestamp1Success.json +0 -27
- package/test/unit/examples/contextResponses/updateActiveAttributesSuccess.json +0 -16
- package/test/unit/examples/contextResponses/updateContext1Failed.json +0 -7
- package/test/unit/examples/contextResponses/updateContext1Success.json +0 -27
- package/test/unit/examples/contextResponses/updateContext2Failed.json +0 -35
- package/test/unit/examples/contextResponses/updateContextAliasPlugin2Success.json +0 -27
- package/test/unit/examples/contextResponses/updateContextAliasPluginSuccess.json +0 -27
- package/test/unit/examples/contextResponses/updateContextCommandFinishSuccess.json +0 -27
- package/test/unit/examples/contextResponses/updateContextCommandStatusSuccess.json +0 -22
- package/test/unit/examples/contextResponses/updateContextCompressTimestamp1Success.json +0 -27
- package/test/unit/examples/contextResponses/updateContextCompressTimestamp2Success.json +0 -34
- package/test/unit/examples/contextResponses/updateContextEvents1Success.json +0 -27
- package/test/unit/examples/contextResponses/updateContextExpressionPlugin1Success.json +0 -22
- package/test/unit/examples/contextResponses/updateContextExpressionPlugin2Success.json +0 -22
- package/test/unit/examples/contextResponses/updateContextExpressionPlugin3Success.json +0 -22
- package/test/unit/examples/contextResponses/updateContextExpressionPlugin5Success.json +0 -32
- package/test/unit/examples/contextResponses/updateContextMultientityPlugin1Success.json +0 -40
- package/test/unit/examples/contextResponses/updateContextMultientityPlugin2Success.json +0 -40
- package/test/unit/examples/contextResponses/updateContextMultientityPlugin3Success.json +0 -40
- package/test/unit/examples/contextResponses/updateContextProcessTimestamp1Success.json +0 -27
- package/test/unit/examples/contextResponses/updateProvisionActiveAttributes1Success.json +0 -22
- package/test/unit/examples/contextResponses/updateProvisionCommands1Success.json +0 -32
- package/test/unit/examples/contextResponses/updateProvisionMinimumDeviceSuccess.json +0 -22
- package/test/unit/examples/subscriptionRequests/bidirectionalNotification.json +0 -24
- package/test/unit/examples/subscriptionRequests/bidirectionalSubscriptionRemove.json +0 -3
- package/test/unit/examples/subscriptionRequests/bidirectionalSubscriptionRequest.json +0 -22
- package/test/unit/examples/subscriptionRequests/errorNotification.json +0 -24
- package/test/unit/examples/subscriptionRequests/simpleNotification.json +0 -24
- package/test/unit/examples/subscriptionRequests/simpleSubscriptionRemove.json +0 -3
- package/test/unit/examples/subscriptionRequests/simpleSubscriptionRequest.json +0 -19
- package/test/unit/examples/subscriptionRequests/simpleSubscriptionRequest1.json +0 -19
- package/test/unit/examples/subscriptionResponses/bidirectionalSubscriptionSuccess.json +0 -6
- package/test/unit/examples/subscriptionResponses/simpleSubscriptionSuccess.json +0 -6
- package/test/unit/expressions/expressionBasedTransformations-test.js +0 -328
- package/test/unit/expressions/expressionCombinedTransformations-test.js +0 -306
- package/test/unit/expressions/jexlBasedTransformations-test.js +0 -334
- package/test/unit/general/contextBrokerOAuthSecurityAccess-test.js +0 -902
- package/test/unit/general/https-support-test.js +0 -286
- package/test/unit/general/iotam-autoregistration-test.js +0 -368
- package/test/unit/lazyAndCommands/active-devices-attribute-update-test.js +0 -168
- package/test/unit/lazyAndCommands/command-test.js +0 -341
- package/test/unit/lazyAndCommands/lazy-devices-test.js +0 -878
- package/test/unit/lazyAndCommands/polling-commands-test.js +0 -421
- package/test/unit/ngsi-ld/examples/contextRequests/updateContextExpressionPlugin20.json +0 -25
- package/test/unit/ngsiService/active-devices-test.js +0 -692
- package/test/unit/ngsiService/staticAttributes-test.js +0 -148
- package/test/unit/ngsiService/subscriptions-test.js +0 -345
- package/test/unit/plugins/alias-plugin_test.js +0 -158
- package/test/unit/plugins/bidirectional-plugin_test.js +0 -564
- package/test/unit/plugins/compress-timestamp-plugin_test.js +0 -257
- package/test/unit/plugins/event-plugin_test.js +0 -119
- package/test/unit/plugins/multientity-plugin_test.js +0 -248
- package/test/unit/plugins/timestamp-processing-plugin_test.js +0 -119
- package/test/unit/provisioning/device-provisioning-api_test.js +0 -748
- package/test/unit/provisioning/device-registration_test.js +0 -432
- package/test/unit/provisioning/device-update-registration_test.js +0 -326
- package/test/unit/provisioning/listProvisionedDevices-test.js +0 -488
- package/test/unit/provisioning/provisionDeviceMultientity-test.js +0 -123
- package/test/unit/provisioning/removeProvisionedDevice-test.js +0 -244
- package/test/unit/provisioning/singleConfigurationMode-test.js +0 -346
- package/test/unit/provisioning/updateProvisionedDevices-test.js +0 -436
|
@@ -41,20 +41,19 @@ const utils = require('./pluginUtils');
|
|
|
41
41
|
/* eslint-disable-next-line no-unused-vars */
|
|
42
42
|
const aliasPlugin = require('./attributeAlias');
|
|
43
43
|
|
|
44
|
-
|
|
45
44
|
function checkJexl(typeInformation) {
|
|
46
45
|
if (
|
|
47
46
|
config.getConfig().defaultExpressionLanguage === 'jexl' &&
|
|
48
|
-
|
|
49
|
-
|
|
47
|
+
typeInformation.expressionLanguage &&
|
|
48
|
+
typeInformation.expressionLanguage !== 'legacy'
|
|
50
49
|
) {
|
|
51
50
|
return true;
|
|
52
51
|
} else if (config.getConfig().defaultExpressionLanguage === 'jexl' && !typeInformation.expressionLanguage) {
|
|
53
52
|
return true;
|
|
54
53
|
} else if (
|
|
55
54
|
config.getConfig().defaultExpressionLanguage === 'legacy' &&
|
|
56
|
-
|
|
57
|
-
|
|
55
|
+
typeInformation.expressionLanguage &&
|
|
56
|
+
typeInformation.expressionLanguage === 'jexl'
|
|
58
57
|
) {
|
|
59
58
|
return true;
|
|
60
59
|
}
|
|
@@ -65,19 +64,6 @@ function hasEntityName(item) {
|
|
|
65
64
|
return item.entity_name;
|
|
66
65
|
}
|
|
67
66
|
|
|
68
|
-
/**
|
|
69
|
-
* Return a list of all the attributes that don't have a multientity option. It considers NGSIv1.
|
|
70
|
-
*
|
|
71
|
-
* @param {Array} originalAttrs Array of original attributes coming from the single-entity device.
|
|
72
|
-
* @param {Array} meAttributes Array of all the multientity attributes.
|
|
73
|
-
* @return {Array} List of all the attrbiutes without multientity flag.
|
|
74
|
-
*/
|
|
75
|
-
function filterOutMultientitiesNgsi1(originalAttrs, meAttributes) {
|
|
76
|
-
return originalAttrs.filter(function (item) {
|
|
77
|
-
return !_.contains(meAttributes, item.name);
|
|
78
|
-
});
|
|
79
|
-
}
|
|
80
|
-
|
|
81
67
|
/**
|
|
82
68
|
* Return a list of all the attributes that don't have a multientity option. It considers NGSIv2.
|
|
83
69
|
*
|
|
@@ -87,8 +73,8 @@ function filterOutMultientitiesNgsi1(originalAttrs, meAttributes) {
|
|
|
87
73
|
*/
|
|
88
74
|
function filterOutMultientitiesNgsi2(originalAttrs, meAttributes) {
|
|
89
75
|
const result = {};
|
|
90
|
-
const meNamesList = _.pluck(
|
|
91
|
-
const meObjectsList = _.pluck(
|
|
76
|
+
const meNamesList = _.pluck(meAttributes, 'name');
|
|
77
|
+
const meObjectsList = _.pluck(meAttributes, 'object_id');
|
|
92
78
|
let toBeFilteredByObj = [];
|
|
93
79
|
|
|
94
80
|
for (const att in originalAttrs) {
|
|
@@ -96,11 +82,14 @@ function filterOutMultientitiesNgsi2(originalAttrs, meAttributes) {
|
|
|
96
82
|
if (!_.contains(meNamesList, att)) {
|
|
97
83
|
result[att] = originalAttrs[att];
|
|
98
84
|
}
|
|
99
|
-
if (originalAttrs[att].hasOwnProperty('multi')){
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
85
|
+
if (originalAttrs[att].hasOwnProperty('multi')) {
|
|
86
|
+
let cleanAttributes = _.union([_.clone(originalAttrs[att])], originalAttrs[att].multi);
|
|
87
|
+
delete cleanAttributes[0].multi;
|
|
88
|
+
cleanAttributes = _.map(cleanAttributes, function (val) {
|
|
89
|
+
val['name'] = att;
|
|
90
|
+
return val;
|
|
91
|
+
});
|
|
92
|
+
toBeFilteredByObj = _.union(toBeFilteredByObj, cleanAttributes);
|
|
104
93
|
}
|
|
105
94
|
}
|
|
106
95
|
}
|
|
@@ -114,85 +103,30 @@ function filterOutMultientitiesNgsi2(originalAttrs, meAttributes) {
|
|
|
114
103
|
return result;
|
|
115
104
|
}
|
|
116
105
|
|
|
117
|
-
/**
|
|
118
|
-
* Generate new Context Elements for each new Entity, with the attributes of the original entity matching its
|
|
119
|
-
* entity_name. It considers Ngsiv1.
|
|
120
|
-
*
|
|
121
|
-
* @param {Object} entity The original entity
|
|
122
|
-
* @param {Array} newEntities List of the new entities that will be generated
|
|
123
|
-
* @param {Array} entityTypes Map of the types for each entity ID
|
|
124
|
-
* @param {Object} typeInformation Object with all the data about the device type
|
|
125
|
-
* @param {Array} multiEntityAttributes List of attributes with multientity option
|
|
126
|
-
* @return {Array} List of the new Context Entities
|
|
127
|
-
*/
|
|
128
|
-
function generateNewCEsNgsi1(entity, newEntities, entityTypes, typeInformation, multiEntityAttributes) {
|
|
129
|
-
const result = [];
|
|
130
|
-
let newEntityAttributes;
|
|
131
|
-
let newEntityAttributeNames;
|
|
132
|
-
let entityName;
|
|
133
|
-
let parser = legacyParser;
|
|
134
|
-
if (checkJexl(typeInformation)) {
|
|
135
|
-
parser = jexlParser;
|
|
136
|
-
}
|
|
137
|
-
function filterByEntityName(entityName) {
|
|
138
|
-
return function (item) {
|
|
139
|
-
return item.entity_name === entityName;
|
|
140
|
-
};
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
function filterByAttributeNames(item) {
|
|
144
|
-
return _.contains(newEntityAttributeNames, item.name);
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
const ctx = parser.extractContext(entity.contextElements[0].attributes);
|
|
148
|
-
|
|
149
|
-
for (let i = 0; i < newEntities.length; i++) {
|
|
150
|
-
newEntityAttributeNames = _.pluck(multiEntityAttributes.filter(filterByEntityName(newEntities[i])), 'name');
|
|
151
|
-
|
|
152
|
-
newEntityAttributes = entity.contextElements[0].attributes.filter(filterByAttributeNames);
|
|
153
|
-
// Fix duplicated attributes in entity
|
|
154
|
-
newEntityAttributes = _.uniq(newEntityAttributes, JSON.stringify);
|
|
155
|
-
entityName = parser.applyExpression(newEntities[i], ctx, typeInformation);
|
|
156
|
-
|
|
157
|
-
result.push({
|
|
158
|
-
type: entityTypes[newEntities[i]],
|
|
159
|
-
isPattern: 'false',
|
|
160
|
-
id: entityName,
|
|
161
|
-
attributes: newEntityAttributes
|
|
162
|
-
});
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
return result;
|
|
166
|
-
}
|
|
167
|
-
|
|
168
106
|
/**
|
|
169
107
|
* Generate new Context Elements for each new Entity, with the attributes of the original entity matching its
|
|
170
108
|
* entity_name. It considers Ngsiv2.
|
|
171
109
|
*
|
|
172
110
|
* @param {Object} entity The original entity
|
|
173
111
|
* @param {Array} newEntities List of the new entities that will be generated
|
|
174
|
-
* @param {Array} entityTypes Map of the types for each entity ID
|
|
175
|
-
* @param {Object} typeInformation Object with all the data about the device type
|
|
176
112
|
* @param {Array} multiEntityAttributes List of attributes with multientity option
|
|
177
113
|
* @return {Array} List of the new Context Entities
|
|
178
114
|
*/
|
|
179
|
-
function generateNewCEsNgsi2(entity, newEntities,
|
|
115
|
+
function generateNewCEsNgsi2(entity, newEntities, multiEntityAttributes) {
|
|
180
116
|
const result = [];
|
|
181
117
|
let newEntityAttributes;
|
|
182
118
|
let newEntityAttributeNames;
|
|
183
119
|
let newEntityAttributeObjectIds;
|
|
184
|
-
|
|
185
|
-
let parser = legacyParser;
|
|
186
|
-
if (checkJexl(typeInformation)) {
|
|
187
|
-
parser = jexlParser;
|
|
188
|
-
}
|
|
189
|
-
function filterByEntityName(entityName) {
|
|
120
|
+
function filterByEntityNameandType(entityNameType) {
|
|
190
121
|
return function (item) {
|
|
191
|
-
return
|
|
122
|
+
return (
|
|
123
|
+
item.entity_name === entityNameType.entity_name &&
|
|
124
|
+
(!item.entity_type || item.entity_type === entityNameType.entity_type)
|
|
125
|
+
);
|
|
192
126
|
};
|
|
193
127
|
}
|
|
194
128
|
|
|
195
|
-
function filterByAttributeObjectIds() {
|
|
129
|
+
function filterByAttributeObjectIds(entity, newEntityAttributeNames, newEntityAttributeObjectIds) {
|
|
196
130
|
const result = {};
|
|
197
131
|
for (const att in entity) {
|
|
198
132
|
if (entity.hasOwnProperty(att)) {
|
|
@@ -218,37 +152,44 @@ function generateNewCEsNgsi2(entity, newEntities, entityTypes, typeInformation,
|
|
|
218
152
|
return result;
|
|
219
153
|
}
|
|
220
154
|
|
|
221
|
-
const attsArray = utils.extractAttributesArrayFromNgsi2Entity(entity);
|
|
222
|
-
const ctx = parser.extractContext(attsArray);
|
|
223
|
-
|
|
224
155
|
for (let i = 0; i < newEntities.length; i++) {
|
|
225
|
-
newEntityAttributeNames = _.pluck(
|
|
156
|
+
newEntityAttributeNames = _.pluck(
|
|
157
|
+
multiEntityAttributes.filter(filterByEntityNameandType(newEntities[i])),
|
|
158
|
+
'name'
|
|
159
|
+
);
|
|
226
160
|
newEntityAttributeObjectIds = _.pluck(
|
|
227
|
-
multiEntityAttributes.filter(
|
|
161
|
+
multiEntityAttributes.filter(filterByEntityNameandType(newEntities[i])),
|
|
228
162
|
'object_id'
|
|
229
163
|
);
|
|
230
|
-
newEntityAttributes = filterByAttributeObjectIds();
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
newEntityAttributes.type = entityTypes[newEntities[i]];
|
|
234
|
-
newEntityAttributes.id = entityName;
|
|
235
|
-
|
|
164
|
+
newEntityAttributes = filterByAttributeObjectIds(entity, newEntityAttributeNames, newEntityAttributeObjectIds);
|
|
165
|
+
newEntityAttributes.type = newEntities[i].entity_type;
|
|
166
|
+
newEntityAttributes.id = newEntities[i].entity_name;
|
|
236
167
|
result.push(newEntityAttributes);
|
|
237
168
|
}
|
|
238
|
-
|
|
239
169
|
return result;
|
|
240
170
|
}
|
|
241
171
|
|
|
242
|
-
function
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
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;
|
|
247
184
|
}
|
|
248
|
-
|
|
249
|
-
|
|
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;
|
|
250
192
|
}
|
|
251
|
-
|
|
252
193
|
/**
|
|
253
194
|
* Propagates the same timestamp used in entity to entities. This is needed given that timestamp processing
|
|
254
195
|
* plugin runs before multientity plugin, so we could have issues as the one described here:
|
|
@@ -283,44 +224,32 @@ function propagateTimestamp(entity, entities) {
|
|
|
283
224
|
});
|
|
284
225
|
}
|
|
285
226
|
|
|
286
|
-
function
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
const attributesList = _.pluck(multiEntityAttributes, 'name');
|
|
291
|
-
const entityTypes = extractTypes(multiEntityAttributes, entity.contextElements[0].type);
|
|
292
|
-
const resultAttributes = filterOutMultientitiesNgsi1(entity.contextElements[0].attributes, attributesList);
|
|
293
|
-
|
|
294
|
-
entity.contextElements = entity.contextElements.concat(
|
|
295
|
-
generateNewCEsNgsi1(entity, newEntities, entityTypes, typeInformation, multiEntityAttributes)
|
|
296
|
-
);
|
|
297
|
-
|
|
298
|
-
entity.contextElements[0].attributes = resultAttributes;
|
|
227
|
+
function updateAttribute(entity, typeInformation, callback) {
|
|
228
|
+
let parser = legacyParser;
|
|
229
|
+
if (checkJexl(typeInformation)) {
|
|
230
|
+
parser = jexlParser;
|
|
299
231
|
}
|
|
232
|
+
const attsArray = utils.extractAttributesArrayFromNgsi2Entity(entity);
|
|
233
|
+
const ctx = parser.extractContext(attsArray);
|
|
300
234
|
|
|
301
|
-
|
|
302
|
-
}
|
|
303
|
-
|
|
304
|
-
function updateAttributeNgsi2(entity, typeInformation, callback) {
|
|
305
|
-
let entities = [];
|
|
306
|
-
entities.push(entity);
|
|
235
|
+
let entities = [entity];
|
|
307
236
|
if (typeInformation.active) {
|
|
308
237
|
const multiEntityAttributes = typeInformation.active.filter(hasEntityName);
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
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);
|
|
312
248
|
|
|
313
249
|
if (multiEntityAttributes.length > 0) {
|
|
314
|
-
resultAttributes = filterOutMultientitiesNgsi2(entity, multiEntityAttributes);
|
|
315
|
-
const newCes = generateNewCEsNgsi2(
|
|
316
|
-
|
|
317
|
-
newEntities,
|
|
318
|
-
entityTypes,
|
|
319
|
-
typeInformation,
|
|
320
|
-
multiEntityAttributes
|
|
321
|
-
);
|
|
322
|
-
entities = entities.concat(newCes);
|
|
323
|
-
entities[0] = resultAttributes;
|
|
250
|
+
let resultAttributes = filterOutMultientitiesNgsi2(entity, multiEntityAttributes);
|
|
251
|
+
const newCes = generateNewCEsNgsi2(entity, newEntities, multiEntityAttributes);
|
|
252
|
+
entities = [resultAttributes].concat(newCes);
|
|
324
253
|
propagateTimestamp(entity, entities);
|
|
325
254
|
} else {
|
|
326
255
|
entities = entity;
|
|
@@ -329,12 +258,4 @@ function updateAttributeNgsi2(entity, typeInformation, callback) {
|
|
|
329
258
|
callback(null, entities, typeInformation);
|
|
330
259
|
}
|
|
331
260
|
|
|
332
|
-
function updateAttribute(entity, typeInformation, callback) {
|
|
333
|
-
if (config.isCurrentNgsi()) {
|
|
334
|
-
updateAttributeNgsi2(entity, typeInformation, callback);
|
|
335
|
-
} else {
|
|
336
|
-
updateAttributeNgsi1(entity, typeInformation, callback);
|
|
337
|
-
}
|
|
338
|
-
}
|
|
339
|
-
|
|
340
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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;
|
|
@@ -195,11 +195,11 @@ function finishSouthboundTransaction(callback) {
|
|
|
195
195
|
* @return {Object} New context containing service information.
|
|
196
196
|
*/
|
|
197
197
|
function fillService(context, data) {
|
|
198
|
-
if (data.service) {
|
|
198
|
+
if (data && data.service) {
|
|
199
199
|
context.srv = data.service;
|
|
200
200
|
}
|
|
201
201
|
|
|
202
|
-
if (data.subservice) {
|
|
202
|
+
if (data && data.subservice) {
|
|
203
203
|
context.subsrv = data.subservice;
|
|
204
204
|
}
|
|
205
205
|
|
|
@@ -71,7 +71,7 @@ function traceRequest(req, res, next) {
|
|
|
71
71
|
|
|
72
72
|
/* eslint-disable-next-line no-unused-vars */
|
|
73
73
|
function changeLogLevel(req, res, next) {
|
|
74
|
-
const levels = ['INFO', 'ERROR', 'FATAL', 'DEBUG', 'WARNING'];
|
|
74
|
+
const levels = ['INFO', 'ERROR', 'FATAL', 'DEBUG', 'WARN', 'WARNING'];
|
|
75
75
|
|
|
76
76
|
if (!req.query.level) {
|
|
77
77
|
res.status(400).json({
|
|
@@ -82,7 +82,11 @@ function changeLogLevel(req, res, next) {
|
|
|
82
82
|
error: 'invalid log level'
|
|
83
83
|
});
|
|
84
84
|
} else {
|
|
85
|
-
|
|
85
|
+
let newLevel = req.query.level.toUpperCase();
|
|
86
|
+
if (newLevel === 'WARNING') {
|
|
87
|
+
newLevel = 'WARN';
|
|
88
|
+
}
|
|
89
|
+
logger.setLevel(newLevel);
|
|
86
90
|
res.status(200).send('');
|
|
87
91
|
}
|
|
88
92
|
}
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
* Modified by: Federico M. Facca - Martel Innovate
|
|
24
24
|
*/
|
|
25
25
|
|
|
26
|
-
const request = require('request');
|
|
26
|
+
const request = require('../../request-shim');
|
|
27
27
|
const async = require('async');
|
|
28
28
|
const errors = require('../../errors');
|
|
29
29
|
const constants = require('../../constants');
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
* please contact with::daniel.moranjimenez@telefonica.com
|
|
22
22
|
*/
|
|
23
23
|
|
|
24
|
-
const request = require('request');
|
|
24
|
+
const request = require('../../request-shim');
|
|
25
25
|
const errors = require('../../errors');
|
|
26
26
|
const config = require('../../commonConfig');
|
|
27
27
|
const intoTrans = require('../common/domain').intoTrans;
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
|
|
27
27
|
/* eslint-disable consistent-return */
|
|
28
28
|
|
|
29
|
-
const request = require('request');
|
|
29
|
+
const request = require('../../request-shim');
|
|
30
30
|
const queryString = require('query-string');
|
|
31
31
|
const errors = require('../../errors');
|
|
32
32
|
const config = require('../../commonConfig');
|
|
@@ -64,7 +64,8 @@ function auth(trust, callback) {
|
|
|
64
64
|
'Content-Length': formData.length,
|
|
65
65
|
'Content-Type': 'application/x-www-form-urlencoded'
|
|
66
66
|
},
|
|
67
|
-
body: formData
|
|
67
|
+
body: formData,
|
|
68
|
+
responseType: 'text'
|
|
68
69
|
};
|
|
69
70
|
|
|
70
71
|
logger.debug(context, 'Authentication on the OAuth2 provider [%s]', url);
|