diff --git a/databox/api/src/Api/InputTransformer/AssetInputTransformer.php b/databox/api/src/Api/InputTransformer/AssetInputTransformer.php index 11922165d..57e2c6b48 100644 --- a/databox/api/src/Api/InputTransformer/AssetInputTransformer.php +++ b/databox/api/src/Api/InputTransformer/AssetInputTransformer.php @@ -118,10 +118,19 @@ public function transform(object $data, string $resourceClass, array $context = if (!empty($data->renditions)) { foreach ($data->renditions as $renditionInput) { - $definition = $this->renditionManager->getRenditionDefinitionByName( - $workspace, - $renditionInput->definition - ); + if ($renditionInput->definitionId) { + $definition = $this->renditionManager->getRenditionDefinitionById( + $workspace, + $renditionInput->definitionId + ); + } elseif ($renditionInput->name) { + $definition = $this->renditionManager->getRenditionDefinitionByName( + $workspace, + $renditionInput->name + ); + } else { + throw new BadRequestHttpException('Rendition input error: You must provide either "name" or "definitionId"'); + } $rendition = $this->renditionManager->getOrCreateRendition($object, $definition); $file = $this->handleSource($renditionInput->source, $workspace); $rendition->setFile($file); diff --git a/databox/api/src/Api/InputTransformer/AttributeInputTrait.php b/databox/api/src/Api/InputTransformer/AttributeInputTrait.php index ce1a20046..f1e7262b4 100644 --- a/databox/api/src/Api/InputTransformer/AttributeInputTrait.php +++ b/databox/api/src/Api/InputTransformer/AttributeInputTrait.php @@ -75,7 +75,7 @@ protected function assignAttributes( $attr = clone $attribute; $attr->value = $value; /** @var Attribute|TemplateAttribute $returnedAttribute */ - $returnedAttribute = $attributeInputProcessor->transform($attr, $returnedAttribute::class, $subContext); + $returnedAttribute = $attributeInputProcessor->transform($attr, Attribute::class, $subContext); $object->addAttribute($returnedAttribute); } @@ -85,7 +85,7 @@ protected function assignAttributes( } /** @var Attribute|TemplateAttribute $returnedAttribute */ - $returnedAttribute = $attributeInputProcessor->transform($attribute, $attribute::class, $subContext); + $returnedAttribute = $attributeInputProcessor->transform($attribute, Attribute::class, $subContext); $object->addAttribute($returnedAttribute); } } diff --git a/databox/api/src/Attribute/AttributeAssigner.php b/databox/api/src/Attribute/AttributeAssigner.php index 078816e68..b77b82b2a 100644 --- a/databox/api/src/Attribute/AttributeAssigner.php +++ b/databox/api/src/Attribute/AttributeAssigner.php @@ -53,7 +53,7 @@ public function assignAttributeFromInput(AbstractBaseAttribute $attribute, Abstr $type = $this->attributeTypeRegistry->getStrictType($attribute->getDefinition()->getFieldType()); $value = $type->normalizeValue($data->value); - $attribute->setValue($value); + $attribute->setValue($value ?? ''); $attribute->setPosition($data->position ?? 0); return $attribute; diff --git a/databox/api/src/Storage/RenditionManager.php b/databox/api/src/Storage/RenditionManager.php index 93ce639a2..bd589e23f 100644 --- a/databox/api/src/Storage/RenditionManager.php +++ b/databox/api/src/Storage/RenditionManager.php @@ -131,6 +131,23 @@ public function getRenditionDefinitionByName(Workspace $workspace, string $name) return $definition; } + public function getRenditionDefinitionById(Workspace $workspace, string $id): RenditionDefinition + { + $definition = $this + ->em + ->getRepository(RenditionDefinition::class) + ->findOneBy([ + 'id' => $id, + 'workspace' => $workspace->getId(), + ]); + + if (!$definition instanceof RenditionDefinition) { + throw new \InvalidArgumentException(sprintf('Rendition definition "%s" not found', $id)); + } + + return $definition; + } + public function resetAssetRenditions(Asset $asset): void { $renditions = $asset->getRenditions(); diff --git a/databox/indexer/package.json b/databox/indexer/package.json index bacd3ae61..54404d177 100644 --- a/databox/indexer/package.json +++ b/databox/indexer/package.json @@ -18,6 +18,7 @@ "scripts": { "start": "node --enable-source-maps dist/index.js", "console": "node --enable-source-maps dist/console.js", + "console:dev": "ts-node --files ./src/console.ts", "build": "rimraf ./dist && tsc", "start:dev": "nodemon", "test": "jest", diff --git a/databox/indexer/src/databox/types.d.ts b/databox/indexer/src/databox/types.d.ts index f0de4656c..1a416041a 100644 --- a/databox/indexer/src/databox/types.d.ts +++ b/databox/indexer/src/databox/types.d.ts @@ -43,7 +43,8 @@ export type AttributeInput = ({value: any} | {values: any[]}) & { } export type RenditionInput = { - definition: string; + definitionId?: string; + name?: string; source?: Source; } diff --git a/databox/indexer/src/handlers/phraseanet/shared.ts b/databox/indexer/src/handlers/phraseanet/shared.ts index ef4d11823..1dea2b6bf 100644 --- a/databox/indexer/src/handlers/phraseanet/shared.ts +++ b/databox/indexer/src/handlers/phraseanet/shared.ts @@ -40,7 +40,7 @@ export function createAsset( const ad = attrDefinitionIndex[c.meta_structure_id.toString()]; const d = { - definition: `/attribute-definitions/${ad.id}`, + definitionId: ad.id, origin: 'machine', originVendor: 'indexer-import', } as Partial; @@ -59,7 +59,7 @@ export function createAsset( } return { - definition: defName, + name: defName, sourceFile: { url: s.permalink.url, isPrivate: false,