Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 41 additions & 12 deletions ETLPrototypes/JsonApiToDataSheet.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use axenox\ETL\Interfaces\NoteInterface;
use exface\Core\CommonLogic\DataSheets\CrudCounter;
use exface\Core\CommonLogic\DataSheets\Mappings\DataColumnMapping;
use exface\Core\CommonLogic\DataSheets\Mappings\LookupMapping;
use exface\Core\CommonLogic\Debugger\LogBooks\FlowStepLogBook;
use exface\Core\CommonLogic\UxonObject;
use exface\Core\DataTypes\ArrayDataType;
Expand All @@ -20,6 +21,7 @@
use axenox\ETL\Interfaces\ETLStepResultInterface;
use exface\Core\Factories\DataSheetMapperFactory;
use exface\Core\Factories\MetaObjectFactory;
use exface\Core\Interfaces\DataSheets\DataMappingInterface;
use exface\Core\Interfaces\DataSheets\DataSheetInterface;
use exface\Core\Interfaces\DataSheets\DataSheetMapperInterface;
use exface\Core\Interfaces\Model\MetaObjectInterface;
Expand Down Expand Up @@ -338,20 +340,12 @@ protected function applyDataSheetMapper(
$toTrackedAliases = [];

foreach ($mapper->getMappings() as $mapping) {
// TODO Are there other mappings, where one column might transform into another?
if(!$mapping instanceof DataColumnMapping) {
continue;
}

$fromAlias = $mapping->getFromExpression()->getAttributeAlias();
if(key_exists($fromAlias, $fromTrackedAliases)) {
$toAlias = $mapping->getToExpression()->getAttributeAlias();
$toTrackedAliases[$fromAlias] = $toAlias;
}
$toTrackedAliases = array_merge(
$fromTrackedAliases,
$this->extractTrackedAliases($fromTrackedAliases, $mapping)
);
}

$toTrackedAliases = array_merge($fromTrackedAliases, $toTrackedAliases);

if($rowByRow) {
$passLogBook = true;
$toSheet = $this->applyTransformRowByRow(
Expand Down Expand Up @@ -419,6 +413,41 @@ function ($i, $data) use (
return $toSheet;
}

/**
* Extract tracked aliases from a DataMapping to enable data tracking.
* TODO 2025-09-17: List of supported mappings is incomplete.
*
* @param array $trackedAliases
* @param DataMappingInterface $mapping
* @return array
*/
protected function extractTrackedAliases(array $trackedAliases, DataMappingInterface $mapping) : array
{
switch (true) {
case $mapping instanceof DataColumnMapping:
$fromAlias = $mapping->getFromExpression()->getAttributeAlias();
if(key_exists($fromAlias, $trackedAliases)) {
$toAlias = $mapping->getToExpression()->getAttributeAlias();
return [$fromAlias => $toAlias];
}
break;
case $mapping instanceof LookupMapping:
$result = [];
$toAlias = $mapping->getToExpression()->getAttributeAlias();

foreach ($mapping->getMatches() as $match) {
$fromAlias = $match['from'];
if(key_exists($fromAlias, $trackedAliases)) {
$result[$fromAlias] = $toAlias;
}
}

return $result;
}

return [];
}

/**
* @param DataSheetInterface $toSheet
* @param CrudCounter $crudCounter
Expand Down