-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
29 changed files
with
277 additions
and
423 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?php | ||
|
||
namespace App\Console\Commands; | ||
|
||
use App\Traits\BuildDatasetForSingleDigitalGatewayAPI; | ||
use Illuminate\Console\Command; | ||
|
||
class SDGBuildStatistics extends Command | ||
{ | ||
use BuildDatasetForSingleDigitalGatewayAPI; | ||
|
||
/** | ||
* Create a new command instance. | ||
* | ||
* @return void | ||
*/ | ||
public function __construct() | ||
{ | ||
$this->signature = 'sdg:build-statistics'; | ||
$this->description = 'Build and outputs statistics data for the Single Digital Gateway statistics information endpoint.'; | ||
parent::__construct(); | ||
} | ||
|
||
/** | ||
* Execute the console command. | ||
* | ||
* @return void | ||
*/ | ||
public function handle(): void | ||
{ | ||
$dataset = $this->buildDatasetForSDG(); | ||
|
||
echo json_encode($dataset, JSON_PRETTY_PRINT) . PHP_EOL; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<?php | ||
|
||
namespace App\Console\Commands; | ||
|
||
use App\Exceptions\SDGServiceException; | ||
use App\Jobs\SDGSendStatistics as SDGSendStatisticsJob; | ||
use Illuminate\Console\Command; | ||
|
||
class SDGSendStatistics extends Command | ||
{ | ||
/** | ||
* Create a new command instance. | ||
* | ||
* @return void | ||
*/ | ||
public function __construct() | ||
{ | ||
$this->signature = 'sdg:send-statistics | ||
{--from-file= : The file containing the statistics to be sent (can be speciefed with absolute path or relative to the application root)}'; | ||
$this->description = 'Send a dataset to Single Digital Gateway API for the Statistics on Information Services'; | ||
parent::__construct(); | ||
} | ||
|
||
/** | ||
* Execute the console command. | ||
* | ||
* @return void | ||
*/ | ||
public function handle(): void | ||
{ | ||
$this->info('Send statistics Single Digital Gateway start'); | ||
|
||
$statisticsFileOption = $this->option('from-file'); | ||
$statisticsFilePath = realpath($statisticsFileOption); | ||
|
||
if (!is_null($statisticsFileOption) && (false === $statisticsFilePath)) { | ||
throw new SDGServiceException($statisticsFileOption . ' statistics file not found.'); | ||
} | ||
|
||
$statisticsData = !is_null($statisticsFileOption) ? file_get_contents($statisticsFilePath) : null; | ||
|
||
dispatch(new SDGSendStatisticsJob($statisticsData))->onConnection('sync'); | ||
|
||
$this->info('Send statistics Single Digital Gateway completed'); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
<?php | ||
|
||
namespace App\Console\Commands; | ||
|
||
use Illuminate\Console\Command; | ||
|
||
class SDGValidateStatistics extends Command | ||
{ | ||
/** | ||
* Create a new command instance. | ||
* | ||
* @return void | ||
*/ | ||
public function __construct() | ||
{ | ||
$this->signature = 'sdg:validate-statistics | ||
{statisticsFile : The file containing the statistics to be validated (can be speciefed with absolute path or relative to the application root)}'; | ||
$this->description = 'Validate statistics data against provided json scheme'; | ||
parent::__construct(); | ||
} | ||
|
||
/** | ||
* Execute the console command. | ||
* | ||
* @return void | ||
*/ | ||
public function handle(): void | ||
{ | ||
$statisticsFileArgument = $this->argument('statisticsFile'); | ||
$statisticsFilePath = realpath($statisticsFileArgument); | ||
|
||
if (false === $statisticsFilePath) { | ||
throw new SDGServiceException($statisticsFileArgument . ' statistics file not found.'); | ||
} | ||
|
||
$statisticsData = file_get_contents($statisticsFilePath); | ||
$statisticsDataObject = json_decode($statisticsData); | ||
|
||
if (is_null($statisticsDataObject)) { | ||
throw new SDGServiceException('Invalid statistics data: incorrect JSON format.'); | ||
} | ||
|
||
$sdgService = app()->make('single-digital-gateway-service'); | ||
|
||
$sdgService->validatePayload($statisticsDataObject); | ||
|
||
$this->info('The statistics data is valid.'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?php | ||
|
||
namespace App\Exceptions; | ||
|
||
use App\Enums\Logs\EventType; | ||
use App\Enums\Logs\ExceptionType; | ||
use Exception; | ||
use Symfony\Component\Console\Exception\ExceptionInterface as SymfonyConsoleExceptionInterface; | ||
|
||
/** | ||
* Single Digital Gateway Service connection exception. | ||
*/ | ||
class SDGServiceException extends Exception implements SymfonyConsoleExceptionInterface | ||
{ | ||
/** | ||
* Report the exception. | ||
*/ | ||
public function report(): void | ||
{ | ||
logger()->critical( | ||
'SDG Service exception: ' . $this->getMessage(), | ||
[ | ||
'event' => EventType::EXCEPTION, | ||
'exception_type' => ExceptionType::SINGLE_DIGITAL_GATEWAY, | ||
'exception' => $this, | ||
] | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.