forked from community/device-mgt-core
commit
41191d6df0
@ -1,137 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2014, 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.common;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
public class EmailMessageProperties {
|
||||
|
||||
private String messageBody;
|
||||
private String[] mailTo;
|
||||
private String[] ccList;
|
||||
private String[] bccList;
|
||||
private String subject;
|
||||
private String firstName;
|
||||
private String enrolmentUrl;
|
||||
private String title;
|
||||
private String password;
|
||||
private String userName;
|
||||
private String domainName;
|
||||
|
||||
public String getUserName() {
|
||||
return userName;
|
||||
}
|
||||
|
||||
public void setUserName(String userName) {
|
||||
this.userName = userName;
|
||||
}
|
||||
|
||||
public String getDomainName() {
|
||||
return domainName;
|
||||
}
|
||||
|
||||
public void setDomainName(String domainName) {
|
||||
this.domainName = domainName;
|
||||
}
|
||||
|
||||
public String getMessageBody() {
|
||||
return messageBody;
|
||||
}
|
||||
|
||||
public void setMessageBody(String messageBody) {
|
||||
this.messageBody = messageBody;
|
||||
}
|
||||
|
||||
public String[] getMailTo() {
|
||||
return mailTo;
|
||||
}
|
||||
|
||||
public void setMailTo(String[] mailTo) {
|
||||
this.mailTo = mailTo;
|
||||
}
|
||||
|
||||
public String[] getCcList() {
|
||||
return ccList;
|
||||
}
|
||||
|
||||
public void setCcList(String[] ccList) {
|
||||
this.ccList = ccList;
|
||||
}
|
||||
|
||||
public String[] getBccList() {
|
||||
return bccList;
|
||||
}
|
||||
|
||||
public void setBccList(String[] bccList) {
|
||||
this.bccList = bccList;
|
||||
}
|
||||
|
||||
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 getEnrolmentUrl() {
|
||||
return enrolmentUrl;
|
||||
}
|
||||
|
||||
public void setEnrolmentUrl(String enrolmentUrl) {
|
||||
this.enrolmentUrl = enrolmentUrl;
|
||||
}
|
||||
|
||||
public String getTitle() {
|
||||
return title;
|
||||
}
|
||||
|
||||
public void setTitle(String title) {
|
||||
this.title = title;
|
||||
}
|
||||
|
||||
public String getPassword() {
|
||||
return password;
|
||||
}
|
||||
|
||||
public void setPassword(String password) {
|
||||
this.password = password;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "EmailMessageProperties{" +
|
||||
"messageBody='" + messageBody + '\'' +
|
||||
", mailTo=" + Arrays.toString(mailTo) +
|
||||
", ccList=" + Arrays.toString(ccList) +
|
||||
", bccList=" + Arrays.toString(bccList) +
|
||||
", subject='" + subject + '\'' +
|
||||
", firstName='" + firstName + '\'' +
|
||||
", enrolmentUrl='" + enrolmentUrl + '\'' +
|
||||
", title='" + title + '\'' +
|
||||
'}';
|
||||
}
|
||||
}
|
@ -0,0 +1,233 @@
|
||||
/*
|
||||
* Copyright (c) 2016, 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.common.device.details;
|
||||
|
||||
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class DeviceInfo implements Serializable{
|
||||
|
||||
private static final long serialVersionUID = 1998101733L;
|
||||
|
||||
private int deviceId;
|
||||
private String deviceType;
|
||||
private DeviceIdentifier deviceIdentifier;
|
||||
|
||||
private String IMEI;
|
||||
private String IMSI;
|
||||
private String deviceModel;
|
||||
private String vendor;
|
||||
private String osVersion;
|
||||
private Double batteryLevel;
|
||||
private Double internalTotalMemory;
|
||||
private Double internalAvailableMemory;
|
||||
private Double externalTotalMemory;
|
||||
private Double externalAvailableMemory;
|
||||
private String operator;
|
||||
private String connectionType;
|
||||
private Double mobileSignalStrength;
|
||||
private String ssid;
|
||||
private Double cpuUsage;
|
||||
private Double totalRAMMemory;
|
||||
private Double availableRAMMemory;
|
||||
private boolean pluggedIn;
|
||||
|
||||
private Map<String, String> deviceDetailsMap = new HashMap<>();
|
||||
|
||||
public int getDeviceId() {
|
||||
return deviceId;
|
||||
}
|
||||
|
||||
public void setDeviceId(int deviceId) {
|
||||
this.deviceId = deviceId;
|
||||
}
|
||||
|
||||
public String getDeviceType() {
|
||||
return deviceType;
|
||||
}
|
||||
|
||||
public void setDeviceType(String deviceType) {
|
||||
this.deviceType = deviceType;
|
||||
}
|
||||
|
||||
public DeviceIdentifier getDeviceIdentifier() {
|
||||
return deviceIdentifier;
|
||||
}
|
||||
|
||||
public void setDeviceIdentifier(DeviceIdentifier deviceIdentifier) {
|
||||
this.deviceIdentifier = deviceIdentifier;
|
||||
}
|
||||
|
||||
public String getIMEI() {
|
||||
return IMEI;
|
||||
}
|
||||
|
||||
public void setIMEI(String IMEI) {
|
||||
this.IMEI = IMEI;
|
||||
}
|
||||
|
||||
public String getIMSI() {
|
||||
return IMSI;
|
||||
}
|
||||
|
||||
public void setIMSI(String IMSI) {
|
||||
this.IMSI = IMSI;
|
||||
}
|
||||
|
||||
public String getDeviceModel() {
|
||||
return deviceModel;
|
||||
}
|
||||
|
||||
public void setDeviceModel(String deviceModel) {
|
||||
this.deviceModel = deviceModel;
|
||||
}
|
||||
|
||||
public String getVendor() {
|
||||
return vendor;
|
||||
}
|
||||
|
||||
public void setVendor(String vendor) {
|
||||
this.vendor = vendor;
|
||||
}
|
||||
|
||||
public String getOsVersion() {
|
||||
return osVersion;
|
||||
}
|
||||
|
||||
public void setOsVersion(String osVersion) {
|
||||
this.osVersion = osVersion;
|
||||
}
|
||||
|
||||
public Double getBatteryLevel() {
|
||||
return batteryLevel;
|
||||
}
|
||||
|
||||
public void setBatteryLevel(Double batteryLevel) {
|
||||
this.batteryLevel = batteryLevel;
|
||||
}
|
||||
|
||||
public Double getInternalTotalMemory() {
|
||||
return internalTotalMemory;
|
||||
}
|
||||
|
||||
public void setInternalTotalMemory(Double internalTotalMemory) {
|
||||
this.internalTotalMemory = internalTotalMemory;
|
||||
}
|
||||
|
||||
public Double getInternalAvailableMemory() {
|
||||
return internalAvailableMemory;
|
||||
}
|
||||
|
||||
public void setInternalAvailableMemory(Double internalAvailableMemory) {
|
||||
this.internalAvailableMemory = internalAvailableMemory;
|
||||
}
|
||||
|
||||
public Double getExternalTotalMemory() {
|
||||
return externalTotalMemory;
|
||||
}
|
||||
|
||||
public void setExternalTotalMemory(Double externalTotalMemory) {
|
||||
this.externalTotalMemory = externalTotalMemory;
|
||||
}
|
||||
|
||||
public Double getExternalAvailableMemory() {
|
||||
return externalAvailableMemory;
|
||||
}
|
||||
|
||||
public void setExternalAvailableMemory(Double externalAvailableMemory) {
|
||||
this.externalAvailableMemory = externalAvailableMemory;
|
||||
}
|
||||
|
||||
public String getOperator() {
|
||||
return operator;
|
||||
}
|
||||
|
||||
public void setOperator(String operator) {
|
||||
this.operator = operator;
|
||||
}
|
||||
|
||||
public String getConnectionType() {
|
||||
return connectionType;
|
||||
}
|
||||
|
||||
public void setConnectionType(String connectionType) {
|
||||
this.connectionType = connectionType;
|
||||
}
|
||||
|
||||
public Double getMobileSignalStrength() {
|
||||
return mobileSignalStrength;
|
||||
}
|
||||
|
||||
public void setMobileSignalStrength(Double mobileSignalStrength) {
|
||||
this.mobileSignalStrength = mobileSignalStrength;
|
||||
}
|
||||
|
||||
public String getSsid() {
|
||||
return ssid;
|
||||
}
|
||||
|
||||
public void setSsid(String ssid) {
|
||||
this.ssid = ssid;
|
||||
}
|
||||
|
||||
public Double getCpuUsage() {
|
||||
return cpuUsage;
|
||||
}
|
||||
|
||||
public void setCpuUsage(Double cpuUsage) {
|
||||
this.cpuUsage = cpuUsage;
|
||||
}
|
||||
|
||||
public Double getTotalRAMMemory() {
|
||||
return totalRAMMemory;
|
||||
}
|
||||
|
||||
public void setTotalRAMMemory(Double totalRAMMemory) {
|
||||
this.totalRAMMemory = totalRAMMemory;
|
||||
}
|
||||
|
||||
public Double getAvailableRAMMemory() {
|
||||
return availableRAMMemory;
|
||||
}
|
||||
|
||||
public void setAvailableRAMMemory(Double availableRAMMemory) {
|
||||
this.availableRAMMemory = availableRAMMemory;
|
||||
}
|
||||
|
||||
public boolean isPluggedIn() {
|
||||
return pluggedIn;
|
||||
}
|
||||
|
||||
public void setPluggedIn(boolean pluggedIn) {
|
||||
this.pluggedIn = pluggedIn;
|
||||
}
|
||||
|
||||
public void setDeviceDetailsMap(Map<String,String> deviceDetailsMap) {
|
||||
this.deviceDetailsMap = deviceDetailsMap;
|
||||
}
|
||||
|
||||
public Map<String, String> getDeviceDetailsMap() {
|
||||
return deviceDetailsMap;
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,123 @@
|
||||
/*
|
||||
* Copyright (c) 2016, 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.common.device.details;
|
||||
|
||||
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
public class DeviceLocation implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1998101722L;
|
||||
|
||||
private int deviceId;
|
||||
private DeviceIdentifier deviceIdentifier;
|
||||
private Double latitude;
|
||||
private Double longitude;
|
||||
|
||||
private String street1;
|
||||
private String street2;
|
||||
|
||||
private String city;
|
||||
private String state;
|
||||
private String zip;
|
||||
private String country;
|
||||
|
||||
public int getDeviceId() {
|
||||
return deviceId;
|
||||
}
|
||||
|
||||
public void setDeviceId(int deviceId) {
|
||||
this.deviceId = deviceId;
|
||||
}
|
||||
|
||||
public DeviceIdentifier getDeviceIdentifier() {
|
||||
return deviceIdentifier;
|
||||
}
|
||||
|
||||
public void setDeviceIdentifier(DeviceIdentifier deviceIdentifier) {
|
||||
this.deviceIdentifier = deviceIdentifier;
|
||||
}
|
||||
|
||||
public Double getLatitude() {
|
||||
return latitude;
|
||||
}
|
||||
|
||||
public void setLatitude(Double latitude) {
|
||||
this.latitude = latitude;
|
||||
}
|
||||
|
||||
public Double getLongitude() {
|
||||
return longitude;
|
||||
}
|
||||
|
||||
public void setLongitude(Double longitude) {
|
||||
this.longitude = longitude;
|
||||
}
|
||||
|
||||
public String getStreet1() {
|
||||
return street1;
|
||||
}
|
||||
|
||||
public void setStreet1(String street1) {
|
||||
this.street1 = street1;
|
||||
}
|
||||
|
||||
public String getStreet2() {
|
||||
return street2;
|
||||
}
|
||||
|
||||
public void setStreet2(String street2) {
|
||||
this.street2 = street2;
|
||||
}
|
||||
|
||||
public String getCity() {
|
||||
return city;
|
||||
}
|
||||
|
||||
public void setCity(String city) {
|
||||
this.city = city;
|
||||
}
|
||||
|
||||
public String getState() {
|
||||
return state;
|
||||
}
|
||||
|
||||
public void setState(String state) {
|
||||
this.state = state;
|
||||
}
|
||||
|
||||
public String getZip() {
|
||||
return zip;
|
||||
}
|
||||
|
||||
public void setZip(String zip) {
|
||||
this.zip = zip;
|
||||
}
|
||||
|
||||
public String getCountry() {
|
||||
return country;
|
||||
}
|
||||
|
||||
public void setCountry(String country) {
|
||||
this.country = country;
|
||||
}
|
||||
}
|
||||
|
@ -1,85 +0,0 @@
|
||||
/*
|
||||
* 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.config.email;
|
||||
|
||||
import javax.xml.bind.annotation.XmlElement;
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
|
||||
@XmlRootElement(name = "EmailClientConfiguration")
|
||||
public class EmailConfigurations {
|
||||
|
||||
private int minNumOfThread;
|
||||
private int maxNumOfThread;
|
||||
private int keepAliveTime;
|
||||
private int threadQueueCapacity;
|
||||
private String lBHostPortPrefix;
|
||||
private String enrollmentContextPath;
|
||||
|
||||
@XmlElement(name = "minimumThread", required = true)
|
||||
public int getMinNumOfThread() {
|
||||
return minNumOfThread;
|
||||
}
|
||||
|
||||
public void setMinNumOfThread(int minNumOfThread) {
|
||||
this.minNumOfThread = minNumOfThread;
|
||||
}
|
||||
@XmlElement(name = "maximumThread", required = true)
|
||||
public int getMaxNumOfThread() {
|
||||
return maxNumOfThread;
|
||||
}
|
||||
|
||||
public void setMaxNumOfThread(int maxNumOfThread) {
|
||||
this.maxNumOfThread = maxNumOfThread;
|
||||
}
|
||||
|
||||
@XmlElement(name = "keepAliveTime", required = true)
|
||||
public int getKeepAliveTime() {
|
||||
return keepAliveTime;
|
||||
}
|
||||
|
||||
public void setKeepAliveTime(int keepAliveTime) {
|
||||
this.keepAliveTime = keepAliveTime;
|
||||
}
|
||||
@XmlElement(name = "ThreadQueueCapacity", required = true)
|
||||
public int getThreadQueueCapacity() {
|
||||
return threadQueueCapacity;
|
||||
}
|
||||
|
||||
public void setThreadQueueCapacity(int threadQueueCapacity) {
|
||||
this.threadQueueCapacity = threadQueueCapacity;
|
||||
}
|
||||
|
||||
@XmlElement(name = "LBHostPortPrefix", required = true)
|
||||
public String getlBHostPortPrefix() {
|
||||
return lBHostPortPrefix;
|
||||
}
|
||||
|
||||
public void setlBHostPortPrefix(String lBHostPortPrefix) {
|
||||
this.lBHostPortPrefix = lBHostPortPrefix;
|
||||
}
|
||||
|
||||
@XmlElement(name = "enrollmentContextPath", required = true)
|
||||
public String getEnrollmentContextPath() {
|
||||
return enrollmentContextPath;
|
||||
}
|
||||
|
||||
public void setEnrollmentContextPath(String enrollmentContextPath) {
|
||||
this.enrollmentContextPath = enrollmentContextPath;
|
||||
}
|
||||
}
|
@ -1,110 +0,0 @@
|
||||
/*
|
||||
* 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.config.email;
|
||||
|
||||
import javax.xml.bind.annotation.XmlAttribute;
|
||||
import javax.xml.bind.annotation.XmlElement;
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
|
||||
@XmlRootElement(name = "NotificationMessage")
|
||||
public class NotificationMessages {
|
||||
|
||||
private String header;
|
||||
private String body;
|
||||
private String footerLine1;
|
||||
private String footerLine2;
|
||||
private String footerLine3;
|
||||
private String subject;
|
||||
private String url;
|
||||
|
||||
@XmlAttribute(name = "type")
|
||||
public String getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public void setType(String type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
private String type;
|
||||
|
||||
@XmlElement(name = "Header", required = true)
|
||||
public String getHeader() {
|
||||
return header;
|
||||
}
|
||||
|
||||
public void setHeader(String header) {
|
||||
this.header = header;
|
||||
}
|
||||
|
||||
@XmlElement(name = "Body", required = true)
|
||||
public String getBody() {
|
||||
return body;
|
||||
}
|
||||
|
||||
public void setBody(String body) {
|
||||
this.body = body;
|
||||
}
|
||||
|
||||
@XmlElement(name = "Subject", required = true)
|
||||
public String getSubject() {
|
||||
return subject;
|
||||
}
|
||||
|
||||
public void setSubject(String subject) {
|
||||
this.subject = subject;
|
||||
}
|
||||
|
||||
@XmlElement(name = "Url", required = true)
|
||||
public String getUrl() {
|
||||
return url;
|
||||
}
|
||||
|
||||
public void setUrl(String url) {
|
||||
this.url = url;
|
||||
}
|
||||
|
||||
@XmlElement(name = "Footer1")
|
||||
public String getFooterLine1() {
|
||||
return footerLine1;
|
||||
}
|
||||
|
||||
public void setFooterLine1(String footerLine1) {
|
||||
this.footerLine1 = footerLine1;
|
||||
}
|
||||
|
||||
@XmlElement(name = "Footer2")
|
||||
public String getFooterLine2() {
|
||||
return footerLine2;
|
||||
}
|
||||
|
||||
public void setFooterLine2(String footerLine2) {
|
||||
this.footerLine2 = footerLine2;
|
||||
}
|
||||
|
||||
@XmlElement(name = "Footer3")
|
||||
public String getFooterLine3() {
|
||||
return footerLine3;
|
||||
}
|
||||
|
||||
public void setFooterLine3(String footerLine3) {
|
||||
this.footerLine3 = footerLine3;
|
||||
}
|
||||
|
||||
}
|
@ -1,39 +0,0 @@
|
||||
/*
|
||||
* 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.config.email;
|
||||
|
||||
import javax.xml.bind.annotation.XmlElement;
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
import java.util.List;
|
||||
|
||||
@XmlRootElement(name = "Notifications")
|
||||
public class NotificationMessagesConfig {
|
||||
|
||||
private List<NotificationMessages> notificationMessagesList;
|
||||
|
||||
@XmlElement(name = "NotificationMessage")
|
||||
public List<NotificationMessages> getNotificationMessagesList() {
|
||||
return notificationMessagesList;
|
||||
}
|
||||
|
||||
public void setNotificationMessagesList(List<NotificationMessages> notificationMessagesList) {
|
||||
this.notificationMessagesList = notificationMessagesList;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,101 @@
|
||||
/*
|
||||
* Copyright (c) 2016, 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.
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* This class will read the configurations related to task. This task will be responsible for adding the operations.
|
||||
*/
|
||||
package org.wso2.carbon.device.mgt.core.config.task;
|
||||
|
||||
import javax.xml.bind.annotation.XmlElement;
|
||||
import javax.xml.bind.annotation.XmlElementWrapper;
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
import java.util.List;
|
||||
|
||||
@XmlRootElement(name = "TaskConfiguration")
|
||||
public class TaskConfiguration {
|
||||
|
||||
|
||||
private boolean enabled;
|
||||
private int frequency;
|
||||
private String taskClazz;
|
||||
private List<Operation> operations;
|
||||
|
||||
@XmlElement(name = "Enable", required = true)
|
||||
public boolean isEnabled() {
|
||||
return enabled;
|
||||
}
|
||||
|
||||
public void setEnabled(boolean enabled) {
|
||||
this.enabled = enabled;
|
||||
}
|
||||
|
||||
@XmlElement(name = "Frequency", required = true)
|
||||
public int getFrequency() {
|
||||
return frequency;
|
||||
}
|
||||
|
||||
public void setFrequency(int frequency) {
|
||||
this.frequency = frequency;
|
||||
}
|
||||
|
||||
@XmlElement(name = "TaskClass", required = true)
|
||||
public String getTaskClazz() {
|
||||
return taskClazz;
|
||||
}
|
||||
|
||||
public void setTaskClazz(String taskClazz) {
|
||||
this.taskClazz = taskClazz;
|
||||
}
|
||||
|
||||
@XmlElementWrapper(name="Operations")
|
||||
@XmlElement(name = "Operation", required = true)
|
||||
public List<Operation> getOperations() {
|
||||
return operations;
|
||||
}
|
||||
|
||||
public void setOperations(List<Operation> operations) {
|
||||
this.operations = operations;
|
||||
}
|
||||
|
||||
@XmlRootElement(name = "Operation")
|
||||
public static class Operation {
|
||||
|
||||
|
||||
private String operationName;
|
||||
private int recurrency;
|
||||
|
||||
@XmlElement(name = "Name", required = true)
|
||||
public String getOperationName() {
|
||||
return operationName;
|
||||
}
|
||||
|
||||
public void setOperationName(String operationName) {
|
||||
this.operationName = operationName;
|
||||
}
|
||||
|
||||
@XmlElement(name = "RecurrentTimes", required = true)
|
||||
public int getRecurrency() {
|
||||
return recurrency;
|
||||
}
|
||||
|
||||
public void setRecurrency(int recurrency) {
|
||||
this.recurrency = recurrency;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,31 +0,0 @@
|
||||
/*
|
||||
* 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;
|
||||
|
||||
public final class EmailConstants {
|
||||
|
||||
public static final class EnrolmentEmailConstants {
|
||||
public static final String DOMAIN = "domain-name";
|
||||
public static final String USERNAME = "user-name";
|
||||
public static final String DOWNLOAD_URL = "downloadUrl";
|
||||
public static final String ENCODED_SCHEME = "UTF-8";
|
||||
public static final String PASSWORD = "password";
|
||||
public static final String FIRST_NAME = "first-name";
|
||||
}
|
||||
|
||||
}
|
@ -1,116 +0,0 @@
|
||||
/*
|
||||
* 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;
|
||||
|
||||
import org.apache.axiom.om.OMAbstractFactory;
|
||||
import org.apache.axiom.om.OMElement;
|
||||
import org.apache.axis2.AxisFault;
|
||||
import org.apache.axis2.Constants;
|
||||
import org.apache.axis2.addressing.EndpointReference;
|
||||
import org.apache.axis2.client.Options;
|
||||
import org.apache.axis2.client.ServiceClient;
|
||||
import org.apache.axis2.context.ConfigurationContext;
|
||||
import org.apache.axis2.context.MessageContext;
|
||||
import org.apache.axis2.transport.base.BaseConstants;
|
||||
import org.apache.axis2.transport.mail.MailConstants;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.wso2.carbon.device.mgt.common.DeviceManagementException;
|
||||
import org.wso2.carbon.device.mgt.common.EmailMessageProperties;
|
||||
import org.wso2.carbon.device.mgt.core.config.DeviceConfigurationManager;
|
||||
import org.wso2.carbon.device.mgt.core.config.email.EmailConfigurations;
|
||||
import org.wso2.carbon.device.mgt.core.internal.EmailServiceDataHolder;
|
||||
import org.wso2.carbon.device.mgt.core.service.EmailService;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.LinkedBlockingQueue;
|
||||
import java.util.concurrent.ThreadPoolExecutor;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
public class EmailServiceProviderImpl implements EmailService {
|
||||
|
||||
private static ThreadPoolExecutor threadPoolExecutor;
|
||||
|
||||
static {
|
||||
EmailConfigurations emailConfig =
|
||||
DeviceConfigurationManager.getInstance().getDeviceManagementConfig().
|
||||
getDeviceManagementConfigRepository().getEmailConfigurations();
|
||||
|
||||
threadPoolExecutor = new ThreadPoolExecutor(emailConfig.getMinNumOfThread(),
|
||||
emailConfig.getMaxNumOfThread(), emailConfig.getKeepAliveTime(), TimeUnit.SECONDS,
|
||||
new LinkedBlockingQueue<Runnable>(emailConfig.getThreadQueueCapacity()));
|
||||
}
|
||||
|
||||
private static final String EMAIL_URI_SCHEME = "mailto:";
|
||||
private static Log log = LogFactory.getLog(EmailServiceProviderImpl.class);
|
||||
|
||||
@Override
|
||||
public void sendEmail(EmailMessageProperties emailMessageProperties) throws DeviceManagementException {
|
||||
for (String toAddr : emailMessageProperties.getMailTo()) {
|
||||
threadPoolExecutor
|
||||
.submit(new EmailSender(toAddr, emailMessageProperties.getSubject(),
|
||||
emailMessageProperties.getMessageBody()));
|
||||
}
|
||||
}
|
||||
|
||||
public static class EmailSender implements Runnable {
|
||||
|
||||
String to;
|
||||
String subject;
|
||||
String body;
|
||||
|
||||
EmailSender(String to, String subject, String body) {
|
||||
this.to = to;
|
||||
this.subject = subject;
|
||||
this.body = body;
|
||||
}
|
||||
|
||||
public void run() {
|
||||
Map<String, String> headerMap = new HashMap<String, String>();
|
||||
headerMap.put(MailConstants.MAIL_HEADER_SUBJECT, subject);
|
||||
OMElement payload = OMAbstractFactory.getOMFactory().createOMElement(
|
||||
BaseConstants.DEFAULT_TEXT_WRAPPER, null);
|
||||
payload.setText(body);
|
||||
try {
|
||||
ServiceClient serviceClient;
|
||||
ConfigurationContext configContext = EmailServiceDataHolder.getInstance().
|
||||
getConfigurationContextService().getServerConfigContext();
|
||||
//Set configuration service client if available, else create new service client
|
||||
if (configContext != null) {
|
||||
serviceClient = new ServiceClient(configContext, null);
|
||||
} else {
|
||||
|
||||
serviceClient = new ServiceClient();
|
||||
}
|
||||
Options options = new Options();
|
||||
options.setProperty(Constants.Configuration.ENABLE_REST, Constants.VALUE_TRUE);
|
||||
options.setProperty(MessageContext.TRANSPORT_HEADERS, headerMap);
|
||||
options.setProperty(MailConstants.TRANSPORT_MAIL_FORMAT,
|
||||
MailConstants.TRANSPORT_FORMAT_TEXT);
|
||||
options.setTo(new EndpointReference(EMAIL_URI_SCHEME + to));
|
||||
serviceClient.setOptions(options);
|
||||
serviceClient.fireAndForget(payload);
|
||||
log.debug("Sending confirmation mail to " + to);
|
||||
} catch (AxisFault e) {
|
||||
log.error("Error in delivering the message, subject: '" + subject + "', to: '" + to + "'", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,98 @@
|
||||
/*
|
||||
* Copyright (c) 2016, 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.internal;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.osgi.service.component.ComponentContext;
|
||||
import org.wso2.carbon.device.mgt.core.config.DeviceConfigurationManager;
|
||||
import org.wso2.carbon.device.mgt.core.device.details.mgt.DeviceInformationManager;
|
||||
import org.wso2.carbon.device.mgt.core.device.details.mgt.impl.DeviceInformationManagerImpl;
|
||||
import org.wso2.carbon.device.mgt.core.search.mgt.SearchManagerService;
|
||||
import org.wso2.carbon.device.mgt.core.search.mgt.impl.SearchManagerServiceImpl;
|
||||
import org.wso2.carbon.device.mgt.core.task.DeviceTaskManagerService;
|
||||
import org.wso2.carbon.device.mgt.core.task.impl.DeviceTaskManagerServiceImpl;
|
||||
import org.wso2.carbon.ntask.core.service.TaskService;
|
||||
|
||||
/**
|
||||
* @scr.component name="org.wso2.carbon.device.task.manager" immediate="true"
|
||||
* @scr.reference name="device.ntask.component"
|
||||
* interface="org.wso2.carbon.ntask.core.service.TaskService"
|
||||
* cardinality="1..1"
|
||||
* policy="dynamic"
|
||||
* bind="setTaskService"
|
||||
* unbind="unsetTaskService"
|
||||
*/
|
||||
|
||||
public class DeviceTaskManagerServiceComponent {
|
||||
|
||||
private static Log log = LogFactory.getLog(DeviceManagementServiceComponent.class);
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
protected void activate(ComponentContext componentContext) {
|
||||
try {
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Initializing device details retrieving task manager bundle.");
|
||||
}
|
||||
// This will start the device details retrieving task.
|
||||
boolean taskEnable = DeviceConfigurationManager.getInstance().getDeviceManagementConfig().
|
||||
getDeviceManagementConfigRepository().getTaskConfiguration().isEnabled();
|
||||
if (taskEnable) {
|
||||
DeviceTaskManagerService taskManagerService = new DeviceTaskManagerServiceImpl();
|
||||
taskManagerService.startTask();
|
||||
}
|
||||
componentContext.getBundleContext().registerService(DeviceInformationManager.class,
|
||||
new DeviceInformationManagerImpl(), null);
|
||||
|
||||
componentContext.getBundleContext().registerService(SearchManagerService.class,
|
||||
new SearchManagerServiceImpl(), null);
|
||||
} catch (Throwable e) {
|
||||
log.error("Error occurred while initializing device details retrieving task manager service.", e);
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
protected void deactivate(ComponentContext componentContext) {
|
||||
|
||||
try {
|
||||
DeviceTaskManagerService taskManagerService = new DeviceTaskManagerServiceImpl();
|
||||
taskManagerService.stopTask();
|
||||
} catch (Throwable e) {
|
||||
log.error("Error occurred while destroying the device details retrieving task manager service.", e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
protected void setTaskService(TaskService taskService) {
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Setting the task service.");
|
||||
}
|
||||
DeviceManagementDataHolder.getInstance().setTaskService(taskService);
|
||||
}
|
||||
|
||||
protected void unsetTaskService(TaskService taskService) {
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Removing the task service.");
|
||||
}
|
||||
DeviceManagementDataHolder.getInstance().setTaskService(null);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,86 +0,0 @@
|
||||
/*
|
||||
* 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.internal;
|
||||
|
||||
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.config.DeviceConfigurationManager;
|
||||
import org.wso2.carbon.device.mgt.core.config.DeviceManagementConfig;
|
||||
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;
|
||||
|
||||
/**
|
||||
* @scr.component component.name="org.wso2.carbon.device.emailmanager" immediate="true"
|
||||
* @scr.reference name="configurationcontext.service"
|
||||
* interface="org.wso2.carbon.utils.ConfigurationContextService" cardinality="1..1"
|
||||
* policy="dynamic" bind="setConfigurationContextService" unbind="unsetConfigurationContextService"
|
||||
*/
|
||||
public class EmailServiceComponent {
|
||||
|
||||
private static Log log = LogFactory.getLog(EmailServiceComponent.class);
|
||||
|
||||
/**
|
||||
* initialize the email service here service here.
|
||||
*
|
||||
* @param context
|
||||
*/
|
||||
protected void activate(ComponentContext context) {
|
||||
try {
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Initializing email service bundle");
|
||||
}
|
||||
|
||||
DeviceConfigurationManager.getInstance().initConfig();
|
||||
DeviceManagementConfig config =
|
||||
DeviceConfigurationManager.getInstance().getDeviceManagementConfig();
|
||||
/* Initializing Email Service Configurations */
|
||||
|
||||
EmailService emailServiceProvider = new EmailServiceProviderImpl();
|
||||
EmailServiceDataHolder.getInstance().setEmailServiceProvider(emailServiceProvider); ;
|
||||
|
||||
this.registerServices(context);
|
||||
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Email management core bundle has been successfully initialized");
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
log.error("Error occurred while initializing device management core bundle", e);
|
||||
}
|
||||
}
|
||||
protected void setConfigurationContextService(ConfigurationContextService configurationContextService) {
|
||||
EmailServiceDataHolder.getInstance().setConfigurationContextService(configurationContextService);
|
||||
}
|
||||
protected void unsetConfigurationContextService(ConfigurationContextService configurationContextService) {
|
||||
EmailServiceDataHolder.getInstance().setConfigurationContextService(null);
|
||||
}
|
||||
|
||||
private void registerServices(ComponentContext componentContext) {
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Registering OSGi service Email Service Impl");
|
||||
}
|
||||
/* Registering Email Service */
|
||||
BundleContext bundleContext = componentContext.getBundleContext();
|
||||
bundleContext.registerService(EmailService.class.getName(), new EmailServiceImpl(), null);
|
||||
}
|
||||
|
||||
}
|
@ -1,61 +0,0 @@
|
||||
/*
|
||||
* 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.internal;
|
||||
|
||||
import org.wso2.carbon.device.mgt.core.service.EmailService;
|
||||
import org.wso2.carbon.utils.ConfigurationContextService;
|
||||
|
||||
public class EmailServiceDataHolder {
|
||||
|
||||
private static EmailServiceDataHolder thisInstance = new EmailServiceDataHolder();
|
||||
private ConfigurationContextService configurationContextService;
|
||||
private EmailService emailServiceProvider;
|
||||
|
||||
public static EmailServiceDataHolder getThisInstance() {
|
||||
return thisInstance;
|
||||
}
|
||||
|
||||
public static void setThisInstance(EmailServiceDataHolder thisInstance) {
|
||||
EmailServiceDataHolder.thisInstance = thisInstance;
|
||||
}
|
||||
|
||||
private EmailServiceDataHolder() {
|
||||
}
|
||||
|
||||
public static EmailServiceDataHolder getInstance() {
|
||||
return thisInstance;
|
||||
}
|
||||
|
||||
public ConfigurationContextService getConfigurationContextService() {
|
||||
if (configurationContextService == null) {
|
||||
throw new IllegalStateException("ConfigurationContext service is not initialized properly");
|
||||
}
|
||||
return configurationContextService;
|
||||
}
|
||||
|
||||
public void setConfigurationContextService(ConfigurationContextService configurationContextService) {
|
||||
this.configurationContextService = configurationContextService;
|
||||
}
|
||||
public EmailService getEmailServiceProvider() {
|
||||
return emailServiceProvider;
|
||||
}
|
||||
|
||||
public void setEmailServiceProvider(EmailService emailServiceProvider) {
|
||||
this.emailServiceProvider = emailServiceProvider;
|
||||
}
|
||||
}
|
@ -0,0 +1,31 @@
|
||||
/*
|
||||
* Copyright (c) 2016, 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.search.mgt;
|
||||
|
||||
import org.wso2.carbon.device.mgt.common.device.details.DeviceWrapper;
|
||||
import org.wso2.carbon.device.mgt.common.search.Condition;
|
||||
import org.wso2.carbon.device.mgt.common.search.SearchContext;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface Processor {
|
||||
|
||||
List<DeviceWrapper> execute(SearchContext searchContext) throws SearchMgtException;
|
||||
}
|
@ -0,0 +1,31 @@
|
||||
/*
|
||||
* Copyright (c) 2016, 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.search.mgt;
|
||||
|
||||
import org.wso2.carbon.device.mgt.common.device.details.DeviceWrapper;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public interface ResultSetAggregator {
|
||||
|
||||
List<DeviceWrapper> aggregate(Map<String, List<DeviceWrapper>> deviceWrappers);
|
||||
|
||||
}
|
@ -0,0 +1,31 @@
|
||||
/*
|
||||
* Copyright (c) 2016, 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.search.mgt;
|
||||
|
||||
import org.wso2.carbon.device.mgt.common.device.details.DeviceWrapper;
|
||||
import org.wso2.carbon.device.mgt.common.search.SearchContext;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface SearchManagerService {
|
||||
|
||||
List<DeviceWrapper> search(SearchContext searchContext) throws SearchMgtException;
|
||||
}
|
||||
|
@ -0,0 +1,59 @@
|
||||
/*
|
||||
* Copyright (c) 2016, 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.search.mgt.dao;
|
||||
|
||||
public class SearchDAOException extends Exception {
|
||||
|
||||
private static final long serialVersionUID = -315127931139999499L;
|
||||
|
||||
private String errorMessage;
|
||||
|
||||
public String getErrorMessage() {
|
||||
return errorMessage;
|
||||
}
|
||||
|
||||
public void setErrorMessage(String errorMessage) {
|
||||
this.errorMessage = errorMessage;
|
||||
}
|
||||
|
||||
public SearchDAOException(String msg, Exception nestedEx) {
|
||||
super(msg, nestedEx);
|
||||
setErrorMessage(msg);
|
||||
}
|
||||
|
||||
public SearchDAOException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
setErrorMessage(message);
|
||||
}
|
||||
|
||||
public SearchDAOException(String msg) {
|
||||
super(msg);
|
||||
setErrorMessage(msg);
|
||||
}
|
||||
|
||||
public SearchDAOException() {
|
||||
super();
|
||||
}
|
||||
|
||||
public SearchDAOException(Throwable cause) {
|
||||
super(cause);
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,193 @@
|
||||
/*
|
||||
* Copyright (c) 2016, 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.search.mgt.impl;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.wso2.carbon.context.PrivilegedCarbonContext;
|
||||
import org.wso2.carbon.device.mgt.common.search.Condition;
|
||||
import org.wso2.carbon.device.mgt.core.search.mgt.Constants;
|
||||
import org.wso2.carbon.device.mgt.core.search.mgt.InvalidOperatorException;
|
||||
import org.wso2.carbon.device.mgt.core.search.mgt.QueryBuilder;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class QueryBuilderImpl implements QueryBuilder {
|
||||
|
||||
|
||||
private static final Log log = LogFactory.getLog(QueryBuilderImpl.class);
|
||||
|
||||
@Override
|
||||
public Map<String, List<String>> buildQueries(List<Condition> conditions) throws InvalidOperatorException {
|
||||
|
||||
List<Condition> andColumns = new ArrayList<>();
|
||||
List<Condition> orColumns = new ArrayList<>();
|
||||
List<Condition> otherANDColumns = new ArrayList<>();
|
||||
List<Condition> otherORColumns = new ArrayList<>();
|
||||
|
||||
if (conditions.size() == 1) {
|
||||
if (Utils.getDeviceDetailsColumnNames().containsKey(conditions.get(0)) ||
|
||||
Utils.getDeviceLocationColumnNames().containsKey(conditions.get(0))) {
|
||||
andColumns.add(conditions.get(0));
|
||||
} else {
|
||||
otherANDColumns.add(conditions.get(0));
|
||||
}
|
||||
} else {
|
||||
for (Condition con : conditions) {
|
||||
if (Utils.getDeviceDetailsColumnNames().containsKey(con.getKey()) ||
|
||||
Utils.getDeviceLocationColumnNames().containsKey(con.getKey())) {
|
||||
if (con.getState().equals(Condition.State.AND)) {
|
||||
andColumns.add(con);
|
||||
} else if (con.getState().equals(Condition.State.OR)) {
|
||||
orColumns.add(con);
|
||||
} else {
|
||||
throw new InvalidOperatorException(con.getState() + " is not a valid operator.");
|
||||
}
|
||||
} else {
|
||||
if (con.getState().equals(Condition.State.AND)) {
|
||||
otherANDColumns.add(con);
|
||||
} else if (con.getState().equals(Condition.State.OR)) {
|
||||
otherORColumns.add(con);
|
||||
} else {
|
||||
throw new InvalidOperatorException(con.getState() + " is not a valid operator.");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Map<String, List<String>> queries = new HashMap<>();
|
||||
queries.put(Constants.GENERAL, Utils.convertStringToList(this.getGenericQueryPart() + this.processAND(andColumns) +
|
||||
this.processOR(orColumns)));
|
||||
queries.put(Constants.PROP_AND, this.processANDProperties(otherANDColumns));
|
||||
queries.put(Constants.PROP_OR, this.processORProperties(otherORColumns));
|
||||
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("General Query : " + queries.get(Constants.GENERAL));
|
||||
log.debug("Property with AND Query : " + queries.get(Constants.PROP_AND));
|
||||
log.debug("Property with OR Query : " + queries.get(Constants.PROP_OR));
|
||||
}
|
||||
|
||||
return queries;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String processAND(List<Condition> conditions) throws InvalidOperatorException {
|
||||
|
||||
String querySuffix = "";
|
||||
|
||||
for (Condition con : conditions) {
|
||||
if (Utils.getDeviceDetailsColumnNames().containsKey(con.getKey())) {
|
||||
querySuffix = querySuffix + " AND DD." + Utils.getDeviceDetailsColumnNames().get(con.getKey()) +
|
||||
con.getOperator() + con.getValue();
|
||||
} else if (Utils.getDeviceLocationColumnNames().containsKey(con.getKey())) {
|
||||
querySuffix = querySuffix + " AND DL." + Utils.getDeviceLocationColumnNames().get(con.getKey()) +
|
||||
con.getOperator() + con.getValue();
|
||||
}
|
||||
}
|
||||
|
||||
return querySuffix;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String processOR(List<Condition> conditions) throws InvalidOperatorException {
|
||||
|
||||
String querySuffix = "";
|
||||
|
||||
for (Condition con : conditions) {
|
||||
if (Utils.getDeviceDetailsColumnNames().containsKey(con.getKey())) {
|
||||
querySuffix = querySuffix + " OR DD." + Utils.getDeviceDetailsColumnNames().get(con.getKey()) +
|
||||
con.getOperator() + con.getValue();
|
||||
} else if (Utils.getDeviceLocationColumnNames().containsKey(con.getKey())) {
|
||||
querySuffix = querySuffix + " OR DL." + Utils.getDeviceLocationColumnNames().get(con.getKey()) +
|
||||
con.getOperator() + con.getValue();
|
||||
}
|
||||
}
|
||||
return querySuffix;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> processANDProperties(List<Condition> conditions) throws InvalidOperatorException {
|
||||
return this.getQueryList(conditions);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> processORProperties(List<Condition> conditions) throws InvalidOperatorException {
|
||||
return this.getQueryList(conditions);
|
||||
}
|
||||
|
||||
private List<String> getQueryList(List<Condition> conditions) {
|
||||
List<String> queryList = new ArrayList<>();
|
||||
for (Condition con : conditions) {
|
||||
|
||||
String querySuffix = this.getPropertyQueryPart() + " AND DI.KEY_FIELD = " + "\'" + con.getKey() + "\'" +
|
||||
" AND DI.VALUE_FIELD " + con.getOperator() + "\'" + con.getValue() + "\'";
|
||||
queryList.add(querySuffix);
|
||||
}
|
||||
return queryList;
|
||||
}
|
||||
|
||||
private String getGenericQueryPart() {
|
||||
|
||||
return "SELECT D.ID, D.DESCRIPTION, D.NAME, \n" +
|
||||
" D.DEVICE_TYPE_ID, D.DEVICE_IDENTIFICATION, DT.ID AS DEVICE_TYPE_ID, \n" +
|
||||
"DT.NAME AS DEVICE_TYPE_NAME, DD.DEVICE_ID, DD.IMEI, DD.IMSI, DD.DEVICE_MODEL, DD.VENDOR, \n" +
|
||||
"DD.OS_VERSION, DD.BATTERY_LEVEL, DD.INTERNAL_TOTAL_MEMORY, DD.INTERNAL_AVAILABLE_MEMORY,\n" +
|
||||
"DD.EXTERNAL_TOTAL_MEMORY, DD.EXTERNAL_AVAILABLE_MEMORY, DD.OPERATOR, DD.CONNECTION_TYPE, \n" +
|
||||
"DD.MOBILE_SIGNAL_STRENGTH, DD.SSID, DD.CPU_USAGE, DD.TOTAL_RAM_MEMORY, DD.AVAILABLE_RAM_MEMORY, \n" +
|
||||
"DD.PLUGGED_IN, DL.LATITUDE, DL.LONGITUDE, DL.STREET1, DL.STREET2, DL.CITY, DL.ZIP, \n" +
|
||||
"DL.STATE, DL.COUNTRY FROM DM_DEVICE_DETAIL AS DD, DM_DEVICE AS D, DM_DEVICE_LOCATION AS DL, " +
|
||||
"DM_DEVICE_TYPE AS DT WHERE D.TENANT_ID = " +
|
||||
PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
|
||||
|
||||
// CREATE TABLE IF NOT EXISTS DM_DEVICE (
|
||||
// ID INTEGER auto_increment NOT NULL,
|
||||
// DESCRIPTION TEXT DEFAULT NULL,
|
||||
// NAME VARCHAR(100) DEFAULT NULL,
|
||||
// DEVICE_TYPE_ID INT(11) DEFAULT NULL,
|
||||
// DEVICE_IDENTIFICATION VARCHAR(300) DEFAULT NULL,
|
||||
// TENANT_ID INTEGER DEFAULT 0,
|
||||
// PRIMARY KEY (ID),
|
||||
// CONSTRAINT fk_DM_DEVICE_DM_DEVICE_TYPE2 FOREIGN KEY (DEVICE_TYPE_ID )
|
||||
// REFERENCES DM_DEVICE_TYPE (ID) ON DELETE NO ACTION ON UPDATE NO ACTION
|
||||
// );
|
||||
|
||||
|
||||
}
|
||||
|
||||
private String getPropertyQueryPart() {
|
||||
|
||||
return "SELECT D.ID, D.DESCRIPTION, D.NAME, \n" +
|
||||
" D.DEVICE_TYPE_ID, D.DEVICE_IDENTIFICATION, DT.ID AS DEVICE_TYPE_ID, \n" +
|
||||
"DT.NAME AS DEVICE_TYPE_NAME, DD.DEVICE_ID, DD.IMEI, DD.IMSI, DD.DEVICE_MODEL, DD.VENDOR, \n" +
|
||||
"DD.OS_VERSION, DD.BATTERY_LEVEL, DD.INTERNAL_TOTAL_MEMORY, DD.INTERNAL_AVAILABLE_MEMORY,\n" +
|
||||
"DD.EXTERNAL_TOTAL_MEMORY, DD.EXTERNAL_AVAILABLE_MEMORY, DD.OPERATOR, DD.CONNECTION_TYPE, \n" +
|
||||
"DD.MOBILE_SIGNAL_STRENGTH, DD.SSID, DD.CPU_USAGE, DD.TOTAL_RAM_MEMORY, DD.AVAILABLE_RAM_MEMORY, \n" +
|
||||
"DD.PLUGGED_IN, DL.LATITUDE, DL.LONGITUDE, DL.STREET1, DL.STREET2, DL.CITY, DL.ZIP, \n" +
|
||||
"DL.STATE, DL.COUNTRY, DI.KEY_FIELD, DI.VALUE_FIELD FROM DM_DEVICE_DETAIL AS DD, " +
|
||||
"DM_DEVICE AS D, DM_DEVICE_LOCATION AS DL, \n" +
|
||||
"DM_DEVICE_INFO AS DI, DM_DEVICE_TYPE AS DT WHERE D.TENANT_ID = " +
|
||||
PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,44 @@
|
||||
/*
|
||||
* Copyright (c) 2016, 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.search.mgt.impl;
|
||||
|
||||
import org.wso2.carbon.device.mgt.common.device.details.DeviceWrapper;
|
||||
import org.wso2.carbon.device.mgt.common.search.SearchContext;
|
||||
import org.wso2.carbon.device.mgt.core.search.mgt.Processor;
|
||||
import org.wso2.carbon.device.mgt.core.search.mgt.SearchManagerService;
|
||||
import org.wso2.carbon.device.mgt.core.search.mgt.SearchMgtException;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class SearchManagerServiceImpl implements SearchManagerService {
|
||||
|
||||
|
||||
private Processor processor;
|
||||
|
||||
public SearchManagerServiceImpl() {
|
||||
processor = new ProcessorImpl();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<DeviceWrapper> search(SearchContext searchContext) throws SearchMgtException {
|
||||
return processor.execute(searchContext);
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,75 @@
|
||||
/*
|
||||
* Copyright (c) 2016, 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.service;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Properties;
|
||||
import java.util.Set;
|
||||
|
||||
public class EmailMetaInfo {
|
||||
|
||||
private Set<String> recipients;
|
||||
private Properties properties;
|
||||
|
||||
public EmailMetaInfo(final Set<String> recipients, final Properties properties) {
|
||||
if (recipients == null) {
|
||||
throw new IllegalArgumentException("Recipient list cannot be null");
|
||||
}
|
||||
if (recipients.size() == 0) {
|
||||
throw new IllegalArgumentException("No recipient is configured. Recipient list should carry at " +
|
||||
"least one recipient");
|
||||
}
|
||||
this.recipients = recipients;
|
||||
if (properties == null) {
|
||||
throw new IllegalArgumentException("Email Context property bag cannot be null");
|
||||
}
|
||||
this.properties = properties;
|
||||
}
|
||||
|
||||
public EmailMetaInfo(final String recipient, final Properties properties) {
|
||||
if (recipient == null || recipient.isEmpty()) {
|
||||
throw new IllegalArgumentException("Recipient can't be null or empty. Please specify a valid " +
|
||||
"recipient email address");
|
||||
}
|
||||
this.recipients = new HashSet<String>() {{
|
||||
add(recipient);
|
||||
}};
|
||||
if (properties == null) {
|
||||
throw new IllegalArgumentException("Email Context property bag cannot be null");
|
||||
}
|
||||
this.properties = properties;
|
||||
}
|
||||
|
||||
public Set<String> getRecipients() {
|
||||
return recipients;
|
||||
}
|
||||
|
||||
public Properties getProperties() {
|
||||
return properties;
|
||||
}
|
||||
|
||||
public String getProperty(String name) {
|
||||
return (String) properties.get(name);
|
||||
}
|
||||
|
||||
public void addProperty(String name, String value) {
|
||||
properties.put(name, value);
|
||||
}
|
||||
|
||||
}
|
@ -1,31 +0,0 @@
|
||||
/*
|
||||
* 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.service;
|
||||
|
||||
import org.wso2.carbon.device.mgt.common.DeviceManagementException;
|
||||
import org.wso2.carbon.device.mgt.common.EmailMessageProperties;
|
||||
import org.wso2.carbon.device.mgt.core.internal.EmailServiceDataHolder;
|
||||
|
||||
public class EmailServiceImpl implements EmailService{
|
||||
|
||||
@Override
|
||||
public void sendEmail(EmailMessageProperties emailMessageProperties) throws DeviceManagementException {
|
||||
EmailServiceDataHolder.getInstance().getEmailServiceProvider().sendEmail(emailMessageProperties);
|
||||
}
|
||||
}
|
@ -0,0 +1,45 @@
|
||||
/*
|
||||
* Copyright (c) 2016, 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.task;
|
||||
|
||||
public interface DeviceTaskManagerService {
|
||||
|
||||
/**
|
||||
* This method will stop the task.
|
||||
* @throws DeviceMgtTaskException
|
||||
*/
|
||||
void startTask() throws DeviceMgtTaskException;
|
||||
|
||||
/**
|
||||
* This method will start the task.
|
||||
* @throws DeviceMgtTaskException
|
||||
*/
|
||||
void stopTask() throws DeviceMgtTaskException;
|
||||
|
||||
/**
|
||||
* This will update the task frequency which it runs.
|
||||
* @param frequency - integer
|
||||
* @throws DeviceMgtTaskException
|
||||
*/
|
||||
void updateTask(int frequency) throws DeviceMgtTaskException;
|
||||
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,47 @@
|
||||
/*
|
||||
* Copyright (c) 2016, 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.task;
|
||||
|
||||
|
||||
/**
|
||||
* This is the bean for the operations added by the task.
|
||||
*/
|
||||
public class TaskOperation {
|
||||
|
||||
private String taskName;
|
||||
private int recurrentTimes;
|
||||
|
||||
public String getTaskName() {
|
||||
return taskName;
|
||||
}
|
||||
|
||||
public void setTaskName(String taskName) {
|
||||
this.taskName = taskName;
|
||||
}
|
||||
|
||||
public int getRecurrentTimes() {
|
||||
return recurrentTimes;
|
||||
}
|
||||
|
||||
public void setRecurrentTimes(int recurrentTimes) {
|
||||
this.recurrentTimes = recurrentTimes;
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,43 @@
|
||||
/*
|
||||
* Copyright (c) 2016, 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.task;
|
||||
|
||||
import org.wso2.carbon.context.PrivilegedCarbonContext;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
public class Utils {
|
||||
|
||||
|
||||
public static HashMap<String, Long> getTenantedTaskOperationMap(HashMap<Integer, HashMap<String, Long>> map) {
|
||||
|
||||
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
|
||||
|
||||
if (map.containsKey(tenantId)) {
|
||||
return map.get(tenantId);
|
||||
} else {
|
||||
HashMap<String, Long> mp = new HashMap<>();
|
||||
map.put(tenantId, mp);
|
||||
return mp;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,151 @@
|
||||
/*
|
||||
* Copyright (c) 2016, 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.task.impl;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.wso2.carbon.device.mgt.common.Device;
|
||||
import org.wso2.carbon.device.mgt.common.DeviceManagementException;
|
||||
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.config.DeviceConfigurationManager;
|
||||
import org.wso2.carbon.device.mgt.core.config.task.TaskConfiguration;
|
||||
import org.wso2.carbon.device.mgt.core.internal.DeviceManagementDataHolder;
|
||||
import org.wso2.carbon.device.mgt.core.operation.mgt.CommandOperation;
|
||||
import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService;
|
||||
import org.wso2.carbon.device.mgt.core.task.DeviceMgtTaskException;
|
||||
import org.wso2.carbon.device.mgt.core.task.DeviceTaskManager;
|
||||
import org.wso2.carbon.device.mgt.core.task.TaskOperation;
|
||||
import org.wso2.carbon.device.mgt.core.task.Utils;
|
||||
import org.wso2.carbon.device.mgt.core.util.DeviceManagerUtil;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
public class DeviceTaskManagerImpl implements DeviceTaskManager {
|
||||
|
||||
private static Log log = LogFactory.getLog(DeviceTaskManagerImpl.class);
|
||||
|
||||
private static HashMap<Integer, HashMap<String, Long>> map = new HashMap<>();
|
||||
|
||||
|
||||
@Override
|
||||
public List<TaskOperation> getOperationList() throws DeviceMgtTaskException {
|
||||
|
||||
TaskConfiguration taskConfiguration = DeviceConfigurationManager.getInstance().getDeviceManagementConfig().
|
||||
getDeviceManagementConfigRepository().getTaskConfiguration();
|
||||
|
||||
List<TaskConfiguration.Operation> ops = taskConfiguration.getOperations();
|
||||
List<TaskOperation> taskOperations = new ArrayList<>();
|
||||
|
||||
for (TaskConfiguration.Operation op : ops) {
|
||||
TaskOperation taskOperation = new TaskOperation();
|
||||
taskOperation.setTaskName(op.getOperationName());
|
||||
taskOperation.setRecurrentTimes(op.getRecurrency());
|
||||
taskOperations.add(taskOperation);
|
||||
}
|
||||
return taskOperations;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getTaskFrequency() throws DeviceMgtTaskException {
|
||||
|
||||
return DeviceConfigurationManager.getInstance().getDeviceManagementConfig().
|
||||
getDeviceManagementConfigRepository().getTaskConfiguration().getFrequency();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTaskImplementedClazz() throws DeviceMgtTaskException {
|
||||
|
||||
return DeviceConfigurationManager.getInstance().getDeviceManagementConfig().
|
||||
getDeviceManagementConfigRepository().getTaskConfiguration().getTaskClazz();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isTaskEnabled() throws DeviceMgtTaskException {
|
||||
|
||||
return DeviceConfigurationManager.getInstance().getDeviceManagementConfig().
|
||||
getDeviceManagementConfigRepository().getTaskConfiguration().isEnabled();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void addOperations() throws DeviceMgtTaskException {
|
||||
|
||||
DeviceManagementProviderService deviceManagementProviderService =
|
||||
DeviceManagementDataHolder.getInstance().getDeviceManagementProvider();
|
||||
try {
|
||||
List<Device> devices = deviceManagementProviderService.getAllDevices();
|
||||
List<String> operations = this.getValidOperationNames();
|
||||
|
||||
if(!devices.isEmpty()) {
|
||||
|
||||
for (String str : operations) {
|
||||
CommandOperation operation = new CommandOperation();
|
||||
operation.setEnabled(true);
|
||||
operation.setType(Operation.Type.COMMAND);
|
||||
operation.setCode(str);
|
||||
deviceManagementProviderService.addOperation(operation, DeviceManagerUtil.convertDevices(devices));
|
||||
}
|
||||
} else {
|
||||
if(log.isDebugEnabled()){
|
||||
log.debug("No devices are available to perform the operations.");
|
||||
}
|
||||
}
|
||||
} catch (DeviceManagementException e) {
|
||||
throw new DeviceMgtTaskException("Error occurred while retrieving the device list.", e);
|
||||
} catch (OperationManagementException e) {
|
||||
throw new DeviceMgtTaskException("Error occurred while adding the operations to devices", e);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getValidOperationNames() throws DeviceMgtTaskException {
|
||||
|
||||
List<TaskOperation> taskOperations = this.getOperationList();
|
||||
List<String> opNames = new ArrayList<>();
|
||||
Long milliseconds = System.currentTimeMillis();
|
||||
int frequency = this.getTaskFrequency();
|
||||
HashMap<String, Long> mp = Utils.getTenantedTaskOperationMap(map);
|
||||
|
||||
for (TaskOperation top : taskOperations) {
|
||||
if (!mp.containsKey(top.getTaskName())) {
|
||||
opNames.add(top.getTaskName());
|
||||
mp.put(top.getTaskName(), milliseconds);
|
||||
} else {
|
||||
Long lastExecutedTime = mp.get(top.getTaskName());
|
||||
Long evalTime = lastExecutedTime + (frequency * top.getRecurrentTimes());
|
||||
if (evalTime <= milliseconds) {
|
||||
opNames.add(top.getTaskName());
|
||||
mp.put(top.getTaskName(), milliseconds);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(log.isDebugEnabled()){
|
||||
log.debug("Valid operation names are : " + Arrays.toString(opNames.toArray()));
|
||||
}
|
||||
return opNames;
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,150 @@
|
||||
/*
|
||||
* Copyright (c) 2016, 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.task.impl;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.wso2.carbon.context.PrivilegedCarbonContext;
|
||||
import org.wso2.carbon.device.mgt.core.internal.DeviceManagementDataHolder;
|
||||
import org.wso2.carbon.device.mgt.core.task.DeviceMgtTaskException;
|
||||
import org.wso2.carbon.device.mgt.core.task.DeviceTaskManager;
|
||||
import org.wso2.carbon.device.mgt.core.task.DeviceTaskManagerService;
|
||||
import org.wso2.carbon.ntask.common.TaskException;
|
||||
import org.wso2.carbon.ntask.core.TaskInfo;
|
||||
import org.wso2.carbon.ntask.core.TaskManager;
|
||||
import org.wso2.carbon.ntask.core.service.TaskService;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class DeviceTaskManagerServiceImpl implements DeviceTaskManagerService {
|
||||
|
||||
public static final String TASK_TYPE = "DEVICE_DETAILS";
|
||||
public static final String TASK_NAME = "DEVICE_DETAILS_TASK";
|
||||
public static final String TENANT_ID = "TENANT_ID";
|
||||
|
||||
private DeviceTaskManager deviceTaskManager;
|
||||
|
||||
private static Log log = LogFactory.getLog(DeviceTaskManagerServiceImpl.class);
|
||||
|
||||
@Override
|
||||
public void startTask() throws DeviceMgtTaskException {
|
||||
|
||||
deviceTaskManager = new DeviceTaskManagerImpl();
|
||||
if (!deviceTaskManager.isTaskEnabled()) {
|
||||
throw new DeviceMgtTaskException("Task cannot be started, Please enable the task in cdm-config.xml file.");
|
||||
}
|
||||
|
||||
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
|
||||
|
||||
try {
|
||||
TaskService taskService = DeviceManagementDataHolder.getInstance().getTaskService();
|
||||
taskService.registerTaskType(TASK_TYPE);
|
||||
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Device details retrieving task is started for the tenant id " + tenantId);
|
||||
log.debug("Device details retrieving task is at frequency of : " + deviceTaskManager.getTaskFrequency());
|
||||
}
|
||||
|
||||
TaskManager taskManager = taskService.getTaskManager(TASK_TYPE);
|
||||
|
||||
TaskInfo.TriggerInfo triggerInfo = new TaskInfo.TriggerInfo();
|
||||
triggerInfo.setIntervalMillis(deviceTaskManager.getTaskFrequency());
|
||||
triggerInfo.setRepeatCount(-1);
|
||||
|
||||
Map<String, String> properties = new HashMap<>();
|
||||
properties.put(TENANT_ID, String.valueOf(tenantId));
|
||||
|
||||
|
||||
if (!taskManager.isTaskScheduled(TASK_NAME)) {
|
||||
|
||||
TaskInfo taskInfo = new TaskInfo(TASK_NAME, deviceTaskManager.getTaskImplementedClazz(),
|
||||
properties, triggerInfo);
|
||||
|
||||
taskManager.registerTask(taskInfo);
|
||||
taskManager.rescheduleTask(taskInfo.getName());
|
||||
} else {
|
||||
throw new DeviceMgtTaskException("Device details retrieving task is already started for this tenant " +
|
||||
tenantId);
|
||||
}
|
||||
|
||||
} catch (TaskException e) {
|
||||
throw new DeviceMgtTaskException("Error occurred while creating the task for tenant " + tenantId, e);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stopTask() throws DeviceMgtTaskException {
|
||||
|
||||
try {
|
||||
TaskService taskService = DeviceManagementDataHolder.getInstance().getTaskService();
|
||||
if (taskService.isServerInit()) {
|
||||
TaskManager taskManager = taskService.getTaskManager(TASK_TYPE);
|
||||
taskManager.deleteTask(TASK_NAME);
|
||||
}
|
||||
} catch (TaskException e) {
|
||||
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
|
||||
throw new DeviceMgtTaskException("Error occurred while deleting the task for tenant " + tenantId, e);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateTask(int frequency) throws DeviceMgtTaskException {
|
||||
|
||||
if (!deviceTaskManager.isTaskEnabled()) {
|
||||
throw new DeviceMgtTaskException("Task cannot be updated, Please enable the task in cdm-config.xml file.");
|
||||
}
|
||||
|
||||
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
|
||||
deviceTaskManager = new DeviceTaskManagerImpl();
|
||||
try {
|
||||
TaskService taskService = DeviceManagementDataHolder.getInstance().getTaskService();
|
||||
TaskManager taskManager = taskService.getTaskManager(TASK_TYPE);
|
||||
|
||||
if (taskManager.isTaskScheduled(TASK_NAME)) {
|
||||
|
||||
taskManager.deleteTask(TASK_NAME);
|
||||
TaskInfo.TriggerInfo triggerInfo = new TaskInfo.TriggerInfo();
|
||||
triggerInfo.setIntervalMillis(frequency);
|
||||
triggerInfo.setRepeatCount(-1);
|
||||
|
||||
Map<String, String> properties = new HashMap<>();
|
||||
properties.put(TENANT_ID, String.valueOf(tenantId));
|
||||
|
||||
TaskInfo taskInfo = new TaskInfo(TASK_NAME, deviceTaskManager.getTaskImplementedClazz(), properties,
|
||||
triggerInfo);
|
||||
|
||||
taskManager.registerTask(taskInfo);
|
||||
taskManager.rescheduleTask(taskInfo.getName());
|
||||
} else {
|
||||
throw new DeviceMgtTaskException("Device details retrieving task has not been started for this tenant " +
|
||||
tenantId + ". Please start the task first.");
|
||||
}
|
||||
|
||||
} catch (TaskException e) {
|
||||
throw new DeviceMgtTaskException("Error occurred while updating the task for tenant " + tenantId, e);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,70 @@
|
||||
/*
|
||||
* Copyright (c) 2016, 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.search;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.testng.annotations.BeforeClass;
|
||||
import org.testng.annotations.Test;
|
||||
import org.wso2.carbon.device.mgt.common.device.details.DeviceWrapper;
|
||||
import org.wso2.carbon.device.mgt.common.search.Condition;
|
||||
import org.wso2.carbon.device.mgt.common.search.SearchContext;
|
||||
import org.wso2.carbon.device.mgt.core.common.BaseDeviceManagementTest;
|
||||
import org.wso2.carbon.device.mgt.core.search.mgt.SearchManagerService;
|
||||
import org.wso2.carbon.device.mgt.core.search.mgt.impl.SearchManagerServiceImpl;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class SearchDevice extends BaseDeviceManagementTest {
|
||||
|
||||
private static final Log log = LogFactory.getLog(DeviceDetails.class);
|
||||
|
||||
@BeforeClass
|
||||
@Override
|
||||
public void init() throws Exception {
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void searchDeviceDetails() throws Exception {
|
||||
|
||||
SearchContext context = new SearchContext();
|
||||
List<Condition> conditions = new ArrayList<>();
|
||||
Condition cond = new Condition();
|
||||
|
||||
cond.setKey("BATTERY_VOLTAGE");
|
||||
cond.setOperator("=");
|
||||
cond.setValue("40");
|
||||
cond.setState(Condition.State.AND);
|
||||
conditions.add(cond);
|
||||
context.setConditions(conditions);
|
||||
|
||||
SearchManagerService service = new SearchManagerServiceImpl();
|
||||
List<DeviceWrapper> deviceWrappers = service.search(context);
|
||||
|
||||
for (DeviceWrapper dw : deviceWrappers) {
|
||||
log.debug(dw.getDevice().getDescription());
|
||||
log.debug(dw.getDevice().getDeviceIdentifier());
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,159 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
~ Copyright (c) 2014, 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.
|
||||
-->
|
||||
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<parent>
|
||||
<groupId>org.wso2.carbon.devicemgt</groupId>
|
||||
<artifactId>email-sender</artifactId>
|
||||
<version>1.0.4-SNAPSHOT</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>org.wso2.carbon.devicemgt</groupId>
|
||||
<artifactId>org.wso2.carbon.email.sender.core</artifactId>
|
||||
<version>1.0.4-SNAPSHOT</version>
|
||||
<packaging>bundle</packaging>
|
||||
<name>WSO2 Carbon - Email Sender Core</name>
|
||||
<description>WSO2 Carbon - Email Sender Core</description>
|
||||
<url>http://wso2.org</url>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.felix</groupId>
|
||||
<artifactId>maven-scr-plugin</artifactId>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.felix</groupId>
|
||||
<artifactId>maven-bundle-plugin</artifactId>
|
||||
<version>1.4.0</version>
|
||||
<extensions>true</extensions>
|
||||
<configuration>
|
||||
<instructions>
|
||||
<Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName>
|
||||
<Bundle-Name>${project.artifactId}</Bundle-Name>
|
||||
<Bundle-Version>${carbon.device.mgt.version}</Bundle-Version>
|
||||
<Bundle-Description>Email Management Core Bundle</Bundle-Description>
|
||||
<Private-Package>org.wso2.carbon.email.sender.core.internal</Private-Package>
|
||||
<Import-Package>
|
||||
org.apache.axis2.*;version="${axis2.osgi.version.range}",
|
||||
org.apache.axiom.*; version="${axiom.osgi.version.range}",
|
||||
org.osgi.framework,
|
||||
org.osgi.service.component,
|
||||
org.apache.commons.logging,
|
||||
javax.xml.*,
|
||||
org.wso2.carbon.context,
|
||||
org.wso2.carbon.utils.*,
|
||||
org.wso2.carbon.registry.api,
|
||||
org.w3c.dom,
|
||||
org.apache.velocity,
|
||||
org.apache.velocity.app,
|
||||
org.apache.velocity.context,
|
||||
org.apache.velocity.exception,
|
||||
org.apache.velocity.runtime.resource,
|
||||
org.apache.velocity.runtime.resource.loader,
|
||||
org.apache.commons.io,
|
||||
org.apache.axis2.transport.mail,
|
||||
org.wso2.carbon.registry.core.service,
|
||||
org.wso2.carbon.registry.core.session,
|
||||
org.apache.commons.collections
|
||||
</Import-Package>
|
||||
<Export-Package>
|
||||
!org.wso2.carbon.email.sender.core.internal,
|
||||
org.wso2.carbon.email.sender.core.*
|
||||
</Export-Package>
|
||||
</instructions>
|
||||
</configuration>
|
||||
</plugin>
|
||||
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
<version>2.18</version>
|
||||
<configuration>
|
||||
<systemPropertyVariables>
|
||||
<log4j.configuration>file:src/test/resources/log4j.properties</log4j.configuration>
|
||||
</systemPropertyVariables>
|
||||
<suiteXmlFiles>
|
||||
<suiteXmlFile>src/test/resources/testng.xml</suiteXmlFile>
|
||||
</suiteXmlFiles>
|
||||
</configuration>
|
||||
</plugin>
|
||||
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.osgi</groupId>
|
||||
<artifactId>org.eclipse.osgi</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.osgi</groupId>
|
||||
<artifactId>org.eclipse.osgi.services</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.wso2.carbon</groupId>
|
||||
<artifactId>org.wso2.carbon.logging</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.wso2.carbon</groupId>
|
||||
<artifactId>org.wso2.carbon.utils</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.testng</groupId>
|
||||
<artifactId>testng</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.wso2.carbon</groupId>
|
||||
<artifactId>org.wso2.carbon.registry.api</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.wso2.carbon</groupId>
|
||||
<artifactId>org.wso2.carbon.base</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.axis2.wso2</groupId>
|
||||
<artifactId>axis2</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.velocity</groupId>
|
||||
<artifactId>velocity</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>commons-io.wso2</groupId>
|
||||
<artifactId>commons-io</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.axis2.transport</groupId>
|
||||
<artifactId>axis2-transport-mail</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.wso2.carbon</groupId>
|
||||
<artifactId>org.wso2.carbon.registry.core</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>commons-collections.wso2</groupId>
|
||||
<artifactId>commons-collections</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
|
@ -0,0 +1,45 @@
|
||||
/*
|
||||
* Copyright (c) 2016, 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.email.sender.core;
|
||||
|
||||
public class ContentProcessingInterruptedException extends Exception {
|
||||
|
||||
private static final long serialVersionUID = -3151279311929070298L;
|
||||
|
||||
public ContentProcessingInterruptedException(String msg, Exception nestedEx) {
|
||||
super(msg, nestedEx);
|
||||
}
|
||||
|
||||
public ContentProcessingInterruptedException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
|
||||
public ContentProcessingInterruptedException(String msg) {
|
||||
super(msg);
|
||||
}
|
||||
|
||||
public ContentProcessingInterruptedException() {
|
||||
super();
|
||||
}
|
||||
|
||||
public ContentProcessingInterruptedException(Throwable cause) {
|
||||
super(cause);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,55 @@
|
||||
/*
|
||||
* Copyright (c) 2016, 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.email.sender.core;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public class ContentProviderInfo {
|
||||
|
||||
private String template;
|
||||
private Map<String, TypedValue<Class<?>, Object>> params;
|
||||
|
||||
public ContentProviderInfo(final String template, final Map<String, TypedValue<Class<?>, Object>> params) {
|
||||
if (template == null || template.isEmpty()) {
|
||||
throw new IllegalArgumentException("Template name cannot be null or empty");
|
||||
}
|
||||
this.template = template;
|
||||
if (params == null) {
|
||||
throw new IllegalArgumentException("Place-holder parameter map cannot be null");
|
||||
}
|
||||
this.params = params;
|
||||
}
|
||||
|
||||
public String getTemplate() {
|
||||
return template;
|
||||
}
|
||||
|
||||
public Map<String, TypedValue<Class<?>, Object>> getParams() {
|
||||
return params;
|
||||
}
|
||||
|
||||
public void addParam(String name, TypedValue<Class<?>, Object> param) {
|
||||
params.put(name, param);
|
||||
}
|
||||
|
||||
public TypedValue<Class<?>, Object> getParam(String name) {
|
||||
return params.get(name);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,28 @@
|
||||
/*
|
||||
* Copyright (c) 2016, 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.email.sender.core;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public interface EmailContentProvider {
|
||||
|
||||
EmailData getContent(String path,
|
||||
Map<String, TypedValue<Class<?>, Object>> params) throws ContentProcessingInterruptedException;
|
||||
|
||||
}
|
@ -0,0 +1,27 @@
|
||||
/*
|
||||
* Copyright (c) 2016, 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.email.sender.core;
|
||||
|
||||
public class EmailContentProviderFactory {
|
||||
|
||||
public static EmailContentProvider getContentProvider() {
|
||||
return new VelocityBasedEmailContentProvider();
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,138 @@
|
||||
/*
|
||||
* Copyright (c) 2016, 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.email.sender.core;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class EmailContext {
|
||||
|
||||
private Set<String> recipients;
|
||||
private Properties properties;
|
||||
private ContentProviderInfo contentProviderInfo;
|
||||
|
||||
private EmailContext(final ContentProviderInfo contentProviderInfo, final Set<String> recipients, final Properties properties) {
|
||||
if (contentProviderInfo == null) {
|
||||
throw new IllegalArgumentException("Content provider information cannot be null");
|
||||
}
|
||||
this.contentProviderInfo = contentProviderInfo;
|
||||
if (recipients == null) {
|
||||
throw new IllegalArgumentException("Recipient list cannot be null");
|
||||
}
|
||||
if (recipients.size() == 0) {
|
||||
throw new IllegalArgumentException("No recipient is configured. Recipient list should carry at " +
|
||||
"least one recipient");
|
||||
}
|
||||
this.recipients = recipients;
|
||||
if (properties == null) {
|
||||
throw new IllegalArgumentException("Email Context property bag cannot be null");
|
||||
}
|
||||
this.properties = properties;
|
||||
}
|
||||
|
||||
private EmailContext(final ContentProviderInfo contentProviderInfo, final String recipient, final Properties properties) {
|
||||
if (contentProviderInfo == null) {
|
||||
throw new IllegalArgumentException("Content provider information cannot be null");
|
||||
}
|
||||
this.contentProviderInfo = contentProviderInfo;
|
||||
if (recipient == null || recipient.isEmpty()) {
|
||||
throw new IllegalArgumentException("Recipient can't be null or empty. Please specify a valid " +
|
||||
"recipient email address");
|
||||
}
|
||||
this.recipients = new HashSet<String>() {{
|
||||
add(recipient);
|
||||
}};
|
||||
if (properties == null) {
|
||||
throw new IllegalArgumentException("Email Context property bag cannot be null");
|
||||
}
|
||||
this.properties = properties;
|
||||
}
|
||||
|
||||
public Set<String> getRecipients() {
|
||||
return recipients;
|
||||
}
|
||||
|
||||
public Properties getProperties() {
|
||||
return properties;
|
||||
}
|
||||
|
||||
public String getProperty(String name) {
|
||||
return (String) properties.get(name);
|
||||
}
|
||||
|
||||
public void addProperty(String name, String value) {
|
||||
properties.put(name, value);
|
||||
}
|
||||
|
||||
public ContentProviderInfo getContentProviderInfo() {
|
||||
return contentProviderInfo;
|
||||
}
|
||||
|
||||
public static class EmailContextBuilder {
|
||||
|
||||
private Set<String> recipients;
|
||||
private ContentProviderInfo contentProviderInfo;
|
||||
private Properties properties;
|
||||
|
||||
public EmailContextBuilder(final ContentProviderInfo contentProviderInfo, Set<String> recipients) {
|
||||
if (contentProviderInfo == null) {
|
||||
throw new IllegalArgumentException("Content provider information cannot be null");
|
||||
}
|
||||
this.contentProviderInfo = contentProviderInfo;
|
||||
if (recipients == null) {
|
||||
throw new IllegalArgumentException("Recipient list cannot be null");
|
||||
}
|
||||
if (recipients.size() == 0) {
|
||||
throw new IllegalArgumentException("No recipient is configured. Recipient list should carry at " +
|
||||
"least one recipient");
|
||||
}
|
||||
this.recipients = recipients;
|
||||
this.properties = new Properties();
|
||||
}
|
||||
|
||||
public EmailContextBuilder(final ContentProviderInfo contentProviderInfo, final String recipient,
|
||||
final Properties properties) {
|
||||
if (contentProviderInfo == null) {
|
||||
throw new IllegalArgumentException("Content provider information cannot be null");
|
||||
}
|
||||
this.contentProviderInfo = contentProviderInfo;
|
||||
if (recipient == null || recipient.isEmpty()) {
|
||||
throw new IllegalArgumentException("Recipient can't be null or empty. Please specify a valid " +
|
||||
"recipient email address");
|
||||
}
|
||||
this.recipients = new HashSet<String>() {{
|
||||
add(recipient);
|
||||
}};
|
||||
if (properties == null) {
|
||||
throw new IllegalArgumentException("Email Context property bag cannot be null");
|
||||
}
|
||||
this.properties = properties;
|
||||
}
|
||||
|
||||
public EmailContextBuilder addProperty(String name, String value) {
|
||||
properties.setProperty(name, value);
|
||||
return this;
|
||||
}
|
||||
|
||||
public EmailContext build() {
|
||||
return new EmailContext(contentProviderInfo, recipients, properties);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,48 @@
|
||||
/*
|
||||
* Copyright (c) 2016, 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.email.sender.core;
|
||||
|
||||
import javax.xml.bind.annotation.XmlElement;
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
|
||||
@XmlRootElement(name = "EmailConfig")
|
||||
public class EmailData {
|
||||
|
||||
private String subject;
|
||||
private String body;
|
||||
|
||||
@XmlElement(name = "Subject", required = true)
|
||||
public String getSubject() {
|
||||
return subject;
|
||||
}
|
||||
|
||||
public void setSubject(String subject) {
|
||||
this.subject = subject;
|
||||
}
|
||||
|
||||
@XmlElement(name = "Body", required = true)
|
||||
public String getBody() {
|
||||
return body;
|
||||
}
|
||||
|
||||
public void setBody(String body) {
|
||||
this.body = body;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,106 @@
|
||||
/*
|
||||
* Copyright (c) 2016, 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.email.sender.core;
|
||||
|
||||
import org.w3c.dom.Document;
|
||||
import org.wso2.carbon.utils.CarbonUtils;
|
||||
|
||||
import javax.xml.bind.JAXBContext;
|
||||
import javax.xml.bind.JAXBException;
|
||||
import javax.xml.bind.Unmarshaller;
|
||||
import javax.xml.bind.annotation.XmlElement;
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
import java.io.File;
|
||||
|
||||
@XmlRootElement(name = "EmailSenderConfig")
|
||||
public class EmailSenderConfig {
|
||||
|
||||
private int minThreads;
|
||||
private int maxThreads;
|
||||
private int keepAliveDuration;
|
||||
private int threadQueueCapacity;
|
||||
|
||||
private static EmailSenderConfig config;
|
||||
|
||||
private static final String EMAIL_SENDER_CONFIG_PATH =
|
||||
CarbonUtils.getEtcCarbonConfigDirPath() + File.separator + "email-sender-config.xml";
|
||||
|
||||
private EmailSenderConfig() {
|
||||
}
|
||||
|
||||
public static EmailSenderConfig getInstance() {
|
||||
if (config == null) {
|
||||
throw new InvalidConfigurationStateException("Webapp Authenticator Configuration is not " +
|
||||
"initialized properly");
|
||||
}
|
||||
return config;
|
||||
}
|
||||
|
||||
@XmlElement(name = "MinThreads", required = true)
|
||||
public int getMinThreads() {
|
||||
return minThreads;
|
||||
}
|
||||
|
||||
public void setMinThreads(int minThreads) {
|
||||
this.minThreads = minThreads;
|
||||
}
|
||||
|
||||
@XmlElement(name = "MaxThreads", required = true)
|
||||
public int getMaxThreads() {
|
||||
return maxThreads;
|
||||
}
|
||||
|
||||
public void setMaxThreads(int maxThreads) {
|
||||
this.maxThreads = maxThreads;
|
||||
}
|
||||
|
||||
@XmlElement(name = "KeepAliveDuration", required = true)
|
||||
public int getKeepAliveDuration() {
|
||||
return keepAliveDuration;
|
||||
}
|
||||
|
||||
public void setKeepAliveDuration(int keepAliveDuration) {
|
||||
this.keepAliveDuration = keepAliveDuration;
|
||||
}
|
||||
@XmlElement(name = "ThreadQueueCapacity", required = true)
|
||||
public int getThreadQueueCapacity() {
|
||||
return threadQueueCapacity;
|
||||
}
|
||||
|
||||
public void setThreadQueueCapacity(int threadQueueCapacity) {
|
||||
this.threadQueueCapacity = threadQueueCapacity;
|
||||
}
|
||||
|
||||
public static void init() throws EmailSenderConfigurationFailedException {
|
||||
try {
|
||||
File emailSenderConfig = new File(EMAIL_SENDER_CONFIG_PATH);
|
||||
Document doc = EmailSenderUtil.convertToDocument(emailSenderConfig);
|
||||
|
||||
/* Un-marshaling Email Sender configuration */
|
||||
JAXBContext ctx = JAXBContext.newInstance(EmailSenderConfig.class);
|
||||
Unmarshaller unmarshaller = ctx.createUnmarshaller();
|
||||
//unmarshaller.setSchema(getSchema());
|
||||
config = (EmailSenderConfig) unmarshaller.unmarshal(doc);
|
||||
} catch (JAXBException e) {
|
||||
throw new EmailSenderConfigurationFailedException("Error occurred while un-marshalling Email " +
|
||||
"Sender Config", e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,45 @@
|
||||
/*
|
||||
* Copyright (c) 2016, 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.email.sender.core;
|
||||
|
||||
public class EmailSenderConfigurationFailedException extends Exception {
|
||||
|
||||
private static final long serialVersionUID = -3151279312929070298L;
|
||||
|
||||
public EmailSenderConfigurationFailedException(String msg, Exception nestedEx) {
|
||||
super(msg, nestedEx);
|
||||
}
|
||||
|
||||
public EmailSenderConfigurationFailedException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
|
||||
public EmailSenderConfigurationFailedException(String msg) {
|
||||
super(msg);
|
||||
}
|
||||
|
||||
public EmailSenderConfigurationFailedException() {
|
||||
super();
|
||||
}
|
||||
|
||||
public EmailSenderConfigurationFailedException(Throwable cause) {
|
||||
super(cause);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,45 @@
|
||||
/*
|
||||
* Copyright (c) 2016, 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.email.sender.core;
|
||||
|
||||
import org.w3c.dom.Document;
|
||||
import org.wso2.carbon.email.sender.core.internal.EmailSenderDataHolder;
|
||||
import org.wso2.carbon.utils.CarbonUtils;
|
||||
import org.wso2.carbon.utils.ConfigurationContextService;
|
||||
import org.wso2.carbon.utils.NetworkUtils;
|
||||
|
||||
import javax.xml.parsers.DocumentBuilder;
|
||||
import javax.xml.parsers.DocumentBuilderFactory;
|
||||
import java.io.File;
|
||||
|
||||
public class EmailSenderUtil {
|
||||
|
||||
public static Document convertToDocument(File file) throws EmailSenderConfigurationFailedException {
|
||||
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
|
||||
factory.setNamespaceAware(true);
|
||||
try {
|
||||
DocumentBuilder docBuilder = factory.newDocumentBuilder();
|
||||
return docBuilder.parse(file);
|
||||
} catch (Exception e) {
|
||||
throw new EmailSenderConfigurationFailedException("Error occurred while parsing file, while converting " +
|
||||
"to a org.w3c.dom.Document", e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,45 @@
|
||||
/*
|
||||
* Copyright (c) 2016, 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.email.sender.core;
|
||||
|
||||
public class EmailSendingFailedException extends Exception {
|
||||
|
||||
private static final long serialVersionUID = -3151279311929070294L;
|
||||
|
||||
public EmailSendingFailedException(String msg, Exception nestedEx) {
|
||||
super(msg, nestedEx);
|
||||
}
|
||||
|
||||
public EmailSendingFailedException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
|
||||
public EmailSendingFailedException(String msg) {
|
||||
super(msg);
|
||||
}
|
||||
|
||||
public EmailSendingFailedException() {
|
||||
super();
|
||||
}
|
||||
|
||||
public EmailSendingFailedException(Throwable cause) {
|
||||
super(cause);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,74 @@
|
||||
/*
|
||||
* 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.email.sender.core;
|
||||
|
||||
public class InvalidConfigurationStateException extends RuntimeException {
|
||||
|
||||
private static final long serialVersionUID = -3151279311329070297L;
|
||||
|
||||
private String errorMessage;
|
||||
private int errorCode;
|
||||
|
||||
public InvalidConfigurationStateException(int errorCode, String message) {
|
||||
super(message);
|
||||
this.errorCode = errorCode;
|
||||
}
|
||||
|
||||
public InvalidConfigurationStateException(int errorCode, String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
this.errorCode = errorCode;
|
||||
}
|
||||
|
||||
public int getErrorCode() {
|
||||
return errorCode;
|
||||
}
|
||||
|
||||
|
||||
public String getErrorMessage() {
|
||||
return errorMessage;
|
||||
}
|
||||
|
||||
public void setErrorMessage(String errorMessage) {
|
||||
this.errorMessage = errorMessage;
|
||||
}
|
||||
|
||||
public InvalidConfigurationStateException(String msg, Exception nestedEx) {
|
||||
super(msg, nestedEx);
|
||||
setErrorMessage(msg);
|
||||
}
|
||||
|
||||
public InvalidConfigurationStateException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
setErrorMessage(message);
|
||||
}
|
||||
|
||||
public InvalidConfigurationStateException(String msg) {
|
||||
super(msg);
|
||||
setErrorMessage(msg);
|
||||
}
|
||||
|
||||
public InvalidConfigurationStateException() {
|
||||
super();
|
||||
}
|
||||
|
||||
public InvalidConfigurationStateException(Throwable cause) {
|
||||
super(cause);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,71 @@
|
||||
/*
|
||||
* Copyright (c) 2016, 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.email.sender.core;
|
||||
|
||||
import org.apache.commons.collections.ExtendedProperties;
|
||||
import org.apache.velocity.exception.ResourceNotFoundException;
|
||||
import org.apache.velocity.runtime.resource.Resource;
|
||||
import org.apache.velocity.runtime.resource.loader.ResourceLoader;
|
||||
import org.wso2.carbon.context.CarbonContext;
|
||||
import org.wso2.carbon.context.RegistryType;
|
||||
import org.wso2.carbon.registry.api.Registry;
|
||||
import org.wso2.carbon.registry.api.RegistryException;
|
||||
|
||||
import java.io.*;
|
||||
|
||||
public class RegistryBasedResourceLoader extends ResourceLoader {
|
||||
|
||||
private static final String EMAIL_CONFIG_BASE_LOCATION = "email-templates";
|
||||
|
||||
@Override
|
||||
public void init(ExtendedProperties extendedProperties) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public InputStream getResourceStream(String name) throws ResourceNotFoundException {
|
||||
try {
|
||||
Registry registry =
|
||||
CarbonContext.getThreadLocalCarbonContext().getRegistry(RegistryType.SYSTEM_CONFIGURATION);
|
||||
if (registry == null) {
|
||||
throw new IllegalStateException("No valid registry instance is attached to the current carbon context");
|
||||
}
|
||||
if (!registry.resourceExists(EMAIL_CONFIG_BASE_LOCATION + "/" + name + ".vm")) {
|
||||
throw new ResourceNotFoundException("Resource '" + name + "' does not exist");
|
||||
}
|
||||
org.wso2.carbon.registry.api.Resource resource =
|
||||
registry.get(EMAIL_CONFIG_BASE_LOCATION + "/" + name + ".vm");
|
||||
|
||||
return resource.getContentStream();
|
||||
} catch (RegistryException e) {
|
||||
throw new ResourceNotFoundException("Error occurred while retrieving resource", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSourceModified(Resource resource) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getLastModified(Resource resource) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,50 @@
|
||||
/*
|
||||
* Copyright (c) 2016, 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.email.sender.core;
|
||||
|
||||
public class TypedValue<T, V> {
|
||||
|
||||
private final T type;
|
||||
private final V value;
|
||||
|
||||
public TypedValue(T type, V value) {
|
||||
this.type = type;
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public T getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public V getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return (type.hashCode() ^ value.hashCode());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
return o instanceof TypedValue && (this.type == ((TypedValue) o).getType() &&
|
||||
this.value == ((TypedValue) o).getValue());
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,87 @@
|
||||
/*
|
||||
* Copyright (c) 2016, 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.email.sender.core;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.apache.velocity.Template;
|
||||
import org.apache.velocity.VelocityContext;
|
||||
import org.apache.velocity.app.VelocityEngine;
|
||||
import org.apache.velocity.runtime.resource.loader.ResourceLoader;
|
||||
import org.wso2.carbon.context.CarbonContext;
|
||||
import org.wso2.carbon.context.RegistryType;
|
||||
import org.wso2.carbon.registry.api.Registry;
|
||||
|
||||
import javax.xml.bind.JAXBContext;
|
||||
import javax.xml.bind.JAXBException;
|
||||
import javax.xml.bind.Unmarshaller;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.StringWriter;
|
||||
import java.util.Map;
|
||||
|
||||
public class VelocityBasedEmailContentProvider implements EmailContentProvider {
|
||||
|
||||
private VelocityEngine engine;
|
||||
private static final Log log = LogFactory.getLog(VelocityBasedEmailContentProvider.class);
|
||||
|
||||
public VelocityBasedEmailContentProvider() {
|
||||
engine = new VelocityEngine();
|
||||
engine.setProperty("resource.loader", "registry");
|
||||
engine.setProperty("velocimacro.library", "");
|
||||
engine.setProperty("registry.resource.loader.class",
|
||||
"org.wso2.carbon.email.sender.core.RegistryBasedResourceLoader");
|
||||
engine.init();
|
||||
}
|
||||
|
||||
@Override
|
||||
public EmailData getContent(String name, Map<String,
|
||||
TypedValue<Class<?>, Object>> params) throws ContentProcessingInterruptedException {
|
||||
VelocityContext ctx = new VelocityContext();
|
||||
for (Map.Entry<String, TypedValue<Class<?>, Object>> param : params.entrySet()) {
|
||||
ctx.put(param.getKey(), param.getValue().getValue());
|
||||
}
|
||||
Template template = engine.getTemplate(name);
|
||||
|
||||
StringWriter content = new StringWriter();
|
||||
template.merge(ctx, content);
|
||||
|
||||
InputStream is = null;
|
||||
try {
|
||||
JAXBContext jaxbCtx = JAXBContext.newInstance(EmailData.class);
|
||||
Unmarshaller unmarshaller = jaxbCtx.createUnmarshaller();
|
||||
|
||||
is = new ByteArrayInputStream(content.toString().getBytes());
|
||||
return (EmailData) unmarshaller.unmarshal(is);
|
||||
} catch (JAXBException e) {
|
||||
throw new ContentProcessingInterruptedException("Error occurred while parsing email data", e);
|
||||
} finally {
|
||||
if (is != null) {
|
||||
try {
|
||||
is.close();
|
||||
} catch (IOException e) {
|
||||
log.warn("Error occurred while closing input stream used to convert email configuration " +
|
||||
"to an internal object model", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,111 @@
|
||||
/*
|
||||
* 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.email.sender.core.internal;
|
||||
|
||||
import org.apache.axis2.context.ConfigurationContext;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.wso2.carbon.context.CarbonContext;
|
||||
import org.wso2.carbon.context.RegistryType;
|
||||
import org.wso2.carbon.email.sender.core.EmailSenderConfigurationFailedException;
|
||||
import org.wso2.carbon.registry.api.Collection;
|
||||
import org.wso2.carbon.registry.api.Registry;
|
||||
import org.wso2.carbon.registry.api.RegistryException;
|
||||
import org.wso2.carbon.registry.api.Resource;
|
||||
import org.wso2.carbon.utils.Axis2ConfigurationContextObserver;
|
||||
import org.wso2.carbon.utils.CarbonUtils;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FilenameFilter;
|
||||
|
||||
public class EmailSenderAxis2ConfigContextObserver implements Axis2ConfigurationContextObserver {
|
||||
|
||||
private static final String EMAIL_TEMPLATE_DIR_RELATIVE_REGISTRY_PATH = "email-templates";
|
||||
private static final Log log = LogFactory.getLog(EmailSenderAxis2ConfigContextObserver.class);
|
||||
|
||||
@Override
|
||||
public void creatingConfigurationContext(int tenantId) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void createdConfigurationContext(ConfigurationContext configurationContext) {
|
||||
try {
|
||||
this.setupEmailTemplates();
|
||||
} catch (EmailSenderConfigurationFailedException e) {
|
||||
log.error("Error occurred while setting up email templates", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void terminatingConfigurationContext(ConfigurationContext configurationContext) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void terminatedConfigurationContext(ConfigurationContext configurationContext) {
|
||||
|
||||
}
|
||||
|
||||
private void setupEmailTemplates() throws EmailSenderConfigurationFailedException {
|
||||
File templateDir =
|
||||
new File(CarbonUtils.getCarbonRepository() + "resources" + File.separator + "email-templates");
|
||||
if (!templateDir.exists()) {
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("The directory that is expected to use as the container for all email templates is not " +
|
||||
"available. Therefore, no template is uploaded to the registry");
|
||||
}
|
||||
}
|
||||
if (templateDir.canRead()) {
|
||||
File[] templates = templateDir.listFiles(new FilenameFilter() {
|
||||
@Override
|
||||
public boolean accept(File dir, String name) {
|
||||
name = name.toLowerCase();
|
||||
return name.endsWith(".vm");
|
||||
}
|
||||
});
|
||||
try {
|
||||
Registry registry =
|
||||
CarbonContext.getThreadLocalCarbonContext().getRegistry(RegistryType.SYSTEM_CONFIGURATION);
|
||||
if (!registry.resourceExists(EMAIL_TEMPLATE_DIR_RELATIVE_REGISTRY_PATH)) {
|
||||
Collection collection = registry.newCollection();
|
||||
registry.put(EMAIL_TEMPLATE_DIR_RELATIVE_REGISTRY_PATH, collection);
|
||||
for (File template : templates) {
|
||||
Resource resource = registry.newResource();
|
||||
resource.setContent(template);
|
||||
registry.put(EMAIL_TEMPLATE_DIR_RELATIVE_REGISTRY_PATH + "/" + template.getName(), resource);
|
||||
}
|
||||
} else {
|
||||
for (File template : templates) {
|
||||
if (!registry.resourceExists(
|
||||
EMAIL_TEMPLATE_DIR_RELATIVE_REGISTRY_PATH + "/" + template.getName())) {
|
||||
Resource resource = registry.newResource();
|
||||
resource.setContent(template);
|
||||
registry.put(
|
||||
EMAIL_TEMPLATE_DIR_RELATIVE_REGISTRY_PATH + "/" + template.getName(), resource);
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (RegistryException e) {
|
||||
throw new EmailSenderConfigurationFailedException("Error occurred while setting up email templates", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,69 @@
|
||||
/*
|
||||
* Copyright (c) 2014, 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.email.sender.core.internal;
|
||||
|
||||
import org.wso2.carbon.email.sender.core.service.EmailSenderService;
|
||||
import org.wso2.carbon.registry.core.service.RegistryService;
|
||||
import org.wso2.carbon.utils.ConfigurationContextService;
|
||||
|
||||
public class EmailSenderDataHolder {
|
||||
|
||||
private RegistryService registryService;
|
||||
private ConfigurationContextService configurationContextService;
|
||||
private EmailSenderService emailServiceProvider;
|
||||
|
||||
private static EmailSenderDataHolder thisInstance = new EmailSenderDataHolder();
|
||||
|
||||
private EmailSenderDataHolder() {}
|
||||
|
||||
public static EmailSenderDataHolder getInstance() {
|
||||
return thisInstance;
|
||||
}
|
||||
|
||||
public RegistryService getRegistryService() {
|
||||
if (registryService == null) {
|
||||
throw new IllegalStateException("Registry service is not initialized properly");
|
||||
}
|
||||
return registryService;
|
||||
}
|
||||
|
||||
public void setRegistryService(RegistryService registryService) {
|
||||
this.registryService = registryService;
|
||||
}
|
||||
|
||||
public ConfigurationContextService getConfigurationContextService() {
|
||||
if (configurationContextService == null) {
|
||||
throw new IllegalStateException("ConfigurationContext service is not initialized properly");
|
||||
}
|
||||
return configurationContextService;
|
||||
}
|
||||
|
||||
public void setConfigurationContextService(ConfigurationContextService configurationContextService) {
|
||||
this.configurationContextService = configurationContextService;
|
||||
}
|
||||
|
||||
public EmailSenderService getEmailServiceProvider() {
|
||||
return emailServiceProvider;
|
||||
}
|
||||
|
||||
public void setEmailServiceProvider(EmailSenderService emailServiceProvider) {
|
||||
this.emailServiceProvider = emailServiceProvider;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,195 @@
|
||||
/*
|
||||
* Copyright (c) 2014, 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.email.sender.core.internal;
|
||||
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.osgi.service.component.ComponentContext;
|
||||
import org.wso2.carbon.email.sender.core.EmailSenderConfig;
|
||||
import org.wso2.carbon.email.sender.core.EmailSenderConfigurationFailedException;
|
||||
import org.wso2.carbon.email.sender.core.service.EmailSenderService;
|
||||
import org.wso2.carbon.email.sender.core.service.EmailSenderServiceImpl;
|
||||
import org.wso2.carbon.registry.api.Collection;
|
||||
import org.wso2.carbon.registry.api.Registry;
|
||||
import org.wso2.carbon.registry.api.RegistryException;
|
||||
import org.wso2.carbon.registry.api.Resource;
|
||||
import org.wso2.carbon.registry.core.service.RegistryService;
|
||||
import org.wso2.carbon.utils.CarbonUtils;
|
||||
import org.wso2.carbon.utils.ConfigurationContextService;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FilenameFilter;
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* @scr.component name="org.wso2.carbon.email.sender.EmailSenderServiceComponent" immediate="true"
|
||||
* @scr.reference name="registry.service"
|
||||
* interface="org.wso2.carbon.registry.core.service.RegistryService"
|
||||
* cardinality="1..1"
|
||||
* policy="dynamic"
|
||||
* bind="setRegistryService"
|
||||
* unbind="unsetRegistryService"
|
||||
* @scr.reference name="config.context.service"
|
||||
* interface="org.wso2.carbon.utils.ConfigurationContextService"
|
||||
* cardinality="0..1"
|
||||
* policy="dynamic"
|
||||
* bind="setConfigurationContextService"
|
||||
* unbind="unsetConfigurationContextService"
|
||||
*/
|
||||
public class EmailSenderServiceComponent {
|
||||
|
||||
private static Log log = LogFactory.getLog(EmailSenderServiceComponent.class);
|
||||
|
||||
private static final String EMAIL_TEMPLATE_DIR_RELATIVE_REGISTRY_PATH = "/email-templates";
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
protected void activate(ComponentContext componentContext) {
|
||||
try {
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Initializing email sender core bundle");
|
||||
}
|
||||
/* Initializing email sende configuration */
|
||||
EmailSenderConfig.init();
|
||||
|
||||
/* Setting up default email templates */
|
||||
this.setupEmailTemplates();
|
||||
|
||||
/* Registering declarative service instances exposed by EmailSenderServiceComponent */
|
||||
this.registerServices(componentContext);
|
||||
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Email sender core bundle has been successfully initialized");
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
log.error("Error occurred while initializing email sender core bundle", e);
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
protected void deactivate(ComponentContext componentContext) {
|
||||
//do nothing
|
||||
}
|
||||
|
||||
private void registerServices(ComponentContext componentContext) {
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Registering email sender service");
|
||||
}
|
||||
EmailSenderService emailServiceProvider = new EmailSenderServiceImpl();
|
||||
EmailSenderDataHolder.getInstance().setEmailServiceProvider(emailServiceProvider);
|
||||
componentContext.getBundleContext().registerService(EmailSenderService.class, emailServiceProvider, null);
|
||||
}
|
||||
|
||||
private void setupEmailTemplates() throws EmailSenderConfigurationFailedException {
|
||||
File templateDir =
|
||||
new File(CarbonUtils.getCarbonHome() + File.separator + "repository" + File.separator +
|
||||
"resources" + File.separator + "email-templates");
|
||||
if (!templateDir.exists()) {
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("The directory that is expected to use as the container for all email templates is not " +
|
||||
"available. Therefore, no template is uploaded to the registry");
|
||||
}
|
||||
}
|
||||
if (templateDir.canRead()) {
|
||||
File[] templates = templateDir.listFiles(new FilenameFilter() {
|
||||
@Override
|
||||
public boolean accept(File dir, String name) {
|
||||
name = name.toLowerCase();
|
||||
return name.endsWith(".vm");
|
||||
}
|
||||
});
|
||||
try {
|
||||
Registry registry =
|
||||
EmailSenderDataHolder.getInstance().getRegistryService().getConfigSystemRegistry();
|
||||
if (!registry.resourceExists(EMAIL_TEMPLATE_DIR_RELATIVE_REGISTRY_PATH)) {
|
||||
Collection collection = registry.newCollection();
|
||||
registry.put(EMAIL_TEMPLATE_DIR_RELATIVE_REGISTRY_PATH, collection);
|
||||
for (File template : templates) {
|
||||
Resource resource = registry.newResource();
|
||||
String contents = FileUtils.readFileToString(template);
|
||||
resource.setContent(contents.getBytes());
|
||||
registry.put(EMAIL_TEMPLATE_DIR_RELATIVE_REGISTRY_PATH + "/" + template.getName(), resource);
|
||||
}
|
||||
} else {
|
||||
/* Existence of a given resource is not checked consciously, before performing registry.put() below.
|
||||
* The rationale is that, the only less expensive way that one can check if a resource exists is
|
||||
* that through registry.resourceExists(), which only checks if 'some' resource exists at the given
|
||||
* registry path. However, this does not capture scenarios where there can be updated contents to
|
||||
* the same resource of which the path hasn't changed after it has been initialized for the first
|
||||
* time. Therefore, whenever the server starts-up, all email templates are updated just to avoid
|
||||
* the aforementioned problem */
|
||||
for (File template : templates) {
|
||||
Resource resource = registry.newResource();
|
||||
String contents = FileUtils.readFileToString(template);
|
||||
resource.setContent(contents.getBytes());
|
||||
registry.put(
|
||||
EMAIL_TEMPLATE_DIR_RELATIVE_REGISTRY_PATH + "/" + template.getName(), resource);
|
||||
}
|
||||
}
|
||||
} catch (RegistryException e) {
|
||||
throw new EmailSenderConfigurationFailedException("Error occurred while setting up email templates", e);
|
||||
} catch (FileNotFoundException e) {
|
||||
throw new EmailSenderConfigurationFailedException("Error occurred while writing template file " +
|
||||
"contents as an input stream of a resource", e);
|
||||
} catch (IOException e) {
|
||||
throw new EmailSenderConfigurationFailedException("Error occurred while serializing file " +
|
||||
"contents to a string", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets Registry Service.
|
||||
*
|
||||
* @param registryService An instance of RegistryService
|
||||
*/
|
||||
protected void setRegistryService(RegistryService registryService) {
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Setting Registry Service");
|
||||
}
|
||||
EmailSenderDataHolder.getInstance().setRegistryService(registryService);
|
||||
}
|
||||
|
||||
/**
|
||||
* Unsets Registry Service.
|
||||
*
|
||||
* @param registryService An instance of RegistryService
|
||||
*/
|
||||
protected void unsetRegistryService(RegistryService registryService) {
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Un setting Registry Service");
|
||||
}
|
||||
EmailSenderDataHolder.getInstance().setRegistryService(null);
|
||||
}
|
||||
|
||||
protected void setConfigurationContextService(ConfigurationContextService configurationContextService) {
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Setting ConfigurationContextService");
|
||||
}
|
||||
EmailSenderDataHolder.getInstance().setConfigurationContextService(configurationContextService);
|
||||
}
|
||||
|
||||
protected void unsetConfigurationContextService(ConfigurationContextService configurationContextService) {
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Un-setting ConfigurationContextService");
|
||||
}
|
||||
EmailSenderDataHolder.getInstance().setConfigurationContextService(null);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,129 @@
|
||||
/*
|
||||
* 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.email.sender.core.service;
|
||||
|
||||
import org.apache.axiom.om.OMElement;
|
||||
import org.apache.axiom.om.impl.llom.util.AXIOMUtil;
|
||||
import org.apache.axis2.AxisFault;
|
||||
import org.apache.axis2.Constants;
|
||||
import org.apache.axis2.addressing.EndpointReference;
|
||||
import org.apache.axis2.client.Options;
|
||||
import org.apache.axis2.client.ServiceClient;
|
||||
import org.apache.axis2.context.ConfigurationContext;
|
||||
import org.apache.axis2.context.MessageContext;
|
||||
import org.apache.axis2.transport.mail.MailConstants;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.wso2.carbon.email.sender.core.*;
|
||||
import org.wso2.carbon.email.sender.core.internal.EmailSenderDataHolder;
|
||||
import org.wso2.carbon.utils.ConfigurationContextService;
|
||||
|
||||
import javax.xml.stream.XMLStreamException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.LinkedBlockingQueue;
|
||||
import java.util.concurrent.ThreadPoolExecutor;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
public class EmailSenderServiceImpl implements EmailSenderService {
|
||||
|
||||
private static ThreadPoolExecutor threadPoolExecutor;
|
||||
private EmailContentProvider contentProvider;
|
||||
|
||||
static {
|
||||
EmailSenderConfig config = EmailSenderConfig.getInstance();
|
||||
threadPoolExecutor = new ThreadPoolExecutor(config.getMinThreads(), config.getMaxThreads(),
|
||||
config.getKeepAliveDuration(), TimeUnit.SECONDS,
|
||||
new LinkedBlockingQueue<Runnable>(config.getThreadQueueCapacity()));
|
||||
}
|
||||
|
||||
private static final String EMAIL_URI_SCHEME = "mailto:";
|
||||
private static Log log = LogFactory.getLog(EmailSenderServiceImpl.class);
|
||||
|
||||
public EmailSenderServiceImpl() {
|
||||
this.contentProvider = EmailContentProviderFactory.getContentProvider();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendEmail(EmailContext emailCtx) throws EmailSendingFailedException {
|
||||
for (String recipient : emailCtx.getRecipients()) {
|
||||
ContentProviderInfo info = emailCtx.getContentProviderInfo();
|
||||
EmailData emailData;
|
||||
try {
|
||||
emailData = contentProvider.getContent(info.getTemplate(), info.getParams());
|
||||
} catch (ContentProcessingInterruptedException e) {
|
||||
throw new EmailSendingFailedException("Error occurred while retrieving email content to be " +
|
||||
"sent for recipient '" + recipient + "'", e);
|
||||
}
|
||||
threadPoolExecutor.submit(new EmailSender(recipient, emailData.getSubject(), emailData.getBody()));
|
||||
}
|
||||
}
|
||||
|
||||
public static class EmailSender implements Runnable {
|
||||
|
||||
String to;
|
||||
String subject;
|
||||
String body;
|
||||
|
||||
EmailSender(String to, String subject, String body) {
|
||||
this.to = to;
|
||||
this.subject = subject;
|
||||
this.body = body;
|
||||
}
|
||||
|
||||
public void run() {
|
||||
OMElement payload = null;
|
||||
try {
|
||||
payload = AXIOMUtil.stringToOM(body);
|
||||
} catch (XMLStreamException e) {
|
||||
log.error("Error occurred while converting email body contents to an XML", e);
|
||||
}
|
||||
try {
|
||||
ConfigurationContextService configCtxService =
|
||||
EmailSenderDataHolder.getInstance().getConfigurationContextService();
|
||||
if (configCtxService == null) {
|
||||
throw new IllegalStateException("Configuration Context Service is not available");
|
||||
}
|
||||
ConfigurationContext configCtx = configCtxService.getServerConfigContext();
|
||||
ServiceClient serviceClient = new ServiceClient(configCtx, null);
|
||||
|
||||
Map<String, String> headerMap = new HashMap<>();
|
||||
headerMap.put(MailConstants.MAIL_HEADER_SUBJECT, subject);
|
||||
|
||||
Options options = new Options();
|
||||
options.setProperty(MessageContext.TRANSPORT_HEADERS, headerMap);
|
||||
options.setProperty("FORCE_CONTENT_TYPE_BASED_FORMATTER", "true");
|
||||
options.setProperty(Constants.Configuration.MESSAGE_TYPE, "text/html");
|
||||
options.setProperty(Constants.Configuration.CONTENT_TYPE, "text/html");
|
||||
options.setTo(new EndpointReference(EMAIL_URI_SCHEME + to));
|
||||
|
||||
serviceClient.setOptions(options);
|
||||
serviceClient.fireAndForget(payload);
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Email has been successfully sent to '" + to + "'");
|
||||
}
|
||||
} catch (AxisFault e) {
|
||||
log.error("Error occurred while delivering the message, subject: '" + subject + "', to: '" + to +
|
||||
"'", e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,32 @@
|
||||
#
|
||||
# Copyright 2009 WSO2, Inc. (http://wso2.com)
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
|
||||
#
|
||||
# This is the log4j configuration file used by WSO2 Carbon
|
||||
#
|
||||
# IMPORTANT : Please do not remove or change the names of any
|
||||
# of the Appenders defined here. The layout pattern & log file
|
||||
# can be changed using the WSO2 Carbon Management Console, and those
|
||||
# settings will override the settings in this file.
|
||||
#
|
||||
|
||||
log4j.rootLogger=INFO, STD_OUT
|
||||
|
||||
# Redirect log messages to console
|
||||
log4j.appender.STD_OUT=org.apache.log4j.ConsoleAppender
|
||||
log4j.appender.STD_OUT.Target=System.out
|
||||
log4j.appender.STD_OUT.layout=org.apache.log4j.PatternLayout
|
||||
log4j.appender.STD_OUT.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n
|
@ -0,0 +1,29 @@
|
||||
|
||||
<!--
|
||||
~ Copyright (c) 2014, 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.
|
||||
-->
|
||||
|
||||
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
|
||||
|
||||
<suite name="DeviceManagementCore">
|
||||
<parameter name="useDefaultListeners" value="false"/>
|
||||
|
||||
<test name="EmailSenderTests" preserve-order="true">
|
||||
<classes>
|
||||
</classes>
|
||||
</test>
|
||||
</suite>
|
@ -0,0 +1,60 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
~ Copyright (c) 2014, 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.
|
||||
-->
|
||||
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
|
||||
<parent>
|
||||
<groupId>org.wso2.carbon.devicemgt</groupId>
|
||||
<artifactId>carbon-devicemgt</artifactId>
|
||||
<version>1.0.4-SNAPSHOT</version>
|
||||
<relativePath>../../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>org.wso2.carbon.devicemgt</groupId>
|
||||
<artifactId>email-sender</artifactId>
|
||||
<version>1.0.4-SNAPSHOT</version>
|
||||
<packaging>pom</packaging>
|
||||
<name>WSO2 Carbon - Email Sender Component</name>
|
||||
<url>http://wso2.org</url>
|
||||
|
||||
<modules>
|
||||
<module>org.wso2.carbon.email.sender.core</module>
|
||||
</modules>
|
||||
|
||||
<build>
|
||||
<pluginManagement>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.felix</groupId>
|
||||
<artifactId>maven-scr-plugin</artifactId>
|
||||
<version>1.7.2</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>generate-scr-scrdescriptor</id>
|
||||
<goals>
|
||||
<goal>scr</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</pluginManagement>
|
||||
</build>
|
||||
</project>
|
@ -1,40 +0,0 @@
|
||||
<Notifications>
|
||||
<NotificationMessage type="enrol">
|
||||
<Subject>Enroll your Device with WSO2 MDM</Subject>
|
||||
<Header>Dear {first-name},</Header>
|
||||
<Body>
|
||||
You have been registered to the WSO2 MDM. Below is the link to enroll.
|
||||
</Body>
|
||||
<Url>{downloadUrl}</Url>
|
||||
<Footer1>
|
||||
Best Regards,
|
||||
</Footer1>
|
||||
<Footer2>
|
||||
WSO2 MDM Team.
|
||||
</Footer2>
|
||||
<Footer3>
|
||||
http://www.wso2.com
|
||||
</Footer3>
|
||||
</NotificationMessage>
|
||||
<NotificationMessage type="userRegistration">
|
||||
<Subject>Enroll your Device with WSO2 MDM</Subject>
|
||||
<Header>Dear {first-name},</Header>
|
||||
<Body>
|
||||
You have been registered to WSO2 MDM with following credentials.
|
||||
Domain: {domain-name}
|
||||
Username: {user-name}
|
||||
Password: {password}
|
||||
Below is the link to enroll.
|
||||
</Body>
|
||||
<Url>{downloadUrl}</Url>
|
||||
<Footer1>
|
||||
Best Regards,
|
||||
</Footer1>
|
||||
<Footer2>
|
||||
WSO2 MDM Team.
|
||||
</Footer2>
|
||||
<Footer3>
|
||||
http://www.wso2.com
|
||||
</Footer3>
|
||||
</NotificationMessage>
|
||||
</Notifications>
|
@ -0,0 +1,72 @@
|
||||
#*
|
||||
Copyright (c) 2016, 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.
|
||||
*#
|
||||
<EmailConfig>
|
||||
<Subject>You have been invited to enroll your device in WSO2 EMM</Subject>
|
||||
<Body>
|
||||
<![CDATA[
|
||||
<html>
|
||||
<head>
|
||||
<title>WSO2 Enterprise Mobility Manager</title>
|
||||
</head>
|
||||
<body style="color: #666666; background-color:#cdcdcd; padding: 0px; margin: 0px;">
|
||||
<div style="background-color:#cdcdcd; font-size: 1em; font-family: Arial, Helvetica; line-height: 170%; color: #666666; padding: 20px 0px; margin: 0px;">
|
||||
<div style="width: 86%; max-width: 650px; padding: 2%; background-color: #ffffff; margin: auto; border-radius: 14px;">
|
||||
<div style="background-color: #49c8f5; line-height: 0px; border-top-left-radius: 10px; border-top-right-radius: 10px; padding: 0px 10px 0px 0px;">
|
||||
<div style="display: inline-block; line-height: 0px;">
|
||||
<img src="http://b.content.wso2.com/sites/all/2015-june-theme/navigation/wso2-nav-logo.png"
|
||||
alt="WSO2" style="margin: 0px 20px 0px 25px; width: 100%; max-width: 251px;"/>
|
||||
</div>
|
||||
</div>
|
||||
<div style="background-color: #ffffff; line-height: 170%; color: #666666; padding: 20px 25px;">
|
||||
<p style="font-size: 1em; font-family: Arial, Helvetica; line-height: 170%; color: #666666; margin: 5px 0px 20px;">
|
||||
Hi $first-name,
|
||||
</p>
|
||||
|
||||
<p style="font-size: 1em; font-family: Arial, Helvetica; line-height: 170%; color: #666666; margin: 5px 0px;">
|
||||
You have been invited to enrol your device in WSO2 Enterprise Mobility Manager.
|
||||
Click <a href="$base-url-https/emm-web-agent/enrollment">here</a> to download the WSO2 EMM client application to begin device
|
||||
enrolment.</p>
|
||||
|
||||
<p style="font-size: 1em; font-family: Arial, Helvetica; line-height: 170%; color: #666666; margin: 5px 0px;">
|
||||
Should you need assistance, please contact your administrator.
|
||||
</p>
|
||||
|
||||
<p style="font-size: 1em; font-family: Arial, Helvetica; line-height: 170%; color: #666666; margin: 20px 0px 5px;">
|
||||
Regards,
|
||||
</p>
|
||||
|
||||
<p style="font-size: 1em; font-family: Arial, Helvetica; line-height: 170%; color: #666666; margin: 5px 0px;">
|
||||
WSO2 EMM Administrator
|
||||
</p>
|
||||
</div>
|
||||
<div style="background-color: #333333; border-bottom-left-radius: 10px; border-bottom-right-radius: 10px;">
|
||||
<table cellpadding="0" cellspacing="0" border="0" width="100%">
|
||||
<tr>
|
||||
<td style="padding: 0px 20px 0px 0px;"><img
|
||||
src="http://b.content.wso2.com/newsletter/images/wso2-logo-cloud-footer.png" alt="WSO2"
|
||||
style="margin: 15px 0px 15px 25px; width: 100%; max-width: 258px;"/></td>
|
||||
</tr>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
]]>
|
||||
</Body>
|
||||
</EmailConfig>
|
@ -0,0 +1,82 @@
|
||||
#*
|
||||
Copyright (c) 2016, 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.
|
||||
*#
|
||||
<EmailConfig>
|
||||
<Subject>You have successfully been registered in WSO2 EMM</Subject>
|
||||
<Body>
|
||||
<![CDATA[
|
||||
<html>
|
||||
<head>
|
||||
<title>WSO2 Enterprise Mobility Manager</title>
|
||||
</head>
|
||||
<body style="color: #666666; background-color:#cdcdcd; padding: 0px; margin: 0px;">
|
||||
<div style="background-color:#cdcdcd; font-size: 1em; font-family: Arial, Helvetica; line-height: 170%; color: #666666; padding: 20px 0px; margin: 0px;">
|
||||
<div style="width: 86%; max-width: 650px; padding: 2%; background-color: #ffffff; margin: auto; border-radius: 14px;">
|
||||
<div style="background-color: #49c8f5; line-height: 0px; border-top-left-radius: 10px; border-top-right-radius: 10px; padding: 0px 10px 0px 0px;">
|
||||
<div style="display: inline-block; line-height: 0px;">
|
||||
<img src="http://b.content.wso2.com/sites/all/2015-june-theme/navigation/wso2-nav-logo.png"
|
||||
alt="WSO2" style="margin: 0px 20px 0px 25px; width: 100%; max-width: 251px;"/>
|
||||
</div>
|
||||
</div>
|
||||
<div style="background-color: #ffffff; line-height: 170%; color: #666666; padding: 20px 25px;">
|
||||
<p style="font-size: 1em; font-family: Arial, Helvetica; line-height: 170%; color: #666666; margin: 5px 0px 20px;">
|
||||
Hi $first-name,
|
||||
</p>
|
||||
|
||||
<p style="font-size: 1em; font-family: Arial, Helvetica; line-height: 170%; color: #666666; margin: 5px 0px;">
|
||||
You have been registered in WSO2 Enterprise Mobility Manager and invited to enrol your device.
|
||||
Click <a href="$base-url-https/emm-web-agent/enrollment">here</a> to download the WSO2 EMM client application to begin device
|
||||
enrolment.</p>
|
||||
|
||||
<p style="font-size: 1em; font-family: Arial, Helvetica; line-height: 170%; color: #666666; margin: 5px 0px;">
|
||||
Use following credentials to log in to WSO2 EMM client application.
|
||||
</p>
|
||||
|
||||
<p style="font-size: 1em; font-family: Arial, Helvetica; line-height: 170%; color: #666666; margin: 5px 0px;">
|
||||
<b>Username:</b> $username
|
||||
<br/>
|
||||
<b>Password:</b> $password
|
||||
</p>
|
||||
|
||||
<p style="font-size: 1em; font-family: Arial, Helvetica; line-height: 170%; color: #666666; margin: 5px 0px;">
|
||||
Should you need assistance, please contact your administrator.
|
||||
</p>
|
||||
|
||||
<p style="font-size: 1em; font-family: Arial, Helvetica; line-height: 170%; color: #666666; margin: 20px 0px 5px;">
|
||||
Regards,
|
||||
</p>
|
||||
|
||||
<p style="font-size: 1em; font-family: Arial, Helvetica; line-height: 170%; color: #666666; margin: 5px 0px;">
|
||||
WSO2 EMM Administrator
|
||||
</p>
|
||||
</div>
|
||||
<div style="background-color: #333333; border-bottom-left-radius: 10px; border-bottom-right-radius: 10px;">
|
||||
<table cellpadding="0" cellspacing="0" border="0" width="100%">
|
||||
<tr>
|
||||
<td style="padding: 0px 20px 0px 0px;"><img
|
||||
src="http://b.content.wso2.com/newsletter/images/wso2-logo-cloud-footer.png" alt="WSO2"
|
||||
style="margin: 15px 0px 15px 25px; width: 100%; max-width: 258px;"/></td>
|
||||
</tr>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
]]>
|
||||
</Body>
|
||||
</EmailConfig>
|
@ -1,7 +1,7 @@
|
||||
instructions.configure = \
|
||||
org.eclipse.equinox.p2.touchpoint.natives.copy(source:${installFolder}/../features/org.wso2.carbon.device.mgt.server_${feature.version}/conf/cdm-config.xml,target:${installFolder}/../../conf/cdm-config.xml,overwrite:true);\
|
||||
org.eclipse.equinox.p2.touchpoint.natives.copy(source:${installFolder}/../features/org.wso2.carbon.device.mgt.server_${feature.version}/conf/notification-messages.xml,target:${installFolder}/../../conf/notification-messages.xml,overwrite:true);\
|
||||
org.eclipse.equinox.p2.touchpoint.natives.copy(source:${installFolder}/../features/org.wso2.carbon.device.mgt.server_${feature.version}/conf/license-config.xml,target:${installFolder}/../../conf/etc/license-config.xml,overwrite:true);\
|
||||
org.eclipse.equinox.p2.touchpoint.natives.copy(source:${installFolder}/../features/org.wso2.carbon.device.mgt.server_${feature.version}/conf/remote-appmanager-config.xml,target:${installFolder}/../../conf/etc/remote-appmanager-config.xml,overwrite:true);\
|
||||
org.eclipse.equinox.p2.touchpoint.natives.copy(source:${installFolder}/../features/org.wso2.carbon.device.mgt.server_${feature.version}/dbscripts/cdm,target:${installFolder}/../../../dbscripts/cdm,overwrite:true);\
|
||||
org.eclipse.equinox.p2.touchpoint.natives.copy(source:${installFolder}/../features/org.wso2.carbon.device.mgt.server_${feature.version}/rxts/license.rxt,target:${installFolder}/../../../repository/resources/rxts/license.rxt,overwrite:true);\
|
||||
org.eclipse.equinox.p2.touchpoint.natives.copy(source:${installFolder}/../features/org.wso2.carbon.device.mgt.server_${feature.version}/rxts/license.rxt,target:${installFolder}/../../../repository/resources/rxts/license.rxt,overwrite:true);\
|
||||
org.eclipse.equinox.p2.touchpoint.natives.copy(source:${installFolder}/../features/org.wso2.carbon.device.mgt.server_${feature.version}/email/templates,target:${installFolder}/../../../repository/resources/email-templates,overwrite:true);\
|
@ -0,0 +1,107 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
~ 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.
|
||||
-->
|
||||
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||
|
||||
<parent>
|
||||
<groupId>org.wso2.carbon.devicemgt</groupId>
|
||||
<artifactId>email-sender-feature</artifactId>
|
||||
<version>1.0.4-SNAPSHOT</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>org.wso2.carbon.email.sender.feature</artifactId>
|
||||
<packaging>pom</packaging>
|
||||
<version>1.0.4-SNAPSHOT</version>
|
||||
<name>WSO2 Carbon - Email Sender Feature</name>
|
||||
<url>http://wso2.org</url>
|
||||
<description>This feature contains the core bundles required for email sender related functionality
|
||||
</description>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.wso2.carbon.devicemgt</groupId>
|
||||
<artifactId>org.wso2.carbon.email.sender.core</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-resources-plugin</artifactId>
|
||||
<version>2.6</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>copy-resources</id>
|
||||
<phase>generate-resources</phase>
|
||||
<goals>
|
||||
<goal>copy-resources</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<outputDirectory>src/main/resources</outputDirectory>
|
||||
<resources>
|
||||
<resource>
|
||||
<directory>resources</directory>
|
||||
<includes>
|
||||
<include>build.properties</include>
|
||||
<include>p2.inf</include>
|
||||
</includes>
|
||||
</resource>
|
||||
</resources>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.wso2.maven</groupId>
|
||||
<artifactId>carbon-p2-plugin</artifactId>
|
||||
<version>${carbon.p2.plugin.version}</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>p2-feature-generation</id>
|
||||
<phase>package</phase>
|
||||
<goals>
|
||||
<goal>p2-feature-gen</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<id>org.wso2.carbon.email.sender</id>
|
||||
<propertiesFile>../../../features/etc/feature.properties</propertiesFile>
|
||||
<adviceFile>
|
||||
<properties>
|
||||
<propertyDef>org.wso2.carbon.p2.category.type:server</propertyDef>
|
||||
<propertyDef>org.eclipse.equinox.p2.type.group:false</propertyDef>
|
||||
</properties>
|
||||
</adviceFile>
|
||||
<bundles>
|
||||
<bundleDef>
|
||||
org.wso2.carbon.devicemgt:org.wso2.carbon.email.sender.core:${carbon.device.mgt.version}
|
||||
</bundleDef>
|
||||
</bundles>
|
||||
<importFeatures>
|
||||
<importFeatureDef>org.wso2.carbon.core.server:${carbon.kernel.version}</importFeatureDef>
|
||||
</importFeatures>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
@ -0,0 +1 @@
|
||||
custom = true
|
@ -0,0 +1,30 @@
|
||||
<?xml version="1.0" encoding="ISO-8859-1"?>
|
||||
<!--
|
||||
~ Copyright (c) 2016, 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.
|
||||
-->
|
||||
<EmailSenderConfig>
|
||||
|
||||
<MinThreads>8</MinThreads>
|
||||
|
||||
<MaxThreads>100</MaxThreads>
|
||||
|
||||
<KeepAliveDuration>20</KeepAliveDuration>
|
||||
|
||||
<ThreadQueueCapacity>1000</ThreadQueueCapacity>
|
||||
|
||||
</EmailSenderConfig>
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue