Skip to content

Commit

Permalink
QueryPlayground: Fixed support for containers and object references
Browse files Browse the repository at this point in the history
 - Fixed example for costCenter (invalid use of <> in XML)
 - Added example for objectReferenceSearch
  • Loading branch information
tonydamage committed Oct 12, 2023
1 parent f32be78 commit 8d60d30
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public static List<QName> createSearchableTypeList() {
supportedObjectTypeList.add(AccessCertificationWorkItemType.COMPLEX_TYPE);
supportedObjectTypeList.add(OperationExecutionType.COMPLEX_TYPE);
supportedObjectTypeList.add(SimulationResultProcessedObjectType.COMPLEX_TYPE);
supportedObjectTypeList.add(ObjectReferenceType.COMPLEX_TYPE);
return supportedObjectTypeList;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import javax.xml.namespace.QName;

import com.evolveum.midpoint.gui.impl.util.DetailsPageUtil;
import com.evolveum.midpoint.prism.Containerable;
import com.evolveum.midpoint.schema.query.TypedQuery;

import org.apache.commons.io.IOUtils;
Expand Down Expand Up @@ -122,7 +123,8 @@ public class QueryPlaygroundPanel extends BasePanel<RepoQueryDto> {
"ObjectType_AllObjectsInASubtree",
"ObjectType_AllObjectsInAnOrg",
"ShadowType_ShadowsOnGivenResource",
"UserType_UsersWithShadowOnGivenResource"
"UserType_UsersWithShadowOnGivenResource",
"ObjectReferenceType_RoleMembershipRefsTargetingSuperuser"
);
private static final Set<QName> USE_IN_OBJECT_LIST_AVAILABLE_FOR = new HashSet<>(Arrays.asList(
UserType.COMPLEX_TYPE,
Expand Down Expand Up @@ -404,7 +406,6 @@ private void useInObjectListPerformed(AjaxRequestTarget target) {
if (storage == null) {
storage = sessionStorage.initPageStorage(storageKey);
}
// TODO add containerable option too
Search search = storage.getSearch() != null ? storage.getSearch() : new SearchBuilder(request.getType()).modelServiceLocator(getPageBase()).build();
search.addAllowedModelType(SearchBoxModeType.AXIOM_QUERY);
search.setSearchMode(SearchBoxModeType.AXIOM_QUERY);
Expand Down Expand Up @@ -472,10 +473,9 @@ private void queryPerformed(QueryPlaygroundPanel.Action action, AjaxRequestTarge

if (action != Action.TRANSLATE_ONLY) {
// not an admin, so have to fetch objects via model
// TODO add containerable option too
queryResult = performModelSearch(request, task, result);
//noinspection unchecked
queryResult = getPageBase().getModelService().searchObjects((Class<? extends ObjectType>) request.getType(), request.getQuery(),
createRawCollection(), task, result);

} else {
queryResult = null;
}
Expand Down Expand Up @@ -509,6 +509,21 @@ private void queryPerformed(QueryPlaygroundPanel.Action action, AjaxRequestTarge
target.add(this);
}

private List<?> performModelSearch(RepositoryQueryDiagRequest request, Task task, OperationResult result) throws SchemaException, ExpressionEvaluationException, SecurityViolationException, CommunicationException, ConfigurationException, ObjectNotFoundException {
if (ObjectType.class.isAssignableFrom(request.getType())) {
return getPageBase().getModelService().searchObjects((Class<? extends ObjectType>) request.getType(), request.getQuery(),
createRawCollection(), task, result);
}
if (Containerable.class.isAssignableFrom(request.getType())) {
return getPageBase().getModelService().searchContainers((Class<? extends Containerable>) request.getType(), request.getQuery(),
createRawCollection(), task, result);
}
if (ObjectReferenceType.class.isAssignableFrom(request.getType())) {
return getPageBase().getModelService().searchReferences(request.getQuery(), createRawCollection(), task, result);
}
throw new SchemaException("Unknown type " + request.getType() + "for search.");
}

private void warnNoQuery(AjaxRequestTarget target) {
warn(getString("PageRepositoryQuery.message.emptyString"));
target.add(getFeedbackPanel());
Expand All @@ -526,9 +541,8 @@ private void updateRequestWithMidpointQuery(
objectType = ObjectType.COMPLEX_TYPE;
}
@SuppressWarnings("unchecked")
Class<? extends ObjectType> clazz = (Class<? extends ObjectType>)
prismContext.getSchemaRegistry().getCompileTimeClassForObjectTypeRequired(objectType);

Class<? extends Containerable> clazz =
prismContext.getSchemaRegistry().determineClassForTypeRequired(objectType);
ObjectQuery queryWithExprEvaluated = null;
if (midPointQueryScript != null) {
PrismPropertyValue<?> filterValue = ExpressionUtil.evaluateExpression(new VariablesMap(), null, midPointQueryScript,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<query>
<filter>
<text>. ownedBy (@type = UserType and @path = roleMembershipRef ) and @/name = "Superuser"</text>
</filter>
</query>
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<query>
<filter>
<text>(costCenter > '100000' and costCenter < '999999') or (costCenter >= 'X100' and costCenter <= 'X999')</text>
<text>(costCenter &gt; '100000' and costCenter &lt; '999999') or (costCenter &gt;= 'X100' and costCenter &lt;= 'X999')</text>
</filter>
</query>
Original file line number Diff line number Diff line change
Expand Up @@ -2122,9 +2122,15 @@ public RepositoryQueryDiagResponse executeQueryDiagnostics(
// Modified code from SqlQueryExecutor.list()
SimulatedSqlQuery<Object> simulatedQuery = new SimulatedSqlQuery<>(
sqlRepoContext.getQuerydslConfiguration(), jdbcSession.connection(), request.isTranslateOnly());
SqaleQueryContext<S, Q, R> context =
SqaleQueryContext.from(type, sqlRepoContext, simulatedQuery, null);

// Special handling for references?
SqaleQueryContext<S, Q, R> context;
if (ObjectReferenceType.class.isAssignableFrom(type)) {
SqaleTableMapping mapping = determineMapping(request.getQuery().getFilter());
context = SqaleQueryContext.from(mapping, sqlRepoContext, simulatedQuery, null);
} else {
context = SqaleQueryContext.from(type, sqlRepoContext, simulatedQuery, null);
}
ObjectQuery query = request.getQuery();
if (query != null) {
context.processFilter(query.getFilter());
Expand All @@ -2139,7 +2145,11 @@ public RepositoryQueryDiagResponse executeQueryDiagnostics(
result = context.executeQuery(jdbcSession);
PageOf<S> transformedResult = context.transformToSchemaType(result, jdbcSession);
//noinspection unchecked
resultList = transformedResult.map(o -> (PrismContainerValue<S>) o.asPrismContainerValue()).content();
if (ObjectReferenceType.class.isAssignableFrom(type)) {
resultList = transformedResult.content();
} else {
resultList = transformedResult.map(o -> (PrismContainerValue<S>) o.asPrismContainerValue()).content();
}
} catch (RuntimeException e) {
if (e != SimulatedSqlQuery.SIMULATION_EXCEPTION) {
throw e; // OK, this was unexpected, so rethrow it
Expand Down

0 comments on commit 8d60d30

Please sign in to comment.