Skip to content

Commit

Permalink
AssignmentPanel - Use modified targetRef for concrete panels
Browse files Browse the repository at this point in the history
Some panels are concretized by targetRef/targetType. In this panels
we can safely assume that targetRef is of static type, which allows
us to create temporary schema overlay with narrowed definition of targetRef.

This narrowed definition is used in collumns models and in search panel
to allow using concrete extension items of Role, Org or Service to serve as
columns and/or basic search fields.

This change also provides nice feature for Axiom Query language, that
user in this specific panels does not need to specify type when dereferencing.
  • Loading branch information
tonydamage committed Aug 10, 2022
1 parent 64a07e7 commit a371c99
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 4 deletions.
2 changes: 1 addition & 1 deletion gui/admin-gui/pom.xml
Expand Up @@ -425,7 +425,7 @@
<groupId>com.evolveum.midpoint.model</groupId>
<artifactId>model-impl</artifactId>
<version>${project.version}</version>
<scope>runtime</scope>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.evolveum.midpoint.model</groupId>
Expand Down
Expand Up @@ -67,6 +67,7 @@
import com.evolveum.midpoint.schema.SelectorOptions;
import com.evolveum.midpoint.schema.constants.ExpressionConstants;
import com.evolveum.midpoint.schema.constants.ObjectTypes;
import com.evolveum.midpoint.schema.expression.TypedValue;
import com.evolveum.midpoint.schema.expression.VariablesMap;
import com.evolveum.midpoint.schema.result.OperationResult;
import com.evolveum.midpoint.schema.util.MiscSchemaUtil;
Expand Down Expand Up @@ -520,11 +521,14 @@ private boolean nothingToTransform(GuiObjectColumnType customColumn) {
return customColumn.getPath() == null && (customColumn.getExport() == null || customColumn.getExport().getExpression() == null);
}

protected PrismContainerDefinition<C> getContainerDefinitionForColumns() {
return getPageBase().getPrismContext().getSchemaRegistry()
.findContainerDefinitionByCompileTimeClass(getType());
}

