Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

REL-1198: List value URI definition should work with neo4j RDF storage. #1076

Closed
wants to merge 28 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
b225703
feat: poc attempt for Neo4j
augustas May 24, 2023
f6df1c1
feat: resource implementation language handling
augustas Jul 12, 2023
0966956
fix: language value and relationship detection
augustas Jul 17, 2023
a64fa30
Merge remote-tracking branch 'origin/develop' into poc/REL-1106/rdf-i…
vbyndych Jul 19, 2023
bccb095
test: make integrational tests running
vbyndych Jun 12, 2023
4de01d2
feat: moved relation checking to property method for better reusability.
vbyndych Jul 26, 2023
4de1193
feat: changed visibility and type hints for inheritance
vbyndych Jul 26, 2023
11c3096
feat: fixed issue with UpdatedAt as a whole number
vbyndych Jul 26, 2023
74e2c7e
feat: introduced abstract filter class which different persistence im…
vbyndych Jul 28, 2023
ce0b52e
feat: system search implementation in neo4j and test coverage.
vbyndych Jul 19, 2023
2d5b490
wip: extra changes required to run tests, but not production ready.
vbyndych Jul 28, 2023
e7d06e3
chore: cleanup imports and test to be more verbose.
vbyndych Aug 14, 2023
87226ff
Merge branch 'feature/REL-1193/system-search-implementation-in-neo4j'…
vbyndych Aug 14, 2023
c9f5a30
feat: rewrite complex search using neo4j.
vbyndych Aug 17, 2023
4fa45b0
feat: rewrite complex search using neo4j.
vbyndych Aug 18, 2023
969248c
chore: provide PHP 7.4 compatibility.
vbyndych Aug 18, 2023
1b95fb6
chore: fix code styles and typos.
vbyndych Aug 21, 2023
56a8480
feature: made search persistance configurable.
vbyndych Aug 21, 2023
aaaaf26
fix: property/relationship identification
augustas Aug 29, 2023
b522bb1
feat: getRdfTriples attempt
augustas Sep 6, 2023
f081159
feat: ontology import/export for neo4j.
vbyndych Sep 29, 2023
4828881
fix: removed duplicated properties.
vbyndych Sep 29, 2023
0df3a8c
fix: fixed tests and typo in functions.
vbyndych Oct 13, 2023
a106519
feat: extended complex search functionality to fetch lists data.
vbyndych Oct 12, 2023
497caa1
chore: removed unused constructors and extra spaces.
vbyndych Oct 12, 2023
9cbb8a7
refactor: changed logic for values fetching using new complex search …
vbyndych Oct 12, 2023
fa1e105
fix: set default value, so no exception will be thrown.
vbyndych Oct 13, 2023
eb99b90
chore: clean-up code styles.
vbyndych Oct 13, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion common/class.Utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class common_Utils
* @access public
* @author Joel Bout, <[email protected]>
* @param string strarg
* @return boolean
* @return bool
*/
public static function isUri($strarg)
{
Expand Down
107 changes: 107 additions & 0 deletions common/persistence/Graph/BasicTransactionManager.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
<?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;
*
*/

namespace oat\generis\persistence\Graph;

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

class BasicTransactionManager implements TransactionManagerInterface
{
private ClientInterface $client;
private UnmanagedTransactionInterface $transaction;

public function __construct(ClientInterface $client)
{
$this->client = $client;
}

public function beginTransaction(): void
{
try {
$this->transaction = $this->client->beginTransaction();
} catch (\Throwable $e) {
throw new GraphTransactionException('Transaction was not started.', $e);
}
}

public function commit(): void
{
try {
if (isset($this->transaction)) {
$this->transaction->commit();
unset($this->transaction);
}
} catch (\Throwable $e) {
throw new GraphTransactionException('Transaction was not committed.', $e);
}
}

public function rollback(): void
{
try {
if (isset($this->transaction)) {
$this->transaction->rollback();
unset($this->transaction);
}
} catch (\Throwable $e) {
throw new GraphTransactionException('Transaction was not rolled back.', $e);
}
}

public function run(string $statement, iterable $parameters = []): SummarizedResult
{
try {
if (isset($this->transaction)) {
$result = $this->transaction->run($statement, $parameters);
} else {
$result = $this->client->run($statement, $parameters);
}
} catch (\Throwable $e) {
throw new GraphTransactionException(
sprintf('Exception happen during query run: %s.', $e->getMessage()),
$e
);
}

return $result;
}

public function runStatement(Statement $statement): SummarizedResult
{
try {
if (isset($this->transaction)) {
$result = $this->transaction->runStatement($statement);
} else {
$result = $this->client->runStatement($statement);
}
} catch (\Throwable $e) {
throw new GraphTransactionException(
sprintf('Exception happen during statement run: %s.', $e->getMessage()),
$e
);
}

return $result;
}
}
30 changes: 30 additions & 0 deletions common/persistence/Graph/GraphTransactionException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?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;
*
*/

namespace oat\generis\persistence\Graph;

class GraphTransactionException extends \RuntimeException
{
public function __construct($message = "", \Throwable $previous = null)
{
parent::__construct($message, 0, $previous);
}
}
91 changes: 91 additions & 0 deletions common/persistence/Graph/NestedTransactionWrapper.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
<?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;
*
*/

namespace oat\generis\persistence\Graph;

use Laudis\Neo4j\Databags\Statement;
use Laudis\Neo4j\Databags\SummarizedResult;

class NestedTransactionWrapper implements TransactionManagerInterface
{
private TransactionManagerInterface $nestedTransactionManager;
private int $transactionNestingLevel = 0;
private bool $isRollbackOnly = false;

public function __construct(TransactionManagerInterface $nestedManager)
{
$this->nestedTransactionManager = $nestedManager;
}

public function beginTransaction(): void
{
$this->transactionNestingLevel++;

if ($this->transactionNestingLevel === 1) {
$this->nestedTransactionManager->beginTransaction();
}
}

public function commit(): void
{
if ($this->transactionNestingLevel === 0) {
throw new GraphTransactionException('Transaction should be started first.');
}

if ($this->isRollbackOnly) {
throw new GraphTransactionException(
'Nested transaction failed, so all data should be rolled back now.'
);
}

if ($this->transactionNestingLevel === 1) {
$this->nestedTransactionManager->commit();
}

$this->transactionNestingLevel--;
}

public function rollback(): void
{
if ($this->transactionNestingLevel === 0) {
throw new GraphTransactionException('Transaction should be started first.');
}

if ($this->transactionNestingLevel === 1) {
$this->nestedTransactionManager->rollBack();
$this->isRollbackOnly = false;
} else {
$this->isRollbackOnly = true;
}

$this->transactionNestingLevel--;
}

public function run(string $statement, iterable $parameters = []): SummarizedResult
{
return $this->nestedTransactionManager->run($statement, $parameters);
}

public function runStatement(Statement $statement): SummarizedResult
{
return $this->nestedTransactionManager->runStatement($statement);
}
}
68 changes: 68 additions & 0 deletions common/persistence/Graph/TransactionManagerInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
<?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;
*
*/

namespace oat\generis\persistence\Graph;

use Laudis\Neo4j\Databags\Statement;
use Laudis\Neo4j\Databags\SummarizedResult;

interface TransactionManagerInterface
{
/**
* @return void
*
* @throws GraphTransactionException when starting transaction failed.
*/
public function beginTransaction(): void;

/**
* @return void
*
* @throws GraphTransactionException when transaction commit failed.
*/
public function commit(): void;

/**
* @return void
*
* @throws GraphTransactionException when transaction was not rolled back.
*/
public function rollback(): void;

/**
* @param string $statement
* @param iterable $parameters
*
* @return SummarizedResult
*
* @throws GraphTransactionException
*/
public function run(string $statement, iterable $parameters = []): SummarizedResult;

/**
* @param Statement $statement
*
* @return SummarizedResult
*
* @throws GraphTransactionException
*/
public function runStatement(Statement $statement): SummarizedResult;
}
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
74 changes: 74 additions & 0 deletions common/persistence/class.GraphPersistence.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
<?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;
use Laudis\Neo4j\Databags\SummarizedResult;
use oat\generis\persistence\Graph\BasicTransactionManager;
use oat\generis\persistence\Graph\NestedTransactionWrapper;
use oat\generis\persistence\Graph\TransactionManagerInterface;

class common_persistence_GraphPersistence extends common_persistence_Persistence implements
common_persistence_Transactional
{
private TransactionManagerInterface $transactionManager;

public function run(string $statement, iterable $parameters = []): SummarizedResult
{
return $this->getConnection()->run($statement, $parameters);
}

public function runStatement(Statement $statement): SummarizedResult
{
return $this->getConnection()->runStatement($statement);
}

public function transactional(Closure $func)
{
$transactionManager = $this->getConnection();

$transactionManager->beginTransaction();
try {
$res = $func();
$transactionManager->commit();

return $res;
} catch (\Throwable $e) {
$transactionManager->rollBack();

throw $e;
}
}

private function getConnection(): TransactionManagerInterface
{
if (!isset($this->transactionManager)) {
/** @var ClientInterface $client */
$client = $this->getDriver()->getClient();
$this->transactionManager = new NestedTransactionWrapper(
new BasicTransactionManager($client)
);
}

return $this->transactionManager;
}
}
Loading
Loading