Skip to content

Commit

Permalink
Merge remote-tracking branch 'refs/remotes/origin/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
skublik committed Sep 19, 2023
2 parents 445f507 + 7e03ac4 commit acbd0ff
Show file tree
Hide file tree
Showing 18 changed files with 212 additions and 149 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -92,4 +92,8 @@ public interface ItemWrapper<I extends Item, VW extends PrismValueWrapper> exten
void setProcessProvenanceMetadata(boolean processProvenanceMetadata);

<C extends Containerable> PrismContainerValueWrapper<C> getParentContainerValue(Class<? extends C> parentClass);

boolean isValidated();

void setValidated(boolean validated);
}
Original file line number Diff line number Diff line change
Expand Up @@ -503,4 +503,25 @@ private static String localizeName(String nameKey, String defaultString) {
Validate.notNull(nameKey, "Null localization key");
return ColumnUtils.createStringResource(nameKey, defaultString).getString();
}

public static void collectWrappers(ItemWrapper iw, List<ItemWrapper> iws) {
iws.add(iw);

if (!(iw instanceof PrismContainerWrapper)) {
return;
}

PrismContainerWrapper pcw = (PrismContainerWrapper) iw;
List<PrismContainerValueWrapper> pcvws = pcw.getValues();
if (pcvws == null) {
return;
}

pcvws.forEach(pcvw -> {
pcvw.getItems().forEach(childIW -> {
collectWrappers((ItemWrapper) childIW, iws);
});
});
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public abstract class ItemPanelContext<T, IW extends ItemWrapper<?, ?>> implemen
private AjaxEventBehavior ajaxEventBehavior;
private ItemMandatoryHandler mandatoryHandler;
private VisibleEnableBehaviour visibleEnableBehaviour;
private ExpressionValidator<T> expressionValidator;
private ExpressionValidator<T, IW> expressionValidator;
private FeedbackAlerts feedback;

private FormPanelType formType = FormPanelType.getDefault();
Expand Down Expand Up @@ -131,11 +131,11 @@ public boolean isMandatory() {
return itemWrapper.getObject().isMandatory();
}

public void setExpressionValidator(ExpressionValidator<T> expressionValidator) {
public void setExpressionValidator(ExpressionValidator<T, IW> expressionValidator) {
this.expressionValidator = expressionValidator;
}

public ExpressionValidator<T> getExpressionValidator() {
public ExpressionValidator<T, IW> getExpressionValidator() {
return expressionValidator;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
import java.util.Collection;
import java.util.List;

import com.evolveum.midpoint.gui.api.prism.wrapper.ItemWrapper;
import com.evolveum.midpoint.gui.api.util.WebPrismUtil;
import org.apache.commons.lang3.BooleanUtils;
import org.apache.wicket.Component;
import org.apache.wicket.ajax.AjaxRequestTarget;
Expand Down Expand Up @@ -185,7 +187,17 @@ protected DetailsFragment createDetailsFragment() {
@Override
protected void initFragmentLayout() {
add(initSummaryPanel());
MidpointForm form = new MidpointForm(ID_MAIN_FORM);
MidpointForm<?> form = new MidpointForm<>(ID_MAIN_FORM) {

private static final long serialVersionUID = 1L;

@Override
protected void onDetach() {
resetValidatedValue();
super.onDetach();
}

};
form.add(new FormWrapperValidator(AbstractPageObjectDetails.this) {

@Override
Expand Down Expand Up @@ -685,4 +697,12 @@ public PrismObject<O> getPrismObject() {
protected SummaryPanelSpecificationType getSummaryPanelSpecification() {
return getObjectDetailsModels().getSummaryPanelSpecification();
}

private void resetValidatedValue() {
List<ItemWrapper> iws = new ArrayList<>();
PrismObjectWrapper<O> wrapper = getModelWrapperObject();
WebPrismUtil.collectWrappers(wrapper, iws);

iws.forEach(iw -> iw.setValidated(false));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,14 @@
import java.util.List;
import java.util.stream.Collectors;

import com.evolveum.midpoint.gui.api.util.WebPrismUtil;

import org.apache.wicket.Component;
import org.apache.wicket.feedback.ComponentFeedbackMessageFilter;
import org.apache.wicket.markup.html.form.Form;
import org.apache.wicket.markup.html.form.FormComponent;
import org.apache.wicket.markup.html.form.validation.IFormValidator;
import org.apache.wicket.model.IModel;
import org.apache.wicket.model.LambdaModel;
import org.apache.wicket.model.Model;
import org.apache.wicket.model.StringResourceModel;
import org.apache.wicket.util.visit.IVisit;
Expand Down Expand Up @@ -64,34 +65,18 @@ private List<ItemWrapper> listWrappersWithFormValidator() {
PrismObjectWrapper pow = getObjectWrapper();

List<ItemWrapper> iws = new ArrayList<>();
visitWrapper(pow, iws);
WebPrismUtil.collectWrappers(pow, iws);

return iws;
return iws
.stream()
.filter(iw -> iw.getFormComponentValidator() != null)
.toList();
}

private void visitWrapper(ItemWrapper iw, List<ItemWrapper> iws) {
if (iw.getFormComponentValidator() != null) {
iws.add(iw);
}

if (!(iw instanceof PrismContainerWrapper)) {
return;
}

PrismContainerWrapper pcw = (PrismContainerWrapper) iw;
List<PrismContainerValueWrapper> pcvws = pcw.getValues();
if (pcvws == null) {
private void validateItemWrapperWithFormValidator(Form form, ItemWrapper iw, PrismValueWrapper value) {
if (iw.isValidated()) {
return;
}

pcvws.forEach(pcvw -> {
pcvw.getItems().forEach(childIW -> {
visitWrapper((ItemWrapper) childIW, iws);
});
});
}

private void validateItemWrapperWithFormValidator(Form form, ItemWrapper iw, PrismValueWrapper value) {
Validatable<Serializable> validatable = new Validatable<>() {

@Override
Expand All @@ -105,8 +90,7 @@ public IModel<Serializable> getModel() {
}
};

ExpressionValidator validator = new ExpressionValidator(
LambdaModel.of(() -> iw.getFormComponentValidator()), modelServiceLocator) {
ExpressionValidator validator = new ExpressionValidator(iw, modelServiceLocator) {

@Override
protected ObjectType getObjectType() {
Expand All @@ -116,16 +100,12 @@ protected ObjectType getObjectType() {

validator.validate(validatable);
if (!validatable.isValid()) {
validatable.getErrors().forEach(e -> {
Serializable errorMessage = e.getErrorMessage((key, vars) ->
new StringResourceModel(key)
.setModel(new Model<String>())
.setDefaultValue(key)
.getString());
if (errorMessage!= null && !hasError(form, errorMessage.toString())) {
form.error(errorMessage);
}
});
validatable.getErrors().forEach(e ->
form.error(e.getErrorMessage((key, vars) ->
new StringResourceModel(key)
.setModel(new Model<String>())
.setDefaultValue(key)
.getString())));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

package com.evolveum.midpoint.gui.impl.page.admin.resource.component;

import static com.evolveum.midpoint.common.LocalizationTestUtil.getLocalizationService;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.ArrayList;
Expand Down Expand Up @@ -54,16 +56,14 @@
import com.evolveum.midpoint.prism.PrismContext;
import com.evolveum.midpoint.prism.path.ItemName;
import com.evolveum.midpoint.prism.path.ItemPath;
import com.evolveum.midpoint.prism.polystring.PolyString;
import com.evolveum.midpoint.prism.query.ObjectFilter;
import com.evolveum.midpoint.prism.query.ObjectQuery;
import com.evolveum.midpoint.prism.query.builder.S_FilterEntry;
import com.evolveum.midpoint.prism.query.builder.S_FilterExit;
import com.evolveum.midpoint.schema.GetOperationOptions;
import com.evolveum.midpoint.schema.SelectorOptions;
import com.evolveum.midpoint.schema.processor.ResourceObjectDefinition;
import com.evolveum.midpoint.schema.processor.ResourceObjectTypeDefinition;
import com.evolveum.midpoint.schema.processor.ResourceSchema;
import com.evolveum.midpoint.schema.processor.ResourceSchemaFactory;
import com.evolveum.midpoint.schema.result.OperationResult;
import com.evolveum.midpoint.schema.util.ObjectQueryUtil;
import com.evolveum.midpoint.schema.util.task.ActivityDefinitionBuilder;
Expand Down Expand Up @@ -689,15 +689,11 @@ protected ObjectQuery getCustomizeContentQuery() {
protected Integer countObjects(Class<ShadowType> type, ObjectQuery query, Collection<SelectorOptions<GetOperationOptions>> currentOptions, Task task, OperationResult result) throws CommonException {
Integer count = 0;
ResourceType resource = getObjectDetailsModels().getObjectType();
ShadowKindType kind = getKind();
if (kind != null) {
ResourceSchema resourceSchema = ResourceSchemaFactory.getCompleteSchemaRequired(resource);
@Nullable ResourceObjectDefinition objectTypeDefinition = resourceSchema.findDefaultDefinitionForKind(kind);
if (objectTypeDefinition != null) {
count = super.countObjects(type, query, currentOptions, task, result);
} else {
warn(String.format("No object type definition for %s/%s in %s", kind, getIntent(), resource));
}
if (getSelectedObjectType() == null) {
StringResourceModel warnMessage = createStringResource("PageResource.warn.no.object.definition", getKind(), getIntent(), resource);
String localeWarnMessage = getLocalizationService()
.translate(PolyString.fromOrig(warnMessage.getString()), WebComponentUtil.getCurrentLocale(), true);
warn(localeWarnMessage);
} else {
count = super.countObjects(type, query, currentOptions, task, result);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,8 +180,7 @@ protected void createValuePanel(MidpointForm form) {

private ExpressionValidator createExpressionValidator() {
ItemWrapper itemWrapper = getModelObject().getParent();
return new ExpressionValidator(
LambdaModel.of(() -> itemWrapper.getFormComponentValidator()), getParentPage()) {
return new ExpressionValidator(itemWrapper, getParentPage()) {

@Override
protected ObjectType getObjectType() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ public abstract class ItemWrapperImpl<I extends Item, VW extends PrismValueWrapp
private boolean readOnly;
private UserInterfaceElementVisibilityType visibleOverwrite;
private Integer displayOrder;
private boolean validated;

public ItemWrapperImpl(PrismContainerValueWrapper<?> parent, I item, ItemStatus status) {
Validate.notNull(item, "Item must not be null.");
Expand Down Expand Up @@ -795,4 +796,14 @@ public <C extends Containerable> PrismContainerValueWrapper<C> getParentContaine
}
return parent.getParentContainerValue(parentClass);
}

@Override
public boolean isValidated() {
return validated;
}

@Override
public void setValidated(boolean validated) {
this.validated = validated;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -660,4 +660,14 @@ public void unselect() {
}
}
}

@Override
public boolean isValidated() {
return metadataValueWrapper.isValidated();
}

@Override
public void setValidated(boolean validated) {
metadataValueWrapper.setValidated(validated);
}
}

0 comments on commit acbd0ff

Please sign in to comment.