Skip to content

Commit

Permalink
Merge remote-tracking branch 'refs/remotes/origin/feature/new-authent…
Browse files Browse the repository at this point in the history
…ication-module' into feature/new-authentication-module
  • Loading branch information
skublik committed Jan 3, 2022
2 parents 29bc4a5 + f428e96 commit ae92473
Show file tree
Hide file tree
Showing 4 changed files with 134 additions and 216 deletions.
Original file line number Diff line number Diff line change
@@ -1,12 +1,26 @@
/*
* Copyright (c) 2010-2017 Evolveum and contributors
* Copyright (C) 2010-2021 Evolveum and contributors
*
* This work is dual-licensed under the Apache License 2.0
* and European Union Public License. See LICENSE file for details.
*/

package com.evolveum.midpoint.web.component.input;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.ajax.form.AjaxFormComponentUpdatingBehavior;
import org.apache.wicket.ajax.markup.html.form.AjaxSubmitLink;
import org.apache.wicket.markup.html.WebMarkupContainer;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.form.DropDownChoice;
import org.apache.wicket.markup.html.form.EnumChoiceRenderer;
import org.apache.wicket.markup.html.form.TextArea;
import org.apache.wicket.model.IModel;
import org.apache.wicket.model.PropertyModel;

import com.evolveum.midpoint.gui.api.component.BasePanel;
import com.evolveum.midpoint.gui.api.model.LoadableModel;
import com.evolveum.midpoint.gui.api.page.PageBase;
Expand All @@ -23,32 +37,14 @@
import com.evolveum.midpoint.xml.ns._public.common.common_3.ExpressionType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ValuePolicyType;
import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.ajax.form.AjaxFormComponentUpdatingBehavior;
import org.apache.wicket.ajax.markup.html.form.AjaxSubmitLink;
import org.apache.wicket.markup.html.WebMarkupContainer;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.form.DropDownChoice;
import org.apache.wicket.markup.html.form.EnumChoiceRenderer;
import org.apache.wicket.markup.html.form.Form;
import org.apache.wicket.markup.html.form.TextArea;
import org.apache.wicket.model.IModel;
import org.apache.wicket.model.PropertyModel;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
* @author shood
* */
* @author shood
*/
public class ExpressionEditorPanel extends BasePanel<ExpressionType> {

private static final Trace LOGGER = TraceManager.getTrace(ExpressionEditorPanel.class);

private static final String DOT_CLASS = ExpressionEditorPanel.class.getName() + ".";
private static final String OPERATION_LOAD_PASSWORD_POLICIES = DOT_CLASS + "createPasswordPolicyList";

private static final String ID_DESCRIPTION = "description";
private static final String ID_TYPE = "type";
private static final String ID_LANGUAGE = "language";
Expand All @@ -67,20 +63,20 @@ public class ExpressionEditorPanel extends BasePanel<ExpressionType> {
private static final String ID_T_EXPRESSION = "expressionTooltip";

private IModel<ExpressionTypeDto> dtoModel;
private Map<String, String> policyMap = new HashMap<>();
private final Map<String, String> policyMap = new HashMap<>();

public ExpressionEditorPanel(String id, IModel<ExpressionType> model, PageBase parentPage) {
super(id, model);
initLayout(parentPage);
}

protected IModel<ExpressionTypeDto> getExpressionDtoModel(){
protected IModel<ExpressionTypeDto> getExpressionDtoModel() {
return dtoModel;
}

private void loadDtoModel() {
if (dtoModel == null) {
dtoModel = new LoadableModel<ExpressionTypeDto>(false) {
dtoModel = new LoadableModel<>(false) {
@Override
protected ExpressionTypeDto load() {
return new ExpressionTypeDto(getModel().getObject(), getPageBase().getPrismContext());
Expand All @@ -97,18 +93,18 @@ protected void initLayout(PageBase parentPage) {
Label descriptionLabel = new Label(ID_LABEL_DESCRIPTION, createStringResource(getDescriptionLabelKey()));
add(descriptionLabel);

TextArea description = new TextArea<>(ID_DESCRIPTION, new PropertyModel<String>(dtoModel, ExpressionTypeDto.F_DESCRIPTION));
TextArea<?> description = new TextArea<>(ID_DESCRIPTION, new PropertyModel<String>(dtoModel, ExpressionTypeDto.F_DESCRIPTION));
description.setOutputMarkupId(true);
//parentPage.addEditingEnabledBehavior(description);
add(description);

Label typeLabel = new Label(ID_LABEL_TYPE, createStringResource(getTypeLabelKey()));
add(typeLabel);

DropDownChoice type = new DropDownChoice<>(ID_TYPE,
new PropertyModel<>(dtoModel, ExpressionTypeDto.F_TYPE),
DropDownChoice<?> type = new DropDownChoice<>(ID_TYPE,
new PropertyModel<>(dtoModel, ExpressionTypeDto.F_TYPE),
WebComponentUtil.createReadonlyModelFromEnum(ExpressionUtil.ExpressionEvaluatorType.class),
new EnumChoiceRenderer<>(this));
new EnumChoiceRenderer<>(this));
//parentPage.addEditingEnabledBehavior(type);
type.add(new AjaxFormComponentUpdatingBehavior("change") {

Expand All @@ -127,20 +123,20 @@ protected void onUpdate(AjaxRequestTarget target) {
WebMarkupContainer languageContainer = new WebMarkupContainer(ID_LANGUAGE_CONTAINER);
languageContainer.setOutputMarkupId(true);
languageContainer.setOutputMarkupPlaceholderTag(true);
languageContainer.add(new VisibleEnableBehaviour(){
languageContainer.add(new VisibleEnableBehaviour() {

@Override
public boolean isVisible(){
public boolean isVisible() {
return ExpressionUtil.ExpressionEvaluatorType.SCRIPT.equals(dtoModel.getObject().getType());
}
});
//parentPage.addEditingEnabledBehavior(languageContainer);
add(languageContainer);

DropDownChoice language = new DropDownChoice<>(ID_LANGUAGE,
new PropertyModel<>(dtoModel, ExpressionTypeDto.F_LANGUAGE),
DropDownChoice<?> language = new DropDownChoice<>(ID_LANGUAGE,
new PropertyModel<>(dtoModel, ExpressionTypeDto.F_LANGUAGE),
WebComponentUtil.createReadonlyModelFromEnum(ExpressionUtil.Language.class),
new EnumChoiceRenderer<>(this));
new EnumChoiceRenderer<>(this));
//parentPage.addEditingEnabledBehavior(language);
language.add(new AjaxFormComponentUpdatingBehavior("change") {

Expand All @@ -157,25 +153,19 @@ protected void onUpdate(AjaxRequestTarget target) {
WebMarkupContainer policyContainer = new WebMarkupContainer(ID_POLICY_CONTAINER);
policyContainer.setOutputMarkupId(true);
policyContainer.setOutputMarkupPlaceholderTag(true);
policyContainer.add(new VisibleEnableBehaviour(){
policyContainer.add(new VisibleEnableBehaviour() {

@Override
public boolean isVisible(){
public boolean isVisible() {
return ExpressionUtil.ExpressionEvaluatorType.GENERATE.equals(dtoModel.getObject().getType());
}
});
add(policyContainer);

DropDownChoice policyRef = new DropDownChoice<>(ID_POLICY_REF,
new PropertyModel<>(dtoModel, ExpressionTypeDto.F_POLICY_REF),
new IModel<List<ObjectReferenceType>>() {

@Override
public List<ObjectReferenceType> getObject() {
return WebModelServiceUtils.createObjectReferenceList(ValuePolicyType.class, getPageBase(), policyMap);
}
}, new ObjectReferenceChoiceRenderer(policyMap));
//parentPage.addEditingEnabledBehavior(policyRef);
DropDownChoice<?> policyRef = new DropDownChoice<>(ID_POLICY_REF,
new PropertyModel<>(dtoModel, ExpressionTypeDto.F_POLICY_REF),
(IModel<List<ObjectReferenceType>>) () -> WebModelServiceUtils.createObjectReferenceList(
ValuePolicyType.class, getPageBase(), policyMap), new ObjectReferenceChoiceRenderer(policyMap));
policyRef.add(new AjaxFormComponentUpdatingBehavior("change") {

@Override
Expand Down Expand Up @@ -206,8 +196,8 @@ protected void onSubmit(AjaxRequestTarget target) {
updateLabel.setRenderBodyOnly(true);
update.add(updateLabel);
if (parentPage instanceof PageResourceWizard) {
((PageResourceWizard)parentPage).addEditingEnabledBehavior(this);
((PageResourceWizard)parentPage).addEditingVisibleBehavior(update);
((PageResourceWizard) parentPage).addEditingEnabledBehavior(this);
((PageResourceWizard) parentPage).addEditingVisibleBehavior(update);
}
add(update);

Expand All @@ -217,12 +207,12 @@ protected void onSubmit(AjaxRequestTarget target) {
add(WebComponentUtil.createHelp(ID_T_EXPRESSION));
}

protected void updateExpressionPerformed(AjaxRequestTarget target){
protected void updateExpressionPerformed(AjaxRequestTarget target) {
try {
dtoModel.getObject().updateExpression(getPageBase().getPrismContext());

success(getString("ExpressionEditorPanel.message.expressionSuccess"));
} catch (Exception e){
} catch (Exception e) {
LoggingUtils.logUnexpectedException(LOGGER, "Could not create JAXBElement<?> from provided xml expression.", e);
error(getString("ExpressionEditorPanel.message.cantSerialize", e));
}
Expand All @@ -232,25 +222,26 @@ protected void updateExpressionPerformed(AjaxRequestTarget target){
}

/**
* Override this in component with ExpressionEditorPanel to provide additional functionality when expression is updated
* */
public void performExpressionHook(AjaxRequestTarget target){}
* Override this in component with ExpressionEditorPanel to provide additional functionality when expression is updated
*/
public void performExpressionHook(AjaxRequestTarget target) {
}

/**
* Provide key for expression type label
* */
public String getTypeLabelKey(){
* Provide key for expression type label
*/
public String getTypeLabelKey() {
return "ExpressionEditorPanel.label.type";
}

public String getDescriptionLabelKey(){
public String getDescriptionLabelKey() {
return "ExpressionEditorPanel.label.description";
}

/**
* Provide key for expression label
* */
public String getExpressionLabelKey(){
* Provide key for expression label
*/
public String getExpressionLabelKey() {
return "ExpressionEditorPanel.label.expression";
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
/*
* Copyright (c) 2010-2014 Evolveum and contributors
* Copyright (C) 2010-2021 Evolveum and contributors
*
* This work is dual-licensed under the Apache License 2.0
* and European Union Public License. See LICENSE file for details.
*/

package com.evolveum.midpoint.web.component.input.dto;

import java.io.Serializable;
import java.util.Objects;
import javax.xml.bind.JAXBElement;

import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import com.evolveum.midpoint.prism.PrismContext;
import com.evolveum.midpoint.util.exception.SchemaException;
import com.evolveum.midpoint.util.logging.LoggingUtils;
Expand All @@ -15,16 +22,11 @@
import com.evolveum.midpoint.web.util.ExpressionUtil;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ExpressionType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import javax.xml.bind.JAXBElement;
import java.io.Serializable;

/**
* @author shood
* */
public class ExpressionTypeDto implements Serializable{
* @author shood
*/
public class ExpressionTypeDto implements Serializable {

private static final Trace LOGGER = TraceManager.getTrace(ExpressionTypeDto.class);

Expand Down Expand Up @@ -58,7 +60,7 @@ private void loadExpression(PrismContext context) {
} else {
StringBuilder sb = new StringBuilder();

for (JAXBElement<?> element: expressionObject.getExpressionEvaluator()) {
for (JAXBElement<?> element : expressionObject.getExpressionEvaluator()) {
String subElement = context.xmlSerializer().serialize(element);
sb.append(subElement).append("\n");
}
Expand All @@ -82,15 +84,15 @@ public void updateExpression(PrismContext context) throws SchemaException, Illeg
ExpressionUtil.parseExpressionEvaluators(expression, expressionObject, context);
}

public void updateExpressionType(){
public void updateExpressionType() {
expression = ExpressionUtil.getExpressionString(type);
}

public void updateExpressionLanguage(){
public void updateExpressionLanguage() {
expression = ExpressionUtil.getExpressionString(type, language);
}

public void updateExpressionValuePolicyRef(){
public void updateExpressionValuePolicyRef() {
expression = ExpressionUtil.getExpressionString(type, policyRef);
}

Expand Down Expand Up @@ -141,28 +143,23 @@ public void setDescription(String description) {

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof ExpressionTypeDto)) return false;

ExpressionTypeDto that = (ExpressionTypeDto) o;

if (expression != null ? !expression.equals(that.expression) : that.expression != null) return false;
if (!expressionObject.equals(that.expressionObject))
if (this == o) {
return true;
}
if (!(o instanceof ExpressionTypeDto)) {
return false;
if (language != that.language) return false;
if (policyRef != null ? !policyRef.equals(that.policyRef) : that.policyRef != null) return false;
if (type != that.type) return false;
}

return true;
ExpressionTypeDto that = (ExpressionTypeDto) o;
return Objects.equals(expression, that.expression)
&& Objects.equals(expressionObject, that.expressionObject)
&& Objects.equals(language, that.language)
&& Objects.equals(policyRef, that.policyRef)
&& Objects.equals(type, that.type);
}

@Override
public int hashCode() {
int result = type != null ? type.hashCode() : 0;
result = 31 * result + (language != null ? language.hashCode() : 0);
result = 31 * result + (policyRef != null ? policyRef.hashCode() : 0);
result = 31 * result + (expression != null ? expression.hashCode() : 0);
result = 31 * result + expressionObject.hashCode();
return result;
return Objects.hash(expression, expressionObject, language, policyRef, type);
}
}

0 comments on commit ae92473

Please sign in to comment.