Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

!!! TASK: Rename NodeTypeConstraints to NodeTypeCriteria #4551

Merged
merged 7 commits into from
Nov 3, 2023
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@
use Neos\ContentRepository\Core\Projection\ContentGraph\Node;
use Neos\ContentRepository\Core\Projection\ContentGraph\NodePath;
use Neos\ContentRepository\Core\Projection\ContentGraph\Nodes;
use Neos\ContentRepository\Core\Projection\ContentGraph\NodeTypeConstraints;
use Neos\ContentRepository\Core\Projection\ContentGraph\NodeTypeConstraintsWithSubNodeTypes;
use Neos\ContentRepository\Core\Projection\ContentGraph\Filter\NodeType\NodeTypeCriteria;
use Neos\ContentRepository\Core\Projection\ContentGraph\Filter\NodeType\ExpandedNodeTypeCriteria;
use Neos\ContentRepository\Core\Projection\ContentGraph\References;
use Neos\ContentRepository\Core\Projection\ContentGraph\SearchTerm;
use Neos\ContentRepository\Core\Projection\ContentGraph\Subtree;
Expand Down Expand Up @@ -301,8 +301,8 @@ public function findSubtree(NodeAggregateId $entryNodeAggregateId, FindSubtreeFi
if ($filter->maximumLevels !== null) {
$queryBuilderRecursive->andWhere('p.level < :maximumLevels')->setParameter('maximumLevels', $filter->maximumLevels);
}
if ($filter->nodeTypeConstraints !== null) {
$this->addNodeTypeConstraints($queryBuilderRecursive, $filter->nodeTypeConstraints, 'c');
if ($filter->nodeTypes !== null) {
$this->addNodeTypeCriteria($queryBuilderRecursive, $filter->nodeTypes, 'c');
}
$this->addRestrictionRelationConstraints($queryBuilderRecursive, 'c');

Expand Down Expand Up @@ -399,8 +399,8 @@ public function findClosestNode(NodeAggregateId $entryNodeAggregateId, FindClose
->setParameter('contentStreamId', $this->contentStreamId->value)
->setParameter('dimensionSpacePointHash', $this->dimensionSpacePoint->hash)
->setParameter('entryNodeAggregateId', $entryNodeAggregateId->value);
if ($filter->nodeTypeConstraints !== null) {
$this->addNodeTypeConstraints($queryBuilderCte, $filter->nodeTypeConstraints, 'p');
if ($filter->nodeTypes !== null) {
$this->addNodeTypeCriteria($queryBuilderCte, $filter->nodeTypes, 'p');
}
$nodeRows = $this->fetchCteResults(
$queryBuilderInitial,
Expand Down Expand Up @@ -509,10 +509,10 @@ private function addRestrictionRelationConstraints(QueryBuilder $queryBuilder, s
);
}

private function addNodeTypeConstraints(QueryBuilder $queryBuilder, NodeTypeConstraints $nodeTypeConstraints, string $nodeTableAlias = 'n'): void
private function addNodeTypeCriteria(QueryBuilder $queryBuilder, NodeTypeCriteria $nodeTypeCriteria, string $nodeTableAlias = 'n'): void
{
$nodeTablePrefix = $nodeTableAlias === '' ? '' : $nodeTableAlias . '.';
$constraintsWithSubNodeTypes = NodeTypeConstraintsWithSubNodeTypes::create($nodeTypeConstraints, $this->nodeTypeManager);
$constraintsWithSubNodeTypes = ExpandedNodeTypeCriteria::create($nodeTypeCriteria, $this->nodeTypeManager);
$allowanceQueryPart = '';
if (!$constraintsWithSubNodeTypes->explicitlyAllowedNodeTypeNames->isEmpty()) {
$allowanceQueryPart = $queryBuilder->expr()->in($nodeTablePrefix . 'nodetypename', ':explicitlyAllowedNodeTypeNames');
Expand Down Expand Up @@ -611,8 +611,8 @@ private function buildChildNodesQuery(NodeAggregateId $parentNodeAggregateId, Fi
->where('pn.nodeaggregateid = :parentNodeAggregateId')->setParameter('parentNodeAggregateId', $parentNodeAggregateId->value)
->andWhere('h.contentstreamid = :contentStreamId')->setParameter('contentStreamId', $this->contentStreamId->value)
->andWhere('h.dimensionspacepointhash = :dimensionSpacePointHash')->setParameter('dimensionSpacePointHash', $this->dimensionSpacePoint->hash);
if ($filter->nodeTypeConstraints !== null) {
$this->addNodeTypeConstraints($queryBuilder, $filter->nodeTypeConstraints);
if ($filter->nodeTypes !== null) {
$this->addNodeTypeCriteria($queryBuilder, $filter->nodeTypes);
}
if ($filter->searchTerm !== null) {
$this->addSearchTermConstraints($queryBuilder, $filter->searchTerm);
Expand Down Expand Up @@ -642,8 +642,8 @@ private function buildReferencesQuery(bool $backReferences, NodeAggregateId $nod
->andWhere('sh.contentstreamid = :contentStreamId');
$this->addRestrictionRelationConstraints($queryBuilder, 'dn', 'dh');
$this->addRestrictionRelationConstraints($queryBuilder, 'sn', 'sh');
if ($filter->nodeTypeConstraints !== null) {
$this->addNodeTypeConstraints($queryBuilder, $filter->nodeTypeConstraints, "{$destinationTablePrefix}n");
if ($filter->nodeTypes !== null) {
$this->addNodeTypeCriteria($queryBuilder, $filter->nodeTypes, "{$destinationTablePrefix}n");
}
if ($filter->nodeSearchTerm !== null) {
$this->addSearchTermConstraints($queryBuilder, $filter->nodeSearchTerm, "{$destinationTablePrefix}n");
Expand Down Expand Up @@ -708,8 +708,8 @@ private function buildSiblingsQuery(bool $preceding, NodeAggregateId $siblingNod
->orderBy('h.position', $preceding ? 'DESC' : 'ASC');

$this->addRestrictionRelationConstraints($queryBuilder);
if ($filter->nodeTypeConstraints !== null) {
$this->addNodeTypeConstraints($queryBuilder, $filter->nodeTypeConstraints);
if ($filter->nodeTypes !== null) {
$this->addNodeTypeCriteria($queryBuilder, $filter->nodeTypes);
}
if ($filter->searchTerm !== null) {
$this->addSearchTermConstraints($queryBuilder, $filter->searchTerm);
Expand Down Expand Up @@ -758,8 +758,8 @@ private function buildAncestorNodesQueries(NodeAggregateId $entryNodeAggregateId
->setParameter('contentStreamId', $this->contentStreamId->value)
->setParameter('dimensionSpacePointHash', $this->dimensionSpacePoint->hash)
->setParameter('entryNodeAggregateId', $entryNodeAggregateId->value);
if ($filter->nodeTypeConstraints !== null) {
$this->addNodeTypeConstraints($queryBuilderCte, $filter->nodeTypeConstraints, 'p');
if ($filter->nodeTypes !== null) {
$this->addNodeTypeCriteria($queryBuilderCte, $filter->nodeTypes, 'p');
}
return compact('queryBuilderInitial', 'queryBuilderRecursive', 'queryBuilderCte');
}
Expand Down Expand Up @@ -799,8 +799,8 @@ private function buildDescendantNodesQueries(NodeAggregateId $entryNodeAggregate
->setParameter('contentStreamId', $this->contentStreamId->value)
->setParameter('dimensionSpacePointHash', $this->dimensionSpacePoint->hash)
->setParameter('entryNodeAggregateId', $entryNodeAggregateId->value);
if ($filter->nodeTypeConstraints !== null) {
$this->addNodeTypeConstraints($queryBuilderCte, $filter->nodeTypeConstraints);
if ($filter->nodeTypes !== null) {
$this->addNodeTypeCriteria($queryBuilderCte, $filter->nodeTypes);
}
if ($filter->searchTerm !== null) {
$this->addSearchTermConstraints($queryBuilderCte, $filter->searchTerm);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@
use Neos\ContentRepository\Core\Projection\ContentGraph\Node;
use Neos\ContentRepository\Core\Projection\ContentGraph\NodePath;
use Neos\ContentRepository\Core\Projection\ContentGraph\Nodes;
use Neos\ContentRepository\Core\Projection\ContentGraph\NodeTypeConstraints;
use Neos\ContentRepository\Core\Projection\ContentGraph\NodeTypeConstraintsWithSubNodeTypes;
use Neos\ContentRepository\Core\Projection\ContentGraph\Filter\NodeType\NodeTypeCriteria;
use Neos\ContentRepository\Core\Projection\ContentGraph\Filter\NodeType\ExpandedNodeTypeCriteria;
use Neos\ContentRepository\Core\Projection\ContentGraph\References;
use Neos\ContentRepository\Core\Projection\ContentGraph\Subtree;
use Neos\ContentRepository\Core\Projection\ContentGraph\VisibilityConstraints;
Expand Down Expand Up @@ -139,12 +139,12 @@ public function findChildNodes(
);
$query = $query->withDimensionSpacePoint($this->dimensionSpacePoint)
->withRestriction($this->visibilityConstraints);
if (!is_null($filter->nodeTypeConstraints)) {
$nodeTypeConstraintsWithSubNodeTypes = NodeTypeConstraintsWithSubNodeTypes::create(
$filter->nodeTypeConstraints,
if (!is_null($filter->nodeTypes)) {
$expandedNodeTypeCriteria = ExpandedNodeTypeCriteria::create(
$filter->nodeTypes,
$this->nodeTypeManager
);
$query = $query->withNodeTypeConstraints($nodeTypeConstraintsWithSubNodeTypes, 'cn');
$query = $query->withNodeTypeCriteria($expandedNodeTypeCriteria, 'cn');
}
if (!is_null($filter->pagination)) {
$query = $query
Expand Down Expand Up @@ -217,12 +217,12 @@ public function findBackReferences(
->withSourceRestriction($this->visibilityConstraints)
->withTargetRestriction($this->visibilityConstraints);

if ($filter->nodeTypeConstraints) {
$nodeTypeConstraintsWithSubNodeTypes = NodeTypeConstraintsWithSubNodeTypes::create(
$filter->nodeTypeConstraints,
if ($filter->nodeTypes) {
$expandedNodeTypeCriteria = ExpandedNodeTypeCriteria::create(
$filter->nodeTypes,
$this->nodeTypeManager
);
$query = $query->withNodeTypeConstraints($nodeTypeConstraintsWithSubNodeTypes, 'srcn');
$query = $query->withNodeTypeCriteria($expandedNodeTypeCriteria, 'srcn');
}
$orderings = [];
if ($filter->referenceName) {
Expand Down Expand Up @@ -316,7 +316,7 @@ public function findSucceedingSiblingNodes(
return $this->findAnySiblings(
$siblingNodeAggregateId,
HypergraphSiblingQueryMode::MODE_ONLY_SUCCEEDING,
$filter->nodeTypeConstraints,
$filter->nodeTypes,
$filter->pagination,
);
}
Expand All @@ -328,15 +328,15 @@ public function findPrecedingSiblingNodes(
return $this->findAnySiblings(
$siblingNodeAggregateId,
HypergraphSiblingQueryMode::MODE_ONLY_PRECEDING,
$filter->nodeTypeConstraints,
$filter->nodeTypes,
$filter->pagination,
);
}

private function findAnySiblings(
NodeAggregateId $sibling,
HypergraphSiblingQueryMode $mode,
?NodeTypeConstraints $nodeTypeConstraints = null,
?NodeTypeCriteria $nodeTypeCriteria = null,
?Pagination $pagination = null,
): Nodes {
$query = HypergraphSiblingQuery::create(
Expand All @@ -347,12 +347,12 @@ private function findAnySiblings(
$this->tableNamePrefix
);
$query = $query->withRestriction($this->visibilityConstraints);
if (!is_null($nodeTypeConstraints)) {
$nodeTypeConstraintsWithSubNodeTypes = NodeTypeConstraintsWithSubNodeTypes::create(
$nodeTypeConstraints,
if (!is_null($nodeTypeCriteria)) {
$expandedNodeTypeCriteria = ExpandedNodeTypeCriteria::create(
$nodeTypeCriteria,
$this->nodeTypeManager
);
$query = $query->withNodeTypeConstraints($nodeTypeConstraintsWithSubNodeTypes, 'sn');
$query = $query->withNodeTypeCriteria($expandedNodeTypeCriteria, 'sn');
}
$query = $query->withOrdinalityOrdering($mode->isOrderingToBeReversed());
if (!is_null($pagination)) {
Expand Down Expand Up @@ -383,14 +383,14 @@ public function findSubtree(
];

$types = [];
if ($filter->nodeTypeConstraints !== null) {
$nodeTypeConstraintsWithSubNodeTypes = NodeTypeConstraintsWithSubNodeTypes::create(
$filter->nodeTypeConstraints,
if ($filter->nodeTypes !== null) {
$expandedNodeTypeCriteria = ExpandedNodeTypeCriteria::create(
$filter->nodeTypes,
$this->nodeTypeManager
);
$nodeTypeConstraintsClause = QueryUtility::getNodeTypeConstraintsClause($nodeTypeConstraintsWithSubNodeTypes, 'cn', $parameters, $types);
$nodeTypeCriteriaClause = QueryUtility::getNodeTypeCriteriaClause($expandedNodeTypeCriteria, 'cn', $parameters, $types);
} else {
$nodeTypeConstraintsClause = '';
$nodeTypeCriteriaClause = '';
}

$query = /** @lang PostgreSQL */
Expand Down Expand Up @@ -438,7 +438,7 @@ public function findSubtree(
AND ch.dimensionspacepointhash = :dimensionSpacePointHash
' . ($filter->maximumLevels !== null ? 'AND p.level + 1 <= :maximumLevels' : '') . '
' . QueryUtility::getRestrictionClause($this->visibilityConstraints, $this->tableNamePrefix, 'c') . '
' . $nodeTypeConstraintsClause . '
' . $nodeTypeCriteriaClause . '
)
SELECT * FROM subtree
-- NOTE: it is crucially important that *inside* a single level, we
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
use Doctrine\DBAL\Connection;
use Doctrine\DBAL\Driver\ResultStatement;
use Doctrine\DBAL\ForwardCompatibility\Result as QueryResult;
use Neos\ContentRepository\Core\Projection\ContentGraph\NodeTypeConstraints;
use Neos\ContentRepository\Core\Projection\ContentGraph\NodeTypeConstraintsWithSubNodeTypes;
use Neos\ContentRepository\Core\Projection\ContentGraph\Filter\NodeType\NodeTypeCriteria;
use Neos\ContentRepository\Core\Projection\ContentGraph\Filter\NodeType\ExpandedNodeTypeCriteria;

/**
* @internal
Expand Down Expand Up @@ -52,13 +52,13 @@ final protected function __construct(
$this->types = $types;
}

final public function withNodeTypeConstraints(
NodeTypeConstraintsWithSubNodeTypes $nodeTypeConstraints,
final public function withNodeTypeCriteria(
ExpandedNodeTypeCriteria $nodeTypeCriteria,
string $prefix
): self {
$parameters = $this->parameters;
$types = $this->types;
$query = $this->query . QueryUtility::getNodeTypeConstraintsClause($nodeTypeConstraints, $prefix, $parameters, $types);
$query = $this->query . QueryUtility::getNodeTypeCriteriaClause($nodeTypeCriteria, $prefix, $parameters, $types);
return new self($query, $parameters, $this->tableNamePrefix, $types);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
namespace Neos\ContentGraph\PostgreSQLAdapter\Domain\Repository\Query;

use Doctrine\DBAL\Connection;
use Neos\ContentRepository\Core\Projection\ContentGraph\NodeTypeConstraintsWithSubNodeTypes;
use Neos\ContentRepository\Core\Projection\ContentGraph\Filter\NodeType\ExpandedNodeTypeCriteria;
use Neos\ContentRepository\Core\Projection\ContentGraph\VisibilityConstraints;

/**
Expand Down Expand Up @@ -43,26 +43,26 @@ public static function getRestrictionClause(
}

/**
* @param NodeTypeConstraintsWithSubNodeTypes $nodeTypeConstraints
* @param ExpandedNodeTypeCriteria $nodeTypeCriteria
* @param string $prefix
* @param array<string,mixed> $parameters
* @param array<string,int|string> $types
* @return string
*/
public static function getNodeTypeConstraintsClause(
NodeTypeConstraintsWithSubNodeTypes $nodeTypeConstraints,
public static function getNodeTypeCriteriaClause(
ExpandedNodeTypeCriteria $nodeTypeCriteria,
string $prefix,
array &$parameters,
array &$types,
): string {
$query = '';
$parameters['allowedNodeTypeNames'] = $nodeTypeConstraints->explicitlyAllowedNodeTypeNames->toStringArray();
$parameters['disallowedNodeTypeNames'] = $nodeTypeConstraints->explicitlyDisallowedNodeTypeNames->toStringArray();
$parameters['allowedNodeTypeNames'] = $nodeTypeCriteria->explicitlyAllowedNodeTypeNames->toStringArray();
$parameters['disallowedNodeTypeNames'] = $nodeTypeCriteria->explicitlyDisallowedNodeTypeNames->toStringArray();
$types['allowedNodeTypeNames'] = Connection::PARAM_STR_ARRAY;
$types['disallowedNodeTypeNames'] = Connection::PARAM_STR_ARRAY;
if (!$nodeTypeConstraints->explicitlyAllowedNodeTypeNames->isEmpty()) {
if (!$nodeTypeConstraints->explicitlyDisallowedNodeTypeNames->isEmpty()) {
if ($nodeTypeConstraints->isWildCardAllowed) {
if (!$nodeTypeCriteria->explicitlyAllowedNodeTypeNames->isEmpty()) {
if (!$nodeTypeCriteria->explicitlyDisallowedNodeTypeNames->isEmpty()) {
if ($nodeTypeCriteria->isWildCardAllowed) {
$query .= '
AND ' . $prefix . '.nodetypename NOT IN (:disallowedNodeTypeNames)
OR ' . $prefix . '.nodetypename IN (:allowedNodeTypeNames)';
Expand All @@ -72,12 +72,12 @@ public static function getNodeTypeConstraintsClause(
AND ' . $prefix . '.nodetypename NOT IN (:disallowedNodeTypeNames)';
}
} else {
if (!$nodeTypeConstraints->isWildCardAllowed) {
if (!$nodeTypeCriteria->isWildCardAllowed) {
$query .= '
AND ' . $prefix . '.nodetypename IN (:allowedNodeTypeNames)';
}
}
} elseif (!$nodeTypeConstraints->explicitlyDisallowedNodeTypeNames->isEmpty()) {
} elseif (!$nodeTypeCriteria->explicitlyDisallowedNodeTypeNames->isEmpty()) {
$query .= '
AND ' . $prefix . '.nodetypename NOT IN (:disallowedNodeTypeNames)';
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,4 +92,4 @@ Feature: Find and count nodes using the findAncestorNodes and countAncestorNodes

# findAncestorNodes queries with results
When I execute the findAncestorNodes query for entry node aggregate id "a2a2b" I expect the nodes "a2a2,a2a,a2,a,home,lady-eleonode-rootford" to be returned and the total count to be 6
When I execute the findAncestorNodes query for entry node aggregate id "a2a2b" and filter '{"nodeTypeConstraints": "Neos.ContentRepository.Testing:Page"}' I expect the nodes "a2a2,a2,a" to be returned and the total count to be 3
When I execute the findAncestorNodes query for entry node aggregate id "a2a2b" and filter '{"nodeTypes": "Neos.ContentRepository.Testing:Page"}' I expect the nodes "a2a2,a2,a" to be returned and the total count to be 3
Loading
Loading