Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduced Query Language serialization
- Loading branch information
1 parent
f0a3acc
commit 67c1893
Showing
8 changed files
with
821 additions
and
11 deletions.
There are no files selected for viewing
30 changes: 30 additions & 0 deletions
30
infra/prism-api/src/main/java/com/evolveum/midpoint/prism/query/PrismQuerySerialization.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,30 @@ | ||
/* | ||
* Copyright (C) 2020-2021 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.query; | ||
|
||
import com.evolveum.midpoint.prism.PrismNamespaceContext; | ||
|
||
public interface PrismQuerySerialization { | ||
|
||
PrismNamespaceContext namespaceContext(); | ||
|
||
String filterText(); | ||
|
||
class NotSupportedException extends Exception { | ||
|
||
private static final long serialVersionUID = -5393426442630191647L; | ||
|
||
public NotSupportedException(String message, Throwable cause) { | ||
super(message, cause); | ||
} | ||
|
||
public NotSupportedException(String message) { | ||
super(message); | ||
} | ||
} | ||
|
||
} |
35 changes: 35 additions & 0 deletions
35
infra/prism-api/src/main/java/com/evolveum/midpoint/prism/query/PrismQuerySerializer.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,35 @@ | ||
/* | ||
* Copyright (C) 2020-2021 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.query; | ||
|
||
import java.util.Optional; | ||
|
||
import com.evolveum.midpoint.prism.PrismNamespaceContext; | ||
|
||
public interface PrismQuerySerializer { | ||
|
||
PrismQuerySerialization serialize(ObjectFilter filter, PrismNamespaceContext context) throws PrismQuerySerialization.NotSupportedException; | ||
|
||
|
||
default PrismQuerySerialization serialize(ObjectFilter filter) throws PrismQuerySerialization.NotSupportedException { | ||
return serialize(filter, PrismNamespaceContext.EMPTY); | ||
} | ||
|
||
default Optional<PrismQuerySerialization> trySerialize(ObjectFilter filter) { | ||
return trySerialize(filter, PrismNamespaceContext.EMPTY); | ||
} | ||
|
||
default Optional<PrismQuerySerialization> trySerialize(ObjectFilter filter, PrismNamespaceContext namespaceContext) { | ||
try { | ||
return Optional.of(serialize(filter, namespaceContext)); | ||
} catch (PrismQuerySerialization.NotSupportedException e) { | ||
return Optional.empty(); | ||
} | ||
} | ||
|
||
|
||
} |
69 changes: 69 additions & 0 deletions
69
infra/prism-impl/src/main/java/com/evolveum/midpoint/prism/impl/query/lang/FilterNames.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,69 @@ | ||
/* | ||
* Copyright (C) 2020-2021 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.impl.query.lang; | ||
|
||
import java.util.Map; | ||
import java.util.Optional; | ||
|
||
import javax.xml.namespace.QName; | ||
|
||
import com.google.common.collect.BiMap; | ||
import com.google.common.collect.ImmutableBiMap; | ||
|
||
class FilterNames { | ||
|
||
public static final String QUERY_NS = "http://prism.evolveum.com/xml/ns/public/query-3"; | ||
public static final String MATCHING_RULE_NS = "http://prism.evolveum.com/xml/ns/public/matching-rule-3"; | ||
|
||
public static final QName AND = queryName("and"); | ||
public static final QName OR = queryName("or"); | ||
public static final QName EQUAL = queryName("equal"); | ||
public static final QName LESS = queryName("less"); | ||
public static final QName GREATER = queryName("greater"); | ||
public static final QName LESS_OR_EQUAL = queryName("lessOrEqual"); | ||
public static final QName GREATER_OR_EQUAL = queryName("greaterOrEqual"); | ||
public static final QName CONTAINS = queryName("contains"); | ||
public static final QName STARTS_WITH = queryName("startsWith"); | ||
public static final QName ENDS_WITH = queryName("endsWith"); | ||
public static final QName MATCHES = queryName("matches"); | ||
public static final QName EXISTS = queryName("exists"); | ||
public static final QName FULL_TEXT = queryName("fullText"); | ||
public static final QName IN_OID = queryName("inOid"); | ||
public static final QName OWNED_BY_OID = queryName("ownedByOid"); | ||
public static final QName IN_ORG = queryName("inOrg"); | ||
public static final QName IS_ROOT = queryName("isRoot"); | ||
public static final QName NOT = queryName("not"); | ||
public static final QName NOT_EQUAL = queryName("notEqual"); | ||
|
||
static final BiMap<String, QName> ALIAS_TO_NAME = ImmutableBiMap.<String, QName>builder() | ||
.put("=", EQUAL) | ||
.put("<", LESS) | ||
.put(">", GREATER) | ||
.put("<=", LESS_OR_EQUAL) | ||
.put(">=", GREATER_OR_EQUAL) | ||
.put("!=", NOT_EQUAL) | ||
.build(); | ||
|
||
static final Map<QName, String> NAME_TO_ALIAS = ALIAS_TO_NAME.inverse(); | ||
|
||
private FilterNames() { | ||
throw new UnsupportedOperationException("Utility class"); | ||
} | ||
|
||
private static QName queryName(String localName) { | ||
return new QName(QUERY_NS, localName); | ||
} | ||
|
||
static Optional<QName> fromAlias(String alias) { | ||
return Optional.ofNullable(ALIAS_TO_NAME.get(alias)); | ||
} | ||
|
||
static Optional<String> aliasFor(QName name) { | ||
return Optional.ofNullable(NAME_TO_ALIAS.get(name)); | ||
} | ||
|
||
} |
21 changes: 21 additions & 0 deletions
21
...rism-impl/src/main/java/com/evolveum/midpoint/prism/impl/query/lang/FilterSerializer.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,21 @@ | ||
/* | ||
* Copyright (C) 2020-2021 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.impl.query.lang; | ||
|
||
import com.evolveum.midpoint.prism.query.PrismQuerySerialization; | ||
import com.evolveum.midpoint.prism.query.ObjectFilter; | ||
|
||
interface FilterSerializer<T extends ObjectFilter> { | ||
|
||
@SuppressWarnings("unchecked") | ||
default void castAndWrite(ObjectFilter source, QueryWriter target) throws PrismQuerySerialization.NotSupportedException { | ||
write((T) source, target); | ||
} | ||
|
||
void write(T source, QueryWriter target) throws PrismQuerySerialization.NotSupportedException; | ||
|
||
} |
Oops, something went wrong.