Skip to content

Commit

Permalink
Merge branch 'release-1.7.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
github-actions committed Nov 2, 2021
2 parents 76922cd + 9b406eb commit 9b6da99
Show file tree
Hide file tree
Showing 7 changed files with 229 additions and 11 deletions.
12 changes: 11 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -157,4 +157,14 @@ Resources not indexed for class http://www.tao.lu/Ontologies/TAOItem.rdf#Item
Summary
Missing resources: 1
Missing resources indexed: 1
```
```

## Env variables

### Avoid indexing metadata

To avoid indexing metadata that is used in the criteria filter:

```shell
ADVANCED_SEARCH_METADATA_BLACK_LIST=URI1,URI2,URI3
```
4 changes: 4 additions & 0 deletions manifest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
* Copyright (c) 2021 (original work) Open Assessment Technologies SA;
*/

use oat\taoAdvancedSearch\model\Metadata\ServiceProvider\MetadataServiceProvider;
use oat\taoAdvancedSearch\scripts\install\RegisterEvents;
use oat\taoAdvancedSearch\scripts\install\RegisterServices;
use oat\taoAdvancedSearch\scripts\install\RegisterTaskQueueServices;
Expand Down Expand Up @@ -52,5 +53,8 @@
],
'constants' => [
'BASE_URL' => ROOT_URL . 'taoAdvancedSearch/',
],
'containerServiceProviders' => [
MetadataServiceProvider::class,
]
];
30 changes: 20 additions & 10 deletions model/Metadata/Normalizer/MetadataNormalizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
use oat\taoAdvancedSearch\model\Index\IndexResource;
use oat\taoAdvancedSearch\model\Index\Normalizer\NormalizerInterface;
use oat\taoAdvancedSearch\model\Metadata\Factory\ClassPathFactory;
use oat\taoAdvancedSearch\model\Metadata\Specification\PropertyAllowedSpecification;
use oat\taoAdvancedSearch\model\Resource\Repository\IndexableClassCachedRepository;
use oat\taoAdvancedSearch\model\Resource\Repository\IndexableClassRepositoryInterface;

Expand Down Expand Up @@ -77,28 +78,32 @@ private function getPropertiesFromClass(core_kernel_classes_Class $class): array
? $this->getGetClassMetadataValuesService()->getByClassRecursive($class, 0)
: $this->getGetClassMetadataValuesService()->getByClassExplicitly($class, 0);

$specification = $this->getPropertyAllowedSpecification();

/** @var Metadata $property */
foreach ($properties as $property) {
$propertyCollection[] = [
'propertyUri' => $property->getPropertyUri(),
'propertyLabel' => $property->getLabel(),
'propertyAlias' => $property->getAlias(),
'propertyType' => $property->getType(),
'propertyValues' => null,
];
if ($specification->isSatisfiedBy($property->getPropertyUri())) {
$propertyCollection[] = [
'propertyUri' => $property->getPropertyUri(),
'propertyLabel' => $property->getLabel(),
'propertyAlias' => $property->getAlias(),
'propertyType' => $property->getType(),
'propertyValues' => null,
];
}
}

return $propertyCollection;
}

private function getGetClassMetadataValuesService(): GetClassMetadataValuesService
{
return $this->getServiceLocator()->get(GetClassMetadataValuesService::class);
return $this->getServiceManager()->getContainer()->get(GetClassMetadataValuesService::class);
}

private function getClassPathFactory(): ClassPathFactory
{
return $this->getServiceLocator()->get(ClassPathFactory::class);
return $this->getServiceManager()->getContainer()->get(ClassPathFactory::class);
}

private function isRootClass(core_kernel_classes_Class $class)
Expand All @@ -108,6 +113,11 @@ private function isRootClass(core_kernel_classes_Class $class)

private function getIndexableClassRepository(): IndexableClassRepositoryInterface
{
return $this->getServiceLocator()->get(IndexableClassCachedRepository::class);
return $this->getServiceManager()->getContainer()->get(IndexableClassCachedRepository::class);
}

private function getPropertyAllowedSpecification(): PropertyAllowedSpecification
{
return $this->getServiceManager()->getContainer()->get(PropertyAllowedSpecification::class);
}
}
59 changes: 59 additions & 0 deletions model/Metadata/ServiceProvider/MetadataServiceProvider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?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) 2021 (original work) Open Assessment Technologies SA;
*/

declare(strict_types=1);

namespace oat\taoAdvancedSearch\model\Metadata\ServiceProvider;

use oat\generis\model\DependencyInjection\ContainerServiceProviderInterface;
use oat\taoAdvancedSearch\model\Metadata\Specification\PropertyAllowedSpecification;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
use function Symfony\Component\DependencyInjection\Loader\Configurator\param;

class MetadataServiceProvider implements ContainerServiceProviderInterface
{
public function __invoke(ContainerConfigurator $configurator): void
{
$this->setParameters($configurator);

$services = $configurator->services();

$services->set(PropertyAllowedSpecification::class, PropertyAllowedSpecification::class)
->args(
[
param(PropertyAllowedSpecification::CONFIG_BLACK_LIST)
]
)->public();
}

private function setParameters(ContainerConfigurator $configurator): void
{
$parameters = $configurator->parameters();
$parameters->set(
PropertyAllowedSpecification::CONFIG_BLACK_LIST,
array_filter(
explode(
',',
(string)getenv(PropertyAllowedSpecification::CONFIG_BLACK_LIST)
)
)
);
}
}
52 changes: 52 additions & 0 deletions model/Metadata/Specification/PropertyAllowedSpecification.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?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) 2021 (original work) Open Assessment Technologies SA;
*/

