Code cleanup

merge-requests/7/head
prabathabey 10 years ago
parent 7dfd3f0dd2
commit d71ea209c2

@ -164,7 +164,6 @@
<groupId>org.apache.axis2.transport</groupId>
<artifactId>axis2-transport-mail</artifactId>
</dependency>
<dependency>
<groupId>org.apache.ws.commons.axiom</groupId>
<artifactId>axiom-api</artifactId>

@ -36,6 +36,7 @@ import org.wso2.carbon.device.mgt.core.dao.DeviceTypeDAO;
import org.wso2.carbon.device.mgt.core.dao.util.DeviceManagementDAOUtil;
import org.wso2.carbon.device.mgt.core.dto.DeviceType;
import org.wso2.carbon.device.mgt.core.dto.Status;
import org.wso2.carbon.device.mgt.core.email.sender.EmailConfig;
import org.wso2.carbon.device.mgt.core.internal.EmailServiceDataHolder;
import org.wso2.carbon.device.mgt.core.license.mgt.LicenseManagerImpl;
import org.wso2.carbon.device.mgt.core.operation.mgt.OperationManagerImpl;
@ -229,14 +230,13 @@ public class DeviceManagementServiceProviderImpl implements DeviceManagementServ
}
@Override
public void sendEnrollInvitation(String title, String userName, String emailAddress, String enrolUrl) throws
DeviceManagementException {
public void sendEnrollInvitation(EmailConfig config) throws DeviceManagementException {
EmailMessageProperties emailMessageProperties = new EmailMessageProperties();
EnrolmentNotifications enrolmentNotifications = DeviceConfigurationManager.getInstance()
.getNotificationMessagesConfig().getEnrolmentNotifications();
emailMessageProperties.setMailTo(new String[] { emailAddress });
emailMessageProperties.setMailTo(new String[] { config.getAddress() });
emailMessageProperties.setSubject(enrolmentNotifications.getSubject());
String messageHeader = enrolmentNotifications.getHeader();
@ -246,28 +246,25 @@ public class DeviceManagementServiceProviderImpl implements DeviceManagementServ
StringBuilder messageBuilder = new StringBuilder();
try {
messageHeader = messageHeader.replaceAll("\\{title\\}",
URLEncoder.encode(title, "UTF-8"));
messageHeader = messageHeader.replaceAll("\\{title\\}", URLEncoder.encode(config.getSubject(), "UTF-8"));
messageHeader = messageHeader.replaceAll("\\{user-name\\}",
URLEncoder.encode(userName, "UTF-8"));
messageHeader =
messageHeader.replaceAll("\\{user-name\\}", URLEncoder.encode(config.getFirstName(), "UTF-8"));
messageBody = messageBody+ System.getProperty("line.separator") + enrolmentNotifications.getUrl()
.replaceAll("\\{downloadUrl\\}", URLEncoder.encode(enrolUrl, "UTF-8"));
messageBody = messageBody + System.getProperty("line.separator") + enrolmentNotifications.getUrl()
.replaceAll("\\{downloadUrl\\}", URLEncoder.encode(config.getEnrollmentUrl(), "UTF-8"));
messageBuilder.append(messageHeader).append(System.getProperty("line.separator"))
.append(System.getProperty("line.separator"));
messageBuilder.append(messageHeader).append(System.getProperty("line.separator")).append(
System.getProperty("line.separator"));
messageBuilder.append(messageBody).append(System.getProperty("line.separator"))
.append(System.getProperty("line.separator")).append(messageFooter);
} catch (IOException ioEx) {
String errorMsg = "Error replacing tags in email template" + title;
log.error(errorMsg, ioEx);
throw new DeviceManagementException(errorMsg, ioEx);
messageBuilder.append(messageBody).append(System.getProperty("line.separator")).append(
System.getProperty("line.separator")).append(messageFooter);
} catch (IOException e) {
throw new DeviceManagementException("Error replacing tags in email template '" +
config.getSubject() + "'", e);
}
emailMessageProperties.setMessageBody(messageBuilder.toString());
EmailServiceDataHolder.getInstance().getEmailServiceProvider().sendEmail(emailMessageProperties);
}
@Override

@ -0,0 +1,67 @@
/*
* Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* WSO2 Inc. licenses this file to you 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 org.wso2.carbon.device.mgt.core.email.sender;
public class EmailConfig {
private String subject;
private String firstName;
private String address;
private String enrollmentUrl;
public EmailConfig(String subject, String firstName, String address, String enrollmentUrl) {
this.subject = subject;
this.firstName = firstName;
this.address = address;
this.enrollmentUrl = enrollmentUrl;
}
public String getSubject() {
return subject;
}
public void setSubject(String subject) {
this.subject = subject;
}
public String getFirstName() {
return firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
public String getEnrollmentUrl() {
return enrollmentUrl;
}
public void setEnrollmentUrl(String enrollmentUrl) {
this.enrollmentUrl = enrollmentUrl;
}
}

@ -16,7 +16,7 @@
* under the License.
*/
package org.wso2.carbon.device.mgt.core;
package org.wso2.carbon.device.mgt.core.email.sender;
import org.apache.axiom.om.OMAbstractFactory;
import org.apache.axiom.om.OMElement;
@ -73,7 +73,6 @@ public class EmailServiceProviderImpl implements EmailService {
}
class EmailSender implements Runnable {
String to;
String subject;
String body;
@ -110,14 +109,7 @@ public class EmailServiceProviderImpl implements EmailService {
serviceClient.fireAndForget(payload);
log.debug("Sending confirmation mail to " + to);
} catch (AxisFault e) {
String msg = "Error in delivering the message, " +
"subject: " + subject + ", to: " + to + ".";
log.error(msg);
} catch (Throwable t) {
String msg = "Error in delivering the message, " +
"subject: " + subject + ", to: " + to + ".";
log.error(msg);
log.error(t);
log.error("Error in delivering the message, subject: '" + subject + "', to: '" + to + "'", e);
}
}
}

