• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

IGNF / validator-api / 14596906002

22 Apr 2025 02:09PM UTC coverage: 33.386% (-12.1%) from 45.455%
14596906002

push

github

web-flow
Merge pull request #78 from IGNF/fix_timeout_error

Fix timeout error

0 of 61 new or added lines in 3 files covered. (0.0%)

72 existing lines in 5 files now uncovered.

210 of 629 relevant lines covered (33.39%)

2.29 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/Validation/ValidatorCLI.php
1
<?php
2

3
namespace App\Validation;
4

5
use App\Entity\Validation;
6
use App\Exception\ValidatorNotFoundException;
7
use App\Storage\ValidationsStorage;
8
use Psr\Log\LoggerInterface;
9
use Symfony\Component\Process\Exception\ProcessFailedException;
10
use Symfony\Component\Process\Process;
11

12
/**
13
 * Helper class to invoke validator-cli.jar from IGNF/validator.
14
 */
15
class ValidatorCLI
16
{
17
    /**
18
     * @var ValidationsStorage
19
     */
20
    private $storage;
21

22
    /**
23
     * @var string
24
     */
25
    private $validatorPath;
26

27
    /**
28
     * @var string
29
     */
30
    private $validatorJavaOpts;
31

32
    /**
33
     * GMLAS_CONFIG environment variable for validator-cli.jar to avoid lower case renaming for GML validation.
34
     *
35
     * @var string
36
     */
37
    private $gmlasConfigPath;
38

39
    /**
40
     * @var LoggerInterface
41
     */
42
    private $logger;
43

44
    public function __construct(
45
        ValidationsStorage $storage,
46
        $validatorPath,
47
        $validatorJavaOpts,
48
        $gmlasConfigPath,
49
        LoggerInterface $logger
50
    ) {
UNCOV
51
        $this->storage = $storage;
×
UNCOV
52
        $this->validatorPath = $validatorPath;
×
UNCOV
53
        if ( ! file_exists($this->validatorPath) ){
×
54
            throw new ValidatorNotFoundException($this->validatorPath);
×
55
        }
UNCOV
56
        $this->validatorJavaOpts = $validatorJavaOpts;
×
UNCOV
57
        $this->gmlasConfigPath = $gmlasConfigPath;
×
UNCOV
58
        $this->logger = $logger;
×
59
    }
60

61
    /**
62
     * Invoke validator-cli.jar from IGNF/validator on the validation.
63
     *
64
     * @return void
65
     *
66
     * @throws ProcessFailedException
67
     */
68
    public function process(Validation $validation)
69
    {
70
        $validationDirectory = $this->storage->getDirectory($validation);
×
71

72
        /* prepare validator-cli.jar command */
73
        $env = $_ENV;
×
74
        $env['GMLAS_CONFIG'] = $this->gmlasConfigPath;
×
75
        /*
76
         * specify validation schema
77
         * TODO : compute DB_URL=jdbc:postgresql:${PGDATABASE}, DB_USER et DB_PASSWORD according to doctrine?
78
         */
79
        $env['DB_SCHEMA'] = "validation" . $validation->getUid();
×
80

81
        $sourceDataDir = $validationDirectory.'/'.$validation->getDatasetName();
×
82
        $cmd = ['java'];
×
83
        $cmd = \array_merge($cmd, explode(' ',$this->validatorJavaOpts));
×
84
        $cmd = \array_merge($cmd,[
×
85
            '-jar', $this->validatorPath,
×
86
            'document_validator',
×
87
            '--input', $sourceDataDir
×
88
        ]);
×
89
        $args = $this->reconstructArgs($validation);
×
90
        $cmd = \array_merge($cmd, $args);
×
91

92
        // executing validation program
93
        $this->logger->info('Validation[{uid}]: executing Java validation program', ['uid' => $validation->getUid()]);
×
94
        $process = new Process(
×
95
            $cmd,
×
96
            $validationDirectory, // note that validator-debug.log is located in current directory,
×
97
            $env
×
98
        );
×
99
        $process->setTimeout(600);
×
100
        $process->setIdleTimeout(600);
×
101
        $process->run();
×
102

103
        if (!$process->isSuccessful()) {
×
104
            throw new ProcessFailedException($process);
×
105
        }
106

107
        /*
108
         * read validation report
109
         */
110
        $reportPath = $validationDirectory.'/validation/validation.jsonl';
×
111
        $results = \file_get_contents($reportPath);
×
112

113
        // jsonl to json_array
114
        $results = \str_replace("}\n{", "},\n{", $results);
×
115
        $results = '['.$results.']';
×
116
        $results = \json_decode($results, true);
×
117

118
        $validation->setResults($results);
×
119
    }
120

121
    /**
122
     * Reconstructs the arguments as an array of strings.
123
     *
124
     * @return array[string]
125
     */
126
    private function reconstructArgs(Validation $validation)
127
    {
128
        $args = [];
×
129
        $arguments = $validation->getArguments();
×
130

131
        foreach ($arguments as $key => $value) {
×
132
            if (!$value || '' == $value || null == $value) {
×
133
                continue;
×
134
            }
135

136
            if (\strlen($key) > 1) {
×
137
                array_push($args, '--'.$key);
×
138
            } else {
139
                array_push($args, '-'.$key);
×
140
            }
141

142
            if (!is_bool($value)) {
×
143
                array_push($args, $value);
×
144
            }
145
        }
146

147
        return $args;
×
148
    }
149
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc