Skip to content

Commit

Permalink
First review
Browse files Browse the repository at this point in the history
  • Loading branch information
pdavide committed Feb 11, 2021
1 parent 17a144d commit 8eabf99
Show file tree
Hide file tree
Showing 29 changed files with 277 additions and 423 deletions.
33 changes: 0 additions & 33 deletions app/Console/Commands/SDGBuildAndSavePayload.php

This file was deleted.

33 changes: 0 additions & 33 deletions app/Console/Commands/SDGBuildPayloadAndSendStatistics.php

This file was deleted.

35 changes: 35 additions & 0 deletions app/Console/Commands/SDGBuildStatistics.php
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;
}
}
46 changes: 46 additions & 0 deletions app/Console/Commands/SDGSendStatistics.php
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');
}
}
33 changes: 0 additions & 33 deletions app/Console/Commands/SDGSendStatisticsFromFile.php

This file was deleted.

33 changes: 0 additions & 33 deletions app/Console/Commands/SDGValidatePayloadFile.php

This file was deleted.

49 changes: 49 additions & 0 deletions app/Console/Commands/SDGValidateStatistics.php
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.');
}
}
9 changes: 2 additions & 7 deletions app/Enums/Logs/ExceptionType.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,7 @@ class ExceptionType extends Enum implements LocalizedEnum
public const EXPIRED_VERIFICATION_LINK_USAGE = 13;

/**
* Generic error in single digital gateway apiCall.
* Error in single digital gateway api calls or payload validation.
*/
public const SINGLE_DIGITAL_GATEWAY_GENERIC_ERROR = 14;

/**
* Json schema validator error.
*/
public const JSON_SCHEMA_VALIDATOR_ERROR = 15;
public const SINGLE_DIGITAL_GATEWAY = 14;
}
29 changes: 29 additions & 0 deletions app/Exceptions/SDGServiceException.php
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,
]
);
}
}
18 changes: 2 additions & 16 deletions app/Http/Controllers/HomeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
use Illuminate\Http\JsonResponse;
use Illuminate\Support\Arr;
use Illuminate\View\View;
use Ramsey\Uuid\Uuid;
use Symfony\Component\Yaml\Yaml;

class HomeController extends Controller
Expand Down Expand Up @@ -90,22 +89,9 @@ public function howToJoin(): View
*
* @return JsonResponse
*/
public function showSDGDataset(): JsonResponse
public function showCurrentSDGDataset(): JsonResponse
{
$dataset = $this->buildDatasetForSDGFromId(Uuid::uuid4()->toString());

$sDGService = app()->make('single-digital-gateway-service');
$isValid = $sDGService->payloadValidator($dataset);

if (!$isValid) {
return response()->json(['message' => 'Payload not valid.'], 400);
}

/*
$sDGService = app()->make('single-digital-gateway-service');
$sDGService->sendStatisticsInformation($dataset);
$sDGService->savePayloadToFilesystem($dataset);
*/
$dataset = $this->buildDatasetForSDG();

return response()->json($dataset);
}
Expand Down
32 changes: 0 additions & 32 deletions app/Jobs/SDGBuildAndSavePayload.php

This file was deleted.

Loading

0 comments on commit 8eabf99

Please sign in to comment.