Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
92.86% covered (success)
92.86%
26 / 28
66.67% covered (warning)
66.67%
2 / 3
CRAP
0.00% covered (danger)
0.00%
0 / 1
NewSqlRdf
92.86% covered (success)
92.86%
26 / 28
66.67% covered (warning)
66.67%
2 / 3
7.02
0.00% covered (danger)
0.00%
0 / 1
 add
90.48% covered (success)
90.48%
19 / 21
0.00% covered (danger)
0.00%
0 / 1
5.02
 tripleToValue
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getTripleParameterTypes
100.00% covered (success)
100.00%
6 / 6
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2
3/**
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; under version 2
7 * of the License (non-upgradable).
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
17 *
18 * Copyright (c) 2020 (original work) Open Assessment Technologies SA (under the project TAO-PRODUCT);
19 *
20 * @license GPLv2
21 */
22
23declare(strict_types=1);
24
25namespace oat\generis\model\kernel\persistence\newsql;
26
27use core_kernel_classes_Triple;
28use core_kernel_persistence_smoothsql_SmoothRdf;
29use Doctrine\DBAL\ParameterType;
30use Exception;
31use oat\generis\Helper\UuidPrimaryKeyTrait;
32use oat\generis\model\OntologyRdfs;
33use oat\generis\model\OntologyRdf;
34use oat\oatbox\event\EventManager;
35use oat\generis\model\data\event\ResourceCreated;
36
37/**
38 * NewSQL rdf interface
39 */
40class NewSqlRdf extends core_kernel_persistence_smoothsql_SmoothRdf
41{
42    use UuidPrimaryKeyTrait;
43
44    public function add(core_kernel_classes_Triple $triple)
45    {
46        $query = 'INSERT INTO statements ( id, modelId, subject, predicate, object, l_language, epoch, author) VALUES '
47            . '( ?, ? , ? , ? , ? , ? , ?, ?);';
48
49        $success = $this->getPersistence()
50        ->exec(
51            $query,
52            [
53                $this->getUniquePrimaryKey(),
54                $triple->modelid,
55                $triple->subject,
56                $triple->predicate,
57                $triple->object,
58                is_null($triple->lg) ? '' : $triple->lg,
59                $this->getPersistence()->getPlatForm()->getNowExpression(),
60                is_null($triple->author) ? '' : $triple->author
61            ],
62            $this->getTripleParameterTypes()
63        );
64
65        if ($triple->predicate == OntologyRdfs::RDFS_SUBCLASSOF || $triple->predicate == OntologyRdf::RDF_TYPE) {
66            $eventManager = $this->getModel()->getServiceLocator()->get(EventManager::SERVICE_ID);
67            $eventManager->trigger(new ResourceCreated($this->getModel()->getResource($triple->subject)));
68        }
69
70        return $success;
71    }
72
73    /**
74     * Add id to set of triple values. Put id in first position to match parameter types
75     *
76     * @param core_kernel_classes_Triple $triple
77     * @return array
78     * @throws Exception
79     */
80    protected function tripleToValue(core_kernel_classes_Triple $triple): array
81    {
82        return ['id' => $this->getUniquePrimaryKey()] + parent::tripleToValue($triple);
83    }
84
85    /**
86     * Get default ontology parameter type and add string id
87     *
88     * @return array
89     */
90    protected function getTripleParameterTypes(): array
91    {
92        return array_merge(
93            [
94                ParameterType::STRING,
95            ],
96            parent::getTripleParameterTypes()
97        );
98    }
99}