From a0d7518cbe536ac1b8d4a8957b6bad17d1e6666b Mon Sep 17 00:00:00 2001 From: ayyoob Date: Thu, 1 Jun 2017 17:19:25 +0530 Subject: [PATCH] Implemented Pull Notification Support --- .../mqtt/MQTTNotificationStrategy.java | 2 +- components/device-mgt-extensions/pom.xml | 1 + .../jaxrs/service/api/DeviceAgentService.java | 36 +++--- .../service/impl/DeviceAgentServiceImpl.java | 11 -- .../notification/NotificationContext.java | 49 ++++++++ .../notification/NotificationPayload.java | 41 +++++++ ...lNotificationExecutionFailedException.java | 45 ++++++++ .../PullNotificationSubscriber.java | 34 ++++++ .../common/spi/DeviceManagementService.java | 3 +- .../DeviceManagementPluginRepository.java | 30 ++--- .../core/config/DeviceManagementConfig.java | 13 ++- .../PullNotificationConfiguration.java | 40 +++++++ .../operation/mgt/OperationManagerImpl.java | 4 +- .../DeviceManagementProviderService.java | 9 ++ .../DeviceManagementProviderServiceImpl.java | 24 ++++ .../mgt/core/TestDeviceManagementService.java | 6 + .../pom.xml | 3 +- .../template/DeviceTypeManagerService.java | 17 +++ .../config/DeviceTypeConfiguration.java | 22 ++++ .../config/PullNotificationSubscriber.java | 106 ++++++++++++++++++ .../PullNotificationSubscriberLoader.java | 43 +++++++ .../src/test/resources/sample.xml | 7 ++ .../modules/business-controllers/device.js | 2 +- .../type-view.hbs | 13 ++- .../pom.xml | 7 ++ .../src/main/resources/conf/cdm-config.xml | 3 + pom.xml | 5 + 27 files changed, 523 insertions(+), 53 deletions(-) create mode 100644 components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/pull/notification/NotificationContext.java create mode 100644 components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/pull/notification/NotificationPayload.java create mode 100644 components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/pull/notification/PullNotificationExecutionFailedException.java create mode 100644 components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/pull/notification/PullNotificationSubscriber.java create mode 100644 components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/config/pull/notification/PullNotificationConfiguration.java create mode 100644 components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/template/config/PullNotificationSubscriber.java create mode 100644 components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/template/pull/notification/PullNotificationSubscriberLoader.java 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 index a2c4c0c3054..e7982f68144 100644 --- 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 @@ -157,7 +157,7 @@ public class MQTTNotificationStrategy implements NotificationStrategy { Map dynamicProperties = new HashMap<>(); String topic = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain(true) + "/" + ctx.getDeviceId().getType() + "/" + ctx.getDeviceId().getId() + "/operation/" - + operation.getType().toString().toLowerCase() + "/" + operation.getCode(); + + operation.getType().toString().toLowerCase() + "/" + operation.getCode() + "/" + operation.getId(); dynamicProperties.put("topic", topic); Object payload; if ("command".equals(operation.getType().toString().toLowerCase())) { diff --git a/components/device-mgt-extensions/pom.xml b/components/device-mgt-extensions/pom.xml index 7a6fc1d0298..44bf0af8a0c 100644 --- a/components/device-mgt-extensions/pom.xml +++ b/components/device-mgt-extensions/pom.xml @@ -38,6 +38,7 @@ org.wso2.carbon.device.mgt.extensions.push.notification.provider.mqtt org.wso2.carbon.device.mgt.extensions.push.notification.provider.xmpp org.wso2.carbon.device.mgt.extensions.device.type.deployer + org.wso2.carbon.device.mgt.extensions.pull.notification diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/DeviceAgentService.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/DeviceAgentService.java index 9f2905fbafe..3f66cd7e517 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/DeviceAgentService.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/DeviceAgentService.java @@ -84,17 +84,23 @@ import javax.ws.rs.core.Response; key = "perm:device:modify", permissions = {"/device-mgt/devices/owning-device/modify"} ), - @Scope( - name = "Getting Device Operation Details", - description = "Getting Device Operation Details", - key = "perm:devices:operations", - permissions = {"/device-mgt/devices/owning-device/view"} - ), @Scope( name = "Disenroll Device", description = "Disenroll a device", key = "perm:device:disenroll", permissions = {"/device-mgt/devices/owning-device/remove"} + ), + @Scope( + name = "Publish Event", + description = "publish device event", + key = "perm:device:publish-event", + permissions = {"/device-mgt/devices/owning-device/event"} + ), + @Scope( + name = "Getting Device Operation Details", + description = "Getting Device Operation Details", + key = "perm:device:operations", + permissions = {"/device-mgt/devices/owning-device/view"} ) } ) @@ -250,18 +256,14 @@ public interface DeviceAgentService { tags = "Device Agent Management", extensions = { @Extension(properties = { - @ExtensionProperty(name = Constants.SCOPE, value = "perm:device:enroll") + @ExtensionProperty(name = Constants.SCOPE, value = "perm:device:publish-event") }) } ) @ApiResponses( value = { - @ApiResponse(code = 201, message = "Created. \n Successfully published the event. Location header " + - "contains URL of newly enrolled device", + @ApiResponse(code = 200, message = "OK. \n Successfully published the event", responseHeaders = { - @ResponseHeader( - name = "Content-Location", - description = "The URL of the added policy."), @ResponseHeader( name = "Content-Type", description = "The content type of the body"), @@ -318,7 +320,7 @@ public interface DeviceAgentService { tags = "Device Agent Management", extensions = { @Extension(properties = { - @ExtensionProperty(name = Constants.SCOPE, value = "perm:devices:operations") + @ExtensionProperty(name = Constants.SCOPE, value = "perm:device:operations") }) } ) @@ -375,7 +377,7 @@ public interface DeviceAgentService { tags = "Device Agent Management", extensions = { @Extension(properties = { - @ExtensionProperty(name = Constants.SCOPE, value = "perm:devices:operations") + @ExtensionProperty(name = Constants.SCOPE, value = "perm:device:operations") }) } ) @@ -432,7 +434,7 @@ public interface DeviceAgentService { tags = "Device Agent Management", extensions = { @Extension(properties = { - @ExtensionProperty(name = Constants.SCOPE, value = "perm:devices:operations") + @ExtensionProperty(name = Constants.SCOPE, value = "perm:device:operations") }) } ) @@ -490,7 +492,7 @@ public interface DeviceAgentService { tags = "Device Agent Management", extensions = { @Extension(properties = { - @ExtensionProperty(name = Constants.SCOPE, value = "perm:devices:operations") + @ExtensionProperty(name = Constants.SCOPE, value = "perm:device:operations") }) } ) @@ -538,6 +540,4 @@ public interface DeviceAgentService { @ApiParam(name = "status", value = "status of the operation.", required = true) @QueryParam("status")Operation.Status status); - - } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/DeviceAgentServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/DeviceAgentServiceImpl.java index 44b55cd53e6..05ff605007f 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/DeviceAgentServiceImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/DeviceAgentServiceImpl.java @@ -19,17 +19,9 @@ package org.wso2.carbon.device.mgt.jaxrs.service.impl; import org.apache.axis2.AxisFault; -import org.apache.axis2.client.Options; -import org.apache.axis2.java.security.SSLProtocolSocketFactory; -import org.apache.axis2.transport.http.HTTPConstants; -import org.apache.commons.codec.binary.Base64; -import org.apache.commons.httpclient.Header; -import org.apache.commons.httpclient.protocol.Protocol; -import org.apache.commons.httpclient.protocol.ProtocolSocketFactory; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.wso2.carbon.context.PrivilegedCarbonContext; -import org.wso2.carbon.core.util.Utils; import org.wso2.carbon.device.mgt.analytics.data.publisher.exception.DataPublisherConfigurationException; import org.wso2.carbon.device.mgt.common.Device; import org.wso2.carbon.device.mgt.common.DeviceIdentifier; @@ -52,12 +44,9 @@ import org.wso2.carbon.device.mgt.jaxrs.util.DeviceMgtAPIUtils; import org.wso2.carbon.event.stream.stub.EventStreamAdminServiceStub; import org.wso2.carbon.event.stream.stub.types.EventStreamAttributeDto; import org.wso2.carbon.event.stream.stub.types.EventStreamDefinitionDto; -import org.wso2.carbon.identity.jwt.client.extension.JWTClient; import org.wso2.carbon.identity.jwt.client.extension.exception.JWTClientException; import org.wso2.carbon.user.api.UserStoreException; -import javax.cache.Cache; -import javax.cache.Caching; import javax.validation.Valid; import javax.ws.rs.DELETE; import javax.ws.rs.GET; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/pull/notification/NotificationContext.java b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/pull/notification/NotificationContext.java new file mode 100644 index 00000000000..b8bc6f7f042 --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/pull/notification/NotificationContext.java @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2017, 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.pull.notification; + +import org.wso2.carbon.device.mgt.common.DeviceIdentifier; + +public class NotificationContext { + + private DeviceIdentifier deviceId; + + private NotificationPayload notificationPayload; + + public NotificationContext(DeviceIdentifier deviceId) { + this.deviceId = deviceId; + } + + public NotificationContext(DeviceIdentifier deviceId, NotificationPayload notificationPayload) { + this.deviceId = deviceId; + this.notificationPayload = notificationPayload; + } + + public DeviceIdentifier getDeviceId() { + return deviceId; + } + + public NotificationPayload getNotificationPayload() { + return notificationPayload; + } + + public void setNotificationPayload(NotificationPayload notificationPayload) { + this.notificationPayload = notificationPayload; + } +} diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/pull/notification/NotificationPayload.java b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/pull/notification/NotificationPayload.java new file mode 100644 index 00000000000..236011d78a9 --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/pull/notification/NotificationPayload.java @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2017, 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.pull.notification; + +public class NotificationPayload { + + int operationId; + private String payload; + + public String getPayload() { + return payload; + } + + public void setPayload(String payload) { + this.payload = payload; + } + + public int getOperationId() { + return operationId; + } + + public void setOperationId(int operationId) { + this.operationId = operationId; + } +} diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/pull/notification/PullNotificationExecutionFailedException.java b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/pull/notification/PullNotificationExecutionFailedException.java new file mode 100644 index 00000000000..ecd3a84ab16 --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/pull/notification/PullNotificationExecutionFailedException.java @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2017, 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.pull.notification; + +public class PullNotificationExecutionFailedException extends Exception { + + private static final long serialVersionUID = -3151279311923070297L; + + public PullNotificationExecutionFailedException(String msg, Exception nestedEx) { + super(msg, nestedEx); + } + + public PullNotificationExecutionFailedException(String message, Throwable cause) { + super(message, cause); + } + + public PullNotificationExecutionFailedException(String msg) { + super(msg); + } + + public PullNotificationExecutionFailedException() { + super(); + } + + public PullNotificationExecutionFailedException(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/pull/notification/PullNotificationSubscriber.java b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/pull/notification/PullNotificationSubscriber.java new file mode 100644 index 00000000000..16134cb8f88 --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/pull/notification/PullNotificationSubscriber.java @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2017, 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.pull.notification; + + +import java.util.Map; + +/** + * This will handle the execution flow when a device sends a payload to IoT Server. + */ +public interface PullNotificationSubscriber { + + void init(Map properties); + + void execute(NotificationContext ctx) throws PullNotificationExecutionFailedException; + + void clean(); +} diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/spi/DeviceManagementService.java b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/spi/DeviceManagementService.java index 7e6f7303372..1f3c134f592 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/spi/DeviceManagementService.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/spi/DeviceManagementService.java @@ -21,6 +21,7 @@ package org.wso2.carbon.device.mgt.common.spi; import org.wso2.carbon.device.mgt.common.*; import org.wso2.carbon.device.mgt.common.app.mgt.ApplicationManager; import org.wso2.carbon.device.mgt.common.policy.mgt.PolicyMonitoringManager; +import org.wso2.carbon.device.mgt.common.pull.notification.PullNotificationSubscriber; import org.wso2.carbon.device.mgt.common.push.notification.PushNotificationConfig; /** @@ -47,6 +48,6 @@ public interface DeviceManagementService { InitialOperationConfig getInitialOperationConfig(); - + PullNotificationSubscriber getPullNotificationSubscriber(); } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/DeviceManagementPluginRepository.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/DeviceManagementPluginRepository.java index cc8083009b2..3d4288e7e33 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/DeviceManagementPluginRepository.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/DeviceManagementPluginRepository.java @@ -22,6 +22,7 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.wso2.carbon.context.PrivilegedCarbonContext; import org.wso2.carbon.device.mgt.common.DeviceManagementException; +import org.wso2.carbon.device.mgt.common.pull.notification.PullNotificationSubscriber; import org.wso2.carbon.device.mgt.core.dto.DeviceManagementServiceHolder; import org.wso2.carbon.device.mgt.core.dto.DeviceTypeServiceIdentifier; import org.wso2.carbon.device.mgt.common.OperationMonitoringTaskConfig; @@ -121,19 +122,22 @@ public class DeviceManagementPluginRepository implements DeviceManagerStartupLis public void removeDeviceManagementProvider(DeviceManagementService provider) throws DeviceManagementException { - String deviceTypeName = provider.getType(); - DeviceTypeServiceIdentifier deviceTypeIdentifier; - ProvisioningConfig provisioningConfig = provider.getProvisioningConfig(); - if (provisioningConfig.isSharedWithAllTenants()) { - deviceTypeIdentifier = new DeviceTypeServiceIdentifier(deviceTypeName); - providers.remove(deviceTypeIdentifier); - } else { - int providerTenantId = DeviceManagerUtil.getTenantId(provisioningConfig.getProviderTenantDomain()); - deviceTypeIdentifier = new DeviceTypeServiceIdentifier(deviceTypeName, providerTenantId); - providers.remove(deviceTypeIdentifier); - } - unregisterPushNotificationStrategy(deviceTypeIdentifier); - unregisterMonitoringTask(provider); + String deviceTypeName = provider.getType(); + DeviceTypeServiceIdentifier deviceTypeIdentifier; + ProvisioningConfig provisioningConfig = provider.getProvisioningConfig(); + if (provisioningConfig.isSharedWithAllTenants()) { + deviceTypeIdentifier = new DeviceTypeServiceIdentifier(deviceTypeName); + } else { + int providerTenantId = DeviceManagerUtil.getTenantId(provisioningConfig.getProviderTenantDomain()); + deviceTypeIdentifier = new DeviceTypeServiceIdentifier(deviceTypeName, providerTenantId); + } + PullNotificationSubscriber pullNotificationSubscriber = provider.getPullNotificationSubscriber(); + if (pullNotificationSubscriber != null) { + pullNotificationSubscriber.clean(); + } + providers.remove(deviceTypeIdentifier); + unregisterPushNotificationStrategy(deviceTypeIdentifier); + unregisterMonitoringTask(provider); } private void unregisterPushNotificationStrategy(DeviceTypeServiceIdentifier deviceTypeIdentifier) { 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 cc9a6256a63..331ac3ea1a5 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 @@ -20,13 +20,12 @@ package org.wso2.carbon.device.mgt.core.config; import org.wso2.carbon.device.mgt.core.config.identity.IdentityConfigurations; import org.wso2.carbon.device.mgt.core.config.pagination.PaginationConfiguration; import org.wso2.carbon.device.mgt.core.config.policy.PolicyConfiguration; +import org.wso2.carbon.device.mgt.core.config.pull.notification.PullNotificationConfiguration; import org.wso2.carbon.device.mgt.core.config.push.notification.PushNotificationConfiguration; import org.wso2.carbon.device.mgt.core.config.task.TaskConfiguration; import javax.xml.bind.annotation.XmlElement; -import javax.xml.bind.annotation.XmlElementWrapper; import javax.xml.bind.annotation.XmlRootElement; -import java.util.List; /** * Represents Device Mgt configuration. @@ -41,6 +40,7 @@ public final class DeviceManagementConfig { private PolicyConfiguration policyConfiguration; private PaginationConfiguration paginationConfiguration; private PushNotificationConfiguration pushNotificationConfiguration; + private PullNotificationConfiguration pullNotificationConfiguration; @XmlElement(name = "ManagementRepository", required = true) @@ -97,5 +97,14 @@ public final class DeviceManagementConfig { public void setPushNotificationConfiguration(PushNotificationConfiguration pushNotificationConfiguration) { this.pushNotificationConfiguration = pushNotificationConfiguration; } + + @XmlElement(name = "PullNotificationConfiguration", required = true) + public PullNotificationConfiguration getPullNotificationConfiguration() { + return pullNotificationConfiguration; + } + + public void setPullNotificationConfiguration(PullNotificationConfiguration pullNotificationConfiguration) { + this.pullNotificationConfiguration = pullNotificationConfiguration; + } } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/config/pull/notification/PullNotificationConfiguration.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/config/pull/notification/PullNotificationConfiguration.java new file mode 100644 index 00000000000..4298987df76 --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/config/pull/notification/PullNotificationConfiguration.java @@ -0,0 +1,40 @@ +/* +* Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. +* +* WSO2 Inc. licenses this file to you under the Apache License, +* Version 2.0 (the "License"); you may not use this file except +* in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, +* software distributed under the License is distributed on an +* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +* KIND, either express or implied. See the License for the +* specific language governing permissions and limitations +* under the License. +*/ +package org.wso2.carbon.device.mgt.core.config.pull.notification; + +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlRootElement; + +/** + * This class is for Pull notification related Configurations + */ +@XmlRootElement(name = "PullNotificationConfiguration") +public class PullNotificationConfiguration { + + private boolean enabled; + + @XmlElement(name = "Enabled", required = true) + public boolean isEnabled() { + return enabled; + } + + public void setEnabled(boolean enabled) { + this.enabled = enabled; + } + +} 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 a8cc3317879..fc89089e489 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 @@ -193,6 +193,8 @@ public class OperationManagerImpl implements OperationManager { if (log.isDebugEnabled()) { log.debug("Sending push notification to " + deviceId + " from add operation method."); } + operation.setId(operationId); + operation.setActivityId(DeviceManagementConstants.OperationAttributes.ACTIVITY + operationId); notificationStrategy.execute(new NotificationContext(deviceId, operation)); operationMappingDAO.updateOperationMapping(operationId, enrolmentId, org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.PushNotificationStatus.COMPLETED); } catch (PushNotificationExecutionFailedException e) { @@ -554,7 +556,7 @@ public class OperationManagerImpl implements OperationManager { Operation.Status.valueOf(operation.getStatus(). toString())); } - if (isUpdated && operation.getOperationResponse() != null) { + if (operation.getOperationResponse() != null) { operationDAO.addOperationResponse(enrolmentId, operationId, operation.getOperationResponse()); } OperationManagementDAOFactory.commitTransaction(); 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 b88a43b2569..19e8bcd8d25 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 @@ -32,6 +32,8 @@ import org.wso2.carbon.device.mgt.common.operation.mgt.Activity; 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.policy.mgt.PolicyMonitoringManager; +import org.wso2.carbon.device.mgt.common.pull.notification.NotificationContext; +import org.wso2.carbon.device.mgt.common.pull.notification.PullNotificationExecutionFailedException; import org.wso2.carbon.device.mgt.common.push.notification.NotificationStrategy; import org.wso2.carbon.device.mgt.common.spi.DeviceManagementService; import org.wso2.carbon.device.mgt.core.dto.DeviceType; @@ -349,4 +351,11 @@ public interface DeviceManagementProviderService { * @throws DeviceManagementException */ List getDeviceTypes() throws DeviceManagementException; + + /** + * This retrieves the device pull notification payload and passes to device type executor. + * @throws PullNotificationExecutionFailedException + */ + void executePullNotification(String deviceType, NotificationContext notificationContext) + throws PullNotificationExecutionFailedException; } 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 22439fafe40..84152f7185e 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 @@ -28,6 +28,9 @@ import org.wso2.carbon.device.mgt.common.DeviceIdentifier; import org.wso2.carbon.device.mgt.common.DeviceManagementException; import org.wso2.carbon.device.mgt.common.DeviceManager; import org.wso2.carbon.device.mgt.common.DeviceNotFoundException; +import org.wso2.carbon.device.mgt.common.pull.notification.NotificationContext; +import org.wso2.carbon.device.mgt.common.pull.notification.PullNotificationExecutionFailedException; +import org.wso2.carbon.device.mgt.common.pull.notification.PullNotificationSubscriber; import org.wso2.carbon.device.mgt.core.dto.DeviceTypeServiceIdentifier; import org.wso2.carbon.device.mgt.common.EnrolmentInfo; import org.wso2.carbon.device.mgt.common.FeatureManager; @@ -2202,4 +2205,25 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv DeviceManagementDAOFactory.closeConnection(); } } + + @Override + public void executePullNotification(String deviceType, NotificationContext notificationContext) + throws PullNotificationExecutionFailedException { + DeviceManagementService dms = + pluginRepository.getDeviceManagementService(deviceType, this.getTenantId()); + if (dms == null) { + String message = "Device type '" + deviceType + "' does not have an associated device management " + + "plugin registered within the framework"; + if (log.isDebugEnabled()) { + log.debug(message); + } + throw new PullNotificationExecutionFailedException(message); + } + PullNotificationSubscriber pullNotificationSubscriber = dms.getPullNotificationSubscriber(); + if (pullNotificationSubscriber == null) { + throw new PullNotificationExecutionFailedException("Pull Notification Subscriber is not configured " + + "for device type" + deviceType); + } + pullNotificationSubscriber.execute(notificationContext); + } } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/TestDeviceManagementService.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/TestDeviceManagementService.java index d425133ce52..c2b469a0f49 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/TestDeviceManagementService.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/TestDeviceManagementService.java @@ -20,6 +20,7 @@ package org.wso2.carbon.device.mgt.core; import org.wso2.carbon.device.mgt.common.*; import org.wso2.carbon.device.mgt.common.app.mgt.ApplicationManager; import org.wso2.carbon.device.mgt.common.policy.mgt.PolicyMonitoringManager; +import org.wso2.carbon.device.mgt.common.pull.notification.PullNotificationSubscriber; import org.wso2.carbon.device.mgt.common.push.notification.PushNotificationConfig; import org.wso2.carbon.device.mgt.common.spi.DeviceManagementService; @@ -77,4 +78,9 @@ public class TestDeviceManagementService implements DeviceManagementService { return null; } + @Override + public PullNotificationSubscriber getPullNotificationSubscriber() { + return null; + } + } 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 c13143625e6..b9807ab6092 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 @@ -109,8 +109,9 @@ org.wso2.carbon.ndatasource.core, org.wso2.carbon.registry.core.service, org.wso2.carbon.utils.dbcreator, - org.wso2.carbon.utils.multitenancy + org.wso2.carbon.utils.multitenancy, + org.wso2.carbon.device.mgt.extensions.pull.notification.* diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/template/DeviceTypeManagerService.java b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/template/DeviceTypeManagerService.java index 0a0bc896ef7..5a3915b925f 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/template/DeviceTypeManagerService.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/template/DeviceTypeManagerService.java @@ -30,6 +30,7 @@ import org.wso2.carbon.device.mgt.common.app.mgt.ApplicationManager; import org.wso2.carbon.device.mgt.common.configuration.mgt.ConfigurationEntry; import org.wso2.carbon.device.mgt.common.configuration.mgt.PlatformConfiguration; import org.wso2.carbon.device.mgt.common.policy.mgt.PolicyMonitoringManager; +import org.wso2.carbon.device.mgt.common.pull.notification.PullNotificationSubscriber; 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.extensions.device.type.template.config.ConfigProperties; @@ -39,6 +40,7 @@ import org.wso2.carbon.device.mgt.extensions.device.type.template.config.Propert import org.wso2.carbon.device.mgt.extensions.device.type.template.config.PushNotificationProvider; import org.wso2.carbon.device.mgt.extensions.device.type.template.config.TaskConfiguration; import org.wso2.carbon.device.mgt.extensions.device.type.template.policy.mgt.DefaultPolicyMonitoringManager; +import org.wso2.carbon.device.mgt.extensions.device.type.template.pull.notification.PullNotificationSubscriberLoader; import java.util.ArrayList; import java.util.HashMap; @@ -61,6 +63,7 @@ public class DeviceTypeManagerService implements DeviceManagementService { private List monitoringOperations; private PolicyMonitoringManager policyMonitoringManager; private InitialOperationConfig initialOperationConfig; + private PullNotificationSubscriber pullNotificationSubscriber; public DeviceTypeManagerService(DeviceTypeConfigIdentifier deviceTypeConfigIdentifier, DeviceTypeConfiguration deviceTypeConfiguration) { @@ -76,6 +79,15 @@ public class DeviceTypeManagerService implements DeviceManagementService { && deviceTypeConfiguration.getPolicyMonitoring().isEnabled()) { this.policyMonitoringManager = new DefaultPolicyMonitoringManager(); } + + if (deviceTypeConfiguration.getPullNotificationExecutor() != null) { + String className = deviceTypeConfiguration.getPullNotificationExecutor().getClassName(); + if (className != null && !className.isEmpty()) { + PullNotificationSubscriberLoader pullNotificationExecutorImpl = new PullNotificationSubscriberLoader(className + , deviceTypeConfiguration.getPullNotificationExecutor().getConfigProperties()); + this.pullNotificationSubscriber = pullNotificationExecutorImpl.getPullNotificationSubscriber(); + } + } } @Override @@ -176,6 +188,11 @@ public class DeviceTypeManagerService implements DeviceManagementService { return initialOperationConfig; } + @Override + public PullNotificationSubscriber getPullNotificationSubscriber() { + return pullNotificationSubscriber; + } + private void setProvisioningConfig(String tenantDomain, DeviceTypeConfiguration deviceTypeConfiguration) { if (deviceTypeConfiguration.getProvisioningConfig() != null) { boolean sharedWithAllTenants = deviceTypeConfiguration.getProvisioningConfig().isSharedWithAllTenants(); diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/template/config/DeviceTypeConfiguration.java b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/template/config/DeviceTypeConfiguration.java index 8661690a1d2..aaecca47266 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/template/config/DeviceTypeConfiguration.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/template/config/DeviceTypeConfiguration.java @@ -61,6 +61,8 @@ public class DeviceTypeConfiguration { protected ProvisioningConfig provisioningConfig; @XmlElement(name = "PushNotificationProvider", required = true) protected PushNotificationProvider pushNotificationProvider; + @XmlElement(name = "PullNotificationSubscriber", required = true) + protected PullNotificationSubscriber pullNotificationSubscriber; @XmlElement(name = "License", required = true) protected License license; @XmlElement(name = "DataSource", required = true) @@ -230,6 +232,26 @@ public class DeviceTypeConfiguration { this.pushNotificationProvider = value; } + /** + * Gets the value of the pullNotificationSubscriber property. + * + * @return possible object is + * {@link PullNotificationSubscriber } + */ + public PullNotificationSubscriber getPullNotificationExecutor() { + return pullNotificationSubscriber; + } + + /** + * Sets the value of the pullNotificationSubscriber property. + * + * @param value allowed object is + * {@link PullNotificationSubscriber } + */ + public void setPullNotificationExecutor(PullNotificationSubscriber value) { + this.pullNotificationSubscriber = value; + } + /** * Gets the value of the license property. * diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/template/config/PullNotificationSubscriber.java b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/template/config/PullNotificationSubscriber.java new file mode 100644 index 00000000000..fbf26b00709 --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/template/config/PullNotificationSubscriber.java @@ -0,0 +1,106 @@ +/* + * Copyright (c) 2017, 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.device.type.template.config; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlAttribute; +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlType; + + +/** + *

Java class for PullNotificationSubscriber complex type. + * + *

The following schema fragment specifies the expected content contained within this class. + * + *

+ * <complexType name="PullNotificationSubscriber">
+ *   <complexContent>
+ *     <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
+ *       <sequence>
+ *         <element name="ConfigProperties" type="{}ConfigProperties"/>
+ *       </sequence>
+ *       <attribute name="type" type="{http://www.w3.org/2001/XMLSchema}string" />
+ *     </restriction>
+ *   </complexContent>
+ * </complexType>
+ * 
+ * + * + */ +@XmlAccessorType(XmlAccessType.FIELD) +@XmlType(name = "PullNotificationSubscriber", propOrder = { + "configProperties" +}) +public class PullNotificationSubscriber { + @XmlElement(name = "ConfigProperties", required = true) + protected ConfigProperties configProperties; + @XmlAttribute(name = "className") + protected String className; + + /** + * Gets the value of the configProperties property. + * + * @return + * possible object is + * {@link ConfigProperties } + * + */ + public ConfigProperties getConfigProperties() { + return configProperties; + } + + /** + * Sets the value of the configProperties property. + * + * @param value + * allowed object is + * {@link ConfigProperties } + * + */ + public void setConfigProperties(ConfigProperties value) { + this.configProperties = value; + } + + /** + * Gets the value of the type property. + * + * @return + * possible object is + * {@link String } + * + */ + public String getClassName() { + return className; + } + + /** + * Sets the value of the type property. + * + * @param value + * allowed object is + * {@link String } + * + */ + public void setClassName(String value) { + this.className = className; + } + +} diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/template/pull/notification/PullNotificationSubscriberLoader.java b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/template/pull/notification/PullNotificationSubscriberLoader.java new file mode 100644 index 00000000000..bdbe2d7d494 --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/template/pull/notification/PullNotificationSubscriberLoader.java @@ -0,0 +1,43 @@ +package org.wso2.carbon.device.mgt.extensions.device.type.template.pull.notification; + +import org.wso2.carbon.device.mgt.common.pull.notification.PullNotificationSubscriber; +import org.wso2.carbon.device.mgt.extensions.device.type.template.config.ConfigProperties; +import org.wso2.carbon.device.mgt.extensions.device.type.template.config.Property; +import org.wso2.carbon.device.mgt.extensions.device.type.template.exception.DeviceTypeDeployerPayloadException; + +import java.util.HashMap; +import java.util.Map; + +/** + * This creates an instance of the pull notification executor strategy with the given class name. + * makes sure the class name starts with the package prefix org.wso2.carbon.device.mgt.pull.notification.* + */ +public class PullNotificationSubscriberLoader { + + private PullNotificationSubscriber pullNotificationSubscriber; + + public PullNotificationSubscriberLoader(String className, ConfigProperties configProperties) { + try { + Class pullNotificationExecutorClass + = Class.forName(className).asSubclass(PullNotificationSubscriber.class); + Map properties = new HashMap<>(); + if (configProperties != null) { + for (Property property : configProperties.getProperty()) { + properties.put(property.getName(), property.getValue()); + } + } + pullNotificationSubscriber = pullNotificationExecutorClass.newInstance(); + pullNotificationSubscriber.init(properties); + } catch (ClassNotFoundException e) { + throw new DeviceTypeDeployerPayloadException("Unable to find the class pull notification executor: " + className, e); + } catch (InstantiationException e) { + throw new DeviceTypeDeployerPayloadException("Unable to create an instance of :" + className, e); + } catch (IllegalAccessException e) { + throw new DeviceTypeDeployerPayloadException("Access of the instance in not allowed.", e); + } + } + + public PullNotificationSubscriber getPullNotificationSubscriber() { + return pullNotificationSubscriber; + } +} diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/test/resources/sample.xml b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/test/resources/sample.xml index 36464ca906b..5fa3001f38d 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/test/resources/sample.xml +++ b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/test/resources/sample.xml @@ -92,6 +92,13 @@ + + + sample.mqtt.adapter + admin + + + diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/business-controllers/device.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/business-controllers/device.js index 4067d09e944..7d002915059 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/business-controllers/device.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/business-controllers/device.js @@ -387,7 +387,7 @@ deviceModule = function () { var jwtClient = JWTClientManagerService.getJWTClient(); // returning access token by JWT grant type var deviceScope = "device_" + type.replace(" ", "") + "_" + deviceId + " perm:device:enroll " + - "perm:device:disenroll perm:device:modify perm:devices:operations"; + "perm:device:disenroll perm:device:modify perm:device:operations perm:device:publish-event"; var tokenInfo = jwtClient.getAccessToken(config.clientId, config.clientSecret, userName, deviceScope); config.accessToken = tokenInfo.getAccessToken(); diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.default.device.type.type-view/type-view.hbs b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.default.device.type.type-view/type-view.hbs index a152f164272..fea3ef63c3e 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.default.device.type.type-view/type-view.hbs +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.default.device.type.type-view/type-view.hbs @@ -117,7 +117,7 @@ -d '{ "applicationName":"testme", "isAllowedToAllDomains":false, "tags":["device_agent"]}'
  • Generate Token

    - curl -k -d "grant_type=password&username=%username%&password=%password%&scope=perm:device:enroll perm:device:disenroll perm:device:modify perm:devices:operations" + curl -k -d "grant_type=password&username=%username%&password=%password%&scope=perm:device:enroll perm:device:disenroll perm:device:modify perm:device:operations perm:device:publish-event" -H "Authorization: Basic Base64(client_id:client_secret)" -H "Content-Type: application/x-www-form-urlencoded" {{httpsGateway}}/token
  • @@ -242,16 +242,21 @@ MQTT - {{mqttGateway}} MQTT Topic : {{tenantDomain}}/{{deviceType}}/<device_id>/operation/#
    + Operation Response: + {{tenantDomain}}/{{deviceType}}/<device_id>/update/operation +
    + Payload : {operationId:1, payload:"example"} +
    Topic Structure:
    • - {{tenantDomain}}/{{deviceType}}/<device_id>/operation/command/<feature_code> + {{tenantDomain}}/{{deviceType}}/<device_id>/operation/command/<feature_code><operation_id>
    • - {{tenantDomain}}/{{deviceType}}/<device_id>/operation/config/<feature_code> + {{tenantDomain}}/{{deviceType}}/<device_id>/operation/config/<feature_code><operation_id>
    • - {{tenantDomain}}/{{deviceType}}/<device_id>/operation/profile/<feature_code> + {{tenantDomain}}/{{deviceType}}/<device_id>/operation/profile/<feature_code><operation_id>
    • {{tenantDomain}}/{{deviceType}}/<device_id>/operation/policy/policy_bundle diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/pom.xml b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/pom.xml index 9649ddf6bbb..6916b3c5cba 100644 --- a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/pom.xml +++ b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/pom.xml @@ -57,6 +57,10 @@ org.wso2.orbit.org.apache.pdfbox pdfbox + + org.wso2.carbon.devicemgt + org.wso2.carbon.device.mgt.extensions.pull.notification + org.wso2.carbon.registry org.wso2.carbon.registry.indexing @@ -141,6 +145,9 @@ org.wso2.carbon.devicemgt:org.wso2.carbon.device.mgt.url.printer:${carbon.device.mgt.version} + + org.wso2.carbon.devicemgt:org.wso2.carbon.device.mgt.extensions.pull.notification:${carbon.device.mgt.version} + 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 99d5473b46b..186f068de26 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 @@ -37,6 +37,9 @@ org.wso2.carbon.device.mgt.extensions.push.notification.provider.xmpp.XMPPBasedPushNotificationProvider + + true + https://localhost:9443 admin diff --git a/pom.xml b/pom.xml index 8cc0ae12b6f..7e9fac9c917 100644 --- a/pom.xml +++ b/pom.xml @@ -1451,6 +1451,11 @@ org.wso2.carbon.device.mgt.extensions.push.notification.provider.xmpp ${carbon.device.mgt.version} + + org.wso2.carbon.devicemgt + org.wso2.carbon.device.mgt.extensions.pull.notification + ${carbon.device.mgt.version} + org.wso2.orbit.com.fasterxml.jackson.core jackson-annotations