@ -22,8 +22,7 @@ import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.osgi.framework.BundleContext;
import org.osgi.service.component.ComponentContext;
import org.wso2.carbon.device.mgt.core.DeviceManagementRepository;
import org.wso2.carbon.device.mgt.core.EmailServiceProviderImpl;
import org.wso2.carbon.device.mgt.core.email.sender.EmailServiceProviderImpl;
import org.wso2.carbon.device.mgt.core.service.EmailService;
import org.wso2.carbon.device.mgt.core.service.EmailServiceImpl;
import org.wso2.carbon.utils.ConfigurationContextService;
@ -60,8 +59,7 @@ public class EmailServiceComponent {
log.debug("Email management core bundle has been successfully initialized");
}
} catch (Throwable e) {
String msg = "Error occurred while initializing device management core bundle";
log.error(msg, e);
log.error("Error occurred while initializing device management core bundle", e);
}
}
protected void setConfigurationContextService(ConfigurationContextService configurationContextService) {
@ -77,7 +75,7 @@ public class EmailServiceComponent {
}
/* Registering Email Service */
BundleContext bundleContext = componentContext.getBundleContext();
bundleContext.registerService(EmailService.class.getName(),
new EmailServiceImpl(), null);
bundleContext.registerService(EmailService.class.getName(), new EmailServiceImpl(), null);
}
}

@ -24,6 +24,7 @@ import org.wso2.carbon.device.mgt.common.FeatureManager;
import org.wso2.carbon.device.mgt.common.spi.DeviceManager;
import org.wso2.carbon.device.mgt.common.license.mgt.LicenseManager;
import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManager;
import org.wso2.carbon.device.mgt.core.email.sender.EmailConfig;
import java.util.List;
@ -39,8 +40,7 @@ public interface DeviceManagementService extends DeviceManager, LicenseManager,
List<Device> getDeviceListOfUser(String username) throws DeviceManagementException;
void sendEnrollInvitation(String title, String firstName, String emailAddress,
String enrolUrl) throws DeviceManagementException;
void sendEnrollInvitation(EmailConfig config) throws DeviceManagementException;
FeatureManager getFeatureManager(String type) throws DeviceManagementException;

@ -25,6 +25,7 @@ import org.wso2.carbon.device.mgt.common.license.mgt.License;
import org.wso2.carbon.device.mgt.common.license.mgt.LicenseManagementException;
import org.wso2.carbon.device.mgt.common.operation.mgt.Operation;
import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManagementException;
import org.wso2.carbon.device.mgt.core.email.sender.EmailConfig;
import org.wso2.carbon.device.mgt.core.internal.DeviceManagementDataHolder;
import java.util.List;
@ -139,9 +140,8 @@ public class DeviceManagementServiceImpl implements DeviceManagementService {
}
@Override
public void sendEnrollInvitation(String title, String userName, String emailAddress, String enrolUrl)
throws DeviceManagementException {
DeviceManagementDataHolder.getInstance().getDeviceManagementProvider()
.sendEnrollInvitation(title, userName, emailAddress, enrolUrl);
public void sendEnrollInvitation(EmailConfig config) throws DeviceManagementException {
DeviceManagementDataHolder.getInstance().getDeviceManagementProvider().sendEnrollInvitation(config);
}
}

Loading…
Cancel
Save