-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/master' into feature/secrets-pro…
…vider
- Loading branch information
Showing
8 changed files
with
246 additions
and
39 deletions.
There are no files selected for viewing
76 changes: 76 additions & 0 deletions
76
infra/prism-api/src/main/java/com/evolveum/midpoint/prism/ResolvedItemPath.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
/* | ||
* Copyright (C) 2010-2024 Evolveum and contributors | ||
* | ||
* This work is dual-licensed under the Apache License 2.0 | ||
* and European Union Public License. See LICENSE file for details. | ||
*/ | ||
|
||
package com.evolveum.midpoint.prism; | ||
|
||
import java.io.Serializable; | ||
|
||
import org.jetbrains.annotations.NotNull; | ||
|
||
import com.evolveum.midpoint.prism.path.ItemPath; | ||
import com.evolveum.midpoint.util.annotation.Experimental; | ||
|
||
/** | ||
* Resolution of a path in a prism container definition, as far as possible. | ||
* See {@link #resolvedPath}, {@link #remainderPath} and {@link #lastDefinition} for details. | ||
*/ | ||
@Experimental | ||
public class ResolvedItemPath<ID extends ItemDefinition<?>> implements Serializable { | ||
|
||
/** The path as in the definitions, i.e. usually with qualified names. */ | ||
@NotNull private final ItemPath resolvedPath; | ||
|
||
/** Path that cannot be resolved. Hopefully empty. */ | ||
@NotNull private final ItemPath remainderPath; | ||
|
||
/** Definition of the last item in {@link #resolvedPath}. */ | ||
@NotNull private final ID lastDefinition; | ||
|
||
private ResolvedItemPath(@NotNull ItemPath resolvedPath, @NotNull ItemPath remainderPath, @NotNull ID lastDefinition) { | ||
this.lastDefinition = lastDefinition; | ||
this.resolvedPath = resolvedPath; | ||
this.remainderPath = remainderPath; | ||
} | ||
|
||
/** Resolves the path against a container definition. The path should be "names-only". */ | ||
public static <ID extends ItemDefinition<?>> ResolvedItemPath<ID> create( | ||
@NotNull PrismContainerDefinition<?> rootDefinition, @NotNull ItemPath rawItemPath) { | ||
ItemPath resolvedPath = ItemPath.EMPTY_PATH; | ||
ItemPath remainderPath = rawItemPath.namedSegmentsOnly(); | ||
PrismContainerDefinition<?> currentDefinition = rootDefinition; | ||
for (;;) { | ||
if (remainderPath.isEmpty()) { | ||
//noinspection unchecked | ||
return new ResolvedItemPath<>(resolvedPath, remainderPath, (ID) currentDefinition); | ||
} | ||
ItemDefinition<?> childDefinition = currentDefinition.findItemDefinition(remainderPath.firstToName()); | ||
if (childDefinition == null) { | ||
//noinspection unchecked | ||
return new ResolvedItemPath<>(resolvedPath, remainderPath, (ID) currentDefinition); | ||
} | ||
resolvedPath = resolvedPath.append(childDefinition.getItemName()); | ||
remainderPath = remainderPath.rest(); | ||
if (!(childDefinition instanceof PrismContainerDefinition<?> childPcd)) { | ||
//noinspection unchecked | ||
return new ResolvedItemPath<>(resolvedPath, remainderPath, (ID) childDefinition); | ||
} | ||
currentDefinition = childPcd; | ||
} | ||
} | ||
|
||
public @NotNull ItemPath getResolvedPath() { | ||
return resolvedPath; | ||
} | ||
|
||
public @NotNull ID getLastDefinition() { | ||
return lastDefinition; | ||
} | ||
|
||
public boolean isComplete() { | ||
return remainderPath.isEmpty(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
114 changes: 114 additions & 0 deletions
114
.../prism-impl/src/test/java/com/evolveum/midpoint/prism/query/lang/TestQueryCompletion.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
package com.evolveum.midpoint.prism.query.lang; | ||
|
||
import com.evolveum.midpoint.prism.*; | ||
import com.evolveum.midpoint.prism.impl.query.lang.AxiomQueryLangServiceImpl; | ||
import com.evolveum.midpoint.prism.schema.SchemaRegistry; | ||
import com.evolveum.midpoint.prism.util.PrismTestUtil; | ||
import com.evolveum.midpoint.util.PrettyPrinter; | ||
import com.evolveum.midpoint.util.exception.SchemaException; | ||
|
||
import org.testng.annotations.BeforeSuite; | ||
import org.testng.annotations.Test; | ||
import org.xml.sax.SAXException; | ||
import org.testng.Assert; | ||
|
||
import javax.xml.namespace.QName; | ||
import java.io.IOException; | ||
import java.util.*; | ||
|
||
import static com.evolveum.midpoint.prism.PrismInternalTestUtil.DEFAULT_NAMESPACE_PREFIX; | ||
|
||
/** | ||
* Created by Dominik. | ||
*/ | ||
public class TestQueryCompletion extends AbstractPrismTest { | ||
|
||
private AxiomQueryLangServiceImpl axiomQueryLangServiceImpl; | ||
|
||
private SchemaRegistry schemaRegistry; | ||
|
||
@BeforeSuite | ||
public void setupDebug() throws SchemaException, SAXException, IOException { | ||
PrettyPrinter.setDefaultNamespacePrefix(DEFAULT_NAMESPACE_PREFIX); | ||
PrismTestUtil.resetPrismContext(new PrismInternalTestUtil()); | ||
axiomQueryLangServiceImpl = new AxiomQueryLangServiceImpl(PrismContext.get()); | ||
schemaRegistry = PrismContext.get().getSchemaRegistry(); | ||
} | ||
|
||
|
||
// Basic filters | ||
@Test | ||
public void testQueryCompletionDot() { | ||
String query = ". "; | ||
Map<String, String> suggestions = axiomQueryLangServiceImpl.queryCompletion(query); | ||
Map<String, String> expected = new HashMap<>(); | ||
expected.put("isRoot", null); | ||
expected.put("inOrg", null); | ||
expected.put("referencedBy", null); | ||
expected.put("matches", null); | ||
expected.put("ownedBy", null); | ||
expected.put("inOid", null); | ||
|
||
Assert.assertEquals(suggestions.keySet().stream().sorted().toList(), expected.keySet().stream().sorted().toList()); | ||
} | ||
|
||
@Test | ||
public void testQueryCompletionTypesOfUserType() { | ||
String query = ". type "; | ||
TypeDefinition typeDefinition = schemaRegistry.findTypeDefinitionByType(new QName("UserType")); | ||
Map<String, String> suggestions = axiomQueryLangServiceImpl.queryCompletion(query); | ||
List<String> objectTypes = schemaRegistry.getAllSubTypesByTypeDefinition(Collections.singletonList(typeDefinition)).stream().map(item -> item.getTypeName().getLocalPart()).sorted().toList(); | ||
Assert.assertEquals(suggestions.keySet().stream().sorted().toList(), objectTypes); | ||
} | ||
|
||
@Test | ||
public void testQueryCompletionBasePathsOfUserType() { | ||
String query = ". type UserType and "; | ||
TypeDefinition typeDefinition = schemaRegistry.findTypeDefinitionByType(new QName("UserType")); | ||
PrismObjectDefinition<?> objectDefinition = schemaRegistry.findObjectDefinitionByCompileTimeClass((Class) typeDefinition.getCompileTimeClass()); | ||
List<String> itemPaths = new ArrayList<>(objectDefinition.getItemNames().stream().map(QName::getLocalPart).toList()); | ||
itemPaths.add("."); | ||
Map<String, String> suggestions = axiomQueryLangServiceImpl.queryCompletion(query); | ||
Assert.assertEquals(suggestions.keySet().stream().sorted().toList(), itemPaths.stream().sorted().toList()); | ||
} | ||
|
||
@Test | ||
public void testQueryCompletionBaseFilterName() { | ||
String query = ". type UserType and givenName "; | ||
|
||
List<String> expected = new ArrayList<String>(); | ||
expected.add("levenshtein"); | ||
expected.add("greaterOrEqual"); | ||
expected.add("isRoot"); | ||
expected.add("inOrg"); | ||
expected.add("lessOrEqual"); | ||
expected.add("notEqual"); | ||
expected.add("fullText"); | ||
expected.add("less"); | ||
expected.add("type"); | ||
expected.add("equal"); | ||
expected.add("contains"); | ||
expected.add("ownedByOid"); | ||
expected.add("similarity"); | ||
expected.add("endsWith"); | ||
expected.add("exists"); | ||
expected.add("anyIn"); | ||
expected.add("greater"); | ||
expected.add("ownedBy"); | ||
expected.add("inOid"); | ||
expected.add("startsWith"); | ||
expected.add("not"); | ||
|
||
Map<String, String> suggestions = axiomQueryLangServiceImpl.queryCompletion(query); | ||
Assert.assertEquals(suggestions.keySet().stream().sorted().toList(), expected.stream().sorted().toList()); | ||
} | ||
|
||
@Test | ||
public void testQueryCompletionBaseSubFilter() { | ||
String query = ". type UserType and givenName equal \"Jack\" "; | ||
Map<String, String> suggestions = axiomQueryLangServiceImpl.queryCompletion(query); | ||
Assert.assertEquals(suggestions.keySet().stream().sorted().toList(), List.of("and", "or")); | ||
} | ||
|
||
// Advanced filters | ||
} |
Oops, something went wrong.