use of com.evolveum.midpoint.repo.sqlbase.QueryException in project midpoint by Evolveum.
the class PropertyRestriction method adaptValueType.
private Object adaptValueType(Object value, ValueFilter filter) throws QueryException {
Class<?> expectedType = linkDefinition.getTargetDefinition().getJaxbClass();
if (expectedType == null || value == null) {
// nothing to check here
return value;
}
Class<?> expectedWrappedType;
if (expectedType.isPrimitive()) {
expectedWrappedType = ClassUtils.primitiveToWrapper(expectedType);
} else {
expectedWrappedType = expectedType;
}
Object adaptedValue;
// attempt to fix value type for polystring (if it was string in filter we create polystring from it)
if (PolyString.class.equals(expectedWrappedType) && value instanceof String) {
LOGGER.debug("Trying to query PolyString value but filter contains String '{}'.", filter);
String orig = (String) value;
adaptedValue = new PolyString(orig, context.getPrismContext().getDefaultPolyStringNormalizer().normalize(orig));
} else if (PolyString.class.equals(expectedWrappedType) && value instanceof PolyStringType) {
// attempt to fix value type for polystring (if it was polystring type in filter we create polystring from it)
LOGGER.debug("Trying to query PolyString value but filter contains PolyStringType '{}'.", filter);
PolyStringType type = (PolyStringType) value;
adaptedValue = new PolyString(type.getOrig(), type.getNorm());
} else if (String.class.equals(expectedWrappedType) && value instanceof QName) {
// eg. shadow/objectClass
adaptedValue = RUtil.qnameToString((QName) value);
} else if (value instanceof RawType) {
// MID-3850: but it's quite a workaround. Maybe we should treat RawType's earlier than this.
try {
adaptedValue = ((RawType) value).getParsedRealValue(expectedWrappedType);
} catch (SchemaException e) {
throw new QueryException("Couldn't parse value " + value + " as " + expectedWrappedType + ": " + e.getMessage(), e);
}
} else {
adaptedValue = value;
}
if (expectedWrappedType.isAssignableFrom(adaptedValue.getClass())) {
return adaptedValue;
} else {
throw new QueryException("Value should be type of '" + expectedWrappedType + "' but it's '" + value.getClass() + "', filter '" + filter + "'.");
}
}
use of com.evolveum.midpoint.repo.sqlbase.QueryException in project midpoint by Evolveum.
the class PropertyRestriction method getValueFromFilter.
private Object getValueFromFilter(ValueFilter filter) throws QueryException {
JpaPropertyDefinition def = linkDefinition.getTargetDefinition();
Object value;
if (filter instanceof PropertyValueFilter) {
value = getValue((PropertyValueFilter) filter);
} else {
throw new QueryException("Unknown filter '" + filter + "', can't get value from it.");
}
Object adaptedValue = adaptValueType(value, filter);
if (def.isEnumerated()) {
return getRepoEnumValue((Enum) adaptedValue, def.getJpaClass());
} else {
return adaptedValue;
}
}
use of com.evolveum.midpoint.repo.sqlbase.QueryException in project midpoint by Evolveum.
the class OrgRestriction method interpret.
@Override
public Condition interpret() throws QueryException {
RootHibernateQuery hibernateQuery = getContext().getHibernateQuery();
if (filter.isRoot()) {
// oid in (select descendantOid from ROrgClosure group by descendantOid having count(descendantOid) = 1)
return hibernateQuery.createIn(getBaseHqlEntity().getHqlPath() + ".oid", "select descendantOid from ROrgClosure group by descendantOid having count(descendantOid) = 1");
}
if (filter.getOrgRef() == null) {
throw new QueryException("No organization reference defined in the search query.");
}
if (filter.getOrgRef().getOid() == null) {
throw new QueryException("No oid specified in organization reference " + filter.getOrgRef().debugDump());
}
String orgOidParamName = hibernateQuery.addParameter("orgOid", filter.getOrgRef().getOid());
String relationParamName = "";
QName relation = filter.getOrgRef().getRelation();
if (doesRelationRestrictionExist(relation)) {
relationParamName = hibernateQuery.addParameter("relation", ReferenceRestriction.getRelationsToTest(relation, context));
}
// oid in ...
String oidQueryText;
switch(filter.getScope()) {
case ONE_LEVEL:
oidQueryText = // TODO distinct(ref.ownerOid) ? (was in original QueryInterpreter)
"select ref.ownerOid " + "from RObjectReference ref " + "where " + "ref.referenceType = " + RReferenceType.OBJECT_PARENT_ORG.ordinal() + (doesRelationRestrictionExist(relation) ? " and ref.relation in (:" + relationParamName + ")" : "") + " and ref.targetOid = :" + orgOidParamName;
break;
case ANCESTORS:
oidQueryText = "select c.ancestorOid " + "from ROrgClosure c " + "where " + "c.ancestorOid != :" + orgOidParamName + " and " + "c.descendantOid = :" + orgOidParamName;
break;
case SUBTREE:
default:
oidQueryText = "select ref.ownerOid " + "from RObjectReference ref " + "where " + "ref.referenceType = " + RReferenceType.OBJECT_PARENT_ORG.ordinal() + (doesRelationRestrictionExist(relation) ? " and ref.relation in (:" + relationParamName + ")" : "") + " and ref.targetOid in (" + "select descendantOid from ROrgClosure where ancestorOid = :" + orgOidParamName + ")";
}
return hibernateQuery.createIn(getBaseHqlEntity().getHqlPath() + ".oid", oidQueryText);
}
use of com.evolveum.midpoint.repo.sqlbase.QueryException in project midpoint by Evolveum.
the class Matcher method basicMatch.
protected Condition basicMatch(RootHibernateQuery hibernateQuery, ItemRestrictionOperation operation, String propertyPath, Object value, boolean ignoreCase) throws QueryException {
Objects.requireNonNull(hibernateQuery, "hibernateQuery");
if (ignoreCase && !(value instanceof String)) {
LOGGER.warn("Ignoring ignoreCase setting for non-string value of {}", value);
ignoreCase = false;
}
Condition condition;
switch(operation) {
case EQ:
if (value == null) {
condition = hibernateQuery.createIsNull(propertyPath);
} else {
condition = hibernateQuery.createEq(propertyPath, value, ignoreCase);
}
break;
case GT:
case GE:
case LT:
case LE:
condition = hibernateQuery.createSimpleComparisonCondition(propertyPath, value, operation.symbol(), ignoreCase);
break;
case NOT_NULL:
// TODO never used so it seems (never assigned to operation)
condition = hibernateQuery.createIsNotNull(propertyPath);
break;
case NULL:
// TODO never used so it seems (never assigned to operation)
condition = hibernateQuery.createIsNull(propertyPath);
break;
case STARTS_WITH:
condition = hibernateQuery.createLike(propertyPath, (String) value, MatchMode.START, ignoreCase);
break;
case ENDS_WITH:
condition = hibernateQuery.createLike(propertyPath, (String) value, MatchMode.END, ignoreCase);
break;
case SUBSTRING:
condition = hibernateQuery.createLike(propertyPath, (String) value, MatchMode.ANYWHERE, ignoreCase);
break;
default:
throw new QueryException("Unknown operation '" + operation + "'.");
}
return condition;
}
use of com.evolveum.midpoint.repo.sqlbase.QueryException in project midpoint by Evolveum.
the class AuditCustomColumnItemFilterProcessor method process.
@Override
public Predicate process(PropertyValueFilter<AuditEventRecordCustomColumnPropertyType> filter) throws QueryException {
// This is a tricky situation, if multi-value, each value can have different path (derived
// from AuditEventRecordCustomColumnPropertyType.getName()), so we can't use this directly.
ValueFilterValues<AuditEventRecordCustomColumnPropertyType, ?> values = ValueFilterValues.from(filter);
if (values.isEmpty()) {
throw new QueryException("Custom column null value is not supported," + " column can't be determined from filter: " + filter);
}
if (values.isMultiValue()) {
Predicate predicate = null;
for (AuditEventRecordCustomColumnPropertyType propertyType : values.allValuesRaw()) {
Predicate right = createPredicate(filter, propertyType);
predicate = predicate != null ? ExpressionUtils.or(predicate, right) : right;
}
return predicate;
}
AuditEventRecordCustomColumnPropertyType value = values.singleValueRaw();
assert value != null;
return createPredicate(filter, value);
}
Aggregations