Search in sources :

Example 1 with OperationResultStatusPresentationProperties

use of com.evolveum.midpoint.web.page.admin.server.dto.OperationResultStatusPresentationProperties in project midpoint by Evolveum.

the class ObjectNameColumn method populateItem.

@Override
public void populateItem(final Item<ICellPopulator<SelectableBean<O>>> cellItem, String componentId, final IModel<SelectableBean<O>> rowModel) {
    IModel<String> labelModel = new AbstractReadOnlyModel<String>() {

        private static final long serialVersionUID = 1L;

        @Override
        public String getObject() {
            SelectableBean<O> selectableBean = rowModel.getObject();
            O value = selectableBean.getValue();
            if (value == null) {
                OperationResult result = selectableBean.getResult();
                OperationResultStatusPresentationProperties props = OperationResultStatusPresentationProperties.parseOperationalResultStatus(result.getStatus());
                return cellItem.getString(props.getStatusLabelKey());
            } else {
                String name = WebComponentUtil.getName(value);
                if (selectableBean.getResult() != null) {
                    StringBuilder complexName = new StringBuilder();
                    complexName.append(name);
                    complexName.append(" (");
                    complexName.append(selectableBean.getResult().getStatus());
                    complexName.append(")");
                    return complexName.toString();
                }
                return name;
            }
        }
    };
    if (isClickable(rowModel)) {
        // beware: rowModel is very probably resolved at this moment; but it seems to cause no problems
        cellItem.add(new LinkPanel(componentId, labelModel) {

            private static final long serialVersionUID = 1L;

            @Override
            public void onClick(AjaxRequestTarget target) {
                SelectableBean<O> selectableBean = rowModel.getObject();
                O value = selectableBean.getValue();
                if (value == null) {
                    OperationResult result = selectableBean.getResult();
                    throw new RestartResponseException(new PageOperationResult(result));
                } else {
                    if (selectableBean.getResult() != null) {
                        throw new RestartResponseException(new PageOperationResult(selectableBean.getResult()));
                    } else {
                        ObjectNameColumn.this.onClick(target, rowModel);
                    }
                }
            }
        });
    } else {
        cellItem.add(new Label(componentId, labelModel));
    }
}
Also used : AbstractReadOnlyModel(org.apache.wicket.model.AbstractReadOnlyModel) Label(org.apache.wicket.markup.html.basic.Label) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) PageOperationResult(com.evolveum.midpoint.web.page.error.PageOperationResult) OperationResultStatusPresentationProperties(com.evolveum.midpoint.web.page.admin.server.dto.OperationResultStatusPresentationProperties) PageOperationResult(com.evolveum.midpoint.web.page.error.PageOperationResult) AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) RestartResponseException(org.apache.wicket.RestartResponseException) SelectableBean(com.evolveum.midpoint.web.component.util.SelectableBean)

Example 2 with OperationResultStatusPresentationProperties

use of com.evolveum.midpoint.web.page.admin.server.dto.OperationResultStatusPresentationProperties in project midpoint by Evolveum.

the class ContainerableListPanel method evaluateExpression.

protected Collection<String> evaluateExpression(C rowValue, Item<?, ?> columnItem, ExpressionType expression, GuiObjectColumnType customColumn) {
    Task task = getPageBase().createSimpleTask(OPERATION_EVALUATE_EXPRESSION);
    OperationResult result = task.getResult();
    try {
        VariablesMap variablesMap = new VariablesMap();
        variablesMap.put(ExpressionConstants.VAR_OBJECT, rowValue, rowValue.getClass());
        if (columnItem != null) {
            variablesMap.put(ExpressionConstants.VAR_INPUT, columnItem, columnItem.getDefinition());
        }
        return ExpressionUtil.evaluateStringExpression(variablesMap, getPageBase().getPrismContext(), expression, MiscSchemaUtil.getExpressionProfile(), getPageBase().getExpressionFactory(), "evaluate column expression", task, result);
    } 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());
    }
}
Also used : Task(com.evolveum.midpoint.task.api.Task) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) VariablesMap(com.evolveum.midpoint.schema.expression.VariablesMap) OperationResultStatusPresentationProperties(com.evolveum.midpoint.web.page.admin.server.dto.OperationResultStatusPresentationProperties)

Example 3 with OperationResultStatusPresentationProperties

use of com.evolveum.midpoint.web.page.admin.server.dto.OperationResultStatusPresentationProperties in project midpoint by Evolveum.

the class ObjectNameColumn method evaluateExpression.

