Skip to content

Commit

Permalink
Feature/distribution elastic (#76)
Browse files Browse the repository at this point in the history
* New elasticsearch index `distribution`
* Allow search asset by multiple licences
* Support for `LicenceGroups` 
  * updated voters
  • Loading branch information
TomasHermanek authored Feb 27, 2024
1 parent 644f2a8 commit c3cb26f
Show file tree
Hide file tree
Showing 68 changed files with 1,670 additions and 158 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/php.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
matrix:
include:
- php-version: 8.3
docker-image: anzusystems/php:3.0.0-php83-cli-vipsffmpeg
docker-image: anzusystems/php:3.1.0-php83-cli-vipsffmpeg

services:
elasticsearch:
Expand Down
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
## [1.8.0](https://github.com/anzusystems/core-dam-bundle/compare/1.7.0...1.8.0) (2024-02-27)
### Changes
* New elasticsearch index `distribution`
* Allow search asset by multiple licences
* Support for `LicenceGroups`
* updated voters

## [1.7.0](https://github.com/anzusystems/core-dam-bundle/compare/1.6.1...1.7.0) (2024-01-18)
### Changes
* `FileFactory` clears png metadata when file is created from storage
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM anzusystems/php:3.0.0-php83-cli-vipsffmpeg
FROM anzusystems/php:3.1.0-php83-cli-vipsffmpeg
#
### Basic arguments and variables
ARG DOCKER_USER_ID
Expand Down
5 changes: 3 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,15 @@
"require": {
"php": ">=8.3",
"ext-json": "*",
"ext-pcntl": "*",
"ext-mongodb": "*",
"ext-redis": "*",
"ext-simplexml": "*",
"ext-vips": "*",
"ext-xmlreader": "*",
"ext-zend-opcache": "*",
"anzusystems/common-bundle": "^4.0",
"doctrine/orm": ">=2.10",
"anzusystems/common-bundle": "^5.0",
"doctrine/orm": "^2.10",
"elasticsearch/elasticsearch": "^8.6",
"fakerphp/faker": "^1.20",
"google/apiclient": "^2.12",
Expand Down
1 change: 1 addition & 0 deletions psalm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
<MoreSpecificImplementedParamType errorLevel="suppress"/>
<UnnecessaryVarAnnotation errorLevel="suppress"/>
<ImplicitToStringCast errorLevel="suppress"/>
<RiskyTruthyFalsyComparison errorLevel="suppress"/>
<RedundantCast errorLevel="suppress"/>
<MoreSpecificReturnType errorLevel="suppress"/>
<LessSpecificReturnStatement errorLevel="suppress"/>
Expand Down
31 changes: 27 additions & 4 deletions src/Controller/Api/Adm/V1/AssetController.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use AnzuSystems\CoreDamBundle\Domain\AssetMetadata\AssetMetadataBulkFacade;
use AnzuSystems\CoreDamBundle\Elasticsearch\Decorator\AssetAdmElasticsearchDecorator;
use AnzuSystems\CoreDamBundle\Elasticsearch\SearchDto\AssetAdmSearchDto;
use AnzuSystems\CoreDamBundle\Elasticsearch\SearchDto\AssetAdmSearchLicenceCollectionDto;
use AnzuSystems\CoreDamBundle\Entity\Asset;
use AnzuSystems\CoreDamBundle\Entity\AssetFile;
use AnzuSystems\CoreDamBundle\Entity\AssetLicence;
Expand All @@ -32,8 +33,10 @@
use AnzuSystems\CoreDamBundle\Security\Permission\DamPermissions;
use AnzuSystems\SerializerBundle\Attributes\SerializeParam;
use AnzuSystems\SerializerBundle\Exception\SerializerException;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\NonUniqueResultException;
use Elastic\Elasticsearch\Exception\ElasticsearchException;
use OpenApi\Attributes as OA;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
Expand Down Expand Up @@ -77,23 +80,43 @@ public function create(#[SerializeParam] AssetAdmCreateDto $assetDto, AssetLicen
* @throws SerializerException
* @throws ValidationException
* @throws AppReadOnlyModeException
* @throws ElasticsearchException
*/
#[Route('/licence/{assetLicence}/search', name: 'search_by_licence', methods: [Request::METHOD_GET])]
#[OAParameterPath('search', description: 'Searched asset.'), OAResponse([AssetAdmListDto::class])]
public function searchByLicence(AssetLicence $assetLicence, #[SerializeParam] AssetAdmSearchDto $searchDto): JsonResponse
public function searchByLicence(AssetLicence $assetLicence, #[SerializeParam] AssetAdmSearchLicenceCollectionDto $searchDto): JsonResponse
{
App::throwOnReadOnlyMode();
$this->denyAccessUnlessGranted(DamPermissions::DAM_ASSET_VIEW, $assetLicence);
$searchDto->setLicences([$assetLicence]);
$searchDto->setLicences(new ArrayCollection([$assetLicence]));

return $this->okResponse(
$this->elasticSearch->searchInfiniteList($searchDto, $assetLicence->getExtSystem())
$this->elasticSearch->searchInfiniteList($searchDto)
);
}

/**
* @throws SerializerException
* @throws ValidationException
* @throws AppReadOnlyModeException
* @throws ElasticsearchException
*/
#[Route('/licence/search', name: 'search', methods: [Request::METHOD_GET])]
#[OAParameterPath('search', description: 'Searched asset.'), OAResponse([AssetAdmListDto::class])]
public function search(#[SerializeParam] AssetAdmSearchLicenceCollectionDto $searchDto): JsonResponse
{
App::throwOnReadOnlyMode();
$this->denyAccessUnlessGranted(DamPermissions::DAM_ASSET_VIEW, $searchDto);

return $this->okResponse(
$this->elasticSearch->searchInfiniteList($searchDto)
);
}

/**
* @throws SerializerException
* @throws ValidationException
* @throws ElasticsearchException
*/
#[Route('/ext-system/{extSystem}/search', name: 'search_by_ext_system', methods: [Request::METHOD_GET])]
#[OAParameterPath('search', description: 'Searched asset.'), OAResponse([AssetAdmListDto::class])]
Expand All @@ -102,7 +125,7 @@ public function searchByExtSystem(ExtSystem $extSystem, #[SerializeParam] AssetA
$this->denyAccessUnlessGranted(DamPermissions::DAM_ASSET_VIEW, $extSystem);

return $this->okResponse(
$this->elasticSearch->searchInfiniteList($searchDto, $extSystem)
$this->elasticSearch->searchInfiniteListByExtSystem($searchDto, $extSystem)
);
}

Expand Down
102 changes: 102 additions & 0 deletions src/Controller/Api/Adm/V1/AssetLicenceGroupController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
<?php

declare(strict_types=1);

namespace AnzuSystems\CoreDamBundle\Controller\Api\Adm\V1;

use AnzuSystems\CommonBundle\ApiFilter\ApiParams;
use AnzuSystems\CommonBundle\Exception\ValidationException;
use AnzuSystems\CommonBundle\Model\OpenApi\Parameter\OAParameterPath;
use AnzuSystems\CommonBundle\Model\OpenApi\Response\OAResponse;
use AnzuSystems\CommonBundle\Model\OpenApi\Response\OAResponseCreated;
use AnzuSystems\CommonBundle\Model\OpenApi\Response\OAResponseInfiniteList;
use AnzuSystems\CommonBundle\Model\OpenApi\Response\OAResponseValidation;
use AnzuSystems\Contracts\Exception\AppReadOnlyModeException;
use AnzuSystems\CoreDamBundle\App;
use AnzuSystems\CoreDamBundle\Controller\Api\AbstractApiController;
use AnzuSystems\CoreDamBundle\Domain\AssetLicenceGroup\AssetLicenceGroupFacade;
use AnzuSystems\CoreDamBundle\Entity\AssetLicenceGroup;
use AnzuSystems\CoreDamBundle\Model\OpenApi\Request\OARequest;
use AnzuSystems\CoreDamBundle\Repository\AssetLicenceGroupRepository;
use AnzuSystems\CoreDamBundle\Security\Permission\DamPermissions;
use AnzuSystems\SerializerBundle\Attributes\SerializeParam;
use Doctrine\ORM\Exception\ORMException;
use OpenApi\Attributes as OA;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Annotation\Route;

#[Route(path: '/asset-licence-group', name: 'adm_asset_licence_group_v1_')]
#[OA\Tag('AssetLicenceGroup')]
final class AssetLicenceGroupController extends AbstractApiController
{
public function __construct(
private readonly AssetLicenceGroupFacade $facade,
private readonly AssetLicenceGroupRepository $repository,
) {
}

/**
* Get one item.
*/
#[Route('/{assetLicenceGroup}', name: 'get_one', methods: [Request::METHOD_GET])]
#[OAParameterPath('assetLicenceGroup'), OAResponse(AssetLicenceGroup::class)]
public function getOne(AssetLicenceGroup $assetLicenceGroup): JsonResponse
{
$this->denyAccessUnlessGranted(DamPermissions::DAM_ASSET_LICENCE_GROUP_VIEW, $assetLicenceGroup);

return $this->okResponse($assetLicenceGroup);
}

/**
* Get list of items.
*
* @throws ORMException
*/
#[Route('', name: 'get_list', methods: [Request::METHOD_GET])]
#[OAResponseInfiniteList(AssetLicenceGroup::class)]
public function getList(ApiParams $apiParams): JsonResponse
{
$this->denyAccessUnlessGranted(DamPermissions::DAM_ASSET_LICENCE_GROUP_LIST);

return $this->okResponse(
$this->repository->findByApiParamsWithInfiniteListing($apiParams),
);
}

/**
* Create item.
*
* @throws AppReadOnlyModeException
* @throws ValidationException
*/
#[Route('', name: 'create', methods: [Request::METHOD_POST])]
#[OARequest(AssetLicenceGroup::class), OAResponseCreated(AssetLicenceGroup::class), OAResponseValidation]
public function create(#[SerializeParam] AssetLicenceGroup $licenceGroup): JsonResponse
{
App::throwOnReadOnlyMode();
$this->denyAccessUnlessGranted(DamPermissions::DAM_ASSET_LICENCE_GROUP_CREATE);

return $this->createdResponse(
$this->facade->create($licenceGroup)
);
}

/**
* Update item.
*
* @throws AppReadOnlyModeException
* @throws ValidationException
*/
#[Route('/{assetLicenceGroup}', name: 'update', methods: [Request::METHOD_PUT])]
#[OAParameterPath('assetLicence'), OARequest(AssetLicenceGroup::class), OAResponse(AssetLicenceGroup::class), OAResponseValidation]
public function update(AssetLicenceGroup $assetLicenceGroup, #[SerializeParam] AssetLicenceGroup $newAssetLicenceGroup): JsonResponse
{
App::throwOnReadOnlyMode();
$this->denyAccessUnlessGranted(DamPermissions::DAM_ASSET_LICENCE_GROUP_UPDATE, $assetLicenceGroup);

return $this->okResponse(
$this->facade->update($assetLicenceGroup, $newAssetLicenceGroup)
);
}
}
19 changes: 19 additions & 0 deletions src/Controller/Api/Adm/V1/DistributionController.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,21 @@
namespace AnzuSystems\CoreDamBundle\Controller\Api\Adm\V1;

use AnzuSystems\CommonBundle\ApiFilter\ApiParams;
use AnzuSystems\CommonBundle\Exception\ValidationException;
use AnzuSystems\CommonBundle\Model\OpenApi\Parameter\OAParameterPath;
use AnzuSystems\CommonBundle\Model\OpenApi\Response\OAResponse;
use AnzuSystems\CoreDamBundle\Controller\Api\AbstractApiController;
use AnzuSystems\CoreDamBundle\Domain\Distribution\DistributionPermissionFacade;
use AnzuSystems\CoreDamBundle\Elasticsearch\Decorator\DistributionAdmElasticsearchDecorator;
use AnzuSystems\CoreDamBundle\Elasticsearch\SearchDto\DistributionAdmSearchDto;
use AnzuSystems\CoreDamBundle\Entity\Asset;
use AnzuSystems\CoreDamBundle\Entity\AssetFile;
use AnzuSystems\CoreDamBundle\Entity\Distribution;
use AnzuSystems\CoreDamBundle\Model\Decorator\DistributionServiceAuthorization;
use AnzuSystems\CoreDamBundle\Repository\Decorator\DistributionRepositoryDecorator;
use AnzuSystems\CoreDamBundle\Security\Permission\DamPermissions;
use AnzuSystems\SerializerBundle\Attributes\SerializeParam;
use AnzuSystems\SerializerBundle\Exception\SerializerException;
use Doctrine\ORM\Exception\ORMException;
use OpenApi\Attributes as OA;
use Symfony\Component\HttpFoundation\JsonResponse;
Expand All @@ -28,9 +33,23 @@ final class DistributionController extends AbstractApiController
public function __construct(
private readonly DistributionRepositoryDecorator $distributionRepository,
private readonly DistributionPermissionFacade $distributionPermissionFacade,
private readonly DistributionAdmElasticsearchDecorator $elasticSearch,
) {
}

/**
* @throws SerializerException
* @throws ValidationException
*/
#[Route('/search', name: 'search', methods: [Request::METHOD_GET])]
#[OAParameterPath('search', description: 'Searched.'), OAResponse([Distribution::class])]
public function search(#[SerializeParam] DistributionAdmSearchDto $searchDto): JsonResponse
{
$this->denyAccessUnlessGranted(DamPermissions::DAM_DISTRIBUTION_VIEW, $searchDto);

return $this->okResponse($this->elasticSearch->searchInfiniteList($searchDto));
}

/**
* Get one item.
*/
Expand Down
4 changes: 2 additions & 2 deletions src/Controller/Api/Adm/V1/JwDistributionController.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
use AnzuSystems\Contracts\Exception\AppReadOnlyModeException;
use AnzuSystems\CoreDamBundle\App;
use AnzuSystems\CoreDamBundle\Controller\Api\AbstractApiController;
use AnzuSystems\CoreDamBundle\Domain\JwDistribution\JwAbstractDistributionFacade;
use AnzuSystems\CoreDamBundle\Domain\JwDistribution\JwDistributionFacade;
use AnzuSystems\CoreDamBundle\Entity\AssetFile;
use AnzuSystems\CoreDamBundle\Entity\JwDistribution;
use AnzuSystems\CoreDamBundle\Entity\YoutubeDistribution;
Expand All @@ -30,7 +30,7 @@
final class JwDistributionController extends AbstractApiController
{
public function __construct(
private readonly JwAbstractDistributionFacade $jwDistributionFacade,
private readonly JwDistributionFacade $jwDistributionFacade,
private readonly AssetRepository $assetRepository,
) {
}
Expand Down
4 changes: 2 additions & 2 deletions src/Controller/Api/Adm/V1/YoutubeDistributionController.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
use AnzuSystems\CoreDamBundle\App;
use AnzuSystems\CoreDamBundle\Controller\Api\AbstractApiController;
use AnzuSystems\CoreDamBundle\Distribution\Modules\Youtube\YoutubeAuthenticator;
use AnzuSystems\CoreDamBundle\Domain\YoutubeDistribution\YoutubeAbstractDistributionFacade;
use AnzuSystems\CoreDamBundle\Domain\YoutubeDistribution\YoutubeDistributionFacade;
use AnzuSystems\CoreDamBundle\Entity\AssetFile;
use AnzuSystems\CoreDamBundle\Entity\YoutubeDistribution;
use AnzuSystems\CoreDamBundle\Exception\DomainException;
Expand All @@ -38,7 +38,7 @@
final class YoutubeDistributionController extends AbstractApiController
{
public function __construct(
private readonly YoutubeAbstractDistributionFacade $youtubeDistributionFacade,
private readonly YoutubeDistributionFacade $youtubeDistributionFacade,
private readonly YoutubeAuthenticator $youtubeAuthenticator,
private readonly AssetRepository $assetRepository,
) {
Expand Down
19 changes: 10 additions & 9 deletions src/Distribution/DistributionBroker.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use AnzuSystems\CommonBundle\Util\ResourceLocker;
use AnzuSystems\CoreDamBundle\Domain\Asset\AssetPropertiesRefresher;
use AnzuSystems\CoreDamBundle\Domain\Distribution\DistributionStatusFacade;
use AnzuSystems\CoreDamBundle\Domain\Distribution\DistributionStatusManager;
use AnzuSystems\CoreDamBundle\Entity\Distribution;
use AnzuSystems\CoreDamBundle\Exception\DistributionFailedException;
Expand All @@ -27,12 +28,12 @@ final class DistributionBroker
{
use MessageBusAwareTrait;

private const LOCK_PREFIX_NAME = 'distribution_';
private const string LOCK_PREFIX_NAME = 'distribution_';

public function __construct(
private readonly ResourceLocker $resourceLocker,
private readonly DistributionRepository $repository,
private readonly DistributionStatusManager $distributionStatusManager,
private readonly DistributionStatusFacade $distributionStatusFacade,
private readonly ModuleProvider $moduleProvider,
private readonly DamLogger $damLogger,
private readonly AssetPropertiesRefresher $propertiesRefresher,
Expand All @@ -59,7 +60,7 @@ public function startDistribution(Distribution $distribution): void
public function redistribute(Distribution $distribution): void
{
$this->resourceLocker->lock($this->getLockName($distribution));
$this->distributionStatusManager->toDistributing($distribution);
$this->distributionStatusFacade->toDistributing($distribution);

if ($this->repository->isNotBlockByNotFinished($distribution)) {
$this->messageBus->dispatch(new DistributeMessage($distribution));
Expand All @@ -73,14 +74,14 @@ public function redistribute(Distribution $distribution): void
*/
public function toDistributing(Distribution $distribution): void
{
$this->distributionStatusManager->toDistributing($distribution);
$this->distributionStatusFacade->toDistributing($distribution);
$module = $this->moduleProvider->provideModule($distribution->getDistributionService(), true);

try {
$module->distribute($distribution);
} catch (DistributionFailedException $exception) {
$distribution->setFailReason($exception->getFailReason());
$this->distributionStatusManager->toFailed($distribution);
$this->distributionStatusFacade->toFailed($distribution);

return;
} catch (Throwable $e) {
Expand All @@ -93,11 +94,11 @@ public function toDistributing(Distribution $distribution): void
);

$distribution->setFailReason(DistributionFailReason::Unknown);
$this->distributionStatusManager->toFailed($distribution);
$this->distributionStatusFacade->toFailed($distribution);
}

if ($module instanceof RemoteProcessingDistributionModuleInterface) {
$this->distributionStatusManager->toRemoteProcessing($distribution);
$this->distributionStatusFacade->toRemoteProcessing($distribution);
$this->messageBus->dispatch(new DistributionRemoteProcessingCheckMessage($distribution));

return;
Expand Down Expand Up @@ -126,7 +127,7 @@ public function checkRemoteProcessing(Distribution $distribution): void
$exception->getMessage(),
));
$distribution->setFailReason(DistributionFailReason::RemoteProcessFailed);
$this->distributionStatusManager->toFailed($distribution);
$this->distributionStatusFacade->toFailed($distribution);
}
}
}
Expand All @@ -136,7 +137,7 @@ public function checkRemoteProcessing(Distribution $distribution): void
*/
public function remoteProcessed(Distribution $distribution): void
{
$this->distributionStatusManager->toDistributed($distribution);
$this->distributionStatusFacade->toDistributed($distribution);
$this->messageBus->dispatch(new AssetRefreshPropertiesMessage($distribution->getAssetId()));

foreach ($distribution->getBlocks() as $blockedDistribution) {
Expand Down
Loading

0 comments on commit c3cb26f

Please sign in to comment.