Skip to content

Commit

Permalink
Merge branch 'master' of github.com:Evolveum/midpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
katkav committed May 16, 2014
2 parents 45edf2d + d4f56c7 commit c059c58
Show file tree
Hide file tree
Showing 6 changed files with 265 additions and 26 deletions.
Expand Up @@ -40,6 +40,7 @@
import com.evolveum.midpoint.web.util.WebMiscUtil;
import com.evolveum.midpoint.xml.ns._public.common.common_3.*;

import com.evolveum.prism.xml.ns._public.types_3.ProtectedStringType;
import org.apache.commons.lang.StringUtils;
import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.extensions.markup.html.tabs.AbstractTab;
Expand Down Expand Up @@ -313,6 +314,7 @@ private void savePerformed(AjaxRequestTarget target) {
SystemConfigurationType s = newObject.asObjectable();

s = saveLogging(target, s);
s = saveNotificationConfiguration(s);

if(LOGGER.isTraceEnabled())
LOGGER.trace("Saving logging configuration.");
Expand Down Expand Up @@ -357,6 +359,67 @@ private void savePerformed(AjaxRequestTarget target) {
resetPerformed(target);
}

/*
* TODO - currently, we are saving changes to MailServerConfigType on index 0 in ArrayList. This will
* change when GUI is update to define multiple mailServer or even SMS notifications
* */
private SystemConfigurationType saveNotificationConfiguration(SystemConfigurationType config){
NotificationConfigurationDto dto;
NotificationConfigurationType notificationConfig;
MailConfigurationType mailConfig;
MailServerConfigurationType mailServerConfig;

if(systemConfigPanel.getModel().getObject().getNotificationConfig() != null){
dto = systemConfigPanel.getModel().getObject().getNotificationConfig();

if(config.getNotificationConfiguration() != null){
notificationConfig = config.getNotificationConfiguration();
} else {
notificationConfig = new NotificationConfigurationType();
}

if(notificationConfig.getMail() != null){
mailConfig = notificationConfig.getMail();
} else {
mailConfig = new MailConfigurationType();
}

mailConfig.setDebug(dto.isDebug());
mailConfig.setDefaultFrom(dto.getDefaultFrom());
mailConfig.setRedirectToFile(dto.getRedirectToFile());

if(!mailConfig.getServer().isEmpty() && mailConfig.getServer().get(0) != null){
mailServerConfig = mailConfig.getServer().get(0);
} else {
mailServerConfig = new MailServerConfigurationType();
}

mailServerConfig.setHost(dto.getHost());
mailServerConfig.setPort(dto.getPort());
mailServerConfig.setUsername(dto.getUsername());
mailServerConfig.setTransportSecurity(dto.getMailTransportSecurityType());

ProtectedStringType pass = new ProtectedStringType();
pass.setClearValue(dto.getPassword());
mailServerConfig.setPassword(pass);

if(mailConfig.getServer().isEmpty()){
if(dto.isConfigured())
mailConfig.getServer().add(0, mailServerConfig);
} else {
if(dto.isConfigured())
mailConfig.getServer().set(0, mailServerConfig);
else
mailConfig.getServer().remove(0);
}

notificationConfig.setMail(mailConfig);
config.setNotificationConfiguration(notificationConfig);
}

return config;
}

private SystemConfigurationType saveLogging(AjaxRequestTarget target, SystemConfigurationType config){
LoggingDto loggingDto = null;
LoggingConfigurationType loggingConfig = null;
Expand Down
Expand Up @@ -98,7 +98,7 @@ <h3>
</label>

<div class="col-lg-4">
<input type="text" class="form-control input-sm" placeholder="Default from">
<input type="text" class="form-control input-sm" placeholder="Default from" wicket:id="defaultFrom">
</div>
</div>
<div class="form-group">
Expand All @@ -109,7 +109,7 @@ <h3>
<div class="col-lg-4">
<div class="checkbox">
<label>
<input type="checkbox" name="optionsRadios1">
<input type="checkbox" name="optionsRadios1" wicket:id="debugCheckbox">
</label>
</div>
</div>
Expand All @@ -122,7 +122,7 @@ <h3>
</label>

<div class="col-lg-4">
<input type="text" class="form-control input-sm"
<input type="text" class="form-control input-sm" wicket:id="host"
wicket:message="placeholder:SystemConfigPanel.mail.host">
</div>
</div>
Expand All @@ -132,7 +132,7 @@ <h3>
</label>

<div class="col-lg-2">
<input type="text" class="form-control input-sm"
<input type="text" class="form-control input-sm" wicket:id="port"
wicket:message="placeholder:SystemConfigPanel.mail.port">
</div>
</div>
Expand All @@ -142,7 +142,7 @@ <h3>
</label>

<div class="col-lg-4">
<input type="text" class="form-control input-sm"
<input type="text" class="form-control input-sm" wicket:id="username"
wicket:message="placeholder:SystemConfigPanel.mail.username">
</div>
</div>
Expand All @@ -152,23 +152,12 @@ <h3>
</label>

<div class="col-lg-4">
<input type="password" class="form-control input-sm"
<input type="password" class="form-control input-sm" wicket:id="password"
wicket:message="placeholder:SystemConfigPanel.mail.password">
</div>
</div>
<div class="form-group">
<label class="col-lg-4 control-label">
<wicket:message key="SystemConfigPanel.mail.transportSecurity"/>
</label>

<div class="col-lg-4">
<select class="form-control input-sm">
<option>None</option>
<option>StartTLS</option>
<option>SSL</option>
</select>
</div>
</div>
<div class="form-group" wicket:id="transportSecurity" />

<hr style="margin-right: 20px;"/>

Expand All @@ -178,11 +167,8 @@ <h3>
</label>

<div class="col-lg-4">
<div class="checkbox">
<label>
<input type="checkbox" name="optionsRadios1">
</label>
</div>
<input type="text" class="form-control input-sm" wicket:id="redirectToFile"
wicket:message="placeholder:SystemConfigPanel.notification.redirectToFile.placeholder">
</div>
</div>

Expand Down
Expand Up @@ -18,17 +18,17 @@

import com.evolveum.midpoint.util.logging.Trace;
import com.evolveum.midpoint.util.logging.TraceManager;
import com.evolveum.midpoint.web.component.form.DropDownFormGroup;
import com.evolveum.midpoint.web.component.util.SimplePanel;
import com.evolveum.midpoint.web.page.admin.configuration.dto.AEPlevel;
import com.evolveum.midpoint.web.page.admin.configuration.dto.SystemConfigurationDto;
import com.evolveum.midpoint.web.page.admin.dto.ObjectViewDto;
import com.evolveum.midpoint.web.util.InfoTooltipBehavior;
import com.evolveum.midpoint.web.util.WebMiscUtil;
import com.evolveum.midpoint.xml.ns._public.common.common_3.MailTransportSecurityType;
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.TextField;
import org.apache.wicket.markup.html.form.*;
import org.apache.wicket.model.IModel;
import org.apache.wicket.model.PropertyModel;

Expand All @@ -47,6 +47,18 @@ public class SystemConfigPanel extends SimplePanel<SystemConfigurationDto> {
private static final String ID_CLEANUP_AUDIT_RECORDS_TOOLTIP = "auditRecordsCleanupTooltip";
private static final String ID_CLEANUP_CLOSED_TASKS_TOOLTIP = "closedTasksCleanupTooltip";

private static final String ID_DEFAULT_FROM = "defaultFrom";
private static final String ID_DEBUG = "debugCheckbox";
private static final String ID_HOST = "host";
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 static final String ID_REDIRECT_TO_FILE = "redirectToFile";

private static final String ID_LABEL_SIZE = "col-lg-4";
private static final String ID_INPUT_SIZE = "col-lg-4";

private ChooseTypePanel passPolicyChoosePanel;
private ChooseTypePanel userTemplateChoosePanel;

Expand Down Expand Up @@ -81,6 +93,30 @@ protected void initLayout(){

createTooltip(ID_CLEANUP_AUDIT_RECORDS_TOOLTIP, this);
createTooltip(ID_CLEANUP_CLOSED_TASKS_TOOLTIP, this);

TextField<String> defaultFromField = new TextField<String>(ID_DEFAULT_FROM, new PropertyModel<String>(getModel(), "notificationConfig.defaultFrom"));
CheckBox debugCheck = new CheckBox(ID_DEBUG, new PropertyModel<Boolean>(getModel(), "notificationConfig.debug"));
TextField<String> hostField = new TextField<String>(ID_HOST, new PropertyModel<String>(getModel(), "notificationConfig.host"));
TextField<Integer> portField = new TextField<Integer>(ID_PORT, new PropertyModel<Integer>(getModel(), "notificationConfig.port"));
TextField<String> userNameField = new TextField<String>(ID_USERNAME, new PropertyModel<String>(getModel(), "notificationConfig.username"));
PasswordTextField passwordField = new PasswordTextField(ID_PASSWORD, new PropertyModel<String>(getModel(), "notificationConfig.password"));
passwordField.setRequired(false);
TextField<String> redirectToFileField = new TextField<String>(ID_REDIRECT_TO_FILE, new PropertyModel<String>(getModel(), "notificationConfig.redirectToFile"));

IModel choices = WebMiscUtil.createReadonlyModelFromEnum(MailTransportSecurityType.class);
IChoiceRenderer renderer = new EnumChoiceRenderer();
DropDownFormGroup transportSecurity = new DropDownFormGroup(ID_TRANSPORT_SECURITY, new PropertyModel(getModel(),
"notificationConfig.mailTransportSecurityType"), choices, renderer,
createStringResource("SystemConfigPanel.mail.transportSecurity"),ID_LABEL_SIZE, ID_INPUT_SIZE, false);

add(defaultFromField);
add(debugCheck);
add(hostField);
add(portField);
add(userNameField);
add(passwordField);
add(redirectToFileField);
add(transportSecurity);
}

private void createTooltip(String id, WebMarkupContainer parent) {
Expand Down
Expand Up @@ -33,4 +33,5 @@ SystemConfigPanel.mail.username=Username
SystemConfigPanel.mail.password=Password
SystemConfigPanel.mail.transportSecurity=Transport security
SystemConfigPanel.notification.redirectToFile=Redirect to file
SystemConfigPanel.notification.redirectToFile.placeholder=Filename
SystemConfigPanel.tooltip.duration=Format: P[n][p], n-number, p-period (d - days, m - months, ...), P3M - cleanup every 3 months
@@ -0,0 +1,138 @@
/*
* Copyright (c) 2010-2013 Evolveum
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.evolveum.midpoint.web.page.admin.configuration.dto;

import com.evolveum.midpoint.web.util.WebMiscUtil;
import com.evolveum.midpoint.xml.ns._public.common.common_3.MailConfigurationType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.MailServerConfigurationType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.MailTransportSecurityType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.NotificationConfigurationType;
import com.evolveum.prism.xml.ns._public.types_3.ProtectedStringType;

import java.io.Serializable;

/**
* @author shood
*
* TODO - contains only fields for e-mail configuration
* */
public class NotificationConfigurationDto implements Serializable{

private String defaultFrom;
private boolean debug;
private String redirectToFile;
private String host;
private Integer port;
private String username;
private String password;
private MailTransportSecurityType mailTransportSecurityType;

public NotificationConfigurationDto(){}

public NotificationConfigurationDto(NotificationConfigurationType config){

if(config.getMail() != null){
MailConfigurationType mailConfig = config.getMail();

defaultFrom = mailConfig.getDefaultFrom();
debug = mailConfig.isDebug();
redirectToFile = mailConfig.getRedirectToFile();

if(!mailConfig.getServer().isEmpty() && mailConfig.getServer().get(0) != null){
MailServerConfigurationType serverConfig = mailConfig.getServer().get(0);

host = serverConfig.getHost();
port = serverConfig.getPort();
username = serverConfig.getUsername();
password = serverConfig.getPassword().getClearValue();
mailTransportSecurityType = serverConfig.getTransportSecurity();
}
}
}

public boolean isConfigured(){
if(defaultFrom == null && redirectToFile == null && host == null
&& port == null && username == null && password == null && mailTransportSecurityType == null){
return false;
}

return true;
}

public String getDefaultFrom() {
return defaultFrom;
}

public void setDefaultFrom(String defaultFrom) {
this.defaultFrom = defaultFrom;
}

public boolean isDebug() {
return debug;
}

public void setDebug(boolean debug) {
this.debug = debug;
}

public String getRedirectToFile() {
return redirectToFile;
}

public void setRedirectToFile(String redirectToFile) {
this.redirectToFile = redirectToFile;
}

public String getHost() {
return host;
}

public void setHost(String host) {
this.host = host;
}

public Integer getPort() {
return port;
}

public void setPort(Integer port) {
this.port = port;
}

public String getUsername() {
return username;
}

public void setUsername(String username) {
this.username = username;
}

public String getPassword() {
return password;
}

public void setPassword(String password) {
this.password = password;
}

public MailTransportSecurityType getMailTransportSecurityType() {
return mailTransportSecurityType;
}

public void setMailTransportSecurityType(MailTransportSecurityType mailTransportSecurityType) {
this.mailTransportSecurityType = mailTransportSecurityType;
}
}

0 comments on commit c059c58

Please sign in to comment.