Rename listener to basic.
This commit is contained in:
parent
0981588bb6
commit
5d42be6412
|
@ -41,21 +41,21 @@ $data = $plugin->storageGet();
|
|||
|
||||
## Core data stream types
|
||||
|
||||
### Listener data stream
|
||||
### Basic data stream
|
||||
|
||||
The data stream module provides a `listener` data stream type. Listeners
|
||||
The data stream module provides a `basic` data stream type. Basic data streams
|
||||
receive data via the farmOS API and save data to the farmOS SQL database. Each
|
||||
listener data stream represents a single "value"; a sensor that records
|
||||
basic data stream represents a single "value"; a sensor that records
|
||||
temperature and humidity would provide two data streams. Data can be accessed
|
||||
via the API with the `private_key`, or by anyone if the data stream is set to
|
||||
`public`. Listener data streams also provide simple ways to view data in a
|
||||
`public`. Basic data streams also provide simple ways to view data in a
|
||||
table or graph, and export as CSV.
|
||||
|
||||
### Legacy listener data stream
|
||||
|
||||
The `farm_sensor_listener` module provides a `legacy_listener` data stream type
|
||||
that is compatible with the Listener sensor type from farmOS 1.x. It is
|
||||
similar to the `listener` type but has a few differences:
|
||||
similar to the `basic` type but has a few differences:
|
||||
|
||||
- Each data stream saves multiple values (eg: temperature and humidity are
|
||||
saved to the same data stream)
|
||||
|
@ -85,7 +85,7 @@ Plugins can optionally implement the `DataStreamStorageInterface` and the
|
|||
`DataStreamApiInterface` to adhere to a common interface other data stream
|
||||
types might use.
|
||||
|
||||
The following defines the `listener` data stream bundle plugin:
|
||||
The following defines the `basic` data stream bundle plugin:
|
||||
|
||||
```php
|
||||
<?php
|
||||
|
@ -98,14 +98,15 @@ use Drupal\data_stream\Traits\DataStreamSqlStorage;
|
|||
use Drupal\data_stream\Traits\DataStreamPrivateKeyAccess;
|
||||
|
||||
/**
|
||||
* Provides the listener data stream type.
|
||||
* Provides the basic data stream type.
|
||||
*
|
||||
* @DataStreamType(
|
||||
* id = "listener",
|
||||
* label = @Translation("Listener"),
|
||||
* id = "basic",
|
||||
* label = @Translation("Basic"),
|
||||
* )
|
||||
*/
|
||||
class Listener extends DataStreamTypeBase implements DataStreamStorageInterface, DataStreamApiInterface {
|
||||
class Basic extends DataStreamTypeBase implements DataStreamStorageInterface,
|
||||
DataStreamApiInterface {
|
||||
|
||||
}
|
||||
```
|
||||
|
|
|
@ -62,7 +62,7 @@ class LegacyApiTest extends DataStreamTestBase {
|
|||
]);
|
||||
|
||||
// Create 100 data points over the next 100 days.
|
||||
$this->mockListenerData($this->listener, 100, \Drupal::time()->getRequestTime());
|
||||
$this->mockBasicData($this->listener, 100, \Drupal::time()->getRequestTime());
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -4,6 +4,6 @@ dependencies:
|
|||
enforced:
|
||||
module:
|
||||
- data_stream
|
||||
id: listener
|
||||
label: Listener
|
||||
description: 'Listener stream'
|
||||
id: basic
|
||||
label: Basic
|
||||
description: 'Basic data stream'
|
|
@ -2,7 +2,7 @@ langcode: en
|
|||
status: true
|
||||
dependencies:
|
||||
config:
|
||||
- data_stream.type.listener
|
||||
- data_stream.type.basic
|
||||
module:
|
||||
- csv_serialization
|
||||
- data_stream
|
||||
|
@ -10,8 +10,8 @@ dependencies:
|
|||
- rest
|
||||
- serialization
|
||||
- user
|
||||
id: data_stream_listener_data
|
||||
label: 'Data stream: listener data'
|
||||
id: data_stream_basic_data
|
||||
label: 'Data stream: basic data'
|
||||
module: views
|
||||
description: ''
|
||||
tag: ''
|
||||
|
@ -105,7 +105,7 @@ display:
|
|||
id: timestamp
|
||||
table: data_stream_data_storage
|
||||
field: timestamp
|
||||
relationship: listener_data
|
||||
relationship: basic_data
|
||||
group_type: group
|
||||
admin_label: ''
|
||||
label: Timestamp
|
||||
|
@ -157,7 +157,7 @@ display:
|
|||
id: value_decimal
|
||||
table: data_stream_data_storage
|
||||
field: value_decimal
|
||||
relationship: listener_data
|
||||
relationship: basic_data
|
||||
group_type: group
|
||||
admin_label: ''
|
||||
label: Value
|
||||
|
@ -210,7 +210,7 @@ display:
|
|||
table: data_stream_data
|
||||
field: type
|
||||
value:
|
||||
listener: listener
|
||||
basic: basic
|
||||
entity_type: data_stream
|
||||
entity_field: type
|
||||
plugin_id: bundle
|
||||
|
@ -221,7 +221,7 @@ display:
|
|||
id: timestamp
|
||||
table: data_stream_data_storage
|
||||
field: timestamp
|
||||
relationship: listener_data
|
||||
relationship: basic_data
|
||||
group_type: group
|
||||
admin_label: ''
|
||||
operator: '>='
|
||||
|
@ -273,7 +273,7 @@ display:
|
|||
id: timestamp_1
|
||||
table: data_stream_data_storage
|
||||
field: timestamp
|
||||
relationship: listener_data
|
||||
relationship: basic_data
|
||||
group_type: group
|
||||
admin_label: ''
|
||||
operator: '<='
|
||||
|
@ -323,7 +323,7 @@ display:
|
|||
id: timestamp
|
||||
table: data_stream_data_storage
|
||||
field: timestamp
|
||||
relationship: listener_data
|
||||
relationship: basic_data
|
||||
group_type: group
|
||||
admin_label: ''
|
||||
order: ASC
|
||||
|
@ -350,13 +350,13 @@ display:
|
|||
format: default
|
||||
plugin_id: text
|
||||
relationships:
|
||||
listener_data:
|
||||
id: listener_data
|
||||
basic_data:
|
||||
id: basic_data
|
||||
table: data_stream_data
|
||||
field: listener_data
|
||||
field: basic_data
|
||||
relationship: none
|
||||
group_type: group
|
||||
admin_label: 'Listener data'
|
||||
admin_label: 'Basic data stream data'
|
||||
required: true
|
||||
entity_type: data_stream
|
||||
plugin_id: standard
|
||||
|
@ -476,7 +476,7 @@ display:
|
|||
id: timestamp
|
||||
table: data_stream_data_storage
|
||||
field: timestamp
|
||||
relationship: listener_data
|
||||
relationship: basic_data
|
||||
group_type: group
|
||||
admin_label: ''
|
||||
label: timestamp
|
||||
|
@ -528,7 +528,7 @@ display:
|
|||
id: value_decimal
|
||||
table: data_stream_data_storage
|
||||
field: value_decimal
|
||||
relationship: listener_data
|
||||
relationship: basic_data
|
||||
group_type: group
|
||||
admin_label: ''
|
||||
label: value
|
|
@ -44,13 +44,13 @@ function data_stream_data_stream_view_alter(array &$build, DataStreamInterface $
|
|||
return;
|
||||
}
|
||||
|
||||
// Bail if not the listener type.
|
||||
if ($data_stream->bundle() != 'listener') {
|
||||
// Bail if not the basic type.
|
||||
if ($data_stream->bundle() != 'basic') {
|
||||
return;
|
||||
}
|
||||
|
||||
// Add the listener data block view.
|
||||
$build['views']['data'] = views_embed_view('data_stream_listener_data', 'block', $data_stream->id());
|
||||
// Add the basic data block view.
|
||||
$build['views']['data'] = views_embed_view('data_stream_basic_data', 'block', $data_stream->id());
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
/**
|
||||
* @file
|
||||
* Provide Views data for the Listener data stream.
|
||||
* Provide Views data for the basic data stream.
|
||||
*/
|
||||
|
||||
/**
|
||||
|
@ -10,17 +10,17 @@
|
|||
*/
|
||||
function data_stream_views_data_alter(array &$data) {
|
||||
|
||||
// Add a listener_data field to the data_stream_data table in views
|
||||
// Add a basic_data field to the data_stream_data table in views
|
||||
// that references the data_stream_data_storage table.
|
||||
$data['data_stream_data']['listener_data'] = [
|
||||
'title' => t('Listener data'),
|
||||
'help' => t('Listener data stream data.'),
|
||||
$data['data_stream_data']['basic_data'] = [
|
||||
'title' => t('Basic data'),
|
||||
'help' => t('Basic data stream data.'),
|
||||
'relationship' => [
|
||||
'base' => 'data_stream_data_storage',
|
||||
'base field' => 'id',
|
||||
'field' => 'id',
|
||||
'id' => 'standard',
|
||||
'label' => t('Listener data'),
|
||||
'label' => t('Basic data'),
|
||||
],
|
||||
];
|
||||
}
|
||||
|
@ -28,7 +28,7 @@ function data_stream_views_data_alter(array &$data) {
|
|||
/**
|
||||
* Implements hook_views_data().
|
||||
*
|
||||
* Views integration for data stream listener data.
|
||||
* Views integration for basic data stream data.
|
||||
*/
|
||||
function data_stream_views_data() {
|
||||
|
||||
|
@ -36,7 +36,7 @@ function data_stream_views_data() {
|
|||
$data_table = 'data_stream_data_storage';
|
||||
|
||||
// Describe the {data_stream_data_storage} table.
|
||||
$data[$data_table]['table']['group'] = t('Listener data stream data');
|
||||
$data[$data_table]['table']['group'] = t('Basic data stream data');
|
||||
|
||||
// Data stream ID.
|
||||
$data[$data_table]['id'] = [
|
||||
|
|
|
@ -19,14 +19,14 @@ use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
|
|||
use Symfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException;
|
||||
|
||||
/**
|
||||
* Provides the listener data stream type.
|
||||
* Provides the basic data stream type.
|
||||
*
|
||||
* @DataStreamType(
|
||||
* id = "listener",
|
||||
* label = @Translation("Listener"),
|
||||
* id = "basic",
|
||||
* label = @Translation("Basic"),
|
||||
* )
|
||||
*/
|
||||
class Listener extends DataStreamTypeBase implements DataStreamStorageInterface, DataStreamApiInterface {
|
||||
class Basic extends DataStreamTypeBase implements DataStreamStorageInterface, DataStreamApiInterface {
|
||||
|
||||
use DataStreamSqlStorage;
|
||||
use DataStreamPrivateKeyAccess;
|
|
@ -7,7 +7,7 @@ use Drupal\Tests\data_stream\Traits\DataStreamCreationTrait;
|
|||
use Symfony\Component\HttpFoundation\Request;
|
||||
|
||||
/**
|
||||
* Test the Listener data stream type.
|
||||
* Test the basic data stream type.
|
||||
*
|
||||
* @group farm
|
||||
*/
|
||||
|
@ -16,11 +16,11 @@ class DataStreamApiTest extends DataStreamTestBase {
|
|||
use DataStreamCreationTrait;
|
||||
|
||||
/**
|
||||
* A Listener data stream.
|
||||
* A basic data stream.
|
||||
*
|
||||
* @var \Drupal\data_stream\Entity\DataStreamInterface
|
||||
*/
|
||||
protected $listener;
|
||||
protected $dataStream;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
|
@ -28,15 +28,15 @@ class DataStreamApiTest extends DataStreamTestBase {
|
|||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
// Create a listener data stream for testing.
|
||||
$this->listener = $this->createDataStreamEntity([
|
||||
'type' => 'listener',
|
||||
// Create a basic data stream for testing.
|
||||
$this->dataStream = $this->createDataStreamEntity([
|
||||
'type' => 'basic',
|
||||
'private_key' => hash('md5', mt_rand()),
|
||||
'public' => FALSE,
|
||||
]);
|
||||
|
||||
// Create 100 data points over the next 100 days.
|
||||
$this->mockListenerData($this->listener, 100, \Drupal::time()->getRequestTime());
|
||||
$this->mockBasicData($this->dataStream, 100, \Drupal::time()->getRequestTime());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -45,7 +45,7 @@ class DataStreamApiTest extends DataStreamTestBase {
|
|||
public function testApiInvalidMethods() {
|
||||
|
||||
// Build the path.
|
||||
$uri = $this->buildPath($this->listener->uuid());
|
||||
$uri = $this->buildPath($this->dataStream->uuid());
|
||||
|
||||
$invalid_methods = [
|
||||
Request::METHOD_PUT => 405,
|
||||
|
@ -55,7 +55,7 @@ class DataStreamApiTest extends DataStreamTestBase {
|
|||
|
||||
// Assert each method is rejected.
|
||||
foreach ($invalid_methods as $method => $response_code) {
|
||||
$request = Request::create($uri, $method, ['private_key' => $this->listener->getPrivateKey()]);
|
||||
$request = Request::create($uri, $method, ['private_key' => $this->dataStream->getPrivateKey()]);
|
||||
$response = $this->processRequest($request);
|
||||
$this->assertEqual($response_code, $response->getStatusCode());
|
||||
}
|
||||
|
@ -67,7 +67,7 @@ class DataStreamApiTest extends DataStreamTestBase {
|
|||
public function testApiGet() {
|
||||
|
||||
// Build the path.
|
||||
$uri = $this->buildPath($this->listener->uuid());
|
||||
$uri = $this->buildPath($this->dataStream->uuid());
|
||||
|
||||
// Make a request.
|
||||
$request = Request::create($uri, 'GET');
|
||||
|
@ -77,7 +77,7 @@ class DataStreamApiTest extends DataStreamTestBase {
|
|||
$this->assertEqual(403, $response->getStatusCode());
|
||||
|
||||
// Make a request with the private key.
|
||||
$request = Request::create($uri, 'GET', ['private_key' => $this->listener->getPrivateKey()]);
|
||||
$request = Request::create($uri, 'GET', ['private_key' => $this->dataStream->getPrivateKey()]);
|
||||
$response = $this->processRequest($request);
|
||||
|
||||
// Assert valid response.
|
||||
|
@ -87,7 +87,7 @@ class DataStreamApiTest extends DataStreamTestBase {
|
|||
|
||||
// Test the limit param.
|
||||
$request = Request::create($uri, 'GET',
|
||||
['private_key' => $this->listener->getPrivateKey(), 'limit' => 10]
|
||||
['private_key' => $this->dataStream->getPrivateKey(), 'limit' => 10]
|
||||
);
|
||||
$response = $this->processRequest($request);
|
||||
$data = Json::decode($response->getContent());
|
||||
|
@ -100,7 +100,7 @@ class DataStreamApiTest extends DataStreamTestBase {
|
|||
$end_time = $request_time + (86400 * 20);
|
||||
$request = Request::create($uri, 'GET',
|
||||
[
|
||||
'private_key' => $this->listener->getPrivateKey(),
|
||||
'private_key' => $this->dataStream->getPrivateKey(),
|
||||
'start' => $start_time,
|
||||
'end' => $end_time,
|
||||
],
|
||||
|
@ -114,7 +114,7 @@ class DataStreamApiTest extends DataStreamTestBase {
|
|||
}
|
||||
|
||||
// Make the sensor public.
|
||||
$this->listener->set('public', TRUE)->save();
|
||||
$this->dataStream->set('public', TRUE)->save();
|
||||
|
||||
// Test that data can be accessed without the private key.
|
||||
$request = Request::create($uri, 'GET');
|
||||
|
@ -130,10 +130,10 @@ class DataStreamApiTest extends DataStreamTestBase {
|
|||
public function testApiPost() {
|
||||
|
||||
// Build the path.
|
||||
$uri = $this->buildPath($this->listener->uuid());
|
||||
$uri = $this->buildPath($this->dataStream->uuid());
|
||||
|
||||
// Make the stream public. This should not matter for posting data.
|
||||
$this->listener->set('public', TRUE)->save();
|
||||
$this->dataStream->set('public', TRUE)->save();
|
||||
|
||||
// Test data.
|
||||
$request_time = \Drupal::time()->getRequestTime();
|
||||
|
@ -150,14 +150,14 @@ class DataStreamApiTest extends DataStreamTestBase {
|
|||
$this->assertEqual(403, $response->getStatusCode());
|
||||
|
||||
// Post data with a private key.
|
||||
$request = $request->duplicate(['private_key' => $this->listener->getPrivateKey()]);
|
||||
$request = $request->duplicate(['private_key' => $this->dataStream->getPrivateKey()]);
|
||||
$response = $this->processRequest($request);
|
||||
// Assert success.
|
||||
$this->assertEqual(201, $response->getStatusCode());
|
||||
|
||||
// Assert that new data was saved in DB.
|
||||
$plugin = $this->listener->getPlugin();
|
||||
$data = $plugin->storageGet($this->listener, ['limit' => 1, 'end' => $timestamp]);
|
||||
$plugin = $this->dataStream->getPlugin();
|
||||
$data = $plugin->storageGet($this->dataStream, ['limit' => 1, 'end' => $timestamp]);
|
||||
$this->assertEqual(1, count($data));
|
||||
$this->assertTrue(in_array($test_point, $data));
|
||||
}
|
||||
|
|
|
@ -34,7 +34,7 @@ trait DataStreamCreationTrait {
|
|||
}
|
||||
|
||||
/**
|
||||
* Helper function to generate data for a listener data stream.
|
||||
* Helper function to generate data for a basic data stream.
|
||||
*
|
||||
* @param \Drupal\data_stream\Entity\DataStreamInterface $stream
|
||||
* The data stream entity.
|
||||
|
@ -43,7 +43,7 @@ trait DataStreamCreationTrait {
|
|||
* @param string|null $start_time
|
||||
* The start timestamp.
|
||||
*/
|
||||
protected function mockListenerData(DataStreamInterface $stream, $count = 1, $start_time = NULL) {
|
||||
protected function mockBasicData(DataStreamInterface $stream, $count = 1, $start_time = NULL) {
|
||||
|
||||
$plugin = $stream->getPlugin();
|
||||
|
||||
|
|
Loading…
Reference in New Issue