Skip to content

Commit 07fe7dd

Browse files
committed
Signed-off-by: Daniel Kastl <[email protected]>
2 parents 4160723 + a207a8a commit 07fe7dd

File tree

15 files changed

+128
-25
lines changed

15 files changed

+128
-25
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
.DS_Store
2+
.env

app/controllers/subscription_templates_controller.rb

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -237,16 +237,19 @@ def handle_fiware_action(action)
237237
http = Net::HTTP.new(uri.host, uri.port)
238238
http.use_ssl = (uri.scheme == 'https')
239239

240+
headers = {
241+
'Authorization' => "Bearer #{@fiware_broker_auth_token}"
242+
}
243+
244+
headers['Content-Type'] = 'application/json' if action == 'publish'
245+
headers['Fiware-Service'] = @subscription_template.fiware_service if @subscription_template.fiware_service.present?
246+
headers['Fiware-ServicePath'] = @subscription_template.fiware_servicepath if @subscription_template.fiware_servicepath.present?
247+
240248
request = case action
241249
when 'publish'
242-
Net::HTTP::Post.new(uri.path, initheader = {
243-
'Content-Type' => 'application/json',
244-
'Authorization' => "Bearer #{@fiware_broker_auth_token}"
245-
}).tap { |req| req.body = @json_payload }
250+
Net::HTTP::Post.new(uri.path, headers).tap { |req| req.body = @json_payload }
246251
when 'unpublish'
247-
Net::HTTP::Delete.new(uri.path, initheader = {
248-
'Authorization' => "Bearer #{@fiware_broker_auth_token}"
249-
})
252+
Net::HTTP::Delete.new(uri.path, headers)
250253
else
251254
Rails.logger.error "Unknown action: #{action}"
252255
@error_message = l(:general_action_error)

app/views/subscription_templates/_form.html.erb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,14 +61,16 @@
6161
if (link) {
6262
link.addEventListener('click', function(e) {
6363
e.preventDefault();
64-
var geom = JSON.parse(e.target.dataset.geom).geometry.coordinates[0].map(coord => [Number(coord[0].toFixed(5)), Number(coord[1].toFixed(5))]).join(';');
64+
var geom = JSON.parse(e.target.dataset.geom).geometry.coordinates[0]
65+
.map(coord => [Number(coord[1].toFixed(5)), Number(coord[0].toFixed(5))]) // Flip the coordinates
66+
.join(';');
6567
document.querySelector('input[name="subscription_template[expression_coords]"]').value = geom;
6668
document.querySelector('select[name="subscription_template[expression_geometry]"]').value = 'polygon';
6769
document.querySelector('input[name="subscription_template[expression_georel]"]').value = 'coveredBy';
6870
});
6971
}
7072
});
71-
</script>
73+
</script>
7274

7375
<p>
7476
<%= content_tag :label, l(:field_subscription_template_alteration_types) %>

config/locales/de.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,11 @@ de:
5151
Suchmaske für die Subscription verwendet'
5252
gtt_fiware_subscription_template_variable_hint: 'Attributwerte können als <code>${Variable}</code>
5353
eingebettet werden.'
54-
field_subscription_template_expression_coords: 'Koordinaten'
54+
field_subscription_template_expression_coords: 'Koordinaten (lat, lon)'
5555
field_subscription_template_standard: 'NGSI-Standard'
5656
field_subscription_template_attachments_string: 'Anlagen (Array)'
5757
field_subscription_template_fiware_servicepath_placeholder: '/environment'
58-
field_subscription_template_expression_coords_placeholder: '40.419,-3.691;40.429,-3.691;40.429,-3.701'
58+
field_subscription_template_expression_coords_placeholder: "lat1, lon1; lat2, lon2; lat3, lon3; lat1, lon1"
5959
field_subscription_template_fiware_service_placeholder: 'smartcity'
6060
field_subscription_template_attachments_placeholder: '[{"filename": "image.jpg",
6161
"url": "https://example.com/image.jpg"}]'

config/locales/en.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,8 @@ en:
5353
field_subscription_template_expression_georel_placeholder: "near;maxDistance:1000"
5454
field_subscription_template_expression_geometry: "Geometry"
5555
field_subscription_template_expression_geometry_placeholder: "Select a geometry"
56-
field_subscription_template_expression_coords: "Coordinates"
57-
field_subscription_template_expression_coords_placeholder: "40.419,-3.691;40.429,-3.691;40.429,-3.701"
56+
field_subscription_template_expression_coords: "Coordinates (lat, lon)"
57+
field_subscription_template_expression_coords_placeholder: "lat1, lon1; lat2, lon2; lat3, lon3; lat1, lon1"
5858
field_subscription_template_alteration_types: "Alteration types"
5959
field_subscription_template_notify_on_metadata_change: "Notify on metadata change"
6060

config/locales/ja.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,8 @@ en:
5353
field_subscription_template_expression_georel_placeholder: "near;maxDistance:1000"
5454
field_subscription_template_expression_geometry: "Geometry"
5555
field_subscription_template_expression_geometry_placeholder: "Select a geometry"
56-
field_subscription_template_expression_coords: "Coordinates"
57-
field_subscription_template_expression_coords_placeholder: "40.419,-3.691;40.429,-3.691;40.429,-3.701"
56+
field_subscription_template_expression_coords: "Coordinates (lat, lon)"
57+
field_subscription_template_expression_coords_placeholder: "lat1, lon1; lat2, lon2; lat3, lon3; lat1, lon1"
5858
field_subscription_template_alteration_types: "Alteration types"
5959
field_subscription_template_notify_on_metadata_change: "Notify on metadata change"
6060

