use of com.evolveum.midpoint.schema.expression.VariablesMap in project midpoint by Evolveum.
the class TestExpressionProfileSafe method test160ScriptJavaScript.
@Test
@Override
public void test160ScriptJavaScript() throws Exception {
skipIfEcmaScriptEngineNotSupported();
given();
OperationResult result = createOperationResult();
rememberScriptExecutionCount();
ExpressionType expressionType = parseExpression(EXPRESSION_SCRIPT_JAVASCRIPT_FILE);
Collection<Source<?, ?>> sources = prepareStringSources();
VariablesMap variables = prepareBasicVariables();
ExpressionEvaluationContext expressionContext = new ExpressionEvaluationContext(sources, variables, getTestNameShort(), null);
when();
evaluatePropertyExpressionRestricted(expressionType, PrimitiveType.STRING, expressionContext, result);
then();
assertScriptExecutionIncrement(0);
}
use of com.evolveum.midpoint.schema.expression.VariablesMap in project midpoint by Evolveum.
the class TestExpressionProfileSafe method test154ScriptGroovySystemDeny.
@Test
@Override
public void test154ScriptGroovySystemDeny() throws Exception {
given();
OperationResult result = createOperationResult();
rememberScriptExecutionCount();
ExpressionType expressionType = parseExpression(EXPRESSION_SCRIPT_GROOVY_SYSTEM_DENY_FILE);
Collection<Source<?, ?>> sources = prepareStringSources();
VariablesMap variables = prepareBasicVariables();
ExpressionEvaluationContext expressionContext = new ExpressionEvaluationContext(sources, variables, getTestNameShort(), null);
when();
evaluatePropertyExpressionRestricted(expressionType, PrimitiveType.STRING, expressionContext, result);
then();
assertScriptExecutionIncrement(0);
}
use of com.evolveum.midpoint.schema.expression.VariablesMap in project midpoint by Evolveum.
the class RunReportPopupPanel method runConfirmPerformed.
private void runConfirmPerformed(AjaxRequestTarget target) {
PrismContainerValue<ReportParameterType> reportParamValue;
@NotNull PrismContainer<ReportParameterType> parameterContainer;
try {
PrismContainerDefinition<ReportParameterType> paramContainerDef = getPrismContext().getSchemaRegistry().findContainerDefinitionByElementName(ReportConstants.REPORT_PARAMS_PROPERTY_NAME);
parameterContainer = paramContainerDef.instantiate();
ReportParameterType reportParam = new ReportParameterType();
reportParamValue = reportParam.asPrismContainerValue();
reportParamValue.revive(getPrismContext());
parameterContainer.add(reportParamValue);
} catch (SchemaException e) {
LOGGER.error("Couldn't create container for report parameters");
return;
}
VariablesMap variablesMap = getTable().getReportVariables();
for (SearchFilterParameterType parameter : getModelObject().getObjectCollection().getParameter()) {
if (variablesMap.get(parameter.getName()) != null && variablesMap.getValue(parameter.getName()) != null) {
Class<?> clazz = getPrismContext().getSchemaRegistry().determineClassForType(parameter.getType());
QName type = getPrismContext().getSchemaRegistry().determineTypeForClass(clazz);
if (Containerable.class.isAssignableFrom(clazz)) {
LOGGER.error("Couldn't create container item for parameter " + parameter);
continue;
}
MutableItemDefinition def;
String namespaceUri = ReportConstants.NS_EXTENSION + "/" + AbstractReportWorkDefinitionType.F_REPORT_PARAM;
if (Referencable.class.isAssignableFrom(clazz)) {
def = getPrismContext().definitionFactory().createReferenceDefinition(new QName(namespaceUri, parameter.getName()), type);
((MutablePrismReferenceDefinition) def).setTargetTypeName(parameter.getTargetType());
} else {
List values = WebComponentUtil.getAllowedValues(parameter, getPageBase());
if (CollectionUtils.isNotEmpty(values)) {
def = getPrismContext().definitionFactory().createPropertyDefinition(new QName(namespaceUri, parameter.getName()), type, values, null).toMutable();
} else {
def = getPrismContext().definitionFactory().createPropertyDefinition(new QName(namespaceUri, parameter.getName()), type);
}
}
def.setDynamic(true);
def.setRuntimeSchema(true);
def.setMaxOccurs(1);
def.setMinOccurs(0);
if (parameter.getDisplay() != null) {
String displayName = WebComponentUtil.getTranslatedPolyString(parameter.getDisplay().getLabel());
def.setDisplayName(displayName);
String help = WebComponentUtil.getTranslatedPolyString(parameter.getDisplay().getHelp());
def.setHelp(help);
}
if (parameter.getAllowedValuesLookupTable() != null) {
def.setValueEnumerationRef(parameter.getAllowedValuesLookupTable().asReferenceValue());
}
try {
Item item = def.instantiate();
if (item instanceof PrismReference) {
ObjectReferenceType ref = (ObjectReferenceType) variablesMap.getValue(parameter.getName());
item.add(ref.asReferenceValue());
} else {
PrismPropertyValue<Object> value = getPrismContext().itemFactory().createPropertyValue();
value.setValue(variablesMap.getValue(parameter.getName()));
item.add(value);
}
reportParamValue.add(item);
} catch (SchemaException e) {
LOGGER.error("Couldn't create item for parameter " + parameter);
}
}
}
runConfirmPerformed(target, getModelObject().asPrismObject(), parameterContainer);
}
use of com.evolveum.midpoint.schema.expression.VariablesMap in project midpoint by Evolveum.
the class ReportObjectsListPanel method evaluateExpression.
@Override
protected Collection evaluateExpression(C rowValue, com.evolveum.midpoint.prism.Item<?, ?> columnItem, ExpressionType expression, GuiObjectColumnType customColumn) {
Task task = getPageBase().createSimpleTask(OPERATION_EVALUATE_EXPRESSION);
OperationResult result = task.getResult();
try {
VariablesMap variablesMap = new VariablesMap();
if (columnItem == null) {
variablesMap.put(ExpressionConstants.VAR_INPUT, null, String.class);
} else {
variablesMap.put(ExpressionConstants.VAR_INPUT, columnItem, columnItem.getDefinition());
}
processVariables(variablesMap);
if (!variablesMap.containsKey(ExpressionConstants.VAR_OBJECT)) {
variablesMap.put(ExpressionConstants.VAR_OBJECT, rowValue, rowValue.asPrismContainerValue().getDefinition());
}
Object object = getPageBase().getReportManager().evaluateScript(getReport().asPrismObject(), expression, variablesMap, "evaluate column expression", task, result);
if (object instanceof Collection) {
return (Collection) object;
}
return Collections.singletonList(object);
} catch (Exception e) {
LOGGER.error("Couldn't execute expression for {} column. Reason: {}", customColumn, e.getMessage(), e);
result.recomputeStatus();
OperationResultStatusPresentationProperties props = OperationResultStatusPresentationProperties.parseOperationalResultStatus(result.getStatus());
// TODO: this is not entirely correct
return Collections.singletonList(getPageBase().createStringResource(props.getStatusLabelKey()).getString());
}
}
use of com.evolveum.midpoint.schema.expression.VariablesMap in project midpoint by Evolveum.
the class ReportObjectsListPanel method createProvider.
@Override
protected ISelectableDataProvider<C, SelectableBean<C>> createProvider() {
SelectableBeanContainerDataProvider<C> provider = new SelectableBeanContainerDataProvider<>(this, getSearchModel(), null, false) {
@Override
public List<SelectableBean<C>> createDataObjectWrappers(Class<? extends C> type, ObjectQuery query, Collection<SelectorOptions<GetOperationOptions>> options, Task task, OperationResult result) throws CommunicationException, ObjectNotFoundException, SchemaException, SecurityViolationException, ConfigurationException, ExpressionEvaluationException {
Collection<SelectorOptions<GetOperationOptions>> defaultOptions = DefaultColumnUtils.createOption(getObjectCollectionView().getTargetClass(getPrismContext()), getSchemaService());
QName qNameType = WebComponentUtil.containerClassToQName(getPrismContext(), type);
VariablesMap variables = new VariablesMap();
if (getSearchModel().getObject() != null) {
variables.putAll(getSearchModel().getObject().getFilterVariables(getVariables(), getPageBase()));
processReferenceVariables(variables);
}
List<C> list = (List<C>) getModelInteractionService().searchObjectsFromCollection(getReport().getObjectCollection().getCollection(), qNameType, defaultOptions, query.getPaging(), variables, task, result);
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("Query {} resulted in {} objects", type.getSimpleName(), list.size());
}
List<SelectableBean<C>> data = new ArrayList<SelectableBean<C>>();
for (C object : list) {
data.add(createDataObjectWrapper(object));
}
return data;
}
@Override
protected Integer countObjects(Class<? extends C> type, ObjectQuery query, Collection<SelectorOptions<GetOperationOptions>> currentOptions, Task task, OperationResult result) throws CommunicationException, ObjectNotFoundException, SchemaException, SecurityViolationException, ConfigurationException, ExpressionEvaluationException {
Collection<SelectorOptions<GetOperationOptions>> defaultOptions = DefaultColumnUtils.createOption(getObjectCollectionView().getTargetClass(getPrismContext()), getSchemaService());
QName qNameType = WebComponentUtil.containerClassToQName(getPrismContext(), type);
VariablesMap variables = new VariablesMap();
if (getSearchModel().getObject() != null) {
variables.putAll(getSearchModel().getObject().getFilterVariables(getVariables(), getPageBase()));
processReferenceVariables(variables);
}
return getModelInteractionService().countObjectsFromCollection(getReport().getObjectCollection().getCollection(), qNameType, defaultOptions, null, variables, task, result);
}
@Override
protected boolean isUseObjectCounting() {
return !isDisableCounting();
}
@Override
public boolean isOrderingDisabled() {
return isDisableSorting();
}
@Override
public ObjectQuery getQuery() {
// fake query because of we need paging in method createDataObjectWrappers
return getPrismContext().queryFor(ObjectType.class).build();
}
@Override
@NotNull
protected List<ObjectOrdering> createObjectOrderings(SortParam<String> sortParam) {
if (AuditEventRecordType.class.equals(getDefaultType()) && sortParam != null && sortParam.getProperty() != null) {
OrderDirection order = sortParam.isAscending() ? OrderDirection.ASCENDING : OrderDirection.DESCENDING;
return Collections.singletonList(getPrismContext().queryFactory().createOrdering(ItemPath.create(new QName(AuditEventRecordType.COMPLEX_TYPE.getNamespaceURI(), sortParam.getProperty())), order));
}
return super.createObjectOrderings(sortParam);
}
};
if (provider.getSort() == null && hasView()) {
if (ObjectType.class.isAssignableFrom(getDefaultType())) {
provider.setSort("name", SortOrder.ASCENDING);
} else if (AuditEventRecordType.class.isAssignableFrom(getDefaultType())) {
provider.setSort("timestamp", SortOrder.ASCENDING);
}
}
return provider;
}
Aggregations