Skip to content

Commit

Permalink
TASK: Pass ContentStreamId to NodeFactory
Browse files Browse the repository at this point in the history
  • Loading branch information
dlubitz authored and mhsdesign committed Mar 15, 2024
1 parent bfd43df commit d24324b
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ public function findRootNodeAggregates(
->andWhere('n.nodetypename = :nodeTypeName')
->setParameter('nodeTypeName', $filter->nodeTypeName->value);
}
return NodeAggregates::fromArray(iterator_to_array($this->mapQueryBuilderToNodeAggregates($queryBuilder)));
return NodeAggregates::fromArray(iterator_to_array($this->mapQueryBuilderToNodeAggregates($queryBuilder, $contentStreamId)));
}

public function findNodeAggregatesByType(
Expand All @@ -169,7 +169,7 @@ public function findNodeAggregatesByType(
'contentStreamId' => $contentStreamId->value,
'nodeTypeName' => $nodeTypeName->value,
]);
return $this->mapQueryBuilderToNodeAggregates($queryBuilder);
return $this->mapQueryBuilderToNodeAggregates($queryBuilder, $contentStreamId);
}

public function findNodeAggregateById(
Expand All @@ -189,6 +189,7 @@ public function findNodeAggregateById(

return $this->nodeFactory->mapNodeRowsToNodeAggregate(
$this->fetchRows($queryBuilder),
$contentStreamId,
VisibilityConstraints::withoutRestrictions()
);
}
Expand All @@ -214,7 +215,7 @@ public function findParentNodeAggregates(
'contentStreamId' => $contentStreamId->value
]);

return $this->mapQueryBuilderToNodeAggregates($queryBuilder);
return $this->mapQueryBuilderToNodeAggregates($queryBuilder, $contentStreamId);
}

