Skip to content

Commit

Permalink
Merge branch 'develop' of github.com:oat-sa/generis into feature/adf-…
Browse files Browse the repository at this point in the history
…1590/optimize-permissions-task-queue
  • Loading branch information
gabrielfs7 committed Oct 20, 2023
2 parents 4d95e76 + 64abf7f commit 4c36f75
Show file tree
Hide file tree
Showing 52 changed files with 4,137 additions and 227 deletions.
41 changes: 41 additions & 0 deletions .github/workflows/sonar.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: Sonarqube_CI
on:

push:
branches:
- master
- main
- develop

pull_request:
types: [opened, synchronize, reopened]
branches:
- '**'
workflow_dispatch:

jobs:
build:
name: Sonarqube_CI
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Sonarqube scan
uses: sonarsource/sonarqube-scan-action@master
env:
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
SONAR_HOST_URL: ${{ secrets.SONAR_HOST_URL }}

# Job will fail when the Quality Gate is red
- name: Sonarqube quality gate check
id: sonarqube-quality-gate-check
uses: sonarsource/sonarqube-quality-gate-action@master
timeout-minutes: 5
env:
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}


- name: "Example show SonarQube Quality Gate Status value"
run: echo "The Quality Gate status is ${{ steps.sonarqube-quality-gate-check.outputs.quality-gate-status }}"
2 changes: 2 additions & 0 deletions common/persistence/PersistenceManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
use common_persistence_SqlPersistence;
use oat\generis\persistence\sql\SchemaProviderInterface;
use oat\oatbox\service\ServiceNotFoundException;
use common_persistence_PhpNeo4jDriver;

/**
* The PersistenceManager is responsible for initializing all persistences
Expand All @@ -51,6 +52,7 @@ class PersistenceManager extends ConfigurableService
'dbal_pdo_sqlite' => 'common_persistence_sql_dbal_Driver',
'dbal_pdo_pgsql' => 'common_persistence_sql_dbal_Driver',
'dbal_pdo_ibm' => 'common_persistence_sql_dbal_Driver',
'phpneo4j' => 'common_persistence_PhpNeo4jDriver',
'phpredis' => 'common_persistence_PhpRedisDriver',
'phpfile' => 'common_persistence_PhpFileDriver',
'SqlKvWrapper' => 'common_persistence_SqlKvDriver',
Expand Down
43 changes: 43 additions & 0 deletions common/persistence/class.GraphPersistence.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php

/**
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; under version 2
* of the License (non-upgradable).
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* Copyright (c) 2023 (original work) Open Assessment Technologies SA ;
*/

declare(strict_types=1);

use Laudis\Neo4j\Contracts\ClientInterface;
use Laudis\Neo4j\Databags\Statement;

class common_persistence_GraphPersistence extends common_persistence_Persistence
{
public function run(string $statement, iterable $parameters = [])
{
/** @var ClientInterface $client */
$client = $this->getDriver()->getClient();

return $client->run($statement, $parameters);
}

public function runStatement(Statement $statement)
{
/** @var ClientInterface $client */
$client = $this->getDriver()->getClient();

return $client->runStatement($statement);
}
}
45 changes: 45 additions & 0 deletions common/persistence/class.PhpNeo4jDriver.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php

/**
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; under version 2
* of the License (non-upgradable).
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* Copyright (c) 2023 (original work) Open Assessment Technologies SA ;
*/

use Laudis\Neo4j\Authentication\Authenticate;
use Laudis\Neo4j\ClientBuilder;
use Laudis\Neo4j\Contracts\ClientInterface;

class common_persistence_PhpNeo4jDriver implements common_persistence_Driver
{
private ClientInterface $client;

public function connect($id, array $params): common_persistence_Persistence
{
$auth = Authenticate::basic($params['user'], $params['password']);

$this->client = ClientBuilder::create()
->withDriver('bolt', sprintf('bolt://%s', $params['host']), $auth)
->withDefaultDriver('bolt')
->build();

return new common_persistence_GraphPersistence($params, $this);
}

public function getClient(): ?ClientInterface
{
return $this->client;
}
}
1 change: 0 additions & 1 deletion common/persistence/sql/class.Filter.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@

use Doctrine\DBAL\Connection;
use Doctrine\DBAL\Query\QueryBuilder;
use oat\generis\model\kernel\persistence\smoothsql\search\filter\Filter;

/**
* Handles the application of filters.
Expand Down
8 changes: 5 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@
"league/flysystem": "~1.0",
"league/flysystem-memory": "~1.0",
"oat-sa/oatbox-extension-installer": "~1.1||dev-master",
"oat-sa/lib-generis-search": "^2.1.2",
"monolog/monolog": "^1.23.0",
"oat-sa/lib-generis-search": "^2.1.2",
"monolog/monolog": "^1.23.0",
"fluent/logger": "^1.0.1",
"symfony/lock": "^3.4",
"symfony/cache": "~4.1",
Expand All @@ -76,7 +76,9 @@
"ramsey/uuid": "^3.8",
"relay/relay": "~2.0",
"composer-runtime-api": "^2.0",
"ext-pdo": "*"
"ext-pdo": "*",
"laudis/neo4j-php-client": "~2.0",
"wikibase-solutions/php-cypher-dsl": "^5.0"
},
"require-dev": {
"mikey179/vfsstream": "~1",
Expand Down
38 changes: 38 additions & 0 deletions core/kernel/classes/class.Property.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

declare(strict_types=1);

use oat\generis\model\OntologyRdf;
use oat\generis\model\WidgetRdf;
use oat\generis\model\GenerisRdf;
use oat\generis\model\OntologyRdfs;
Expand All @@ -42,6 +43,15 @@
*/
class core_kernel_classes_Property extends core_kernel_classes_Resource
{
private const RELATIONSHIP_PROPERTIES = [
OntologyRdf::RDF_TYPE,
OntologyRdfs::RDFS_CLASS,
OntologyRdfs::RDFS_RANGE,
OntologyRdfs::RDFS_DOMAIN,
OntologyRdfs::RDFS_SUBCLASSOF,
OntologyRdfs::RDFS_SUBPROPERTYOF,
];

// --- ASSOCIATIONS ---


Expand Down Expand Up @@ -381,6 +391,34 @@ public function setMultiple($isMultiple)
$this->multiple = $isMultiple;
}

