-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
160 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Api\Model\Output; | ||
|
||
use Alchemy\WebhookBundle\Normalizer\WebhookSerializationInterface; | ||
use ApiPlatform\Metadata\ApiProperty; | ||
use App\Api\Filter\Group\GroupValue; | ||
use App\Api\Model\Output\Traits\CapabilitiesDTOTrait; | ||
use App\Api\Model\Output\Traits\CreatedAtDTOTrait; | ||
use App\Api\Model\Output\Traits\UpdatedAtDTOTrait; | ||
use App\Entity\Core\Asset; | ||
use App\Entity\Core\AssetRendition; | ||
use App\Entity\Core\File; | ||
use App\Entity\Core\Share; | ||
use Symfony\Component\Serializer\Annotation\Groups; | ||
|
||
final readonly class ESDocumentOutput | ||
{ | ||
public function __construct( | ||
#[Groups(['_'])] | ||
private array $data, | ||
) | ||
{ | ||
} | ||
|
||
public function getData(): array | ||
{ | ||
return $this->data; | ||
} | ||
} |
45 changes: 45 additions & 0 deletions
45
databox/api/src/Api/Provider/AssetElasticsearchDocumentProvider.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Api\Provider; | ||
|
||
use Alchemy\AuthBundle\Security\JwtUser; | ||
use Alchemy\AuthBundle\Security\Traits\SecurityAwareTrait; | ||
use ApiPlatform\Metadata\Operation; | ||
use ApiPlatform\State\ProviderInterface; | ||
use App\Api\Model\Output\ESDocumentOutput; | ||
use App\Api\Traits\ItemProviderAwareTrait; | ||
use App\Elasticsearch\ElasticSearchClient; | ||
use App\Entity\Core\Asset; | ||
use App\Security\Voter\AbstractVoter; | ||
use Doctrine\ORM\EntityManagerInterface; | ||
use Elastica\Request; | ||
|
||
final class AssetElasticsearchDocumentProvider implements ProviderInterface | ||
{ | ||
use SecurityAwareTrait; | ||
use ItemProviderAwareTrait; | ||
|
||
public function __construct( | ||
private readonly EntityManagerInterface $em, | ||
private readonly ElasticSearchClient $elasticSearchClient, | ||
) { | ||
} | ||
|
||
public function provide(Operation $operation, array $uriVariables = [], array $context = []): object|array|null | ||
{ | ||
$asset = $this->itemProvider->provide($operation, $uriVariables, $context); | ||
$this->denyAccessUnlessGranted(AbstractVoter::READ, $asset); | ||
$this->denyAccessUnlessGranted(JwtUser::ROLE_TECH); | ||
|
||
if ($asset instanceof Asset) { | ||
$indexName = $this->elasticSearchClient->getIndexName('asset'); | ||
$response = $this->elasticSearchClient->request($indexName.'/_doc/'.$asset->getId(), [], Request::GET); | ||
|
||
return new ESDocumentOutput($response->getData()); | ||
} | ||
|
||
return null; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
databox/client/src/components/Dialog/Asset/AssetESDocument.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import {Asset, StateSetter} from '../../../types'; | ||
import {DialogTabProps} from '../Tabbed/TabbedDialog'; | ||
import ContentTab from '../Tabbed/ContentTab'; | ||
import {getAssetESDocument} from '../../../api/asset'; | ||
import {useCallback, useEffect, useState} from "react"; | ||
import RefreshIcon from '@mui/icons-material/Refresh'; | ||
import {IconButton, LinearProgress, Typography} from "@mui/material"; | ||
|
||
type Props = { | ||
data: Asset; | ||
setData: StateSetter<Asset>; | ||
} & DialogTabProps; | ||
|
||
export default function AssetESDocument({ | ||
data, | ||
onClose, | ||
minHeight, | ||
}: Props) { | ||
const [document, setDocument] = useState<object>(); | ||
const [loading, setLoading] = useState(false); | ||
|
||
const refresh = useCallback(async () => { | ||
setLoading(true); | ||
try { | ||
setDocument(await getAssetESDocument(data.id)); | ||
} finally { | ||
setLoading(false); | ||
} | ||
}, [data.id]); | ||
|
||
useEffect(() => { | ||
refresh(); | ||
}, [refresh]); | ||
|
||
return ( | ||
<ContentTab onClose={onClose} minHeight={minHeight}> | ||
{loading && <LinearProgress/>} | ||
{document ? <> | ||
<IconButton onClick={refresh}> | ||
<RefreshIcon /> | ||
</IconButton> | ||
<pre style={{ | ||
fontSize: 12, | ||
}}> | ||
{JSON.stringify(document, null, 4)} | ||
</pre> | ||
</> : null} | ||
</ContentTab> | ||
); | ||
} |