use of com.evolveum.midpoint.schema.expression.VariablesMap in project midpoint by Evolveum.
the class ReportObjectsListPanel method customProcessNewRowItem.
@Override
protected void customProcessNewRowItem(org.apache.wicket.markup.repeater.Item<SelectableBean<C>> item, IModel<SelectableBean<C>> model) {
if (model == null || model.getObject() == null || model.getObject().getValue() == null) {
return;
}
VariablesMap variables = getSearchModel().getObject().getFilterVariables(null, getPageBase());
variables.put(ExpressionConstants.VAR_OBJECT, model.getObject().getValue(), model.getObject().getValue().getClass());
if (getReport().getObjectCollection() != null && getReport().getObjectCollection().getSubreport() != null && !getReport().getObjectCollection().getSubreport().isEmpty()) {
Task task = getPageBase().createSimpleTask("evaluate subreports");
processReferenceVariables(variables);
VariablesMap subreportsVariables = getPageBase().getReportManager().evaluateSubreportParameters(getReport().asPrismObject(), variables, task, task.getResult());
variables.putAll(subreportsVariables);
}
this.variables.clear();
for (String key : variables.keySet()) {
this.variables.put(key, variables.get(key).getValue());
}
}
use of com.evolveum.midpoint.schema.expression.VariablesMap in project midpoint by Evolveum.
the class FlexibleLabelModel method getExpressionValue.
private String getExpressionValue(ExpressionType expressionType, String contextDesc, Task task, OperationResult result) throws SchemaException, ExpressionEvaluationException, ObjectNotFoundException, CommunicationException, ConfigurationException, SecurityViolationException {
C object = model.getObject();
ExpressionFactory expressionFactory = serviceLocator.getExpressionFactory();
PrismContext prismContext = object.asPrismContainerValue().getPrismContext();
PrismPropertyDefinition<String> outputDefinition = prismContext.definitionFactory().createPropertyDefinition(ExpressionConstants.OUTPUT_ELEMENT_NAME, DOMUtil.XSD_STRING);
Expression<PrismPropertyValue<String>, PrismPropertyDefinition<String>> expression = expressionFactory.makeExpression(expressionType, outputDefinition, MiscSchemaUtil.getExpressionProfile(), contextDesc, task, result);
VariablesMap variables = new VariablesMap();
variables.put(ExpressionConstants.VAR_OBJECT, object, object.asPrismContainerValue().getDefinition());
addAdditionalVariablesMap(variables);
ExpressionEvaluationContext context = new ExpressionEvaluationContext(null, variables, contextDesc, task);
PrismValueDeltaSetTriple<PrismPropertyValue<String>> outputTriple = expression.evaluate(context, result);
if (outputTriple == null) {
return "";
}
Collection<PrismPropertyValue<String>> outputValues = outputTriple.getNonNegativeValues();
if (outputValues.isEmpty()) {
return "";
}
if (outputValues.size() > 1) {
throw new SchemaException("Expression " + contextDesc + " produced more than one value");
}
return outputValues.iterator().next().getRealValue();
}
use of com.evolveum.midpoint.schema.expression.VariablesMap in project midpoint by Evolveum.
the class PageRepositoryQuery method updateRequestWithMidpointQuery.
private void updateRequestWithMidpointQuery(RepositoryQueryDiagRequest request, QName objectType, String queryText, boolean distinct, Task task, OperationResult result) throws SchemaException, ObjectNotFoundException, ExpressionEvaluationException, CommunicationException, ConfigurationException, SecurityViolationException {
PrismContext prismContext = getPrismContext();
if (objectType == null) {
objectType = ObjectType.COMPLEX_TYPE;
}
@SuppressWarnings("unchecked") Class<? extends ObjectType> clazz = (Class<? extends ObjectType>) prismContext.getSchemaRegistry().getCompileTimeClassForObjectType(objectType);
if (clazz == null) {
throw new SchemaException("Couldn't find compile-time class for object type of " + objectType);
}
QueryType queryType = prismContext.parserFor(queryText).language(dataLanguage).parseRealValue(QueryType.class);
request.setType(clazz);
ObjectQuery objectQuery = prismContext.getQueryConverter().createObjectQuery(clazz, queryType);
ObjectQuery queryWithExprEvaluated = ExpressionUtil.evaluateQueryExpressions(objectQuery, new VariablesMap(), MiscSchemaUtil.getExpressionProfile(), getExpressionFactory(), getPrismContext(), "evaluate query expressions", task, result);
request.setQuery(queryWithExprEvaluated);
Collection<SelectorOptions<GetOperationOptions>> options = distinct ? createCollection(createDistinct()) : null;
request.setOptions(options);
}
use of com.evolveum.midpoint.schema.expression.VariablesMap in project midpoint by Evolveum.
the class PageBase method executeResultScriptHook.
private OperationResult executeResultScriptHook(OperationResult result) {
CompiledGuiProfile adminGuiConfiguration = getCompiledGuiProfile();
if (adminGuiConfiguration.getFeedbackMessagesHook() == null) {
return result;
}
FeedbackMessagesHookType hook = adminGuiConfiguration.getFeedbackMessagesHook();
ExpressionType expressionType = hook.getOperationResultHook();
if (expressionType == null) {
return result;
}
String contextDesc = "operation result (" + result.getOperation() + ") script hook";
Task task = getPageTask();
OperationResult topResult = task.getResult();
try {
ExpressionFactory factory = getExpressionFactory();
PrismPropertyDefinition<OperationResultType> outputDefinition = getPrismContext().definitionFactory().createPropertyDefinition(ExpressionConstants.OUTPUT_ELEMENT_NAME, OperationResultType.COMPLEX_TYPE);
Expression<PrismPropertyValue<OperationResultType>, PrismPropertyDefinition<OperationResultType>> expression = factory.makeExpression(expressionType, outputDefinition, MiscSchemaUtil.getExpressionProfile(), contextDesc, task, topResult);
VariablesMap variables = new VariablesMap();
OperationResultType resultType = result.createOperationResultType();
variables.put(ExpressionConstants.VAR_INPUT, resultType, OperationResultType.class);
ExpressionEvaluationContext context = new ExpressionEvaluationContext(null, variables, contextDesc, task);
PrismValueDeltaSetTriple<PrismPropertyValue<OperationResultType>> outputTriple = expression.evaluate(context, topResult);
if (outputTriple == null) {
return null;
}
Collection<PrismPropertyValue<OperationResultType>> values = outputTriple.getNonNegativeValues();
if (values == null || values.isEmpty()) {
return null;
}
if (values.size() > 1) {
throw new SchemaException("Expression " + contextDesc + " produced more than one value");
}
OperationResultType newResultType = values.iterator().next().getRealValue();
if (newResultType == null) {
return null;
}
return OperationResult.createOperationResult(newResultType);
} catch (SchemaException | ExpressionEvaluationException | ObjectNotFoundException | CommunicationException | ConfigurationException | SecurityViolationException e) {
topResult.recordFatalError(e);
if (StringUtils.isEmpty(result.getMessage())) {
topResult.setMessage("Couldn't process operation result script hook.");
}
topResult.addSubresult(result);
LoggingUtils.logUnexpectedException(LOGGER, contextDesc, e);
if (InternalsConfig.nonCriticalExceptionsAreFatal()) {
throw new SystemException(e.getMessage(), e);
} else {
return topResult;
}
}
}
use of com.evolveum.midpoint.schema.expression.VariablesMap in project midpoint by Evolveum.
the class RoleCatalogTabPanel method createScopeItem.
private SearchItem createScopeItem(Search search) {
return new SpecialSearchItem(search) {
@Override
public ObjectFilter createFilter(PageBase pageBase, VariablesMap variables) {
return null;
}
@Override
public SearchSpecialItemPanel createSpecialSearchPanel(String id) {
return new SearchSpecialItemPanel(id, new PropertyModel(getRoleCatalogStorage(), RoleCatalogStorage.F_ORG_SEARCH_SCOPE)) {
@Override
protected WebMarkupContainer initSearchItemField(String id) {
DropDownChoicePanel inputPanel = new DropDownChoicePanel(id, getModelValue(), Model.of(Arrays.asList(SearchBoxScopeType.values())), new EnumChoiceRenderer(), false);
inputPanel.getBaseFormComponent().add(WebComponentUtil.getSubmitOnEnterKeyDownBehavior("searchSimple"));
inputPanel.getBaseFormComponent().add(AttributeAppender.append("style", "width: 88px; max-width: 400px !important;"));
inputPanel.setOutputMarkupId(true);
return inputPanel;
}
@Override
protected IModel<String> createLabelModel() {
return getPageBase().createStringResource("abstractRoleMemberPanel.searchScope");
}
@Override
protected IModel<String> createHelpModel() {
return getPageBase().createStringResource("abstractRoleMemberPanel.searchScope.tooltip");
}
};
}
};
}
Aggregations