declare(strict_types=1);

namespace oat\taoAdvancedSearch\model\Metadata\Specification;

class PropertyAllowedSpecification
{
public const CONFIG_BLACK_LIST = 'ADVANCED_SEARCH_METADATA_BLACK_LIST';

private const SYSTEM_PROPERTIES = [
'http://www.tao.lu/Ontologies/TAOItem.rdf#ItemModel',
'http://www.w3.org/2000/01/rdf-schema#comment',
'http://www.w3.org/2000/01/rdf-schema#isDefinedBy',
'http://www.w3.org/2000/01/rdf-schema#seeAlso',
'http://www.w3.org/1999/02/22-rdf-syntax-ns#value',
'http://www.tao.lu/Ontologies/TAOTest.rdf#TestModel',
'http://www.tao.lu/Ontologies/TAOTest.rdf#TestTestModel',
'http://www.tao.lu/Ontologies/generis.rdf#userDefLg',
];

/** @var array */
private $blackListUris;

public function __construct(array $blackListUris = [])
{
$this->blackListUris = array_merge($blackListUris, self::SYSTEM_PROPERTIES);
}

public function isSatisfiedBy(string $propertyUri): bool
{
return !in_array($propertyUri, $this->blackListUris, true);
}
}
14 changes: 14 additions & 0 deletions tests/Unit/Metadata/Normalizer/MetadataNormalizerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
use oat\tao\model\TaoOntology;
use oat\taoAdvancedSearch\model\Metadata\Factory\ClassPathFactory;
use oat\taoAdvancedSearch\model\Metadata\Normalizer\MetadataNormalizer;
use oat\taoAdvancedSearch\model\Metadata\Specification\PropertyAllowedSpecification;
use oat\taoAdvancedSearch\model\Resource\Repository\IndexableClassCachedRepository;
use PHPUnit\Framework\MockObject\MockObject;

Expand All @@ -58,6 +59,9 @@ class MetadataNormalizerTest extends TestCase
/** @var IndexableClassCachedRepository|MockObject */
private $indexableClassRepository;

/** @var PropertyAllowedSpecification|MockObject */
private $propertyAllowedSpecification;

public function setUp(): void
{
$this->subject = new MetadataNormalizer();
Expand All @@ -67,6 +71,7 @@ public function setUp(): void
$this->metadataMock = $this->createMock(Metadata::class);
$this->ontology = $this->createMock(Ontology::class);
$this->classPathFactory = $this->createMock(ClassPathFactory::class);
$this->propertyAllowedSpecification = $this->createMock(PropertyAllowedSpecification::class);

$this->classPathFactory
->method('create')
Expand All @@ -79,6 +84,7 @@ public function setUp(): void
Ontology::SERVICE_ID => $this->ontology,
ClassPathFactory::class => $this->classPathFactory,
IndexableClassCachedRepository::class => $this->indexableClassRepository,
PropertyAllowedSpecification::class => $this->propertyAllowedSpecification,
]
)
);
Expand All @@ -90,6 +96,10 @@ public function testNormalizeTakesOnlyClass(): void
->method('getClass')
->willReturn($this->classMock);

$this->propertyAllowedSpecification
->method('isSatisfiedBy')
->willReturn(true);

$this->classMock
->method('isClass')
->willReturn(false);
Expand All @@ -116,6 +126,10 @@ public function testNormalize(
]
);

$this->propertyAllowedSpecification
->method('isSatisfiedBy')
->willReturn(true);

$this->ontology
->method('getClass')
->willReturn($this->classMock);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
<?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) 2021 (original work) Open Assessment Technologies SA;
*/

declare(strict_types=1);

namespace oat\taoAdvancedSearch\tests\Unit\model\Metadata\Normalizer;

use oat\generis\test\TestCase;
use oat\taoAdvancedSearch\model\Metadata\Specification\PropertyAllowedSpecification;

class PropertyAllowedSpecificationTest extends TestCase
{
private const PROPERTY_FORBIDDEN = 'forbidden';

/** @var PropertyAllowedSpecification */
private $subject;

public function setUp(): void
{
$this->subject = new PropertyAllowedSpecification(
[
self::PROPERTY_FORBIDDEN,
]
);
}

/**
* @dataProvider getDataProvider
*/
public function testIsSatisfiedBy(bool $expected, string $property): void
{
$this->assertSame($expected, $this->subject->isSatisfiedBy($property));
}

public function getDataProvider(): array
{
return [
'with allowed properties' => [
true,
'anyUriHere'
],
'with not allowed properties' => [
false,
self::PROPERTY_FORBIDDEN
],
'with not allowed system properties' => [
false,
'http://www.tao.lu/Ontologies/TAOItem.rdf#ItemModel'
],
];
}
}

0 comments on commit 9b6da99

Please sign in to comment.