{"action":"created","comment":{"url":"https://api.github.com/repos/telefonicaid/iotagent-node-lib/pulls/comments/187540429","pull_request_review_id":119341517,"id":187540429,"diff_hunk":"@@ -129,22 +182,99 @@ function subscribe(device, triggers, content, callback) {\n     if (device.cbHost) {\n         options.uri = 'http://' + device.cbHost + '/v1/subscribeContext';\n     } else {\n-        options.uri = 'http://' + config.getConfig().contextBroker.host + ':' +\n-            config.getConfig().contextBroker.port + '/v1/subscribeContext';\n+        options.uri = config.getConfig().contextBroker.url + '/v1/subscribeContext';\n     }\n \n-    request(options, createSubscriptionHandler(device, triggers, store, callback));\n+    request(options, createSubscriptionHandlerNgsi1(device, triggers, store, callback));\n }\n \n /**\n- * Generate a new unsubscription request handler, based on the device and subscription ID given to the function.\n+ * Makes a subscription for the given device's entity using NGSIv2, triggered by the given attributes.\n+ * The contents of the notification can be selected using the \"content\" array (that can be left blank\n+ * to notify the complete entity).\n+ *\n+ * @param {Object} device       Object containing all the information about a particular device.\n+ * @param {Object} triggers     Array with the names of the attributes that would trigger the subscription\n+ * @param {Object} content      Array with the names of the attributes to retrieve in the notification.\n+ */\n+function subscribeNgsi2(device, triggers, content, callback) {\n+    var options = {\n+        method: 'POST',\n+        headers: {\n+            'fiware-service': device.service,\n+            'fiware-servicepath': device.subservice\n+        },\n+        json: {\n+                subject:\n+                {\n+                    entities: [\n+                        {\n+                            id: device.name,\n+                            type: device.type\n+                        }\n+                    ],\n+\n+                    condition: {\n+                        attrs: triggers\n+                    },\n+                },\n+                notification: {\n+                    http: {\n+                        url: config.getConfig().providerUrl + '/notify'\n+                    },\n+                    attrs: content || [],\n+                    attrsFormat: 'normalized'\n+                },\n+                throttling: moment.duration(config.getConfig().throttling).seconds()\n+        }\n+    };\n+\n+    if (config.getConfig().deviceRegistrationDuration) {","path":"lib/services/ngsi/subscriptionService.js","position":156,"original_position":156,"commit_id":"2238b14974be1e3e06df8c6dd4e33a800569e78d","original_commit_id":"2238b14974be1e3e06df8c6dd4e33a800569e78d","user":{"login":"fgalan","id":1534240,"avatar_url":"https://avatars3.githubusercontent.com/u/1534240?v=4","gravatar_id":"","url":"https://api.github.com/users/fgalan","html_url":"https://github.com/fgalan","followers_url":"https://api.github.com/users/fgalan/followers","following_url":"https://api.github.com/users/fgalan/following{/other_user}","gists_url":"https://api.github.com/users/fgalan/gists{/gist_id}","starred_url":"https://api.github.com/users/fgalan/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/fgalan/subscriptions","organizations_url":"https://api.github.com/users/fgalan/orgs","repos_url":"https://api.github.com/users/fgalan/repos","events_url":"https://api.github.com/users/fgalan/events{/privacy}","received_events_url":"https://api.github.com/users/fgalan/received_events","type":"User","site_admin":false},"body":"After running e2e integration test I think there is an issue in the way of calculating expiration in NGSIv2 subscription logic.\r\n\r\nNote that `config.getConfig().deviceRegistrationDuration` is a string in ISO8601 duration format, such as `P1M` (see https://github.com/telefonicaid/iotagent-node-lib/blob/master/config.js#L73).\r\n\r\nI'm not an expert, but as far as I understand this format is not compatible with the ones used by  [add() function](https://momentjs.com/docs/#/manipulating/add/) and I have check empirically that `.add(config.getConfig().deviceRegistrationDuration)` adds 0, so the subscription expires instantaneously and makes test cases related with reverse bidirectionality plugin to fail. Moreover, if I hack this part of the code, e.g. `options.json.expires = 1841595324`  (a date in 2028) then the tests work again.\r\n\r\nIs this makes sense to you (I may be wrong :) this should be fixed (maybe with a function to adapt the ISO8601 duration format to the one that adds expects). In addition, we should have a look to unit test to discover why this has been passed.","created_at":"2018-05-11T07:34:48Z","updated_at":"2018-05-11T07:34:48Z","html_url":"https://github.com/telefonicaid/iotagent-node-lib/pull/556#discussion_r187540429","pull_request_url":"https://api.github.com/repos/telefonicaid/iotagent-node-lib/pulls/556","author_association":"MEMBER","_links":{"self":{"href":"https://api.github.com/repos/telefonicaid/iotagent-node-lib/pulls/comments/187540429"},"html":{"href":"https://github.com/telefonicaid/iotagent-node-lib/pull/556#discussion_r187540429"},"pull_request":{"href":"https://api.github.com/repos/telefonicaid/iotagent-node-lib/pulls/556"}}},"pull_request":{"url":"https://api.github.com/repos/telefonicaid/iotagent-node-lib/pulls/556","id":148397701,"html_url":"https://github.com/telefonicaid/iotagent-node-lib/pull/556","diff_url":"https://github.com/telefonicaid/iotagent-node-lib/pull/556.diff","patch_url":"https://github.com/telefonicaid/iotagent-node-lib/pull/556.patch","issue_url":"https://api.github.com/repos/telefonicaid/iotagent-node-lib/issues/556","number":556,"state":"open","locked":false,"title":"Supporting sending updates to CB using NGSI2 (active attributes)","user":{"login":"dcalvoalonso","id":11388886,"avatar_url":"https://avatars3.githubusercontent.com/u/11388886?v=4","gravatar_id":"","url":"https://api.github.com/users/dcalvoalonso","html_url":"https://github.com/dcalvoalonso","followers_url":"https://api.github.com/users/dcalvoalonso/followers","following_url":"https://api.github.com/users/dcalvoalonso/following{/other_user}","gists_url":"https://api.github.com/users/dcalvoalonso/gists{/gist_id}","starred_url":"https://api.github.com/users/dcalvoalonso/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dcalvoalonso/subscriptions","organizations_url":"https://api.github.com/users/dcalvoalonso/orgs","repos_url":"https://api.github.com/users/dcalvoalonso/repos","events_url":"https://api.github.com/users/dcalvoalonso/events{/privacy}","received_events_url":"https://api.github.com/users/dcalvoalonso/received_events","type":"User","site_admin":false},"body":"As it was proposed by reviewers in [PR 555](https://github.com/telefonicaid/iotagent-node-lib/pull/555), I have reduced the scope of the original PR to support only sending updates to CB using NGSI2 for active attributes.","created_at":"2017-10-24T13:30:57Z","updated_at":"2018-05-11T07:34:49Z","closed_at":null,"merged_at":null,"merge_commit_sha":"07d9394c7150f5a0606c5b5a894e1dade9455b82","assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"labels":[],"milestone":null,"commits_url":"https://api.github.com/repos/telefonicaid/iotagent-node-lib/pulls/556/commits","review_comments_url":"https://api.github.com/repos/telefonicaid/iotagent-node-lib/pulls/556/comments","review_comment_url":"https://api.github.com/repos/telefonicaid/iotagent-node-lib/pulls/comments{/number}","comments_url":"https://api.github.com/repos/telefonicaid/iotagent-node-lib/issues/556/comments","statuses_url":"https://api.github.com/repos/telefonicaid/iotagent-node-lib/statuses/2238b14974be1e3e06df8c6dd4e33a800569e78d","head":{"label":"dcalvoalonso:task/activeAttsNgsi2","ref":"task/activeAttsNgsi2","sha":"2238b14974be1e3e06df8c6dd4e33a800569e78d","user":{"login":"dcalvoalonso","id":11388886,"avatar_url":"https://avatars3.githubusercontent.com/u/11388886?v=4","gravatar_id":"","url":"https://api.github.com/users/dcalvoalonso","html_url":"https://github.com/dcalvoalonso","followers_url":"https://api.github.com/users/dcalvoalonso/followers","following_url":"https://api.github.com/users/dcalvoalonso/following{/other_user}","gists_url":"https://api.github.com/users/dcalvoalonso/gists{/gist_id}","starred_url":"https://api.github.com/users/dcalvoalonso/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dcalvoalonso/subscriptions","organizations_url":"https://api.github.com/users/dcalvoalonso/orgs","repos_url":"https://api.github.com/users/dcalvoalonso/repos","events_url":"https://api.github.com/users/dcalvoalonso/events{/privacy}","received_events_url":"https://api.github.com/users/dcalvoalonso/received_events","type":"User","site_admin":false},"repo":{"id":107990219,"name":"iotagent-node-lib","full_name":"dcalvoalonso/iotagent-node-lib","owner":{"login":"dcalvoalonso","id":11388886,"avatar_url":"https://avatars3.githubusercontent.com/u/11388886?v=4","gravatar_id":"","url":"https://api.github.com/users/dcalvoalonso","html_url":"https://github.com/dcalvoalonso","followers_url":"https://api.github.com/users/dcalvoalonso/followers","following_url":"https://api.github.com/users/dcalvoalonso/following{/other_user}","gists_url":"https://api.github.com/users/dcalvoalonso/gists{/gist_id}","starred_url":"https://api.github.com/users/dcalvoalonso/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dcalvoalonso/subscriptions","organizations_url":"https://api.github.com/users/dcalvoalonso/orgs","repos_url":"https://api.github.com/users/dcalvoalonso/repos","events_url":"https://api.github.com/users/dcalvoalonso/events{/privacy}","received_events_url":"https://api.github.com/users/dcalvoalonso/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/dcalvoalonso/iotagent-node-lib","description":"IoT Agent library to interface with NGSI Context Broker","fork":true,"url":"https://api.github.com/repos/dcalvoalonso/iotagent-node-lib","forks_url":"https://api.github.com/repos/dcalvoalonso/iotagent-node-lib/forks","keys_url":"https://api.github.com/repos/dcalvoalonso/iotagent-node-lib/keys{/key_id}","collaborators_url":"https://api.github.com/repos/dcalvoalonso/iotagent-node-lib/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/dcalvoalonso/iotagent-node-lib/teams","hooks_url":"https://api.github.com/repos/dcalvoalonso/iotagent-node-lib/hooks","issue_events_url":"https://api.github.com/repos/dcalvoalonso/iotagent-node-lib/issues/events{/number}","events_url":"https://api.github.com/repos/dcalvoalonso/iotagent-node-lib/events","assignees_url":"https://api.github.com/repos/dcalvoalonso/iotagent-node-lib/assignees{/user}","branches_url":"https://api.github.com/repos/dcalvoalonso/iotagent-node-lib/branches{/branch}","tags_url":"https://api.github.com/repos/dcalvoalonso/iotagent-node-lib/tags","blobs_url":"https://api.github.com/repos/dcalvoalonso/iotagent-node-lib/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/dcalvoalonso/iotagent-node-lib/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/dcalvoalonso/iotagent-node-lib/git/refs{/sha}","trees_url":"https://api.github.com/repos/dcalvoalonso/iotagent-node-lib/git/trees{/sha}","statuses_url":"https://api.github.com/repos/dcalvoalonso/iotagent-node-lib/statuses/{sha}","languages_url":"https://api.github.com/repos/dcalvoalonso/iotagent-node-lib/languages","stargazers_url":"https://api.github.com/repos/dcalvoalonso/iotagent-node-lib/stargazers","contributors_url":"https://api.github.com/repos/dcalvoalonso/iotagent-node-lib/contributors","subscribers_url":"https://api.github.com/repos/dcalvoalonso/iotagent-node-lib/subscribers","subscription_url":"https://api.github.com/repos/dcalvoalonso/iotagent-node-lib/subscription","commits_url":"https://api.github.com/repos/dcalvoalonso/iotagent-node-lib/commits{/sha}","git_commits_url":"https://api.github.com/repos/dcalvoalonso/iotagent-node-lib/git/commits{/sha}","comments_url":"https://api.github.com/repos/dcalvoalonso/iotagent-node-lib/comments{/number}","issue_comment_url":"https://api.github.com/repos/dcalvoalonso/iotagent-node-lib/issues/comments{/number}","contents_url":"https://api.github.com/repos/dcalvoalonso/iotagent-node-lib/contents/{+path}","compare_url":"https://api.github.com/repos/dcalvoalonso/iotagent-node-lib/compare/{base}...{head}","merges_url":"https://api.github.com/repos/dcalvoalonso/iotagent-node-lib/merges","archive_url":"https://api.github.com/repos/dcalvoalonso/iotagent-node-lib/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/dcalvoalonso/iotagent-node-lib/downloads","issues_url":"https://api.github.com/repos/dcalvoalonso/iotagent-node-lib/issues{/number}","pulls_url":"https://api.github.com/repos/dcalvoalonso/iotagent-node-lib/pulls{/number}","milestones_url":"https://api.github.com/repos/dcalvoalonso/iotagent-node-lib/milestones{/number}","notifications_url":"https://api.github.com/repos/dcalvoalonso/iotagent-node-lib/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/dcalvoalonso/iotagent-node-lib/labels{/name}","releases_url":"https://api.github.com/repos/dcalvoalonso/iotagent-node-lib/releases{/id}","deployments_url":"https://api.github.com/repos/dcalvoalonso/iotagent-node-lib/deployments","created_at":"2017-10-23T14:01:39Z","updated_at":"2017-10-23T14:01:42Z","pushed_at":"2018-05-11T06:19:29Z","git_url":"git://github.com/dcalvoalonso/iotagent-node-lib.git","ssh_url":"git@github.com:dcalvoalonso/iotagent-node-lib.git","clone_url":"https://github.com/dcalvoalonso/iotagent-node-lib.git","svn_url":"https://github.com/dcalvoalonso/iotagent-node-lib","homepage":null,"size":2787,"stargazers_count":0,"watchers_count":0,"language":"JavaScript","has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"open_issues_count":0,"license":{"key":"agpl-3.0","name":"GNU Affero General Public License v3.0","spdx_id":"AGPL-3.0","url":"https://api.github.com/licenses/agpl-3.0"},"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"telefonicaid:master","ref":"master","sha":"62dc00eda4bc53926cbe5f7ab146414c4c3188eb","user":{"login":"telefonicaid","id":968363,"avatar_url":"https://avatars2.githubusercontent.com/u/968363?v=4","gravatar_id":"","url":"https://api.github.com/users/telefonicaid","html_url":"https://github.com/telefonicaid","followers_url":"https://api.github.com/users/telefonicaid/followers","following_url":"https://api.github.com/users/telefonicaid/following{/other_user}","gists_url":"https://api.github.com/users/telefonicaid/gists{/gist_id}","starred_url":"https://api.github.com/users/telefonicaid/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/telefonicaid/subscriptions","organizations_url":"https://api.github.com/users/telefonicaid/orgs","repos_url":"https://api.github.com/users/telefonicaid/repos","events_url":"https://api.github.com/users/telefonicaid/events{/privacy}","received_events_url":"https://api.github.com/users/telefonicaid/received_events","type":"Organization","site_admin":false},"repo":{"id":25203883,"name":"iotagent-node-lib","full_name":"telefonicaid/iotagent-node-lib","owner":{"login":"telefonicaid","id":968363,"avatar_url":"https://avatars2.githubusercontent.com/u/968363?v=4","gravatar_id":"","url":"https://api.github.com/users/telefonicaid","html_url":"https://github.com/telefonicaid","followers_url":"https://api.github.com/users/telefonicaid/followers","following_url":"https://api.github.com/users/telefonicaid/following{/other_user}","gists_url":"https://api.github.com/users/telefonicaid/gists{/gist_id}","starred_url":"https://api.github.com/users/telefonicaid/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/telefonicaid/subscriptions","organizations_url":"https://api.github.com/users/telefonicaid/orgs","repos_url":"https://api.github.com/users/telefonicaid/repos","events_url":"https://api.github.com/users/telefonicaid/events{/privacy}","received_events_url":"https://api.github.com/users/telefonicaid/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/telefonicaid/iotagent-node-lib","description":"IoT Agent library to interface with NGSI Context Broker","fork":false,"url":"https://api.github.com/repos/telefonicaid/iotagent-node-lib","forks_url":"https://api.github.com/repos/telefonicaid/iotagent-node-lib/forks","keys_url":"https://api.github.com/repos/telefonicaid/iotagent-node-lib/keys{/key_id}","collaborators_url":"https://api.github.com/repos/telefonicaid/iotagent-node-lib/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/telefonicaid/iotagent-node-lib/teams","hooks_url":"https://api.github.com/repos/telefonicaid/iotagent-node-lib/hooks","issue_events_url":"https://api.github.com/repos/telefonicaid/iotagent-node-lib/issues/events{/number}","events_url":"https://api.github.com/repos/telefonicaid/iotagent-node-lib/events","assignees_url":"https://api.github.com/repos/telefonicaid/iotagent-node-lib/assignees{/user}","branches_url":"https://api.github.com/repos/telefonicaid/iotagent-node-lib/branches{/branch}","tags_url":"https://api.github.com/repos/telefonicaid/iotagent-node-lib/tags","blobs_url":"https://api.github.com/repos/telefonicaid/iotagent-node-lib/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/telefonicaid/iotagent-node-lib/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/telefonicaid/iotagent-node-lib/git/refs{/sha}","trees_url":"https://api.github.com/repos/telefonicaid/iotagent-node-lib/git/trees{/sha}","statuses_url":"https://api.github.com/repos/telefonicaid/iotagent-node-lib/statuses/{sha}","languages_url":"https://api.github.com/repos/telefonicaid/iotagent-node-lib/languages","stargazers_url":"https://api.github.com/repos/telefonicaid/iotagent-node-lib/stargazers","contributors_url":"https://api.github.com/repos/telefonicaid/iotagent-node-lib/contributors","subscribers_url":"https://api.github.com/repos/telefonicaid/iotagent-node-lib/subscribers","subscription_url":"https://api.github.com/repos/telefonicaid/iotagent-node-lib/subscription","commits_url":"https://api.github.com/repos/telefonicaid/iotagent-node-lib/commits{/sha}","git_commits_url":"https://api.github.com/repos/telefonicaid/iotagent-node-lib/git/commits{/sha}","comments_url":"https://api.github.com/repos/telefonicaid/iotagent-node-lib/comments{/number}","issue_comment_url":"https://api.github.com/repos/telefonicaid/iotagent-node-lib/issues/comments{/number}","contents_url":"https://api.github.com/repos/telefonicaid/iotagent-node-lib/contents/{+path}","compare_url":"https://api.github.com/repos/telefonicaid/iotagent-node-lib/compare/{base}...{head}","merges_url":"https://api.github.com/repos/telefonicaid/iotagent-node-lib/merges","archive_url":"https://api.github.com/repos/telefonicaid/iotagent-node-lib/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/telefonicaid/iotagent-node-lib/downloads","issues_url":"https://api.github.com/repos/telefonicaid/iotagent-node-lib/issues{/number}","pulls_url":"https://api.github.com/repos/telefonicaid/iotagent-node-lib/pulls{/number}","milestones_url":"https://api.github.com/repos/telefonicaid/iotagent-node-lib/milestones{/number}","notifications_url":"https://api.github.com/repos/telefonicaid/iotagent-node-lib/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/telefonicaid/iotagent-node-lib/labels{/name}","releases_url":"https://api.github.com/repos/telefonicaid/iotagent-node-lib/releases{/id}","deployments_url":"https://api.github.com/repos/telefonicaid/iotagent-node-lib/deployments","created_at":"2014-10-14T11:48:27Z","updated_at":"2018-05-10T14:07:31Z","pushed_at":"2018-05-11T06:19:30Z","git_url":"git://github.com/telefonicaid/iotagent-node-lib.git","ssh_url":"git@github.com:telefonicaid/iotagent-node-lib.git","clone_url":"https://github.com/telefonicaid/iotagent-node-lib.git","svn_url":"https://github.com/telefonicaid/iotagent-node-lib","homepage":null,"size":2457,"stargazers_count":25,"watchers_count":25,"language":"JavaScript","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":31,"mirror_url":null,"archived":false,"open_issues_count":44,"license":{"key":"agpl-3.0","name":"GNU Affero General Public License v3.0","spdx_id":"AGPL-3.0","url":"https://api.github.com/licenses/agpl-3.0"},"forks":31,"open_issues":44,"watchers":25,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/telefonicaid/iotagent-node-lib/pulls/556"},"html":{"href":"https://github.com/telefonicaid/iotagent-node-lib/pull/556"},"issue":{"href":"https://api.github.com/repos/telefonicaid/iotagent-node-lib/issues/556"},"comments":{"href":"https://api.github.com/repos/telefonicaid/iotagent-node-lib/issues/556/comments"},"review_comments":{"href":"https://api.github.com/repos/telefonicaid/iotagent-node-lib/pulls/556/comments"},"review_comment":{"href":"https://api.github.com/repos/telefonicaid/iotagent-node-lib/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/telefonicaid/iotagent-node-lib/pulls/556/commits"},"statuses":{"href":"https://api.github.com/repos/telefonicaid/iotagent-node-lib/statuses/2238b14974be1e3e06df8c6dd4e33a800569e78d"}},"author_association":"CONTRIBUTOR"}}
{"actor":{"display_login":"fgalan"}}