private boolean noItemDefinitionFor(ItemPath columnPath, GuiObjectColumnType customColumn) {
if (columnPath != null) {
ItemDefinition itemDefinition = getPageBase().getPrismContext().getSchemaRegistry()
.findContainerDefinitionByCompileTimeClass(getType())
.findItemDefinition(columnPath);
ItemDefinition itemDefinition = getContainerDefinitionForColumns().findItemDefinition(columnPath);
if (itemDefinition == null) { // TODO check && expression == null) {
LOGGER.warn("Unknown path '{}' in a definition of column '{}'", columnPath, customColumn.getName());
return true;
Expand Down Expand Up @@ -666,6 +670,9 @@ protected Collection<String> evaluateExpression(C rowValue, Item<?, ?> columnIte
variablesMap.put(ExpressionConstants.VAR_OBJECT, rowValue, rowValue.getClass());
if (columnItem != null) {
variablesMap.put(ExpressionConstants.VAR_INPUT, columnItem, columnItem.getDefinition());
} else {
// TODO: Is this correct?
variablesMap.put(ExpressionConstants.VAR_INPUT, new TypedValue<>(null, Item.class));
}
return ExpressionUtil.evaluateStringExpression(variablesMap, getPageBase().getPrismContext(), expression,
MiscSchemaUtil.getExpressionProfile(), getPageBase().getExpressionFactory(), "evaluate column expression",
Expand Down Expand Up @@ -1139,6 +1146,7 @@ public void clearCache() {
WebComponentUtil.clearProviderCache(getDataProvider());
}

@Override
public StringResourceModel createStringResource(String resourceKey, Object... objects) {
return PageBase.createStringResourceStatic(resourceKey, objects);
}
Expand Down
Expand Up @@ -22,6 +22,7 @@
import org.apache.wicket.model.LoadableDetachableModel;
import org.apache.wicket.model.Model;
import org.apache.wicket.model.PropertyModel;
import org.checkerframework.common.returnsreceiver.qual.This;

import com.evolveum.midpoint.gui.api.GuiStyleConstants;
import com.evolveum.midpoint.gui.api.component.AssignmentPopup;
Expand All @@ -42,6 +43,8 @@
import com.evolveum.midpoint.gui.impl.component.icon.CompositedIconBuilder;
import com.evolveum.midpoint.gui.impl.component.icon.IconCssStyle;
import com.evolveum.midpoint.gui.impl.prism.wrapper.PrismReferenceValueWrapperImpl;
import com.evolveum.midpoint.model.impl.schema.transform.TransformableContainerDefinition;
import com.evolveum.midpoint.model.impl.schema.transform.TransformableReferenceDefinition;
import com.evolveum.midpoint.prism.*;
import com.evolveum.midpoint.prism.path.ItemPath;
import com.evolveum.midpoint.prism.query.ObjectFilter;
Expand Down Expand Up @@ -88,11 +91,14 @@ public abstract class AbstractAssignmentTypePanel extends MultivalueContainerLis
protected static final String OPERATION_LOAD_ASSIGNMENTS_TARGET_OBJ = DOT_CLASS + "loadAssignmentsTargetRefObject";
protected static final String OPERATION_LOAD_ASSIGNMENT_TARGET_RELATIONS = DOT_CLASS + "loadAssignmentTargetRelations";

private static final ItemPath TARGET_REF_EXTENSION = ItemPath.create(AssignmentType.F_TARGET_REF, PrismConstants.T_OBJECT_REFERENCE, ObjectType.F_EXTENSION);

private IModel<PrismContainerWrapper<AssignmentType>> model;
protected int assignmentsRequestsLimit = -1;

private Class<? extends Objectable> objectType;
private String objectOid;
private PrismContainerDefinition<AssignmentType> searchDefinition;

public AbstractAssignmentTypePanel(String id, IModel<PrismContainerWrapper<AssignmentType>> model, ContainerPanelConfigurationType config, Class<? extends Objectable> type, String oid) {
super(id, AssignmentType.class, config);
Expand Down Expand Up @@ -629,9 +635,39 @@ protected List<SearchItemDefinition> initSearchableItems(PrismContainerDefinitio
return createSearchableItems(containerDef);
}


@Override
protected PrismContainerDefinition<AssignmentType> getTypeDefinitionForSearch() {
if (searchDefinition != null) {
return searchDefinition;
}
PrismContainerDefinition<AssignmentType> orig = super.getTypeDefinitionForSearch();
if (getAssignmentType() == null) {
searchDefinition = orig;
} else {
// We have more concrete assignment type, we should replace targetRef definition
// with one with concrete assignment type.
var transformed = TransformableContainerDefinition.of(orig);
var targetRef = TransformableReferenceDefinition.of(orig.getComplexTypeDefinition().findReferenceDefinition(AssignmentType.F_TARGET_REF));
targetRef.setTargetTypeName(getAssignmentType());
transformed.getComplexTypeDefinition().replaceDefinition(AssignmentType.F_TARGET_REF, targetRef);
searchDefinition = transformed;
}

return searchDefinition;
}


@Override
protected PrismContainerDefinition<AssignmentType> getContainerDefinitionForColumns() {
// In columns model we can benefit for same targetType expansion as in container model.
return getTypeDefinitionForSearch();
}

@Override
protected Search createSearch(Class<AssignmentType> type) {
Search search = super.createSearch(type);
search.getType().setContainerDefinition(getTypeDefinitionForSearch());
search.setFullTextSearchEnabled(isRepositorySearchEnabled());
return search;
}
Expand All @@ -645,6 +681,12 @@ protected List<SearchItemDefinition> createSearchableItems(PrismContainerDefinit

defs.addAll(SearchFactory.createExtensionDefinitionList(containerDef));

// We can determine indexed extensions if getAssignmentType() != null
if (getAssignmentType() != null) {
var objectExt = SearchFactory.createExtensionDefinitionList(containerDef, TARGET_REF_EXTENSION);
LOGGER.info("Adding extension properties from targetRef/@: {}", objectExt);
defs.addAll(objectExt);
}
return defs;

}
Expand Down

0 comments on commit a371c99

Please sign in to comment.