Fixed conflicts and merged

revert-70aa11f8
mharindu 9 years ago
commit 968cb00f35

@ -157,6 +157,16 @@
<artifactId>org.wso2.carbon.apimgt.application.extension</artifactId> <artifactId>org.wso2.carbon.apimgt.application.extension</artifactId>
<scope>provided</scope> <scope>provided</scope>
</dependency> </dependency>
<dependency>
<groupId>org.wso2.carbon</groupId>
<artifactId>org.wso2.carbon.user.core</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.wso2.carbon</groupId>
<artifactId>org.wso2.carbon.user.api</artifactId>
<scope>provided</scope>
</dependency>
</dependencies> </dependencies>
<build> <build>

@ -59,6 +59,7 @@ public class ApiApplicationRegistrationServiceImpl implements ApiApplicationRegi
} }
String username = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUserRealm() String username = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUserRealm()
.getRealmConfiguration().getAdminUserName(); .getRealmConfiguration().getAdminUserName();
username = username + "@" + APIUtil.getTenantDomainOftheUser();
PrivilegedCarbonContext.getThreadLocalCarbonContext().setUsername(username); PrivilegedCarbonContext.getThreadLocalCarbonContext().setUsername(username);
APIManagementProviderService apiManagementProviderService = APIUtil.getAPIManagementProviderService(); APIManagementProviderService apiManagementProviderService = APIUtil.getAPIManagementProviderService();
ApiApplicationKey apiApplicationKey = apiManagementProviderService.generateAndRetrieveApplicationKeys( ApiApplicationKey apiApplicationKey = apiManagementProviderService.generateAndRetrieveApplicationKeys(
@ -81,7 +82,7 @@ public class ApiApplicationRegistrationServiceImpl implements ApiApplicationRegi
@POST @POST
public Response register(RegistrationProfile registrationProfile) { public Response register(RegistrationProfile registrationProfile) {
try { try {
String username = APIUtil.getAuthenticatedUser(); String username = APIUtil.getAuthenticatedUser() + "@" + APIUtil.getTenantDomainOftheUser();
APIManagementProviderService apiManagementProviderService = APIUtil.getAPIManagementProviderService(); APIManagementProviderService apiManagementProviderService = APIUtil.getAPIManagementProviderService();
if (registrationProfile.isMappingAnExistingOAuthApp()) { if (registrationProfile.isMappingAnExistingOAuthApp()) {
JSONObject jsonStringObject = new JSONObject(); JSONObject jsonStringObject = new JSONObject();
@ -116,7 +117,7 @@ public class ApiApplicationRegistrationServiceImpl implements ApiApplicationRegi
@DELETE @DELETE
public Response unregister(@QueryParam("applicationName") String applicationName) { public Response unregister(@QueryParam("applicationName") String applicationName) {
try { try {
String username = APIUtil.getAuthenticatedUser(); String username = APIUtil.getAuthenticatedUser() + "@" + APIUtil.getTenantDomainOftheUser();
APIManagementProviderService apiManagementProviderService = APIUtil.getAPIManagementProviderService(); APIManagementProviderService apiManagementProviderService = APIUtil.getAPIManagementProviderService();
apiManagementProviderService.removeAPIApplication(applicationName, username); apiManagementProviderService.removeAPIApplication(applicationName, username);
return Response.status(Response.Status.ACCEPTED).build(); return Response.status(Response.Status.ACCEPTED).build();

@ -0,0 +1,118 @@
package org.wso2.carbon.apimgt.application.extension.api.filter;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.apimgt.application.extension.api.util.APIUtil;
import org.wso2.carbon.context.PrivilegedCarbonContext;
import org.wso2.carbon.user.api.UserRealm;
import org.wso2.carbon.user.api.UserStoreException;
import javax.servlet.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Unmarshaller;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.util.List;
/**
* this filter check for permission for the request
*/
public class ApiPermissionFilter implements Filter{
private static final Log log = LogFactory.getLog(ApiPermissionFilter.class);
private static final String UI_EXECUTE = "ui.execute";
private static final String PERMISSION_CONFIG_PATH = File.separator + "META-INF" + File.separator
+ "permissions.xml";
private static final String PERMISSION_PREFIX = "/permission/admin";
private static List<Permission> permissions;
private static final String WEBAPP_CONTEXT = "/api-application-registration";
@Override
public void init(FilterConfig filterConfig) throws ServletException {
InputStream permissionStream = filterConfig.getServletContext().getResourceAsStream(PERMISSION_CONFIG_PATH);
if (permissionStream != null) {
try {
JAXBContext cdmContext = JAXBContext.newInstance(PermissionConfiguration.class);
Unmarshaller unmarshaller = cdmContext.createUnmarshaller();
PermissionConfiguration permissionConfiguration = (PermissionConfiguration)
unmarshaller.unmarshal(permissionStream);
permissions = permissionConfiguration.getPermissions();
} catch (JAXBException e) {
log.error("invalid permissions.xml", e);
}
}
}
@Override
public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain)
throws IOException, ServletException {
if (servletRequest instanceof HttpServletRequest) {
String uri = ((HttpServletRequest)servletRequest).getRequestURI();
boolean status = false;
if (uri.contains("register/tenants")) {
String urlPermission = getPermission("/register/tenants/*");
if (urlPermission != null) {
status = isUserAuthorized(PERMISSION_PREFIX + urlPermission, UI_EXECUTE);
}
} else {
String urlPermission = getPermission(uri);
if (urlPermission != null) {
status = isUserAuthorized(PERMISSION_PREFIX + urlPermission, UI_EXECUTE);
}
}
if (status) {
filterChain.doFilter(servletRequest, servletResponse);
} else {
HttpServletResponse res = (HttpServletResponse) servletResponse;
res.setStatus(HttpServletResponse.SC_FORBIDDEN);
return;
}
} else {
HttpServletResponse res = (HttpServletResponse) servletResponse;
res.setStatus(HttpServletResponse.SC_FORBIDDEN);
return;
}
}
@Override
public void destroy() {
//do nothing
}
private static String getPermission(String url) {
if (permissions != null) {
for (int i = 0; i < permissions.size(); i++) {
Permission permission = permissions.get(i);
if ((WEBAPP_CONTEXT + permission.getUrl()).equals(url)) {
return permission.getPath();
}
}
}
return null;
}
/**
* Check whether the client is authorized with the given permission and action.
* @param permission Carbon permission that requires for the use
* @param action Carbon permission action that requires for the given permission.
* @return boolean - true if user is authorized else return false.
*/
private boolean isUserAuthorized(String permission, String action) {
PrivilegedCarbonContext context = PrivilegedCarbonContext.getThreadLocalCarbonContext();
String username = context.getUsername();
try {
UserRealm userRealm = APIUtil.getRealmService().getTenantUserRealm(PrivilegedCarbonContext
.getThreadLocalCarbonContext().getTenantId());
return userRealm.getAuthorizationManager().isUserAuthorized(username, permission, action);
} catch (UserStoreException e) {
String errorMsg = String.format("Unable to authorize the user : %s", username, e);
log.error(errorMsg, e);
return false;
}
}
}

@ -0,0 +1,60 @@
/*
* 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.apimgt.application.extension.api.filter;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
/**
* This class represents the information related to permission.
*/
@XmlRootElement (name = "Permission")
public class Permission {
private String path; // permission string
private String url; // url of the resource
private String method; // http method
public String getPath() {
return path;
}
@XmlElement (name = "path", required = true)
public void setPath(String path) {
this.path = path;
}
public String getUrl() {
return url;
}
@XmlElement (name = "url", required = true)
public void setUrl(String url) {
this.url = url;
}
public String getMethod() {
return method;
}
@XmlElement (name = "method", required = true)
public void setMethod(String method) {
this.method = method;
}
}

@ -0,0 +1,41 @@
/*
* 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.apimgt.application.extension.api.filter;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import java.util.List;
/**
* This class represents the information related to permission configuration.
*/
@XmlRootElement (name = "PermissionConfiguration")
public class PermissionConfiguration {
private List<Permission> permissions;
public List<Permission> getPermissions() {
return permissions;
}
@XmlElement (name = "Permission", required = true)
public void setPermissions(List<Permission> permissions) {
this.permissions = permissions;
}
}

@ -22,6 +22,7 @@ import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.apimgt.application.extension.APIManagementProviderService; import org.wso2.carbon.apimgt.application.extension.APIManagementProviderService;
import org.wso2.carbon.context.PrivilegedCarbonContext; import org.wso2.carbon.context.PrivilegedCarbonContext;
import org.wso2.carbon.user.core.service.RealmService;
/** /**
* This class provides utility functions used by REST-API. * This class provides utility functions used by REST-API.
@ -57,4 +58,16 @@ public class APIUtil {
} }
return apiManagementProviderService; return apiManagementProviderService;
} }
public static RealmService getRealmService() {
PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext();
RealmService realmService =
(RealmService) ctx.getOSGiService(RealmService.class, null);
if (realmService == null) {
String msg = "Device Management service has not initialized.";
log.error(msg);
throw new IllegalStateException(msg);
}
return realmService;
}
} }

@ -30,21 +30,21 @@
<!-- Device related APIs --> <!-- Device related APIs -->
<Permission> <Permission>
<name>Register tenant specific application</name> <name>Register tenant specific application</name>
<path>/device-mgt</path> <path>/device-mgt/admin</path>
<url>/register/tenants/*</url> <url>/register/tenants/*</url>
<method>POST</method> <method>POST</method>
<scope>super_admin_user</scope> <scope>super_admin_user</scope>
</Permission> </Permission>
<Permission> <Permission>
<name>Register application</name> <name>Register application</name>
<path>/device-mgt/api/application/add</path> <path>/device-mgt/user/api/application</path>
<url>/register</url> <url>/register</url>
<method>POST</method> <method>POST</method>
<scope>application_user</scope> <scope>application_user</scope>
</Permission> </Permission>
<Permission> <Permission>
<name>Delete application</name> <name>Delete application</name>
<path>/device-mgt/api/application/remove</path> <path>/device-mgt/user/api/application</path>
<url>/unregister</url> <url>/unregister</url>
<method>DELETE</method> <method>DELETE</method>
<scope>application_user</scope> <scope>application_user</scope>

@ -49,4 +49,14 @@
<param-name>managed-api-enabled</param-name> <param-name>managed-api-enabled</param-name>
<param-value>false</param-value> <param-value>false</param-value>
</context-param> </context-param>
<filter>
<filter-name>ApiPermissionFilter</filter-name>
<filter-class>org.wso2.carbon.apimgt.application.extension.api.filter.ApiPermissionFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>ApiPermissionFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
</web-app> </web-app>

@ -0,0 +1,147 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ 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.
-->
<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>
<artifactId>device-mgt-extensions</artifactId>
<groupId>org.wso2.carbon.devicemgt</groupId>
<version>1.1.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>org.wso2.carbon.device.mgt.extensions.push.notification.provider.gcm</artifactId>
<packaging>bundle</packaging>
<name>WSO2 Carbon - GCM Based Push Notification Provider Implementation</name>
<description>WSO2 Carbon - GCM Based Push Notification Provider Implementation</description>
<url>http://wso2.org</url>
<dependencies>
<dependency>
<groupId>org.wso2.carbon.governance</groupId>
<artifactId>org.wso2.carbon.governance.api</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.registry.core</artifactId>
</dependency>
<dependency>
<groupId>org.wso2.carbon.devicemgt</groupId>
<artifactId>org.wso2.carbon.device.mgt.common</artifactId>
</dependency>
<dependency>
<groupId>org.wso2.carbon.devicemgt</groupId>
<artifactId>org.wso2.carbon.device.mgt.core</artifactId>
</dependency>
<dependency>
<groupId>org.apache.ws.commons.axiom</groupId>
<artifactId>axiom-api</artifactId>
</dependency>
<dependency>
<groupId>org.wso2.carbon</groupId>
<artifactId>org.wso2.carbon.utils</artifactId>
</dependency>
<dependency>
<groupId>org.wso2.orbit.org.scannotation</groupId>
<artifactId>scannotation</artifactId>
</dependency>
<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.tomcat</groupId>
<artifactId>tomcat</artifactId>
</dependency>
<dependency>
<groupId>org.wso2.tomcat</groupId>
<artifactId>tomcat-servlet-api</artifactId>
</dependency>
<dependency>
<groupId>javax.ws.rs</groupId>
<artifactId>jsr311-api</artifactId>
</dependency>
<dependency>
<groupId>org.apache.axis2.wso2</groupId>
<artifactId>axis2</artifactId>
</dependency>
<dependency>
<groupId>commons-lang.wso2</groupId>
<artifactId>commons-lang</artifactId>
</dependency>
<dependency>
<groupId>org.eclipse.paho</groupId>
<artifactId>org.eclipse.paho.client.mqttv3</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
</dependency>
<dependency>
<groupId>org.json.wso2</groupId>
<artifactId>json</artifactId>
</dependency>
<dependency>
<groupId>org.wso2.carbon.analytics-common</groupId>
<artifactId>org.wso2.carbon.event.output.adapter.core</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<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>GCM Based Push Notification Provider Bundle</Bundle-Description>
<Export-Package>
!org.wso2.carbon.device.mgt.extensions.push.notification.provider.gcm.internal,
org.wso2.carbon.device.mgt.extensions.push.notification.provider.gcm.*
</Export-Package>
<Import-Package>
com.google.gson,
org.osgi.service.component,
org.wso2.carbon.device.mgt.common.operation.mgt,
org.wso2.carbon.device.mgt.common.push.notification,
org.apache.commons.logging,
org.wso2.carbon.device.mgt.common,
org.wso2.carbon.device.mgt.core.service
</Import-Package>
</instructions>
</configuration>
</plugin>
</plugins>
</build>
</project>

@ -0,0 +1,39 @@
/*
* 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.extensions.push.notification.provider.gcm;
import org.wso2.carbon.device.mgt.common.push.notification.NotificationStrategy;
import org.wso2.carbon.device.mgt.common.push.notification.PushNotificationConfig;
import org.wso2.carbon.device.mgt.common.push.notification.PushNotificationProvider;
public class GCMBasedPushNotificationProvider implements PushNotificationProvider {
private static final String PS_PROVIDER_GCM = "GCM";
@Override
public String getType() {
return PS_PROVIDER_GCM;
}
@Override
public NotificationStrategy getNotificationStrategy(PushNotificationConfig config) {
return new GCMNotificationStrategy(config);
}
}

@ -0,0 +1,134 @@
/*
* 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.extensions.push.notification.provider.gcm;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import com.google.gson.JsonPrimitive;
import org.wso2.carbon.device.mgt.common.Device;
import org.wso2.carbon.device.mgt.common.DeviceManagementException;
import org.wso2.carbon.device.mgt.common.push.notification.NotificationContext;
import org.wso2.carbon.device.mgt.common.push.notification.NotificationStrategy;
import org.wso2.carbon.device.mgt.common.push.notification.PushNotificationConfig;
import org.wso2.carbon.device.mgt.common.push.notification.PushNotificationExecutionFailedException;
import org.wso2.carbon.device.mgt.extensions.push.notification.provider.gcm.internal.GCMDataHolder;
import java.io.IOException;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.List;
public class GCMNotificationStrategy implements NotificationStrategy {
private static final String GCM_TOKEN = "GCM_TOKEN";
private final static String GCM_ENDPOINT = "https://gcm-http.googleapis.com/gcm/send";
private static final String GCM_API_KEY = "gcmAPIKey";
private static final int TIME_TO_LIVE = 60;
private static final int HTTP_STATUS_CODE_OK = 200;
private PushNotificationConfig config;
public GCMNotificationStrategy(PushNotificationConfig config) {
this.config = config;
}
@Override
public void init() {
}
@Override
public void execute(NotificationContext ctx) throws PushNotificationExecutionFailedException {
try {
Device device =
GCMDataHolder.getInstance().getDeviceManagementProviderService().getDevice(ctx.getDeviceId());
this.sendWakeUpCall(ctx.getOperation().getCode(), device);
} catch (DeviceManagementException e) {
throw new PushNotificationExecutionFailedException("Error occurred while retrieving device information", e);
} catch (IOException e) {
throw new PushNotificationExecutionFailedException("Error occurred while sending push notification", e);
}
}
@Override
public NotificationContext buildContext() {
return null;
}
private void sendWakeUpCall(String message,
Device device) throws IOException, PushNotificationExecutionFailedException {
OutputStream os = null;
byte[] bytes = getGCMRequest(message, getGCMToken(device.getProperties())).getBytes();
HttpURLConnection conn = null;
try {
conn = (HttpURLConnection) (new URL(config.getProperty(GCM_ENDPOINT)).openConnection());
conn.setDoOutput(true);
conn.setUseCaches(false);
conn.setFixedLengthStreamingMode(bytes.length);
conn.setRequestMethod("POST");
conn.setRequestProperty("Content-Type", "application/json");
conn.setRequestProperty("Authorization", "key=" + config.getProperty(GCM_API_KEY));
os = conn.getOutputStream();
os.write(bytes);
} finally {
if (os != null) {
os.close();
}
}
int status = conn.getResponseCode();
if (status != HTTP_STATUS_CODE_OK) {
throw new PushNotificationExecutionFailedException("Push notification sending failed with the HTTP " +
"error code '" + status + "'");
}
}
private static String getGCMRequest(String message, String registrationId) {
JsonObject gcmRequest = new JsonObject();
gcmRequest.addProperty("delay_while_idle", false);
gcmRequest.addProperty("time_to_live", TIME_TO_LIVE);
//Add message to GCM request
JsonObject data = new JsonObject();
if (message != null && !message.isEmpty()) {
data.addProperty("data", message);
gcmRequest.add("data", data);
}
//Set device reg-id
JsonArray regIds = new JsonArray();
regIds.add(new JsonPrimitive(registrationId));
gcmRequest.add("registration_ids", regIds);
return gcmRequest.toString();
}
private static String getGCMToken(List<Device.Property> properties) {
String gcmToken = null;
for (Device.Property property : properties) {
if (GCM_TOKEN.equals(property.getName())) {
gcmToken = property.getValue();
break;
}
}
return gcmToken;
}
}

@ -0,0 +1,40 @@
/*
* 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.extensions.push.notification.provider.gcm.internal;
import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService;
public class GCMDataHolder {
private DeviceManagementProviderService deviceManagementProviderService;
private static GCMDataHolder thisInstance = new GCMDataHolder();
public static GCMDataHolder getInstance() {
return thisInstance;
}
public DeviceManagementProviderService getDeviceManagementProviderService() {
return deviceManagementProviderService;
}
public void setDeviceManagementProviderService(DeviceManagementProviderService deviceManagementProviderService) {
this.deviceManagementProviderService = deviceManagementProviderService;
}
}

@ -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.extensions.push.notification.provider.gcm.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.service.DeviceManagementProviderService;
/**
* @scr.component name="org.wso2.carbon.device.mgt.extensions.push.notification.provider.gcm.internal.GCMPushNotificationServiceComponent" immediate="true"
* @scr.reference name="carbon.device.mgt.provider"
* interface="org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService"
* cardinality="1..1"
* policy="dynamic"
* bind="setDeviceManagementProviderService"
* unbind="unsetDeviceManagementProviderService"
*/
public class GCMPushNotificationServiceComponent {
private static final Log log = LogFactory.getLog(GCMPushNotificationServiceComponent.class);
@SuppressWarnings("unused")
protected void activate(ComponentContext componentContext) {
try {
if (log.isDebugEnabled()) {
log.debug("Initializing GCM based push notification provider implementation bundle");
}
//Do nothing
if (log.isDebugEnabled()) {
log.debug("GCM based push notification provider implementation bundle has been successfully " +
"initialized");
}
} catch (Throwable e) {
log.error("Error occurred while initializing GCM based push notification provider " +
"implementation bundle", e);
}
}
protected void deactivate(ComponentContext componentContext) {
//Do nothing
}
protected void setDeviceManagementProviderService(
DeviceManagementProviderService deviceManagementProviderService) {
GCMDataHolder.getInstance().setDeviceManagementProviderService(deviceManagementProviderService);
}
protected void unsetDeviceManagementProviderService(
DeviceManagementProviderService deviceManagementProviderService) {
GCMDataHolder.getInstance().setDeviceManagementProviderService(deviceManagementProviderService);
}
}

@ -0,0 +1,148 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ 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.
-->
<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>
<artifactId>device-mgt-extensions</artifactId>
<groupId>org.wso2.carbon.devicemgt</groupId>
<version>1.1.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>org.wso2.carbon.device.mgt.extensions.push.notification.provider.mqtt</artifactId>
<packaging>bundle</packaging>
<name>WSO2 Carbon - MQTT Based Push Notification Provider Implementation</name>
<description>WSO2 Carbon - MQTT Based Push Notification Provider Implementation</description>
<url>http://wso2.org</url>
<dependencies>
<dependency>
<groupId>org.wso2.carbon.governance</groupId>
<artifactId>org.wso2.carbon.governance.api</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.registry.core</artifactId>
</dependency>
<dependency>
<groupId>org.wso2.carbon.devicemgt</groupId>
<artifactId>org.wso2.carbon.device.mgt.common</artifactId>
</dependency>
<dependency>
<groupId>org.wso2.carbon.devicemgt</groupId>
<artifactId>org.wso2.carbon.device.mgt.core</artifactId>
</dependency>
<dependency>
<groupId>org.apache.ws.commons.axiom</groupId>
<artifactId>axiom-api</artifactId>
</dependency>
<dependency>
<groupId>org.wso2.carbon</groupId>
<artifactId>org.wso2.carbon.utils</artifactId>
</dependency>
<dependency>
<groupId>org.wso2.orbit.org.scannotation</groupId>
<artifactId>scannotation</artifactId>
</dependency>
<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.tomcat</groupId>
<artifactId>tomcat</artifactId>
</dependency>
<dependency>
<groupId>org.wso2.tomcat</groupId>
<artifactId>tomcat-servlet-api</artifactId>
</dependency>
<dependency>
<groupId>javax.ws.rs</groupId>
<artifactId>jsr311-api</artifactId>
</dependency>
<dependency>
<groupId>org.apache.axis2.wso2</groupId>
<artifactId>axis2</artifactId>
</dependency>
<dependency>
<groupId>commons-lang.wso2</groupId>
<artifactId>commons-lang</artifactId>
</dependency>
<dependency>
<groupId>org.eclipse.paho</groupId>
<artifactId>org.eclipse.paho.client.mqttv3</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
</dependency>
<dependency>
<groupId>org.json.wso2</groupId>
<artifactId>json</artifactId>
</dependency>
<dependency>
<groupId>org.wso2.carbon.analytics-common</groupId>
<artifactId>org.wso2.carbon.event.output.adapter.core</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<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>MQTT Based Push Notification Provider Bundle</Bundle-Description>
<Export-Package>
!org.wso2.carbon.device.mgt.extensions.push.notification.provider.mqtt.internal,
org.wso2.carbon.device.mgt.extensions.push.notification.provider.mqtt.*
</Export-Package>
<Import-Package>
org.apache.commons.logging,
org.osgi.service.component,
org.wso2.carbon.context,
org.wso2.carbon.device.mgt.common.operation.mgt,
org.wso2.carbon.device.mgt.common.push.notification,
org.wso2.carbon.device.mgt.core.service,
org.wso2.carbon.event.output.adapter.core,
org.wso2.carbon.event.output.adapter.core.exception
</Import-Package>
</instructions>
</configuration>
</plugin>
</plugins>
</build>
</project>

@ -0,0 +1,37 @@
/*
* 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.extensions.push.notification.provider.mqtt;
import org.wso2.carbon.device.mgt.common.push.notification.NotificationStrategy;
import org.wso2.carbon.device.mgt.common.push.notification.PushNotificationConfig;
import org.wso2.carbon.device.mgt.common.push.notification.PushNotificationProvider;
public class MQTTBasedPushNotificationProvider implements PushNotificationProvider {
@Override
public String getType() {
return "MQTT";
}
@Override
public NotificationStrategy getNotificationStrategy(PushNotificationConfig config) {
return new MQTTNotificationStrategy(config);
}
}

@ -0,0 +1,85 @@
/*
* 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.extensions.push.notification.provider.mqtt;
import org.wso2.carbon.device.mgt.common.push.notification.NotificationContext;
import org.wso2.carbon.device.mgt.common.push.notification.NotificationStrategy;
import org.wso2.carbon.device.mgt.common.push.notification.PushNotificationConfig;
import org.wso2.carbon.device.mgt.common.push.notification.PushNotificationExecutionFailedException;
import org.wso2.carbon.device.mgt.extensions.push.notification.provider.mqtt.internal.MQTTDataHolder;
import org.wso2.carbon.device.mgt.extensions.push.notification.provider.mqtt.internal.util.MQTTAdapterConstants;
import org.wso2.carbon.event.output.adapter.core.MessageType;
import org.wso2.carbon.event.output.adapter.core.OutputEventAdapterConfiguration;
import org.wso2.carbon.event.output.adapter.core.exception.OutputEventAdapterException;
import java.util.HashMap;
import java.util.Map;
public class MQTTNotificationStrategy implements NotificationStrategy {
private static final String MQTT_ADAPTER_PROPERTY_NAME = "mqtt.adapter.name";
private static final String MQTT_ADAPTER_TOPIC = "mqtt.adapter.topic";
private static final String MQTT_ADAPTER_NAME = "mqtt.push.notification.publisher";
public MQTTNotificationStrategy(PushNotificationConfig config) {
OutputEventAdapterConfiguration adapterConfig = new OutputEventAdapterConfiguration();
adapterConfig.setType(MQTTAdapterConstants.MQTT_ADAPTER_TYPE);
adapterConfig.setName(MQTT_ADAPTER_NAME);
adapterConfig.setMessageFormat(MessageType.JSON);
Map<String, String> configProperties = new HashMap<String, String>();
configProperties.put(MQTTAdapterConstants.MQTT_ADAPTER_PROPERTY_BROKER_URL,
config.getProperty(MQTTAdapterConstants.MQTT_ADAPTER_PROPERTY_BROKER_URL));
configProperties.put(MQTTAdapterConstants.MQTT_ADAPTER_PROPERTY_USERNAME,
config.getProperty(MQTTAdapterConstants.MQTT_ADAPTER_PROPERTY_USERNAME));
configProperties.put(MQTTAdapterConstants.MQTT_ADAPTER_PROPERTY_DCR_URL,
config.getProperty(MQTTAdapterConstants.MQTT_ADAPTER_PROPERTY_DCR_URL));
configProperties.put(MQTTAdapterConstants.MQTT_ADAPTER_PROPERTY_CLEAR_SESSION,
config.getProperty(MQTTAdapterConstants.MQTT_ADAPTER_PROPERTY_CLEAR_SESSION));
configProperties.put(MQTTAdapterConstants.MQTT_ADAPTER_PROPERTY_SCOPES,
config.getProperty(MQTTAdapterConstants.MQTT_ADAPTER_PROPERTY_SCOPES));
configProperties.put(MQTTAdapterConstants.MQTT_ADAPTER_PROPERTY_MESSAGE_QOS,
config.getProperty(MQTTAdapterConstants.MQTT_ADAPTER_PROPERTY_MESSAGE_QOS));
adapterConfig.setStaticProperties(configProperties);
try {
MQTTDataHolder.getInstance().getOutputEventAdapterService().create(adapterConfig);
} catch (OutputEventAdapterException e) {
throw new RuntimeException("Error occurred while initializing MQTT output event adapter", e);
}
}
@Override
public void init() {
}
@Override
public void execute(NotificationContext ctx) throws PushNotificationExecutionFailedException {
Map<String, String> dynamicProperties = ctx.getProperties();
dynamicProperties.put("topic", (String) ctx.getOperation().getProperties().get(MQTT_ADAPTER_TOPIC));
MQTTDataHolder.getInstance().getOutputEventAdapterService().publish(MQTT_ADAPTER_NAME, dynamicProperties,
ctx.getOperation().getPayLoad());
}
@Override
public NotificationContext buildContext() {
return null;
}
}

@ -0,0 +1,46 @@
/*
* 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.extensions.push.notification.provider.mqtt;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.context.CarbonContext;
import org.wso2.carbon.context.PrivilegedCarbonContext;
import org.wso2.carbon.event.output.adapter.core.OutputEventAdapterService;
public class MQTTPushNotificationStrategyUtil {
private static final Log log = LogFactory.getLog(MQTTPushNotificationStrategyUtil.class);
public static String getAuthenticatedUser() {
CarbonContext carbonContext = CarbonContext.getThreadLocalCarbonContext();
String username = carbonContext.getUsername();
String tenantDomain = carbonContext.getTenantDomain();
if (username.endsWith(tenantDomain)) {
return username.substring(0, username.lastIndexOf("@"));
}
return username;
}
public static String getAuthenticatedUserTenantDomain() {
return CarbonContext.getThreadLocalCarbonContext().getTenantDomain();
}
}

@ -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.device.mgt.extensions.push.notification.provider.mqtt.internal;
import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService;
import org.wso2.carbon.event.output.adapter.core.OutputEventAdapterService;
public class MQTTDataHolder {
private OutputEventAdapterService outputEventAdapterService;
private DeviceManagementProviderService deviceManagementProviderService;
private static MQTTDataHolder thisInstance = new MQTTDataHolder();
public static MQTTDataHolder getInstance() {
return thisInstance;
}
public DeviceManagementProviderService getDeviceManagementProviderService() {
return deviceManagementProviderService;
}
public void setDeviceManagementProviderService(DeviceManagementProviderService deviceManagementProviderService) {
this.deviceManagementProviderService = deviceManagementProviderService;
}
public void setOutputEventAdapterService(OutputEventAdapterService outputEventAdapterService) {
this.outputEventAdapterService = outputEventAdapterService;
}
public OutputEventAdapterService getOutputEventAdapterService() {
return outputEventAdapterService;
}
}

@ -0,0 +1,83 @@
/*
* 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.extensions.push.notification.provider.mqtt.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.service.DeviceManagementProviderService;
import org.wso2.carbon.event.output.adapter.core.OutputEventAdapterService;
/**
* @scr.component name="org.wso2.carbon.device.mgt.extensions.push.notification.provider.gcm.internal.MQTTPushNotificationServiceComponent" immediate="true"
* @scr.reference name="carbon.device.mgt.provider"
* interface="org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService"
* cardinality="1..1"
* policy="dynamic"
* bind="setDeviceManagementProviderService"
* unbind="unsetDeviceManagementProviderService"
* @scr.reference name="event.output.adapter.service"
* interface="org.wso2.carbon.event.output.adapter.core.OutputEventAdapterService"
* cardinality="1..1" policy="dynamic" bind="setOutputEventAdapterService"
* unbind="unsetOutputEventAdapterService"
*/
public class MQTTPushNotificationServiceComponent {
private static final Log log = LogFactory.getLog(MQTTPushNotificationServiceComponent.class);
@SuppressWarnings("unused")
protected void activate(ComponentContext componentContext) {
try {
if (log.isDebugEnabled()) {
log.debug("Initializing MQTT based push notification provider implementation bundle");
}
//Do nothing
if (log.isDebugEnabled()) {
log.debug("MQTT based push notification provider implementation bundle has been successfully " +
"initialized");
}
} catch (Throwable e) {
log.error("Error occurred while initializing MQTT based push notification provider " +
"implementation bundle", e);
}
}
protected void deactivate(ComponentContext componentContext) {
//Do nothing
}
protected void setDeviceManagementProviderService(
DeviceManagementProviderService deviceManagementProviderService) {
MQTTDataHolder.getInstance().setDeviceManagementProviderService(deviceManagementProviderService);
}
protected void unsetDeviceManagementProviderService(
DeviceManagementProviderService deviceManagementProviderService) {
MQTTDataHolder.getInstance().setDeviceManagementProviderService(deviceManagementProviderService);
}
protected void setOutputEventAdapterService(OutputEventAdapterService outputEventAdapterService){
MQTTDataHolder.getInstance().setOutputEventAdapterService(outputEventAdapterService);
}
protected void unsetOutputEventAdapterService(OutputEventAdapterService outputEventAdapterService){
MQTTDataHolder.getInstance().setOutputEventAdapterService(null);
}
}

@ -0,0 +1,37 @@
/*
* 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.extensions.push.notification.provider.mqtt.internal.util;
public final class MQTTAdapterConstants {
private MQTTAdapterConstants() {
throw new AssertionError();
}
public static final String MQTT_ADAPTER_TYPE = "oauth-mqtt";
public static final String MQTT_ADAPTER_PROPERTY_BROKER_URL = "url";
public static final String MQTT_ADAPTER_PROPERTY_USERNAME = "username";
public static final String MQTT_ADAPTER_PROPERTY_DCR_URL = "dcrUrl";
public static final String MQTT_ADAPTER_PROPERTY_SCOPES = "scopes";
public static final String MQTT_ADAPTER_PROPERTY_PASSWORD = "password";
public static final String MQTT_ADAPTER_PROPERTY_CLIENT_ID = "clientId";
public static final String MQTT_ADAPTER_PROPERTY_CLEAR_SESSION = "cleanSession";
public static final String MQTT_ADAPTER_PROPERTY_MESSAGE_QOS = "qos";
}

@ -0,0 +1,144 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ 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.
-->
<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>
<artifactId>device-mgt-extensions</artifactId>
<groupId>org.wso2.carbon.devicemgt</groupId>
<version>1.1.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>org.wso2.carbon.device.mgt.extensions.push.notification.provider.xmpp</artifactId>
<packaging>bundle</packaging>
<name>WSO2 Carbon - XMPP Based Push Notification Provider Implementation</name>
<description>WSO2 Carbon - XMPP Based Push Notification Provider Implementation</description>
<url>http://wso2.org</url>
<dependencies>
<dependency>
<groupId>org.wso2.carbon.governance</groupId>
<artifactId>org.wso2.carbon.governance.api</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.registry.core</artifactId>
</dependency>
<dependency>
<groupId>org.wso2.carbon.devicemgt</groupId>
<artifactId>org.wso2.carbon.device.mgt.common</artifactId>
</dependency>
<dependency>
<groupId>org.wso2.carbon.devicemgt</groupId>
<artifactId>org.wso2.carbon.device.mgt.core</artifactId>
</dependency>
<dependency>
<groupId>org.apache.ws.commons.axiom</groupId>
<artifactId>axiom-api</artifactId>
</dependency>
<dependency>
<groupId>org.wso2.carbon</groupId>
<artifactId>org.wso2.carbon.utils</artifactId>
</dependency>
<dependency>
<groupId>org.wso2.orbit.org.scannotation</groupId>
<artifactId>scannotation</artifactId>
</dependency>
<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.tomcat</groupId>
<artifactId>tomcat</artifactId>
</dependency>
<dependency>
<groupId>org.wso2.tomcat</groupId>
<artifactId>tomcat-servlet-api</artifactId>
</dependency>
<dependency>
<groupId>javax.ws.rs</groupId>
<artifactId>jsr311-api</artifactId>
</dependency>
<dependency>
<groupId>org.apache.axis2.wso2</groupId>
<artifactId>axis2</artifactId>
</dependency>
<dependency>
<groupId>commons-lang.wso2</groupId>
<artifactId>commons-lang</artifactId>
</dependency>
<dependency>
<groupId>org.eclipse.paho</groupId>
<artifactId>org.eclipse.paho.client.mqttv3</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
</dependency>
<dependency>
<groupId>org.json.wso2</groupId>
<artifactId>json</artifactId>
</dependency>
<dependency>
<groupId>org.wso2.carbon.analytics-common</groupId>
<artifactId>org.wso2.carbon.event.output.adapter.core</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<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>XMPP Based Push Notification Provider Bundle</Bundle-Description>
<Export-Package>
!org.wso2.carbon.device.mgt.extensions.push.notification.provider.xmpp.internal,
org.wso2.carbon.device.mgt.extensions.push.notification.provider.xmpp.*
</Export-Package>
<Import-Package>
org.apache.commons.logging,
org.osgi.service.component,
org.wso2.carbon.device.mgt.common.push.notification,
org.wso2.carbon.device.mgt.core.service
</Import-Package>
</instructions>
</configuration>
</plugin>
</plugins>
</build>
</project>

@ -0,0 +1,37 @@
/*
* 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.extensions.push.notification.provider.xmpp;
import org.wso2.carbon.device.mgt.common.push.notification.NotificationStrategy;
import org.wso2.carbon.device.mgt.common.push.notification.PushNotificationConfig;
import org.wso2.carbon.device.mgt.common.push.notification.PushNotificationProvider;
public class XMPPBasedPushNotificationProvider implements PushNotificationProvider {
@Override
public String getType() {
return "XMPP";
}
@Override
public NotificationStrategy getNotificationStrategy(PushNotificationConfig pushNotificationConfig) {
return null;
}
}

@ -0,0 +1,42 @@
/*
* 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.extensions.push.notification.provider.xmpp;
import org.wso2.carbon.device.mgt.common.push.notification.NotificationContext;
import org.wso2.carbon.device.mgt.common.push.notification.NotificationStrategy;
import org.wso2.carbon.device.mgt.common.push.notification.PushNotificationExecutionFailedException;
public class XMPPNotificationStrategy implements NotificationStrategy {
@Override
public void init() {
}
@Override
public void execute(NotificationContext ctx) throws PushNotificationExecutionFailedException {
}
@Override
public NotificationContext buildContext() {
return null;
}
}

@ -0,0 +1,40 @@
/*
* 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.extensions.push.notification.provider.xmpp.internal;
import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService;
public class XMPPDataHolder {
private DeviceManagementProviderService deviceManagementProviderService;
private static XMPPDataHolder thisInstance = new XMPPDataHolder();
public static XMPPDataHolder getInstance() {
return thisInstance;
}
public DeviceManagementProviderService getDeviceManagementProviderService() {
return deviceManagementProviderService;
}
public void setDeviceManagementProviderService(DeviceManagementProviderService deviceManagementProviderService) {
this.deviceManagementProviderService = deviceManagementProviderService;
}
}

@ -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.extensions.push.notification.provider.xmpp.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.service.DeviceManagementProviderService;
/**
* @scr.component name="org.wso2.carbon.device.mgt.extensions.push.notification.provider.gcm.internal.XMPPPushNotificationServiceComponent" immediate="true"
* @scr.reference name="carbon.device.mgt.provider"
* interface="org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService"
* cardinality="1..1"
* policy="dynamic"
* bind="setDeviceManagementProviderService"
* unbind="unsetDeviceManagementProviderService"
*/
public class XMPPPushNotificationServiceComponent {
private static final Log log = LogFactory.getLog(XMPPPushNotificationServiceComponent.class);
@SuppressWarnings("unused")
protected void activate(ComponentContext componentContext) {
try {
if (log.isDebugEnabled()) {
log.debug("Initializing XMPP based push notification provider implementation bundle");
}
//Do nothing
if (log.isDebugEnabled()) {
log.debug("XMPP based push notification provider implementation bundle has been successfully " +
"initialized");
}
} catch (Throwable e) {
log.error("Error occurred while initializing XMPP based push notification provider " +
"implementation bundle", e);
}
}
protected void deactivate(ComponentContext componentContext) {
//Do nothing
}
protected void setDeviceManagementProviderService(
DeviceManagementProviderService deviceManagementProviderService) {
XMPPDataHolder.getInstance().setDeviceManagementProviderService(deviceManagementProviderService);
}
protected void unsetDeviceManagementProviderService(
DeviceManagementProviderService deviceManagementProviderService) {
XMPPDataHolder.getInstance().setDeviceManagementProviderService(deviceManagementProviderService);
}
}

@ -0,0 +1,42 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ 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.
-->
<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>
<artifactId>carbon-devicemgt</artifactId>
<groupId>org.wso2.carbon.devicemgt</groupId>
<version>1.1.0-SNAPSHOT</version>
<relativePath>../../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>device-mgt-extensions</artifactId>
<packaging>pom</packaging>
<name>WSO2 Carbon - Device Management Extensions</name>
<description>WSO2 Carbon - Device Management Extensions</description>
<url>http://wso2.org</url>
<modules>
<module>org.wso2.carbon.device.mgt.extensions.push.notification.provider.gcm</module>
<module>org.wso2.carbon.device.mgt.extensions.push.notification.provider.mqtt</module>
<module>org.wso2.carbon.device.mgt.extensions.push.notification.provider.xmpp</module>
</modules>
</project>

@ -128,7 +128,14 @@ public class OperationImpl implements org.wso2.carbon.device.mgt.jaxrs.api.Opera
ResponsePayload responseMsg = new ResponsePayload(); ResponsePayload responseMsg = new ResponsePayload();
try { try {
dmService = DeviceMgtAPIUtils.getDeviceManagementService(); dmService = DeviceMgtAPIUtils.getDeviceManagementService();
int operationId = dmService.addOperation(operationContext.getOperation(), operationContext.getDevices());
//TODO: Fix this properly later adding device type to be passed in when the task manage executes "addOperations()"
String type = null;
List<DeviceIdentifier> deviceIdentifiers = operationContext.getDevices();
if (deviceIdentifiers.size() > 0) {
type = deviceIdentifiers.get(0).getType();
}
int operationId = dmService.addOperation(type, operationContext.getOperation(), operationContext.getDevices());
if (operationId > 0) { if (operationId > 0) {
responseMsg.setStatusCode(HttpStatus.SC_CREATED); responseMsg.setStatusCode(HttpStatus.SC_CREATED);
responseMsg.setMessageFromServer("Operation has added successfully."); responseMsg.setMessageFromServer("Operation has added successfully.");

@ -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.device.mgt.common.push.notification;
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
import org.wso2.carbon.device.mgt.common.operation.mgt.Operation;
import java.util.Map;
public class NotificationContext {
private DeviceIdentifier deviceId;
private Operation operation;
private Map<String, String> properties;
public NotificationContext(DeviceIdentifier deviceId) {
this.deviceId = deviceId;
}
public NotificationContext(DeviceIdentifier deviceId, Operation operation) {
this.deviceId = deviceId;
this.operation = operation;
}
public DeviceIdentifier getDeviceId() {
return deviceId;
}
public Map<String, String> getProperties() {
return properties;
}
public Operation getOperation() {
return operation;
}
}

@ -0,0 +1,29 @@
/*
* 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.push.notification;
public interface NotificationStrategy {
void init();
void execute(NotificationContext ctx) throws PushNotificationExecutionFailedException;
NotificationContext buildContext();
}

@ -18,24 +18,32 @@
*/ */
package org.wso2.carbon.device.mgt.common.push.notification; package org.wso2.carbon.device.mgt.common.push.notification;
import java.util.Set; import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import java.util.Map;
@XmlRootElement(name = "PushNotificationProviderConfiguration")
public class PushNotificationConfig { public class PushNotificationConfig {
private String type; private String type;
private Set<String> properties; Map<String, String> properties;
public PushNotificationConfig(String type, Set<String> properties) { public PushNotificationConfig(String type, Map<String, String> properties) {
this.type = type; this.type = type;
this.properties = properties; this.properties = properties;
} }
@XmlElement(name = "Type", required = true)
public String getType() { public String getType() {
return type; return type;
} }
public Set<String> getProperties() { public Map<String, String> getProperties() {
return properties; return properties;
} }
public String getProperty(String name) {
return properties.get(name);
}
} }

@ -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.common.push.notification;
public class PushNotificationExecutionFailedException extends Exception {
private static final long serialVersionUID = -3151279311923070297L;
public PushNotificationExecutionFailedException(String msg, Exception nestedEx) {
super(msg, nestedEx);
}
public PushNotificationExecutionFailedException(String message, Throwable cause) {
super(message, cause);
}
public PushNotificationExecutionFailedException(String msg) {
super(msg);
}
public PushNotificationExecutionFailedException() {
super();
}
public PushNotificationExecutionFailedException(Throwable cause) {
super(cause);
}
}

@ -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.device.mgt.common.push.notification;
public interface PushNotificationProvider {
String getType();
NotificationStrategy getNotificationStrategy(PushNotificationConfig config);
}

@ -91,6 +91,7 @@
!org.wso2.carbon.device.mgt.core.internal, !org.wso2.carbon.device.mgt.core.internal,
org.wso2.carbon.device.mgt.core.* org.wso2.carbon.device.mgt.core.*
</Export-Package> </Export-Package>
<DynamicImport-Package>*</DynamicImport-Package>
</instructions> </instructions>
</configuration> </configuration>
</plugin> </plugin>

@ -80,13 +80,13 @@ public class ApplicationManagerProviderServiceImpl implements ApplicationManagem
@Override @Override
public void updateApplicationStatus(DeviceIdentifier deviceId, Application application, public void updateApplicationStatus(DeviceIdentifier deviceId, Application application,
String status) throws ApplicationManagementException { String status) throws ApplicationManagementException {
} }
@Override @Override
public String getApplicationStatus(DeviceIdentifier deviceId, public String getApplicationStatus(DeviceIdentifier deviceId,
Application application) throws ApplicationManagementException { Application application) throws ApplicationManagementException {
return null; return null;
} }
@ -94,17 +94,19 @@ public class ApplicationManagerProviderServiceImpl implements ApplicationManagem
public void installApplicationForDevices(Operation operation, List<DeviceIdentifier> deviceIds) public void installApplicationForDevices(Operation operation, List<DeviceIdentifier> deviceIds)
throws ApplicationManagementException { throws ApplicationManagementException {
try { try {
DeviceManagementDataHolder.getInstance().getDeviceManagementProvider().addOperation(operation, deviceIds); //TODO: Fix this properly later adding device type to be passed in when the task manage executes "addOperations()"
String type = null;
if (deviceIds.size() > 0) {
type = deviceIds.get(0).getType();
}
DeviceManagementDataHolder.getInstance().getDeviceManagementProvider().addOperation(type, operation,
deviceIds);
DeviceManagementDataHolder.getInstance().getDeviceManagementProvider().notifyOperationToDevices DeviceManagementDataHolder.getInstance().getDeviceManagementProvider().notifyOperationToDevices
(operation, deviceIds); (operation, deviceIds);
} catch (OperationManagementException opeEx) { } catch (OperationManagementException e) {
String errorMsg = "Error in add operation at app installation:" + opeEx.getErrorMessage(); throw new ApplicationManagementException("Error in add operation at app installation", e);
log.error(errorMsg, opeEx); } catch (DeviceManagementException e) {
throw new ApplicationManagementException(errorMsg, opeEx); throw new ApplicationManagementException("Error in notify operation at app installation", e);
}catch (DeviceManagementException deviceEx){
String errorMsg = "Error in notify operation at app installation:" + deviceEx.getErrorMessage();
log.error(errorMsg, deviceEx);
throw new ApplicationManagementException(errorMsg, deviceEx);
} }
} }
@ -119,7 +121,6 @@ public class ApplicationManagerProviderServiceImpl implements ApplicationManagem
DeviceIdentifier deviceIdentifier; DeviceIdentifier deviceIdentifier;
for (String user : userNameList) { for (String user : userNameList) {
userName = user; userName = user;
deviceList = DeviceManagementDataHolder.getInstance().getDeviceManagementProvider().getDevicesOfUser deviceList = DeviceManagementDataHolder.getInstance().getDeviceManagementProvider().getDevicesOfUser
@ -132,18 +133,20 @@ public class ApplicationManagerProviderServiceImpl implements ApplicationManagem
deviceIdentifierList.add(deviceIdentifier); deviceIdentifierList.add(deviceIdentifier);
} }
} }
//TODO: Fix this properly later adding device type to be passed in when the task manage executes "addOperations()"
String type = null;
if (deviceIdentifierList.size() > 0) {
type = deviceIdentifierList.get(0).getType();
}
DeviceManagementDataHolder.getInstance().getDeviceManagementProvider() DeviceManagementDataHolder.getInstance().getDeviceManagementProvider()
.addOperation(operation, deviceIdentifierList); .addOperation(type, operation, deviceIdentifierList);
} catch (DeviceManagementException devEx) { } catch (DeviceManagementException e) {
String errorMsg = "Error in get devices for user: "+userName+ " in app installation:" + devEx.getErrorMessage(); throw new ApplicationManagementException("Error in get devices for user: " + userName +
log.error(errorMsg, devEx); " in app installation", e);
throw new ApplicationManagementException(errorMsg, devEx);
} catch (OperationManagementException opeEx) { } catch (OperationManagementException e) {
String errorMsg = "Error in add operation at app installation:" + opeEx.getErrorMessage(); throw new ApplicationManagementException("Error in add operation at app installation", e);
log.error(errorMsg, opeEx);
throw new ApplicationManagementException(errorMsg, opeEx);
} }
} }
@ -170,19 +173,20 @@ public class ApplicationManagerProviderServiceImpl implements ApplicationManagem
deviceIdentifierList.add(deviceIdentifier); deviceIdentifierList.add(deviceIdentifier);
} }
} }
DeviceManagementDataHolder.getInstance().getDeviceManagementProvider() //TODO: Fix this properly later adding device type to be passed in when the task manage executes "addOperations()"
.addOperation(operation, deviceIdentifierList); String type = null;
if (deviceIdentifierList.size() > 0) {
} catch (DeviceManagementException devEx) { type = deviceIdentifierList.get(0).getType();
String errorMsg = "Error in get devices for user role "+userRole+ " in app installation:" }
+ devEx.getErrorMessage(); DeviceManagementDataHolder.getInstance().getDeviceManagementProvider().addOperation(type, operation,
log.error(errorMsg, devEx); deviceIdentifierList);
throw new ApplicationManagementException(errorMsg, devEx);
} catch (DeviceManagementException e) {
} catch (OperationManagementException opeEx) { throw new ApplicationManagementException("Error in get devices for user role " + userRole +
String errorMsg = "Error in add operation at app installation:" + opeEx.getErrorMessage(); " in app installation", e);
log.error(errorMsg, opeEx);
throw new ApplicationManagementException(errorMsg, opeEx); } catch (OperationManagementException e) {
throw new ApplicationManagementException("Error in add operation at app installation", e);
} }
} }

@ -22,18 +22,23 @@ import org.wso2.carbon.device.mgt.core.config.policy.PolicyConfiguration;
import org.wso2.carbon.device.mgt.core.config.task.TaskConfiguration; import org.wso2.carbon.device.mgt.core.config.task.TaskConfiguration;
import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlElementWrapper;
import javax.xml.bind.annotation.XmlRootElement; import javax.xml.bind.annotation.XmlRootElement;
import java.util.List;
/** /**
* Represents Device Mgt configuration. * Represents Device Mgt configuration.
*/ */
@XmlRootElement(name = "DeviceMgtConfiguration") @XmlRootElement(name = "DeviceMgtConfiguration")
@SuppressWarnings("unused")
public final class DeviceManagementConfig { public final class DeviceManagementConfig {
private DeviceManagementConfigRepository deviceManagementConfigRepository; private DeviceManagementConfigRepository deviceManagementConfigRepository;
private TaskConfiguration taskConfiguration; private TaskConfiguration taskConfiguration;
private IdentityConfigurations identityConfigurations; private IdentityConfigurations identityConfigurations;
private PolicyConfiguration policyConfiguration; private PolicyConfiguration policyConfiguration;
private List<String> pushNotificationProviders;
@XmlElement(name = "ManagementRepository", required = true) @XmlElement(name = "ManagementRepository", required = true)
public DeviceManagementConfigRepository getDeviceManagementConfigRepository() { public DeviceManagementConfigRepository getDeviceManagementConfigRepository() {
@ -72,15 +77,15 @@ public final class DeviceManagementConfig {
this.taskConfiguration = taskConfiguration; this.taskConfiguration = taskConfiguration;
} }
// @XmlElementWrapper(name = "PushNotificationProviders", required = true) @XmlElementWrapper(name = "PushNotificationProviders", required = true)
// @XmlElement(name = "Provider", required = true) @XmlElement(name = "Provider", required = true)
// public List<String> getPushNotificationProviders() { public List<String> getPushNotificationProviders() {
// return pushNotificationProviders; return pushNotificationProviders;
// } }
//
// public void setPushNotificationProviders(List<String> pushNotificationProviders) { public void setPushNotificationProviders(List<String> pushNotificationProviders) {
// this.pushNotificationProviders = pushNotificationProviders; this.pushNotificationProviders = pushNotificationProviders;
// } }
} }

@ -24,6 +24,7 @@ import org.wso2.carbon.device.mgt.common.license.mgt.LicenseManager;
import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManager; import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManager;
import org.wso2.carbon.device.mgt.core.app.mgt.config.AppManagementConfig; import org.wso2.carbon.device.mgt.core.app.mgt.config.AppManagementConfig;
import org.wso2.carbon.device.mgt.core.config.license.LicenseConfig; import org.wso2.carbon.device.mgt.core.config.license.LicenseConfig;
import org.wso2.carbon.device.mgt.core.push.notification.mgt.PushNotificationProviderRepository;
import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService; import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService;
import org.wso2.carbon.device.mgt.core.service.GroupManagementProviderService; import org.wso2.carbon.device.mgt.core.service.GroupManagementProviderService;
import org.wso2.carbon.email.sender.core.service.EmailSenderService; import org.wso2.carbon.email.sender.core.service.EmailSenderService;
@ -53,6 +54,7 @@ public class DeviceManagementDataHolder {
private GroupManagementProviderService groupManagementProviderService; private GroupManagementProviderService groupManagementProviderService;
private TaskService taskService; private TaskService taskService;
private EmailSenderService emailSenderService; private EmailSenderService emailSenderService;
private PushNotificationProviderRepository pushNotificationProviderRepository;
private DeviceManagementDataHolder() {} private DeviceManagementDataHolder() {}
@ -196,4 +198,13 @@ public class DeviceManagementDataHolder {
this.emailSenderService = emailSenderService; this.emailSenderService = emailSenderService;
} }
public void setPushNotificationProviderRepository(
PushNotificationProviderRepository pushNotificationProviderRepository) {
this.pushNotificationProviderRepository = pushNotificationProviderRepository;
}
public PushNotificationProviderRepository getPushNotificationProviderRepository() {
return pushNotificationProviderRepository;
}
} }

