mirror of
https://repository.entgra.net/community/device-mgt-core.git
synced 2025-10-06 02:01:45 +00:00
Code cleanup
This commit is contained in:
parent
7dfd3f0dd2
commit
d71ea209c2
@ -164,7 +164,6 @@
|
|||||||
<groupId>org.apache.axis2.transport</groupId>
|
<groupId>org.apache.axis2.transport</groupId>
|
||||||
<artifactId>axis2-transport-mail</artifactId>
|
<artifactId>axis2-transport-mail</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.apache.ws.commons.axiom</groupId>
|
<groupId>org.apache.ws.commons.axiom</groupId>
|
||||||
<artifactId>axiom-api</artifactId>
|
<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.dao.util.DeviceManagementDAOUtil;
|
||||||
import org.wso2.carbon.device.mgt.core.dto.DeviceType;
|
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.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.internal.EmailServiceDataHolder;
|
||||||
import org.wso2.carbon.device.mgt.core.license.mgt.LicenseManagerImpl;
|
import org.wso2.carbon.device.mgt.core.license.mgt.LicenseManagerImpl;
|
||||||
import org.wso2.carbon.device.mgt.core.operation.mgt.OperationManagerImpl;
|
import org.wso2.carbon.device.mgt.core.operation.mgt.OperationManagerImpl;
|
||||||
@ -229,14 +230,13 @@ public class DeviceManagementServiceProviderImpl implements DeviceManagementServ
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void sendEnrollInvitation(String title, String userName, String emailAddress, String enrolUrl) throws
|
public void sendEnrollInvitation(EmailConfig config) throws DeviceManagementException {
|
||||||
DeviceManagementException {
|
|
||||||
|
|
||||||
EmailMessageProperties emailMessageProperties = new EmailMessageProperties();
|
EmailMessageProperties emailMessageProperties = new EmailMessageProperties();
|
||||||
EnrolmentNotifications enrolmentNotifications = DeviceConfigurationManager.getInstance()
|
EnrolmentNotifications enrolmentNotifications = DeviceConfigurationManager.getInstance()
|
||||||
.getNotificationMessagesConfig().getEnrolmentNotifications();
|
.getNotificationMessagesConfig().getEnrolmentNotifications();
|
||||||
|
|
||||||
emailMessageProperties.setMailTo(new String[] { emailAddress });
|
emailMessageProperties.setMailTo(new String[] { config.getAddress() });
|
||||||
emailMessageProperties.setSubject(enrolmentNotifications.getSubject());
|
emailMessageProperties.setSubject(enrolmentNotifications.getSubject());
|
||||||
|
|
||||||
String messageHeader = enrolmentNotifications.getHeader();
|
String messageHeader = enrolmentNotifications.getHeader();
|
||||||
@ -246,28 +246,25 @@ public class DeviceManagementServiceProviderImpl implements DeviceManagementServ
|
|||||||
StringBuilder messageBuilder = new StringBuilder();
|
StringBuilder messageBuilder = new StringBuilder();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
messageHeader = messageHeader.replaceAll("\\{title\\}",
|
messageHeader = messageHeader.replaceAll("\\{title\\}", URLEncoder.encode(config.getSubject(), "UTF-8"));
|
||||||
URLEncoder.encode(title, "UTF-8"));
|
|
||||||
|
|
||||||
messageHeader = messageHeader.replaceAll("\\{user-name\\}",
|
messageHeader =
|
||||||
URLEncoder.encode(userName, "UTF-8"));
|
messageHeader.replaceAll("\\{user-name\\}", URLEncoder.encode(config.getFirstName(), "UTF-8"));
|
||||||
|
|
||||||
messageBody = messageBody+ System.getProperty("line.separator") + enrolmentNotifications.getUrl()
|
messageBody = messageBody + System.getProperty("line.separator") + enrolmentNotifications.getUrl()
|
||||||
.replaceAll("\\{downloadUrl\\}", URLEncoder.encode(enrolUrl, "UTF-8"));
|
.replaceAll("\\{downloadUrl\\}", URLEncoder.encode(config.getEnrollmentUrl(), "UTF-8"));
|
||||||
|
|
||||||
messageBuilder.append(messageHeader).append(System.getProperty("line.separator"))
|
messageBuilder.append(messageHeader).append(System.getProperty("line.separator")).append(
|
||||||
.append(System.getProperty("line.separator"));
|
System.getProperty("line.separator"));
|
||||||
|
|
||||||
messageBuilder.append(messageBody).append(System.getProperty("line.separator"))
|
messageBuilder.append(messageBody).append(System.getProperty("line.separator")).append(
|
||||||
.append(System.getProperty("line.separator")).append(messageFooter);
|
System.getProperty("line.separator")).append(messageFooter);
|
||||||
} catch (IOException ioEx) {
|
} catch (IOException e) {
|
||||||
String errorMsg = "Error replacing tags in email template" + title;
|
throw new DeviceManagementException("Error replacing tags in email template '" +
|
||||||
log.error(errorMsg, ioEx);
|
config.getSubject() + "'", e);
|
||||||
throw new DeviceManagementException(errorMsg, ioEx);
|
|
||||||
}
|
}
|
||||||
emailMessageProperties.setMessageBody(messageBuilder.toString());
|
emailMessageProperties.setMessageBody(messageBuilder.toString());
|
||||||
EmailServiceDataHolder.getInstance().getEmailServiceProvider().sendEmail(emailMessageProperties);
|
EmailServiceDataHolder.getInstance().getEmailServiceProvider().sendEmail(emailMessageProperties);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@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.
|
* 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.OMAbstractFactory;
|
||||||
import org.apache.axiom.om.OMElement;
|
import org.apache.axiom.om.OMElement;
|
||||||
@ -73,7 +73,6 @@ public class EmailServiceProviderImpl implements EmailService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class EmailSender implements Runnable {
|
class EmailSender implements Runnable {
|
||||||
|
|
||||||
String to;
|
String to;
|
||||||
String subject;
|
String subject;
|
||||||
String body;
|
String body;
|
||||||
@ -110,14 +109,7 @@ public class EmailServiceProviderImpl implements EmailService {
|
|||||||
serviceClient.fireAndForget(payload);
|
serviceClient.fireAndForget(payload);
|
||||||
log.debug("Sending confirmation mail to " + to);
|
log.debug("Sending confirmation mail to " + to);
|
||||||
} catch (AxisFault e) {
|
} catch (AxisFault e) {
|
||||||
String msg = "Error in delivering the message, " +
|
log.error("Error in delivering the message, subject: '" + subject + "', to: '" + to + "'", e);
|
||||||
"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);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -22,8 +22,7 @@ import org.apache.commons.logging.Log;
|
|||||||
import org.apache.commons.logging.LogFactory;
|
import org.apache.commons.logging.LogFactory;
|
||||||
import org.osgi.framework.BundleContext;
|
import org.osgi.framework.BundleContext;
|
||||||
import org.osgi.service.component.ComponentContext;
|
import org.osgi.service.component.ComponentContext;
|
||||||
import org.wso2.carbon.device.mgt.core.DeviceManagementRepository;
|
import org.wso2.carbon.device.mgt.core.email.sender.EmailServiceProviderImpl;
|
||||||
import org.wso2.carbon.device.mgt.core.EmailServiceProviderImpl;
|
|
||||||
import org.wso2.carbon.device.mgt.core.service.EmailService;
|
import org.wso2.carbon.device.mgt.core.service.EmailService;
|
||||||
import org.wso2.carbon.device.mgt.core.service.EmailServiceImpl;
|
import org.wso2.carbon.device.mgt.core.service.EmailServiceImpl;
|
||||||
import org.wso2.carbon.utils.ConfigurationContextService;
|
import org.wso2.carbon.utils.ConfigurationContextService;
|
||||||
@ -60,8 +59,7 @@ public class EmailServiceComponent {
|
|||||||
log.debug("Email management core bundle has been successfully initialized");
|
log.debug("Email management core bundle has been successfully initialized");
|
||||||
}
|
}
|
||||||
} catch (Throwable e) {
|
} catch (Throwable e) {
|
||||||
String msg = "Error occurred while initializing device management core bundle";
|
log.error("Error occurred while initializing device management core bundle", e);
|
||||||
log.error(msg, e);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
protected void setConfigurationContextService(ConfigurationContextService configurationContextService) {
|
protected void setConfigurationContextService(ConfigurationContextService configurationContextService) {
|
||||||
@ -77,7 +75,7 @@ public class EmailServiceComponent {
|
|||||||
}
|
}
|
||||||
/* Registering Email Service */
|
/* Registering Email Service */
|
||||||
BundleContext bundleContext = componentContext.getBundleContext();
|
BundleContext bundleContext = componentContext.getBundleContext();
|
||||||
bundleContext.registerService(EmailService.class.getName(),
|
bundleContext.registerService(EmailService.class.getName(), new EmailServiceImpl(), null);
|
||||||
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.spi.DeviceManager;
|
||||||
import org.wso2.carbon.device.mgt.common.license.mgt.LicenseManager;
|
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.common.operation.mgt.OperationManager;
|
||||||
|
import org.wso2.carbon.device.mgt.core.email.sender.EmailConfig;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@ -39,8 +40,7 @@ public interface DeviceManagementService extends DeviceManager, LicenseManager,
|
|||||||
|
|
||||||
List<Device> getDeviceListOfUser(String username) throws DeviceManagementException;
|
List<Device> getDeviceListOfUser(String username) throws DeviceManagementException;
|
||||||
|
|
||||||
void sendEnrollInvitation(String title, String firstName, String emailAddress,
|
void sendEnrollInvitation(EmailConfig config) throws DeviceManagementException;
|
||||||
String enrolUrl) throws DeviceManagementException;
|
|
||||||
|
|
||||||
FeatureManager getFeatureManager(String type) 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.license.mgt.LicenseManagementException;
|
||||||
import org.wso2.carbon.device.mgt.common.operation.mgt.Operation;
|
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.common.operation.mgt.OperationManagementException;
|
||||||
|
import org.wso2.carbon.device.mgt.core.email.sender.EmailConfig;
|
||||||
import org.wso2.carbon.device.mgt.core.internal.DeviceManagementDataHolder;
|
import org.wso2.carbon.device.mgt.core.internal.DeviceManagementDataHolder;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -139,9 +140,8 @@ public class DeviceManagementServiceImpl implements DeviceManagementService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void sendEnrollInvitation(String title, String userName, String emailAddress, String enrolUrl)
|
public void sendEnrollInvitation(EmailConfig config) throws DeviceManagementException {
|
||||||
throws DeviceManagementException {
|
DeviceManagementDataHolder.getInstance().getDeviceManagementProvider().sendEnrollInvitation(config);
|
||||||
DeviceManagementDataHolder.getInstance().getDeviceManagementProvider()
|
|
||||||
.sendEnrollInvitation(title, userName, emailAddress, enrolUrl);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user