Skip to content

Commit

Permalink
MID-7815 mail/sms transport missing fields panels, wip
Browse files Browse the repository at this point in the history
  • Loading branch information
1azyman committed Sep 16, 2022
1 parent ed574d3 commit d2ccf38
Show file tree
Hide file tree
Showing 5 changed files with 115 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public class PrismPropertyWrapperColumnPanel<T> extends AbstractItemWrapperColum
private static final long serialVersionUID = 1L;
private static final Trace LOGGER = TraceManager.getTrace(PrismPropertyWrapperColumnPanel.class);

PrismPropertyWrapperColumnPanel(String id, IModel<PrismPropertyWrapper<T>> model, ColumnType columnType) {
public PrismPropertyWrapperColumnPanel(String id, IModel<PrismPropertyWrapper<T>> model, ColumnType columnType) {
super(id, model, columnType);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@
<div class="col-xl-2 col-md-4 col-xs-12 prism-property-label"><wicket:message key="MailServerPanel.password"/></div>
<div class="prism-property-value col-xl-10 col-md-8 col-xs-12" wicket:id="password"/>
</div>
<div class="row no-gutters mb-3">
<div class="col-xl-2 col-md-4 col-xs-12 prism-property-label"><wicket:message key="MailServerPanel.transportSecurity"/></div>
<div class="prism-property-value col-xl-10 col-md-8 col-xs-12" wicket:id="transportSecurity"/>
</div>
</wicket:panel>
</body>
</html>
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,23 @@

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

import java.io.Serializable;
import java.util.Arrays;

import org.apache.wicket.markup.html.form.FormComponent;
import org.apache.wicket.model.IModel;
import org.apache.wicket.model.PropertyModel;
import org.apache.wicket.validation.validator.RangeValidator;

import com.evolveum.midpoint.gui.api.component.password.PasswordPanel;
import com.evolveum.midpoint.gui.api.model.LoadableModel;
import com.evolveum.midpoint.gui.api.util.WebComponentUtil;
import com.evolveum.midpoint.web.component.input.DropDownChoicePanel;
import com.evolveum.midpoint.web.component.input.TextPanel;
import com.evolveum.midpoint.web.component.prism.InputPanel;
import com.evolveum.midpoint.web.component.util.SerializableBiConsumer;
import com.evolveum.midpoint.web.component.util.SerializableFunction;
import com.evolveum.midpoint.web.page.admin.configuration.component.EmptyOnChangeAjaxFormUpdatingBehavior;
import com.evolveum.midpoint.xml.ns._public.common.common_3.MailServerConfigurationType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.MailTransportSecurityType;

/**
* Created by Viliam Repan (lazyman).
Expand All @@ -28,25 +36,14 @@ public class MailServerPanel extends InputPanel {
private static final String ID_PORT = "port";
private static final String ID_USERNAME = "username";
private static final String ID_PASSWORD = "password";
private static final String ID_TRANSPORT_SECURITY = "transportSecurity";

private IModel<MailServerConfigurationType> model;

public MailServerPanel(String id, IModel<MailServerConfigurationType> model) {
super(id);

this.model = new LoadableModel<>() {

@Override
protected MailServerConfigurationType load() {
if (model == null) {
return new MailServerConfigurationType();
}

MailServerConfigurationType config = model.getObject();

return config != null ? config : new MailServerConfigurationType();
}
};
this.model = model;

initLayout();
}
Expand All @@ -56,10 +53,71 @@ public IModel<MailServerConfigurationType> getModel() {
}

private void initLayout() {
add(new TextPanel<>(ID_HOST, new PropertyModel<>(model, MailServerConfigurationType.F_HOST.getLocalPart())));
add(new TextPanel<>(ID_PORT, new PropertyModel<>(model, MailServerConfigurationType.F_PORT.getLocalPart())));
add(new TextPanel<>(ID_USERNAME, new PropertyModel<>(model, MailServerConfigurationType.F_USERNAME.getLocalPart())));
add(new PasswordPanel(ID_PASSWORD, new PropertyModel<>(model, MailServerConfigurationType.F_PASSWORD.getLocalPart())));
add(new TextPanel<>(ID_HOST, createEmbeddedModel(c -> c.getHost(), (c, o) -> c.setHost(o))));

TextPanel port = new TextPanel<>(ID_PORT, createEmbeddedModel(c -> c.getPort(), (c, o) -> c.setPort(o)));
FormComponent portFC = port.getBaseFormComponent();
portFC.setType(Integer.class);
portFC.add(new RangeValidator(0, 2 ^ 16 - 1)); // 65535

port.getBaseFormComponent().add(new EmptyOnChangeAjaxFormUpdatingBehavior());
add(port);

TextPanel username = new TextPanel<>(ID_USERNAME, createEmbeddedModel(c -> c.getUsername(), (c, o) -> c.setUsername(o)));
username.getBaseFormComponent().add(new EmptyOnChangeAjaxFormUpdatingBehavior());
add(username);

add(new PasswordPanel(ID_PASSWORD, createEmbeddedModel(c -> c.getPassword(), (c, o) -> c.setPassword(o))));

DropDownChoicePanel transportSecurity = WebComponentUtil.createEnumPanel(MailTransportSecurityType.class, ID_TRANSPORT_SECURITY,
createEmbeddedModel(c -> c.getTransportSecurity(), (c, o) -> c.setTransportSecurity(o)), this);
transportSecurity.getBaseFormComponent().add(new EmptyOnChangeAjaxFormUpdatingBehavior());
add(transportSecurity);
}

private <T extends Serializable> IModel<T> createEmbeddedModel(SerializableFunction<MailServerConfigurationType, T> get, SerializableBiConsumer<MailServerConfigurationType, T> set) {
return new IModel<T>() {
@Override
public T getObject() {
MailServerConfigurationType config = model.getObject();
if (config == null) {
return null;
}

return get.apply(config);
}

@Override
public void setObject(T object) {
MailServerConfigurationType config = model.getObject();

if (object == null && config == null) {
return;
}

if (config == null) {
config = new MailServerConfigurationType();
model.setObject(config);
}

set.accept(config, object);

if (isParentModelObjectEmpty(config)) {
model.setObject(null);
}
}

private boolean isParentModelObjectEmpty(MailServerConfigurationType config) {
Object[] values = new Object[] {
config.getHost(),
config.getPassword(),
config.getUsername(),
config.getPassword()
};

return Arrays.stream(values).allMatch(v -> v == null);
}
};
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,30 @@
import java.util.ArrayList;
import java.util.List;

import org.apache.commons.lang3.StringUtils;
import org.apache.wicket.Component;
import org.apache.wicket.extensions.markup.html.repeater.data.table.IColumn;
import org.apache.wicket.markup.html.list.ListItem;
import org.apache.wicket.model.IModel;

import com.evolveum.midpoint.gui.api.GuiStyleConstants;
import com.evolveum.midpoint.gui.api.prism.wrapper.ItemWrapper;
import com.evolveum.midpoint.gui.api.prism.wrapper.PrismContainerValueWrapper;
import com.evolveum.midpoint.gui.api.prism.wrapper.PrismPropertyWrapper;
import com.evolveum.midpoint.gui.impl.component.MultivalueContainerDetailsPanel;
import com.evolveum.midpoint.gui.impl.component.MultivalueContainerListPanelWithDetailsPanel;
import com.evolveum.midpoint.gui.impl.component.data.column.AbstractItemWrapperColumn;
import com.evolveum.midpoint.gui.impl.component.data.column.PrismPropertyWrapperColumn;
import com.evolveum.midpoint.gui.impl.component.data.column.PrismPropertyWrapperColumnPanel;
import com.evolveum.midpoint.gui.impl.page.admin.assignmentholder.AssignmentHolderDetailsModel;
import com.evolveum.midpoint.gui.impl.prism.wrapper.PrismPropertyValueWrapper;
import com.evolveum.midpoint.web.application.Counter;
import com.evolveum.midpoint.web.application.PanelDisplay;
import com.evolveum.midpoint.web.application.PanelInstance;
import com.evolveum.midpoint.web.application.PanelType;
import com.evolveum.midpoint.web.session.UserProfileStorage;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ContainerPanelConfigurationType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.MailServerConfigurationType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.MailTransportConfigurationType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.MessageTransportConfigurationType;

Expand Down Expand Up @@ -54,7 +62,28 @@ protected List<IColumn<PrismContainerValueWrapper<MailTransportConfigurationType
List<IColumn<PrismContainerValueWrapper<MailTransportConfigurationType>, String>> columns = new ArrayList<>();
columns.addAll(super.createDefaultColumns());
columns.add(new PrismPropertyWrapperColumn<>(getContainerModel(), MailTransportConfigurationType.F_SERVER,
AbstractItemWrapperColumn.ColumnType.STRING, getPageBase()));
AbstractItemWrapperColumn.ColumnType.STRING, getPageBase()) {
@Override
protected <IW extends ItemWrapper> Component createColumnPanel(String componentId, IModel<IW> rowModel) {
return new PrismPropertyWrapperColumnPanel<>(componentId,
(IModel<PrismPropertyWrapper<MailServerConfigurationType>>) rowModel, getColumnType()) {

@Override
protected String createLabel(PrismPropertyValueWrapper<MailServerConfigurationType> object) {
MailServerConfigurationType server = object.getRealValue();
if (server == null) {
return null;
}

if (StringUtils.isEmpty(server.getHost()) && server.getPort() == null) {
return null;
}

return StringUtils.joinWith(":", server.getHost(), server.getPort());
}
};
}
});
columns.add(new PrismPropertyWrapperColumn<>(getContainerModel(), MailTransportConfigurationType.F_DEFAULT_FROM,
AbstractItemWrapperColumn.ColumnType.STRING, getPageBase()));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,9 @@
Configuration of a particular mail server host. If there are more of them, they are tried
one after another. If there is none, mail notifications are not sent.
</xsd:documentation>
<xsd:appinfo>
<a:displayName>MailConfigurationType.server</a:displayName>
</xsd:appinfo>
</xsd:annotation>
</xsd:element>
<xsd:element name="defaultFrom" type="xsd:string" minOccurs="0">
Expand Down

0 comments on commit d2ccf38

Please sign in to comment.