public function findParentNodeAggregateByChildOriginDimensionSpacePoint(
Expand Down Expand Up @@ -246,6 +247,7 @@ public function findParentNodeAggregateByChildOriginDimensionSpacePoint(

return $this->nodeFactory->mapNodeRowsToNodeAggregate(
$this->fetchRows($queryBuilder),
$contentStreamId,
VisibilityConstraints::withoutRestrictions()
);
}
Expand All @@ -258,7 +260,7 @@ public function findChildNodeAggregates(
NodeAggregateId $parentNodeAggregateId
): iterable {
$queryBuilder = $this->buildChildNodeAggregateQuery($parentNodeAggregateId, $contentStreamId);
return $this->mapQueryBuilderToNodeAggregates($queryBuilder);
return $this->mapQueryBuilderToNodeAggregates($queryBuilder, $contentStreamId);
}

/**
Expand All @@ -272,7 +274,7 @@ public function findChildNodeAggregatesByName(
$queryBuilder = $this->buildChildNodeAggregateQuery($parentNodeAggregateId, $contentStreamId)
->andWhere('ch.name = :relationName')
->setParameter('relationName', $name->value);
return $this->mapQueryBuilderToNodeAggregates($queryBuilder);
return $this->mapQueryBuilderToNodeAggregates($queryBuilder, $contentStreamId);
}

/**
Expand All @@ -285,7 +287,7 @@ public function findTetheredChildNodeAggregates(
$queryBuilder = $this->buildChildNodeAggregateQuery($parentNodeAggregateId, $contentStreamId)
->andWhere('cn.classification = :tetheredClassification')
->setParameter('tetheredClassification', NodeAggregateClassification::CLASSIFICATION_TETHERED->value);
return $this->mapQueryBuilderToNodeAggregates($queryBuilder);
return $this->mapQueryBuilderToNodeAggregates($queryBuilder, $contentStreamId);
}

/**
Expand Down Expand Up @@ -390,10 +392,11 @@ private function createQueryBuilder(): QueryBuilder
* @param QueryBuilder $queryBuilder
* @return iterable<NodeAggregate>
*/
private function mapQueryBuilderToNodeAggregates(QueryBuilder $queryBuilder): iterable
private function mapQueryBuilderToNodeAggregates(QueryBuilder $queryBuilder, ContentStreamId $contentStreamId): iterable
{
return $this->nodeFactory->mapNodeRowsToNodeAggregates(
$this->fetchRows($queryBuilder),
$contentStreamId,
VisibilityConstraints::withoutRestrictions()
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ public function findSubtree(NodeAggregateId $entryNodeAggregateId, FindSubtreeFi
foreach (array_reverse($result) as $nodeData) {
$nodeAggregateId = $nodeData['nodeaggregateid'];
$parentNodeAggregateId = $nodeData['parentNodeAggregateId'];
$node = $this->nodeFactory->mapNodeRowToNode($nodeData, $this->dimensionSpacePoint, $this->visibilityConstraints);
$node = $this->nodeFactory->mapNodeRowToNode($nodeData, $this->contentStreamId, $this->dimensionSpacePoint, $this->visibilityConstraints);
$subtree = new Subtree((int)$nodeData['level'], $node, array_key_exists($nodeAggregateId, $subtreesByParentNodeId) ? array_reverse($subtreesByParentNodeId[$nodeAggregateId]) : []);
if ($subtree->level === 0) {
return $subtree;
Expand Down Expand Up @@ -357,6 +357,7 @@ public function findAncestorNodes(NodeAggregateId $entryNodeAggregateId, FindAnc

return $this->nodeFactory->mapNodeRowsToNodes(
$nodeRows,
$this->contentStreamId,
$this->dimensionSpacePoint,
$this->visibilityConstraints
);
Expand Down Expand Up @@ -417,6 +418,7 @@ public function findClosestNode(NodeAggregateId $entryNodeAggregateId, FindClose
);
return $this->nodeFactory->mapNodeRowsToNodes(
$nodeRows,
$this->contentStreamId,
$this->dimensionSpacePoint,
$this->visibilityConstraints
)->first();
Expand All @@ -433,7 +435,7 @@ public function findDescendantNodes(NodeAggregateId $entryNodeAggregateId, FindD
}
$queryBuilderCte->addOrderBy('level')->addOrderBy('position');
$nodeRows = $this->fetchCteResults($queryBuilderInitial, $queryBuilderRecursive, $queryBuilderCte, 'tree');
return $this->nodeFactory->mapNodeRowsToNodes($nodeRows, $this->dimensionSpacePoint, $this->visibilityConstraints);
return $this->nodeFactory->mapNodeRowsToNodes($nodeRows, $this->contentStreamId, $this->dimensionSpacePoint, $this->visibilityConstraints);
}

public function countDescendantNodes(NodeAggregateId $entryNodeAggregateId, CountDescendantNodesFilter $filter): int
Expand Down Expand Up @@ -861,6 +863,7 @@ private function fetchNode(QueryBuilder $queryBuilder): ?Node
}
return $this->nodeFactory->mapNodeRowToNode(
$nodeRow,
$this->contentStreamId,
$this->dimensionSpacePoint,
$this->visibilityConstraints
);
Expand All @@ -873,7 +876,7 @@ private function fetchNodes(QueryBuilder $queryBuilder): Nodes
} catch (DbalDriverException | DbalException $e) {
throw new \RuntimeException(sprintf('Failed to fetch nodes: %s', $e->getMessage()), 1678292896, $e);
}
return $this->nodeFactory->mapNodeRowsToNodes($nodeRows, $this->dimensionSpacePoint, $this->visibilityConstraints);
return $this->nodeFactory->mapNodeRowsToNodes($nodeRows, $this->contentStreamId, $this->dimensionSpacePoint, $this->visibilityConstraints);
}

private function fetchCount(QueryBuilder $queryBuilder): int
Expand All @@ -892,7 +895,7 @@ private function fetchReferences(QueryBuilder $queryBuilder): References
} catch (DbalDriverException | DbalException $e) {
throw new \RuntimeException(sprintf('Failed to fetch references: %s', $e->getMessage()), 1678364944, $e);
}
return $this->nodeFactory->mapReferenceRowsToReferences($referenceRows, $this->dimensionSpacePoint, $this->visibilityConstraints);
return $this->nodeFactory->mapReferenceRowsToReferences($referenceRows, $this->contentStreamId, $this->dimensionSpacePoint, $this->visibilityConstraints);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ public function __construct(
*/
public function mapNodeRowToNode(
array $nodeRow,
ContentStreamId $contentStreamId,
DimensionSpacePoint $dimensionSpacePoint,
VisibilityConstraints $visibilityConstraints
): Node {
Expand All @@ -74,7 +75,7 @@ public function mapNodeRowToNode(
return Node::create(
ContentSubgraphIdentity::create(
$this->contentRepositoryId,
ContentStreamId::fromString($nodeRow['contentstreamid']),
$contentStreamId,
$dimensionSpacePoint,
$visibilityConstraints
),
Expand All @@ -98,10 +99,10 @@ public function mapNodeRowToNode(
/**
* @param array<int, array<string, mixed>> $nodeRows
*/
public function mapNodeRowsToNodes(array $nodeRows, DimensionSpacePoint $dimensionSpacePoint, VisibilityConstraints $visibilityConstraints): Nodes
public function mapNodeRowsToNodes(array $nodeRows, ContentStreamId $contentStreamId, DimensionSpacePoint $dimensionSpacePoint, VisibilityConstraints $visibilityConstraints): Nodes
{
return Nodes::fromArray(
array_map(fn (array $nodeRow) => $this->mapNodeRowToNode($nodeRow, $dimensionSpacePoint, $visibilityConstraints), $nodeRows)
array_map(fn (array $nodeRow) => $this->mapNodeRowToNode($nodeRow, $contentStreamId, $dimensionSpacePoint, $visibilityConstraints), $nodeRows)
);
}

Expand All @@ -118,13 +119,15 @@ public function createPropertyCollectionFromJsonString(string $jsonString): Prop
*/
public function mapReferenceRowsToReferences(
array $nodeRows,
ContentStreamId $contentStreamId,
DimensionSpacePoint $dimensionSpacePoint,
VisibilityConstraints $visibilityConstraints
): References {
$result = [];
foreach ($nodeRows as $nodeRow) {
$node = $this->mapNodeRowToNode(
$nodeRow,
$contentStreamId,
$dimensionSpacePoint,
$visibilityConstraints
);
Expand All @@ -146,6 +149,7 @@ public function mapReferenceRowsToReferences(
*/
public function mapNodeRowsToNodeAggregate(
array $nodeRows,
ContentStreamId $contentStreamId,
VisibilityConstraints $visibilityConstraints
): ?NodeAggregate {
if (empty($nodeRows)) {
Expand Down Expand Up @@ -173,6 +177,7 @@ public function mapNodeRowsToNodeAggregate(
// ... so we handle occupation exactly once ...
$nodesByOccupiedDimensionSpacePoints[$occupiedDimensionSpacePoint->hash] = $this->mapNodeRowToNode(
$nodeRow,
$contentStreamId,
$occupiedDimensionSpacePoint->toDimensionSpacePoint(),
$visibilityConstraints
);
Expand Down Expand Up @@ -227,6 +232,7 @@ public function mapNodeRowsToNodeAggregate(
*/
public function mapNodeRowsToNodeAggregates(
iterable $nodeRows,
ContentStreamId $contentStreamId,
VisibilityConstraints $visibilityConstraints
): iterable {
$nodeTypeNames = [];
Expand Down Expand Up @@ -254,6 +260,7 @@ public function mapNodeRowsToNodeAggregates(
$nodesByOccupiedDimensionSpacePointsByNodeAggregate
[$rawNodeAggregateId][$occupiedDimensionSpacePoint->hash] = $this->mapNodeRowToNode(
$nodeRow,
$contentStreamId,
$occupiedDimensionSpacePoint->toDimensionSpacePoint(),
$visibilityConstraints
);
Expand Down

0 comments on commit d24324b

Please sign in to comment.