private String evaluateExpression(Item<ICellPopulator<SelectableBean<O>>> cellItem, ItemPath itemPath, O value) {
    Task task = pageBase.createSimpleTask("evaluate column expression");
    try {
        com.evolveum.midpoint.prism.Item<?, ?> item = value.asPrismObject().findItem(itemPath);
        VariablesMap variablesMap = new VariablesMap();
        variablesMap.put(ExpressionConstants.VAR_OBJECT, value, value.getClass());
        if (item != null) {
            variablesMap.put(ExpressionConstants.VAR_INPUT, item, item.getDefinition().getTypeClass());
        }
        Collection<String> evaluatedValues = ExpressionUtil.evaluateStringExpression(variablesMap, pageBase.getPrismContext(), expression, MiscSchemaUtil.getExpressionProfile(), pageBase.getExpressionFactory(), "evaluate column expression", task, task.getResult());
        if (evaluatedValues != null) {
            return evaluatedValues.iterator().next();
        }
        return null;
    } catch (SchemaException | ExpressionEvaluationException | ObjectNotFoundException | CommunicationException | ConfigurationException | SecurityViolationException e) {
        LOGGER.error("Couldn't execute expression for name column");
        OperationResult result = task.getResult();
        OperationResultStatusPresentationProperties props = OperationResultStatusPresentationProperties.parseOperationalResultStatus(result.getStatus());
        return cellItem.getString(props.getStatusLabelKey());
    }
}
Also used : Task(com.evolveum.midpoint.task.api.Task) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) PageOperationResult(com.evolveum.midpoint.web.page.error.PageOperationResult) OperationResultStatusPresentationProperties(com.evolveum.midpoint.web.page.admin.server.dto.OperationResultStatusPresentationProperties) VariablesMap(com.evolveum.midpoint.schema.expression.VariablesMap)

Example 4 with OperationResultStatusPresentationProperties

use of com.evolveum.midpoint.web.page.admin.server.dto.OperationResultStatusPresentationProperties in project midpoint by Evolveum.

the class WebComponentUtil method createErrorIcon.

public static String createErrorIcon(OperationResult result) {
    if (result == null) {
        return "";
    }
    OperationResultStatus status = result.getStatus();
    OperationResultStatusPresentationProperties icon = OperationResultStatusPresentationProperties.parseOperationalResultStatus(status);
    return icon.getIcon() + " fa-lg";
}
Also used : OperationResultStatus(com.evolveum.midpoint.schema.result.OperationResultStatus) OperationResultStatusPresentationProperties(com.evolveum.midpoint.web.page.admin.server.dto.OperationResultStatusPresentationProperties)

Example 5 with OperationResultStatusPresentationProperties

use of com.evolveum.midpoint.web.page.admin.server.dto.OperationResultStatusPresentationProperties in project midpoint by Evolveum.

the class ObjectNameColumn method getResultAsString.

private String getResultAsString(Item<ICellPopulator<SelectableBean<O>>> cellItem, SelectableBean<O> selectableBean) {
    OperationResult result = selectableBean.getResult();
    OperationResultStatusPresentationProperties props = OperationResultStatusPresentationProperties.parseOperationalResultStatus(result.getStatus());
    return cellItem.getString(props.getStatusLabelKey());
}
Also used : OperationResult(com.evolveum.midpoint.schema.result.OperationResult) PageOperationResult(com.evolveum.midpoint.web.page.error.PageOperationResult) OperationResultStatusPresentationProperties(com.evolveum.midpoint.web.page.admin.server.dto.OperationResultStatusPresentationProperties)

Aggregations

OperationResultStatusPresentationProperties (com.evolveum.midpoint.web.page.admin.server.dto.OperationResultStatusPresentationProperties)8 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)6 VariablesMap (com.evolveum.midpoint.schema.expression.VariablesMap)3 Task (com.evolveum.midpoint.task.api.Task)3 PageOperationResult (com.evolveum.midpoint.web.page.error.PageOperationResult)3 AjaxRequestTarget (org.apache.wicket.ajax.AjaxRequestTarget)2 LoadableModel (com.evolveum.midpoint.gui.api.model.LoadableModel)1 CompositedIconPanel (com.evolveum.midpoint.gui.impl.component.data.column.CompositedIconPanel)1 CompositedIcon (com.evolveum.midpoint.gui.impl.component.icon.CompositedIcon)1 CompositedIconBuilder (com.evolveum.midpoint.gui.impl.component.icon.CompositedIconBuilder)1 OperationResultStatus (com.evolveum.midpoint.schema.result.OperationResultStatus)1 CommunicationException (com.evolveum.midpoint.util.exception.CommunicationException)1 AjaxButton (com.evolveum.midpoint.web.component.AjaxButton)1 SelectableBean (com.evolveum.midpoint.web.component.util.SelectableBean)1 VisibleEnableBehaviour (com.evolveum.midpoint.web.component.util.VisibleEnableBehaviour)1 DisplayType (com.evolveum.midpoint.xml.ns._public.common.common_3.DisplayType)1 IconType (com.evolveum.midpoint.xml.ns._public.common.common_3.IconType)1 RestartResponseException (org.apache.wicket.RestartResponseException)1 Label (org.apache.wicket.markup.html.basic.Label)1 AbstractReadOnlyModel (org.apache.wicket.model.AbstractReadOnlyModel)1