@ -30,6 +30,8 @@ import org.wso2.carbon.device.mgt.common.notification.mgt.NotificationManagement
import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManagementException; import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManagementException;
import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManager; import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManager;
import org.wso2.carbon.device.mgt.common.permission.mgt.PermissionManagerService; import org.wso2.carbon.device.mgt.common.permission.mgt.PermissionManagerService;
import org.wso2.carbon.device.mgt.common.push.notification.PushNotificationConfig;
import org.wso2.carbon.device.mgt.common.push.notification.PushNotificationProvider;
import org.wso2.carbon.device.mgt.common.spi.DeviceManagementService; import org.wso2.carbon.device.mgt.common.spi.DeviceManagementService;
import org.wso2.carbon.device.mgt.core.DeviceManagementConstants; import org.wso2.carbon.device.mgt.core.DeviceManagementConstants;
import org.wso2.carbon.device.mgt.core.DeviceManagementPluginRepository; import org.wso2.carbon.device.mgt.core.DeviceManagementPluginRepository;
@ -49,6 +51,8 @@ import org.wso2.carbon.device.mgt.core.notification.mgt.dao.NotificationManageme
import org.wso2.carbon.device.mgt.core.operation.mgt.OperationManagerImpl; import org.wso2.carbon.device.mgt.core.operation.mgt.OperationManagerImpl;
import org.wso2.carbon.device.mgt.core.operation.mgt.dao.OperationManagementDAOFactory; import org.wso2.carbon.device.mgt.core.operation.mgt.dao.OperationManagementDAOFactory;
import org.wso2.carbon.device.mgt.core.permission.mgt.PermissionManagerServiceImpl; import org.wso2.carbon.device.mgt.core.permission.mgt.PermissionManagerServiceImpl;
import org.wso2.carbon.device.mgt.core.push.notification.mgt.PushNotificationConfigRepository;
import org.wso2.carbon.device.mgt.core.push.notification.mgt.PushNotificationProviderRepository;
import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService; import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService;
import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderServiceImpl; import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderServiceImpl;
import org.wso2.carbon.device.mgt.core.service.GroupManagementProviderService; import org.wso2.carbon.device.mgt.core.service.GroupManagementProviderService;
@ -153,15 +157,26 @@ public class DeviceManagementServiceComponent {
NotificationManagementDAOFactory.init(dsConfig); NotificationManagementDAOFactory.init(dsConfig);
OperationManagementDAOFactory.init(dsConfig); OperationManagementDAOFactory.init(dsConfig);
/*Initialize Operation Manager*/
/* Initialize Operation Manager */
this.initOperationsManager(); this.initOperationsManager();
PushNotificationProviderRepository pushNotificationRepo = new PushNotificationProviderRepository();
List<String> pushNotificationProviders = config.getPushNotificationProviders();
if (pushNotificationProviders != null) {
for (String pushNoteProvider : pushNotificationProviders) {
pushNotificationRepo.addProvider(pushNoteProvider);
}
}
DeviceManagementDataHolder.getInstance().setPushNotificationProviderRepository(pushNotificationRepo);
/* If -Dsetup option enabled then create device management database schema */ /* If -Dsetup option enabled then create device management database schema */
String setupOption = String setupOption =
System.getProperty(DeviceManagementConstants.Common.PROPERTY_SETUP); System.getProperty(DeviceManagementConstants.Common.PROPERTY_SETUP);
if (setupOption != null) { if (setupOption != null) {
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
log.debug("-Dsetup is enabled. Device management repository schema initialization is about to " + log.debug("-Dsetup is enabled. Device management repository schema initialization is about to " +
"begin"); "begin");
} }
this.setupDeviceManagementSchema(dsConfig); this.setupDeviceManagementSchema(dsConfig);
} }

