Skip to content

Commit

Permalink
Merge pull request #751 from dcalvoalonso/task/ngsiv2Type
Browse files Browse the repository at this point in the history
Add the "type" URL parameter to NGSIv2 queries
  • Loading branch information
fgalan committed Jan 25, 2019
2 parents 163cf9d + 5dc7723 commit 8a649e2
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 9 deletions.
1 change: 1 addition & 0 deletions CHANGES_NEXT_RELEASE
Expand Up @@ -2,3 +2,4 @@ Fix: modified engine version >=6 in packages.json
Fix: update logops dependency from 1.0.8 to 2.1.0
Fix: user provider timestamp correctly propagated to mapped entities when multientity pluging is used (#748)
Add: new functions to set callbacks for removal of devices and groups (#735)
Fix: add ?type parameter in CB request updates to avoid potential entity ambiguities (#733)
4 changes: 4 additions & 0 deletions lib/services/devices/deviceService.js
Expand Up @@ -491,6 +491,10 @@ function updateEntityNgsi2(deviceData, updatedDevice, callback) {
options.url = 'http://' + deviceData.cbHost + '/v2/entities/' + String(deviceData.name) + '/attrs';
}

if (deviceData.type) {
options.url += '?type=' + deviceData.type;
}

jsonConcat(options.json, formatAttributesNgsi2(deviceData.active, false));
jsonConcat(options.json, formatAttributesNgsi2(deviceData.staticAttributes, true));
jsonConcat(options.json, formatCommandsNgsi2(deviceData.commands));
Expand Down
8 changes: 8 additions & 0 deletions lib/services/ngsi/ngsiService.js
Expand Up @@ -668,6 +668,14 @@ function sendQueryValueNgsi2(entityName, attributes, typeInformation, token, cal
url = url + '?attrs=' + attributesQueryParam;
}

if (typeInformation.type) {
if (attributes && attributes.length > 0) {
url += '&type=' + typeInformation.type;
} else {
url += '?type=' + typeInformation.type;
}
}

var options = createRequestObject(url, typeInformation, token);
options.method = 'GET';
options.json = true;
Expand Down
Expand Up @@ -238,7 +238,7 @@ describe('Secured access to the Context Broker with OAuth2 provider', function()
.matchHeader('fiware-service', 'smartGondor')
.matchHeader('fiware-servicepath', 'electricity')
.matchHeader('Authorization', 'Bearer eyJhbGciOiJSUzI1NiIsInR5cCIgOiAiSldUIiwia2lkIiA6ICJ3cHdWclJ3')
.get('/v2/entities/light1/attrs?attrs=state,dimming')
.get('/v2/entities/light1/attrs?attrs=state,dimming&type=Light')
.reply(200,
utils.readExampleFile('./test/unit/ngsiv2/examples/contextResponses/queryContext1Success.json'));

Expand Down Expand Up @@ -342,7 +342,7 @@ describe('Secured access to the Context Broker with OAuth2 provider (FIWARE Keyr
.matchHeader('fiware-service', 'smartGondor')
.matchHeader('fiware-servicepath', 'electricity')
.matchHeader('Authorization', 'Bearer c1b752e377680acd1349a3ed59db855a1db07605')
.get('/v2/entities/light1/attrs?attrs=state,dimming')
.get('/v2/entities/light1/attrs?attrs=state,dimming&type=Light')
.reply(200,
utils.readExampleFile('./test/unit/ngsiv2/examples/contextResponses/queryContext1Success.json'));

Expand Down
2 changes: 1 addition & 1 deletion test/unit/ngsiv2/plugins/compress-timestamp-plugin_test.js
Expand Up @@ -228,7 +228,7 @@ describe('Timestamp compression plugin', function() {
contextBrokerMock = nock('http://192.168.1.1:1026')
.matchHeader('fiware-service', 'smartGondor')
.matchHeader('fiware-servicepath', 'gardens')
.get('/v2/entities/light1/attrs?attrs=state,TheTargetValue')
.get('/v2/entities/light1/attrs?attrs=state,TheTargetValue&type=Light')
.reply(200, utils.readExampleFile(
'./test/unit/ngsiv2/examples/contextResponses/queryContextCompressTimestamp1Success.json'));
});
Expand Down
Expand Up @@ -177,7 +177,7 @@ describe('IoT Agent Device Update Registration', function() {
contextBrokerMock
.matchHeader('fiware-service', 'smartGondor')
.matchHeader('fiware-servicepath', 'gardens')
.post('/v2/entities/Light:light1/attrs', utils.readExampleFile(
.post('/v2/entities/Light:light1/attrs?type=Light', utils.readExampleFile(
'./test/unit/ngsiv2/examples/contextRequests/updateProvisionActiveAttributes1.json'))
.reply(204);

Expand Down Expand Up @@ -253,7 +253,7 @@ describe('IoT Agent Device Update Registration', function() {
contextBrokerMock
.matchHeader('fiware-service', 'smartGondor')
.matchHeader('fiware-servicepath', 'gardens')
.post('/v2/entities/Light:light1/attrs', utils.readExampleFile(
.post('/v2/entities/Light:light1/attrs?type=Light', utils.readExampleFile(
'./test/unit/ngsiv2/examples/contextRequests/updateProvisionCommands1.json'))
.reply(204);

Expand Down Expand Up @@ -345,7 +345,7 @@ describe('IoT Agent Device Update Registration', function() {
contextBrokerMock
.matchHeader('fiware-service', 'smartGondor')
.matchHeader('fiware-servicepath', 'gardens')
.post('/v2/entities/Light:light1/attrs')
.post('/v2/entities/Light:light1/attrs?type=Light')
.reply(204);
});

Expand Down
Expand Up @@ -165,7 +165,7 @@ describe('Device provisioning API: Update provisioned devices', function() {
contextBrokerMock
.matchHeader('fiware-service', 'smartGondor')
.matchHeader('fiware-servicepath', '/gardens')
.post('/v2/entities/TheFirstLight/attrs', {})
.post('/v2/entities/TheFirstLight/attrs?type=TheLightType', {})
.reply(204);

// FIXME: When https://github.com/telefonicaid/fiware-orion/issues/3007 is merged into master branch,
Expand Down Expand Up @@ -322,7 +322,7 @@ describe('Device provisioning API: Update provisioned devices', function() {
contextBrokerMock
.matchHeader('fiware-service', 'smartGondor')
.matchHeader('fiware-servicepath', '/gardens')
.post('/v2/entities/SecondMicroLight/attrs', utils.readExampleFile(
.post('/v2/entities/SecondMicroLight/attrs?type=MicroLights', utils.readExampleFile(
'./test/unit/ngsiv2/examples/contextRequests/updateProvisionMinimumDevice.json'))
.reply(204);

Expand Down Expand Up @@ -399,7 +399,7 @@ describe('Device provisioning API: Update provisioned devices', function() {
contextBrokerMock
.matchHeader('fiware-service', 'smartGondor')
.matchHeader('fiware-servicepath', '/gardens')
.post('/v2/entities/SecondMicroLight/attrs', utils.readExampleFile(
.post('/v2/entities/SecondMicroLight/attrs?type=MicroLights', utils.readExampleFile(
'./test/unit/ngsiv2/examples/contextRequests/updateProvisionDeviceStatic.json'))
.reply(204);

Expand Down

0 comments on commit 8a649e2

Please sign in to comment.