doc/.env.example

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
BROKER_URL=http://your_broker:1026
2+
BROKER_TOKEN=your_token
3+
FIWARE_SERVICE=your_service
4+
FIWARE_SERVICEPATH=your_servicepath

doc/broker_scripts.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ URL specified in the header for each subscription.
3434
`http://app.local:1026` if not set.
3535
- `BROKER_TOKEN`: The bearer token for authentication. If provided, it will be
3636
used in the `Authorization` header for the requests.
37+
- `FIWARE_SERVICE`: The FIWARE service for the subscriptions (optional).
38+
- `FIWARE_SERVICEPATH`: The FIWARE service path for the subscriptions (optional).
3739

3840
**Note:** Make sure to set the `BROKER_URL` and `BROKER_TOKEN` (optional) environment
3941
variables to your context broker URL and authentication token respectively
@@ -71,6 +73,8 @@ subscriptions, and then makes DELETE requests to the
7173
`http://app.local:1026` if not set.
7274
- `BROKER_TOKEN`: The bearer token for authentication. If provided, it will be
7375
used in the `Authorization` header for the requests.
76+
- `FIWARE_SERVICE`: The FIWARE service for the subscriptions (optional).
77+
- `FIWARE_SERVICEPATH`: The FIWARE service path for the subscriptions (optional).
7478

7579
**Note:** This script does not require any arguments. Make sure to set the
7680
`BROKER_URL` and `BROKER_TOKEN` (optional) environment variables to your context

doc/examples/camera_sensor.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ Create the subscription template and publish it.
4646
curl -iX POST "${BROKER_URL}/v2/entities" \
4747
-H "Content-Type: application/json" \
4848
-H "Authorization: Bearer ${BROKER_TOKEN}" \
49+
-H "Fiware-Service: ${FIWARE_SERVICE}" \
50+
-H "Fiware-ServicePath: ${FIWARE_SERVICEPATH}" \
4951
-d '{
5052
"id": "urn:ngsi-ld:SpeedCameraSensor:001",
5153
"type": "SpeedCameraSensor",
@@ -78,6 +80,8 @@ curl -iX PATCH \
7880
"${BROKER_URL}/v2/entities/urn:ngsi-ld:SpeedCameraSensor:001/attrs" \
7981
-H "Content-Type: application/json" \
8082
-H "Authorization: Bearer ${BROKER_TOKEN}" \
83+
-H "Fiware-Service: ${FIWARE_SERVICE}" \
84+
-H "Fiware-ServicePath: ${FIWARE_SERVICEPATH}" \
8185
-d '{
8286
"speed": {
8387
"value": 90.0,
@@ -91,5 +95,7 @@ curl -iX PATCH \
9195
```bash
9296
curl -iX DELETE \
9397
"${BROKER_URL}/v2/entities/urn:ngsi-ld:SpeedCameraSensor:001" \
94-
-H "Authorization: Bearer ${BROKER_TOKEN}"
98+
-H "Authorization: Bearer ${BROKER_TOKEN}" \
99+
-H "Fiware-Service: ${FIWARE_SERVICE}" \
100+
-H "Fiware-ServicePath: ${FIWARE_SERVICEPATH}"
95101
```

doc/examples/location_sensor.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ Create the subscription template and publish it.
4545
curl -iX POST "${BROKER_URL}/v2/entities" \
4646
-H "Content-Type: application/json" \
4747
-H "Authorization: Bearer ${BROKER_TOKEN}" \
48+
-H "Fiware-Service: ${FIWARE_SERVICE}" \
49+
-H "Fiware-ServicePath: ${FIWARE_SERVICEPATH}" \
4850
-d '{
4951
"id": "urn:ngsi-ld:LocationSensor:001",
5052
"type": "LocationSensor",
@@ -64,6 +66,8 @@ curl -iX POST "${BROKER_URL}/v2/entities" \
6466
curl -iX PATCH \
6567
"${BROKER_URL}/v2/entities/urn:ngsi-ld:LocationSensor:001/attrs" \
6668
-H "Authorization: Bearer ${BROKER_TOKEN}" \
69+
-H "Fiware-Service: ${FIWARE_SERVICE}" \
70+
-H "Fiware-ServicePath: ${FIWARE_SERVICEPATH}" \
6771
-H "Content-Type: application/json" \
6872
-d '{
6973
"location": {
@@ -85,5 +89,7 @@ within the project boundary.
8589
```bash
8690
curl -iX DELETE \
8791
"${BROKER_URL}/v2/entities/urn:ngsi-ld:LocationSensor:001" \
88-
-H "Authorization: Bearer ${BROKER_TOKEN}"
92+
-H "Authorization: Bearer ${BROKER_TOKEN}" \
93+
-H "Fiware-Service: ${FIWARE_SERVICE}" \
94+
-H "Fiware-ServicePath: ${FIWARE_SERVICEPATH}"
8995
```

0 commit comments

Comments
 (0)