diff --git a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.gcm/pom.xml b/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.gcm/pom.xml
new file mode 100644
index 0000000000..a15fcce6ef
--- /dev/null
+++ b/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.gcm/pom.xml
@@ -0,0 +1,147 @@
+
+
+
+
+
+
+ device-mgt-extensions
+ org.wso2.carbon.devicemgt
+ 1.1.0-SNAPSHOT
+ ../pom.xml
+
+
+ 4.0.0
+ org.wso2.carbon.device.mgt.extensions.push.notification.provider.gcm
+ bundle
+ WSO2 Carbon - GCM Based Push Notification Provider Implementation
+ WSO2 Carbon - GCM Based Push Notification Provider Implementation
+ http://wso2.org
+
+
+
+ org.wso2.carbon.governance
+ org.wso2.carbon.governance.api
+
+
+ org.wso2.carbon
+ org.wso2.carbon.registry.api
+
+
+ org.wso2.carbon
+ org.wso2.carbon.registry.core
+
+
+ org.wso2.carbon.devicemgt
+ org.wso2.carbon.device.mgt.common
+
+
+ org.wso2.carbon.devicemgt
+ org.wso2.carbon.device.mgt.core
+
+
+ org.apache.ws.commons.axiom
+ axiom-api
+
+
+ org.wso2.carbon
+ org.wso2.carbon.utils
+
+
+ org.wso2.orbit.org.scannotation
+ scannotation
+
+
+ org.eclipse.osgi
+ org.eclipse.osgi
+
+
+ org.eclipse.osgi
+ org.eclipse.osgi.services
+
+
+ org.wso2.tomcat
+ tomcat
+
+
+ org.wso2.tomcat
+ tomcat-servlet-api
+
+
+ javax.ws.rs
+ jsr311-api
+
+
+ org.apache.axis2.wso2
+ axis2
+
+
+ commons-lang.wso2
+ commons-lang
+
+
+ org.eclipse.paho
+ org.eclipse.paho.client.mqttv3
+ provided
+
+
+ com.google.code.gson
+ gson
+
+
+ org.json.wso2
+ json
+
+
+ org.wso2.carbon.analytics-common
+ org.wso2.carbon.event.output.adapter.core
+
+
+
+
+
+
+ org.apache.felix
+ maven-bundle-plugin
+ true
+
+
+ ${project.artifactId}
+ ${project.artifactId}
+ ${carbon.device.mgt.version}
+ GCM Based Push Notification Provider Bundle
+
+ !org.wso2.carbon.device.mgt.extensions.push.notification.provider.gcm.internal,
+ org.wso2.carbon.device.mgt.extensions.push.notification.provider.gcm.*
+
+
+ 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
+
+
+
+
+
+
+
+
diff --git a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.gcm/src/main/java/org/wso2/carbon/device/mgt/extensions/push/notification/provider/gcm/GCMBasedPushNotificationProvider.java b/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.gcm/src/main/java/org/wso2/carbon/device/mgt/extensions/push/notification/provider/gcm/GCMBasedPushNotificationProvider.java
new file mode 100644
index 0000000000..5168e25e25
--- /dev/null
+++ b/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.gcm/src/main/java/org/wso2/carbon/device/mgt/extensions/push/notification/provider/gcm/GCMBasedPushNotificationProvider.java
@@ -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);
+ }
+
+}
diff --git a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.gcm/src/main/java/org/wso2/carbon/device/mgt/extensions/push/notification/provider/gcm/GCMNotificationStrategy.java b/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.gcm/src/main/java/org/wso2/carbon/device/mgt/extensions/push/notification/provider/gcm/GCMNotificationStrategy.java
new file mode 100644
index 0000000000..65738e4ee1
--- /dev/null
+++ b/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.gcm/src/main/java/org/wso2/carbon/device/mgt/extensions/push/notification/provider/gcm/GCMNotificationStrategy.java
@@ -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 properties) {
+ String gcmToken = null;
+ for (Device.Property property : properties) {
+ if (GCM_TOKEN.equals(property.getName())) {
+ gcmToken = property.getValue();
+ break;
+ }
+ }
+ return gcmToken;
+ }
+
+}
diff --git a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.gcm/src/main/java/org/wso2/carbon/device/mgt/extensions/push/notification/provider/gcm/internal/GCMDataHolder.java b/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.gcm/src/main/java/org/wso2/carbon/device/mgt/extensions/push/notification/provider/gcm/internal/GCMDataHolder.java
new file mode 100644
index 0000000000..67b44109af
--- /dev/null
+++ b/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.gcm/src/main/java/org/wso2/carbon/device/mgt/extensions/push/notification/provider/gcm/internal/GCMDataHolder.java
@@ -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;
+ }
+
+}
diff --git a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.gcm/src/main/java/org/wso2/carbon/device/mgt/extensions/push/notification/provider/gcm/internal/GCMPushNotificationServiceComponent.java b/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.gcm/src/main/java/org/wso2/carbon/device/mgt/extensions/push/notification/provider/gcm/internal/GCMPushNotificationServiceComponent.java
new file mode 100644
index 0000000000..6e5171ec4b
--- /dev/null
+++ b/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.gcm/src/main/java/org/wso2/carbon/device/mgt/extensions/push/notification/provider/gcm/internal/GCMPushNotificationServiceComponent.java
@@ -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);
+ }
+
+}
diff --git a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.mqtt/pom.xml b/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.mqtt/pom.xml
new file mode 100644
index 0000000000..d06f9e6417
--- /dev/null
+++ b/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.mqtt/pom.xml
@@ -0,0 +1,148 @@
+
+
+
+
+
+
+ device-mgt-extensions
+ org.wso2.carbon.devicemgt
+ 1.1.0-SNAPSHOT
+ ../pom.xml
+
+
+ 4.0.0
+ org.wso2.carbon.device.mgt.extensions.push.notification.provider.mqtt
+ bundle
+ WSO2 Carbon - MQTT Based Push Notification Provider Implementation
+ WSO2 Carbon - MQTT Based Push Notification Provider Implementation
+ http://wso2.org
+
+
+
+ org.wso2.carbon.governance
+ org.wso2.carbon.governance.api
+
+
+ org.wso2.carbon
+ org.wso2.carbon.registry.api
+
+
+ org.wso2.carbon
+ org.wso2.carbon.registry.core
+
+
+ org.wso2.carbon.devicemgt
+ org.wso2.carbon.device.mgt.common
+
+
+ org.wso2.carbon.devicemgt
+ org.wso2.carbon.device.mgt.core
+
+
+ org.apache.ws.commons.axiom
+ axiom-api
+
+
+ org.wso2.carbon
+ org.wso2.carbon.utils
+
+
+ org.wso2.orbit.org.scannotation
+ scannotation
+
+
+ org.eclipse.osgi
+ org.eclipse.osgi
+
+
+ org.eclipse.osgi
+ org.eclipse.osgi.services
+
+
+ org.wso2.tomcat
+ tomcat
+
+
+ org.wso2.tomcat
+ tomcat-servlet-api
+
+
+ javax.ws.rs
+ jsr311-api
+
+
+ org.apache.axis2.wso2
+ axis2
+
+
+ commons-lang.wso2
+ commons-lang
+
+
+ org.eclipse.paho
+ org.eclipse.paho.client.mqttv3
+ provided
+
+
+ com.google.code.gson
+ gson
+
+
+ org.json.wso2
+ json
+
+
+ org.wso2.carbon.analytics-common
+ org.wso2.carbon.event.output.adapter.core
+
+
+
+
+
+
+ org.apache.felix
+ maven-bundle-plugin
+ true
+
+
+ ${project.artifactId}
+ ${project.artifactId}
+ ${carbon.device.mgt.version}
+ MQTT Based Push Notification Provider Bundle
+
+ !org.wso2.carbon.device.mgt.extensions.push.notification.provider.mqtt.internal,
+ org.wso2.carbon.device.mgt.extensions.push.notification.provider.mqtt.*
+
+
+ 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
+
+
+
+
+
+
+
+
diff --git a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.mqtt/src/main/java/org/wso2/carbon/device/mgt/extensions/push/notification/provider/mqtt/MQTTBasedPushNotificationProvider.java b/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.mqtt/src/main/java/org/wso2/carbon/device/mgt/extensions/push/notification/provider/mqtt/MQTTBasedPushNotificationProvider.java
new file mode 100644
index 0000000000..c4f645b255
--- /dev/null
+++ b/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.mqtt/src/main/java/org/wso2/carbon/device/mgt/extensions/push/notification/provider/mqtt/MQTTBasedPushNotificationProvider.java
@@ -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);
+ }
+
+}
diff --git a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.mqtt/src/main/java/org/wso2/carbon/device/mgt/extensions/push/notification/provider/mqtt/MQTTNotificationStrategy.java b/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.mqtt/src/main/java/org/wso2/carbon/device/mgt/extensions/push/notification/provider/mqtt/MQTTNotificationStrategy.java
new file mode 100644
index 0000000000..849b481208
--- /dev/null
+++ b/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.mqtt/src/main/java/org/wso2/carbon/device/mgt/extensions/push/notification/provider/mqtt/MQTTNotificationStrategy.java
@@ -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 configProperties = new HashMap();
+ 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 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;
+ }
+
+}
diff --git a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.mqtt/src/main/java/org/wso2/carbon/device/mgt/extensions/push/notification/provider/mqtt/MQTTPushNotificationStrategyUtil.java b/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.mqtt/src/main/java/org/wso2/carbon/device/mgt/extensions/push/notification/provider/mqtt/MQTTPushNotificationStrategyUtil.java
new file mode 100644
index 0000000000..fe3d83f365
--- /dev/null
+++ b/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.mqtt/src/main/java/org/wso2/carbon/device/mgt/extensions/push/notification/provider/mqtt/MQTTPushNotificationStrategyUtil.java
@@ -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();
+ }
+
+
+}
diff --git a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.mqtt/src/main/java/org/wso2/carbon/device/mgt/extensions/push/notification/provider/mqtt/internal/MQTTDataHolder.java b/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.mqtt/src/main/java/org/wso2/carbon/device/mgt/extensions/push/notification/provider/mqtt/internal/MQTTDataHolder.java
new file mode 100644
index 0000000000..90d68f036a
--- /dev/null
+++ b/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.mqtt/src/main/java/org/wso2/carbon/device/mgt/extensions/push/notification/provider/mqtt/internal/MQTTDataHolder.java
@@ -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;
+ }
+
+}
diff --git a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.mqtt/src/main/java/org/wso2/carbon/device/mgt/extensions/push/notification/provider/mqtt/internal/MQTTPushNotificationServiceComponent.java b/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.mqtt/src/main/java/org/wso2/carbon/device/mgt/extensions/push/notification/provider/mqtt/internal/MQTTPushNotificationServiceComponent.java
new file mode 100644
index 0000000000..25fed275cd
--- /dev/null
+++ b/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.mqtt/src/main/java/org/wso2/carbon/device/mgt/extensions/push/notification/provider/mqtt/internal/MQTTPushNotificationServiceComponent.java
@@ -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);
+ }
+
+}
diff --git a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.mqtt/src/main/java/org/wso2/carbon/device/mgt/extensions/push/notification/provider/mqtt/internal/util/MQTTAdapterConstants.java b/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.mqtt/src/main/java/org/wso2/carbon/device/mgt/extensions/push/notification/provider/mqtt/internal/util/MQTTAdapterConstants.java
new file mode 100644
index 0000000000..534afb3ab7
--- /dev/null
+++ b/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.mqtt/src/main/java/org/wso2/carbon/device/mgt/extensions/push/notification/provider/mqtt/internal/util/MQTTAdapterConstants.java
@@ -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";
+
+}
diff --git a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.xmpp/pom.xml b/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.xmpp/pom.xml
new file mode 100644
index 0000000000..8c16fa3a4b
--- /dev/null
+++ b/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.xmpp/pom.xml
@@ -0,0 +1,144 @@
+
+
+
+
+
+
+ device-mgt-extensions
+ org.wso2.carbon.devicemgt
+ 1.1.0-SNAPSHOT
+ ../pom.xml
+
+
+ 4.0.0
+ org.wso2.carbon.device.mgt.extensions.push.notification.provider.xmpp
+ bundle
+ WSO2 Carbon - XMPP Based Push Notification Provider Implementation
+ WSO2 Carbon - XMPP Based Push Notification Provider Implementation
+ http://wso2.org
+
+
+
+ org.wso2.carbon.governance
+ org.wso2.carbon.governance.api
+
+
+ org.wso2.carbon
+ org.wso2.carbon.registry.api
+
+
+ org.wso2.carbon
+ org.wso2.carbon.registry.core
+
+
+ org.wso2.carbon.devicemgt
+ org.wso2.carbon.device.mgt.common
+
+
+ org.wso2.carbon.devicemgt
+ org.wso2.carbon.device.mgt.core
+
+
+ org.apache.ws.commons.axiom
+ axiom-api
+
+
+ org.wso2.carbon
+ org.wso2.carbon.utils
+
+
+ org.wso2.orbit.org.scannotation
+ scannotation
+
+
+ org.eclipse.osgi
+ org.eclipse.osgi
+
+
+ org.eclipse.osgi
+ org.eclipse.osgi.services
+
+
+ org.wso2.tomcat
+ tomcat
+
+
+ org.wso2.tomcat
+ tomcat-servlet-api
+
+
+ javax.ws.rs
+ jsr311-api
+
+
+ org.apache.axis2.wso2
+ axis2
+
+
+ commons-lang.wso2
+ commons-lang
+
+
+ org.eclipse.paho
+ org.eclipse.paho.client.mqttv3
+ provided
+
+
+ com.google.code.gson
+ gson
+
+
+ org.json.wso2
+ json
+
+
+ org.wso2.carbon.analytics-common
+ org.wso2.carbon.event.output.adapter.core
+
+
+
+
+
+
+ org.apache.felix
+ maven-bundle-plugin
+ true
+
+
+ ${project.artifactId}
+ ${project.artifactId}
+ ${carbon.device.mgt.version}
+ XMPP Based Push Notification Provider Bundle
+
+ !org.wso2.carbon.device.mgt.extensions.push.notification.provider.xmpp.internal,
+ org.wso2.carbon.device.mgt.extensions.push.notification.provider.xmpp.*
+
+
+ org.apache.commons.logging,
+ org.osgi.service.component,
+ org.wso2.carbon.device.mgt.common.push.notification,
+ org.wso2.carbon.device.mgt.core.service
+
+
+
+
+
+
+
+
diff --git a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.xmpp/src/main/java/org/wso2/carbon/device/mgt/extensions/push/notification/provider/xmpp/XMPPBasedPushNotificationProvider.java b/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.xmpp/src/main/java/org/wso2/carbon/device/mgt/extensions/push/notification/provider/xmpp/XMPPBasedPushNotificationProvider.java
new file mode 100644
index 0000000000..df3799408f
--- /dev/null
+++ b/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.xmpp/src/main/java/org/wso2/carbon/device/mgt/extensions/push/notification/provider/xmpp/XMPPBasedPushNotificationProvider.java
@@ -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;
+ }
+
+}
diff --git a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.xmpp/src/main/java/org/wso2/carbon/device/mgt/extensions/push/notification/provider/xmpp/XMPPNotificationStrategy.java b/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.xmpp/src/main/java/org/wso2/carbon/device/mgt/extensions/push/notification/provider/xmpp/XMPPNotificationStrategy.java
new file mode 100644
index 0000000000..a8d460c7c2
--- /dev/null
+++ b/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.xmpp/src/main/java/org/wso2/carbon/device/mgt/extensions/push/notification/provider/xmpp/XMPPNotificationStrategy.java
@@ -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;
+ }
+
+}
diff --git a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.xmpp/src/main/java/org/wso2/carbon/device/mgt/extensions/push/notification/provider/xmpp/internal/XMPPDataHolder.java b/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.xmpp/src/main/java/org/wso2/carbon/device/mgt/extensions/push/notification/provider/xmpp/internal/XMPPDataHolder.java
new file mode 100644
index 0000000000..e9f38543a2
--- /dev/null
+++ b/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.xmpp/src/main/java/org/wso2/carbon/device/mgt/extensions/push/notification/provider/xmpp/internal/XMPPDataHolder.java
@@ -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;
+ }
+
+}
diff --git a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.xmpp/src/main/java/org/wso2/carbon/device/mgt/extensions/push/notification/provider/xmpp/internal/XMPPPushNotificationServiceComponent.java b/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.xmpp/src/main/java/org/wso2/carbon/device/mgt/extensions/push/notification/provider/xmpp/internal/XMPPPushNotificationServiceComponent.java
new file mode 100644
index 0000000000..3cf153c09f
--- /dev/null
+++ b/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.xmpp/src/main/java/org/wso2/carbon/device/mgt/extensions/push/notification/provider/xmpp/internal/XMPPPushNotificationServiceComponent.java
@@ -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);
+ }
+
+}
diff --git a/components/device-mgt-extensions/pom.xml b/components/device-mgt-extensions/pom.xml
new file mode 100644
index 0000000000..c1210f488a
--- /dev/null
+++ b/components/device-mgt-extensions/pom.xml
@@ -0,0 +1,42 @@
+
+
+
+
+
+
+ carbon-devicemgt
+ org.wso2.carbon.devicemgt
+ 1.1.0-SNAPSHOT
+ ../../pom.xml
+
+
+ 4.0.0
+ device-mgt-extensions
+ pom
+ WSO2 Carbon - Device Management Extensions
+ WSO2 Carbon - Device Management Extensions
+ http://wso2.org
+
+
+ org.wso2.carbon.device.mgt.extensions.push.notification.provider.gcm
+ org.wso2.carbon.device.mgt.extensions.push.notification.provider.mqtt
+ org.wso2.carbon.device.mgt.extensions.push.notification.provider.xmpp
+
+
+
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/api/impl/OperationImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/api/impl/OperationImpl.java
index edd4fc1906..f4631514c9 100644
--- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/api/impl/OperationImpl.java
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/api/impl/OperationImpl.java
@@ -128,7 +128,14 @@ public class OperationImpl implements org.wso2.carbon.device.mgt.jaxrs.api.Opera
ResponsePayload responseMsg = new ResponsePayload();
try {
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 deviceIdentifiers = operationContext.getDevices();
+ if (deviceIdentifiers.size() > 0) {
+ type = deviceIdentifiers.get(0).getType();
+ }
+ int operationId = dmService.addOperation(type, operationContext.getOperation(), operationContext.getDevices());
if (operationId > 0) {
responseMsg.setStatusCode(HttpStatus.SC_CREATED);
responseMsg.setMessageFromServer("Operation has added successfully.");
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/push/notification/NotificationContext.java b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/push/notification/NotificationContext.java
new file mode 100644
index 0000000000..546e4fcf29
--- /dev/null
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/push/notification/NotificationContext.java
@@ -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 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 getProperties() {
+ return properties;
+ }
+
+ public Operation getOperation() {
+ return operation;
+ }
+
+}
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/push/notification/NotificationStrategy.java b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/push/notification/NotificationStrategy.java
new file mode 100644
index 0000000000..137c87034b
--- /dev/null
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/push/notification/NotificationStrategy.java
@@ -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();
+
+}
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/push/notification/PushNotificationConfig.java b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/push/notification/PushNotificationConfig.java
index 8bced1717e..56cb65648e 100644
--- a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/push/notification/PushNotificationConfig.java
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/push/notification/PushNotificationConfig.java
@@ -18,24 +18,32 @@
*/
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 {
private String type;
- private Set properties;
+ Map properties;
- public PushNotificationConfig(String type, Set properties) {
+ public PushNotificationConfig(String type, Map properties) {
this.type = type;
this.properties = properties;
}
+ @XmlElement(name = "Type", required = true)
public String getType() {
return type;
}
- public Set getProperties() {
+ public Map getProperties() {
return properties;
}
+ public String getProperty(String name) {
+ return properties.get(name);
+ }
+
}
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/push/notification/PushNotificationExecutionFailedException.java b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/push/notification/PushNotificationExecutionFailedException.java
new file mode 100644
index 0000000000..83f726e09b
--- /dev/null
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/push/notification/PushNotificationExecutionFailedException.java
@@ -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);
+ }
+
+}
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/push/notification/PushNotificationProvider.java b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/push/notification/PushNotificationProvider.java
new file mode 100644
index 0000000000..c406670453
--- /dev/null
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/push/notification/PushNotificationProvider.java
@@ -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);
+
+}
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/pom.xml b/components/device-mgt/org.wso2.carbon.device.mgt.core/pom.xml
index 7e36265173..4ce3faf47b 100644
--- a/components/device-mgt/org.wso2.carbon.device.mgt.core/pom.xml
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/pom.xml
@@ -91,6 +91,7 @@
!org.wso2.carbon.device.mgt.core.internal,
org.wso2.carbon.device.mgt.core.*
+ *
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/app/mgt/ApplicationManagerProviderServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/app/mgt/ApplicationManagerProviderServiceImpl.java
index a19f7c3f6a..2df1177d20 100644
--- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/app/mgt/ApplicationManagerProviderServiceImpl.java
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/app/mgt/ApplicationManagerProviderServiceImpl.java
@@ -80,13 +80,13 @@ public class ApplicationManagerProviderServiceImpl implements ApplicationManagem
@Override
public void updateApplicationStatus(DeviceIdentifier deviceId, Application application,
- String status) throws ApplicationManagementException {
+ String status) throws ApplicationManagementException {
}
@Override
public String getApplicationStatus(DeviceIdentifier deviceId,
- Application application) throws ApplicationManagementException {
+ Application application) throws ApplicationManagementException {
return null;
}
@@ -94,17 +94,19 @@ public class ApplicationManagerProviderServiceImpl implements ApplicationManagem
public void installApplicationForDevices(Operation operation, List deviceIds)
throws ApplicationManagementException {
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
(operation, deviceIds);
- } catch (OperationManagementException opeEx) {
- String errorMsg = "Error in add operation at app installation:" + opeEx.getErrorMessage();
- log.error(errorMsg, opeEx);
- throw new ApplicationManagementException(errorMsg, opeEx);
- }catch (DeviceManagementException deviceEx){
- String errorMsg = "Error in notify operation at app installation:" + deviceEx.getErrorMessage();
- log.error(errorMsg, deviceEx);
- throw new ApplicationManagementException(errorMsg, deviceEx);
+ } catch (OperationManagementException e) {
+ throw new ApplicationManagementException("Error in add operation at app installation", e);
+ } catch (DeviceManagementException e) {
+ throw new ApplicationManagementException("Error in notify operation at app installation", e);
}
}
@@ -119,7 +121,6 @@ public class ApplicationManagerProviderServiceImpl implements ApplicationManagem
DeviceIdentifier deviceIdentifier;
-
for (String user : userNameList) {
userName = user;
deviceList = DeviceManagementDataHolder.getInstance().getDeviceManagementProvider().getDevicesOfUser
@@ -132,18 +133,20 @@ public class ApplicationManagerProviderServiceImpl implements ApplicationManagem
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()
- .addOperation(operation, deviceIdentifierList);
+ .addOperation(type, operation, deviceIdentifierList);
- } catch (DeviceManagementException devEx) {
- String errorMsg = "Error in get devices for user: "+userName+ " in app installation:" + devEx.getErrorMessage();
- log.error(errorMsg, devEx);
- throw new ApplicationManagementException(errorMsg, devEx);
+ } catch (DeviceManagementException e) {
+ throw new ApplicationManagementException("Error in get devices for user: " + userName +
+ " in app installation", e);
- } catch (OperationManagementException opeEx) {
- String errorMsg = "Error in add operation at app installation:" + opeEx.getErrorMessage();
- log.error(errorMsg, opeEx);
- throw new ApplicationManagementException(errorMsg, opeEx);
+ } catch (OperationManagementException e) {
+ throw new ApplicationManagementException("Error in add operation at app installation", e);
}
}
@@ -170,19 +173,20 @@ public class ApplicationManagerProviderServiceImpl implements ApplicationManagem
deviceIdentifierList.add(deviceIdentifier);
}
}
- DeviceManagementDataHolder.getInstance().getDeviceManagementProvider()
- .addOperation(operation, deviceIdentifierList);
-
- } catch (DeviceManagementException devEx) {
- String errorMsg = "Error in get devices for user role "+userRole+ " in app installation:"
- + devEx.getErrorMessage();
- log.error(errorMsg, devEx);
- throw new ApplicationManagementException(errorMsg, devEx);
-
- } catch (OperationManagementException opeEx) {
- String errorMsg = "Error in add operation at app installation:" + opeEx.getErrorMessage();
- log.error(errorMsg, opeEx);
- throw new ApplicationManagementException(errorMsg, opeEx);
+ //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().addOperation(type, operation,
+ deviceIdentifierList);
+
+ } catch (DeviceManagementException e) {
+ throw new ApplicationManagementException("Error in get devices for user role " + userRole +
+ " in app installation", e);
+
+ } catch (OperationManagementException e) {
+ throw new ApplicationManagementException("Error in add operation at app installation", e);
}
}
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/config/DeviceManagementConfig.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/config/DeviceManagementConfig.java
index ee11038ca4..30f7f7ea94 100644
--- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/config/DeviceManagementConfig.java
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/config/DeviceManagementConfig.java
@@ -31,13 +31,14 @@ import java.util.List;
* Represents Device Mgt configuration.
*/
@XmlRootElement(name = "DeviceMgtConfiguration")
+@SuppressWarnings("unused")
public final class DeviceManagementConfig {
private DeviceManagementConfigRepository deviceManagementConfigRepository;
private TaskConfiguration taskConfiguration;
private IdentityConfigurations identityConfigurations;
private PolicyConfiguration policyConfiguration;
- //private List pushNotificationProviders;
+ private List pushNotificationProviders;
private DTConfiguration dTDepyloymentConfiguration;
@XmlElement(name = "ManagementRepository", required = true)
@@ -86,15 +87,16 @@ public final class DeviceManagementConfig {
this.dTDepyloymentConfiguration = dTDeploymentConfiguration;
}
-// @XmlElementWrapper(name = "PushNotificationProviders", required = true)
-// @XmlElement(name = "Provider", required = true)
-// public List getPushNotificationProviders() {
-// return pushNotificationProviders;
-// }
-//
-// public void setPushNotificationProviders(List pushNotificationProviders) {
-// this.pushNotificationProviders = pushNotificationProviders;
-// }
+
+ @XmlElementWrapper(name = "PushNotificationProviders", required = true)
+ @XmlElement(name = "Provider", required = true)
+ public List getPushNotificationProviders() {
+ return pushNotificationProviders;
+ }
+
+ public void setPushNotificationProviders(List pushNotificationProviders) {
+ this.pushNotificationProviders = pushNotificationProviders;
+ }
}
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/internal/DeviceManagementDataHolder.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/internal/DeviceManagementDataHolder.java
index 0f966baf3b..8ca3ca45cc 100644
--- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/internal/DeviceManagementDataHolder.java
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/internal/DeviceManagementDataHolder.java
@@ -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.core.app.mgt.config.AppManagementConfig;
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.GroupManagementProviderService;
import org.wso2.carbon.email.sender.core.service.EmailSenderService;
@@ -53,6 +54,7 @@ public class DeviceManagementDataHolder {
private GroupManagementProviderService groupManagementProviderService;
private TaskService taskService;
private EmailSenderService emailSenderService;
+ private PushNotificationProviderRepository pushNotificationProviderRepository;
private DeviceManagementDataHolder() {}
@@ -196,4 +198,13 @@ public class DeviceManagementDataHolder {
this.emailSenderService = emailSenderService;
}
+ public void setPushNotificationProviderRepository(
+ PushNotificationProviderRepository pushNotificationProviderRepository) {
+ this.pushNotificationProviderRepository = pushNotificationProviderRepository;
+ }
+
+ public PushNotificationProviderRepository getPushNotificationProviderRepository() {
+ return pushNotificationProviderRepository;
+ }
+
}
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/internal/DeviceManagementServiceComponent.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/internal/DeviceManagementServiceComponent.java
index 09ac3fcd90..eee04e06da 100644
--- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/internal/DeviceManagementServiceComponent.java
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/internal/DeviceManagementServiceComponent.java
@@ -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.OperationManager;
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.core.DeviceManagementConstants;
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.dao.OperationManagementDAOFactory;
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.DeviceManagementProviderServiceImpl;
import org.wso2.carbon.device.mgt.core.service.GroupManagementProviderService;
@@ -153,15 +157,26 @@ public class DeviceManagementServiceComponent {
NotificationManagementDAOFactory.init(dsConfig);
OperationManagementDAOFactory.init(dsConfig);
- /*Initialize Operation Manager*/
+
+ /* Initialize Operation Manager */
this.initOperationsManager();
+
+ PushNotificationProviderRepository pushNotificationRepo = new PushNotificationProviderRepository();
+ List 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 */
String setupOption =
System.getProperty(DeviceManagementConstants.Common.PROPERTY_SETUP);
if (setupOption != null) {
if (log.isDebugEnabled()) {
log.debug("-Dsetup is enabled. Device management repository schema initialization is about to " +
- "begin");
+ "begin");
}
this.setupDeviceManagementSchema(dsConfig);
}
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/OperationManagerImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/OperationManagerImpl.java
index 6784b0cb70..f0dfbe95dc 100644
--- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/OperationManagerImpl.java
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/OperationManagerImpl.java
@@ -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.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 org.wso2.carbon.device.mgt.core.DeviceManagementConstants;
import org.wso2.carbon.device.mgt.core.dao.DeviceDAO;
import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOException;
@@ -62,6 +65,7 @@ public class OperationManagerImpl implements OperationManager {
private OperationMappingDAO operationMappingDAO;
private OperationDAO operationDAO;
private DeviceDAO deviceDAO;
+ private NotificationStrategy notificationStrategy;
public OperationManagerImpl() {
commandOperationDAO = OperationManagementDAOFactory.getCommandOperationDAO();
@@ -73,6 +77,11 @@ public class OperationManagerImpl implements OperationManager {
deviceDAO = DeviceManagementDAOFactory.getDeviceDAO();
}
+ public OperationManagerImpl(NotificationStrategy notificationStrategy) {
+ this();
+ this.notificationStrategy = notificationStrategy;
+ }
+
@Override
public int addOperation(Operation operation,
List deviceIds) throws OperationManagementException {
@@ -80,66 +89,92 @@ public class OperationManagerImpl implements OperationManager {
log.debug("operation:[" + operation.toString() + "]");
for (DeviceIdentifier deviceIdentifier : deviceIds) {
log.debug("device identifier id:[" + deviceIdentifier.getId() + "] type:[" +
- deviceIdentifier.getType() + "]");
+ deviceIdentifier.getType() + "]");
}
}
+
+ List 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 enrolments = this.getEnrollmentsByStatus(deviceIds);
try {
- List authorizedDeviceList;
- if (operation != null && isAuthenticationSkippedOperation(operation)) {
- authorizedDeviceList = deviceIds;
- } else {
- authorizedDeviceList = DeviceManagementDataHolder.getInstance().
- getDeviceAccessAuthorizationService().isUserAuthorized(deviceIds, DeviceGroupConstants.
- Permissions.DEFAULT_OPERATOR_PERMISSIONS).getAuthorizedDevices();
- }
- if (authorizedDeviceList.size() > 0) {
- try {
- int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
- List enrolments;
+
+ OperationManagementDAOFactory.beginTransaction();
+ org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation operationDto =
+ OperationDAOUtil.convertOperation(operation);
+ int operationId = this.lookupOperationDAO(operation).addOperation(operationDto);
+ for (EnrolmentInfo enrolmentInfo : enrolments) {
+ if (operationDto.getControl() ==
+ org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Control.NO_REPEAT) {
+ 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());
+ if (notificationStrategy != null) {
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();
- org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation operationDto =
- OperationDAOUtil.convertOperation(operation);
- int operationId = this.lookupOperationDAO(operation).addOperation(operationDto);
- for (EnrolmentInfo enrolmentInfo : enrolments) {
- if(operationDto.getControl() ==
- org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Control.NO_REPEAT){
- 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());
+ notificationStrategy.execute(new NotificationContext(
+ new DeviceIdentifier(enrolmentInfo.getDevice().getDeviceIdentifier(),
+ enrolmentInfo.getDevice().getType())));
+ } catch (PushNotificationExecutionFailedException e) {
+ log.error("Error occurred while sending push notifications to " +
+ enrolmentInfo.getDevice().getType() + " device carrying id '" +
+ enrolmentInfo.getDevice().getDeviceIdentifier() + "'", e);
}
- 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 getAuthorizedDevices(
+ Operation operation, List deviceIds) throws OperationManagementException {
+ List authorizedDeviceList;
+ try {
+ if (operation != null && isAuthenticationSkippedOperation(operation)) {
+ authorizedDeviceList = deviceIds;
} 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) {
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 getEnrollmentsByStatus(
+ List deviceIds) throws OperationManagementException {
+ List 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
@@ -162,8 +197,8 @@ public class OperationManagerImpl implements OperationManager {
OperationManagementDAOFactory.openConnection();
if (enrolmentId < 0) {
throw new OperationManagementException("Device not found for given device " +
- "Identifier:" + deviceId.getId() + " and given type" +
- deviceId.getType());
+ "Identifier:" + deviceId.getId() + " and given type" +
+ deviceId.getType());
}
List extends org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation> operationList =
operationDAO.getOperationsForDevice(enrolmentId);
@@ -174,12 +209,12 @@ public class OperationManagerImpl implements OperationManager {
}
} catch (OperationManagementDAOException e) {
throw new OperationManagementException("Error occurred while retrieving the list of " +
- "operations assigned for '" + deviceId.getType() +
- "' device '" + deviceId.getId() + "'", e);
+ "operations assigned for '" + deviceId.getType() +
+ "' device '" + deviceId.getId() + "'", e);
} catch (DeviceManagementDAOException e) {
throw new OperationManagementException("Error occurred while retrieving metadata of '" +
- deviceId.getType() + "' device carrying the identifier '" +
- deviceId.getId() + "'");
+ deviceId.getType() + "' device carrying the identifier '" +
+ deviceId.getId() + "'");
} catch (SQLException e) {
throw new OperationManagementException(
"Error occurred while opening a connection to the data source", e);
@@ -191,7 +226,7 @@ public class OperationManagerImpl implements OperationManager {
}
} catch (DeviceAccessAuthorizationException e) {
throw new OperationManagementException("Error occurred while authorizing access to the devices for user : " +
- this.getUser(), e);
+ this.getUser(), e);
}
return operations;
}
@@ -218,8 +253,8 @@ public class OperationManagerImpl implements OperationManager {
OperationManagementDAOFactory.openConnection();
if (enrolmentId < 0) {
throw new OperationManagementException("Device not found for given device " +
- "Identifier:" + deviceId.getId() + " and given type" +
- deviceId.getType());
+ "Identifier:" + deviceId.getId() + " and given type" +
+ deviceId.getType());
}
List extends org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation> operationList =
operationDAO.getOperationsForDevice(enrolmentId, request);
@@ -234,12 +269,12 @@ public class OperationManagerImpl implements OperationManager {
paginationResult.setRecordsFiltered(count);
} catch (OperationManagementDAOException e) {
throw new OperationManagementException("Error occurred while retrieving the list of " +
- "operations assigned for '" + deviceId.getType() +
- "' device '" + deviceId.getId() + "'", e);
+ "operations assigned for '" + deviceId.getType() +
+ "' device '" + deviceId.getId() + "'", e);
} catch (DeviceManagementDAOException e) {
throw new OperationManagementException("Error occurred while retrieving metadata of '" +
- deviceId.getType() + "' device carrying the identifier '" +
- deviceId.getId() + "'");
+ deviceId.getType() + "' device carrying the identifier '" +
+ deviceId.getId() + "'");
} catch (SQLException e) {
throw new OperationManagementException(
"Error occurred while opening a connection to the data source", e);
@@ -251,7 +286,7 @@ public class OperationManagerImpl implements OperationManager {
}
} catch (DeviceAccessAuthorizationException e) {
throw new OperationManagementException("Error occurred while authorizing access to the devices for user : " +
- this.getUser(), e);
+ this.getUser(), e);
}
return paginationResult;
@@ -259,7 +294,7 @@ public class OperationManagerImpl implements OperationManager {
@Override
public List extends Operation> getPendingOperations(DeviceIdentifier deviceId) throws
- OperationManagementException {
+ OperationManagementException {
if (log.isDebugEnabled()) {
log.debug("Device identifier id:[" + deviceId.getId() + "] type:[" + deviceId.getType() + "]");
}
@@ -281,8 +316,8 @@ public class OperationManagerImpl implements OperationManager {
OperationManagementDAOFactory.openConnection();
if (enrolmentId < 0) {
throw new OperationManagementException("Device not found for the given device Identifier:" +
- deviceId.getId() + " and given type:" +
- deviceId.getType());
+ deviceId.getId() + " and given type:" +
+ deviceId.getType());
}
dtoOperationList.addAll(commandOperationDAO.getOperationsByDeviceAndStatus(
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());
} catch (OperationManagementDAOException e) {
throw new OperationManagementException("Error occurred while retrieving the list of " +
- "pending operations assigned for '" + deviceId.getType() +
- "' device '" + deviceId.getId() + "'", e);
+ "pending operations assigned for '" + deviceId.getType() +
+ "' device '" + deviceId.getId() + "'", e);
} catch (DeviceManagementDAOException e) {
throw new OperationManagementException("Error occurred while retrieving the device " +
- "for device Identifier type -'" + deviceId.getType() +
- "' and device Id '" + deviceId.getId() + "'", e);
+ "for device Identifier type -'" + deviceId.getType() +
+ "' and device Id '" + deviceId.getId() + "'", e);
} catch (SQLException e) {
throw new OperationManagementException(
"Error occurred while opening a connection to the data source", e);
@@ -314,11 +349,11 @@ public class OperationManagerImpl implements OperationManager {
}
} else {
log.info("User : " + getUser() + " is not authorized to fetch operations on device : "
- + deviceId.getId());
+ + deviceId.getId());
}
} catch (DeviceAccessAuthorizationException e) {
throw new OperationManagementException("Error occurred while authorizing access to the devices for user :" +
- this.getUser(), e);
+ this.getUser(), e);
}
return operations;
}
@@ -345,27 +380,27 @@ public class OperationManagerImpl implements OperationManager {
OperationManagementDAOFactory.openConnection();
if (enrolmentId < 0) {
throw new OperationManagementException("Device not found for given device " +
- "Identifier:" + deviceId.getId() + " and given type" +
- deviceId.getType());
+ "Identifier:" + deviceId.getId() + " and given type" +
+ deviceId.getType());
}
org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation dtoOperation = operationDAO.
- getNextOperation(enrolmentId);
+ getNextOperation(enrolmentId);
if (dtoOperation != null) {
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;
commandOperation =
(org.wso2.carbon.device.mgt.core.dto.operation.mgt.CommandOperation) commandOperationDAO.
- getOperation(dtoOperation.getId());
+ getOperation(dtoOperation.getId());
dtoOperation.setEnabled(commandOperation.isEnabled());
} 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());
} 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());
} 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());
}
operation = OperationDAOUtil.convertOperation(dtoOperation);
@@ -374,8 +409,8 @@ public class OperationManagerImpl implements OperationManager {
throw new OperationManagementException("Error occurred while retrieving next pending operation", e);
} catch (DeviceManagementDAOException e) {
throw new OperationManagementException("Error occurred while retrieving the device " +
- "for device Identifier type -'" + deviceId.getType() +
- "' and device Id '" + deviceId.getId(), e);
+ "for device Identifier type -'" + deviceId.getType() +
+ "' and device Id '" + deviceId.getId(), e);
} catch (SQLException e) {
throw new OperationManagementException(
"Error occurred while opening a connection to the data source", e);
@@ -384,11 +419,11 @@ public class OperationManagerImpl implements OperationManager {
}
} else {
log.info("User : " + getUser() + " is not authorized to fetch operations on device : "
- + deviceId.getId());
+ + deviceId.getId());
}
} catch (DeviceAccessAuthorizationException e) {
throw new OperationManagementException("Error occurred while authorizing access to the devices for user : " +
- this.getUser(), e);
+ this.getUser(), e);
}
return operation;
}
@@ -411,15 +446,15 @@ public class OperationManagerImpl implements OperationManager {
enrolmentId = deviceDAO.getEnrolmentByStatus(deviceId, EnrolmentInfo.Status.ACTIVE, tenantId);
} catch (SQLException e) {
throw new OperationManagementException("Error occurred while opening a connection to the" +
- " data source", e);
+ " data source", e);
} finally {
DeviceManagementDAOFactory.closeConnection();
}
OperationManagementDAOFactory.beginTransaction();
if (operation.getStatus() != null) {
operationDAO.updateOperationStatus(enrolmentId, operationId,
- org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Status.
- valueOf(operation.getStatus().toString()));
+ org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Status.
+ valueOf(operation.getStatus().toString()));
}
if (operation.getOperationResponse() != null) {
operationDAO.addOperationResponse(enrolmentId, operationId, operation.getOperationResponse());
@@ -429,12 +464,12 @@ public class OperationManagerImpl implements OperationManager {
OperationManagementDAOFactory.rollbackTransaction();
throw new OperationManagementException(
"Error occurred while updating the operation: " + operationId + " status:" +
- operation.getStatus(), e);
+ operation.getStatus(), e);
} catch (DeviceManagementDAOException e) {
OperationManagementDAOFactory.rollbackTransaction();
throw new OperationManagementException(
- "Error occurred while fetching the device for device identifier: " + deviceId.getId() +
- "type:" + deviceId.getType(), e);
+ "Error occurred while fetching the device for device identifier: " + deviceId.getId() +
+ "type:" + deviceId.getType(), e);
} catch (TransactionManagementException e) {
throw new OperationManagementException("Error occurred while initiating a transaction", e);
} finally {
@@ -442,11 +477,11 @@ public class OperationManagerImpl implements OperationManager {
}
} else {
log.info("User : " + getUser() + " is not authorized to update operations on device : "
- + deviceId.getId());
+ + deviceId.getId());
}
} catch (DeviceAccessAuthorizationException e) {
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;
if (log.isDebugEnabled()) {
log.debug("Operation Id: " + operationId + " Device Type: " + deviceId.getType() + " Device Identifier: " +
- deviceId.getId());
+ deviceId.getId());
}
try {
boolean isUserAuthorized = DeviceManagementDataHolder.getInstance().getDeviceAccessAuthorizationService().
@@ -496,16 +531,16 @@ public class OperationManagerImpl implements OperationManager {
OperationManagementDAOFactory.openConnection();
if (enrolmentId < 0) {
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.
- getOperationByDeviceAndId(enrolmentId, operationId);
+ getOperationByDeviceAndId(enrolmentId, operationId);
if (dtoOperation.getType().
equals(org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Type.COMMAND)) {
org.wso2.carbon.device.mgt.core.dto.operation.mgt.CommandOperation commandOperation;
commandOperation =
(org.wso2.carbon.device.mgt.core.dto.operation.mgt.CommandOperation) commandOperationDAO.
- getOperation(dtoOperation.getId());
+ getOperation(dtoOperation.getId());
dtoOperation.setEnabled(commandOperation.isEnabled());
} else if (dtoOperation.getType().
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) {
throw new OperationManagementException("Operation not found for operation Id:" + operationId +
- " device id:" + deviceId.getId());
+ " device id:" + deviceId.getId());
}
operation = OperationDAOUtil.convertOperation(dtoOperation);
} catch (OperationManagementDAOException e) {
throw new OperationManagementException("Error occurred while retrieving the list of " +
- "operations assigned for '" + deviceId.getType() +
- "' device '" + deviceId.getId() + "'", e);
+ "operations assigned for '" + deviceId.getType() +
+ "' device '" + deviceId.getId() + "'", e);
} catch (DeviceManagementDAOException e) {
throw new OperationManagementException("Error occurred while retrieving the device " +
- "for device Identifier type -'" + deviceId.getType() +
- "' and device Id '" + deviceId.getId() + "'", e);
+ "for device Identifier type -'" + deviceId.getType() +
+ "' and device Id '" + deviceId.getId() + "'", e);
} catch (SQLException e) {
throw new OperationManagementException("Error occurred while opening connection to the data source",
- e);
+ e);
} finally {
OperationManagementDAOFactory.closeConnection();
}
} else {
log.info("User : " + getUser() + " is not authorized to fetch operations on device : "
- + deviceId.getId());
+ + deviceId.getId());
}
} catch (DeviceAccessAuthorizationException e) {
throw new OperationManagementException("Error occurred while authorizing access to the devices for user :" +
- this.getUser(), e);
+ this.getUser(), e);
}
return operation;
}
@@ -571,18 +606,18 @@ public class OperationManagerImpl implements OperationManager {
if (enrolmentId < 0) {
throw new OperationManagementException(
"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.valueOf(status.toString());
dtoOperationList.addAll(commandOperationDAO.getOperationsByDeviceAndStatus(enrolmentId, dtoOpStatus));
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,
- 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,
- 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;
@@ -593,13 +628,13 @@ public class OperationManagerImpl implements OperationManager {
} catch (OperationManagementDAOException e) {
throw new OperationManagementException("Error occurred while retrieving the list of " +
- "operations assigned for '" + deviceId.getType() +
- "' device '" +
- deviceId.getId() + "' and status:" + status.toString(), e);
+ "operations assigned for '" + deviceId.getType() +
+ "' device '" +
+ deviceId.getId() + "' and status:" + status.toString(), e);
} catch (DeviceManagementDAOException e) {
throw new OperationManagementException("Error occurred while retrieving the device " +
- "for device Identifier type -'" + deviceId.getType() +
- "' and device Id '" + deviceId.getId(), e);
+ "for device Identifier type -'" + deviceId.getType() +
+ "' and device Id '" + deviceId.getId(), e);
} catch (SQLException e) {
throw new OperationManagementException(
"Error occurred while opening a connection to the data source", e);
@@ -608,11 +643,11 @@ public class OperationManagerImpl implements OperationManager {
}
} else {
log.info("User : " + getUser() + " is not authorized to fetch operations on device : "
- + deviceId.getId());
+ + deviceId.getId());
}
} catch (DeviceAccessAuthorizationException e) {
throw new OperationManagementException("Error occurred while authorizing access to the devices for user :" +
- this.getUser(), e);
+ this.getUser(), e);
}
return operations;
}
@@ -623,7 +658,7 @@ public class OperationManagerImpl implements OperationManager {
try {
OperationManagementDAOFactory.openConnection();
org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation dtoOperation = operationDAO.
- getOperation(operationId);
+ getOperation(operationId);
if (dtoOperation == null) {
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;
commandOperation =
(org.wso2.carbon.device.mgt.core.dto.operation.mgt.CommandOperation) commandOperationDAO.
- getOperation(dtoOperation.getId());
+ getOperation(dtoOperation.getId());
dtoOperation.setEnabled(commandOperation.isEnabled());
} else if (dtoOperation.getType().
equals(org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Type.CONFIG)) {
dtoOperation = configOperationDAO.getOperation(dtoOperation.getId());
} else if (dtoOperation.getType().equals(org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Type.
- PROFILE)) {
+ PROFILE)) {
dtoOperation = profileOperationDAO.getOperation(dtoOperation.getId());
} else if (dtoOperation.getType().equals(org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Type.
- POLICY)) {
+ POLICY)) {
dtoOperation = policyOperationDAO.getOperation(dtoOperation.getId());
}
operation = OperationDAOUtil.convertOperation(dtoOperation);
} catch (OperationManagementDAOException e) {
throw new OperationManagementException("Error occurred while retrieving the operation with operation Id '" +
- operationId, e);
+ operationId, e);
} catch (SQLException e) {
throw new OperationManagementException("Error occurred while opening a connection to the data source", e);
} finally {
@@ -662,7 +697,7 @@ public class OperationManagerImpl implements OperationManager {
Operation operation;
int enrollmentOpMappingId = Integer.parseInt(
activity.replace(DeviceManagementConstants.OperationAttributes.ACTIVITY, ""));
- if(enrollmentOpMappingId == 0){
+ if (enrollmentOpMappingId == 0) {
throw new IllegalArgumentException("Operation ID cannot be null or zero (0).");
}
try {
@@ -692,7 +727,7 @@ public class OperationManagerImpl implements OperationManager {
}
operation = OperationDAOUtil.convertOperation(dtoOperation);
int enrolmentId = operationDAO.getEnrolmentIdFromMappingId(enrollmentOpMappingId);
- if (enrolmentId !=0) {
+ if (enrolmentId != 0) {
operation.setResponses(operationDAO.getOperationResponses(enrolmentId, operation.getId()));
}
@@ -754,10 +789,10 @@ public class OperationManagerImpl implements OperationManager {
boolean status;
switch (operation.getCode()) {
- case DeviceManagementConstants.AuthorizationSkippedOperationCodes.POLICY_OPERATION_CODE :
+ case DeviceManagementConstants.AuthorizationSkippedOperationCodes.POLICY_OPERATION_CODE:
status = true;
break;
- case DeviceManagementConstants.AuthorizationSkippedOperationCodes.MONITOR_OPERATION_CODE :
+ case DeviceManagementConstants.AuthorizationSkippedOperationCodes.MONITOR_OPERATION_CODE:
status = true;
break;
default:
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/OperationManagerRepository.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/OperationManagerRepository.java
new file mode 100644
index 0000000000..fb85d91fca
--- /dev/null
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/OperationManagerRepository.java
@@ -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 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);
+ }
+
+}
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/push/notification/mgt/PushNotificationBasedOperationManager.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/push/notification/mgt/PushNotificationBasedOperationManager.java
new file mode 100644
index 0000000000..94486be464
--- /dev/null
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/push/notification/mgt/PushNotificationBasedOperationManager.java
@@ -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 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);
+ }
+
+}
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/push/notification/mgt/PushNotificationConfigRepository.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/push/notification/mgt/PushNotificationConfigRepository.java
new file mode 100644
index 0000000000..5e55404d56
--- /dev/null
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/push/notification/mgt/PushNotificationConfigRepository.java
@@ -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 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());
+ }
+
+}
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/push/notification/mgt/PushNotificationEnabledDeviceManagementService.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/push/notification/mgt/PushNotificationEnabledDeviceManagementService.java
new file mode 100644
index 0000000000..186329181e
--- /dev/null
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/push/notification/mgt/PushNotificationEnabledDeviceManagementService.java
@@ -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) {
+
+ }
+
+}
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/push/notification/mgt/PushNotificationProviderFactory.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/push/notification/mgt/PushNotificationProviderFactory.java
new file mode 100644
index 0000000000..609fb74106
--- /dev/null
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/push/notification/mgt/PushNotificationProviderFactory.java
@@ -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;
+ }
+
+}
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/push/notification/mgt/PushNotificationProviderRepository.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/push/notification/mgt/PushNotificationProviderRepository.java
new file mode 100644
index 0000000000..822f62dff1
--- /dev/null
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/push/notification/mgt/PushNotificationProviderRepository.java
@@ -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 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);
+ }
+
+}
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/push/notification/mgt/UnsupportedPushNotificationProviderException.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/push/notification/mgt/UnsupportedPushNotificationProviderException.java
new file mode 100644
index 0000000000..f7434216ae
--- /dev/null
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/push/notification/mgt/UnsupportedPushNotificationProviderException.java
@@ -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);
+ }
+
+}
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderService.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderService.java
index 1a6cd8b7e8..69e49d2c9e 100644
--- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderService.java
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderService.java
@@ -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.license.mgt.License;
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.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
* and resolve the appropriate plugin implementation
*/
-public interface DeviceManagementProviderService extends OperationManager {
+public interface DeviceManagementProviderService {
List getAllDevices(String deviceType) throws DeviceManagementException;
@@ -212,6 +213,35 @@ public interface DeviceManagementProviderService extends OperationManager {
boolean setStatus(DeviceIdentifier deviceId, String currentOwner,
EnrolmentInfo.Status status) throws DeviceManagementException;
- void notifyOperationToDevices(Operation operation, List deviceIds) throws DeviceManagementException;
+ void notifyOperationToDevices(Operation operation,
+ List deviceIds) throws DeviceManagementException;
+
+ int addOperation(String type, Operation operation,
+ List 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;
}
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderServiceImpl.java
index 3324da66ac..8543b76e79 100644
--- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderServiceImpl.java
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderServiceImpl.java
@@ -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.operation.mgt.Operation;
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.core.DeviceManagementPluginRepository;
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.DeviceManagementServiceComponent;
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.email.sender.core.ContentProviderInfo;
import org.wso2.carbon.email.sender.core.EmailContext;
@@ -70,9 +74,11 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
private DeviceTypeDAO deviceTypeDAO;
private EnrollmentDAO enrollmentDAO;
private DeviceManagementPluginRepository pluginRepository;
+ private OperationManagerRepository operationManagerRepository;
public DeviceManagementProviderServiceImpl() {
this.pluginRepository = new DeviceManagementPluginRepository();
+ this.operationManagerRepository = new OperationManagerRepository();
initDataAccessObjects();
/* Registering a listener to retrieve events when some device management service plugin is installed after
* the component is done getting initialized */
@@ -88,7 +94,8 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
@Override
public boolean saveConfiguration(TenantConfiguration configuration) throws DeviceManagementException {
DeviceManager dms =
- this.getPluginRepository().getDeviceManagementService(configuration.getType(), this.getTenantId()).getDeviceManager();
+ pluginRepository.getDeviceManagementService(configuration.getType(),
+ this.getTenantId()).getDeviceManager();
return dms.saveConfiguration(configuration);
}
@@ -100,7 +107,7 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
@Override
public TenantConfiguration getConfiguration(String deviceType) throws DeviceManagementException {
DeviceManager dms =
- this.getPluginRepository().getDeviceManagementService(deviceType, this.getTenantId()).getDeviceManager();
+ pluginRepository.getDeviceManagementService(deviceType, this.getTenantId()).getDeviceManager();
if (dms == null) {
if (log.isDebugEnabled()) {
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) {
//Get all the enrollments of current user for the same device
List enrolmentInfos = this.getEnrollmentsOfUser(existingDevice.getId(),
- newEnrolmentInfo.getOwner());
+ newEnrolmentInfo.getOwner());
for (EnrolmentInfo enrolmentInfo : enrolmentInfos) {
//If the enrollments are same then we'll update the existing enrollment.
if (enrolmentInfo.equals(newEnrolmentInfo)) {
@@ -182,15 +189,15 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
DeviceManagementDAOFactory.commitTransaction();
if (log.isDebugEnabled()) {
log.debug("An enrolment is successfully added with the id '" + enrolmentId +
- "' associated with " + "the device identified by key '" +
- device.getDeviceIdentifier() + "', which belongs to " + "platform '" +
- device.getType() + " upon the user '" + device.getEnrolmentInfo().getOwner() +
- "'");
+ "' associated with " + "the device identified by key '" +
+ device.getDeviceIdentifier() + "', which belongs to " + "platform '" +
+ device.getType() + " upon the user '" + device.getEnrolmentInfo().getOwner() +
+ "'");
}
status = true;
} else {
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) {
DeviceManagementDAOFactory.rollbackTransaction();
@@ -277,7 +284,7 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
enrolmentInfos = enrollmentDAO.getEnrollmentsOfUser(deviceId, user, this.getTenantId());
} catch (DeviceManagementDAOException e) {
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) {
throw new DeviceManagementException("Error occurred while opening a connection to the data source", e);
} finally {
@@ -424,7 +431,7 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
count = deviceDAO.getDeviceCountByType(deviceType, tenantId);
} catch (DeviceManagementDAOException e) {
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) {
throw new DeviceManagementException("Error occurred while opening a connection to the data source", e);
} finally {
@@ -435,7 +442,7 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
if (deviceManager == null) {
if (log.isDebugEnabled()) {
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);
continue;
@@ -467,7 +474,7 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
count = deviceDAO.getDeviceCount(request, tenantId);
} catch (DeviceManagementDAOException e) {
throw new DeviceManagementException("Error occurred while retrieving device list pertaining to " +
- "the current tenant", e);
+ "the current tenant", e);
} catch (SQLException e) {
throw new DeviceManagementException("Error occurred while opening a connection to the data source", e);
} finally {
@@ -478,7 +485,7 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
if (deviceManager == null) {
if (log.isDebugEnabled()) {
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);
continue;
@@ -546,7 +553,7 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
try {
EmailContext ctx =
new EmailContext.EmailContextBuilder(new ContentProviderInfo("user-enrollment", params),
- metaInfo.getRecipients()).build();
+ metaInfo.getRecipients()).build();
DeviceManagementDataHolder.getInstance().getEmailSenderService().sendEmail(ctx);
} catch (EmailSendingFailedException e) {
throw new DeviceManagementException("Error occurred while sending enrollment invitation", e);
@@ -571,7 +578,7 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
try {
EmailContext ctx =
new EmailContext.EmailContextBuilder(new ContentProviderInfo("user-registration", params),
- metaInfo.getRecipients()).build();
+ metaInfo.getRecipients()).build();
DeviceManagementDataHolder.getInstance().getEmailSenderService().sendEmail(ctx);
} catch (EmailSendingFailedException 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());
} catch (DeviceManagementDAOException e) {
throw new DeviceManagementException("Error occurred while obtaining the device for id " +
- "'" + deviceId.getId() + "'", e);
+ "'" + deviceId.getId() + "'", e);
} catch (SQLException e) {
throw new DeviceManagementException("Error occurred while opening a connection to the data source", e);
} finally {
@@ -633,7 +640,7 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
if (deviceManager == null) {
if (log.isDebugEnabled()) {
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;
}
@@ -693,7 +700,7 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
return deviceTypesResponse;
}
- @Override
+ @Override
public boolean updateDeviceInfo(DeviceIdentifier deviceId, Device device) throws DeviceManagementException {
DeviceManager deviceManager = this.getDeviceManager(deviceId.getType());
if (deviceManager == null) {
@@ -758,7 +765,7 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
for (DeviceIdentifier deviceId : deviceIds) {
DeviceManagementService dms =
- getPluginRepository().getDeviceManagementService(deviceId.getType(), this.getTenantId());
+ pluginRepository.getDeviceManagementService(deviceId.getType(), this.getTenantId());
//TODO FIX THIS WITH PUSH NOTIFICATIONS
//dms.notifyOperationToDevices(operation, deviceIds);
}
@@ -808,12 +815,8 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
}
}
- private DeviceManagementPluginRepository getPluginRepository() {
- return pluginRepository;
- }
-
@Override
- public int addOperation(Operation operation,
+ public int addOperation(String type, Operation operation,
List devices) throws OperationManagementException {
return DeviceManagementDataHolder.getInstance().getOperationManager().addOperation(operation, devices);
}
@@ -846,7 +849,7 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
}
@Override
- public void deleteOperation(int operationId) throws OperationManagementException {
+ public void deleteOperation(String type, int operationId) throws OperationManagementException {
DeviceManagementDataHolder.getInstance().getOperationManager().deleteOperation(operationId);
}
@@ -866,7 +869,7 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
}
@Override
- public Operation getOperation(int operationId) throws OperationManagementException {
+ public Operation getOperation(String type, int operationId) throws OperationManagementException {
return DeviceManagementDataHolder.getInstance().getOperationManager().getOperation(operationId);
}
@@ -910,7 +913,6 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
devices.add(device);
}
return devices;
-
}
@Override
@@ -928,7 +930,7 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
deviceCount = deviceDAO.getDeviceCountByUser(username, tenantId);
} catch (DeviceManagementDAOException e) {
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) {
throw new DeviceManagementException("Error occurred while opening a connection to the data source", e);
} finally {
@@ -940,7 +942,7 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
if (deviceManager == null) {
if (log.isDebugEnabled()) {
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);
continue;
@@ -1039,7 +1041,7 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
return deviceDAO.getDeviceCount(username, this.getTenantId());
} catch (DeviceManagementDAOException e) {
throw new DeviceManagementException("Error occurred while retrieving the device count of user '"
- + username + "'", e);
+ + username + "'", e);
} catch (SQLException e) {
throw new DeviceManagementException("Error occurred while opening a connection to the data source", e);
} finally {
@@ -1104,7 +1106,7 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
result.setRecordsFiltered(deviceCount);
} catch (DeviceManagementDAOException e) {
throw new DeviceManagementException("Error occurred while fetching the list of devices that matches to '"
- + deviceName + "'", e);
+ + deviceName + "'", e);
} catch (SQLException e) {
throw new DeviceManagementException("Error occurred while opening a connection to the data source", e);
} finally {
@@ -1147,6 +1149,17 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
public void registerDeviceManagementService(DeviceManagementService deviceManagementService) {
try {
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) {
log.error("Error occurred while registering device management plugin '" +
deviceManagementService.getType() + "'", e);
@@ -1157,6 +1170,7 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
public void unregisterDeviceManagementService(DeviceManagementService deviceManagementService) {
try {
pluginRepository.removeDeviceManagementProvider(deviceManagementService);
+ operationManagerRepository.removeOperationManager(deviceManagementService.getType());
} catch (DeviceManagementException e) {
log.error("Error occurred while un-registering device management plugin '" +
deviceManagementService.getType() + "'", e);
@@ -1230,7 +1244,7 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
private DeviceManager getDeviceManager(String deviceType) {
DeviceManagementService deviceManagementService =
- this.getPluginRepository().getDeviceManagementService(deviceType, this.getTenantId());
+ pluginRepository.getDeviceManagementService(deviceType, this.getTenantId());
if (deviceManagementService == null) {
if (log.isDebugEnabled()) {
log.debug("Device type '" + deviceType + "' does not have an associated device management " +
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/task/impl/DeviceTaskManagerImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/task/impl/DeviceTaskManagerImpl.java
index b3bd8d5db0..ab83fd3587 100644
--- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/task/impl/DeviceTaskManagerImpl.java
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/task/impl/DeviceTaskManagerImpl.java
@@ -95,7 +95,13 @@ public class DeviceTaskManagerImpl implements DeviceTaskManager {
operation.setEnabled(true);
operation.setType(Operation.Type.COMMAND);
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 {
if (log.isDebugEnabled()) {
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.extensions/pom.xml b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/pom.xml
index 41aa93f835..a0484f63cd 100644
--- a/components/device-mgt/org.wso2.carbon.device.mgt.extensions/pom.xml
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/pom.xml
@@ -50,6 +50,10 @@
org.wso2.carbon.devicemgt
org.wso2.carbon.device.mgt.common
+
+ org.wso2.carbon.devicemgt
+ org.wso2.carbon.device.mgt.core
+
org.apache.ws.commons.axiom
axiom-api
@@ -91,8 +95,21 @@
commons-lang
- org.wso2.carbon.devicemgt
- org.wso2.carbon.device.mgt.core
+ org.eclipse.paho
+ org.eclipse.paho.client.mqttv3
+ provided
+
+
+ com.google.code.gson
+ gson
+
+
+ org.json.wso2
+ json
+
+
+ org.wso2.carbon.analytics-common
+ org.wso2.carbon.event.output.adapter.core
diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/PolicyManagerServiceImpl.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/PolicyManagerServiceImpl.java
index 2027c10a7f..24bfc8294d 100644
--- a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/PolicyManagerServiceImpl.java
+++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/PolicyManagerServiceImpl.java
@@ -96,7 +96,13 @@ public class PolicyManagerServiceImpl implements PolicyManagerService {
}
List deviceIdentifiers = new ArrayList();
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);
return policy;
} catch (PolicyEvaluationException e) {
diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/impl/ComplianceDecisionPointImpl.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/impl/ComplianceDecisionPointImpl.java
index 45f92146b2..94b1107440 100644
--- a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/impl/ComplianceDecisionPointImpl.java
+++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/impl/ComplianceDecisionPointImpl.java
@@ -160,8 +160,14 @@ public class ComplianceDecisionPointImpl implements ComplianceDecisionPoint {
}
policyOperation.setProfileOperations(profileOperationList);
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().
- addOperation(policyOperation, deviceIdentifiers);
+ addOperation(type, policyOperation, deviceIdentifiers);
}
diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/mgt/impl/MonitoringManagerImpl.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/mgt/impl/MonitoringManagerImpl.java
index 9f6df4969c..25bb2709d8 100644
--- a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/mgt/impl/MonitoringManagerImpl.java
+++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/mgt/impl/MonitoringManagerImpl.java
@@ -402,8 +402,13 @@ public class MonitoringManagerImpl implements MonitoringManager {
// appListOperation.setType(Operation.Type.COMMAND);
// 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();
- service.addOperation(monitoringOperation, deviceIdentifiers);
+ service.addOperation(type, monitoringOperation, deviceIdentifiers);
// service.addOperation(infoOperation, deviceIdentifiers);
// service.addOperation(appListOperation, deviceIdentifiers);
}
diff --git a/features/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.gcm.feature/pom.xml b/features/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.gcm.feature/pom.xml
new file mode 100644
index 0000000000..139f1c2eef
--- /dev/null
+++ b/features/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.gcm.feature/pom.xml
@@ -0,0 +1,106 @@
+
+
+
+
+
+
+ org.wso2.carbon.devicemgt
+ device-mgt-extensions-feature
+ 1.1.0-SNAPSHOT
+ ../pom.xml
+
+
+ 4.0.0
+ org.wso2.carbon.device.mgt.extensions.push.notification.provider.gcm.feature
+ pom
+ 1.1.0-SNAPSHOT
+ WSO2 Carbon - GCM Based Push Notification Provider Feature
+ http://wso2.org
+ WSO2 Carbon - MQTT Based Push Notification Provider Feature
+
+
+
+ org.wso2.carbon.devicemgt
+ org.wso2.carbon.device.mgt.extensions.push.notification.provider.gcm
+
+
+
+
+
+
+ maven-resources-plugin
+ 2.6
+
+
+ copy-resources
+ generate-resources
+
+ copy-resources
+
+
+ src/main/resources
+
+
+ resources
+
+ build.properties
+ p2.inf
+
+
+
+
+
+
+
+
+ org.wso2.maven
+ carbon-p2-plugin
+ ${carbon.p2.plugin.version}
+
+
+ p2-feature-generation
+ package
+
+ p2-feature-gen
+
+
+ org.wso2.carbon.device.mgt.extensions.push.notification.provider.gcm
+ ../../../features/etc/feature.properties
+
+
+ org.wso2.carbon.p2.category.type:server
+ org.eclipse.equinox.p2.type.group:false
+
+
+
+
+ org.wso2.carbon.devicemgt:org.wso2.carbon.device.mgt.extensions.push.notification.provider.gcm:${carbon.device.mgt.version}
+
+
+
+ org.wso2.carbon.core.server:${carbon.kernel.version}
+ org.wso2.carbon.device.mgt.server:${carbon.device.mgt.version}
+
+
+
+
+
+
+
+
diff --git a/features/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.gcm.feature/src/main/resources/build.properties b/features/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.gcm.feature/src/main/resources/build.properties
new file mode 100644
index 0000000000..9c86577d76
--- /dev/null
+++ b/features/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.gcm.feature/src/main/resources/build.properties
@@ -0,0 +1 @@
+custom = true
diff --git a/features/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.gcm.feature/src/main/resources/p2.inf b/features/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.gcm.feature/src/main/resources/p2.inf
new file mode 100644
index 0000000000..7ab37b9d7d
--- /dev/null
+++ b/features/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.gcm.feature/src/main/resources/p2.inf
@@ -0,0 +1 @@
+instructions.configure = \
\ No newline at end of file
diff --git a/features/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.mqtt.feature/pom.xml b/features/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.mqtt.feature/pom.xml
new file mode 100644
index 0000000000..452d0c3feb
--- /dev/null
+++ b/features/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.mqtt.feature/pom.xml
@@ -0,0 +1,106 @@
+
+
+
+
+
+
+ org.wso2.carbon.devicemgt
+ device-mgt-extensions-feature
+ 1.1.0-SNAPSHOT
+ ../pom.xml
+
+
+ 4.0.0
+ org.wso2.carbon.device.mgt.extensions.push.notification.provider.mqtt.feature
+ pom
+ 1.1.0-SNAPSHOT
+ WSO2 Carbon - MQTT Based Push Notification Provider Feature
+ http://wso2.org
+ WSO2 Carbon - MQTT Based Push Notification Provider Feature
+
+
+
+ org.wso2.carbon.devicemgt
+ org.wso2.carbon.device.mgt.extensions.push.notification.provider.mqtt
+
+
+
+
+
+
+ maven-resources-plugin
+ 2.6
+
+
+ copy-resources
+ generate-resources
+
+ copy-resources
+
+
+ src/main/resources
+
+
+ resources
+
+ build.properties
+ p2.inf
+
+
+
+
+
+
+
+
+ org.wso2.maven
+ carbon-p2-plugin
+ ${carbon.p2.plugin.version}
+
+
+ p2-feature-generation
+ package
+
+ p2-feature-gen
+
+
+ org.wso2.carbon.device.mgt.extensions.push.notification.provider.mqtt
+ ../../../features/etc/feature.properties
+
+
+ org.wso2.carbon.p2.category.type:server
+ org.eclipse.equinox.p2.type.group:false
+
+
+
+
+ org.wso2.carbon.devicemgt:org.wso2.carbon.device.mgt.extensions.push.notification.provider.mqtt:${carbon.device.mgt.version}
+
+
+
+ org.wso2.carbon.core.server:${carbon.kernel.version}
+ org.wso2.carbon.device.mgt.server:${carbon.device.mgt.version}
+
+
+
+
+
+
+
+
diff --git a/features/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.mqtt.feature/src/main/resources/build.properties b/features/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.mqtt.feature/src/main/resources/build.properties
new file mode 100644
index 0000000000..9c86577d76
--- /dev/null
+++ b/features/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.mqtt.feature/src/main/resources/build.properties
@@ -0,0 +1 @@
+custom = true
diff --git a/features/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.mqtt.feature/src/main/resources/p2.inf b/features/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.mqtt.feature/src/main/resources/p2.inf
new file mode 100644
index 0000000000..7ab37b9d7d
--- /dev/null
+++ b/features/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.mqtt.feature/src/main/resources/p2.inf
@@ -0,0 +1 @@
+instructions.configure = \
\ No newline at end of file
diff --git a/features/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.xmpp.feature/pom.xml b/features/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.xmpp.feature/pom.xml
new file mode 100644
index 0000000000..dc0811d68e
--- /dev/null
+++ b/features/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.xmpp.feature/pom.xml
@@ -0,0 +1,106 @@
+
+
+
+
+
+
+ org.wso2.carbon.devicemgt
+ device-mgt-extensions-feature
+ 1.1.0-SNAPSHOT
+ ../pom.xml
+
+
+ 4.0.0
+ org.wso2.carbon.device.mgt.extensions.push.notification.provider.xmpp.feature
+ pom
+ 1.1.0-SNAPSHOT
+ WSO2 Carbon - XMPP Based Push Notification Provider Feature
+ http://wso2.org
+ WSO2 Carbon - XMPP Based Push Notification Provider Feature
+
+
+
+ org.wso2.carbon.devicemgt
+ org.wso2.carbon.device.mgt.extensions.push.notification.provider.xmpp
+
+
+
+
+
+
+ maven-resources-plugin
+ 2.6
+
+
+ copy-resources
+ generate-resources
+
+ copy-resources
+
+
+ src/main/resources
+
+
+ resources
+
+ build.properties
+ p2.inf
+
+
+
+
+
+
+
+
+ org.wso2.maven
+ carbon-p2-plugin
+ ${carbon.p2.plugin.version}
+
+
+ p2-feature-generation
+ package
+
+ p2-feature-gen
+
+
+ org.wso2.carbon.device.mgt.extensions.push.notification.provider.xmpp
+ ../../../features/etc/feature.properties
+
+
+ org.wso2.carbon.p2.category.type:server
+ org.eclipse.equinox.p2.type.group:false
+
+
+
+
+ org.wso2.carbon.devicemgt:org.wso2.carbon.device.mgt.extensions.push.notification.provider.xmpp:${carbon.device.mgt.version}
+
+
+
+ org.wso2.carbon.core.server:${carbon.kernel.version}
+ org.wso2.carbon.device.mgt.server:${carbon.device.mgt.version}
+
+
+
+
+
+
+
+
diff --git a/features/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.xmpp.feature/src/main/resources/build.properties b/features/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.xmpp.feature/src/main/resources/build.properties
new file mode 100644
index 0000000000..9c86577d76
--- /dev/null
+++ b/features/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.xmpp.feature/src/main/resources/build.properties
@@ -0,0 +1 @@
+custom = true
diff --git a/features/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.xmpp.feature/src/main/resources/p2.inf b/features/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.xmpp.feature/src/main/resources/p2.inf
new file mode 100644
index 0000000000..7ab37b9d7d
--- /dev/null
+++ b/features/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.xmpp.feature/src/main/resources/p2.inf
@@ -0,0 +1 @@
+instructions.configure = \
\ No newline at end of file
diff --git a/features/device-mgt-extensions/pom.xml b/features/device-mgt-extensions/pom.xml
new file mode 100644
index 0000000000..2631efbebe
--- /dev/null
+++ b/features/device-mgt-extensions/pom.xml
@@ -0,0 +1,41 @@
+
+
+
+
+
+
+ org.wso2.carbon.devicemgt
+ carbon-devicemgt
+ 1.1.0-SNAPSHOT
+ ../../pom.xml
+
+
+ 4.0.0
+ device-mgt-extensions-feature
+ pom
+ WSO2 Carbon - Device Management Extensions Feature
+ http://wso2.org
+
+
+ org.wso2.carbon.device.mgt.extensions.push.notification.provider.gcm.feature
+ org.wso2.carbon.device.mgt.extensions.push.notification.provider.mqtt.feature
+ org.wso2.carbon.device.mgt.extensions.push.notification.provider.xmpp.feature
+
+
+
diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/conf/cdm-config.xml b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/conf/cdm-config.xml
index cd5ae9c577..449736b1bd 100644
--- a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/conf/cdm-config.xml
+++ b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/conf/cdm-config.xml
@@ -25,6 +25,10 @@
+
+ org.wso2.carbon.device.mgt.extensions.push.notification.provider.gcm.GCMBasedPushNotificationProvider
+ org.wso2.carbon.device.mgt.extensions.push.notification.provider.mqtt.MQTTBasedPushNotificationProvider
+
https://localhost:9443
admin
diff --git a/pom.xml b/pom.xml
index 54e1346008..772bcecc45 100644
--- a/pom.xml
+++ b/pom.xml
@@ -17,7 +17,8 @@
~ under the License.
-->
-
+
4.0.0
org.wso2.carbon.devicemgt
@@ -36,12 +37,13 @@
components/device-mgt
+ components/device-mgt-extensions
components/apimgt-extensions
components/policy-mgt
components/certificate-mgt
components/webapp-authenticator-framework
components/identity-extensions
- components/email-sender
+ components/email-sender
features/device-mgt
features/apimgt-extensions
features/policy-mgt
@@ -49,8 +51,9 @@
features/certificate-mgt
features/dynamic-client-registration
features/oauth-extensions
- features/email-sender
+ features/email-sender
features/jwt-client
+ features/device-mgt-extensions
@@ -1472,6 +1475,28 @@
servlet-api
${servlet-api.version}
+
+
+ org.wso2.carbon.analytics-common
+ org.wso2.carbon.event.output.adapter.core
+ ${carbon.analytics.common.version}
+
+
+
+ org.wso2.carbon.devicemgt
+ org.wso2.carbon.device.mgt.extensions.push.notification.provider.gcm
+ ${carbon.device.mgt.version}
+
+
+ org.wso2.carbon.devicemgt
+ org.wso2.carbon.device.mgt.extensions.push.notification.provider.mqtt
+ ${carbon.device.mgt.version}
+
+
+ org.wso2.carbon.devicemgt
+ org.wso2.carbon.device.mgt.extensions.push.notification.provider.xmpp
+ ${carbon.device.mgt.version}
+