Skip to content

Commit

Permalink
More work on query ... but still in progress
Browse files Browse the repository at this point in the history
  • Loading branch information
semancik committed Mar 11, 2014
1 parent 8c8cc91 commit b472e20
Show file tree
Hide file tree
Showing 23 changed files with 371 additions and 221 deletions.
Expand Up @@ -92,7 +92,7 @@ public static PrismContext create(SchemaRegistry schemaRegistry) {
schemaRegistry.setPrismContext(prismContext);

prismContext.xnodeProcessor = new XNodeProcessor(prismContext);
prismContext.beanConverter = new PrismBeanConverter(schemaRegistry);
prismContext.beanConverter = new PrismBeanConverter(prismContext);

prismContext.parserMap = new HashMap<String, Parser>();
DomParser parserDom = new DomParser(schemaRegistry);
Expand Down
Expand Up @@ -47,6 +47,7 @@
import org.w3c.dom.Node;

import com.evolveum.midpoint.prism.PrismConstants;
import com.evolveum.midpoint.prism.PrismContext;
import com.evolveum.midpoint.prism.path.ItemPath;
import com.evolveum.midpoint.prism.query.ObjectQuery;
import com.evolveum.midpoint.prism.schema.SchemaRegistry;
Expand All @@ -69,14 +70,29 @@ public class PrismBeanConverter {

public static final String DEFAULT_NAMESPACE_PLACEHOLDER = "##default";

private SchemaRegistry schemaRegistry;
private PrismContext prismContext;

public PrismBeanConverter(SchemaRegistry schemaRegistry) {
this.schemaRegistry = schemaRegistry;
public PrismBeanConverter(PrismContext prismContext) {
this.prismContext = prismContext;
}

public PrismContext getPrismContext() {
return prismContext;
}

public void setPrismContext(PrismContext prismContext) {
this.prismContext = prismContext;
}

private SchemaRegistry getSchemaRegistry() {
if (prismContext == null) {
return null;
}
return prismContext.getSchemaRegistry();
}

public boolean canConvert(QName typeName) {
return schemaRegistry.determineCompileTimeClass(typeName) != null;
return getSchemaRegistry().determineCompileTimeClass(typeName) != null;
}

public boolean canConvert(Class<?> clazz) {
Expand All @@ -85,7 +101,7 @@ public boolean canConvert(Class<?> clazz) {
}

public <T> T unmarshall(MapXNode xnode, QName typeQName) throws SchemaException {
Class<T> classType = schemaRegistry.determineCompileTimeClass(typeQName);
Class<T> classType = getSchemaRegistry().determineCompileTimeClass(typeQName);
return unmarshall(xnode, classType);
}

Expand Down Expand Up @@ -254,7 +270,7 @@ public <T> T unmarshall(MapXNode xnode, Class<T> beanClass) throws SchemaExcepti

//check for subclasses???
if (xsubnode.getTypeQName()!= null){
Class explicitParamType = schemaRegistry.determineCompileTimeClass(xsubnode.getTypeQName());
Class explicitParamType = getSchemaRegistry().determineCompileTimeClass(xsubnode.getTypeQName());
if (explicitParamType != null && explicitParamType != null){
paramType = explicitParamType;
}
Expand Down Expand Up @@ -318,42 +334,15 @@ private SearchFilterType unmarshalSearchFilterType(MapXNode xmap) throws SchemaE
return null;
}
SearchFilterType filterType = new SearchFilterType();
MapXNode xfilter = xmap;
XNode xdesc = xmap.get(SearchFilterType.F_DESCRIPTION);
if (xdesc != null) {
if (xdesc instanceof PrimitiveXNode<?>) {
String desc = ((PrimitiveXNode<String>)xdesc).getParsedValue(DOMUtil.XSD_STRING);
filterType.setDescription(desc);
}
xfilter = new MapXNode();
for (Entry<QName,XNode> entry: xmap.entrySet()) {
if (!QNameUtil.match(entry.getKey(), SearchFilterType.F_DESCRIPTION)) {
xfilter.put(entry.getKey(), entry.getValue());
}
}
}
filterType.setXFilter(xfilter);
filterType.parseFromXNode(xmap, prismContext);
return filterType;
}

private XNode marshalSearchFilterType(SearchFilterType value) {
private XNode marshalSearchFilterType(SearchFilterType value) throws SchemaException {
if (value == null) {
return null;
}
MapXNode xfilter = value.getXFilter();
if (value.getDescription() == null) {
return xfilter;
}
MapXNode xmap = new MapXNode();
if (xfilter != null) {
for (Entry<QName,XNode> entry: xfilter.entrySet()) {
if (!QNameUtil.match(entry.getKey(), SearchFilterType.F_DESCRIPTION)) {
xmap.put(entry.getKey(), entry.getValue());
}
}
}
xmap.put(SearchFilterType.F_DESCRIPTION, new PrimitiveXNode<String>(value.getDescription()));
return xmap;
return value.serializeToXNode(prismContext);
}


Expand Down Expand Up @@ -595,7 +584,7 @@ private List<String> getPropOrder(Class<? extends Object> beanClass) {


public <T> T unmarshallPrimitive(PrimitiveXNode<?> xprim, QName typeQName) throws SchemaException {
Class<T> classType = schemaRegistry.determineCompileTimeClass(typeQName);
Class<T> classType = getSchemaRegistry().determineCompileTimeClass(typeQName);
return unmarshallPrimitive(xprim, classType);
}

Expand Down Expand Up @@ -697,7 +686,7 @@ private <T> T postConvertUnmarshall(Object parsedPrimValue) {
}
}

public <T> XNode marshall(T bean) {
public <T> XNode marshall(T bean) throws SchemaException {
if (bean == null) {
return null;
}
Expand Down Expand Up @@ -858,7 +847,7 @@ private String determineNamespace(Class<? extends Object> beanClass) {
return namespace;
}

private <T> XNode marshallValue(T value, QName fieldTypeName, boolean isAttribute) {
private <T> XNode marshallValue(T value, QName fieldTypeName, boolean isAttribute) throws SchemaException {
if (value == null) {
return null;
}
Expand Down
Expand Up @@ -90,8 +90,6 @@ public class QueryConvertor {
private static final QName KEY_FILTER_EQUALS_PATH = new QName(NS_QUERY, "path");
private static final QName KEY_FILTER_EQUALS_MATCHING = new QName(NS_QUERY, "matching");
private static final QName KEY_FILTER_EQUALS_VALUE = new QName(NS_QUERY, "value");
private static final QName KEY_FILTER_EQUALS_EXPRESSION = new QName(NS_QUERY, "expression");
private static final QName KEY_FILTER_EQUALS_VALUE_EXPRESSION = new QName(NS_QUERY, "valueExpression"); // deprecated

public static final QName KEY_FILTER_ORG_REF = new QName(NS_QUERY, "orgRef");
public static final QName KEY_FILTER_ORG_REF_OID = new QName(NS_QUERY, "oid");
Expand Down Expand Up @@ -279,9 +277,13 @@ private static <T,C extends Containerable> EqualsFilter<PrismPropertyDefinition<
return EqualsFilter.createEqual(itemPath, (PrismProperty) item, matchingRule);

} else {
XNode expressionXnode = xmap.get(KEY_FILTER_EQUALS_EXPRESSION);
if (expressionXnode == null) {
expressionXnode = xmap.get(KEY_FILTER_EQUALS_VALUE_EXPRESSION);
MapXNode expressionXnode = null;

Entry<QName,XNode> expressionEntry = xmap.getSingleEntryThatDoesNotMatch(
KEY_FILTER_EQUALS_VALUE, KEY_FILTER_EQUALS_MATCHING, KEY_FILTER_EQUALS_PATH);
if (expressionEntry != null) {
expressionXnode = new MapXNode();
expressionXnode.put(expressionEntry.getKey(), expressionEntry.getValue());
}

return EqualsFilter.createEqual(itemPath, (PrismPropertyDefinition) itemDefinition, matchingRule, expressionXnode);
Expand Down Expand Up @@ -326,10 +328,7 @@ private static <C extends Containerable> RefFilter parseRefFilter(XNode xnode, P
throw new IllegalStateException("No values to search specified for item " + itemName);
}

XNode expressionXnode = xmap.get(KEY_FILTER_EQUALS_EXPRESSION);
if (expressionXnode == null) {
expressionXnode = xmap.get(KEY_FILTER_EQUALS_VALUE_EXPRESSION);
}
MapXNode expressionXnode = null;

return RefFilter.createReferenceEqual(itemPath, ref, expressionXnode);
}
Expand Down Expand Up @@ -543,26 +542,34 @@ private static <T> MapXNode serializeEqualsFilter(EqualsFilter<T> filter, XNodeS
return map;
}

private static <T extends PrismValue> MapXNode serializeValueFilter(PropertyValueFilter<T> filter, XNodeSerializer xnodeSerializer) throws SchemaException{
private static <T extends PrismValue> MapXNode serializeValueFilter(PropertyValueFilter<T> filter, XNodeSerializer xnodeSerializer) throws SchemaException {
MapXNode map = new MapXNode();
serializeMatchingRule(filter, map);

serializePath(filter, map);

ListXNode valuesNode = new ListXNode();

for (T val : filter.getValues()) {
if (val.getParent() == null) {
val.setParent(filter);
List<T> values = filter.getValues();
if (values != null) {
for (T val : values) {
if (val.getParent() == null) {
val.setParent(filter);
}
XNode valNode = null;

valNode = xnodeSerializer.serializeItemValue(val, filter.getDefinition());

valuesNode.add(valNode);
}
XNode valNode = null;

valNode = xnodeSerializer.serializeItemValue(val, filter.getDefinition());

valuesNode.add(valNode);
map.put(KEY_FILTER_EQUALS_VALUE, valuesNode);
}

map.put(KEY_FILTER_EQUALS_VALUE, valuesNode);
MapXNode xexpression = filter.getExpression();
if (xexpression != null) {
map.merge(xexpression);
}

return map;
}
Expand Down
Expand Up @@ -64,6 +64,7 @@
import com.evolveum.midpoint.prism.xnode.XNode;
import com.evolveum.midpoint.util.DOMUtil;
import com.evolveum.midpoint.util.exception.SchemaException;
import com.evolveum.midpoint.util.exception.SystemException;
import com.evolveum.prism.xml.ns._public.types_2.EncryptedDataType;
import com.evolveum.prism.xml.ns._public.types_2.ItemPathType;
import com.evolveum.prism.xml.ns._public.types_2.PolyStringType;
Expand Down Expand Up @@ -201,6 +202,24 @@ public <V extends PrismValue> XNode serializeItemValue(V itemValue, ItemDefiniti
if (definition == null){
return serializePropertyRawValue((PrismPropertyValue<?>) itemValue);
}
if (beanConverter.getPrismContext() == null) {
// HACK. Ugly hack. We need to make sure that the bean converter has a prism context.
// If it does not then it cannot serialize any values and the subsequent calls may fail.
// The bean converter usually has a context. The context may be missing if it was initialized
// inside one of the JAXB getters/setters.
// We need to get rid of JAXB entirelly to get rid of hacks like this
PrismContext context = null;
if (definition != null) {
context = definition.getPrismContext();
}
if (context == null && itemValue.getParent() != null) {
context = itemValue.getParent().getPrismContext();
}
if (context == null) {
throw new SystemException("Cannot determine prism context when serializing "+itemValue);
}
beanConverter.setPrismContext(context);
}
if (itemValue instanceof PrismReferenceValue) {
xnode = serializeReferenceValue((PrismReferenceValue)itemValue, (PrismReferenceDefinition) definition);
} else if (itemValue instanceof PrismPropertyValue<?>) {
Expand Down Expand Up @@ -293,7 +312,7 @@ private XNode serializePolyString(PolyString realValue) {
return xprim;
}

private <T> MapXNode serializeProtectedDataType(ProtectedDataType<T> protectedType) {
private <T> MapXNode serializeProtectedDataType(ProtectedDataType<T> protectedType) throws SchemaException {
MapXNode xmap = new MapXNode();
if (protectedType.getEncryptedDataType() != null) {
EncryptedDataType encryptedDataType = protectedType.getEncryptedDataType();
Expand Down
Expand Up @@ -49,6 +49,7 @@
import com.evolveum.midpoint.prism.path.ItemPath;
import com.evolveum.midpoint.prism.polystring.PolyString;
import com.evolveum.midpoint.prism.util.PrismUtil;
import com.evolveum.midpoint.prism.xnode.MapXNode;
import com.evolveum.midpoint.prism.xnode.XNode;
import com.evolveum.midpoint.util.DebugUtil;
import com.evolveum.midpoint.util.exception.SchemaException;
Expand All @@ -70,11 +71,11 @@ private EqualsFilter(ItemPath parentPath, PrismPropertyDefinition definition, QN
super(parentPath, definition, matchingRule);
}

EqualsFilter(ItemPath parentPath, PrismPropertyDefinition definition, QName matchingRule, XNode expression) {
EqualsFilter(ItemPath parentPath, PrismPropertyDefinition definition, QName matchingRule, MapXNode expression) {
super(parentPath, definition, matchingRule, expression);
}

public static EqualsFilter createEqual(ItemPath path, PrismPropertyDefinition definition, QName matchingRule, XNode expression){
public static EqualsFilter createEqual(ItemPath path, PrismPropertyDefinition definition, QName matchingRule, MapXNode expression){
Validate.notNull(path, "Path must not be null");
// Do not check definition. We may want queries for which the definition is supplied later.
return new EqualsFilter(path, definition, matchingRule, expression);
Expand Down
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2010-2013 Evolveum
* Copyright (c) 2010-2014 Evolveum
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -30,48 +30,21 @@



public abstract class ObjectFilter implements DebugDumpable, Serializable{

// private ItemPath fullPath;
private XNode expression;

ObjectFilter(XNode expression) {
this.expression = expression;
}
public abstract class ObjectFilter implements DebugDumpable, Serializable {

ObjectFilter() {
// Nothing to do
}

public XNode getExpression() {
return expression;
}

public void setExpression(XNode expression) {
this.expression = expression;
}


public abstract ObjectFilter clone();

public abstract <T extends Objectable> boolean match(PrismObject<T> object, MatchingRuleRegistry matchingRuleRegistry);

protected void cloneValues(ObjectFilter clone) {
clone.expression = this.expression;
}

public void accept(Visitor visitor) {
visitor.visit(this);
}

// public ItemPath getFullPath() {
// return fullPath;
// }
//
// public ItemPath getParentPath(){
// if (fullPath == null){
// return null;
// }
//
// return fullPath.allExceptLast();
// }


}

0 comments on commit b472e20

Please sign in to comment.