Skip to content

Commit

Permalink
Cleanup of query serialization (MID-2771) - first step. Added GT/GE/L…
Browse files Browse the repository at this point in the history
…T/LE filters.
  • Loading branch information
mederly committed May 3, 2016
1 parent c07675b commit af69421
Show file tree
Hide file tree
Showing 72 changed files with 2,097 additions and 895 deletions.
11 changes: 11 additions & 0 deletions build-system/pom.xml
Expand Up @@ -67,6 +67,7 @@
<spring.security.version>4.0.4.RELEASE</spring.security.version>
<testng.version>6.8.8</testng.version>
<xml.resolver.version>1.2</xml.resolver.version>
<xmlunit.version>2.1.1</xmlunit.version>
<cron4j.version>2.2.3</cron4j.version>
<hibernate.version>4.3.8.Final</hibernate.version>
<h2.version>1.3.171</h2.version>
Expand Down Expand Up @@ -753,6 +754,16 @@
<artifactId>testng</artifactId>
<version>${testng.version}</version>
</dependency>
<dependency>
<groupId>org.xmlunit</groupId>
<artifactId>xmlunit-core</artifactId>
<version>${xmlunit.version}</version>
</dependency>
<dependency>
<groupId>org.xmlunit</groupId>
<artifactId>xmlunit-legacy</artifactId>
<version>${xmlunit.version}</version>
</dependency>
<dependency>
<groupId>xml-resolver</groupId>
<artifactId>xml-resolver</artifactId>
Expand Down
Expand Up @@ -227,8 +227,14 @@ public <ID extends ItemDefinition> ID findItemDefinition(ItemPath path, Class<ID
} else if (first instanceof IdItemPathSegment) {
path = path.rest();
} else if (first instanceof ParentPathSegment) {
ComplexTypeDefinition parent = getSchemaRegistry().determineParentDefinition(getComplexTypeDefinition(), path.rest());
return parent.findItemDefinition(path.tail(), clazz);
ItemPath rest = path.rest();
ComplexTypeDefinition parent = getSchemaRegistry().determineParentDefinition(getComplexTypeDefinition(), rest);
if (rest.isEmpty()) {
// requires that the parent is defined as an item (container, object)
return (ID) getSchemaRegistry().findItemDefinitionByType(parent.getTypeName());
} else {
return parent.findItemDefinition(rest, clazz);
}
} else if (first instanceof ObjectReferencePathSegment) {
throw new IllegalStateException("Couldn't use '@' path segment in this context. PCD=" + getTypeName() + ", path=" + path);
} else {
Expand Down

Large diffs are not rendered by default.

Expand Up @@ -29,7 +29,8 @@
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;

import com.evolveum.midpoint.prism.path.IdItemPathSegment;
import com.evolveum.midpoint.prism.PrismConstants;
import com.evolveum.midpoint.prism.path.*;

import com.evolveum.midpoint.util.QNameUtil;
import org.apache.commons.lang.StringUtils;
Expand All @@ -38,9 +39,6 @@
import org.w3c.dom.Element;
import org.w3c.dom.Node;

import com.evolveum.midpoint.prism.path.ItemPath;
import com.evolveum.midpoint.prism.path.ItemPathSegment;
import com.evolveum.midpoint.prism.path.NameItemPathSegment;
import com.evolveum.midpoint.prism.xml.GlobalDynamicNamespacePrefixMapper;
import com.evolveum.midpoint.util.DOMUtil;
import com.evolveum.midpoint.util.exception.SystemException;
Expand Down Expand Up @@ -109,7 +107,7 @@ public XPathHolder(String xpath, Node domNode) {
*/
private void parse(String xpath, Node domNode, Map<String, String> namespaceMap) {

segments = new ArrayList<XPathSegment>();
segments = new ArrayList<>();
absolute = false;

if (".".equals(xpath)) {
Expand Down Expand Up @@ -168,9 +166,17 @@ private void parse(String xpath, Node domNode, Map<String, String> namespaceMap)
}
QName qname;
if (qnameArray.length == 1 || qnameArray[1] == null || qnameArray[1].isEmpty()) {
// default namespace <= empty prefix
String namespace = findNamespace(null, domNode, namespaceMap);
qname = new QName(namespace, qnameArray[0]);
if (ParentPathSegment.SYMBOL.equals(qnameArray[0])) {
qname = ParentPathSegment.QNAME;
} else if (ObjectReferencePathSegment.SYMBOL.equals(qnameArray[0])) {
qname = ObjectReferencePathSegment.QNAME;
} else if (IdentifierPathSegment.SYMBOL.equals(qnameArray[0])) {
qname = IdentifierPathSegment.QNAME;
} else {
// default namespace <= empty prefix
String namespace = findNamespace(null, domNode, namespaceMap);
qname = new QName(namespace, qnameArray[0]);
}
} else {
String namespacePrefix = qnameArray[0];
String namespace = findNamespace(namespacePrefix, domNode, namespaceMap);
Expand Down Expand Up @@ -258,15 +264,23 @@ public XPathHolder(QName... segmentQNames) {
}

public XPathHolder(ItemPath propertyPath) {
this.segments = new ArrayList<XPathSegment>();
this.segments = new ArrayList<>();
for (ItemPathSegment segment: propertyPath.getSegments()) {
XPathSegment xsegment = null;
XPathSegment xsegment;
if (segment instanceof NameItemPathSegment) {
boolean variable = ((NameItemPathSegment) segment).isVariable();
xsegment = new XPathSegment(((NameItemPathSegment)segment).getName(), variable);
} else if (segment instanceof IdItemPathSegment) {
xsegment = new XPathSegment(idToString(((IdItemPathSegment) segment).getId()));
}
} else if (segment instanceof ObjectReferencePathSegment) {
xsegment = new XPathSegment(PrismConstants.T_OBJECT_REFERENCE, false);
} else if (segment instanceof ParentPathSegment) {
xsegment = new XPathSegment(PrismConstants.T_PARENT, false);
} else if (segment instanceof IdentifierPathSegment) {
xsegment = new XPathSegment(PrismConstants.T_ID, false);
} else {
throw new IllegalStateException("Unknown segment: " + segment);
}
this.segments.add(xsegment);
}
this.explicitNamespaceDeclarations = propertyPath.getNamespaceMap();
Expand Down Expand Up @@ -343,7 +357,14 @@ private void addPureXpath(StringBuilder sb) {
sb.append("$");
}
QName qname = seg.getQName();
if (!StringUtils.isEmpty(qname.getPrefix())) {

if (ObjectReferencePathSegment.QNAME.equals(qname)) {
sb.append(ObjectReferencePathSegment.SYMBOL);
} else if (ParentPathSegment.QNAME.equals(qname)) {
sb.append(ParentPathSegment.SYMBOL);
} else if (IdentifierPathSegment.QNAME.equals(qname)) {
sb.append(IdentifierPathSegment.SYMBOL);
} else if (!StringUtils.isEmpty(qname.getPrefix())) {
sb.append(qname.getPrefix() + ":" + qname.getLocalPart());
} else {
if (StringUtils.isNotEmpty(qname.getNamespaceURI())) {
Expand Down Expand Up @@ -435,7 +456,7 @@ public ItemPath toItemPath() {
} else {
QName qName = segment.getQName();
boolean variable = segment.isVariable();
segments.add(new NameItemPathSegment(qName, variable));
segments.add(ItemPath.createSegment(qName, variable));
}
}
ItemPath path = new ItemPath(segments);
Expand Down
Expand Up @@ -16,6 +16,10 @@

package com.evolveum.midpoint.prism.path;

import com.evolveum.midpoint.prism.PrismConstants;

import javax.xml.namespace.QName;

/**
* Denotes identifier of the object or container (i.e. OID or container ID).
* Currently supported only for sorting (not even for filtering!).
Expand All @@ -24,7 +28,10 @@
*/
public class IdentifierPathSegment extends ItemPathSegment {

@Override
public static final String SYMBOL = "#";
public static final QName QNAME = PrismConstants.T_ID;

@Override
public boolean equivalent(Object obj) {
return equals(obj);
}
Expand All @@ -36,6 +43,6 @@ public ItemPathSegment clone() {

@Override
public String toString() {
return "#";
return SYMBOL;
}
}
Expand Up @@ -87,12 +87,12 @@ public ItemPath(Object[] namesOrIds) {

private QName stringToQName(String name) {
Validate.notNull(name, "name");
if ("..".equals(name)) {
return PrismConstants.T_PARENT;
} else if ("@".equals(name)) {
return PrismConstants.T_OBJECT_REFERENCE;
} else if ("#".equals(name)) {
return PrismConstants.T_ID;
if (ParentPathSegment.SYMBOL.equals(name)) {
return ParentPathSegment.QNAME;
} else if (ObjectReferencePathSegment.SYMBOL.equals(name)) {
return ObjectReferencePathSegment.QNAME;
} else if (IdentifierPathSegment.SYMBOL.equals(name)) {
return IdentifierPathSegment.QNAME;
} else {
return new QName(name);
}
Expand Down Expand Up @@ -171,14 +171,18 @@ public static ItemPath subPath(ItemPath prefix, ItemPathSegment subSegment) {
}

private void add(QName qname) {
if (PrismConstants.T_PARENT.equals(qname)) {
this.segments.add(new ParentPathSegment());
} else if (PrismConstants.T_OBJECT_REFERENCE.equals(qname)) {
this.segments.add(new ObjectReferencePathSegment());
} else if (PrismConstants.T_ID.equals(qname)) {
this.segments.add(new IdentifierPathSegment());
this.segments.add(createSegment(qname, false));
}

public static ItemPathSegment createSegment(QName qname, boolean variable) {
if (ParentPathSegment.QNAME.equals(qname)) {
return new ParentPathSegment();
} else if (ObjectReferencePathSegment.QNAME.equals(qname)) {
return new ObjectReferencePathSegment();
} else if (IdentifierPathSegment.QNAME.equals(qname)) {
return new IdentifierPathSegment();
} else {
this.segments.add(new NameItemPathSegment(qname));
return new NameItemPathSegment(qname, variable);
}
}

Expand Down Expand Up @@ -586,6 +590,14 @@ public int hashCode() {
return result;
}

public boolean equals(Object obj, boolean exact) {
if (exact) {
return equals(obj);
} else {
return obj instanceof ItemPath && equivalent((ItemPath) obj);
}
}

/**
* More strict version of ItemPath comparison. Does not use any normalization
* nor approximate matching QNames via QNameUtil.match.
Expand Down
Expand Up @@ -16,14 +16,21 @@

package com.evolveum.midpoint.prism.path;

import com.evolveum.midpoint.prism.PrismConstants;

import javax.xml.namespace.QName;

/**
* Denotes referenced object, like "assignment/targetRef/@/name" (name of assignment's target object)
*
* @author mederly
*/
public class ObjectReferencePathSegment extends ReferencePathSegment {

@Override
public static final String SYMBOL = "@";
public static final QName QNAME = PrismConstants.T_OBJECT_REFERENCE;

@Override
public boolean equivalent(Object obj) {
return equals(obj);
}
Expand All @@ -35,6 +42,6 @@ public ItemPathSegment clone() {

@Override
public String toString() {
return "@";
return SYMBOL;
}
}
Expand Up @@ -16,14 +16,21 @@

package com.evolveum.midpoint.prism.path;

import com.evolveum.midpoint.prism.PrismConstants;

import javax.xml.namespace.QName;

/**
* Denotes parent object or container.
*
* @author mederly
*/
public class ParentPathSegment extends ReferencePathSegment {

@Override
public static final String SYMBOL = "..";
public static final QName QNAME = PrismConstants.T_PARENT;

@Override
public boolean equivalent(Object obj) {
return equals(obj);
}
Expand All @@ -35,6 +42,6 @@ public ItemPathSegment clone() {

@Override
public String toString() {
return "..";
return SYMBOL;
}
}
Expand Up @@ -74,4 +74,13 @@ public boolean match(PrismContainerValue value, MatchingRuleRegistry matchingRul
return true;
}

@Override
public boolean equals(Object obj, boolean exact) {
return obj instanceof AllFilter;
}

@Override
public int hashCode() {
return 0;
}
}
Expand Up @@ -106,4 +106,8 @@ public boolean match(PrismContainerValue value, MatchingRuleRegistry matchingRul
return true;
}

@Override
public boolean equals(Object obj, boolean exact) {
return super.equals(obj, exact) && obj instanceof AndFilter;
}
}
Expand Up @@ -74,24 +74,24 @@ static <T> PrismPropertyValue<T> createPropertyValue(PrismPropertyDefinition ite
}

@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + (equals ? 1231 : 1237);
return result;
}

@Override
public boolean equals(Object obj) {
if (this == obj)
public boolean equals(Object o, boolean exact) {
if (this == o)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
if (o == null || getClass() != o.getClass())
return false;
ComparativeFilter other = (ComparativeFilter) obj;
if (equals != other.equals)
if (!super.equals(o, exact))
return false;
return true;

ComparativeFilter<?> that = (ComparativeFilter<?>) o;

return equals == that.equals;

}

@Override
public int hashCode() {
int result = super.hashCode();
result = 31 * result + (equals ? 1 : 0);
return result;
}
}
Expand Up @@ -96,6 +96,16 @@ public static <T> EqualFilter<T> createEqual(ItemPath path, PrismPropertyDefinit
List<PrismPropertyValue<T>> pVals = createPropertyList(itemDefinition, realValue);
return new EqualFilter(path, itemDefinition, matchingRule, pVals);
}

public static <T> EqualFilter<T> createEqualMultiple(ItemPath path, PrismPropertyDefinition<T> itemDefinition, QName matchingRule, T... realValues) {
Validate.notNull(itemDefinition, "Item definition in the filter must not be null");
Validate.notNull(path, "Path in the filter must not be null");
if (realValues.length == 0 || (realValues.length == 1 && realValues[0] == null)) {
return createNullEqual(path, itemDefinition, matchingRule);
}
List<PrismPropertyValue<T>> pVals = createPropertyListFromArray(itemDefinition, realValues);
return new EqualFilter(path, itemDefinition, matchingRule, pVals);
}

public static <T> EqualFilter<T> createEqual(QName propertyName, PrismPropertyDefinition<T> propertyDefinition, QName matchingRule, T realValue){
return createEqual(new ItemPath(propertyName), propertyDefinition, matchingRule, realValue);
Expand Down Expand Up @@ -280,6 +290,11 @@ public List<PrismPropertyValue<T>> getValues() {
// TODO Auto-generated method stub
return super.getValues();
}


@Override
public boolean equals(Object obj, boolean exact) {
return super.equals(obj, exact) && obj instanceof EqualFilter;
}

}

0 comments on commit af69421

Please sign in to comment.