Skip to content

Commit

Permalink
chore: use unique ids and parent classes ids instead
Browse files Browse the repository at this point in the history
  • Loading branch information
gabrielfs7 committed Sep 10, 2024
1 parent 4a92817 commit b93da9f
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,25 +25,18 @@
class ResourceTranslatableQuery
{
private string $resourceType;
private array $resourceIds;
private array $uniqueIds;

public function __construct(string $resourceType, array $resourceIds = [], array $uniqueIds = [])
public function __construct(string $resourceType, array $uniqueIds = [])
{
$this->resourceType = $resourceType;
$this->resourceIds = $resourceIds;
$this->uniqueIds = $uniqueIds;
}

public function getResourceType(): string
{
return $this->resourceType;
}

public function getResourceIds(): array
{
return $this->resourceIds;
}

public function getUniqueIds(): array
{
Expand Down
10 changes: 5 additions & 5 deletions models/classes/Translation/Query/ResourceTranslationQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@
class ResourceTranslationQuery
{
private string $resourceType;
private string $originResourceId;
private string $uniqueId;
private ?string $languageUri;

public function __construct(string $resourceType, string $originResourceId, string $languageUri = null)
public function __construct(string $resourceType, string $uniqueId, string $languageUri = null)
{
$this->resourceType = $resourceType;
$this->originResourceId = $originResourceId;
$this->uniqueId = $uniqueId;
$this->languageUri = $languageUri;
}

Expand All @@ -40,9 +40,9 @@ public function getResourceType(): string
return $this->resourceType;
}

public function getOriginResourceId(): string
public function getUniqueId(): string
{
return $this->originResourceId;
return $this->uniqueId;
}

public function getLanguageUri(): ?string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,24 +60,22 @@ public function __construct(

public function find(ResourceTranslationQuery $query): ResourceCollection
{
$originResourceId = $query->getOriginResourceId();
$uniqueId = $query->getUniqueId();
$resources = $this->resourceTranslatableRepository->find(
new ResourceTranslatableQuery(
$query->getResourceType(),
[
$originResourceId
$uniqueId
]
)
);

if ($resources->count() === 0) {
throw new Exception(sprintf('Translation Origin Resource %s does not exist', $originResourceId));
throw new Exception(sprintf('Translation Origin Resource %s does not exist', $uniqueId));
}

/** @var ResourceTranslatable $originResource */
$originResource = $resources->current();

$uniqueId = $originResource->getUniqueId();
$output = [];

$queryBuilder = $this->complexSearch->query();
Expand Down Expand Up @@ -121,8 +119,8 @@ public function find(ResourceTranslationQuery $query): ResourceCollection
} catch (Throwable $exception) {
$this->logger->warning(
sprintf(
'Cannot read translation status for [originResourceId=%s, translationResourceId=%s]: %s - %s',
$originResourceId,
'Cannot read translation status for [uniqueId=%s, translationResourceId=%s]: %s - %s',
$uniqueId,
$translationResource->getUri(),
$exception->getMessage(),
$exception->getTraceAsString()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,11 @@ public function populate(AbstractResource $resource, core_kernel_classes_Resourc
{
$valueProperty = $this->ontology->getProperty('http://www.w3.org/1999/02/22-rdf-syntax-ns#value');

foreach ($originResource->getTypes() as $type) {
if (empty($this->metadata[$type->getUri()])) {
continue;
}
$parentClasses = $originResource->getParentClassesIds();
$resourceType = array_pop($parentClasses);

foreach ($this->metadata[$type->getUri()] as $metadataUri) {
$resource->addMetadataUri($metadataUri);
}
foreach ($this->metadata[$resourceType] ?? [] as $metadataUri) {
$resource->addMetadataUri($metadataUri);
}

foreach ($resource->getMetadataUris() as $metadataUri) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,17 +41,19 @@ public function getByRequest(ServerRequestInterface $request): ResourceCollectio
{
$queryParams = $request->getQueryParams();
$resourceType = $queryParams['resourceType'] ?? null;
$resourceUris = $queryParams['resourceUris'] ?? [];
$uniqueIds = $queryParams['uniqueIds'] ?? [];

if (empty($resourceType)) {
throw new InvalidArgumentException('Param resourceType is required');
}

if (empty($uniqueIds)) {
throw new InvalidArgumentException('Param uniqueIds is required');
}

return $this->resourceTranslatableRepository->find(
new ResourceTranslatableQuery(
$resourceType,
$resourceUris,
$uniqueIds
)
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,21 +41,21 @@ public function getByRequest(ServerRequestInterface $request): ResourceCollectio
{
$queryParams = $request->getQueryParams();
$resourceType = $queryParams['resourceType'] ?? null;
$resourceUri = $queryParams['resourceUri'] ?? null;
$uniqueId = $queryParams['uniqueId'] ?? null;
$languageUri = $queryParams['languageUri'] ?? null;

if (empty($resourceType)) {
throw new InvalidArgumentException('Param resourceType is required');
}

if (empty($resourceUri)) {
throw new InvalidArgumentException('Param resourceUri is required');
if (empty($uniqueId)) {
throw new InvalidArgumentException('Param uniqueId is required');
}

return $this->resourceTranslationRepository->find(
new ResourceTranslationQuery(
$resourceType,
$resourceUri,
$uniqueId,
$languageUri
)
);
Expand Down

0 comments on commit b93da9f

Please sign in to comment.