use of com.evolveum.midpoint.web.page.admin.configuration.dto.RepoQueryDto in project midpoint by Evolveum.
the class PageRepositoryQuery method queryPerformed.
private void queryPerformed(Action action, AjaxRequestTarget target) {
String opName = action == Action.TRANSLATE_ONLY ? OPERATION_TRANSLATE_QUERY : OPERATION_EXECUTE_QUERY;
Task task = createSimpleTask(opName);
OperationResult result = new OperationResult(opName);
RepoQueryDto dto = model.getObject();
try {
boolean queryPresent;
RepositoryQueryDiagRequest request = new RepositoryQueryDiagRequest();
switch(action) {
case EXECUTE_HIBERNATE:
String hqlText = dto.getHibernateQuery();
queryPresent = StringUtils.isNotBlank(hqlText);
request.setImplementationLevelQuery(hqlText);
break;
case TRANSLATE_ONLY:
request.setTranslateOnly(true);
case EXECUTE_MIDPOINT:
queryPresent = StringUtils.isNotBlank(dto.getMidPointQuery());
if (queryPresent) {
updateRequestWithMidpointQuery(request, dto.getObjectType(), dto.getMidPointQuery(), task, result);
}
break;
default:
throw new IllegalArgumentException("Invalid action: " + action);
}
if (!queryPresent) {
warnNoQuery(target);
return;
}
RepositoryQueryDiagResponse response;
List<?> queryResult;
if (isAdmin) {
response = getModelDiagnosticService().executeRepositoryQuery(request, task, result);
queryResult = response.getQueryResult();
} else {
request.setTranslateOnly(true);
// just to be sure
request.setImplementationLevelQuery(null);
response = getModelDiagnosticService().executeRepositoryQuery(request, task, result);
if (action != Action.TRANSLATE_ONLY) {
// not an admin, so have to fetch objects via model
queryResult = getModelService().searchObjects(request.getType(), request.getQuery(), GetOperationOptions.createRawCollection(), task, result);
} else {
queryResult = null;
}
}
if (action != Action.EXECUTE_HIBERNATE) {
dto.setHibernateQuery(String.valueOf(response.getImplementationLevelQuery()));
StringBuilder sb = new StringBuilder();
for (Map.Entry<String, RepositoryQueryDiagResponse.ParameterValue> entry : response.getImplementationLevelQueryParameters().entrySet()) {
sb.append(entry.getKey()).append(" = ").append(entry.getValue().displayValue).append("\n");
}
dto.setHibernateParameters(sb.toString());
} else {
dto.setHibernateParameters("");
}
if (action != Action.TRANSLATE_ONLY) {
dto.setQueryResultText(formatQueryResult(queryResult));
dto.setQueryResultObject(queryResult);
} else {
dto.resetQueryResultText();
dto.setQueryResultObject(null);
}
} catch (CommonException | RuntimeException e) {
result.recordFatalError("Couldn't execute query", e);
LoggingUtils.logUnexpectedException(LOGGER, "Couldn't execute query", e);
dto.setQueryResultText(e.getMessage());
dto.setQueryResultObject(e);
} finally {
result.computeStatus();
}
showResult(result);
target.add(this);
}
use of com.evolveum.midpoint.web.page.admin.configuration.dto.RepoQueryDto in project midpoint by Evolveum.
the class PageRepositoryQuery method useInObjectListPerformed.
private void useInObjectListPerformed(AjaxRequestTarget target) {
final RepoQueryDto dto = model.getObject();
String queryText = dto.getMidPointQuery();
if (StringUtils.isBlank(queryText)) {
queryText = "<query/>";
}
RepositoryQueryDiagRequest request = new RepositoryQueryDiagRequest();
Task task = createSimpleTask(OPERATION_CHECK_QUERY);
OperationResult result = task.getResult();
try {
// just to parse the query
updateRequestWithMidpointQuery(request, dto.getObjectType(), queryText, task, result);
ObjectFilter parsedFilter = request.getQuery().getFilter();
String filterAsString;
if (parsedFilter != null) {
SearchFilterType filterType = QueryConvertor.createSearchFilterType(parsedFilter, getPrismContext());
filterAsString = getPrismContext().xmlSerializer().serializeRealValue(filterType, SchemaConstantsGenerated.Q_FILTER);
// TODO remove extra xmlns from serialized value
} else {
filterAsString = "";
}
Class<? extends PageBase> listPageClass = WebComponentUtil.getObjectListPage(request.getType());
String storageKey = listPageClass != null ? WebComponentUtil.getStorageKeyForPage(listPageClass) : null;
if (storageKey == null) {
// shouldn't occur because of button visibility
error("No page to redirect for " + dto.getObjectType());
target.add(getFeedbackPanel());
return;
}
Search search = SearchFactory.createSearch(request.getType(), this);
search.setAdvancedQuery(filterAsString);
search.setShowAdvanced(true);
if (!search.isAdvancedQueryValid(getPrismContext())) {
// shouldn't occur because the query was already parsed
error("Query is not valid: " + search.getAdvancedError());
target.add(getFeedbackPanel());
return;
}
SessionStorage sessionStorage = ((MidPointAuthWebSession) getSession()).getSessionStorage();
PageStorage storage = sessionStorage.getPageStorageMap().get(storageKey);
if (storage == null) {
storage = sessionStorage.initPageStorage(storageKey);
}
storage.setSearch(search);
setResponsePage(listPageClass);
} catch (CommonException | RuntimeException e) {
result.recordFatalError("Couldn't parse query: " + e.getMessage(), e);
showResult(result);
target.add(this);
}
}
Aggregations