Skip to content

Commit

Permalink
Merge branches 'master' and 'master' of github.com:Evolveum/midpoint
Browse files Browse the repository at this point in the history
* 'master' of github.com:Evolveum/midpoint:
  Add auto-unlocking of locked-out users
  small change for parameters usage
  filter parameters fix

* 'master' of github.com:Evolveum/midpoint:
  Add auto-unlocking of locked-out users
  small change for parameters usage
  filter parameters fix
  • Loading branch information
katkav committed Sep 5, 2022
2 parents aa6adb9 + fe8dc17 commit 5046525
Show file tree
Hide file tree
Showing 25 changed files with 486 additions and 240 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5277,26 +5277,29 @@ public static int countLinkForDeadShadows(Collection<ObjectReferenceType> refs)
return count;
}

public static List<DisplayableValue<?>> getAllowedValues(SearchFilterParameterType parameter, PageBase pageBase) {
public static List<DisplayableValue<?>> getAllowedValues(SearchFilterParameterType parameter, ModelServiceLocator modelServiceLocator) {
if (parameter == null || parameter.getAllowedValuesExpression() == null) {
return new ArrayList<>();
}
return getAllowedValues(parameter.getAllowedValuesExpression(), pageBase);
return getAllowedValues(parameter.getAllowedValuesExpression(), modelServiceLocator);
}

public static List<DisplayableValue<?>> getAllowedValues(ExpressionType expression, PageBase pageBase) {
public static List<DisplayableValue<?>> getAllowedValues(ExpressionType expression, ModelServiceLocator modelServiceLocator) {
List<DisplayableValue<?>> allowedValues = new ArrayList<>();

Task task = pageBase.createSimpleTask("evaluate expression for allowed values");
if (expression == null) {
return allowedValues;
}
Task task = modelServiceLocator.createSimpleTask("evaluate expression for allowed values");
Object value;
try {

value = ExpressionUtil.evaluateExpressionNative(null, new VariablesMap(), null,
expression, MiscSchemaUtil.getExpressionProfile(),
pageBase.getExpressionFactory(), "evaluate expression for allowed values", task, task.getResult());
modelServiceLocator.getExpressionFactory(), "evaluate expression for allowed values", task, task.getResult());
} catch (Exception e) {
LOGGER.error("Couldn't execute expression " + expression, e);
pageBase.error(pageBase.createStringResource("FilterSearchItem.message.error.evaluateAllowedValuesExpression", expression).getString());
if (modelServiceLocator instanceof PageBase) {
((PageBase)modelServiceLocator).error(PageBase.createStringResourceStatic("FilterSearchItem.message.error.evaluateAllowedValuesExpression", expression).getString());
}
return allowedValues;
}
if (value instanceof PrismPropertyValue) {
Expand All @@ -5305,15 +5308,19 @@ public static List<DisplayableValue<?>> getAllowedValues(ExpressionType expressi

if (!(value instanceof Set)) {
LOGGER.error("Exception return unexpected type, expected Set<PPV<DisplayableValue>>, but was " + (value == null ? null : value.getClass()));
pageBase.error(pageBase.createStringResource("FilterSearchItem.message.error.wrongType", expression).getString());
if (modelServiceLocator instanceof PageBase) {
((PageBase)modelServiceLocator).error(PageBase.createStringResourceStatic("FilterSearchItem.message.error.wrongType", expression).getString());
}
return allowedValues;
}

if (!((Set<?>) value).isEmpty()) {
if (!(((Set<?>) value).iterator().next() instanceof PrismPropertyValue)
|| !(((PrismPropertyValue) (((Set<?>) value).iterator().next())).getValue() instanceof DisplayableValue)) {
LOGGER.error("Exception return unexpected type, expected Set<PPV<DisplayableValue>>, but was " + (value == null ? null : value.getClass()));
pageBase.error(pageBase.createStringResource("FilterSearchItem.message.error.wrongType", expression).getString());
if (modelServiceLocator instanceof PageBase) {
((PageBase)modelServiceLocator).error(PageBase.createStringResourceStatic("FilterSearchItem.message.error.wrongType", expression).getString());
}
return allowedValues;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ private SearchConfigurationWrapper<C> createSearchConfigWrapper(Class<C> type) {
}


SearchConfigurationWrapper<C> searchConfigWrapper = maybeConfig != null ? new SearchConfigurationWrapper<C>(type, maybeConfig) : new SearchConfigurationWrapper<C>(type);
SearchConfigurationWrapper<C> searchConfigWrapper = maybeConfig != null ? new SearchConfigurationWrapper<C>(type, maybeConfig, getPageBase()) : new SearchConfigurationWrapper<C>(type, getPageBase());
CompiledObjectCollectionView collectionView = getObjectCollectionView();
if (objectCollectionRefExists(collectionView)) {
searchConfigWrapper.setCollectionRefOid(collectionView.getCollection().getCollectionRef().getOid());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,8 @@
import com.evolveum.midpoint.gui.api.page.PageBase;
import com.evolveum.midpoint.prism.Containerable;
import com.evolveum.midpoint.prism.query.ObjectFilter;
import com.evolveum.midpoint.schema.expression.TypedValue;
import com.evolveum.midpoint.schema.expression.VariablesMap;
import com.evolveum.midpoint.util.DisplayableValue;
import com.evolveum.midpoint.web.component.util.SelectableBean;
import com.evolveum.midpoint.web.component.util.SelectableRow;
import com.evolveum.midpoint.xml.ns._public.common.common_3.SearchBoxModeType;

Expand All @@ -35,8 +33,8 @@ public abstract class AbstractSearchItemWrapper<T extends Serializable> implemen
private boolean visible;
private boolean canConfigure = true;

String functionParameterName;
TypedValue functionParameterValue;
String parameterName;
Class<T> parameterValueType;

public abstract Class<? extends AbstractSearchItemPanel> getSearchItemPanelClass();

Expand Down Expand Up @@ -77,20 +75,20 @@ public DisplayableValue<T> getValue() {
return value;
}

public String getFunctionParameterName() {
return functionParameterName;
public String getParameterName() {
return parameterName;
}

public void setFunctionParameterName(String functionParameterName) {
this.functionParameterName = functionParameterName;
public void setParameterName(String parameterName) {
this.parameterName = parameterName;
}

public TypedValue getFunctionParameterValue() {
return functionParameterValue;
public Class<T> getParameterValueType() {
return parameterValueType;
}

public void setFunctionParameterValue(TypedValue functionParameterValue) {
this.functionParameterValue = functionParameterValue;
public void setParameterValueType(Class<T> parameterValueType) {
this.parameterValueType = parameterValueType;
}

public void setValue(DisplayableValue<T> value) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,14 @@

public class PropertySearchItemWrapper<T extends Serializable> extends AbstractSearchItemWrapper<T> {

// private ItemDefinition<?> itemDef;
private ItemPath path;
private QName valueTypeName;
private String name;
private String help;

public PropertySearchItemWrapper () {
}

public PropertySearchItemWrapper (ItemPath path) {
this.path = path;
}
Expand Down Expand Up @@ -76,43 +78,6 @@ private boolean isResourceRefSearchItem() {
return ShadowType.F_RESOURCE_REF.equivalent(path);
}

// @Override
// public String getName() {
// if (searchItem.getDisplayName() != null){
// return WebComponentUtil.getTranslatedPolyString(searchItem.getDisplayName());
// }
// return "";
// String key = getDefinition().getDef().getDisplayName();
// if (StringUtils.isEmpty(key)) {
// key = getSearch().getTypeClass().getSimpleName() + '.' + getDefinition().getDef().getItemName().getLocalPart();
// }
//
// StringResourceModel nameModel = PageBase.createStringResourceStatic(null, key);
// if (nameModel != null) {
// if (StringUtils.isNotEmpty(nameModel.getString())) {
// return nameModel.getString();
// }
// }
// String name = getDefinition().getDef().getDisplayName();
// if (StringUtils.isNotEmpty(name)) {
// return name;
// }
//
// return getDefinition().getDef().getItemName().getLocalPart();
// if (getDisplayName() != null){
// return WebComponentUtil.getTranslatedPolyString(getDisplayName());
// }

// if (getDef() != null && StringUtils.isNotEmpty(getDef().getDisplayName())) {
// return PageBase.createStringResourceStatic(null, getDef().getDisplayName()).getString();
// }
// return WebComponentUtil.getItemDefinitionDisplayNameOrName(getDef(), null);
// }

// @Override
// public String getHelp() {
// return help;
// }

@Override
public String getTitle() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import com.evolveum.midpoint.gui.api.util.WebModelServiceUtils;
import com.evolveum.midpoint.model.api.authentication.CompiledObjectCollectionView;
import com.evolveum.midpoint.prism.*;
import com.evolveum.midpoint.schema.expression.TypedValue;
import com.evolveum.midpoint.schema.result.OperationResult;
import com.evolveum.midpoint.task.api.Task;
import com.evolveum.midpoint.xml.ns._public.common.common_3.*;
Expand Down Expand Up @@ -348,7 +349,8 @@ public List<ObjectFilter> getSearchItemFilterList(PageBase pageBase, VariablesMa
}
boolean abstractRoleFilterCheck = false;
for (AbstractSearchItemWrapper item : getItems()) {
if (!item.isApplyFilter(getSearchMode()) ||
if (hasParameter(item) ||
!item.isApplyFilter(getSearchMode()) ||
(item instanceof AbstractRoleSearchItemWrapper && abstractRoleFilterCheck)) {
continue;
}
Expand All @@ -363,27 +365,20 @@ public List<ObjectFilter> getSearchItemFilterList(PageBase pageBase, VariablesMa
return conditions;
}

private boolean hasParameter(AbstractSearchItemWrapper<?> searchItemWrapper) {
return StringUtils.isNotEmpty(searchItemWrapper.getParameterName());
}

public VariablesMap getFilterVariables(VariablesMap defaultVariables, PageBase pageBase) {
VariablesMap variables = defaultVariables == null ? new VariablesMap() : defaultVariables;
List<AbstractSearchItemWrapper> items = getItems();
items.forEach(item -> {
if (StringUtils.isNoneEmpty(item.getFunctionParameterName())) {
variables.put(item.getFunctionParameterName(), item.functionParameterValue);
if (StringUtils.isNotEmpty(item.getParameterName())) {
Object parameterValue = item.getValue() != null ? item.getValue().getValue() : null;
TypedValue value = new TypedValue(parameterValue, item.getParameterValueType());
variables.put(item.getParameterName(), value);
}
});

// if (getConfig().getSearchItems() == null) {
// return variables;
// }
// for (SearchItemType item : getConfig().getSearchItems().getSearchItem()) {
// SearchFilterParameterType functionParameter = item.getParameter();
// if (functionParameter != null && functionParameter.getType() != null) {
// Class<?> inputClass = pageBase.getPrismContext().getSchemaRegistry().determineClassForType(functionParameter.getType());
// TypedValue value = new TypedValue(//item.getInput() != null ? item.getInput().getValue() :
// null, inputClass);
// variables.put(functionParameter.getName(), value);
// }
// }
return variables;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.evolveum.midpoint.gui.impl.component.search;

import com.evolveum.midpoint.gui.api.util.ModelServiceLocator;
import com.evolveum.midpoint.gui.api.util.WebComponentUtil;
import com.evolveum.midpoint.prism.Containerable;
import com.evolveum.midpoint.prism.PrismContext;
Expand Down Expand Up @@ -45,11 +46,11 @@ public class SearchConfigurationWrapper<C extends Containerable> implements Seri
private ObjectReferenceType projectRef;
private ObjectReferenceType tenantRef;

public SearchConfigurationWrapper(Class<C> typeClass) {
public SearchConfigurationWrapper(Class<C> typeClass, ModelServiceLocator modelServiceLocator) {
this.typeClass = typeClass;
}

public SearchConfigurationWrapper(Class<C> typeClass, SearchBoxConfigurationType searchBoxConfig) {
public SearchConfigurationWrapper(Class<C> typeClass, SearchBoxConfigurationType searchBoxConfig, ModelServiceLocator modelServiceLocator) {
this.typeClass = typeClass;
if (searchBoxConfig.getObjectTypeConfiguration() != null) {
searchBoxConfig.getObjectTypeConfiguration().getSupportedTypes()
Expand Down Expand Up @@ -82,7 +83,8 @@ public SearchConfigurationWrapper(Class<C> typeClass, SearchBoxConfigurationType
}
if (searchBoxConfig.getSearchItems() != null && CollectionUtils.isNotEmpty(searchBoxConfig.getSearchItems().getSearchItem())) {
searchBoxConfig.getSearchItems().getSearchItem().forEach(item -> {
PropertySearchItemWrapper itemWrapper = SearchFactory.createPropertySearchItemWrapper(typeClass, item, null, null);
PropertySearchItemWrapper itemWrapper = SearchFactory.createPropertySearchItemWrapper(typeClass, item, null, null,
modelServiceLocator);
if (itemWrapper != null) {
itemsList.add(itemWrapper);
}
Expand Down

0 comments on commit 5046525

Please sign in to comment.