/**
* Checks if property is a relation to other class
*
* @return bool
*/
public function isRelationship(): bool
{
if (in_array($this->getUri(), self::RELATIONSHIP_PROPERTIES)) {
return true;
}

if ($this->getUri() === OntologyRdf::RDF_VALUE) {
return false;
}

$range = $this->getRange();

return $range
&& !in_array(
$range->getUri(),
[
OntologyRdfs::RDFS_LITERAL,
GenerisRdf::CLASS_GENERIS_FILE
],
true
);
}

/**
* Short description of method delete
*
Expand Down
52 changes: 52 additions & 0 deletions core/kernel/persistence/Filter.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?php

namespace oat\generis\model\kernel\persistence;

class Filter
{
protected string $key;

/** @var string|object */
protected $value;

protected string $operator;

protected array $orConditionValues = [];

/**
* @param string $key
* @param string|object $value
* @param string $operator
* @param array $orConditionValues
*/
public function __construct(string $key, $value, string $operator, array $orConditionValues = [])
{
$this->key = $key;
$this->value = $value;
$this->operator = $operator;
$this->orConditionValues = $orConditionValues;
}

public function getKey(): string
{
return $this->key;
}

/**
* @return string|object
*/
public function getValue()
{
return $this->value;
}

public function getOperator(): string
{
return $this->operator;
}

public function getOrConditionValues(): array
{
return $this->orConditionValues;
}
}
2 changes: 1 addition & 1 deletion core/kernel/persistence/file/FileModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public static function toFile($filePath, $triples)
if (!empty($triple->lg)) {
$graph->addLiteral($triple->subject, $triple->predicate, $triple->object, $triple->lg);
} elseif (\common_Utils::isUri($triple->object)) {
$graph->add($triple->subject, $triple->predicate, $triple->object);
$graph->addResource($triple->subject, $triple->predicate, $triple->object);
} else {
$graph->addLiteral($triple->subject, $triple->predicate, $triple->object);
}
Expand Down
3 changes: 2 additions & 1 deletion core/kernel/persistence/smoothsql/class.Resource.php
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,8 @@ public function setPropertiesValues(core_kernel_classes_Resource $resource, $pro
}

if (!empty($triples)) {
$returnValue = $this->getModel()->getRdfInterface()->addTripleCollection($triples);
$this->getModel()->getRdfInterface()->addTripleCollection($triples);
$returnValue = true;
}

return $returnValue;
Expand Down
23 changes: 13 additions & 10 deletions core/kernel/persistence/smoothsql/class.SmoothRdf.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,15 @@ public function get($subject, $predicate)
throw new \common_Exception('Not implemented');
}

/**
* (non-PHPdoc)
* @see \oat\generis\model\data\RdfInterface::search()
*/
public function search($predicate, $object)
{
throw new \common_Exception('Not implemented');
}

/**
* (non-PHPdoc)
* @see \oat\generis\model\data\RdfInterface::add()
Expand Down Expand Up @@ -155,18 +164,12 @@ public function remove(core_kernel_classes_Triple $triple)
);
}

/**
* (non-PHPdoc)
* @see \oat\generis\model\data\RdfInterface::search()
*/
public function search($predicate, $object)
{
throw new \common_Exception('Not implemented');
}

public function getIterator()
{
return new core_kernel_persistence_smoothsql_SmoothIterator($this->getPersistence());
return new core_kernel_persistence_smoothsql_SmoothIterator(
$this->getPersistence(),
array_diff($this->model->getReadableModels(), ['1'])
);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,15 @@
namespace oat\generis\model\kernel\persistence\smoothsql\search;

use core_kernel_persistence_smoothsql_SmoothModel;
use oat\generis\model\data\Model;
use oat\generis\model\kernel\persistence\smoothsql\search\filter\FilterFactory;
use oat\generis\model\OntologyAwareTrait;
use oat\oatbox\service\ConfigurableService;
use oat\search\base\QueryBuilderInterface;
use oat\search\base\QueryInterface;
use oat\search\base\SearchGateWayInterface;
use Zend\ServiceManager\Config;
use Zend\ServiceManager\ServiceManager;
use oat\generis\model\data\ModelManager;
use oat\generis\model\data\Model;

/**
* Complexe search service
Expand All @@ -43,6 +43,8 @@
*/
class ComplexSearchService extends ConfigurableService
{
use OntologyAwareTrait;

public const SERVICE_ID = 'generis/complexSearch';

public const SERVICE_SEARCH_ID = 'search.tao.gateway';
Expand Down Expand Up @@ -71,7 +73,10 @@ protected function getZendServiceManager()
{
if (is_null($this->services)) {
$options = $this->getOptions();
$options['services']['search.options']['model'] = $this->model;
$model = $this->model ?? $this->getModel();
$ontologyOptions = $model->getOptions();
$options['services']['search.options']['model'] = $model;
$options['services']['search.options']['persistence'] = $ontologyOptions['persistence'] ?? null;
$config = new Config($options);
$this->services = new ServiceManager($config);
}
Expand Down
Loading

0 comments on commit 4c36f75

Please sign in to comment.