use of com.evolveum.midpoint.repo.sqlbase.QueryException in project midpoint by Evolveum.
the class JsonbPolysPathItemFilterProcessor method processPolyStringBoth.
private Predicate processPolyStringBoth(ValueFilterValues<?, ?> values) throws QueryException {
Object value = values.singleValueRaw();
// empty values treated in main process()
assert value != null;
if (!(value instanceof PolyString)) {
throw new QueryException("PolyString value must be provided to match both orig and norm values, was: " + value + " (type " + value.getClass() + ")");
}
// must be Poly here
PolyString poly = (PolyString) value;
return predicateWithNotTreated(path, booleanTemplate("{0} @> {1}::jsonb", path, String.format("[{\"" + JSONB_POLY_ORIG_KEY + "\":\"%s\",\"" + JSONB_POLY_NORM_KEY + "\":\"%s\"}]", poly.getOrig(), poly.getNorm())));
}
use of com.evolveum.midpoint.repo.sqlbase.QueryException in project midpoint by Evolveum.
the class AuditCustomColumnItemFilterProcessor method createPredicate.
private Predicate createPredicate(PropertyValueFilter<AuditEventRecordCustomColumnPropertyType> filter, AuditEventRecordCustomColumnPropertyType customColumnPropertyType) throws QueryException {
FilterOperation operation = operation(filter);
Path<?> path = context.path().getPath(customColumnPropertyType.getName());
if (customColumnPropertyType.getValue() == null) {
if (operation.isAnyEqualOperation()) {
return ExpressionUtils.predicate(Ops.IS_NULL, path);
} else {
throw new QueryException("Null value for other than EQUAL filter: " + filter);
}
}
return singleValuePredicate(path, operation, customColumnPropertyType.getValue());
}
use of com.evolveum.midpoint.repo.sqlbase.QueryException in project midpoint by Evolveum.
the class OrgFilterProcessor method process.
@Override
public Predicate process(OrgFilter filter) throws QueryException {
// necessary for lazy refresh of org closure
context.markContainsOrgFilter();
FlexibleRelationalPathBase<?> path = context.root();
if (!(path instanceof QObject)) {
throw new QueryException("Org filter can only be used for objects," + " not for path " + path + " of type " + path.getClass());
}
QObject<?> objectPath = (QObject<?>) path;
if (filter.isRoot()) {
QObjectReference<MObject> ref = getNewRefAlias();
return subQuery(ref).where(ref.ownerOid.eq(objectPath.oid)).notExists();
}
if (filter.getOrgRef() == null) {
throw new QueryException("No organization reference defined in the search query.");
}
String oidParam = filter.getOrgRef().getOid();
if (oidParam == null) {
throw new QueryException("No oid specified in organization reference " + filter.getOrgRef().debugDump());
}
QName relation = filter.getOrgRef().getRelation();
// null means ANY (not "default") here, so we only search/normalize non-nulls
Integer relationId = relation != null ? context.repositoryContext().searchCachedRelationId(relation) : null;
if (filter.getScope() == OrgFilter.Scope.ONE_LEVEL) {
QObjectReference<MObject> ref = getNewRefAlias();
SQLQuery<?> subQuery = subQuery(ref).where(ref.ownerOid.eq(objectPath.oid).and(ref.targetOid.eq(UUID.fromString(oidParam))));
if (relationId != null) {
subQuery.where(ref.relationId.eq(relationId));
}
return subQuery.exists();
} else if (filter.getScope() == OrgFilter.Scope.SUBTREE) {
QObjectReference<MObject> ref = getNewRefAlias();
QOrgClosure oc = getNewClosureAlias();
SQLQuery<?> subQuery = subQuery(ref).join(oc).on(oc.descendantOid.eq(ref.targetOid)).where(ref.ownerOid.eq(objectPath.oid).and(oc.ancestorOid.eq(UUID.fromString(oidParam))));
if (relationId != null) {
subQuery.where(ref.relationId.eq(relationId));
}
return subQuery.exists();
} else if (filter.getScope() == OrgFilter.Scope.ANCESTORS) {
QOrgClosure oc = getNewClosureAlias();
return subQuery(oc).where(oc.ancestorOid.eq(objectPath.oid).and(oc.descendantOid.eq(UUID.fromString(oidParam))).and(oc.ancestorOid.ne(oc.descendantOid))).exists();
} else {
throw new QueryException("Unknown scope if org filter: " + filter);
}
}
use of com.evolveum.midpoint.repo.sqlbase.QueryException in project midpoint by Evolveum.
the class UuidItemFilterProcessor method process.
@Override
public Predicate process(PropertyValueFilter<Object> filter) throws RepositoryException {
// This is adapted version of ItemValueFilterProcessor#createBinaryCondition.
// Because conversion is different for various operations, we don't use ValueFilterValues.
FilterOperation operation = operation(filter);
if (filter.getValues() == null || filter.getValues().isEmpty()) {
if (operation.isAnyEqualOperation()) {
return ExpressionUtils.predicate(Ops.IS_NULL, path);
} else {
throw new QueryException("Null value for other than EQUAL filter: " + filter);
}
}
if (filter.getValues().size() > 1) {
if (operation.isAnyEqualOperation()) {
List<UUID> oids = filter.getValues().stream().map(s -> UUID.fromString(uuidString(s.getValue()))).collect(Collectors.toList());
return ExpressionUtils.predicate(Ops.IN, operation.treatPathForIn(path), ConstantImpl.create(oids));
} else {
throw new QueryException("Multi-value for other than EQUAL filter: " + filter);
}
}
// noinspection ConstantConditions
String oid = uuidString(filter.getSingleValue().getValue());
if (oid.length() < OID_MIN.length()) {
// operator is enough, ignore case doesn't play any role for UUID type
return processIncompleteOid(oid, operation.operator, filter);
} else {
// singleValuePredicate() treatment is not necessary, let's just create the predicate
return ExpressionUtils.predicate(operation.operator, path, ConstantImpl.create(UUID.fromString(oid)));
}
}
use of com.evolveum.midpoint.repo.sqlbase.QueryException in project midpoint by Evolveum.
the class ObjectRetriever method executeQueryDiagnosticsRequest.
public RepositoryQueryDiagResponse executeQueryDiagnosticsRequest(RepositoryQueryDiagRequest request, OperationResult result) {
LOGGER_PERFORMANCE.debug("> execute query diagnostics {}", request);
Session session = null;
try {
// beware, not all databases support read-only transactions!
session = baseHelper.beginReadOnlyTransaction();
final String implementationLevelQuery;
final Map<String, RepositoryQueryDiagResponse.ParameterValue> implementationLevelQueryParameters;
final Query<?> query;
final boolean isMidpointQuery = request.getImplementationLevelQuery() == null;
if (isMidpointQuery) {
QueryEngine engine = new QueryEngine(getConfiguration(), extItemDictionary, prismContext, relationRegistry);
RQueryImpl rQuery = (RQueryImpl) engine.interpret(request.getQuery(), request.getType(), request.getOptions(), false, session);
query = rQuery.getQuery();
implementationLevelQuery = query.getQueryString();
implementationLevelQueryParameters = new HashMap<>();
for (Map.Entry<String, QueryParameterValue> entry : rQuery.getQuerySource().getParameters().entrySet()) {
implementationLevelQueryParameters.put(entry.getKey(), new RepositoryQueryDiagResponse.ParameterValue(entry.getValue().getValue(), entry.getValue().toString()));
}
} else {
implementationLevelQuery = (String) request.getImplementationLevelQuery();
implementationLevelQueryParameters = new HashMap<>();
query = session.createQuery(implementationLevelQuery);
}
List<?> objects = request.isTranslateOnly() ? null : query.list();
if (isMidpointQuery && objects != null) {
// raw GetObjectResult instances are useless outside repo-sql-impl module, so we'll convert them to objects
@SuppressWarnings("unchecked") List<GetObjectResult> listOfGetObjectResults = (List<GetObjectResult>) objects;
objects = queryResultToPrismObjects(listOfGetObjectResults, request.getType(), null, session, result);
}
RepositoryQueryDiagResponse response = new RepositoryQueryDiagResponse(objects, implementationLevelQuery, implementationLevelQueryParameters);
session.getTransaction().rollback();
return response;
} catch (SchemaException | QueryException | RuntimeException ex) {
baseHelper.handleGeneralException(ex, session, result);
throw new IllegalStateException("shouldn't get here");
} finally {
baseHelper.cleanupSessionAndResult(session, result);
}
}
Aggregations