@ -27,6 +27,9 @@ import org.wso2.carbon.device.mgt.common.group.mgt.DeviceGroupConstants;
import org.wso2.carbon.device.mgt.common.operation.mgt.Operation; import org.wso2.carbon.device.mgt.common.operation.mgt.Operation;
import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManagementException; import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManagementException;
import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManager; import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManager;
import org.wso2.carbon.device.mgt.common.push.notification.NotificationContext;
import org.wso2.carbon.device.mgt.common.push.notification.NotificationStrategy;
import org.wso2.carbon.device.mgt.common.push.notification.PushNotificationExecutionFailedException;
import org.wso2.carbon.device.mgt.core.DeviceManagementConstants; import org.wso2.carbon.device.mgt.core.DeviceManagementConstants;
import org.wso2.carbon.device.mgt.core.dao.DeviceDAO; import org.wso2.carbon.device.mgt.core.dao.DeviceDAO;
import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOException; import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOException;
@ -62,6 +65,7 @@ public class OperationManagerImpl implements OperationManager {
private OperationMappingDAO operationMappingDAO; private OperationMappingDAO operationMappingDAO;
private OperationDAO operationDAO; private OperationDAO operationDAO;
private DeviceDAO deviceDAO; private DeviceDAO deviceDAO;
private NotificationStrategy notificationStrategy;
public OperationManagerImpl() { public OperationManagerImpl() {
commandOperationDAO = OperationManagementDAOFactory.getCommandOperationDAO(); commandOperationDAO = OperationManagementDAOFactory.getCommandOperationDAO();
@ -73,6 +77,11 @@ public class OperationManagerImpl implements OperationManager {
deviceDAO = DeviceManagementDAOFactory.getDeviceDAO(); deviceDAO = DeviceManagementDAOFactory.getDeviceDAO();
} }
public OperationManagerImpl(NotificationStrategy notificationStrategy) {
this();
this.notificationStrategy = notificationStrategy;
}
@Override @Override
public int addOperation(Operation operation, public int addOperation(Operation operation,
List<DeviceIdentifier> deviceIds) throws OperationManagementException { List<DeviceIdentifier> deviceIds) throws OperationManagementException {
@ -80,66 +89,92 @@ public class OperationManagerImpl implements OperationManager {
log.debug("operation:[" + operation.toString() + "]"); log.debug("operation:[" + operation.toString() + "]");
for (DeviceIdentifier deviceIdentifier : deviceIds) { for (DeviceIdentifier deviceIdentifier : deviceIds) {
log.debug("device identifier id:[" + deviceIdentifier.getId() + "] type:[" + log.debug("device identifier id:[" + deviceIdentifier.getId() + "] type:[" +
deviceIdentifier.getType() + "]"); deviceIdentifier.getType() + "]");
} }
} }
List<DeviceIdentifier> authorizedDeviceList = this.getAuthorizedDevices(operation, deviceIds);
if (authorizedDeviceList.size() <= 0) {
log.info("User : " + getUser() + " is not authorized to perform operations on given device-list.");
return -1;
}
List<EnrolmentInfo> enrolments = this.getEnrollmentsByStatus(deviceIds);
try { try {
List<DeviceIdentifier> authorizedDeviceList;
if (operation != null && isAuthenticationSkippedOperation(operation)) { OperationManagementDAOFactory.beginTransaction();
authorizedDeviceList = deviceIds; org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation operationDto =
} else { OperationDAOUtil.convertOperation(operation);
authorizedDeviceList = DeviceManagementDataHolder.getInstance(). int operationId = this.lookupOperationDAO(operation).addOperation(operationDto);
getDeviceAccessAuthorizationService().isUserAuthorized(deviceIds, DeviceGroupConstants. for (EnrolmentInfo enrolmentInfo : enrolments) {
Permissions.DEFAULT_OPERATOR_PERMISSIONS).getAuthorizedDevices(); if (operationDto.getControl() ==
} org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Control.NO_REPEAT) {
if (authorizedDeviceList.size() > 0) { operationDAO.updateEnrollmentOperationsStatus(enrolmentInfo.getId(), operationDto.getCode(),
try { org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Status.PENDING,
int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId(); org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Status.REPEATED);
List<EnrolmentInfo> enrolments; }
operationMappingDAO.addOperationMapping(operationId, enrolmentInfo.getId());
if (notificationStrategy != null) {
try { try {
DeviceManagementDAOFactory.openConnection();
enrolments = deviceDAO.getEnrolmentsByStatus(authorizedDeviceList, EnrolmentInfo.Status.ACTIVE, tenantId);
} catch (SQLException e) {
throw new OperationManagementException("Error occurred while opening a connection the data " +
"source", e);
} finally {
DeviceManagementDAOFactory.closeConnection();
}
OperationManagementDAOFactory.beginTransaction(); notificationStrategy.execute(new NotificationContext(
org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation operationDto = new DeviceIdentifier(enrolmentInfo.getDevice().getDeviceIdentifier(),
OperationDAOUtil.convertOperation(operation); enrolmentInfo.getDevice().getType())));
int operationId = this.lookupOperationDAO(operation).addOperation(operationDto); } catch (PushNotificationExecutionFailedException e) {
for (EnrolmentInfo enrolmentInfo : enrolments) { log.error("Error occurred while sending push notifications to " +
if(operationDto.getControl() == enrolmentInfo.getDevice().getType() + " device carrying id '" +
org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Control.NO_REPEAT){ enrolmentInfo.getDevice().getDeviceIdentifier() + "'", e);
operationDAO.updateEnrollmentOperationsStatus(enrolmentInfo.getId(), operationDto.getCode(),
org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Status.PENDING,
org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Status.REPEATED);
}
operationMappingDAO.addOperationMapping(operationId, enrolmentInfo.getId());
} }
OperationManagementDAOFactory.commitTransaction();
return operationId;
} catch (OperationManagementDAOException e) {
OperationManagementDAOFactory.rollbackTransaction();
throw new OperationManagementException("Error occurred while adding operation", e);
} catch (DeviceManagementDAOException e) {
OperationManagementDAOFactory.rollbackTransaction();
throw new OperationManagementException("Error occurred while retrieving device metadata", e);
} catch (TransactionManagementException e) {
throw new OperationManagementException("Error occurred while initiating the transaction", e);
} finally {
OperationManagementDAOFactory.closeConnection();
} }
}
OperationManagementDAOFactory.commitTransaction();
return operationId;
} catch (OperationManagementDAOException e) {
OperationManagementDAOFactory.rollbackTransaction();
throw new OperationManagementException("Error occurred while adding operation", e);
} catch (TransactionManagementException e) {
throw new OperationManagementException("Error occurred while initiating the transaction", e);
} finally {
OperationManagementDAOFactory.closeConnection();
}
}
private List<DeviceIdentifier> getAuthorizedDevices(
Operation operation, List<DeviceIdentifier> deviceIds) throws OperationManagementException {
List<DeviceIdentifier> authorizedDeviceList;
try {
if (operation != null && isAuthenticationSkippedOperation(operation)) {
authorizedDeviceList = deviceIds;
} else { } else {
log.info("User : " + getUser() + " is not authorized to perform operations on given device-list."); authorizedDeviceList = DeviceManagementDataHolder.getInstance().
getDeviceAccessAuthorizationService().isUserAuthorized(deviceIds).getAuthorizedDevices();
} }
} catch (DeviceAccessAuthorizationException e) { } catch (DeviceAccessAuthorizationException e) {
throw new OperationManagementException("Error occurred while authorizing access to the devices for user :" + throw new OperationManagementException("Error occurred while authorizing access to the devices for user :" +
this.getUser(), e); this.getUser(), e);
} }
return -1; return authorizedDeviceList;
}
private List<EnrolmentInfo> getEnrollmentsByStatus(
List<DeviceIdentifier> deviceIds) throws OperationManagementException {
List<EnrolmentInfo> enrolments;
int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
try {
DeviceManagementDAOFactory.openConnection();
enrolments = deviceDAO.getEnrolmentsByStatus(deviceIds, EnrolmentInfo.Status.ACTIVE, tenantId);
} catch (SQLException e) {
throw new OperationManagementException("Error occurred while opening a connection the data " +
"source", e);
} catch (DeviceManagementDAOException e) {
OperationManagementDAOFactory.rollbackTransaction();
throw new OperationManagementException(
"Error occurred while retrieving enrollments by status", e);
} finally {
DeviceManagementDAOFactory.closeConnection();
}
return enrolments;
} }
@Override @Override
@ -162,8 +197,8 @@ public class OperationManagerImpl implements OperationManager {
OperationManagementDAOFactory.openConnection(); OperationManagementDAOFactory.openConnection();
if (enrolmentId < 0) { if (enrolmentId < 0) {
throw new OperationManagementException("Device not found for given device " + throw new OperationManagementException("Device not found for given device " +
"Identifier:" + deviceId.getId() + " and given type" + "Identifier:" + deviceId.getId() + " and given type" +
deviceId.getType()); deviceId.getType());
} }
List<? extends org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation> operationList = List<? extends org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation> operationList =
operationDAO.getOperationsForDevice(enrolmentId); operationDAO.getOperationsForDevice(enrolmentId);
@ -174,12 +209,12 @@ public class OperationManagerImpl implements OperationManager {
} }
} catch (OperationManagementDAOException e) { } catch (OperationManagementDAOException e) {
throw new OperationManagementException("Error occurred while retrieving the list of " + throw new OperationManagementException("Error occurred while retrieving the list of " +
"operations assigned for '" + deviceId.getType() + "operations assigned for '" + deviceId.getType() +
"' device '" + deviceId.getId() + "'", e); "' device '" + deviceId.getId() + "'", e);
} catch (DeviceManagementDAOException e) { } catch (DeviceManagementDAOException e) {
throw new OperationManagementException("Error occurred while retrieving metadata of '" + throw new OperationManagementException("Error occurred while retrieving metadata of '" +
deviceId.getType() + "' device carrying the identifier '" + deviceId.getType() + "' device carrying the identifier '" +
deviceId.getId() + "'"); deviceId.getId() + "'");
} catch (SQLException e) { } catch (SQLException e) {
throw new OperationManagementException( throw new OperationManagementException(
"Error occurred while opening a connection to the data source", e); "Error occurred while opening a connection to the data source", e);
@ -191,7 +226,7 @@ public class OperationManagerImpl implements OperationManager {
} }
} catch (DeviceAccessAuthorizationException e) { } catch (DeviceAccessAuthorizationException e) {
throw new OperationManagementException("Error occurred while authorizing access to the devices for user : " + throw new OperationManagementException("Error occurred while authorizing access to the devices for user : " +
this.getUser(), e); this.getUser(), e);
} }
return operations; return operations;
} }
@ -218,8 +253,8 @@ public class OperationManagerImpl implements OperationManager {
OperationManagementDAOFactory.openConnection(); OperationManagementDAOFactory.openConnection();
if (enrolmentId < 0) { if (enrolmentId < 0) {
throw new OperationManagementException("Device not found for given device " + throw new OperationManagementException("Device not found for given device " +
"Identifier:" + deviceId.getId() + " and given type" + "Identifier:" + deviceId.getId() + " and given type" +
deviceId.getType()); deviceId.getType());
} }
List<? extends org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation> operationList = List<? extends org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation> operationList =
operationDAO.getOperationsForDevice(enrolmentId, request); operationDAO.getOperationsForDevice(enrolmentId, request);
@ -234,12 +269,12 @@ public class OperationManagerImpl implements OperationManager {
paginationResult.setRecordsFiltered(count); paginationResult.setRecordsFiltered(count);
} catch (OperationManagementDAOException e) { } catch (OperationManagementDAOException e) {
throw new OperationManagementException("Error occurred while retrieving the list of " + throw new OperationManagementException("Error occurred while retrieving the list of " +
"operations assigned for '" + deviceId.getType() + "operations assigned for '" + deviceId.getType() +
"' device '" + deviceId.getId() + "'", e); "' device '" + deviceId.getId() + "'", e);
} catch (DeviceManagementDAOException e) { } catch (DeviceManagementDAOException e) {
throw new OperationManagementException("Error occurred while retrieving metadata of '" + throw new OperationManagementException("Error occurred while retrieving metadata of '" +
deviceId.getType() + "' device carrying the identifier '" + deviceId.getType() + "' device carrying the identifier '" +
deviceId.getId() + "'"); deviceId.getId() + "'");
} catch (SQLException e) { } catch (SQLException e) {
throw new OperationManagementException( throw new OperationManagementException(
"Error occurred while opening a connection to the data source", e); "Error occurred while opening a connection to the data source", e);
@ -251,7 +286,7 @@ public class OperationManagerImpl implements OperationManager {
} }
} catch (DeviceAccessAuthorizationException e) { } catch (DeviceAccessAuthorizationException e) {
throw new OperationManagementException("Error occurred while authorizing access to the devices for user : " + throw new OperationManagementException("Error occurred while authorizing access to the devices for user : " +
this.getUser(), e); this.getUser(), e);
} }
return paginationResult; return paginationResult;
@ -259,7 +294,7 @@ public class OperationManagerImpl implements OperationManager {
@Override @Override
public List<? extends Operation> getPendingOperations(DeviceIdentifier deviceId) throws public List<? extends Operation> getPendingOperations(DeviceIdentifier deviceId) throws
OperationManagementException { OperationManagementException {
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
log.debug("Device identifier id:[" + deviceId.getId() + "] type:[" + deviceId.getType() + "]"); log.debug("Device identifier id:[" + deviceId.getId() + "] type:[" + deviceId.getType() + "]");
} }
@ -281,8 +316,8 @@ public class OperationManagerImpl implements OperationManager {
OperationManagementDAOFactory.openConnection(); OperationManagementDAOFactory.openConnection();
if (enrolmentId < 0) { if (enrolmentId < 0) {
throw new OperationManagementException("Device not found for the given device Identifier:" + throw new OperationManagementException("Device not found for the given device Identifier:" +
deviceId.getId() + " and given type:" + deviceId.getId() + " and given type:" +
deviceId.getType()); deviceId.getType());
} }
dtoOperationList.addAll(commandOperationDAO.getOperationsByDeviceAndStatus( dtoOperationList.addAll(commandOperationDAO.getOperationsByDeviceAndStatus(
enrolmentId, org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Status.PENDING)); enrolmentId, org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Status.PENDING));
@ -300,12 +335,12 @@ public class OperationManagerImpl implements OperationManager {
Collections.sort(operations, new OperationCreateTimeComparator()); Collections.sort(operations, new OperationCreateTimeComparator());
} catch (OperationManagementDAOException e) { } catch (OperationManagementDAOException e) {
throw new OperationManagementException("Error occurred while retrieving the list of " + throw new OperationManagementException("Error occurred while retrieving the list of " +
"pending operations assigned for '" + deviceId.getType() + "pending operations assigned for '" + deviceId.getType() +
"' device '" + deviceId.getId() + "'", e); "' device '" + deviceId.getId() + "'", e);
} catch (DeviceManagementDAOException e) { } catch (DeviceManagementDAOException e) {
throw new OperationManagementException("Error occurred while retrieving the device " + throw new OperationManagementException("Error occurred while retrieving the device " +
"for device Identifier type -'" + deviceId.getType() + "for device Identifier type -'" + deviceId.getType() +
"' and device Id '" + deviceId.getId() + "'", e); "' and device Id '" + deviceId.getId() + "'", e);
} catch (SQLException e) { } catch (SQLException e) {
throw new OperationManagementException( throw new OperationManagementException(
"Error occurred while opening a connection to the data source", e); "Error occurred while opening a connection to the data source", e);
@ -314,11 +349,11 @@ public class OperationManagerImpl implements OperationManager {
} }
} else { } else {
log.info("User : " + getUser() + " is not authorized to fetch operations on device : " log.info("User : " + getUser() + " is not authorized to fetch operations on device : "
+ deviceId.getId()); + deviceId.getId());
} }
} catch (DeviceAccessAuthorizationException e) { } catch (DeviceAccessAuthorizationException e) {
throw new OperationManagementException("Error occurred while authorizing access to the devices for user :" + throw new OperationManagementException("Error occurred while authorizing access to the devices for user :" +
this.getUser(), e); this.getUser(), e);
} }
return operations; return operations;
} }
@ -345,27 +380,27 @@ public class OperationManagerImpl implements OperationManager {
OperationManagementDAOFactory.openConnection(); OperationManagementDAOFactory.openConnection();
if (enrolmentId < 0) { if (enrolmentId < 0) {
throw new OperationManagementException("Device not found for given device " + throw new OperationManagementException("Device not found for given device " +
"Identifier:" + deviceId.getId() + " and given type" + "Identifier:" + deviceId.getId() + " and given type" +
deviceId.getType()); deviceId.getType());
} }
org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation dtoOperation = operationDAO. org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation dtoOperation = operationDAO.
getNextOperation(enrolmentId); getNextOperation(enrolmentId);
if (dtoOperation != null) { if (dtoOperation != null) {
if (org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Type.COMMAND. if (org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Type.COMMAND.
equals(dtoOperation.getType())) { equals(dtoOperation.getType())) {
org.wso2.carbon.device.mgt.core.dto.operation.mgt.CommandOperation commandOperation; org.wso2.carbon.device.mgt.core.dto.operation.mgt.CommandOperation commandOperation;
commandOperation = commandOperation =
(org.wso2.carbon.device.mgt.core.dto.operation.mgt.CommandOperation) commandOperationDAO. (org.wso2.carbon.device.mgt.core.dto.operation.mgt.CommandOperation) commandOperationDAO.
getOperation(dtoOperation.getId()); getOperation(dtoOperation.getId());
dtoOperation.setEnabled(commandOperation.isEnabled()); dtoOperation.setEnabled(commandOperation.isEnabled());
} else if (org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Type.CONFIG. } else if (org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Type.CONFIG.
equals(dtoOperation.getType())) { equals(dtoOperation.getType())) {
dtoOperation = configOperationDAO.getOperation(dtoOperation.getId()); dtoOperation = configOperationDAO.getOperation(dtoOperation.getId());
} else if (org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Type.PROFILE. } else if (org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Type.PROFILE.
equals(dtoOperation.getType())) { equals(dtoOperation.getType())) {
dtoOperation = profileOperationDAO.getOperation(dtoOperation.getId()); dtoOperation = profileOperationDAO.getOperation(dtoOperation.getId());
} else if (org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Type.POLICY. } else if (org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Type.POLICY.
equals(dtoOperation.getType())) { equals(dtoOperation.getType())) {
dtoOperation = policyOperationDAO.getOperation(dtoOperation.getId()); dtoOperation = policyOperationDAO.getOperation(dtoOperation.getId());
} }
operation = OperationDAOUtil.convertOperation(dtoOperation); operation = OperationDAOUtil.convertOperation(dtoOperation);
@ -374,8 +409,8 @@ public class OperationManagerImpl implements OperationManager {
throw new OperationManagementException("Error occurred while retrieving next pending operation", e); throw new OperationManagementException("Error occurred while retrieving next pending operation", e);
} catch (DeviceManagementDAOException e) { } catch (DeviceManagementDAOException e) {
throw new OperationManagementException("Error occurred while retrieving the device " + throw new OperationManagementException("Error occurred while retrieving the device " +
"for device Identifier type -'" + deviceId.getType() + "for device Identifier type -'" + deviceId.getType() +
"' and device Id '" + deviceId.getId(), e); "' and device Id '" + deviceId.getId(), e);
} catch (SQLException e) { } catch (SQLException e) {
throw new OperationManagementException( throw new OperationManagementException(
"Error occurred while opening a connection to the data source", e); "Error occurred while opening a connection to the data source", e);
@ -384,11 +419,11 @@ public class OperationManagerImpl implements OperationManager {
} }
} else { } else {
log.info("User : " + getUser() + " is not authorized to fetch operations on device : " log.info("User : " + getUser() + " is not authorized to fetch operations on device : "
+ deviceId.getId()); + deviceId.getId());
} }
} catch (DeviceAccessAuthorizationException e) { } catch (DeviceAccessAuthorizationException e) {
throw new OperationManagementException("Error occurred while authorizing access to the devices for user : " + throw new OperationManagementException("Error occurred while authorizing access to the devices for user : " +
this.getUser(), e); this.getUser(), e);
} }
return operation; return operation;
} }
@ -411,15 +446,15 @@ public class OperationManagerImpl implements OperationManager {
enrolmentId = deviceDAO.getEnrolmentByStatus(deviceId, EnrolmentInfo.Status.ACTIVE, tenantId); enrolmentId = deviceDAO.getEnrolmentByStatus(deviceId, EnrolmentInfo.Status.ACTIVE, tenantId);
} catch (SQLException e) { } catch (SQLException e) {
throw new OperationManagementException("Error occurred while opening a connection to the" + throw new OperationManagementException("Error occurred while opening a connection to the" +
" data source", e); " data source", e);
} finally { } finally {
DeviceManagementDAOFactory.closeConnection(); DeviceManagementDAOFactory.closeConnection();
} }
OperationManagementDAOFactory.beginTransaction(); OperationManagementDAOFactory.beginTransaction();
if (operation.getStatus() != null) { if (operation.getStatus() != null) {
operationDAO.updateOperationStatus(enrolmentId, operationId, operationDAO.updateOperationStatus(enrolmentId, operationId,
org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Status. org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Status.
valueOf(operation.getStatus().toString())); valueOf(operation.getStatus().toString()));
} }
if (operation.getOperationResponse() != null) { if (operation.getOperationResponse() != null) {
operationDAO.addOperationResponse(enrolmentId, operationId, operation.getOperationResponse()); operationDAO.addOperationResponse(enrolmentId, operationId, operation.getOperationResponse());
@ -429,12 +464,12 @@ public class OperationManagerImpl implements OperationManager {
OperationManagementDAOFactory.rollbackTransaction(); OperationManagementDAOFactory.rollbackTransaction();
throw new OperationManagementException( throw new OperationManagementException(
"Error occurred while updating the operation: " + operationId + " status:" + "Error occurred while updating the operation: " + operationId + " status:" +
operation.getStatus(), e); operation.getStatus(), e);
} catch (DeviceManagementDAOException e) { } catch (DeviceManagementDAOException e) {
OperationManagementDAOFactory.rollbackTransaction(); OperationManagementDAOFactory.rollbackTransaction();
throw new OperationManagementException( throw new OperationManagementException(
"Error occurred while fetching the device for device identifier: " + deviceId.getId() + "Error occurred while fetching the device for device identifier: " + deviceId.getId() +
"type:" + deviceId.getType(), e); "type:" + deviceId.getType(), e);
} catch (TransactionManagementException e) { } catch (TransactionManagementException e) {
throw new OperationManagementException("Error occurred while initiating a transaction", e); throw new OperationManagementException("Error occurred while initiating a transaction", e);
} finally { } finally {
@ -442,11 +477,11 @@ public class OperationManagerImpl implements OperationManager {
} }
} else { } else {
log.info("User : " + getUser() + " is not authorized to update operations on device : " log.info("User : " + getUser() + " is not authorized to update operations on device : "
+ deviceId.getId()); + deviceId.getId());
} }
} catch (DeviceAccessAuthorizationException e) { } catch (DeviceAccessAuthorizationException e) {
throw new OperationManagementException("Error occurred while authorizing access to the devices for user :" + throw new OperationManagementException("Error occurred while authorizing access to the devices for user :" +
this.getUser(), e); this.getUser(), e);
} }
} }
@ -478,7 +513,7 @@ public class OperationManagerImpl implements OperationManager {
Operation operation = null; Operation operation = null;
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
log.debug("Operation Id: " + operationId + " Device Type: " + deviceId.getType() + " Device Identifier: " + log.debug("Operation Id: " + operationId + " Device Type: " + deviceId.getType() + " Device Identifier: " +
deviceId.getId()); deviceId.getId());
} }
try { try {
boolean isUserAuthorized = DeviceManagementDataHolder.getInstance().getDeviceAccessAuthorizationService(). boolean isUserAuthorized = DeviceManagementDataHolder.getInstance().getDeviceAccessAuthorizationService().
@ -496,16 +531,16 @@ public class OperationManagerImpl implements OperationManager {
OperationManagementDAOFactory.openConnection(); OperationManagementDAOFactory.openConnection();
if (enrolmentId < 0) { if (enrolmentId < 0) {
throw new OperationManagementException("Device not found for given device identifier: " + throw new OperationManagementException("Device not found for given device identifier: " +
deviceId.getId() + " type: " + deviceId.getType()); deviceId.getId() + " type: " + deviceId.getType());
} }
org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation dtoOperation = operationDAO. org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation dtoOperation = operationDAO.
getOperationByDeviceAndId(enrolmentId, operationId); getOperationByDeviceAndId(enrolmentId, operationId);
if (dtoOperation.getType(). if (dtoOperation.getType().
equals(org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Type.COMMAND)) { equals(org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Type.COMMAND)) {
org.wso2.carbon.device.mgt.core.dto.operation.mgt.CommandOperation commandOperation; org.wso2.carbon.device.mgt.core.dto.operation.mgt.CommandOperation commandOperation;
commandOperation = commandOperation =
(org.wso2.carbon.device.mgt.core.dto.operation.mgt.CommandOperation) commandOperationDAO. (org.wso2.carbon.device.mgt.core.dto.operation.mgt.CommandOperation) commandOperationDAO.
getOperation(dtoOperation.getId()); getOperation(dtoOperation.getId());
dtoOperation.setEnabled(commandOperation.isEnabled()); dtoOperation.setEnabled(commandOperation.isEnabled());
} else if (dtoOperation.getType(). } else if (dtoOperation.getType().
equals(org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Type.CONFIG)) { equals(org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Type.CONFIG)) {
@ -520,30 +555,30 @@ public class OperationManagerImpl implements OperationManager {
if (dtoOperation == null) { if (dtoOperation == null) {
throw new OperationManagementException("Operation not found for operation Id:" + operationId + throw new OperationManagementException("Operation not found for operation Id:" + operationId +
" device id:" + deviceId.getId()); " device id:" + deviceId.getId());
} }
operation = OperationDAOUtil.convertOperation(dtoOperation); operation = OperationDAOUtil.convertOperation(dtoOperation);
} catch (OperationManagementDAOException e) { } catch (OperationManagementDAOException e) {
throw new OperationManagementException("Error occurred while retrieving the list of " + throw new OperationManagementException("Error occurred while retrieving the list of " +
"operations assigned for '" + deviceId.getType() + "operations assigned for '" + deviceId.getType() +
"' device '" + deviceId.getId() + "'", e); "' device '" + deviceId.getId() + "'", e);
} catch (DeviceManagementDAOException e) { } catch (DeviceManagementDAOException e) {
throw new OperationManagementException("Error occurred while retrieving the device " + throw new OperationManagementException("Error occurred while retrieving the device " +
"for device Identifier type -'" + deviceId.getType() + "for device Identifier type -'" + deviceId.getType() +
"' and device Id '" + deviceId.getId() + "'", e); "' and device Id '" + deviceId.getId() + "'", e);
} catch (SQLException e) { } catch (SQLException e) {
throw new OperationManagementException("Error occurred while opening connection to the data source", throw new OperationManagementException("Error occurred while opening connection to the data source",
e); e);
} finally { } finally {
OperationManagementDAOFactory.closeConnection(); OperationManagementDAOFactory.closeConnection();
} }
} else { } else {
log.info("User : " + getUser() + " is not authorized to fetch operations on device : " log.info("User : " + getUser() + " is not authorized to fetch operations on device : "
+ deviceId.getId()); + deviceId.getId());
} }
} catch (DeviceAccessAuthorizationException e) { } catch (DeviceAccessAuthorizationException e) {
throw new OperationManagementException("Error occurred while authorizing access to the devices for user :" + throw new OperationManagementException("Error occurred while authorizing access to the devices for user :" +
this.getUser(), e); this.getUser(), e);
} }
return operation; return operation;
} }
@ -571,18 +606,18 @@ public class OperationManagerImpl implements OperationManager {
if (enrolmentId < 0) { if (enrolmentId < 0) {
throw new OperationManagementException( throw new OperationManagementException(
"Device not found for device id:" + deviceId.getId() + " " + "type:" + "Device not found for device id:" + deviceId.getId() + " " + "type:" +
deviceId.getType()); deviceId.getType());
} }
org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Status dtoOpStatus = org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Status dtoOpStatus =
org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Status.valueOf(status.toString()); org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Status.valueOf(status.toString());
dtoOperationList.addAll(commandOperationDAO.getOperationsByDeviceAndStatus(enrolmentId, dtoOpStatus)); dtoOperationList.addAll(commandOperationDAO.getOperationsByDeviceAndStatus(enrolmentId, dtoOpStatus));
dtoOperationList.addAll(configOperationDAO.getOperationsByDeviceAndStatus(enrolmentId, dtoOperationList.addAll(configOperationDAO.getOperationsByDeviceAndStatus(enrolmentId,
org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Status.PENDING)); org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Status.PENDING));
dtoOperationList.addAll(profileOperationDAO.getOperationsByDeviceAndStatus(enrolmentId, dtoOperationList.addAll(profileOperationDAO.getOperationsByDeviceAndStatus(enrolmentId,
org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Status.PENDING)); org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Status.PENDING));
dtoOperationList.addAll(policyOperationDAO.getOperationsByDeviceAndStatus(enrolmentId, dtoOperationList.addAll(policyOperationDAO.getOperationsByDeviceAndStatus(enrolmentId,
org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Status.PENDING)); org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Status.PENDING));
Operation operation; Operation operation;
@ -593,13 +628,13 @@ public class OperationManagerImpl implements OperationManager {
} catch (OperationManagementDAOException e) { } catch (OperationManagementDAOException e) {
throw new OperationManagementException("Error occurred while retrieving the list of " + throw new OperationManagementException("Error occurred while retrieving the list of " +
"operations assigned for '" + deviceId.getType() + "operations assigned for '" + deviceId.getType() +
"' device '" + "' device '" +
deviceId.getId() + "' and status:" + status.toString(), e); deviceId.getId() + "' and status:" + status.toString(), e);
} catch (DeviceManagementDAOException e) { } catch (DeviceManagementDAOException e) {
throw new OperationManagementException("Error occurred while retrieving the device " + throw new OperationManagementException("Error occurred while retrieving the device " +
"for device Identifier type -'" + deviceId.getType() + "for device Identifier type -'" + deviceId.getType() +
"' and device Id '" + deviceId.getId(), e); "' and device Id '" + deviceId.getId(), e);
} catch (SQLException e) { } catch (SQLException e) {
throw new OperationManagementException( throw new OperationManagementException(
"Error occurred while opening a connection to the data source", e); "Error occurred while opening a connection to the data source", e);
@ -608,11 +643,11 @@ public class OperationManagerImpl implements OperationManager {
} }
} else { } else {
log.info("User : " + getUser() + " is not authorized to fetch operations on device : " log.info("User : " + getUser() + " is not authorized to fetch operations on device : "
+ deviceId.getId()); + deviceId.getId());
} }
} catch (DeviceAccessAuthorizationException e) { } catch (DeviceAccessAuthorizationException e) {
throw new OperationManagementException("Error occurred while authorizing access to the devices for user :" + throw new OperationManagementException("Error occurred while authorizing access to the devices for user :" +
this.getUser(), e); this.getUser(), e);
} }
return operations; return operations;
} }
@ -623,7 +658,7 @@ public class OperationManagerImpl implements OperationManager {
try { try {
OperationManagementDAOFactory.openConnection(); OperationManagementDAOFactory.openConnection();
org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation dtoOperation = operationDAO. org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation dtoOperation = operationDAO.
getOperation(operationId); getOperation(operationId);
if (dtoOperation == null) { if (dtoOperation == null) {
throw new OperationManagementException("Operation not found for given Id:" + operationId); throw new OperationManagementException("Operation not found for given Id:" + operationId);
} }
@ -632,22 +667,22 @@ public class OperationManagerImpl implements OperationManager {
org.wso2.carbon.device.mgt.core.dto.operation.mgt.CommandOperation commandOperation; org.wso2.carbon.device.mgt.core.dto.operation.mgt.CommandOperation commandOperation;
commandOperation = commandOperation =
(org.wso2.carbon.device.mgt.core.dto.operation.mgt.CommandOperation) commandOperationDAO. (org.wso2.carbon.device.mgt.core.dto.operation.mgt.CommandOperation) commandOperationDAO.
getOperation(dtoOperation.getId()); getOperation(dtoOperation.getId());
dtoOperation.setEnabled(commandOperation.isEnabled()); dtoOperation.setEnabled(commandOperation.isEnabled());
} else if (dtoOperation.getType(). } else if (dtoOperation.getType().
equals(org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Type.CONFIG)) { equals(org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Type.CONFIG)) {
dtoOperation = configOperationDAO.getOperation(dtoOperation.getId()); dtoOperation = configOperationDAO.getOperation(dtoOperation.getId());
} else if (dtoOperation.getType().equals(org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Type. } else if (dtoOperation.getType().equals(org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Type.
PROFILE)) { PROFILE)) {
dtoOperation = profileOperationDAO.getOperation(dtoOperation.getId()); dtoOperation = profileOperationDAO.getOperation(dtoOperation.getId());
} else if (dtoOperation.getType().equals(org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Type. } else if (dtoOperation.getType().equals(org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Type.
POLICY)) { POLICY)) {
dtoOperation = policyOperationDAO.getOperation(dtoOperation.getId()); dtoOperation = policyOperationDAO.getOperation(dtoOperation.getId());
} }
operation = OperationDAOUtil.convertOperation(dtoOperation); operation = OperationDAOUtil.convertOperation(dtoOperation);
} catch (OperationManagementDAOException e) { } catch (OperationManagementDAOException e) {
throw new OperationManagementException("Error occurred while retrieving the operation with operation Id '" + throw new OperationManagementException("Error occurred while retrieving the operation with operation Id '" +
operationId, e); operationId, e);
} catch (SQLException e) { } catch (SQLException e) {
throw new OperationManagementException("Error occurred while opening a connection to the data source", e); throw new OperationManagementException("Error occurred while opening a connection to the data source", e);
} finally { } finally {
@ -662,7 +697,7 @@ public class OperationManagerImpl implements OperationManager {
Operation operation; Operation operation;
int enrollmentOpMappingId = Integer.parseInt( int enrollmentOpMappingId = Integer.parseInt(
activity.replace(DeviceManagementConstants.OperationAttributes.ACTIVITY, "")); activity.replace(DeviceManagementConstants.OperationAttributes.ACTIVITY, ""));
if(enrollmentOpMappingId == 0){ if (enrollmentOpMappingId == 0) {
throw new IllegalArgumentException("Operation ID cannot be null or zero (0)."); throw new IllegalArgumentException("Operation ID cannot be null or zero (0).");
} }
try { try {
@ -692,7 +727,7 @@ public class OperationManagerImpl implements OperationManager {
} }
operation = OperationDAOUtil.convertOperation(dtoOperation); operation = OperationDAOUtil.convertOperation(dtoOperation);
int enrolmentId = operationDAO.getEnrolmentIdFromMappingId(enrollmentOpMappingId); int enrolmentId = operationDAO.getEnrolmentIdFromMappingId(enrollmentOpMappingId);
if (enrolmentId !=0) { if (enrolmentId != 0) {
operation.setResponses(operationDAO.getOperationResponses(enrolmentId, operation.getId())); operation.setResponses(operationDAO.getOperationResponses(enrolmentId, operation.getId()));
} }
@ -754,10 +789,10 @@ public class OperationManagerImpl implements OperationManager {
boolean status; boolean status;
switch (operation.getCode()) { switch (operation.getCode()) {
case DeviceManagementConstants.AuthorizationSkippedOperationCodes.POLICY_OPERATION_CODE : case DeviceManagementConstants.AuthorizationSkippedOperationCodes.POLICY_OPERATION_CODE:
status = true; status = true;
break; break;
case DeviceManagementConstants.AuthorizationSkippedOperationCodes.MONITOR_OPERATION_CODE : case DeviceManagementConstants.AuthorizationSkippedOperationCodes.MONITOR_OPERATION_CODE:
status = true; status = true;
break; break;
default: default:

@ -0,0 +1,46 @@
/*
* 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.operation.mgt;
import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManager;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
public class OperationManagerRepository {
private Map<String, OperationManager> operationManagers;
public OperationManagerRepository() {
operationManagers = new ConcurrentHashMap<>();
}
public void addOperationManager(String type, OperationManager operationManager) {
operationManagers.put(type, operationManager);
}
public OperationManager getOperationManager(String type) {
return operationManagers.get(type);
}
public void removeOperationManager(String type) {
operationManagers.remove(type);
}
}

@ -0,0 +1,120 @@
/*
* 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.push.notification.mgt;
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
import org.wso2.carbon.device.mgt.common.DeviceManagementException;
import org.wso2.carbon.device.mgt.common.PaginationRequest;
import org.wso2.carbon.device.mgt.common.PaginationResult;
import org.wso2.carbon.device.mgt.common.operation.mgt.Operation;
import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManagementException;
import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManager;
import org.wso2.carbon.device.mgt.common.push.notification.NotificationContext;
import org.wso2.carbon.device.mgt.common.push.notification.NotificationStrategy;
import org.wso2.carbon.device.mgt.common.push.notification.PushNotificationExecutionFailedException;
import java.util.List;
public class PushNotificationBasedOperationManager implements OperationManager {
private OperationManager operationManager;
private NotificationStrategy notificationProvider;
public PushNotificationBasedOperationManager(
OperationManager operationManager, NotificationStrategy notificationProvider) {
this.operationManager = operationManager;
this.notificationProvider = notificationProvider;
}
@Override
public int addOperation(Operation operation,
List<DeviceIdentifier> devices) throws OperationManagementException {
int operationId = this.operationManager.addOperation(operation, devices);
for (DeviceIdentifier deviceId : devices) {
try {
this.notificationProvider.execute(new NotificationContext(deviceId));
} catch (PushNotificationExecutionFailedException e) {
throw new OperationManagementException("Error occurred while sending push notification to device", e);
}
}
return operationId;
}
@Override
public List<? extends Operation> getOperations(DeviceIdentifier deviceId) throws OperationManagementException {
return this.operationManager.getOperations(deviceId);
}
@Override
public PaginationResult getOperations(DeviceIdentifier deviceId,
PaginationRequest request) throws OperationManagementException {
return this.operationManager.getOperations(deviceId, request);
}
@Override
public List<? extends Operation> getPendingOperations(
DeviceIdentifier deviceId) throws OperationManagementException {
return this.operationManager.getPendingOperations(deviceId);
}
@Override
public Operation getNextPendingOperation(DeviceIdentifier deviceId) throws OperationManagementException {
return this.operationManager.getNextPendingOperation(deviceId);
}
@Override
public void updateOperation(DeviceIdentifier deviceId,
Operation operation) throws OperationManagementException {
this.operationManager.updateOperation(deviceId, operation);
}
@Override
public void deleteOperation(int operationId) throws OperationManagementException {
this.operationManager.deleteOperation(operationId);
}
@Override
public Operation getOperationByDeviceAndOperationId(
DeviceIdentifier deviceId, int operationId) throws OperationManagementException {
return this.operationManager.getOperationByDeviceAndOperationId(deviceId, operationId);
}
@Override
public List<? extends Operation> getOperationsByDeviceAndStatus(
DeviceIdentifier deviceId,
Operation.Status status) throws OperationManagementException {
try {
return this.operationManager.getOperationsByDeviceAndStatus(deviceId, status);
} catch (DeviceManagementException e) {
throw new OperationManagementException("Error occurred while retrieving the list of operations by " +
"device and status", e);
}
}
@Override
public Operation getOperation(int operationId) throws OperationManagementException {
return this.operationManager.getOperation(operationId);
}
@Override
public Operation getOperationByActivityId(String activity) throws OperationManagementException {
return this.operationManager.getOperationByActivityId(activity);
}
}

@ -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.push.notification.mgt;
import org.wso2.carbon.context.CarbonContext;
import org.wso2.carbon.device.mgt.common.push.notification.PushNotificationConfig;
import java.util.HashMap;
import java.util.Map;
public class PushNotificationConfigRepository {
private Map<Integer, PushNotificationConfig> configs;
public PushNotificationConfigRepository() {
configs = new HashMap<>();
}
public void addConfig(PushNotificationConfig config) {
configs.put(CarbonContext.getThreadLocalCarbonContext().getTenantId(), config);
}
public PushNotificationConfig getConfig() {
return configs.get(CarbonContext.getThreadLocalCarbonContext().getTenantId());
}
}

@ -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.push.notification.mgt;
import org.wso2.carbon.device.mgt.common.push.notification.NotificationStrategy;
import org.wso2.carbon.device.mgt.common.spi.DeviceManagementService;
public class PushNotificationEnabledDeviceManagementService {
public PushNotificationEnabledDeviceManagementService(
DeviceManagementService provider, NotificationStrategy strategy) {
}
}

@ -0,0 +1,36 @@
/*
* 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.push.notification.mgt;
import org.wso2.carbon.device.mgt.common.push.notification.PushNotificationProvider;
import org.wso2.carbon.device.mgt.core.internal.DeviceManagementDataHolder;
public class PushNotificationProviderFactory {
public static PushNotificationProvider getPushNotificationFactory(String type) {
PushNotificationProvider provider =
DeviceManagementDataHolder.getInstance().getPushNotificationProviderRepository().getProvider(type);
if (provider == null) {
throw new UnsupportedPushNotificationProviderException("Push notification type '" + type +
"' is not supported");
}
return provider;
}
}

@ -0,0 +1,60 @@
/*
* 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.push.notification.mgt;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.device.mgt.common.push.notification.PushNotificationProvider;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
public class PushNotificationProviderRepository {
private Map<String, PushNotificationProvider> providers;
private static final Log log = LogFactory.getLog(PushNotificationProviderRepository.class);
public PushNotificationProviderRepository() {
this.providers = new ConcurrentHashMap<>();
}
public void addProvider(PushNotificationProvider provider) {
providers.put(provider.getType(), provider);
}
public void addProvider(String className) {
try {
Class<?> clz = Class.forName(className);
PushNotificationProvider provider = (PushNotificationProvider) clz.newInstance();
providers.put(provider.getType(), provider);
} catch (ClassNotFoundException e) {
log.error("Provided push notification provider implementation '" + className + "' cannot be found", e);
} catch (InstantiationException e) {
log.error("Error occurred while instantiating push notification provider implementation '" +
className + "'", e);
} catch (IllegalAccessException e) {
log.error("Error occurred while adding push notification provider implementation '" + className + "'", e);
}
}
public PushNotificationProvider getProvider(String type) {
return providers.get(type);
}
}

@ -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.push.notification.mgt;
public class UnsupportedPushNotificationProviderException extends RuntimeException {
private static final long serialVersionUID = -3151279321923070297L;
public UnsupportedPushNotificationProviderException(String msg, Exception nestedEx) {
super(msg, nestedEx);
}
public UnsupportedPushNotificationProviderException(String message, Throwable cause) {
super(message, cause);
}
public UnsupportedPushNotificationProviderException(String msg) {
super(msg);
}
public UnsupportedPushNotificationProviderException() {
super();
}
public UnsupportedPushNotificationProviderException(Throwable cause) {
super(cause);
}
}

@ -27,6 +27,7 @@ import org.wso2.carbon.device.mgt.common.PaginationResult;
import org.wso2.carbon.device.mgt.common.configuration.mgt.TenantConfiguration; import org.wso2.carbon.device.mgt.common.configuration.mgt.TenantConfiguration;
import org.wso2.carbon.device.mgt.common.license.mgt.License; import org.wso2.carbon.device.mgt.common.license.mgt.License;
import org.wso2.carbon.device.mgt.common.operation.mgt.Operation; import org.wso2.carbon.device.mgt.common.operation.mgt.Operation;
import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManagementException;
import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManager; import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManager;
import org.wso2.carbon.device.mgt.core.dto.DeviceType; import org.wso2.carbon.device.mgt.core.dto.DeviceType;
@ -36,7 +37,7 @@ import java.util.List;
* Proxy class for all Device Management related operations that take the corresponding plugin type in * Proxy class for all Device Management related operations that take the corresponding plugin type in
* and resolve the appropriate plugin implementation * and resolve the appropriate plugin implementation
*/ */
public interface DeviceManagementProviderService extends OperationManager { public interface DeviceManagementProviderService {
List<Device> getAllDevices(String deviceType) throws DeviceManagementException; List<Device> getAllDevices(String deviceType) throws DeviceManagementException;
@ -212,6 +213,35 @@ public interface DeviceManagementProviderService extends OperationManager {
boolean setStatus(DeviceIdentifier deviceId, String currentOwner, boolean setStatus(DeviceIdentifier deviceId, String currentOwner,
EnrolmentInfo.Status status) throws DeviceManagementException; EnrolmentInfo.Status status) throws DeviceManagementException;
void notifyOperationToDevices(Operation operation, List<DeviceIdentifier> deviceIds) throws DeviceManagementException; void notifyOperationToDevices(Operation operation,
List<DeviceIdentifier> deviceIds) throws DeviceManagementException;
int addOperation(String type, Operation operation,
List<DeviceIdentifier> devices) throws OperationManagementException;
List<? extends Operation> getOperations(DeviceIdentifier deviceId) throws OperationManagementException;
PaginationResult getOperations(DeviceIdentifier deviceId,
PaginationRequest request) throws OperationManagementException;
List<? extends Operation> getPendingOperations(
DeviceIdentifier deviceId) throws OperationManagementException;
Operation getNextPendingOperation(DeviceIdentifier deviceId) throws OperationManagementException;
void updateOperation(DeviceIdentifier deviceId, Operation operation) throws OperationManagementException;
void deleteOperation(String type, int operationId) throws OperationManagementException;
Operation getOperationByDeviceAndOperationId(DeviceIdentifier deviceId, int operationId)
throws OperationManagementException;
List<? extends Operation> getOperationsByDeviceAndStatus(DeviceIdentifier identifier,
Operation.Status status)
throws OperationManagementException, DeviceManagementException;
Operation getOperation(String type, int operationId) throws OperationManagementException;
Operation getOperationByActivityId(String activity) throws OperationManagementException;
} }

@ -35,6 +35,8 @@ import org.wso2.carbon.device.mgt.common.license.mgt.License;
import org.wso2.carbon.device.mgt.common.license.mgt.LicenseManagementException; import org.wso2.carbon.device.mgt.common.license.mgt.LicenseManagementException;
import org.wso2.carbon.device.mgt.common.operation.mgt.Operation; import org.wso2.carbon.device.mgt.common.operation.mgt.Operation;
import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManagementException; import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManagementException;
import org.wso2.carbon.device.mgt.common.push.notification.NotificationStrategy;
import org.wso2.carbon.device.mgt.common.push.notification.PushNotificationConfig;
import org.wso2.carbon.device.mgt.common.spi.DeviceManagementService; import org.wso2.carbon.device.mgt.common.spi.DeviceManagementService;
import org.wso2.carbon.device.mgt.core.DeviceManagementPluginRepository; import org.wso2.carbon.device.mgt.core.DeviceManagementPluginRepository;
import org.wso2.carbon.device.mgt.core.dao.DeviceDAO; import org.wso2.carbon.device.mgt.core.dao.DeviceDAO;
@ -46,6 +48,8 @@ import org.wso2.carbon.device.mgt.core.dto.DeviceType;
import org.wso2.carbon.device.mgt.core.internal.DeviceManagementDataHolder; import org.wso2.carbon.device.mgt.core.internal.DeviceManagementDataHolder;
import org.wso2.carbon.device.mgt.core.internal.DeviceManagementServiceComponent; import org.wso2.carbon.device.mgt.core.internal.DeviceManagementServiceComponent;
import org.wso2.carbon.device.mgt.core.internal.PluginInitializationListener; import org.wso2.carbon.device.mgt.core.internal.PluginInitializationListener;
import org.wso2.carbon.device.mgt.core.operation.mgt.OperationManagerImpl;
import org.wso2.carbon.device.mgt.core.operation.mgt.OperationManagerRepository;
import org.wso2.carbon.device.mgt.core.util.DeviceManagerUtil; import org.wso2.carbon.device.mgt.core.util.DeviceManagerUtil;
import org.wso2.carbon.email.sender.core.ContentProviderInfo; import org.wso2.carbon.email.sender.core.ContentProviderInfo;
import org.wso2.carbon.email.sender.core.EmailContext; import org.wso2.carbon.email.sender.core.EmailContext;
@ -70,9 +74,11 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
private DeviceTypeDAO deviceTypeDAO; private DeviceTypeDAO deviceTypeDAO;
private EnrollmentDAO enrollmentDAO; private EnrollmentDAO enrollmentDAO;
private DeviceManagementPluginRepository pluginRepository; private DeviceManagementPluginRepository pluginRepository;
private OperationManagerRepository operationManagerRepository;
public DeviceManagementProviderServiceImpl() { public DeviceManagementProviderServiceImpl() {
this.pluginRepository = new DeviceManagementPluginRepository(); this.pluginRepository = new DeviceManagementPluginRepository();
this.operationManagerRepository = new OperationManagerRepository();
initDataAccessObjects(); initDataAccessObjects();
/* Registering a listener to retrieve events when some device management service plugin is installed after /* Registering a listener to retrieve events when some device management service plugin is installed after
* the component is done getting initialized */ * the component is done getting initialized */
@ -88,7 +94,8 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
@Override @Override
public boolean saveConfiguration(TenantConfiguration configuration) throws DeviceManagementException { public boolean saveConfiguration(TenantConfiguration configuration) throws DeviceManagementException {
DeviceManager dms = DeviceManager dms =
this.getPluginRepository().getDeviceManagementService(configuration.getType(), this.getTenantId()).getDeviceManager(); pluginRepository.getDeviceManagementService(configuration.getType(),
this.getTenantId()).getDeviceManager();
return dms.saveConfiguration(configuration); return dms.saveConfiguration(configuration);
} }
@ -100,7 +107,7 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
@Override @Override
public TenantConfiguration getConfiguration(String deviceType) throws DeviceManagementException { public TenantConfiguration getConfiguration(String deviceType) throws DeviceManagementException {
DeviceManager dms = DeviceManager dms =
this.getPluginRepository().getDeviceManagementService(deviceType, this.getTenantId()).getDeviceManager(); pluginRepository.getDeviceManagementService(deviceType, this.getTenantId()).getDeviceManager();
if (dms == null) { if (dms == null) {
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
log.debug("Device type '" + deviceType + "' does not have an associated device management " + log.debug("Device type '" + deviceType + "' does not have an associated device management " +
@ -154,7 +161,7 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
if (existingEnrolmentInfo != null && newEnrolmentInfo != null) { if (existingEnrolmentInfo != null && newEnrolmentInfo != null) {
//Get all the enrollments of current user for the same device //Get all the enrollments of current user for the same device
List<EnrolmentInfo> enrolmentInfos = this.getEnrollmentsOfUser(existingDevice.getId(), List<EnrolmentInfo> enrolmentInfos = this.getEnrollmentsOfUser(existingDevice.getId(),
newEnrolmentInfo.getOwner()); newEnrolmentInfo.getOwner());
for (EnrolmentInfo enrolmentInfo : enrolmentInfos) { for (EnrolmentInfo enrolmentInfo : enrolmentInfos) {
//If the enrollments are same then we'll update the existing enrollment. //If the enrollments are same then we'll update the existing enrollment.
if (enrolmentInfo.equals(newEnrolmentInfo)) { if (enrolmentInfo.equals(newEnrolmentInfo)) {
@ -182,15 +189,15 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
DeviceManagementDAOFactory.commitTransaction(); DeviceManagementDAOFactory.commitTransaction();
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
log.debug("An enrolment is successfully added with the id '" + enrolmentId + log.debug("An enrolment is successfully added with the id '" + enrolmentId +
"' associated with " + "the device identified by key '" + "' associated with " + "the device identified by key '" +
device.getDeviceIdentifier() + "', which belongs to " + "platform '" + device.getDeviceIdentifier() + "', which belongs to " + "platform '" +
device.getType() + " upon the user '" + device.getEnrolmentInfo().getOwner() + device.getType() + " upon the user '" + device.getEnrolmentInfo().getOwner() +
"'"); "'");
} }
status = true; status = true;
} else { } else {
log.warn("Unable to update device enrollment for device : " + device.getDeviceIdentifier() + log.warn("Unable to update device enrollment for device : " + device.getDeviceIdentifier() +
" belonging to user : " + device.getEnrolmentInfo().getOwner()); " belonging to user : " + device.getEnrolmentInfo().getOwner());
} }
} catch (DeviceManagementDAOException e) { } catch (DeviceManagementDAOException e) {
DeviceManagementDAOFactory.rollbackTransaction(); DeviceManagementDAOFactory.rollbackTransaction();
@ -277,7 +284,7 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
enrolmentInfos = enrollmentDAO.getEnrollmentsOfUser(deviceId, user, this.getTenantId()); enrolmentInfos = enrollmentDAO.getEnrollmentsOfUser(deviceId, user, this.getTenantId());
} catch (DeviceManagementDAOException e) { } catch (DeviceManagementDAOException e) {
throw new DeviceManagementException("Error occurred while obtaining the enrollment information device for" + throw new DeviceManagementException("Error occurred while obtaining the enrollment information device for" +
"id '" + deviceId + "' and user : " + user, e); "id '" + deviceId + "' and user : " + user, e);
} catch (SQLException e) { } catch (SQLException e) {
throw new DeviceManagementException("Error occurred while opening a connection to the data source", e); throw new DeviceManagementException("Error occurred while opening a connection to the data source", e);
} finally { } finally {
@ -424,7 +431,7 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
count = deviceDAO.getDeviceCountByType(deviceType, tenantId); count = deviceDAO.getDeviceCountByType(deviceType, tenantId);
} catch (DeviceManagementDAOException e) { } catch (DeviceManagementDAOException e) {
throw new DeviceManagementException("Error occurred while retrieving device list pertaining to " + throw new DeviceManagementException("Error occurred while retrieving device list pertaining to " +
"the current tenant of type " + deviceType, e); "the current tenant of type " + deviceType, e);
} catch (SQLException e) { } catch (SQLException e) {
throw new DeviceManagementException("Error occurred while opening a connection to the data source", e); throw new DeviceManagementException("Error occurred while opening a connection to the data source", e);
} finally { } finally {
@ -435,7 +442,7 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
if (deviceManager == null) { if (deviceManager == null) {
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
log.debug("Device Manager associated with the device type '" + device.getType() + "' is null. " + log.debug("Device Manager associated with the device type '" + device.getType() + "' is null. " +
"Therefore, not attempting method 'isEnrolled'"); "Therefore, not attempting method 'isEnrolled'");
} }
devices.add(device); devices.add(device);
continue; continue;
@ -467,7 +474,7 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
count = deviceDAO.getDeviceCount(request, tenantId); count = deviceDAO.getDeviceCount(request, tenantId);
} catch (DeviceManagementDAOException e) { } catch (DeviceManagementDAOException e) {
throw new DeviceManagementException("Error occurred while retrieving device list pertaining to " + throw new DeviceManagementException("Error occurred while retrieving device list pertaining to " +
"the current tenant", e); "the current tenant", e);
} catch (SQLException e) { } catch (SQLException e) {
throw new DeviceManagementException("Error occurred while opening a connection to the data source", e); throw new DeviceManagementException("Error occurred while opening a connection to the data source", e);
} finally { } finally {
@ -478,7 +485,7 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
if (deviceManager == null) { if (deviceManager == null) {
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
log.debug("Device Manager associated with the device type '" + device.getType() + "' is null. " + log.debug("Device Manager associated with the device type '" + device.getType() + "' is null. " +
"Therefore, not attempting method 'isEnrolled'"); "Therefore, not attempting method 'isEnrolled'");
} }
devices.add(device); devices.add(device);
continue; continue;
@ -546,7 +553,7 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
try { try {
EmailContext ctx = EmailContext ctx =
new EmailContext.EmailContextBuilder(new ContentProviderInfo("user-enrollment", params), new EmailContext.EmailContextBuilder(new ContentProviderInfo("user-enrollment", params),
metaInfo.getRecipients()).build(); metaInfo.getRecipients()).build();
DeviceManagementDataHolder.getInstance().getEmailSenderService().sendEmail(ctx); DeviceManagementDataHolder.getInstance().getEmailSenderService().sendEmail(ctx);
} catch (EmailSendingFailedException e) { } catch (EmailSendingFailedException e) {
throw new DeviceManagementException("Error occurred while sending enrollment invitation", e); throw new DeviceManagementException("Error occurred while sending enrollment invitation", e);
@ -571,7 +578,7 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
try { try {
EmailContext ctx = EmailContext ctx =
new EmailContext.EmailContextBuilder(new ContentProviderInfo("user-registration", params), new EmailContext.EmailContextBuilder(new ContentProviderInfo("user-registration", params),
metaInfo.getRecipients()).build(); metaInfo.getRecipients()).build();
DeviceManagementDataHolder.getInstance().getEmailSenderService().sendEmail(ctx); DeviceManagementDataHolder.getInstance().getEmailSenderService().sendEmail(ctx);
} catch (EmailSendingFailedException e) { } catch (EmailSendingFailedException e) {
throw new DeviceManagementException("Error occurred while sending user registration notification", e); throw new DeviceManagementException("Error occurred while sending user registration notification", e);
@ -620,7 +627,7 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
device = deviceDAO.getDevice(deviceId, status, this.getTenantId()); device = deviceDAO.getDevice(deviceId, status, this.getTenantId());
} catch (DeviceManagementDAOException e) { } catch (DeviceManagementDAOException e) {
throw new DeviceManagementException("Error occurred while obtaining the device for id " + throw new DeviceManagementException("Error occurred while obtaining the device for id " +
"'" + deviceId.getId() + "'", e); "'" + deviceId.getId() + "'", e);
} catch (SQLException e) { } catch (SQLException e) {
throw new DeviceManagementException("Error occurred while opening a connection to the data source", e); throw new DeviceManagementException("Error occurred while opening a connection to the data source", e);
} finally { } finally {
@ -633,7 +640,7 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
if (deviceManager == null) { if (deviceManager == null) {
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
log.debug("Device Manager associated with the device type '" + deviceId.getType() + "' is null. " + log.debug("Device Manager associated with the device type '" + deviceId.getType() + "' is null. " +
"Therefore, not attempting method 'getDevice'"); "Therefore, not attempting method 'getDevice'");
} }
return device; return device;
} }
@ -693,7 +700,7 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
return deviceTypesResponse; return deviceTypesResponse;
} }
@Override @Override
public boolean updateDeviceInfo(DeviceIdentifier deviceId, Device device) throws DeviceManagementException { public boolean updateDeviceInfo(DeviceIdentifier deviceId, Device device) throws DeviceManagementException {
DeviceManager deviceManager = this.getDeviceManager(deviceId.getType()); DeviceManager deviceManager = this.getDeviceManager(deviceId.getType());
if (deviceManager == null) { if (deviceManager == null) {
@ -758,7 +765,7 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
for (DeviceIdentifier deviceId : deviceIds) { for (DeviceIdentifier deviceId : deviceIds) {
DeviceManagementService dms = DeviceManagementService dms =
getPluginRepository().getDeviceManagementService(deviceId.getType(), this.getTenantId()); pluginRepository.getDeviceManagementService(deviceId.getType(), this.getTenantId());
//TODO FIX THIS WITH PUSH NOTIFICATIONS //TODO FIX THIS WITH PUSH NOTIFICATIONS
//dms.notifyOperationToDevices(operation, deviceIds); //dms.notifyOperationToDevices(operation, deviceIds);
} }
@ -808,12 +815,8 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
} }
} }
private DeviceManagementPluginRepository getPluginRepository() {
return pluginRepository;
}
@Override @Override
public int addOperation(Operation operation, public int addOperation(String type, Operation operation,
List<DeviceIdentifier> devices) throws OperationManagementException { List<DeviceIdentifier> devices) throws OperationManagementException {
return DeviceManagementDataHolder.getInstance().getOperationManager().addOperation(operation, devices); return DeviceManagementDataHolder.getInstance().getOperationManager().addOperation(operation, devices);
} }
@ -846,7 +849,7 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
} }
@Override @Override
public void deleteOperation(int operationId) throws OperationManagementException { public void deleteOperation(String type, int operationId) throws OperationManagementException {
DeviceManagementDataHolder.getInstance().getOperationManager().deleteOperation(operationId); DeviceManagementDataHolder.getInstance().getOperationManager().deleteOperation(operationId);
} }
@ -866,7 +869,7 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
} }
@Override @Override
public Operation getOperation(int operationId) throws OperationManagementException { public Operation getOperation(String type, int operationId) throws OperationManagementException {
return DeviceManagementDataHolder.getInstance().getOperationManager().getOperation(operationId); return DeviceManagementDataHolder.getInstance().getOperationManager().getOperation(operationId);
} }
@ -910,7 +913,6 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
devices.add(device); devices.add(device);
} }
return devices; return devices;
} }
@Override @Override
@ -928,7 +930,7 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
deviceCount = deviceDAO.getDeviceCountByUser(username, tenantId); deviceCount = deviceDAO.getDeviceCountByUser(username, tenantId);
} catch (DeviceManagementDAOException e) { } catch (DeviceManagementDAOException e) {
throw new DeviceManagementException("Error occurred while retrieving the list of devices that " + throw new DeviceManagementException("Error occurred while retrieving the list of devices that " +
"belong to the user '" + username + "'", e); "belong to the user '" + username + "'", e);
} catch (SQLException e) { } catch (SQLException e) {
throw new DeviceManagementException("Error occurred while opening a connection to the data source", e); throw new DeviceManagementException("Error occurred while opening a connection to the data source", e);
} finally { } finally {
@ -940,7 +942,7 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
if (deviceManager == null) { if (deviceManager == null) {
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
log.debug("Device Manager associated with the device type '" + device.getType() + "' is null. " + log.debug("Device Manager associated with the device type '" + device.getType() + "' is null. " +
"Therefore, not attempting method 'isEnrolled'"); "Therefore, not attempting method 'isEnrolled'");
} }
devices.add(device); devices.add(device);
continue; continue;
@ -1039,7 +1041,7 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
return deviceDAO.getDeviceCount(username, this.getTenantId()); return deviceDAO.getDeviceCount(username, this.getTenantId());
} catch (DeviceManagementDAOException e) { } catch (DeviceManagementDAOException e) {
throw new DeviceManagementException("Error occurred while retrieving the device count of user '" throw new DeviceManagementException("Error occurred while retrieving the device count of user '"
+ username + "'", e); + username + "'", e);
} catch (SQLException e) { } catch (SQLException e) {
throw new DeviceManagementException("Error occurred while opening a connection to the data source", e); throw new DeviceManagementException("Error occurred while opening a connection to the data source", e);
} finally { } finally {
@ -1104,7 +1106,7 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
result.setRecordsFiltered(deviceCount); result.setRecordsFiltered(deviceCount);
} catch (DeviceManagementDAOException e) { } catch (DeviceManagementDAOException e) {
throw new DeviceManagementException("Error occurred while fetching the list of devices that matches to '" throw new DeviceManagementException("Error occurred while fetching the list of devices that matches to '"
+ deviceName + "'", e); + deviceName + "'", e);
} catch (SQLException e) { } catch (SQLException e) {
throw new DeviceManagementException("Error occurred while opening a connection to the data source", e); throw new DeviceManagementException("Error occurred while opening a connection to the data source", e);
} finally { } finally {
@ -1147,6 +1149,17 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
public void registerDeviceManagementService(DeviceManagementService deviceManagementService) { public void registerDeviceManagementService(DeviceManagementService deviceManagementService) {
try { try {
pluginRepository.addDeviceManagementProvider(deviceManagementService); pluginRepository.addDeviceManagementProvider(deviceManagementService);
PushNotificationConfig pushNoteConfig = deviceManagementService.getPushNotificationConfig();
if (pushNoteConfig != null) {
NotificationStrategy notificationStrategy =
DeviceManagementDataHolder.getInstance().getPushNotificationProviderRepository().getProvider(
pushNoteConfig.getType()).getNotificationStrategy(pushNoteConfig);
operationManagerRepository.addOperationManager(
deviceManagementService.getType(), new OperationManagerImpl(notificationStrategy));
} else {
operationManagerRepository.addOperationManager(
deviceManagementService.getType(), new OperationManagerImpl());
}
} catch (DeviceManagementException e) { } catch (DeviceManagementException e) {
log.error("Error occurred while registering device management plugin '" + log.error("Error occurred while registering device management plugin '" +
deviceManagementService.getType() + "'", e); deviceManagementService.getType() + "'", e);
@ -1157,6 +1170,7 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
public void unregisterDeviceManagementService(DeviceManagementService deviceManagementService) { public void unregisterDeviceManagementService(DeviceManagementService deviceManagementService) {
try { try {
pluginRepository.removeDeviceManagementProvider(deviceManagementService); pluginRepository.removeDeviceManagementProvider(deviceManagementService);
operationManagerRepository.removeOperationManager(deviceManagementService.getType());
} catch (DeviceManagementException e) { } catch (DeviceManagementException e) {
log.error("Error occurred while un-registering device management plugin '" + log.error("Error occurred while un-registering device management plugin '" +
deviceManagementService.getType() + "'", e); deviceManagementService.getType() + "'", e);
@ -1230,7 +1244,7 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
private DeviceManager getDeviceManager(String deviceType) { private DeviceManager getDeviceManager(String deviceType) {
DeviceManagementService deviceManagementService = DeviceManagementService deviceManagementService =
this.getPluginRepository().getDeviceManagementService(deviceType, this.getTenantId()); pluginRepository.getDeviceManagementService(deviceType, this.getTenantId());
if (deviceManagementService == null) { if (deviceManagementService == null) {
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
log.debug("Device type '" + deviceType + "' does not have an associated device management " + log.debug("Device type '" + deviceType + "' does not have an associated device management " +

@ -95,7 +95,13 @@ public class DeviceTaskManagerImpl implements DeviceTaskManager {
operation.setEnabled(true); operation.setEnabled(true);
operation.setType(Operation.Type.COMMAND); operation.setType(Operation.Type.COMMAND);
operation.setCode(str); operation.setCode(str);
deviceManagementProviderService.addOperation(operation, DeviceManagerUtil.convertDevices(devices)); //TODO: Fix this properly later adding device type to be passed in when the task manage executes "addOperations()"
String type = null;
if (devices.size() > 0) {
type = devices.get(0).getType();
}
deviceManagementProviderService.addOperation(type, operation,
DeviceManagerUtil.convertDevices(devices));
} }
} else { } else {
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {

@ -50,6 +50,10 @@
<groupId>org.wso2.carbon.devicemgt</groupId> <groupId>org.wso2.carbon.devicemgt</groupId>
<artifactId>org.wso2.carbon.device.mgt.common</artifactId> <artifactId>org.wso2.carbon.device.mgt.common</artifactId>
</dependency> </dependency>
<dependency>
<groupId>org.wso2.carbon.devicemgt</groupId>
<artifactId>org.wso2.carbon.device.mgt.core</artifactId>
</dependency>
<dependency> <dependency>
<groupId>org.apache.ws.commons.axiom</groupId> <groupId>org.apache.ws.commons.axiom</groupId>
<artifactId>axiom-api</artifactId> <artifactId>axiom-api</artifactId>
@ -91,8 +95,21 @@
<artifactId>commons-lang</artifactId> <artifactId>commons-lang</artifactId>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.wso2.carbon.devicemgt</groupId> <groupId>org.eclipse.paho</groupId>
<artifactId>org.wso2.carbon.device.mgt.core</artifactId> <artifactId>org.eclipse.paho.client.mqttv3</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
</dependency>
<dependency>
<groupId>org.json.wso2</groupId>
<artifactId>json</artifactId>
</dependency>
<dependency>
<groupId>org.wso2.carbon.analytics-common</groupId>
<artifactId>org.wso2.carbon.event.output.adapter.core</artifactId>
</dependency> </dependency>
</dependencies> </dependencies>

@ -29,6 +29,6 @@ var utility = require("/app/modules/utility.js")["utility"];
var permissions = { var permissions = {
'/permission/admin/device-mgt/user': ['ui.execute'], '/permission/admin/device-mgt/user': ['ui.execute'],
'/permission/admin/device-mgt/api/application': ['ui.execute'] '/permission/admin/manage/api/subscribe': ['ui.execute']
}; };
userModule.addRole("internal/devicemgt-user", ["admin"], permissions); userModule.addRole("internal/devicemgt-user", ["admin"], permissions);

@ -27,7 +27,7 @@ import org.wso2.carbon.context.RegistryType;
import org.wso2.carbon.registry.api.Registry; import org.wso2.carbon.registry.api.Registry;
import org.wso2.carbon.registry.api.RegistryException; import org.wso2.carbon.registry.api.RegistryException;
import java.io.*; import java.io.InputStream;
public class RegistryBasedResourceLoader extends ResourceLoader { public class RegistryBasedResourceLoader extends ResourceLoader {
@ -46,12 +46,12 @@ public class RegistryBasedResourceLoader extends ResourceLoader {
if (registry == null) { if (registry == null) {
throw new IllegalStateException("No valid registry instance is attached to the current carbon context"); throw new IllegalStateException("No valid registry instance is attached to the current carbon context");
} }
if (!registry.resourceExists(EMAIL_CONFIG_BASE_LOCATION + "/" + name + ".vm")) { if (!registry.resourceExists(EMAIL_CONFIG_BASE_LOCATION + "/" + name)) {
throw new ResourceNotFoundException("Resource '" + name + "' does not exist"); throw new ResourceNotFoundException("Resource '" + name + "' does not exist");
} }
org.wso2.carbon.registry.api.Resource resource = org.wso2.carbon.registry.api.Resource resource =
registry.get(EMAIL_CONFIG_BASE_LOCATION + "/" + name + ".vm"); registry.get(EMAIL_CONFIG_BASE_LOCATION + "/" + name);
resource.setMediaType("text/plain");
return resource.getContentStream(); return resource.getContentStream();
} catch (RegistryException e) { } catch (RegistryException e) {
throw new ResourceNotFoundException("Error occurred while retrieving resource", e); throw new ResourceNotFoundException("Error occurred while retrieving resource", e);

@ -21,22 +21,11 @@ package org.wso2.carbon.email.sender.core.internal;
import org.apache.axis2.context.ConfigurationContext; import org.apache.axis2.context.ConfigurationContext;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; 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.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.Axis2ConfigurationContextObserver;
import org.wso2.carbon.utils.CarbonUtils;
import java.io.File; class EmailSenderAxis2ConfigContextObserver implements Axis2ConfigurationContextObserver {
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); private static final Log log = LogFactory.getLog(EmailSenderAxis2ConfigContextObserver.class);
@Override @Override
@ -47,7 +36,7 @@ public class EmailSenderAxis2ConfigContextObserver implements Axis2Configuration
@Override @Override
public void createdConfigurationContext(ConfigurationContext configurationContext) { public void createdConfigurationContext(ConfigurationContext configurationContext) {
try { try {
this.setupEmailTemplates(); EmailUtils.setupEmailTemplates();
} catch (EmailSenderConfigurationFailedException e) { } catch (EmailSenderConfigurationFailedException e) {
log.error("Error occurred while setting up email templates", e); log.error("Error occurred while setting up email templates", e);
} }
@ -63,50 +52,4 @@ public class EmailSenderAxis2ConfigContextObserver implements Axis2Configuration
} }
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 =
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);
}
}
}
} }

@ -17,28 +17,16 @@
*/ */
package org.wso2.carbon.email.sender.core.internal; 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.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import org.osgi.service.component.ComponentContext; import org.osgi.service.component.ComponentContext;
import org.wso2.carbon.email.sender.core.EmailSenderConfig; 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.EmailSenderService;
import org.wso2.carbon.email.sender.core.service.EmailSenderServiceImpl; 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.registry.core.service.RegistryService;
import org.wso2.carbon.utils.Axis2ConfigurationContextObserver; import org.wso2.carbon.utils.Axis2ConfigurationContextObserver;
import org.wso2.carbon.utils.CarbonUtils;
import org.wso2.carbon.utils.ConfigurationContextService; 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.component name="org.wso2.carbon.email.sender.EmailSenderServiceComponent" immediate="true"
* @scr.reference name="registry.service" * @scr.reference name="registry.service"
@ -56,7 +44,6 @@ import java.io.IOException;
*/ */
public class EmailSenderServiceComponent { public class EmailSenderServiceComponent {
private static final String EMAIL_TEMPLATE_DIR_RELATIVE_REGISTRY_PATH = "/email-templates";
private static Log log = LogFactory.getLog(EmailSenderServiceComponent.class); private static Log log = LogFactory.getLog(EmailSenderServiceComponent.class);
@SuppressWarnings("unused") @SuppressWarnings("unused")
@ -69,7 +56,7 @@ public class EmailSenderServiceComponent {
EmailSenderConfig.init(); EmailSenderConfig.init();
/* Setting up default email templates */ /* Setting up default email templates */
this.setupEmailTemplates(); EmailUtils.setupEmailTemplates();
/* Registering declarative service instances exposed by EmailSenderServiceComponent */ /* Registering declarative service instances exposed by EmailSenderServiceComponent */
this.registerServices(componentContext); this.registerServices(componentContext);
@ -98,64 +85,6 @@ public class EmailSenderServiceComponent {
componentContext.getBundleContext().registerService(EmailSenderService.class, emailServiceProvider, null); 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. * Sets Registry Service.
* *

@ -0,0 +1,87 @@
/*
* 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.wso2.carbon.context.CarbonContext;
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.CarbonUtils;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FilenameFilter;
import java.io.IOException;
class EmailUtils {
private static final String EMAIL_TEMPLATE_DIR_RELATIVE_REGISTRY_PATH = "/email-templates";
private static Log log = LogFactory.getLog(EmailSenderServiceComponent.class);
static 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 {
int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
Registry registry =
EmailSenderDataHolder.getInstance().getRegistryService().getConfigSystemRegistry(tenantId);
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.setMediaType("text/plain");
String contents = FileUtils.readFileToString(template);
resource.setContent(contents);
registry.put(EMAIL_TEMPLATE_DIR_RELATIVE_REGISTRY_PATH + "/"
+ template.getName().replace(".vm", ""), 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);
}
}
}
}

@ -96,7 +96,13 @@ public class PolicyManagerServiceImpl implements PolicyManagerService {
} }
List<DeviceIdentifier> deviceIdentifiers = new ArrayList<DeviceIdentifier>(); List<DeviceIdentifier> deviceIdentifiers = new ArrayList<DeviceIdentifier>();
deviceIdentifiers.add(deviceIdentifier); deviceIdentifiers.add(deviceIdentifier);
PolicyManagementDataHolder.getInstance().getDeviceManagementService().addOperation(
//TODO: Fix this properly later adding device type to be passed in when the task manage executes "addOperations()"
String type = null;
if (deviceIdentifiers.size() > 0) {
type = deviceIdentifiers.get(0).getType();
}
PolicyManagementDataHolder.getInstance().getDeviceManagementService().addOperation(type,
PolicyManagerUtil.transformPolicy(policy), deviceIdentifiers); PolicyManagerUtil.transformPolicy(policy), deviceIdentifiers);
return policy; return policy;
} catch (PolicyEvaluationException e) { } catch (PolicyEvaluationException e) {

@ -160,8 +160,14 @@ public class ComplianceDecisionPointImpl implements ComplianceDecisionPoint {
} }
policyOperation.setProfileOperations(profileOperationList); policyOperation.setProfileOperations(profileOperationList);
policyOperation.setPayLoad(policyOperation.getProfileOperations()); policyOperation.setPayLoad(policyOperation.getProfileOperations());
//TODO: Fix this properly later adding device type to be passed in when the task manage executes "addOperations()"
String type = null;
if (deviceIdentifiers.size() > 0) {
type = deviceIdentifiers.get(0).getType();
}
PolicyManagementDataHolder.getInstance().getDeviceManagementService(). PolicyManagementDataHolder.getInstance().getDeviceManagementService().
addOperation(policyOperation, deviceIdentifiers); addOperation(type, policyOperation, deviceIdentifiers);
} }

@ -402,8 +402,13 @@ public class MonitoringManagerImpl implements MonitoringManager {
// appListOperation.setType(Operation.Type.COMMAND); // appListOperation.setType(Operation.Type.COMMAND);
// appListOperation.setCode(OPERATION_APP_LIST); // appListOperation.setCode(OPERATION_APP_LIST);
//TODO: Fix this properly later adding device type to be passed in when the task manage executes "addOperations()"
String type = null;
if (deviceIdentifiers.size() > 0) {
type = deviceIdentifiers.get(0).getType();
}
DeviceManagementProviderService service = new DeviceManagementProviderServiceImpl(); DeviceManagementProviderService service = new DeviceManagementProviderServiceImpl();
service.addOperation(monitoringOperation, deviceIdentifiers); service.addOperation(type, monitoringOperation, deviceIdentifiers);
// service.addOperation(infoOperation, deviceIdentifiers); // service.addOperation(infoOperation, deviceIdentifiers);
// service.addOperation(appListOperation, deviceIdentifiers); // service.addOperation(appListOperation, deviceIdentifiers);
} }

@ -0,0 +1,106 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
~ 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.
-->
<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>device-mgt-extensions-feature</artifactId>
<version>1.1.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>org.wso2.carbon.device.mgt.extensions.push.notification.provider.gcm.feature</artifactId>
<packaging>pom</packaging>
<version>1.1.0-SNAPSHOT</version>
<name>WSO2 Carbon - GCM Based Push Notification Provider Feature</name>
<url>http://wso2.org</url>
<description>WSO2 Carbon - MQTT Based Push Notification Provider Feature</description>
<dependencies>
<dependency>
<groupId>org.wso2.carbon.devicemgt</groupId>
<artifactId>org.wso2.carbon.device.mgt.extensions.push.notification.provider.gcm</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<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.device.mgt.extensions.push.notification.provider.gcm</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.device.mgt.extensions.push.notification.provider.gcm:${carbon.device.mgt.version}
</bundleDef>
</bundles>
<importFeatures>
<importFeatureDef>org.wso2.carbon.core.server:${carbon.kernel.version}</importFeatureDef>
<importFeatureDef>org.wso2.carbon.device.mgt.server:${carbon.device.mgt.version}</importFeatureDef>
</importFeatures>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>

@ -0,0 +1,106 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
~ 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.
-->
<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>device-mgt-extensions-feature</artifactId>
<version>1.1.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>org.wso2.carbon.device.mgt.extensions.push.notification.provider.mqtt.feature</artifactId>
<packaging>pom</packaging>
<version>1.1.0-SNAPSHOT</version>
<name>WSO2 Carbon - MQTT Based Push Notification Provider Feature</name>
<url>http://wso2.org</url>
<description>WSO2 Carbon - MQTT Based Push Notification Provider Feature</description>
<dependencies>
<dependency>
<groupId>org.wso2.carbon.devicemgt</groupId>
<artifactId>org.wso2.carbon.device.mgt.extensions.push.notification.provider.mqtt</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<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.device.mgt.extensions.push.notification.provider.mqtt</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.device.mgt.extensions.push.notification.provider.mqtt:${carbon.device.mgt.version}
</bundleDef>
</bundles>
<importFeatures>
<importFeatureDef>org.wso2.carbon.core.server:${carbon.kernel.version}</importFeatureDef>
<importFeatureDef>org.wso2.carbon.device.mgt.server:${carbon.device.mgt.version}</importFeatureDef>
</importFeatures>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>

@ -0,0 +1,106 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
~ 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.
-->
<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>device-mgt-extensions-feature</artifactId>
<version>1.1.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>org.wso2.carbon.device.mgt.extensions.push.notification.provider.xmpp.feature</artifactId>
<packaging>pom</packaging>
<version>1.1.0-SNAPSHOT</version>
<name>WSO2 Carbon - XMPP Based Push Notification Provider Feature</name>
<url>http://wso2.org</url>
<description>WSO2 Carbon - XMPP Based Push Notification Provider Feature</description>
<dependencies>
<dependency>
<groupId>org.wso2.carbon.devicemgt</groupId>
<artifactId>org.wso2.carbon.device.mgt.extensions.push.notification.provider.xmpp</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<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.device.mgt.extensions.push.notification.provider.xmpp</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.device.mgt.extensions.push.notification.provider.xmpp:${carbon.device.mgt.version}
</bundleDef>
</bundles>
<importFeatures>
<importFeatureDef>org.wso2.carbon.core.server:${carbon.kernel.version}</importFeatureDef>
<importFeatureDef>org.wso2.carbon.device.mgt.server:${carbon.device.mgt.version}</importFeatureDef>
</importFeatures>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>

@ -0,0 +1,41 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ 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.
-->
<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.1.0-SNAPSHOT</version>
<relativePath>../../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>device-mgt-extensions-feature</artifactId>
<packaging>pom</packaging>
<name>WSO2 Carbon - Device Management Extensions Feature</name>
<url>http://wso2.org</url>
<modules>
<module>org.wso2.carbon.device.mgt.extensions.push.notification.provider.gcm.feature</module>
<module>org.wso2.carbon.device.mgt.extensions.push.notification.provider.mqtt.feature</module>
<module>org.wso2.carbon.device.mgt.extensions.push.notification.provider.xmpp.feature</module>
</modules>
</project>

@ -25,6 +25,10 @@
</JndiLookupDefinition> </JndiLookupDefinition>
</DataSourceConfiguration> </DataSourceConfiguration>
</ManagementRepository> </ManagementRepository>
<PushNotificationProviders>
<Provider>org.wso2.carbon.device.mgt.extensions.push.notification.provider.gcm.GCMBasedPushNotificationProvider</Provider>
<Provider>org.wso2.carbon.device.mgt.extensions.push.notification.provider.mqtt.MQTTBasedPushNotificationProvider</Provider>
</PushNotificationProviders>
<IdentityConfiguration> <IdentityConfiguration>
<ServerUrl>https://localhost:9443</ServerUrl> <ServerUrl>https://localhost:9443</ServerUrl>
<AdminUsername>admin</AdminUsername> <AdminUsername>admin</AdminUsername>

@ -17,7 +17,8 @@
~ under the License. ~ 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"> <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">
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<groupId>org.wso2.carbon.devicemgt</groupId> <groupId>org.wso2.carbon.devicemgt</groupId>
@ -36,12 +37,13 @@
<modules> <modules>
<module>components/device-mgt</module> <module>components/device-mgt</module>
<module>components/device-mgt-extensions</module>
<module>components/apimgt-extensions</module> <module>components/apimgt-extensions</module>
<module>components/policy-mgt</module> <module>components/policy-mgt</module>
<module>components/certificate-mgt</module> <module>components/certificate-mgt</module>
<module>components/webapp-authenticator-framework</module> <module>components/webapp-authenticator-framework</module>
<module>components/identity-extensions</module> <module>components/identity-extensions</module>
<module>components/email-sender</module> <module>components/email-sender</module>
<module>features/device-mgt</module> <module>features/device-mgt</module>
<module>features/apimgt-extensions</module> <module>features/apimgt-extensions</module>
<module>features/policy-mgt</module> <module>features/policy-mgt</module>
@ -49,8 +51,9 @@
<module>features/certificate-mgt</module> <module>features/certificate-mgt</module>
<module>features/dynamic-client-registration</module> <module>features/dynamic-client-registration</module>
<module>features/oauth-extensions</module> <module>features/oauth-extensions</module>
<module>features/email-sender</module> <module>features/email-sender</module>
<module>features/jwt-client</module> <module>features/jwt-client</module>
<module>features/device-mgt-extensions</module>
</modules> </modules>
<dependencyManagement> <dependencyManagement>
@ -1472,6 +1475,28 @@
<artifactId>servlet-api</artifactId> <artifactId>servlet-api</artifactId>
<version>${servlet-api.version}</version> <version>${servlet-api.version}</version>
</dependency> </dependency>
<dependency>
<groupId>org.wso2.carbon.analytics-common</groupId>
<artifactId>org.wso2.carbon.event.output.adapter.core</artifactId>
<version>${carbon.analytics.common.version}</version>
</dependency>
<dependency>
<groupId>org.wso2.carbon.devicemgt</groupId>
<artifactId>org.wso2.carbon.device.mgt.extensions.push.notification.provider.gcm</artifactId>
<version>${carbon.device.mgt.version}</version>
</dependency>
<dependency>
<groupId>org.wso2.carbon.devicemgt</groupId>
<artifactId>org.wso2.carbon.device.mgt.extensions.push.notification.provider.mqtt</artifactId>
<version>${carbon.device.mgt.version}</version>
</dependency>
<dependency>
<groupId>org.wso2.carbon.devicemgt</groupId>
<artifactId>org.wso2.carbon.device.mgt.extensions.push.notification.provider.xmpp</artifactId>
<version>${carbon.device.mgt.version}</version>
</dependency>
</dependencies> </dependencies>
</dependencyManagement> </dependencyManagement>

Loading…
Cancel
Save