diff --git a/components/iot-plugins/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.agent/app/src/main/java/org/wso2/carbon/iot/android/sense/util/dto/AndroidSenseManagerService.java b/components/iot-plugins/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.agent/app/src/main/java/org/wso2/carbon/iot/android/sense/util/dto/AndroidSenseManagerService.java
index 86f58a142c..6bdd63c135 100755
--- a/components/iot-plugins/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.agent/app/src/main/java/org/wso2/carbon/iot/android/sense/util/dto/AndroidSenseManagerService.java
+++ b/components/iot-plugins/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.agent/app/src/main/java/org/wso2/carbon/iot/android/sense/util/dto/AndroidSenseManagerService.java
@@ -24,7 +24,7 @@ import javax.ws.rs.QueryParam;
*/
public interface AndroidSenseManagerService {
- @Path("/enrollment/devices/{device_id}")
+ @Path("/device/{device_id}/register")
@POST
AndroidConfiguration register(@PathParam("device_id") String deviceId, @QueryParam("deviceName") String deviceName);
}
diff --git a/components/iot-plugins/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.api/src/main/java/org/wso2/carbon/device/mgt/iot/androidsense/service/impl/AndroidSenseManagerService.java b/components/iot-plugins/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.api/src/main/java/org/wso2/carbon/device/mgt/iot/androidsense/service/impl/AndroidSenseManagerService.java
deleted file mode 100644
index 68e48074ac..0000000000
--- a/components/iot-plugins/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.api/src/main/java/org/wso2/carbon/device/mgt/iot/androidsense/service/impl/AndroidSenseManagerService.java
+++ /dev/null
@@ -1,56 +0,0 @@
-/*
- * 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.iot.androidsense.service.impl;
-
-import org.wso2.carbon.apimgt.annotations.api.API;
-import org.wso2.carbon.device.mgt.extensions.feature.mgt.annotations.DeviceType;
-import javax.ws.rs.Consumes;
-import javax.ws.rs.DELETE;
-import javax.ws.rs.GET;
-import javax.ws.rs.POST;
-import javax.ws.rs.PUT;
-import javax.ws.rs.Path;
-import javax.ws.rs.PathParam;
-import javax.ws.rs.Produces;
-import javax.ws.rs.QueryParam;
-import javax.ws.rs.core.Response;
-@Path("enrollment")
-@API(name = "android_sense_mgt", version = "1.0.0", context = "/android_sense_mgt", tags = {"android_sense"})
-public interface AndroidSenseManagerService {
-
- @Path("/devices/{device_id}")
- @POST
- Response register(@PathParam("device_id") String deviceId, @QueryParam("deviceName") String deviceName);
-
- @Path("/devices/{device_id}")
- @DELETE
- Response removeDevice(@PathParam("device_id") String deviceId);
-
- @Path("/devices/{device_id}")
- @PUT
- Response updateDevice(@PathParam("device_id") String deviceId, @QueryParam("name") String name);
-
- @Path("/devices/{device_id}")
- @GET
- @Consumes("application/json")
- @Produces("application/json")
- Response getDevice(@PathParam("device_id") String deviceId);
-
-}
-
diff --git a/components/iot-plugins/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.api/src/main/java/org/wso2/carbon/device/mgt/iot/androidsense/service/impl/AndroidSenseManagerServiceImpl.java b/components/iot-plugins/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.api/src/main/java/org/wso2/carbon/device/mgt/iot/androidsense/service/impl/AndroidSenseManagerServiceImpl.java
deleted file mode 100644
index e5a794f509..0000000000
--- a/components/iot-plugins/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.api/src/main/java/org/wso2/carbon/device/mgt/iot/androidsense/service/impl/AndroidSenseManagerServiceImpl.java
+++ /dev/null
@@ -1,181 +0,0 @@
-/*
- * 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.iot.androidsense.service.impl;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.wso2.carbon.device.mgt.common.Device;
-import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
-import org.wso2.carbon.device.mgt.common.DeviceManagementException;
-import org.wso2.carbon.device.mgt.common.EnrolmentInfo;
-import org.wso2.carbon.device.mgt.common.authorization.DeviceAccessAuthorizationException;
-import org.wso2.carbon.device.mgt.common.group.mgt.DeviceGroupConstants;
-import org.wso2.carbon.device.mgt.iot.androidsense.plugin.mqtt.MqttConfig;
-import org.wso2.carbon.device.mgt.iot.androidsense.service.impl.util.APIUtil;
-import org.wso2.carbon.device.mgt.iot.androidsense.plugin.constants.AndroidSenseConstants;
-import org.wso2.carbon.device.mgt.iot.androidsense.service.impl.util.AndroidConfiguration;
-import org.wso2.carbon.device.mgt.iot.androidsense.service.impl.util.Constants;
-import org.wso2.carbon.device.mgt.iot.util.Utils;
-
-import javax.ws.rs.Consumes;
-import javax.ws.rs.DELETE;
-import javax.ws.rs.GET;
-import javax.ws.rs.POST;
-import javax.ws.rs.PUT;
-import javax.ws.rs.Path;
-import javax.ws.rs.PathParam;
-import javax.ws.rs.Produces;
-import javax.ws.rs.QueryParam;
-import javax.ws.rs.core.Response;
-import java.util.Date;
-
-@Path("enrollment")
-public class AndroidSenseManagerServiceImpl implements AndroidSenseManagerService {
-
- private static Log log = LogFactory.getLog(AndroidSenseManagerServiceImpl.class);
-
- @Path("/devices/{device_id}")
- @POST
- public Response register(@PathParam("device_id") String deviceId, @QueryParam("deviceName") String deviceName) {
- DeviceIdentifier deviceIdentifier = new DeviceIdentifier();
- deviceIdentifier.setId(deviceId);
- deviceIdentifier.setType(AndroidSenseConstants.DEVICE_TYPE);
- try {
- if (APIUtil.getDeviceManagementService().isEnrolled(deviceIdentifier)) {
- AndroidConfiguration androidConfiguration = new AndroidConfiguration();
- androidConfiguration.setTenantDomain(APIUtil.getAuthenticatedUserTenantDomain());
- String mqttEndpoint = MqttConfig.getInstance().getBrokerEndpoint();
- if (mqttEndpoint.contains(Constants.LOCALHOST)) {
- mqttEndpoint = mqttEndpoint.replace(Constants.LOCALHOST, Utils.getHostName());
- }
- androidConfiguration.setMqttEndpoint(mqttEndpoint);
- return Response.status(Response.Status.ACCEPTED.getStatusCode()).entity(androidConfiguration.toString())
- .build();
- }
- Device device = new Device();
- device.setDeviceIdentifier(deviceId);
- EnrolmentInfo enrolmentInfo = new EnrolmentInfo();
- enrolmentInfo.setDateOfEnrolment(new Date().getTime());
- enrolmentInfo.setDateOfLastUpdate(new Date().getTime());
- enrolmentInfo.setStatus(EnrolmentInfo.Status.ACTIVE);
- device.setName(deviceName);
- device.setType(AndroidSenseConstants.DEVICE_TYPE);
- enrolmentInfo.setOwner(APIUtil.getAuthenticatedUser());
- enrolmentInfo.setOwnership(EnrolmentInfo.OwnerShip.BYOD);
- device.setEnrolmentInfo(enrolmentInfo);
- boolean added = APIUtil.getDeviceManagementService().enrollDevice(device);
- if (added) {
- AndroidConfiguration androidConfiguration = new AndroidConfiguration();
- androidConfiguration.setTenantDomain(APIUtil.getAuthenticatedUserTenantDomain());
- String mqttEndpoint = MqttConfig.getInstance().getBrokerEndpoint();
- if (mqttEndpoint.contains(Constants.LOCALHOST)) {
- mqttEndpoint = mqttEndpoint.replace(Constants.LOCALHOST, Utils.getHostName());
- }
- androidConfiguration.setMqttEndpoint(mqttEndpoint);
- return Response.ok(androidConfiguration.toString()).build();
- } else {
- return Response.status(Response.Status.NOT_ACCEPTABLE.getStatusCode()).entity(false).build();
- }
- } catch (DeviceManagementException e) {
- log.error(e.getErrorMessage(), e);
- return Response.status(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()).entity(false).build();
- }
- }
-
- @Path("/devices/{device_id}")
- @DELETE
- public Response removeDevice(@PathParam("device_id") String deviceId) {
- DeviceIdentifier deviceIdentifier = new DeviceIdentifier();
- deviceIdentifier.setId(deviceId);
- deviceIdentifier.setType(AndroidSenseConstants.DEVICE_TYPE);
- try {
- if (!APIUtil.getDeviceAccessAuthorizationService().isUserAuthorized(deviceIdentifier, DeviceGroupConstants.
- Permissions.DEFAULT_ADMIN_PERMISSIONS)) {
- return Response.status(Response.Status.UNAUTHORIZED.getStatusCode()).build();
- }
- boolean removed = APIUtil.getDeviceManagementService().disenrollDevice(deviceIdentifier);
- if (removed) {
- return Response.ok().build();
- } else {
- return Response.status(Response.Status.NOT_ACCEPTABLE.getStatusCode()).build();
- }
- } catch (DeviceManagementException e) {
- log.error(e.getErrorMessage(), e);
- return Response.status(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()).build();
- } catch (DeviceAccessAuthorizationException e) {
- log.error(e.getErrorMessage(), e);
- return Response.status(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()).build();
- }
- }
-
- @Path("/devices/{device_id}")
- @PUT
- public Response updateDevice(@PathParam("device_id") String deviceId, @QueryParam("name") String name) {
- DeviceIdentifier deviceIdentifier = new DeviceIdentifier();
- deviceIdentifier.setId(deviceId);
- deviceIdentifier.setType(AndroidSenseConstants.DEVICE_TYPE);
- try {
- if (!APIUtil.getDeviceAccessAuthorizationService().isUserAuthorized(deviceIdentifier, DeviceGroupConstants.
- Permissions.DEFAULT_ADMIN_PERMISSIONS)) {
- return Response.status(Response.Status.UNAUTHORIZED.getStatusCode()).build();
- }
- Device device = APIUtil.getDeviceManagementService().getDevice(deviceIdentifier);
- device.setDeviceIdentifier(deviceId);
- device.getEnrolmentInfo().setDateOfLastUpdate(new Date().getTime());
- device.setName(name);
- device.setType(AndroidSenseConstants.DEVICE_TYPE);
- boolean updated = APIUtil.getDeviceManagementService().modifyEnrollment(device);
- if (updated) {
- return Response.ok().build();
- } else {
- return Response.status(Response.Status.NOT_ACCEPTABLE.getStatusCode()).build();
- }
- } catch (DeviceManagementException e) {
- log.error(e.getErrorMessage(), e);
- return Response.status(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()).build();
- } catch (DeviceAccessAuthorizationException e) {
- log.error(e.getErrorMessage(), e);
- return Response.status(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()).build();
- }
- }
-
- @Path("/devices/{device_id}")
- @GET
- @Consumes("application/json")
- @Produces("application/json")
- public Response getDevice(@PathParam("device_id") String deviceId) {
- DeviceIdentifier deviceIdentifier = new DeviceIdentifier();
- deviceIdentifier.setId(deviceId);
- deviceIdentifier.setType(AndroidSenseConstants.DEVICE_TYPE);
- try {
- if (!APIUtil.getDeviceAccessAuthorizationService().isUserAuthorized(deviceIdentifier)) {
- return Response.status(Response.Status.UNAUTHORIZED.getStatusCode()).build();
- }
- Device device = APIUtil.getDeviceManagementService().getDevice(deviceIdentifier);
- return Response.ok().entity(device).build();
- } catch (DeviceManagementException e) {
- log.error(e.getErrorMessage(), e);
- return Response.status(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()).build();
- } catch (DeviceAccessAuthorizationException e) {
- log.error(e.getErrorMessage(), e);
- return Response.status(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()).build();
- }
- }
-
-}
diff --git a/components/iot-plugins/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.api/src/main/java/org/wso2/carbon/device/mgt/iot/androidsense/service/impl/AndroidSenseControllerService.java b/components/iot-plugins/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.api/src/main/java/org/wso2/carbon/device/mgt/iot/androidsense/service/impl/AndroidSenseService.java
similarity index 77%
rename from components/iot-plugins/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.api/src/main/java/org/wso2/carbon/device/mgt/iot/androidsense/service/impl/AndroidSenseControllerService.java
rename to components/iot-plugins/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.api/src/main/java/org/wso2/carbon/device/mgt/iot/androidsense/service/impl/AndroidSenseService.java
index 2b11cc8631..8ba820d180 100644
--- a/components/iot-plugins/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.api/src/main/java/org/wso2/carbon/device/mgt/iot/androidsense/service/impl/AndroidSenseControllerService.java
+++ b/components/iot-plugins/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.api/src/main/java/org/wso2/carbon/device/mgt/iot/androidsense/service/impl/AndroidSenseService.java
@@ -19,6 +19,7 @@
package org.wso2.carbon.device.mgt.iot.androidsense.service.impl;
import org.wso2.carbon.apimgt.annotations.api.API;
+import org.wso2.carbon.apimgt.annotations.api.Permission;
import org.wso2.carbon.device.mgt.extensions.feature.mgt.annotations.DeviceType;
import org.wso2.carbon.device.mgt.extensions.feature.mgt.annotations.Feature;
import javax.ws.rs.Consumes;
@@ -33,7 +34,7 @@ import javax.ws.rs.core.Response;
@DeviceType(value = "android_sense")
@API(name = "android_sense", version = "1.0.0", context = "/android_sense", tags = {"android_sense"})
-public interface AndroidSenseControllerService {
+public interface AndroidSenseService {
/**
* End point to send the key words to the device
@@ -44,6 +45,7 @@ public interface AndroidSenseControllerService {
@Path("device/{deviceId}/words")
@POST
@Feature(code = "keywords", name = "Add Keywords", description = "Send keywords to the device")
+ @Permission(scope = "android_sense_user", permissions = {"/permission/admin/device-mgt/user/operations"})
Response sendKeyWords(@PathParam("deviceId") String deviceId, @QueryParam("keywords") String keywords);
/**
@@ -55,11 +57,13 @@ public interface AndroidSenseControllerService {
@Path("device/{deviceId}/words/threshold")
@POST
@Feature(code = "threshold", name = "Add a Threshold", description = "Set a threshold for word in the device")
+ @Permission(scope = "android_sense_user", permissions = {"/permission/admin/device-mgt/user/operations"})
Response sendThreshold(@PathParam("deviceId") String deviceId, @QueryParam("threshold") String threshold);
@Path("device/{deviceId}/words")
@DELETE
@Feature(code = "remove", name = "Remove Keywords", description = "Remove the keywords")
+ @Permission(scope = "android_sense_user", permissions = {"/permission/admin/device-mgt/user/operations"})
Response removeKeyWords(@PathParam("deviceId") String deviceId, @QueryParam("words") String words);
/**
@@ -68,9 +72,18 @@ public interface AndroidSenseControllerService {
@Path("stats/{deviceId}/sensors/{sensorName}")
@GET
@Consumes("application/json")
+ @Permission(scope = "android_sense_user", permissions = {"/permission/admin/device-mgt/user/stats"})
@Produces("application/json")
Response getAndroidSenseDeviceStats(@PathParam("deviceId") String deviceId, @PathParam("sensorName") String sensor,
@QueryParam("from") long from, @QueryParam("to") long to);
+ /**
+ * Enroll devices.
+ */
+ @Path("device/{device_id}/register")
+ @POST
+ @Permission(scope = "android_sense_user", permissions = {"/permission/admin/device-mgt/user/devices"})
+ Response register(@PathParam("device_id") String deviceId, @QueryParam("deviceName") String deviceName);
+
}
diff --git a/components/iot-plugins/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.api/src/main/java/org/wso2/carbon/device/mgt/iot/androidsense/service/impl/AndroidSenseControllerServiceImpl.java b/components/iot-plugins/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.api/src/main/java/org/wso2/carbon/device/mgt/iot/androidsense/service/impl/AndroidSenseServiceImpl.java
similarity index 73%
rename from components/iot-plugins/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.api/src/main/java/org/wso2/carbon/device/mgt/iot/androidsense/service/impl/AndroidSenseControllerServiceImpl.java
rename to components/iot-plugins/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.api/src/main/java/org/wso2/carbon/device/mgt/iot/androidsense/service/impl/AndroidSenseServiceImpl.java
index b3e4488353..15ec090c19 100644
--- a/components/iot-plugins/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.api/src/main/java/org/wso2/carbon/device/mgt/iot/androidsense/service/impl/AndroidSenseControllerServiceImpl.java
+++ b/components/iot-plugins/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.api/src/main/java/org/wso2/carbon/device/mgt/iot/androidsense/service/impl/AndroidSenseServiceImpl.java
@@ -23,12 +23,19 @@ import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.analytics.dataservice.commons.SORT;
import org.wso2.carbon.analytics.dataservice.commons.SortByField;
import org.wso2.carbon.analytics.datasource.commons.exception.AnalyticsException;
+import org.wso2.carbon.device.mgt.common.Device;
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
+import org.wso2.carbon.device.mgt.common.DeviceManagementException;
+import org.wso2.carbon.device.mgt.common.EnrolmentInfo;
import org.wso2.carbon.device.mgt.common.authorization.DeviceAccessAuthorizationException;
import org.wso2.carbon.device.mgt.common.group.mgt.DeviceGroupConstants;
+import org.wso2.carbon.device.mgt.iot.androidsense.plugin.mqtt.MqttConfig;
import org.wso2.carbon.device.mgt.iot.androidsense.service.impl.util.APIUtil;
+import org.wso2.carbon.device.mgt.iot.androidsense.service.impl.util.AndroidConfiguration;
+import org.wso2.carbon.device.mgt.iot.androidsense.service.impl.util.Constants;
import org.wso2.carbon.device.mgt.iot.androidsense.service.impl.util.SensorRecord;
import org.wso2.carbon.device.mgt.iot.androidsense.plugin.constants.AndroidSenseConstants;
+import org.wso2.carbon.device.mgt.iot.util.Utils;
import javax.ws.rs.Consumes;
import javax.ws.rs.DELETE;
@@ -40,6 +47,7 @@ import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.Response;
import java.util.ArrayList;
+import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -47,9 +55,9 @@ import java.util.Map;
/**
* The api for
*/
-public class AndroidSenseControllerServiceImpl implements AndroidSenseControllerService {
+public class AndroidSenseServiceImpl implements AndroidSenseService {
- private static Log log = LogFactory.getLog(AndroidSenseControllerServiceImpl.class);
+ private static Log log = LogFactory.getLog(AndroidSenseServiceImpl.class);
@Path("device/{deviceId}/words")
@POST
@@ -198,4 +206,52 @@ public class AndroidSenseControllerServiceImpl implements AndroidSenseController
return sensorEventTableName;
}
+ @Path("device/{device_id}/register")
+ @POST
+ public Response register(@PathParam("device_id") String deviceId, @QueryParam("deviceName") String deviceName) {
+ DeviceIdentifier deviceIdentifier = new DeviceIdentifier();
+ deviceIdentifier.setId(deviceId);
+ deviceIdentifier.setType(AndroidSenseConstants.DEVICE_TYPE);
+ try {
+ if (APIUtil.getDeviceManagementService().isEnrolled(deviceIdentifier)) {
+ AndroidConfiguration androidConfiguration = new AndroidConfiguration();
+ androidConfiguration.setTenantDomain(APIUtil.getAuthenticatedUserTenantDomain());
+ String mqttEndpoint = MqttConfig.getInstance().getBrokerEndpoint();
+ if (mqttEndpoint.contains(Constants.LOCALHOST)) {
+ mqttEndpoint = mqttEndpoint.replace(Constants.LOCALHOST, Utils.getServerUrl());
+ }
+ androidConfiguration.setMqttEndpoint(mqttEndpoint);
+ return Response.status(Response.Status.ACCEPTED.getStatusCode()).entity(androidConfiguration.toString())
+ .build();
+ }
+ Device device = new Device();
+ device.setDeviceIdentifier(deviceId);
+ EnrolmentInfo enrolmentInfo = new EnrolmentInfo();
+ enrolmentInfo.setDateOfEnrolment(new Date().getTime());
+ enrolmentInfo.setDateOfLastUpdate(new Date().getTime());
+ enrolmentInfo.setStatus(EnrolmentInfo.Status.ACTIVE);
+ device.setName(deviceName);
+ device.setType(AndroidSenseConstants.DEVICE_TYPE);
+ enrolmentInfo.setOwner(APIUtil.getAuthenticatedUser());
+ enrolmentInfo.setOwnership(EnrolmentInfo.OwnerShip.BYOD);
+ device.setEnrolmentInfo(enrolmentInfo);
+ boolean added = APIUtil.getDeviceManagementService().enrollDevice(device);
+ if (added) {
+ AndroidConfiguration androidConfiguration = new AndroidConfiguration();
+ androidConfiguration.setTenantDomain(APIUtil.getAuthenticatedUserTenantDomain());
+ String mqttEndpoint = MqttConfig.getInstance().getBrokerEndpoint();
+ if (mqttEndpoint.contains(Constants.LOCALHOST)) {
+ mqttEndpoint = mqttEndpoint.replace(Constants.LOCALHOST, Utils.getServerUrl());
+ }
+ androidConfiguration.setMqttEndpoint(mqttEndpoint);
+ return Response.ok(androidConfiguration.toString()).build();
+ } else {
+ return Response.status(Response.Status.NOT_ACCEPTABLE.getStatusCode()).entity(false).build();
+ }
+ } catch (DeviceManagementException e) {
+ log.error(e.getErrorMessage(), e);
+ return Response.status(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()).entity(false).build();
+ }
+ }
+
}
diff --git a/components/iot-plugins/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.api/src/main/webapp/META-INF/permissions.xml b/components/iot-plugins/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.api/src/main/webapp/META-INF/permissions.xml
index 26e63ecaf5..d4d5b3b7e6 100644
--- a/components/iot-plugins/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.api/src/main/webapp/META-INF/permissions.xml
+++ b/components/iot-plugins/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.api/src/main/webapp/META-INF/permissions.xml
@@ -56,33 +56,12 @@
GET
android_sense_device
-
- Get device
- /device-mgt/user/devices/list
- /enrollment/devices/*
- GET
- android_sense_user
-
Add device
/device-mgt/user/devices
- /enrollment/devices/*
+ /device/*/register
POST
android_sense_user
-
- Remove device
- /device-mgt/user/devices/remove
- /enrollment/devices/*
- DELETE
- android_sense_user
-
-
- Update device
- /device-mgt/user/devices/update
- /enrollment/devices/*
- PUT
- android_sense_user
-
diff --git a/components/iot-plugins/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.api/src/main/webapp/WEB-INF/cxf-servlet.xml b/components/iot-plugins/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.api/src/main/webapp/WEB-INF/cxf-servlet.xml
index 2eee6325ff..c82a0fc58c 100644
--- a/components/iot-plugins/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.api/src/main/webapp/WEB-INF/cxf-servlet.xml
+++ b/components/iot-plugins/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.api/src/main/webapp/WEB-INF/cxf-servlet.xml
@@ -24,11 +24,9 @@
-
+
-
diff --git a/components/iot-plugins/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.android_sense.type-view/public/asset/androidsense.apk b/components/iot-plugins/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.android_sense.type-view/public/asset/androidsense.apk
index fb49b9ceeb..37a03c22bb 100644
Binary files a/components/iot-plugins/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.android_sense.type-view/public/asset/androidsense.apk and b/components/iot-plugins/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.android_sense.type-view/public/asset/androidsense.apk differ
diff --git a/components/iot-plugins/arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.api/src/main/java/org/wso2/carbon/device/mgt/iot/arduino/service/impl/ArduinoControllerServiceImpl.java b/components/iot-plugins/arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.api/src/main/java/org/wso2/carbon/device/mgt/iot/arduino/service/impl/ArduinoControllerServiceImpl.java
deleted file mode 100644
index eecf8aca60..0000000000
--- a/components/iot-plugins/arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.api/src/main/java/org/wso2/carbon/device/mgt/iot/arduino/service/impl/ArduinoControllerServiceImpl.java
+++ /dev/null
@@ -1,150 +0,0 @@
-/*
- * 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.iot.arduino.service.impl;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.wso2.carbon.analytics.dataservice.commons.SORT;
-import org.wso2.carbon.analytics.dataservice.commons.SortByField;
-import org.wso2.carbon.analytics.datasource.commons.exception.AnalyticsException;
-import org.wso2.carbon.context.PrivilegedCarbonContext;
-import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
-import org.wso2.carbon.device.mgt.common.authorization.DeviceAccessAuthorizationException;
-import org.wso2.carbon.device.mgt.common.group.mgt.DeviceGroupConstants;
-import org.wso2.carbon.device.mgt.iot.arduino.service.impl.dto.SensorRecord;
-import org.wso2.carbon.device.mgt.iot.arduino.service.impl.util.APIUtil;
-import org.wso2.carbon.device.mgt.iot.arduino.plugin.constants.ArduinoConstants;
-import javax.ws.rs.Consumes;
-import javax.ws.rs.GET;
-import javax.ws.rs.POST;
-import javax.ws.rs.Path;
-import javax.ws.rs.PathParam;
-import javax.ws.rs.Produces;
-import javax.ws.rs.QueryParam;
-import javax.ws.rs.core.Response;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Map;
-import java.util.NoSuchElementException;
-public class ArduinoControllerServiceImpl implements ArduinoControllerService {
-
- private static Log log = LogFactory.getLog(ArduinoControllerServiceImpl.class);
- private static Map> internalControlsQueue = new HashMap<>();
-
- @Override
- @Path("device/{deviceId}/bulb")
- @POST
- public Response switchBulb(@PathParam("deviceId") String deviceId, @QueryParam("state") String state) {
- try {
- if (!APIUtil.getDeviceAccessAuthorizationService().isUserAuthorized(new DeviceIdentifier(deviceId,
- ArduinoConstants.DEVICE_TYPE), DeviceGroupConstants.Permissions.DEFAULT_OPERATOR_PERMISSIONS)) {
- return Response.status(Response.Status.UNAUTHORIZED.getStatusCode()).build();
- }
- LinkedList deviceControlList = internalControlsQueue.get(deviceId);
- String operation = "BULB:" + state.toUpperCase();
- if (deviceControlList == null) {
- deviceControlList = new LinkedList<>();
- deviceControlList.add(operation);
- internalControlsQueue.put(deviceId, deviceControlList);
- } else {
- deviceControlList.add(operation);
- }
- return Response.status(Response.Status.OK.getStatusCode()).build();
- } catch (DeviceAccessAuthorizationException e) {
- log.error(e.getErrorMessage(), e);
- return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
- }
- }
-
- @Override
- @Path("device/{deviceId}/controls")
- @GET
- public Response readControls(@PathParam("deviceId") String deviceId) {
- try {
- if (!APIUtil.getDeviceAccessAuthorizationService().isUserAuthorized(new DeviceIdentifier(deviceId,
- ArduinoConstants.DEVICE_TYPE), DeviceGroupConstants.Permissions.DEFAULT_OPERATOR_PERMISSIONS)) {
- return Response.status(Response.Status.UNAUTHORIZED.getStatusCode()).build();
- }
- String result;
- LinkedList deviceControlList = internalControlsQueue.get(deviceId);
- String owner = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername();
- if (deviceControlList == null) {
- result = "No controls have been set for device " + deviceId + " of owner " + owner;
- if (log.isDebugEnabled()) {
- log.debug(result);
- }
- return Response.status(Response.Status.CONFLICT.getStatusCode()).entity(result).build();
- } else {
- try {
- result = deviceControlList.remove();
- if (log.isDebugEnabled()) {
- log.debug(result);
- }
- return Response.status(Response.Status.ACCEPTED.getStatusCode()).entity(result).build();
- } catch (NoSuchElementException ex) {
- result = "There are no more controls for device " + deviceId + " of owner " + owner;
- if (log.isDebugEnabled()) {
- log.debug(result);
- }
- return Response.status(Response.Status.NO_CONTENT.getStatusCode()).entity(result).build();
- }
- }
- } catch (DeviceAccessAuthorizationException e) {
- log.error(e.getErrorMessage(), e);
- return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
- }
- }
-
- @Override
- @Path("device/stats/{deviceId}")
- @GET
- @Consumes("application/json")
- @Produces("application/json")
- public Response getArduinoTemperatureStats(@PathParam("deviceId") String deviceId, @QueryParam("from") long from,
- @QueryParam("to") long to) {
- try {
- if (!APIUtil.getDeviceAccessAuthorizationService().isUserAuthorized(new DeviceIdentifier(deviceId,
- ArduinoConstants.DEVICE_TYPE), DeviceGroupConstants.Permissions.DEFAULT_STATS_MONITOR_PERMISSIONS)) {
- return Response.status(Response.Status.UNAUTHORIZED.getStatusCode()).build();
- }
- String fromDate = String.valueOf(from);
- String toDate = String.valueOf(to);
- String query = "deviceId:" + deviceId + " AND deviceType:" +
- ArduinoConstants.DEVICE_TYPE + " AND time : [" + fromDate + " TO " + toDate + "]";
- String sensorTableName = ArduinoConstants.TEMPERATURE_EVENT_TABLE;
- try {
- List sortByFields = new ArrayList<>();
- SortByField sortByField = new SortByField("time", SORT.ASC, false);
- sortByFields.add(sortByField);
- List sensorRecords = APIUtil.getAllEventsForDevice(sensorTableName, query, sortByFields);
- return Response.status(Response.Status.OK.getStatusCode()).entity(sensorRecords).build();
- } catch (AnalyticsException e) {
- String errorMsg = "Error on retrieving stats on table " + sensorTableName + " with query " + query;
- log.error(errorMsg);
- return Response.status(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()).entity(errorMsg).build();
- }
- } catch (DeviceAccessAuthorizationException e) {
- log.error(e.getErrorMessage(), e);
- return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
- }
- }
-
-}
diff --git a/components/iot-plugins/arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.api/src/main/java/org/wso2/carbon/device/mgt/iot/arduino/service/impl/ArduinoManagerService.java b/components/iot-plugins/arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.api/src/main/java/org/wso2/carbon/device/mgt/iot/arduino/service/impl/ArduinoManagerService.java
deleted file mode 100644
index d161127ac7..0000000000
--- a/components/iot-plugins/arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.api/src/main/java/org/wso2/carbon/device/mgt/iot/arduino/service/impl/ArduinoManagerService.java
+++ /dev/null
@@ -1,63 +0,0 @@
-/*
- * 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.iot.arduino.service.impl;
-
-import org.wso2.carbon.apimgt.annotations.api.API;
-import org.wso2.carbon.device.mgt.extensions.feature.mgt.annotations.DeviceType;
-
-import javax.ws.rs.Consumes;
-import javax.ws.rs.DELETE;
-import javax.ws.rs.GET;
-import javax.ws.rs.PUT;
-import javax.ws.rs.Path;
-import javax.ws.rs.PathParam;
-import javax.ws.rs.Produces;
-import javax.ws.rs.QueryParam;
-import javax.ws.rs.core.MediaType;
-import javax.ws.rs.core.Response;
-
-@Path("enrollment")
-@API(name = "arduino_mgt", version = "1.0.0", context = "/arduino_mgt", tags = {"arduino"})
-public interface ArduinoManagerService {
-
- @Path("devices/{device_id}")
- @PUT
- Response updateDevice(@PathParam("device_id") String deviceId, @QueryParam("name") String name);
-
- @Path("devices/{device_id}")
- @GET
- @Consumes(MediaType.APPLICATION_JSON)
- @Produces(MediaType.APPLICATION_JSON)
- Response getDevice(@PathParam("device_id") String deviceId);
-
- @Path("devices/{device_id}")
- @DELETE
- Response removeDevice(@PathParam("device_id") String deviceId);
-
- @Path("devices")
- @GET
- @Consumes(MediaType.APPLICATION_JSON)
- @Produces(MediaType.APPLICATION_JSON)
- Response getArduinoDevices();
-
- @Path("devices/download")
- @GET
- @Produces("application/octet-stream")
- Response downloadSketch(@QueryParam("deviceName") String customDeviceName);
-}
diff --git a/components/iot-plugins/arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.api/src/main/java/org/wso2/carbon/device/mgt/iot/arduino/service/impl/ArduinoControllerService.java b/components/iot-plugins/arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.api/src/main/java/org/wso2/carbon/device/mgt/iot/arduino/service/impl/ArduinoService.java
similarity index 73%
rename from components/iot-plugins/arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.api/src/main/java/org/wso2/carbon/device/mgt/iot/arduino/service/impl/ArduinoControllerService.java
rename to components/iot-plugins/arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.api/src/main/java/org/wso2/carbon/device/mgt/iot/arduino/service/impl/ArduinoService.java
index d0986ee866..afe0c89b1a 100644
--- a/components/iot-plugins/arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.api/src/main/java/org/wso2/carbon/device/mgt/iot/arduino/service/impl/ArduinoControllerService.java
+++ b/components/iot-plugins/arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.api/src/main/java/org/wso2/carbon/device/mgt/iot/arduino/service/impl/ArduinoService.java
@@ -19,6 +19,7 @@
package org.wso2.carbon.device.mgt.iot.arduino.service.impl;
import org.wso2.carbon.apimgt.annotations.api.API;
+import org.wso2.carbon.apimgt.annotations.api.Permission;
import org.wso2.carbon.device.mgt.extensions.feature.mgt.annotations.DeviceType;
import org.wso2.carbon.device.mgt.extensions.feature.mgt.annotations.Feature;
import javax.ws.rs.Consumes;
@@ -32,15 +33,17 @@ import javax.ws.rs.core.Response;
@API(name = "arduino", version = "1.0.0", context = "/arduino", tags = {"arduino"})
@DeviceType(value = "arduino")
-public interface ArduinoControllerService {
+public interface ArduinoService {
@Path("device/{deviceId}/bulb")
@POST
@Feature(code = "bulb", name = "Control Bulb", description = "Control Bulb on Arduino Uno")
+ @Permission(scope = "arduino_user", permissions = {"/permission/admin/device-mgt/user/operations"})
Response switchBulb(@PathParam("deviceId") String deviceId, @QueryParam("state") String state);
@Path("device/{deviceId}/controls")
@GET
+ @Permission(scope = "arduino_device", permissions = {"/permission/admin/device-mgt/user/operations"})
Response readControls(@PathParam("deviceId") String deviceId);
/**
@@ -50,7 +53,17 @@ public interface ArduinoControllerService {
@GET
@Consumes("application/json")
@Produces("application/json")
+ @Permission(scope = "arduino_user", permissions = {"/permission/admin/device-mgt/user/stats"})
Response getArduinoTemperatureStats(@PathParam("deviceId") String deviceId, @QueryParam("from") long from,
@QueryParam("to") long to);
+ /**
+ * download device agent
+ */
+ @Path("device/download")
+ @GET
+ @Produces("application/octet-stream")
+ @Permission(scope = "arduino_user", permissions = {"/permission/admin/device-mgt/user/devices"})
+ Response downloadSketch(@QueryParam("deviceName") String customDeviceName);
+
}
diff --git a/components/iot-plugins/arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.api/src/main/java/org/wso2/carbon/device/mgt/iot/arduino/service/impl/ArduinoManagerServiceImpl.java b/components/iot-plugins/arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.api/src/main/java/org/wso2/carbon/device/mgt/iot/arduino/service/impl/ArduinoServiceImpl.java
similarity index 57%
rename from components/iot-plugins/arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.api/src/main/java/org/wso2/carbon/device/mgt/iot/arduino/service/impl/ArduinoManagerServiceImpl.java
rename to components/iot-plugins/arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.api/src/main/java/org/wso2/carbon/device/mgt/iot/arduino/service/impl/ArduinoServiceImpl.java
index 2b1268e9ea..8bd141809c 100644
--- a/components/iot-plugins/arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.api/src/main/java/org/wso2/carbon/device/mgt/iot/arduino/service/impl/ArduinoManagerServiceImpl.java
+++ b/components/iot-plugins/arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.api/src/main/java/org/wso2/carbon/device/mgt/iot/arduino/service/impl/ArduinoServiceImpl.java
@@ -21,6 +21,9 @@ package org.wso2.carbon.device.mgt.iot.arduino.service.impl;
import org.apache.commons.io.FileUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import org.wso2.carbon.analytics.dataservice.commons.SORT;
+import org.wso2.carbon.analytics.dataservice.commons.SortByField;
+import org.wso2.carbon.analytics.datasource.commons.exception.AnalyticsException;
import org.wso2.carbon.apimgt.application.extension.APIManagementProviderService;
import org.wso2.carbon.apimgt.application.extension.dto.ApiApplicationKey;
import org.wso2.carbon.apimgt.application.extension.exception.APIManagerException;
@@ -29,6 +32,9 @@ import org.wso2.carbon.device.mgt.common.Device;
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
import org.wso2.carbon.device.mgt.common.DeviceManagementException;
import org.wso2.carbon.device.mgt.common.EnrolmentInfo;
+import org.wso2.carbon.device.mgt.common.authorization.DeviceAccessAuthorizationException;
+import org.wso2.carbon.device.mgt.common.group.mgt.DeviceGroupConstants;
+import org.wso2.carbon.device.mgt.iot.arduino.service.impl.dto.SensorRecord;
import org.wso2.carbon.device.mgt.iot.arduino.service.impl.util.APIUtil;
import org.wso2.carbon.device.mgt.iot.arduino.plugin.constants.ArduinoConstants;
import org.wso2.carbon.device.mgt.iot.arduino.service.impl.util.ZipUtil;
@@ -39,115 +45,132 @@ import org.wso2.carbon.identity.jwt.client.extension.exception.JWTClientExceptio
import org.wso2.carbon.user.api.UserStoreException;
import javax.ws.rs.Consumes;
-import javax.ws.rs.DELETE;
import javax.ws.rs.GET;
-import javax.ws.rs.PUT;
+import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
-import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Date;
+import java.util.HashMap;
+import java.util.LinkedList;
import java.util.List;
+import java.util.Map;
+import java.util.NoSuchElementException;
import java.util.UUID;
-@Path("enrollment")
-public class ArduinoManagerServiceImpl implements ArduinoManagerService {
+public class ArduinoServiceImpl implements ArduinoService {
+ private static Log log = LogFactory.getLog(ArduinoServiceImpl.class);
+ private static Map> internalControlsQueue = new HashMap<>();
private static final String KEY_TYPE = "PRODUCTION";
private static ApiApplicationKey apiApplicationKey;
- private static Log log = LogFactory.getLog(ArduinoManagerServiceImpl.class);
@Override
- @Path("devices/{device_id}")
- @DELETE
- public Response removeDevice(@PathParam("device_id") String deviceId) {
- DeviceIdentifier deviceIdentifier = new DeviceIdentifier();
- deviceIdentifier.setId(deviceId);
- deviceIdentifier.setType(ArduinoConstants.DEVICE_TYPE);
+ @Path("device/{deviceId}/bulb")
+ @POST
+ public Response switchBulb(@PathParam("deviceId") String deviceId, @QueryParam("state") String state) {
try {
- boolean removed = APIUtil.getDeviceManagementService().disenrollDevice(deviceIdentifier);
- if (removed) {
- return Response.status(Response.Status.OK.getStatusCode()).entity(true).build();
- } else {
- return Response.status(Response.Status.NOT_ACCEPTABLE.getStatusCode()).build();
+ if (!APIUtil.getDeviceAccessAuthorizationService().isUserAuthorized(new DeviceIdentifier(deviceId,
+ ArduinoConstants.DEVICE_TYPE), DeviceGroupConstants.Permissions.DEFAULT_OPERATOR_PERMISSIONS)) {
+ return Response.status(Response.Status.UNAUTHORIZED.getStatusCode()).build();
}
- } catch (DeviceManagementException e) {
- return Response.status(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()).build();
- }
- }
-
- @Override
- @Path("devices/{device_id}")
- @PUT
- public Response updateDevice(@PathParam("device_id") String deviceId, @QueryParam("name") String name) {
- DeviceIdentifier deviceIdentifier = new DeviceIdentifier();
- deviceIdentifier.setId(deviceId);
- deviceIdentifier.setType(ArduinoConstants.DEVICE_TYPE);
- try {
- Device device = APIUtil.getDeviceManagementService().getDevice(deviceIdentifier);
- device.setDeviceIdentifier(deviceId);
- device.getEnrolmentInfo().setDateOfLastUpdate(new Date().getTime());
- device.setName(name);
- device.setType(ArduinoConstants.DEVICE_TYPE);
- boolean updated = APIUtil.getDeviceManagementService().modifyEnrollment(device);
- if (updated) {
- return Response.status(Response.Status.OK.getStatusCode()).entity(true).build();
+ LinkedList deviceControlList = internalControlsQueue.get(deviceId);
+ String operation = "BULB:" + state.toUpperCase();
+ if (deviceControlList == null) {
+ deviceControlList = new LinkedList<>();
+ deviceControlList.add(operation);
+ internalControlsQueue.put(deviceId, deviceControlList);
} else {
- return Response.status(Response.Status.NOT_ACCEPTABLE.getStatusCode()).build();
+ deviceControlList.add(operation);
}
- } catch (DeviceManagementException e) {
- return Response.status(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()).build();
+ return Response.status(Response.Status.OK.getStatusCode()).build();
+ } catch (DeviceAccessAuthorizationException e) {
+ log.error(e.getErrorMessage(), e);
+ return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
}
}
@Override
- @Path("devices/{device_id}")
+ @Path("device/{deviceId}/controls")
@GET
- @Consumes(MediaType.APPLICATION_JSON)
- @Produces(MediaType.APPLICATION_JSON)
- public Response getDevice(@PathParam("device_id") String deviceId) {
- DeviceIdentifier deviceIdentifier = new DeviceIdentifier();
- deviceIdentifier.setId(deviceId);
- deviceIdentifier.setType(ArduinoConstants.DEVICE_TYPE);
+ public Response readControls(@PathParam("deviceId") String deviceId) {
try {
- Device device = APIUtil.getDeviceManagementService().getDevice(deviceIdentifier);
- return Response.status(Response.Status.OK.getStatusCode()).entity(device).build();
- } catch (DeviceManagementException e) {
- return Response.status(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()).build();
+ if (!APIUtil.getDeviceAccessAuthorizationService().isUserAuthorized(new DeviceIdentifier(deviceId,
+ ArduinoConstants.DEVICE_TYPE), DeviceGroupConstants.Permissions.DEFAULT_OPERATOR_PERMISSIONS)) {
+ return Response.status(Response.Status.UNAUTHORIZED.getStatusCode()).build();
+ }
+ String result;
+ LinkedList deviceControlList = internalControlsQueue.get(deviceId);
+ String owner = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername();
+ if (deviceControlList == null) {
+ result = "No controls have been set for device " + deviceId + " of owner " + owner;
+ if (log.isDebugEnabled()) {
+ log.debug(result);
+ }
+ return Response.status(Response.Status.CONFLICT.getStatusCode()).entity(result).build();
+ } else {
+ try {
+ result = deviceControlList.remove();
+ if (log.isDebugEnabled()) {
+ log.debug(result);
+ }
+ return Response.status(Response.Status.ACCEPTED.getStatusCode()).entity(result).build();
+ } catch (NoSuchElementException ex) {
+ result = "There are no more controls for device " + deviceId + " of owner " + owner;
+ if (log.isDebugEnabled()) {
+ log.debug(result);
+ }
+ return Response.status(Response.Status.NO_CONTENT.getStatusCode()).entity(result).build();
+ }
+ }
+ } catch (DeviceAccessAuthorizationException e) {
+ log.error(e.getErrorMessage(), e);
+ return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
}
}
@Override
- @Path("devices")
+ @Path("device/stats/{deviceId}")
@GET
- @Consumes(MediaType.APPLICATION_JSON)
- @Produces(MediaType.APPLICATION_JSON)
- public Response getArduinoDevices() {
+ @Consumes("application/json")
+ @Produces("application/json")
+ public Response getArduinoTemperatureStats(@PathParam("deviceId") String deviceId, @QueryParam("from") long from,
+ @QueryParam("to") long to) {
try {
- List userDevices = APIUtil.getDeviceManagementService().getDevicesOfUser(
- APIUtil.getAuthenticatedUser());
- ArrayList userDevicesforArduino = new ArrayList<>();
- for (Device device : userDevices) {
- if (device.getType().equals(ArduinoConstants.DEVICE_TYPE) &&
- device.getEnrolmentInfo().getStatus().equals(EnrolmentInfo.Status.ACTIVE)) {
- userDevicesforArduino.add(device);
- }
+ if (!APIUtil.getDeviceAccessAuthorizationService().isUserAuthorized(new DeviceIdentifier(deviceId,
+ ArduinoConstants.DEVICE_TYPE), DeviceGroupConstants.Permissions.DEFAULT_STATS_MONITOR_PERMISSIONS)) {
+ return Response.status(Response.Status.UNAUTHORIZED.getStatusCode()).build();
}
- Device[] devices = userDevicesforArduino.toArray(new Device[]{});
- return Response.status(Response.Status.OK.getStatusCode()).entity(devices).build();
- } catch (DeviceManagementException e) {
- return Response.status(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()).entity(true).build();
+ String fromDate = String.valueOf(from);
+ String toDate = String.valueOf(to);
+ String query = "deviceId:" + deviceId + " AND deviceType:" +
+ ArduinoConstants.DEVICE_TYPE + " AND time : [" + fromDate + " TO " + toDate + "]";
+ String sensorTableName = ArduinoConstants.TEMPERATURE_EVENT_TABLE;
+ try {
+ List sortByFields = new ArrayList<>();
+ SortByField sortByField = new SortByField("time", SORT.ASC, false);
+ sortByFields.add(sortByField);
+ List sensorRecords = APIUtil.getAllEventsForDevice(sensorTableName, query, sortByFields);
+ return Response.status(Response.Status.OK.getStatusCode()).entity(sensorRecords).build();
+ } catch (AnalyticsException e) {
+ String errorMsg = "Error on retrieving stats on table " + sensorTableName + " with query " + query;
+ log.error(errorMsg);
+ return Response.status(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()).entity(errorMsg).build();
+ }
+ } catch (DeviceAccessAuthorizationException e) {
+ log.error(e.getErrorMessage(), e);
+ return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
}
}
@Override
- @Path("/devices/download")
+ @Path("/device/download")
@GET
@Produces("application/zip")
public Response downloadSketch(@QueryParam("deviceName") String deviceName) {
@@ -197,7 +220,7 @@ public class ArduinoManagerServiceImpl implements ArduinoManagerService {
ArduinoConstants.DEVICE_TYPE, tags, KEY_TYPE, applicationUsername, true);
}
JWTClient jwtClient = APIUtil.getJWTClientManagerService().getJWTClient();
- String scopes = "device_type_" + ArduinoConstants.DEVICE_TYPE + " device_" + deviceId;
+ String scopes = "arduino_device device_type_" + ArduinoConstants.DEVICE_TYPE + " device_" + deviceId;
AccessTokenInfo accessTokenInfo = jwtClient.getAccessToken(apiApplicationKey.getConsumerKey(),
apiApplicationKey.getConsumerSecret(), owner, scopes);
//create token
@@ -210,9 +233,8 @@ public class ArduinoManagerServiceImpl implements ArduinoManagerService {
throw new DeviceManagementException(msg);
}
ZipUtil ziputil = new ZipUtil();
- ZipArchive zipFile = ziputil.createZipFile(owner, APIUtil.getTenantDomainOftheUser(),
- ArduinoConstants.DEVICE_TYPE, deviceId, deviceName, accessToken, refreshToken);
- return zipFile;
+ return ziputil.createZipFile(owner, APIUtil.getTenantDomainOftheUser(),
+ ArduinoConstants.DEVICE_TYPE, deviceId, deviceName, accessToken, refreshToken);
}
private static String shortUUID() {
@@ -245,5 +267,4 @@ public class ArduinoManagerServiceImpl implements ArduinoManagerService {
return false;
}
}
-
}
diff --git a/components/iot-plugins/arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.api/src/main/java/org/wso2/carbon/device/mgt/iot/arduino/service/impl/util/ZipUtil.java b/components/iot-plugins/arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.api/src/main/java/org/wso2/carbon/device/mgt/iot/arduino/service/impl/util/ZipUtil.java
index 9f3dca2690..1cad521204 100644
--- a/components/iot-plugins/arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.api/src/main/java/org/wso2/carbon/device/mgt/iot/arduino/service/impl/util/ZipUtil.java
+++ b/components/iot-plugins/arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.api/src/main/java/org/wso2/carbon/device/mgt/iot/arduino/service/impl/util/ZipUtil.java
@@ -47,7 +47,7 @@ public class ZipUtil {
String iotServerIP;
try {
- iotServerIP = Utils.getHostName();
+ iotServerIP = Utils.getServerUrl();
String httpServerPort = System.getProperty(HTTP_PORT_PROPERTY);
Map contextParams = new HashMap<>();
diff --git a/components/iot-plugins/arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.api/src/main/webapp/META-INF/permissions.xml b/components/iot-plugins/arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.api/src/main/webapp/META-INF/permissions.xml
index 4966eba2e2..eb8e9f67fd 100644
--- a/components/iot-plugins/arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.api/src/main/webapp/META-INF/permissions.xml
+++ b/components/iot-plugins/arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.api/src/main/webapp/META-INF/permissions.xml
@@ -50,33 +50,12 @@
GET
arduino_device
-
- Get device
- /device-mgt/user/devices/list
- /enrollment/devices/*
- GET
- arduino_user
-
-
- Remove device
- /device-mgt/user/devices/remove
- /enrollment/devices/*
- DELETE
- arduino_user
-
Download device
/device-mgt/user/devices
- /enrollment/devices/download
+ /device/download
GET
arduino_user
-
- Update device
- /device-mgt/user/devices/update
- /enrollment/devices/*
- PUT
- arduino_user
-
diff --git a/components/iot-plugins/arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.api/src/main/webapp/WEB-INF/cxf-servlet.xml b/components/iot-plugins/arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.api/src/main/webapp/WEB-INF/cxf-servlet.xml
index c902d3024a..a5b895b00b 100644
--- a/components/iot-plugins/arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.api/src/main/webapp/WEB-INF/cxf-servlet.xml
+++ b/components/iot-plugins/arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.api/src/main/webapp/WEB-INF/cxf-servlet.xml
@@ -25,11 +25,8 @@
-
-
-
+
diff --git a/components/iot-plugins/arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.arduino.type-view/private/config.json b/components/iot-plugins/arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.arduino.type-view/private/config.json
index 73294d4ecc..e85ea2bc62 100644
--- a/components/iot-plugins/arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.arduino.type-view/private/config.json
+++ b/components/iot-plugins/arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.arduino.type-view/private/config.json
@@ -2,6 +2,6 @@
"deviceType": {
"label": "Arduino",
"category": "iot",
- "downloadAgentUri": "arduino/enrollment/devices/download"
+ "downloadAgentUri": "arduino/device/download"
}
}
\ No newline at end of file
diff --git a/components/iot-plugins/iot-base-plugin/org.wso2.carbon.device.mgt.iot/src/main/java/org/wso2/carbon/device/mgt/iot/util/Utils.java b/components/iot-plugins/iot-base-plugin/org.wso2.carbon.device.mgt.iot/src/main/java/org/wso2/carbon/device/mgt/iot/util/Utils.java
index 4bc6a6164c..26aaf2aa7f 100644
--- a/components/iot-plugins/iot-base-plugin/org.wso2.carbon.device.mgt.iot/src/main/java/org/wso2/carbon/device/mgt/iot/util/Utils.java
+++ b/components/iot-plugins/iot-base-plugin/org.wso2.carbon.device.mgt.iot/src/main/java/org/wso2/carbon/device/mgt/iot/util/Utils.java
@@ -55,7 +55,7 @@ public class Utils {
public static final String HOST_NAME = "HostName";
private static final Log log = LogFactory.getLog(Utils.class);
- public static String getHostName() {
+ public static String getServerUrl() {
String hostName = ServerConfiguration.getInstance().getFirstProperty(HOST_NAME);
try {
if (hostName == null) {
diff --git a/components/iot-plugins/raspberrypi-plugin/org.wso2.carbon.device.mgt.iot.raspberrypi.api/src/main/java/org/wso2/carbon/device/mgt/iot/raspberrypi/service/impl/RaspberryPiControllerServiceImpl.java b/components/iot-plugins/raspberrypi-plugin/org.wso2.carbon.device.mgt.iot.raspberrypi.api/src/main/java/org/wso2/carbon/device/mgt/iot/raspberrypi/service/impl/RaspberryPiControllerServiceImpl.java
deleted file mode 100644
index d4a8f747cc..0000000000
--- a/components/iot-plugins/raspberrypi-plugin/org.wso2.carbon.device.mgt.iot.raspberrypi.api/src/main/java/org/wso2/carbon/device/mgt/iot/raspberrypi/service/impl/RaspberryPiControllerServiceImpl.java
+++ /dev/null
@@ -1,109 +0,0 @@
-/*
- * 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.iot.raspberrypi.service.impl;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.wso2.carbon.analytics.dataservice.commons.SORT;
-import org.wso2.carbon.analytics.dataservice.commons.SortByField;
-import org.wso2.carbon.analytics.datasource.commons.exception.AnalyticsException;
-import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
-import org.wso2.carbon.device.mgt.common.authorization.DeviceAccessAuthorizationException;
-import org.wso2.carbon.device.mgt.common.group.mgt.DeviceGroupConstants;
-import org.wso2.carbon.device.mgt.iot.raspberrypi.service.impl.dto.SensorRecord;
-import org.wso2.carbon.device.mgt.iot.raspberrypi.service.impl.util.APIUtil;
-import org.wso2.carbon.device.mgt.iot.raspberrypi.plugin.constants.RaspberrypiConstants;
-
-import javax.ws.rs.Consumes;
-import javax.ws.rs.GET;
-import javax.ws.rs.POST;
-import javax.ws.rs.Path;
-import javax.ws.rs.PathParam;
-import javax.ws.rs.Produces;
-import javax.ws.rs.QueryParam;
-import javax.ws.rs.core.Response;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-public class RaspberryPiControllerServiceImpl implements RaspberryPiControllerService {
-
- private static Log log = LogFactory.getLog(RaspberryPiControllerServiceImpl.class);
-
- @Path("device/{deviceId}/bulb")
- @POST
- public Response switchBulb(@PathParam("deviceId") String deviceId, @QueryParam("state") String state) {
- try {
- if (!APIUtil.getDeviceAccessAuthorizationService().isUserAuthorized(new DeviceIdentifier(deviceId,
- RaspberrypiConstants.DEVICE_TYPE), DeviceGroupConstants.Permissions.DEFAULT_OPERATOR_PERMISSIONS)) {
- return Response.status(Response.Status.UNAUTHORIZED.getStatusCode()).build();
- }
- String switchToState = state.toUpperCase();
- if (!switchToState.equals(RaspberrypiConstants.STATE_ON) && !switchToState.equals(
- RaspberrypiConstants.STATE_OFF)) {
- log.error("The requested state change shoud be either - 'ON' or 'OFF'");
- return Response.status(Response.Status.BAD_REQUEST.getStatusCode()).build();
- }
- String actualMessage = RaspberrypiConstants.BULB_CONTEXT + ":" + state;
- Map dynamicProperties = new HashMap<>();
- String publishTopic = APIUtil.getTenantDomainOftheUser() + "/"
- + RaspberrypiConstants.DEVICE_TYPE + "/" + deviceId;
- dynamicProperties.put(RaspberrypiConstants.ADAPTER_TOPIC_PROPERTY, publishTopic);
- APIUtil.getOutputEventAdapterService().publish(RaspberrypiConstants.MQTT_ADAPTER_NAME,
- dynamicProperties, actualMessage);
- return Response.ok().build();
- } catch (DeviceAccessAuthorizationException e) {
- log.error(e.getErrorMessage(), e);
- return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
- }
- }
-
- @Path("device/stats/{deviceId}")
- @GET
- @Consumes("application/json")
- @Produces("application/json")
- public Response getRaspberryPiTemperatureStats(@PathParam("deviceId") String deviceId,
- @QueryParam("from") long from, @QueryParam("to") long to) {
- String fromDate = String.valueOf(from);
- String toDate = String.valueOf(to);
- String query = "deviceId:" + deviceId + " AND deviceType:" +
- RaspberrypiConstants.DEVICE_TYPE + " AND time : [" + fromDate + " TO " + toDate + "]";
- String sensorTableName = RaspberrypiConstants.TEMPERATURE_EVENT_TABLE;
- try {
- if (!APIUtil.getDeviceAccessAuthorizationService().isUserAuthorized(new DeviceIdentifier(deviceId,
- RaspberrypiConstants.DEVICE_TYPE), DeviceGroupConstants.Permissions.DEFAULT_STATS_MONITOR_PERMISSIONS)) {
- return Response.status(Response.Status.UNAUTHORIZED.getStatusCode()).build();
- }
- List sortByFields = new ArrayList<>();
- SortByField sortByField = new SortByField("time", SORT.ASC, false);
- sortByFields.add(sortByField);
- List sensorRecords = APIUtil.getAllEventsForDevice(sensorTableName, query, sortByFields);
- return Response.status(Response.Status.OK.getStatusCode()).entity(sensorRecords).build();
- } catch (AnalyticsException e) {
- String errorMsg = "Error on retrieving stats on table " + sensorTableName + " with query " + query;
- log.error(errorMsg);
- return Response.status(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()).entity(errorMsg).build();
- } catch (DeviceAccessAuthorizationException e) {
- log.error(e.getErrorMessage(), e);
- return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
- }
- }
-
-}
diff --git a/components/iot-plugins/raspberrypi-plugin/org.wso2.carbon.device.mgt.iot.raspberrypi.api/src/main/java/org/wso2/carbon/device/mgt/iot/raspberrypi/service/impl/RaspberryPiManagerService.java b/components/iot-plugins/raspberrypi-plugin/org.wso2.carbon.device.mgt.iot.raspberrypi.api/src/main/java/org/wso2/carbon/device/mgt/iot/raspberrypi/service/impl/RaspberryPiManagerService.java
deleted file mode 100644
index 07c4bc2131..0000000000
--- a/components/iot-plugins/raspberrypi-plugin/org.wso2.carbon.device.mgt.iot.raspberrypi.api/src/main/java/org/wso2/carbon/device/mgt/iot/raspberrypi/service/impl/RaspberryPiManagerService.java
+++ /dev/null
@@ -1,66 +0,0 @@
-/*
- * 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.iot.raspberrypi.service.impl;
-
-import org.wso2.carbon.apimgt.annotations.api.API;
-import org.wso2.carbon.device.mgt.extensions.feature.mgt.annotations.DeviceType;
-
-import javax.ws.rs.Consumes;
-import javax.ws.rs.DELETE;
-import javax.ws.rs.GET;
-import javax.ws.rs.PUT;
-import javax.ws.rs.Path;
-import javax.ws.rs.PathParam;
-import javax.ws.rs.Produces;
-import javax.ws.rs.QueryParam;
-import javax.ws.rs.core.MediaType;
-import javax.ws.rs.core.Response;
-
-@Path("enrollment")
-@API(name = "raspberrypi_mgt", version = "1.0.0", context = "/raspberrypi_mgt", tags = {"raspberrypi"})
-@DeviceType(value = "raspberrypi")
-public interface RaspberryPiManagerService {
-
- @Path("devices/{device_id}")
- @DELETE
- Response removeDevice(@PathParam("device_id") String deviceId);
-
- @Path("devices/{device_id}")
- @PUT
- Response updateDevice(@PathParam("device_id") String deviceId,
- @QueryParam("name") String name);
-
- @Path("devices/{device_id}")
- @GET
- @Consumes(MediaType.APPLICATION_JSON)
- @Produces(MediaType.APPLICATION_JSON)
- Response getDevice(@PathParam("device_id") String deviceId);
-
- @Path("devices")
- @GET
- @Consumes(MediaType.APPLICATION_JSON)
- @Produces(MediaType.APPLICATION_JSON)
- Response getRaspberrypiDevices();
-
- @Path("devicesg/download")
- @GET
- @Produces(MediaType.APPLICATION_JSON)
- Response downloadSketch(@QueryParam("deviceName") String deviceName, @QueryParam("sketch_type") String sketchType);
-
-}
diff --git a/components/iot-plugins/raspberrypi-plugin/org.wso2.carbon.device.mgt.iot.raspberrypi.api/src/main/java/org/wso2/carbon/device/mgt/iot/raspberrypi/service/impl/RaspberryPiControllerService.java b/components/iot-plugins/raspberrypi-plugin/org.wso2.carbon.device.mgt.iot.raspberrypi.api/src/main/java/org/wso2/carbon/device/mgt/iot/raspberrypi/service/impl/RaspberryPiService.java
similarity index 73%
rename from components/iot-plugins/raspberrypi-plugin/org.wso2.carbon.device.mgt.iot.raspberrypi.api/src/main/java/org/wso2/carbon/device/mgt/iot/raspberrypi/service/impl/RaspberryPiControllerService.java
rename to components/iot-plugins/raspberrypi-plugin/org.wso2.carbon.device.mgt.iot.raspberrypi.api/src/main/java/org/wso2/carbon/device/mgt/iot/raspberrypi/service/impl/RaspberryPiService.java
index c32353a2b1..299f7be26f 100644
--- a/components/iot-plugins/raspberrypi-plugin/org.wso2.carbon.device.mgt.iot.raspberrypi.api/src/main/java/org/wso2/carbon/device/mgt/iot/raspberrypi/service/impl/RaspberryPiControllerService.java
+++ b/components/iot-plugins/raspberrypi-plugin/org.wso2.carbon.device.mgt.iot.raspberrypi.api/src/main/java/org/wso2/carbon/device/mgt/iot/raspberrypi/service/impl/RaspberryPiService.java
@@ -19,25 +19,27 @@
package org.wso2.carbon.device.mgt.iot.raspberrypi.service.impl;
import org.wso2.carbon.apimgt.annotations.api.API;
+import org.wso2.carbon.apimgt.annotations.api.Permission;
import org.wso2.carbon.device.mgt.extensions.feature.mgt.annotations.DeviceType;
import org.wso2.carbon.device.mgt.extensions.feature.mgt.annotations.Feature;
import javax.ws.rs.Consumes;
-import javax.ws.rs.FormParam;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
+import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
@API(name = "raspberrypi", version = "1.0.0", context = "/raspberrypi", tags = {"raspberrypi"})
@DeviceType(value = "raspberrypi")
-public interface RaspberryPiControllerService {
+public interface RaspberryPiService {
@Path("device/{deviceId}/bulb")
@POST
@Feature(code = "bulb", name = "Bulb On / Off", description = "Switch on/off Raspberry Pi agent's bulb. (On / Off)")
+ @Permission(scope = "raspberrypi_user", permissions = {"/permission/admin/device-mgt/user/operations"})
Response switchBulb(@PathParam("deviceId") String deviceId, @QueryParam("state") String state);
/**
@@ -47,7 +49,17 @@ public interface RaspberryPiControllerService {
@GET
@Consumes("application/json")
@Produces("application/json")
+ @Permission(scope = "raspberrypi_user", permissions = {"/permission/admin/device-mgt/user/stats"})
Response getRaspberryPiTemperatureStats(@PathParam("deviceId") String deviceId,
@QueryParam("from") long from, @QueryParam("to") long to);
+ /**
+ * download the agent.
+ */
+ @Path("device/download")
+ @GET
+ @Produces(MediaType.APPLICATION_JSON)
+ @Permission(scope = "raspberrypi_user", permissions = {"/permission/admin/device-mgt/user/devices"})
+ Response downloadSketch(@QueryParam("deviceName") String deviceName, @QueryParam("sketch_type") String sketchType);
+
}
diff --git a/components/iot-plugins/raspberrypi-plugin/org.wso2.carbon.device.mgt.iot.raspberrypi.api/src/main/java/org/wso2/carbon/device/mgt/iot/raspberrypi/service/impl/RaspberryPiManagerServiceImpl.java b/components/iot-plugins/raspberrypi-plugin/org.wso2.carbon.device.mgt.iot.raspberrypi.api/src/main/java/org/wso2/carbon/device/mgt/iot/raspberrypi/service/impl/RaspberryPiServiceImpl.java
similarity index 65%
rename from components/iot-plugins/raspberrypi-plugin/org.wso2.carbon.device.mgt.iot.raspberrypi.api/src/main/java/org/wso2/carbon/device/mgt/iot/raspberrypi/service/impl/RaspberryPiManagerServiceImpl.java
rename to components/iot-plugins/raspberrypi-plugin/org.wso2.carbon.device.mgt.iot.raspberrypi.api/src/main/java/org/wso2/carbon/device/mgt/iot/raspberrypi/service/impl/RaspberryPiServiceImpl.java
index 35fa4ad196..49073cb022 100644
--- a/components/iot-plugins/raspberrypi-plugin/org.wso2.carbon.device.mgt.iot.raspberrypi.api/src/main/java/org/wso2/carbon/device/mgt/iot/raspberrypi/service/impl/RaspberryPiManagerServiceImpl.java
+++ b/components/iot-plugins/raspberrypi-plugin/org.wso2.carbon.device.mgt.iot.raspberrypi.api/src/main/java/org/wso2/carbon/device/mgt/iot/raspberrypi/service/impl/RaspberryPiServiceImpl.java
@@ -21,6 +21,9 @@ package org.wso2.carbon.device.mgt.iot.raspberrypi.service.impl;
import org.apache.commons.io.FileUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import org.wso2.carbon.analytics.dataservice.commons.SORT;
+import org.wso2.carbon.analytics.dataservice.commons.SortByField;
+import org.wso2.carbon.analytics.datasource.commons.exception.AnalyticsException;
import org.wso2.carbon.apimgt.application.extension.APIManagementProviderService;
import org.wso2.carbon.apimgt.application.extension.dto.ApiApplicationKey;
import org.wso2.carbon.apimgt.application.extension.exception.APIManagerException;
@@ -29,8 +32,11 @@ import org.wso2.carbon.device.mgt.common.Device;
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
import org.wso2.carbon.device.mgt.common.DeviceManagementException;
import org.wso2.carbon.device.mgt.common.EnrolmentInfo;
-import org.wso2.carbon.device.mgt.iot.raspberrypi.plugin.constants.RaspberrypiConstants;
+import org.wso2.carbon.device.mgt.common.authorization.DeviceAccessAuthorizationException;
+import org.wso2.carbon.device.mgt.common.group.mgt.DeviceGroupConstants;
+import org.wso2.carbon.device.mgt.iot.raspberrypi.service.impl.dto.SensorRecord;
import org.wso2.carbon.device.mgt.iot.raspberrypi.service.impl.util.APIUtil;
+import org.wso2.carbon.device.mgt.iot.raspberrypi.plugin.constants.RaspberrypiConstants;
import org.wso2.carbon.device.mgt.iot.raspberrypi.service.impl.util.ZipUtil;
import org.wso2.carbon.device.mgt.iot.util.ZipArchive;
import org.wso2.carbon.identity.jwt.client.extension.JWTClient;
@@ -39,118 +45,90 @@ import org.wso2.carbon.identity.jwt.client.extension.exception.JWTClientExceptio
import org.wso2.carbon.user.api.UserStoreException;
import javax.ws.rs.Consumes;
-import javax.ws.rs.DELETE;
import javax.ws.rs.GET;
-import javax.ws.rs.PUT;
+import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
-import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Date;
+import java.util.HashMap;
import java.util.List;
+import java.util.Map;
import java.util.UUID;
-@Path("enrollment")
-public class RaspberryPiManagerServiceImpl implements RaspberryPiManagerService {
+public class RaspberryPiServiceImpl implements RaspberryPiService {
- private static Log log = LogFactory.getLog(RaspberryPiManagerServiceImpl.class);
+ private static Log log = LogFactory.getLog(RaspberryPiServiceImpl.class);
private static final String KEY_TYPE = "PRODUCTION";
private static ApiApplicationKey apiApplicationKey;
- @Override
- @Path("devices/{device_id}")
- @DELETE
- public Response removeDevice(@PathParam("device_id") String deviceId) {
+ @Path("device/{deviceId}/bulb")
+ @POST
+ public Response switchBulb(@PathParam("deviceId") String deviceId, @QueryParam("state") String state) {
try {
- DeviceIdentifier deviceIdentifier = new DeviceIdentifier();
- deviceIdentifier.setId(deviceId);
- deviceIdentifier.setType(RaspberrypiConstants.DEVICE_TYPE);
- boolean removed = APIUtil.getDeviceManagementService().disenrollDevice(
- deviceIdentifier);
- if (removed) {
- return Response.ok().build();
- } else {
- return Response.status(Response.Status.NOT_ACCEPTABLE.getStatusCode()).build();
+ if (!APIUtil.getDeviceAccessAuthorizationService().isUserAuthorized(new DeviceIdentifier(deviceId,
+ RaspberrypiConstants.DEVICE_TYPE), DeviceGroupConstants.Permissions.DEFAULT_OPERATOR_PERMISSIONS)) {
+ return Response.status(Response.Status.UNAUTHORIZED.getStatusCode()).build();
}
- } catch (DeviceManagementException e) {
- return Response.status(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()).build();
- }
- }
-
- @Override
- @Path("devices/{device_id}")
- @PUT
- public Response updateDevice(@PathParam("device_id") String deviceId, @QueryParam("name") String name) {
- DeviceIdentifier deviceIdentifier = new DeviceIdentifier();
- deviceIdentifier.setId(deviceId);
- deviceIdentifier.setType(RaspberrypiConstants.DEVICE_TYPE);
- try {
- Device device = APIUtil.getDeviceManagementService().getDevice(deviceIdentifier);
- device.setDeviceIdentifier(deviceId);
- device.getEnrolmentInfo().setDateOfLastUpdate(new Date().getTime());
- device.setName(name);
- device.setType(RaspberrypiConstants.DEVICE_TYPE);
- boolean updated = APIUtil.getDeviceManagementService().modifyEnrollment(device);
- if (updated) {
- return Response.ok().build();
- } else {
- return Response.status(Response.Status.NOT_ACCEPTABLE.getStatusCode()).build();
+ String switchToState = state.toUpperCase();
+ if (!switchToState.equals(RaspberrypiConstants.STATE_ON) && !switchToState.equals(
+ RaspberrypiConstants.STATE_OFF)) {
+ log.error("The requested state change shoud be either - 'ON' or 'OFF'");
+ return Response.status(Response.Status.BAD_REQUEST.getStatusCode()).build();
}
- } catch (DeviceManagementException e) {
- log.error(e.getErrorMessage());
- return Response.status(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()).build();
+ String actualMessage = RaspberrypiConstants.BULB_CONTEXT + ":" + state;
+ Map dynamicProperties = new HashMap<>();
+ String publishTopic = APIUtil.getTenantDomainOftheUser() + "/"
+ + RaspberrypiConstants.DEVICE_TYPE + "/" + deviceId;
+ dynamicProperties.put(RaspberrypiConstants.ADAPTER_TOPIC_PROPERTY, publishTopic);
+ APIUtil.getOutputEventAdapterService().publish(RaspberrypiConstants.MQTT_ADAPTER_NAME,
+ dynamicProperties, actualMessage);
+ return Response.ok().build();
+ } catch (DeviceAccessAuthorizationException e) {
+ log.error(e.getErrorMessage(), e);
+ return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
}
}
- @Override
- @Path("devices/{device_id}")
+ @Path("device/stats/{deviceId}")
@GET
- @Consumes(MediaType.APPLICATION_JSON)
- @Produces(MediaType.APPLICATION_JSON)
- public Response getDevice(@PathParam("device_id") String deviceId) {
- DeviceIdentifier deviceIdentifier = new DeviceIdentifier();
- deviceIdentifier.setId(deviceId);
- deviceIdentifier.setType(RaspberrypiConstants.DEVICE_TYPE);
+ @Consumes("application/json")
+ @Produces("application/json")
+ public Response getRaspberryPiTemperatureStats(@PathParam("deviceId") String deviceId,
+ @QueryParam("from") long from, @QueryParam("to") long to) {
+ String fromDate = String.valueOf(from);
+ String toDate = String.valueOf(to);
+ String query = "deviceId:" + deviceId + " AND deviceType:" +
+ RaspberrypiConstants.DEVICE_TYPE + " AND time : [" + fromDate + " TO " + toDate + "]";
+ String sensorTableName = RaspberrypiConstants.TEMPERATURE_EVENT_TABLE;
try {
- Device device = APIUtil.getDeviceManagementService().getDevice(deviceIdentifier);
- return Response.ok().entity(device).build();
- } catch (DeviceManagementException ex) {
- log.error("Error occurred while retrieving device with Id " + deviceId + "\n" + ex);
- return Response.status(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()).build();
- }
- }
-
- @Override
- @Path("devices")
- @GET
- @Consumes(MediaType.APPLICATION_JSON)
- @Produces(MediaType.APPLICATION_JSON)
- public Response getRaspberrypiDevices() {
- try {
- List userDevices = APIUtil.getDeviceManagementService().getDevicesOfUser(
- APIUtil.getAuthenticatedUser());
- ArrayList usersRaspberrypiDevices = new ArrayList<>();
- for (Device device : userDevices) {
- if (device.getType().equals(RaspberrypiConstants.DEVICE_TYPE) &&
- device.getEnrolmentInfo().getStatus().equals(EnrolmentInfo.Status.ACTIVE)) {
- usersRaspberrypiDevices.add(device);
- }
+ if (!APIUtil.getDeviceAccessAuthorizationService().isUserAuthorized(new DeviceIdentifier(deviceId,
+ RaspberrypiConstants.DEVICE_TYPE), DeviceGroupConstants.Permissions.DEFAULT_STATS_MONITOR_PERMISSIONS)) {
+ return Response.status(Response.Status.UNAUTHORIZED.getStatusCode()).build();
}
- Device[] devices = usersRaspberrypiDevices.toArray(new Device[]{});
- return Response.ok().entity(devices).build();
- } catch (DeviceManagementException e) {
- return Response.status(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()).build();
+ List sortByFields = new ArrayList<>();
+ SortByField sortByField = new SortByField("time", SORT.ASC, false);
+ sortByFields.add(sortByField);
+ List sensorRecords = APIUtil.getAllEventsForDevice(sensorTableName, query, sortByFields);
+ return Response.status(Response.Status.OK.getStatusCode()).entity(sensorRecords).build();
+ } catch (AnalyticsException e) {
+ String errorMsg = "Error on retrieving stats on table " + sensorTableName + " with query " + query;
+ log.error(errorMsg);
+ return Response.status(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()).entity(errorMsg).build();
+ } catch (DeviceAccessAuthorizationException e) {
+ log.error(e.getErrorMessage(), e);
+ return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
}
}
@Override
- @Path("devices/download")
+ @Path("device/download")
@GET
@Produces("application/zip")
public Response downloadSketch(@QueryParam("deviceName") String deviceName, @QueryParam("sketchType") String sketchType) {
@@ -234,9 +212,8 @@ public class RaspberryPiManagerServiceImpl implements RaspberryPiManagerService
throw new DeviceManagementException(msg);
}
ZipUtil ziputil = new ZipUtil();
- ZipArchive zipFile = ziputil.createZipFile(owner, APIUtil.getTenantDomainOftheUser(), sketchType,
+ return ziputil.createZipFile(owner, APIUtil.getTenantDomainOftheUser(), sketchType,
deviceId, deviceName, accessToken, refreshToken);
- return zipFile;
}
private static String shortUUID() {
@@ -244,5 +221,4 @@ public class RaspberryPiManagerServiceImpl implements RaspberryPiManagerService
long l = ByteBuffer.wrap(uuid.toString().getBytes(StandardCharsets.UTF_8)).getLong();
return Long.toString(l, Character.MAX_RADIX);
}
-
}
diff --git a/components/iot-plugins/raspberrypi-plugin/org.wso2.carbon.device.mgt.iot.raspberrypi.api/src/main/java/org/wso2/carbon/device/mgt/iot/raspberrypi/service/impl/util/ZipUtil.java b/components/iot-plugins/raspberrypi-plugin/org.wso2.carbon.device.mgt.iot.raspberrypi.api/src/main/java/org/wso2/carbon/device/mgt/iot/raspberrypi/service/impl/util/ZipUtil.java
index b90c145ad4..6c9fd54b36 100644
--- a/components/iot-plugins/raspberrypi-plugin/org.wso2.carbon.device.mgt.iot.raspberrypi.api/src/main/java/org/wso2/carbon/device/mgt/iot/raspberrypi/service/impl/util/ZipUtil.java
+++ b/components/iot-plugins/raspberrypi-plugin/org.wso2.carbon.device.mgt.iot.raspberrypi.api/src/main/java/org/wso2/carbon/device/mgt/iot/raspberrypi/service/impl/util/ZipUtil.java
@@ -52,7 +52,7 @@ public class ZipUtil {
String iotServerIP;
try {
- iotServerIP = Utils.getHostName();
+ iotServerIP = Utils.getServerUrl();
String httpsServerPort = System.getProperty(HTTPS_PORT_PROPERTY);
String httpServerPort = System.getProperty(HTTP_PORT_PROPERTY);
String httpsServerEP = HTTPS_PROTOCOL_APPENDER + iotServerIP + ":" + httpsServerPort;
diff --git a/components/iot-plugins/raspberrypi-plugin/org.wso2.carbon.device.mgt.iot.raspberrypi.api/src/main/webapp/META-INF/permissions.xml b/components/iot-plugins/raspberrypi-plugin/org.wso2.carbon.device.mgt.iot.raspberrypi.api/src/main/webapp/META-INF/permissions.xml
index 6813569dd2..be74ef64dc 100644
--- a/components/iot-plugins/raspberrypi-plugin/org.wso2.carbon.device.mgt.iot.raspberrypi.api/src/main/webapp/META-INF/permissions.xml
+++ b/components/iot-plugins/raspberrypi-plugin/org.wso2.carbon.device.mgt.iot.raspberrypi.api/src/main/webapp/META-INF/permissions.xml
@@ -36,34 +36,13 @@
GET
raspberrypi_user
-
- Remove device
- /device-mgt/user/devices/remove
- /enrollment/devices/*
- DELETE
- raspberrypi_user
-
Download device
/device-mgt/user/devices
- /enrollment/devices/download
+ /device/download
GET
raspberrypi_user
-
- Update device
- /device-mgt/user/devices/update
- /enrollment/devices/*
- POST
- raspberrypi_user
-
-
- Get Devices
- /device-mgt/user/devices/list
- /enrollment/devices
- GET
- raspberrypi_user
-
Control Bulb
/device-mgt/user/operations
diff --git a/components/iot-plugins/raspberrypi-plugin/org.wso2.carbon.device.mgt.iot.raspberrypi.api/src/main/webapp/WEB-INF/cxf-servlet.xml b/components/iot-plugins/raspberrypi-plugin/org.wso2.carbon.device.mgt.iot.raspberrypi.api/src/main/webapp/WEB-INF/cxf-servlet.xml
index 7272253227..abb72753d1 100644
--- a/components/iot-plugins/raspberrypi-plugin/org.wso2.carbon.device.mgt.iot.raspberrypi.api/src/main/webapp/WEB-INF/cxf-servlet.xml
+++ b/components/iot-plugins/raspberrypi-plugin/org.wso2.carbon.device.mgt.iot.raspberrypi.api/src/main/webapp/WEB-INF/cxf-servlet.xml
@@ -27,11 +27,8 @@
-
-
-
+
diff --git a/components/iot-plugins/raspberrypi-plugin/org.wso2.carbon.device.mgt.iot.raspberrypi.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.raspberrypi.type-view/private/config.json b/components/iot-plugins/raspberrypi-plugin/org.wso2.carbon.device.mgt.iot.raspberrypi.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.raspberrypi.type-view/private/config.json
index 99f710bd89..f19ba03414 100644
--- a/components/iot-plugins/raspberrypi-plugin/org.wso2.carbon.device.mgt.iot.raspberrypi.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.raspberrypi.type-view/private/config.json
+++ b/components/iot-plugins/raspberrypi-plugin/org.wso2.carbon.device.mgt.iot.raspberrypi.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.raspberrypi.type-view/private/config.json
@@ -2,6 +2,6 @@
"deviceType": {
"label": "Raspberry Pi",
"category": "iot",
- "downloadAgentUri": "raspberrypi/enrollment/devices/download"
+ "downloadAgentUri": "raspberrypi/device/download"
}
}
\ No newline at end of file
diff --git a/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.agent.advanced.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/agent/advanced/communication/xmpp/FireAlarmXMPPCommunicator.java b/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.agent.advanced.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/agent/advanced/communication/xmpp/FireAlarmXMPPCommunicator.java
index f1fe40bd90..5beebd415c 100644
--- a/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.agent.advanced.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/agent/advanced/communication/xmpp/FireAlarmXMPPCommunicator.java
+++ b/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.agent.advanced.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/agent/advanced/communication/xmpp/FireAlarmXMPPCommunicator.java
@@ -68,11 +68,8 @@ public class FireAlarmXMPPCommunicator extends XMPPTransportHandler {
final AgentManager agentManager = AgentManager.getInstance();
username = agentManager.getAgentConfigs().getDeviceId();
password = agentManager.getAgentConfigs().getAuthToken();
- resource = agentManager.getAgentConfigs().getDeviceOwner();
-
- xmppDeviceJID = username + "@" + server;
- xmppAdminJID = "wso2_" + AgentConstants.DEVICE_TYPE + "@" + server;
-
+ xmppDeviceJID = username + "@" + agentManager.getAgentConfigs().getXmppServerName();
+ xmppAdminJID = "wso2admin_" + AgentConstants.DEVICE_TYPE + "@" + agentManager.getAgentConfigs().getXmppServerName();
Runnable connect = new Runnable() {
public void run() {
diff --git a/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.agent.advanced.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/agent/advanced/core/AgentConfiguration.java b/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.agent.advanced.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/agent/advanced/core/AgentConfiguration.java
index 7a54be78ef..d79e6b029b 100644
--- a/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.agent.advanced.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/agent/advanced/core/AgentConfiguration.java
+++ b/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.agent.advanced.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/agent/advanced/core/AgentConfiguration.java
@@ -39,6 +39,7 @@ public class AgentConfiguration {
private String authToken;
private String refreshToken;
private int dataPushInterval;
+ private String xmppServerName;
public String getTenantDomain() {
return tenantDomain;
@@ -159,6 +160,14 @@ public class AgentConfiguration {
public void setScepContext(String scepContext) {
this.scepContext = scepContext;
}
+
+ public String getXmppServerName() {
+ return xmppServerName;
+ }
+
+ public void setXmppServerName(String xmppServerName) {
+ this.xmppServerName = xmppServerName;
+ }
}
diff --git a/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.agent.advanced.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/agent/advanced/core/AgentConstants.java b/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.agent.advanced.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/agent/advanced/core/AgentConstants.java
index 09975cde4a..84267523f8 100644
--- a/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.agent.advanced.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/agent/advanced/core/AgentConstants.java
+++ b/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.agent.advanced.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/agent/advanced/core/AgentConstants.java
@@ -134,4 +134,6 @@ public class AgentConstants {
"select deviceID, temp\n" +
"insert into bulbOffStream;";
+
+ public static final String XMPP_SERVER_NAME_PROPERTY = "xmpp-server-name";
}
diff --git a/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.agent.advanced.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/agent/advanced/core/AgentUtilOperations.java b/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.agent.advanced.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/agent/advanced/core/AgentUtilOperations.java
index 440582c7f7..822327301f 100644
--- a/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.agent.advanced.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/agent/advanced/core/AgentUtilOperations.java
+++ b/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.agent.advanced.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/agent/advanced/core/AgentUtilOperations.java
@@ -102,6 +102,8 @@ public class AgentUtilOperations {
AgentConstants.MQTT_BROKER_EP_PROPERTY));
iotServerConfigs.setXmppServerEndpoint(properties.getProperty(
AgentConstants.XMPP_SERVER_EP_PROPERTY));
+ iotServerConfigs.setXmppServerName(properties.getProperty(
+ AgentConstants.XMPP_SERVER_NAME_PROPERTY));
iotServerConfigs.setAuthMethod(properties.getProperty(
AgentConstants.AUTH_METHOD_PROPERTY));
iotServerConfigs.setAuthToken(properties.getProperty(
@@ -138,6 +140,8 @@ public class AgentUtilOperations {
iotServerConfigs.getRefreshToken());
log.info(AgentConstants.LOG_APPENDER + "Data Push Interval: " +
iotServerConfigs.getDataPushInterval());
+ log.info(AgentConstants.LOG_APPENDER + "XMPP Server Name: " +
+ iotServerConfigs.getXmppServerName());
} catch (FileNotFoundException ex) {
log.error(AgentConstants.LOG_APPENDER + "Unable to find " + propertiesFileName +
diff --git a/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.agent.advanced.impl/src/main/resources/deviceConfig.properties b/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.agent.advanced.impl/src/main/resources/deviceConfig.properties
index 1dc1374b99..4eba166c1a 100644
--- a/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.agent.advanced.impl/src/main/resources/deviceConfig.properties
+++ b/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.agent.advanced.impl/src/main/resources/deviceConfig.properties
@@ -32,3 +32,4 @@ auth-token=79d68b50ae5f5a06e812889979b3453
refresh-token=8bdda6359dddad218cff3354d5a8cb3b
network-interface=en0
push-interval=14
+xmpp-server-name=localhost
\ No newline at end of file
diff --git a/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.agent.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/agent/communication/xmpp/FireAlarmXMPPCommunicator.java b/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.agent.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/agent/communication/xmpp/FireAlarmXMPPCommunicator.java
index b29cd492eb..45d103adcd 100644
--- a/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.agent.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/agent/communication/xmpp/FireAlarmXMPPCommunicator.java
+++ b/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.agent.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/agent/communication/xmpp/FireAlarmXMPPCommunicator.java
@@ -21,6 +21,7 @@ package org.wso2.carbon.device.mgt.iot.virtualfirealarm.agent.communication.xmpp
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.jivesoftware.smack.packet.Message;
+import org.wso2.carbon.device.mgt.iot.virtualfirealarm.agent.core.AgentConfiguration;
import org.wso2.carbon.device.mgt.iot.virtualfirealarm.agent.core.AgentConstants;
import org.wso2.carbon.device.mgt.iot.virtualfirealarm.agent.core.AgentManager;
import org.wso2.carbon.device.mgt.iot.virtualfirealarm.agent.core.AgentUtilOperations;
@@ -68,11 +69,8 @@ public class FireAlarmXMPPCommunicator extends XMPPTransportHandler {
final AgentManager agentManager = AgentManager.getInstance();
username = agentManager.getAgentConfigs().getDeviceId();
password = agentManager.getAgentConfigs().getAuthToken();
- resource = agentManager.getAgentConfigs().getDeviceOwner();
-
- xmppDeviceJID = username + "@" + server;
- xmppAdminJID = "wso2_" + AgentConstants.DEVICE_TYPE + "@" + server;
-
+ xmppDeviceJID = username + "@" + agentManager.getAgentConfigs().getXmppServerName();
+ xmppAdminJID = "wso2admin_" + AgentConstants.DEVICE_TYPE + "@" + agentManager.getAgentConfigs().getXmppServerName();
Runnable connect = new Runnable() {
public void run() {
diff --git a/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.agent.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/agent/core/AgentConfiguration.java b/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.agent.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/agent/core/AgentConfiguration.java
index 68cb58ee80..64b52b8b78 100644
--- a/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.agent.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/agent/core/AgentConfiguration.java
+++ b/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.agent.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/agent/core/AgentConfiguration.java
@@ -39,6 +39,7 @@ public class AgentConfiguration {
private String authToken;
private String refreshToken;
private int dataPushInterval;
+ private String xmppServerName;
public String getTenantDomain() {
return tenantDomain;
@@ -159,6 +160,14 @@ public class AgentConfiguration {
public void setScepContext(String scepContext) {
this.scepContext = scepContext;
}
+
+ public String getXmppServerName() {
+ return xmppServerName;
+ }
+
+ public void setXmppServerName(String xmppServerName) {
+ this.xmppServerName = xmppServerName;
+ }
}
diff --git a/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.agent.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/agent/core/AgentConstants.java b/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.agent.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/agent/core/AgentConstants.java
index 1a9771b8e8..8836aa09c7 100644
--- a/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.agent.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/agent/core/AgentConstants.java
+++ b/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.agent.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/agent/core/AgentConstants.java
@@ -77,6 +77,7 @@ public class AgentConstants {
public static final String APIM_GATEWAY_EP_PROPERTY = "apim-ep";
public static final String MQTT_BROKER_EP_PROPERTY = "mqtt-ep";
public static final String XMPP_SERVER_EP_PROPERTY = "xmpp-ep";
+ public static final String XMPP_SERVER_NAME_PROPERTY = "xmpp-server-name";
public static final String AUTH_METHOD_PROPERTY = "auth-method";
public static final String AUTH_TOKEN_PROPERTY = "auth-token";
public static final String REFRESH_TOKEN_PROPERTY = "refresh-token";
diff --git a/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.agent.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/agent/core/AgentUtilOperations.java b/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.agent.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/agent/core/AgentUtilOperations.java
index c7eb9d342c..656ce84905 100644
--- a/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.agent.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/agent/core/AgentUtilOperations.java
+++ b/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.agent.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/agent/core/AgentUtilOperations.java
@@ -106,6 +106,8 @@ public class AgentUtilOperations {
AgentConstants.MQTT_BROKER_EP_PROPERTY));
iotServerConfigs.setXmppServerEndpoint(properties.getProperty(
AgentConstants.XMPP_SERVER_EP_PROPERTY));
+ iotServerConfigs.setXmppServerName(properties.getProperty(
+ AgentConstants.XMPP_SERVER_NAME_PROPERTY));
iotServerConfigs.setAuthMethod(properties.getProperty(
AgentConstants.AUTH_METHOD_PROPERTY));
iotServerConfigs.setAuthToken(properties.getProperty(
@@ -142,6 +144,8 @@ public class AgentUtilOperations {
iotServerConfigs.getRefreshToken());
log.info(AgentConstants.LOG_APPENDER + "Data Push Interval: " +
iotServerConfigs.getDataPushInterval());
+ log.info(AgentConstants.LOG_APPENDER + "XMPP Server Name: " +
+ iotServerConfigs.getXmppServerName());
} catch (FileNotFoundException ex) {
String errorMsg = "[" + propertiesFileName + "] file not found at: " + AgentConstants.PROPERTIES_FILE_PATH;
diff --git a/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.agent.impl/src/main/resources/deviceConfig.properties b/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.agent.impl/src/main/resources/deviceConfig.properties
index 1dc1374b99..4eba166c1a 100644
--- a/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.agent.impl/src/main/resources/deviceConfig.properties
+++ b/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.agent.impl/src/main/resources/deviceConfig.properties
@@ -32,3 +32,4 @@ auth-token=79d68b50ae5f5a06e812889979b3453
refresh-token=8bdda6359dddad218cff3354d5a8cb3b
network-interface=en0
push-interval=14
+xmpp-server-name=localhost
\ No newline at end of file
diff --git a/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.api/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/service/impl/VirtualFireAlarmManagerService.java b/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.api/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/service/impl/VirtualFireAlarmManagerService.java
deleted file mode 100644
index 7b5bdaf097..0000000000
--- a/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.api/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/service/impl/VirtualFireAlarmManagerService.java
+++ /dev/null
@@ -1,65 +0,0 @@
-/*
- * 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.iot.virtualfirealarm.service.impl;
-
-import org.wso2.carbon.apimgt.annotations.api.API;
-import org.wso2.carbon.device.mgt.extensions.feature.mgt.annotations.DeviceType;
-
-import javax.ws.rs.Consumes;
-import javax.ws.rs.DELETE;
-import javax.ws.rs.GET;
-import javax.ws.rs.PUT;
-import javax.ws.rs.Path;
-import javax.ws.rs.PathParam;
-import javax.ws.rs.Produces;
-import javax.ws.rs.QueryParam;
-import javax.ws.rs.core.MediaType;
-import javax.ws.rs.core.Response;
-
-@Path("enrollment")
-@API(name = "virtual_firealarm_mgt", version = "1.0.0", context = "/virtual_firealarm_mgt", tags = {"virtual_firealarm"})
-public interface VirtualFireAlarmManagerService {
-
- @Path("/devices/{device_id}")
- @DELETE
- Response removeDevice(@PathParam("device_id") String deviceId);
-
-
- @Path("/devices/{device_id}")
- @PUT
- Response updateDevice(@PathParam("device_id") String deviceId, @QueryParam("name") String name);
-
- @Path("/devices/{device_id}")
- @GET
- @Consumes(MediaType.APPLICATION_JSON)
- @Produces(MediaType.APPLICATION_JSON)
- Response getDevice(@PathParam("device_id") String deviceId);
-
- @Path("/devices")
- @GET
- @Consumes(MediaType.APPLICATION_JSON)
- @Produces(MediaType.APPLICATION_JSON)
- Response getFirealarmDevices();
-
- @Path("/devices/download")
- @GET
- @Produces("application/zip")
- Response downloadSketch(@QueryParam("deviceName") String deviceName, @QueryParam("sketchType") String sketchType);
-
-}
\ No newline at end of file
diff --git a/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.api/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/service/impl/VirtualFireAlarmManagerServiceImpl.java b/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.api/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/service/impl/VirtualFireAlarmManagerServiceImpl.java
deleted file mode 100644
index 17e1a46110..0000000000
--- a/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.api/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/service/impl/VirtualFireAlarmManagerServiceImpl.java
+++ /dev/null
@@ -1,294 +0,0 @@
-/*
- * 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.iot.virtualfirealarm.service.impl;
-
-import org.apache.commons.io.FileUtils;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.wso2.carbon.apimgt.application.extension.APIManagementProviderService;
-import org.wso2.carbon.apimgt.application.extension.dto.ApiApplicationKey;
-import org.wso2.carbon.apimgt.application.extension.exception.APIManagerException;
-import org.wso2.carbon.context.PrivilegedCarbonContext;
-import org.wso2.carbon.device.mgt.common.Device;
-import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
-import org.wso2.carbon.device.mgt.common.DeviceManagementException;
-import org.wso2.carbon.device.mgt.common.EnrolmentInfo;
-import org.wso2.carbon.device.mgt.common.authorization.DeviceAccessAuthorizationException;
-import org.wso2.carbon.device.mgt.common.group.mgt.DeviceGroupConstants;
-import org.wso2.carbon.device.mgt.iot.util.ZipArchive;
-import org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin.constants.VirtualFireAlarmConstants;
-import org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin.exception.VirtualFirealarmDeviceMgtPluginException;
-import org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin.xmpp.XmppAccount;
-import org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin.xmpp.XmppConfig;
-import org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin.xmpp.XmppServerClient;
-import org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.impl.util.APIUtil;
-import org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.impl.util.ZipUtil;
-import org.wso2.carbon.identity.jwt.client.extension.JWTClient;
-import org.wso2.carbon.identity.jwt.client.extension.dto.AccessTokenInfo;
-import org.wso2.carbon.identity.jwt.client.extension.exception.JWTClientException;
-import org.wso2.carbon.user.api.UserStoreException;
-
-import javax.ws.rs.Consumes;
-import javax.ws.rs.DELETE;
-import javax.ws.rs.GET;
-import javax.ws.rs.PUT;
-import javax.ws.rs.Path;
-import javax.ws.rs.PathParam;
-import javax.ws.rs.Produces;
-import javax.ws.rs.QueryParam;
-import javax.ws.rs.core.MediaType;
-import javax.ws.rs.core.Response;
-import java.io.IOException;
-import java.nio.ByteBuffer;
-import java.nio.charset.StandardCharsets;
-import java.util.ArrayList;
-import java.util.Date;
-import java.util.List;
-import java.util.UUID;
-
-@Path("enrollment")
-public class VirtualFireAlarmManagerServiceImpl implements VirtualFireAlarmManagerService {
-
- private static final String KEY_TYPE = "PRODUCTION";
- private static ApiApplicationKey apiApplicationKey;
- private static Log log = LogFactory.getLog(VirtualFireAlarmManagerServiceImpl.class);
-
- @Path("/devices/{device_id}")
- @DELETE
- public Response removeDevice(@PathParam("device_id") String deviceId) {
- try {
- DeviceIdentifier deviceIdentifier = new DeviceIdentifier();
- deviceIdentifier.setId(deviceId);
- deviceIdentifier.setType(VirtualFireAlarmConstants.DEVICE_TYPE);
- if (!APIUtil.getDeviceAccessAuthorizationService().isUserAuthorized(deviceIdentifier, DeviceGroupConstants.
- Permissions.DEFAULT_ADMIN_PERMISSIONS)) {
- return Response.status(Response.Status.UNAUTHORIZED.getStatusCode()).build();
- }
- boolean removed = APIUtil.getDeviceManagementService().disenrollDevice(
- deviceIdentifier);
- if (removed) {
- return Response.ok().build();
- } else {
- return Response.status(Response.Status.NOT_ACCEPTABLE.getStatusCode()).build();
- }
- } catch (DeviceManagementException e) {
- log.error(e.getErrorMessage(), e);
- return Response.status(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()).build();
- } catch (DeviceAccessAuthorizationException e) {
- log.error(e.getErrorMessage(), e);
- return Response.status(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()).build();
- }
- }
-
- @Path("/devices/{device_id}")
- @PUT
- public Response updateDevice(@PathParam("device_id") String deviceId, @QueryParam("name") String name) {
- try {
- DeviceIdentifier deviceIdentifier = new DeviceIdentifier();
- deviceIdentifier.setId(deviceId);
- deviceIdentifier.setType(VirtualFireAlarmConstants.DEVICE_TYPE);
- if (!APIUtil.getDeviceAccessAuthorizationService().isUserAuthorized(deviceIdentifier, DeviceGroupConstants.
- Permissions.DEFAULT_ADMIN_PERMISSIONS)) {
- return Response.status(Response.Status.UNAUTHORIZED.getStatusCode()).build();
- }
- Device device = APIUtil.getDeviceManagementService().getDevice(deviceIdentifier);
- device.setDeviceIdentifier(deviceId);
- device.getEnrolmentInfo().setDateOfLastUpdate(new Date().getTime());
- device.setName(name);
- device.setType(VirtualFireAlarmConstants.DEVICE_TYPE);
- boolean updated = APIUtil.getDeviceManagementService().modifyEnrollment(device);
- if (updated) {
- return Response.ok().build();
- } else {
- return Response.status(Response.Status.NOT_ACCEPTABLE.getStatusCode()).build();
- }
- } catch (DeviceManagementException e) {
- log.error(e.getErrorMessage(), e);
- return Response.status(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()).build();
- } catch (DeviceAccessAuthorizationException e) {
- log.error(e.getErrorMessage(), e);
- return Response.status(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()).build();
- }
- }
-
- @Path("/devices/{device_id}")
- @GET
- @Consumes(MediaType.APPLICATION_JSON)
- @Produces(MediaType.APPLICATION_JSON)
- public Response getDevice(@PathParam("device_id") String deviceId) {
- try {
- DeviceIdentifier deviceIdentifier = new DeviceIdentifier();
- deviceIdentifier.setId(deviceId);
- deviceIdentifier.setType(VirtualFireAlarmConstants.DEVICE_TYPE);
- if (!APIUtil.getDeviceAccessAuthorizationService().isUserAuthorized(deviceIdentifier)) {
- return Response.status(Response.Status.UNAUTHORIZED.getStatusCode()).build();
- }
- Device device = APIUtil.getDeviceManagementService().getDevice(deviceIdentifier);
- return Response.ok().entity(device).build();
- } catch (DeviceManagementException e) {
- log.error(e.getErrorMessage(), e);
- return Response.status(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()).build();
- } catch (DeviceAccessAuthorizationException e) {
- log.error(e.getErrorMessage(), e);
- return Response.status(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()).build();
- }
- }
-
- @Path("/devices")
- @GET
- @Consumes(MediaType.APPLICATION_JSON)
- @Produces(MediaType.APPLICATION_JSON)
- public Response getFirealarmDevices() {
- try {
- List userDevices =
- APIUtil.getDeviceManagementService().getDevicesOfUser(APIUtil.getAuthenticatedUser());
- ArrayList userDevicesforFirealarm = new ArrayList<>();
- for (Device device : userDevices) {
- if (device.getType().equals(VirtualFireAlarmConstants.DEVICE_TYPE) &&
- device.getEnrolmentInfo().getStatus().equals(EnrolmentInfo.Status.ACTIVE)) {
- userDevicesforFirealarm.add(device);
- }
- }
- Device[] devices = userDevicesforFirealarm.toArray(new Device[]{});
- return Response.ok().entity(devices).build();
- } catch (DeviceManagementException e) {
- log.error(e.getErrorMessage(), e);
- return Response.status(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()).build();
- }
- }
-
- @Path("/devices/download")
- @GET
- @Produces("application/zip")
- public Response downloadSketch(@QueryParam("deviceName") String deviceName,
- @QueryParam("sketchType") String sketchType) {
- try {
- ZipArchive zipFile = createDownloadFile(APIUtil.getAuthenticatedUser(), deviceName, sketchType);
- Response.ResponseBuilder response = Response.ok(FileUtils.readFileToByteArray(zipFile.getZipFile()));
- response.status(Response.Status.OK);
- response.type("application/zip");
- response.header("Content-Disposition", "attachment; filename=\"" + zipFile.getFileName() + "\"");
- Response resp = response.build();
- zipFile.getZipFile().delete();
- return resp;
- } catch (IllegalArgumentException ex) {
- return Response.status(400).entity(ex.getMessage()).build();//bad request
- } catch (DeviceManagementException ex) {
- log.error(ex.getMessage(), ex);
- return Response.status(500).entity(ex.getMessage()).build();
- } catch (JWTClientException ex) {
- log.error(ex.getMessage(), ex);
- return Response.status(500).entity(ex.getMessage()).build();
- } catch (APIManagerException ex) {
- log.error(ex.getMessage(), ex);
- return Response.status(500).entity(ex.getMessage()).build();
- } catch (IOException ex) {
- log.error(ex.getMessage(), ex);
- return Response.status(500).entity(ex.getMessage()).build();
- } catch (UserStoreException ex) {
- log.error(ex.getMessage(), ex);
- return Response.status(500).entity(ex.getMessage()).build();
- } catch (VirtualFirealarmDeviceMgtPluginException ex) {
- log.error(ex.getMessage(), ex);
- return Response.status(500).entity(ex.getMessage()).build();
- }
- }
-
- private boolean register(String deviceId, String name) {
- try {
- DeviceIdentifier deviceIdentifier = new DeviceIdentifier();
- deviceIdentifier.setId(deviceId);
- deviceIdentifier.setType(VirtualFireAlarmConstants.DEVICE_TYPE);
- if (APIUtil.getDeviceManagementService().isEnrolled(deviceIdentifier)) {
- return false;
- }
- Device device = new Device();
- device.setDeviceIdentifier(deviceId);
- EnrolmentInfo enrolmentInfo = new EnrolmentInfo();
- enrolmentInfo.setDateOfEnrolment(new Date().getTime());
- enrolmentInfo.setDateOfLastUpdate(new Date().getTime());
- enrolmentInfo.setStatus(EnrolmentInfo.Status.ACTIVE);
- enrolmentInfo.setOwnership(EnrolmentInfo.OwnerShip.BYOD);
- device.setName(name);
- device.setType(VirtualFireAlarmConstants.DEVICE_TYPE);
- enrolmentInfo.setOwner(APIUtil.getAuthenticatedUser());
- device.setEnrolmentInfo(enrolmentInfo);
- return APIUtil.getDeviceManagementService().enrollDevice(device);
- } catch (DeviceManagementException e) {
- log.error(e.getMessage(), e);
- return false;
- }
- }
-
- private ZipArchive createDownloadFile(String owner, String deviceName, String sketchType)
- throws DeviceManagementException, APIManagerException, JWTClientException,
- UserStoreException, VirtualFirealarmDeviceMgtPluginException {
- //create new device id
- String deviceId = shortUUID();
- if (apiApplicationKey == null) {
- String applicationUsername =
- PrivilegedCarbonContext.getThreadLocalCarbonContext().getUserRealm().getRealmConfiguration()
- .getAdminUserName();
- APIManagementProviderService apiManagementProviderService = APIUtil.getAPIManagementProviderService();
- String[] tags = {VirtualFireAlarmConstants.DEVICE_TYPE};
- apiApplicationKey = apiManagementProviderService.generateAndRetrieveApplicationKeys(
- VirtualFireAlarmConstants.DEVICE_TYPE, tags, KEY_TYPE, applicationUsername, true);
- }
- JWTClient jwtClient = APIUtil.getJWTClientManagerService().getJWTClient();
- String scopes = "device_type_" + VirtualFireAlarmConstants.DEVICE_TYPE + " device_" + deviceId;
- AccessTokenInfo accessTokenInfo = jwtClient.getAccessToken(apiApplicationKey.getConsumerKey(),
- apiApplicationKey.getConsumerSecret(), owner,
- scopes);
- String accessToken = accessTokenInfo.getAccessToken();
- String refreshToken = accessTokenInfo.getRefreshToken();
- //adding registering data
- XmppAccount newXmppAccount = new XmppAccount();
- newXmppAccount.setAccountName(deviceId);
- newXmppAccount.setUsername(deviceId);
- newXmppAccount.setPassword(accessToken);
- newXmppAccount.setEmail(deviceId + "@" + APIUtil.getTenantDomainOftheUser());
- XmppServerClient xmppServerClient = new XmppServerClient();
- boolean status;
- if (XmppConfig.getInstance().isEnabled()) {
- status = xmppServerClient.createAccount(newXmppAccount);
- if (!status) {
- String msg = "XMPP Account was not created for device - " + deviceId + " of owner - " + owner +
- ".XMPP might have been disabled in org.wso2.carbon.device.mgt.iot" +
- ".common.config.server.configs";
- throw new DeviceManagementException(msg);
- }
- }
- status = register(deviceId, deviceName);
- if (!status) {
- String msg = "Error occurred while registering the device with " + "id: " + deviceId + " owner:" + owner;
- throw new DeviceManagementException(msg);
- }
- ZipUtil ziputil = new ZipUtil();
- ZipArchive zipFile = ziputil.createZipFile(owner, APIUtil.getTenantDomainOftheUser(), sketchType, deviceId,
- deviceName, accessToken, refreshToken);
- return zipFile;
- }
-
- private static String shortUUID() {
- UUID uuid = UUID.randomUUID();
- long l = ByteBuffer.wrap(uuid.toString().getBytes(StandardCharsets.UTF_8)).getLong();
- return Long.toString(l, Character.MAX_RADIX);
- }
-
-}
diff --git a/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.api/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/service/impl/VirtualFireAlarmControllerService.java b/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.api/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/service/impl/VirtualFireAlarmService.java
similarity index 88%
rename from components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.api/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/service/impl/VirtualFireAlarmControllerService.java
rename to components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.api/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/service/impl/VirtualFireAlarmService.java
index 0417bcbad8..5e235b872f 100644
--- a/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.api/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/service/impl/VirtualFireAlarmControllerService.java
+++ b/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.api/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/service/impl/VirtualFireAlarmService.java
@@ -35,7 +35,7 @@ import javax.ws.rs.core.Response;
*/
@API(name = "virtual_firealarm", version = "1.0.0", context = "/virtual_firealarm", tags = {"virtual_firealarm"})
@DeviceType(value = "virtual_firealarm")
-public interface VirtualFireAlarmControllerService {
+public interface VirtualFireAlarmService {
/**
* This is an API called/used from within the Server(Front-End) or by a device Owner. It sends a control command to
@@ -49,7 +49,7 @@ public interface VirtualFireAlarmControllerService {
*/
@POST
@Path("device/{deviceId}/buzz")
- @Permission(scope = "virtual_firealarm_user", permissions = {"device-mgt/virtual_firealarm/user"})
+ @Permission(scope = "virtual_firealarm_user", permissions = {"/permission/admin/device-mgt/user/operations"})
@Feature(code = "buzz", name = "Buzzer On / Off", description = "Switch on/off Virtual Fire Alarm Buzzer. (On / Off)")
Response switchBuzzer(@PathParam("deviceId") String deviceId, @QueryParam("protocol") String protocol,
@FormParam("state") String state);
@@ -60,10 +60,16 @@ public interface VirtualFireAlarmControllerService {
*/
@Path("device/stats/{deviceId}")
@GET
- @Permission(scope = "virtual_firealarm_user", permissions = {"device-mgt/virtual_firealarm/user"})
+ @Permission(scope = "virtual_firealarm_user", permissions = {"/permission/admin/device-mgt/user/stats"})
@Consumes("application/json")
@Produces("application/json")
Response getVirtualFirealarmStats(@PathParam("deviceId") String deviceId, @QueryParam("from") long from,
@QueryParam("to") long to);
+ @Path("device/download")
+ @GET
+ @Produces("application/zip")
+ @Permission(scope = "virtual_firealarm_user", permissions = {"/permission/admin/device-mgt/user/devices"})
+ Response downloadSketch(@QueryParam("deviceName") String deviceName, @QueryParam("sketchType") String sketchType);
+
}
diff --git a/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.api/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/service/impl/VirtualFireAlarmControllerServiceImpl.java b/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.api/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/service/impl/VirtualFireAlarmServiceImpl.java
similarity index 56%
rename from components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.api/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/service/impl/VirtualFireAlarmControllerServiceImpl.java
rename to components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.api/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/service/impl/VirtualFireAlarmServiceImpl.java
index 213cb3fbc8..0548ff9d6a 100644
--- a/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.api/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/service/impl/VirtualFireAlarmControllerServiceImpl.java
+++ b/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.api/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/service/impl/VirtualFireAlarmServiceImpl.java
@@ -18,20 +18,38 @@
package org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.impl;
+import org.apache.commons.io.FileUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.analytics.dataservice.commons.SORT;
import org.wso2.carbon.analytics.dataservice.commons.SortByField;
import org.wso2.carbon.analytics.datasource.commons.exception.AnalyticsException;
+import org.wso2.carbon.apimgt.application.extension.APIManagementProviderService;
+import org.wso2.carbon.apimgt.application.extension.dto.ApiApplicationKey;
+import org.wso2.carbon.apimgt.application.extension.exception.APIManagerException;
+import org.wso2.carbon.context.PrivilegedCarbonContext;
+import org.wso2.carbon.device.mgt.common.Device;
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
+import org.wso2.carbon.device.mgt.common.DeviceManagementException;
+import org.wso2.carbon.device.mgt.common.EnrolmentInfo;
import org.wso2.carbon.device.mgt.common.authorization.DeviceAccessAuthorizationException;
import org.wso2.carbon.device.mgt.common.group.mgt.DeviceGroupConstants;
+import org.wso2.carbon.device.mgt.iot.util.ZipArchive;
import org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin.constants.VirtualFireAlarmConstants;
+import org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin.exception.VirtualFirealarmDeviceMgtPluginException;
import org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin.impl.util.VirtualFirealarmSecurityManager;
+import org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin.xmpp.XmppAccount;
+import org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin.xmpp.XmppConfig;
+import org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin.xmpp.XmppServerClient;
import org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.impl.dto.SensorRecord;
import org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.impl.exception.VirtualFireAlarmException;
import org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.impl.util.APIUtil;
import org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.impl.util.VirtualFireAlarmServiceUtils;
+import org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.impl.util.ZipUtil;
+import org.wso2.carbon.identity.jwt.client.extension.JWTClient;
+import org.wso2.carbon.identity.jwt.client.extension.dto.AccessTokenInfo;
+import org.wso2.carbon.identity.jwt.client.extension.exception.JWTClientException;
+import org.wso2.carbon.user.api.UserStoreException;
import javax.ws.rs.Consumes;
import javax.ws.rs.FormParam;
@@ -43,16 +61,23 @@ import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.Response;
+import java.io.IOException;
+import java.nio.ByteBuffer;
+import java.nio.charset.StandardCharsets;
import java.security.PrivateKey;
import java.util.ArrayList;
+import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import java.util.UUID;
-public class VirtualFireAlarmControllerServiceImpl implements VirtualFireAlarmControllerService {
+public class VirtualFireAlarmServiceImpl implements VirtualFireAlarmService {
private static final String XMPP_PROTOCOL = "XMPP";
- private static Log log = LogFactory.getLog(VirtualFireAlarmControllerServiceImpl.class);
+ private static final String KEY_TYPE = "PRODUCTION";
+ private static ApiApplicationKey apiApplicationKey;
+ private static Log log = LogFactory.getLog(VirtualFireAlarmServiceImpl.class);
@POST
@Path("device/{deviceId}/buzz")
@@ -83,7 +108,8 @@ public class VirtualFireAlarmControllerServiceImpl implements VirtualFireAlarmCo
Map dynamicProperties = new HashMap<>();
switch (protocolString) {
case XMPP_PROTOCOL:
- dynamicProperties.put(VirtualFireAlarmConstants.JID_PROPERTY_KEY, deviceId);
+ dynamicProperties.put(VirtualFireAlarmConstants.JID_PROPERTY_KEY,
+ deviceId + "@" + XmppConfig.getInstance().getXmppServerName());
dynamicProperties.put(VirtualFireAlarmConstants.SUBJECT_PROPERTY_KEY, "CONTROL-REQUEST");
dynamicProperties.put(VirtualFireAlarmConstants.MESSAGE_TYPE_PROPERTY_KEY,
VirtualFireAlarmConstants.CHAT_PROPERTY_KEY);
@@ -91,7 +117,6 @@ public class VirtualFireAlarmControllerServiceImpl implements VirtualFireAlarmCo
dynamicProperties, encryptedMsg);
break;
default:
-
String publishTopic = APIUtil.getTenantDomainOftheUser() + "/"
+ VirtualFireAlarmConstants.DEVICE_TYPE + "/" + deviceId;
dynamicProperties.put(VirtualFireAlarmConstants.ADAPTER_TOPIC_PROPERTY, publishTopic);
@@ -131,7 +156,8 @@ public class VirtualFireAlarmControllerServiceImpl implements VirtualFireAlarmCo
Map dynamicProperties = new HashMap<>();
switch (protocolString) {
case XMPP_PROTOCOL:
- dynamicProperties.put(VirtualFireAlarmConstants.JID_PROPERTY_KEY, deviceId);
+ dynamicProperties.put(VirtualFireAlarmConstants.JID_PROPERTY_KEY,
+ deviceId + "@" + XmppConfig.getInstance().getXmppServerName());
dynamicProperties.put(VirtualFireAlarmConstants.SUBJECT_PROPERTY_KEY, "POLICTY-REQUEST");
dynamicProperties.put(VirtualFireAlarmConstants.MESSAGE_TYPE_PROPERTY_KEY,
VirtualFireAlarmConstants.CHAT_PROPERTY_KEY);
@@ -190,4 +216,120 @@ public class VirtualFireAlarmControllerServiceImpl implements VirtualFireAlarmCo
}
}
+ @Path("device/download")
+ @GET
+ @Produces("application/zip")
+ public Response downloadSketch(@QueryParam("deviceName") String deviceName,
+ @QueryParam("sketchType") String sketchType) {
+ try {
+ ZipArchive zipFile = createDownloadFile(APIUtil.getAuthenticatedUser(), deviceName, sketchType);
+ Response.ResponseBuilder response = Response.ok(FileUtils.readFileToByteArray(zipFile.getZipFile()));
+ response.status(Response.Status.OK);
+ response.type("application/zip");
+ response.header("Content-Disposition", "attachment; filename=\"" + zipFile.getFileName() + "\"");
+ Response resp = response.build();
+ zipFile.getZipFile().delete();
+ return resp;
+ } catch (IllegalArgumentException ex) {
+ return Response.status(400).entity(ex.getMessage()).build();//bad request
+ } catch (DeviceManagementException ex) {
+ log.error(ex.getMessage(), ex);
+ return Response.status(500).entity(ex.getMessage()).build();
+ } catch (JWTClientException ex) {
+ log.error(ex.getMessage(), ex);
+ return Response.status(500).entity(ex.getMessage()).build();
+ } catch (APIManagerException ex) {
+ log.error(ex.getMessage(), ex);
+ return Response.status(500).entity(ex.getMessage()).build();
+ } catch (IOException ex) {
+ log.error(ex.getMessage(), ex);
+ return Response.status(500).entity(ex.getMessage()).build();
+ } catch (UserStoreException ex) {
+ log.error(ex.getMessage(), ex);
+ return Response.status(500).entity(ex.getMessage()).build();
+ } catch (VirtualFirealarmDeviceMgtPluginException ex) {
+ log.error(ex.getMessage(), ex);
+ return Response.status(500).entity(ex.getMessage()).build();
+ }
+ }
+
+ private boolean register(String deviceId, String name) {
+ try {
+ DeviceIdentifier deviceIdentifier = new DeviceIdentifier();
+ deviceIdentifier.setId(deviceId);
+ deviceIdentifier.setType(VirtualFireAlarmConstants.DEVICE_TYPE);
+ if (APIUtil.getDeviceManagementService().isEnrolled(deviceIdentifier)) {
+ return false;
+ }
+ Device device = new Device();
+ device.setDeviceIdentifier(deviceId);
+ EnrolmentInfo enrolmentInfo = new EnrolmentInfo();
+ enrolmentInfo.setDateOfEnrolment(new Date().getTime());
+ enrolmentInfo.setDateOfLastUpdate(new Date().getTime());
+ enrolmentInfo.setStatus(EnrolmentInfo.Status.ACTIVE);
+ enrolmentInfo.setOwnership(EnrolmentInfo.OwnerShip.BYOD);
+ device.setName(name);
+ device.setType(VirtualFireAlarmConstants.DEVICE_TYPE);
+ enrolmentInfo.setOwner(APIUtil.getAuthenticatedUser());
+ device.setEnrolmentInfo(enrolmentInfo);
+ return APIUtil.getDeviceManagementService().enrollDevice(device);
+ } catch (DeviceManagementException e) {
+ log.error(e.getMessage(), e);
+ return false;
+ }
+ }
+
+ private ZipArchive createDownloadFile(String owner, String deviceName, String sketchType)
+ throws DeviceManagementException, APIManagerException, JWTClientException,
+ UserStoreException, VirtualFirealarmDeviceMgtPluginException {
+ //create new device id
+ String deviceId = shortUUID();
+ if (apiApplicationKey == null) {
+ String applicationUsername =
+ PrivilegedCarbonContext.getThreadLocalCarbonContext().getUserRealm().getRealmConfiguration()
+ .getAdminUserName();
+ APIManagementProviderService apiManagementProviderService = APIUtil.getAPIManagementProviderService();
+ String[] tags = {VirtualFireAlarmConstants.DEVICE_TYPE};
+ apiApplicationKey = apiManagementProviderService.generateAndRetrieveApplicationKeys(
+ VirtualFireAlarmConstants.DEVICE_TYPE, tags, KEY_TYPE, applicationUsername, true);
+ }
+ JWTClient jwtClient = APIUtil.getJWTClientManagerService().getJWTClient();
+ String scopes = "device_type_" + VirtualFireAlarmConstants.DEVICE_TYPE + " device_" + deviceId;
+ AccessTokenInfo accessTokenInfo = jwtClient.getAccessToken(apiApplicationKey.getConsumerKey(),
+ apiApplicationKey.getConsumerSecret(), owner,
+ scopes);
+ String accessToken = accessTokenInfo.getAccessToken();
+ String refreshToken = accessTokenInfo.getRefreshToken();
+ //adding registering data
+ XmppAccount newXmppAccount = new XmppAccount();
+ newXmppAccount.setAccountName(deviceId);
+ newXmppAccount.setUsername(deviceId);
+ newXmppAccount.setPassword(accessToken);
+ newXmppAccount.setEmail(deviceId + "@" + APIUtil.getTenantDomainOftheUser());
+ boolean status;
+ if (XmppConfig.getInstance().isEnabled()) {
+ status = XmppServerClient.createAccount(newXmppAccount);
+ if (!status) {
+ String msg = "XMPP Account was not created for device - " + deviceId + " of owner - " + owner +
+ ".XMPP might have been disabled in org.wso2.carbon.device.mgt.iot" +
+ ".common.config.server.configs";
+ throw new DeviceManagementException(msg);
+ }
+ }
+ status = register(deviceId, deviceName);
+ if (!status) {
+ String msg = "Error occurred while registering the device with " + "id: " + deviceId + " owner:" + owner;
+ throw new DeviceManagementException(msg);
+ }
+ ZipUtil ziputil = new ZipUtil();
+ return ziputil.createZipFile(owner, APIUtil.getTenantDomainOftheUser(), sketchType, deviceId,
+ deviceName, accessToken, refreshToken);
+ }
+
+ private static String shortUUID() {
+ UUID uuid = UUID.randomUUID();
+ long l = ByteBuffer.wrap(uuid.toString().getBytes(StandardCharsets.UTF_8)).getLong();
+ return Long.toString(l, Character.MAX_RADIX);
+ }
+
}
diff --git a/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.api/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/service/impl/util/ZipUtil.java b/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.api/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/service/impl/util/ZipUtil.java
index 7929873068..4d7fed54cf 100644
--- a/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.api/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/service/impl/util/ZipUtil.java
+++ b/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.api/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/service/impl/util/ZipUtil.java
@@ -53,7 +53,7 @@ public class ZipUtil {
String iotServerIP;
try {
- iotServerIP = Utils.getHostName();
+ iotServerIP = Utils.getServerUrl();
String httpsServerPort = System.getProperty(HTTPS_PORT_PROPERTY);
String httpServerPort = System.getProperty(HTTP_PORT_PROPERTY);
String httpsServerEP = HTTPS_PROTOCOL_APPENDER + iotServerIP + ":" + httpsServerPort;
@@ -80,7 +80,7 @@ public class ZipUtil {
contextParams.put("XMPP_EP", "XMPP:" + xmppEndpoint);
contextParams.put("DEVICE_TOKEN", token);
contextParams.put("DEVICE_REFRESH_TOKEN", refreshToken);
-
+ contextParams.put("SERVER_NAME", XmppConfig.getInstance().getXmppServerName());
ZipArchive zipFile;
zipFile = Utils.getSketchArchive(archivesPath, templateSketchPath, contextParams, deviceName);
return zipFile;
diff --git a/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.api/src/main/webapp/META-INF/permissions.xml b/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.api/src/main/webapp/META-INF/permissions.xml
index 8b8957385b..8c18f748ec 100644
--- a/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.api/src/main/webapp/META-INF/permissions.xml
+++ b/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.api/src/main/webapp/META-INF/permissions.xml
@@ -28,48 +28,13 @@
-
- Get device
- /device-mgt/user/devices/list
- /enrollment/devices/*
- GET
- virtual_firealarm_user
-
-
- Remove device
- /device-mgt/user/devices/remove
- /enrollment/devices/*
- DELETE
- virtual_firealarm_user
-
Download device
- /device-mgt/virtual_firealarm/user
- /enrollment/devices/download
+ /device-mgt/user/devices
+ /device/download
GET
virtual_firealarm_user
-
- Update device
- /device-mgt/user/devices/update
- /enrollment/devices/*
- POST
- virtual_firealarm_user
-
-
- Get Devices
- /device-mgt/user/devices/list
- /enrollment/devices
- GET
- virtual_firealarm_user
-
-
- Register Device
- /device-mgt/user/operations
- /device/register/*/*/*
- POST
- virtual_firealarm_device
-
Control Buzz
/device-mgt/user/operations
@@ -77,13 +42,6 @@
POST
virtual_firealarm_user
-
- Push Temperature
- /device-mgt/user/stats
- /device/temperature
- POST
- virtual_firealarm_device
-
Get Stats
/device-mgt/user/stats
diff --git a/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.api/src/main/webapp/WEB-INF/cxf-servlet.xml b/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.api/src/main/webapp/WEB-INF/cxf-servlet.xml
index dd9427cea0..37a69c2682 100644
--- a/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.api/src/main/webapp/WEB-INF/cxf-servlet.xml
+++ b/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.api/src/main/webapp/WEB-INF/cxf-servlet.xml
@@ -25,11 +25,8 @@
-
-
-
+
diff --git a/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/plugin/constants/VirtualFireAlarmConstants.java b/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/plugin/constants/VirtualFireAlarmConstants.java
index 64d4e50fd5..693eb3524f 100644
--- a/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/plugin/constants/VirtualFireAlarmConstants.java
+++ b/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/plugin/constants/VirtualFireAlarmConstants.java
@@ -80,11 +80,12 @@ public class VirtualFireAlarmConstants {
public static final String IS_ENABLED_KEY = "enabled";
public static final String HOST_KEY = "host";
public static final String PORT_KEY = "port";
- public static final String CONNECTION_PORT = "connection.port";
public static final String ADMIN_USERNAME = "admin.username";
public static final String ADMIN_PASSWORD = "admin.password";
public static final String XMPP_SERVER_PASSWORD = "admin@123456789";
+ public static final String SERVER_NAME = "serverName";
+
public static final String MQTT_CONFIG_LOCATION = CarbonUtils.getEtcCarbonConfigDirPath() + File.separator
+ "mqtt.properties";
public static final String XMPP_CONFIG_LOCATION = CarbonUtils.getEtcCarbonConfigDirPath() + File.separator
diff --git a/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/plugin/impl/util/VirtualFireAlarmUtils.java b/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/plugin/impl/util/VirtualFireAlarmUtils.java
index 011334538d..16189c2633 100644
--- a/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/plugin/impl/util/VirtualFireAlarmUtils.java
+++ b/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/plugin/impl/util/VirtualFireAlarmUtils.java
@@ -38,6 +38,8 @@ 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 org.json.JSONObject;
+import org.wso2.carbon.utils.NetworkUtils;
+
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
@@ -45,6 +47,7 @@ import javax.sql.DataSource;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
+import java.net.SocketException;
import java.security.PublicKey;
import java.security.cert.X509Certificate;
import java.sql.Connection;
@@ -359,7 +362,8 @@ public class VirtualFireAlarmUtils {
xmppAdapterProperties.put(VirtualFireAlarmConstants.PORT_KEY, String.valueOf(xmppConfig.getXmppServerPort()));
xmppAdapterProperties.put(VirtualFireAlarmConstants.USERNAME_PROPERTY_KEY, xmppConfig.getVirtualFirealarmAdminUsername());
xmppAdapterProperties.put(VirtualFireAlarmConstants.PASSWORD_PROPERTY_KEY, xmppConfig.getVirtualFirealarmAdminPassword());
- xmppAdapterProperties.put(VirtualFireAlarmConstants.JID_PROPERTY_KEY, xmppConfig.getVirtualFirealarmAdminJID());
+ xmppAdapterProperties.put(VirtualFireAlarmConstants.JID_PROPERTY_KEY, xmppConfig.getVirtualFirealarmAdminJID()
+ + "/input-adapter");
xmppAdapterProperties.put(VirtualFireAlarmConstants.CONTENT_TRANSFORMATION,
VirtualFirealarmXmppContentTransformer.class.getName());
xmppAdapterProperties.put(VirtualFireAlarmConstants.CONTENT_VALIDATION, "default");
@@ -397,7 +401,8 @@ public class VirtualFireAlarmUtils {
xmppAdapterProperties.put(VirtualFireAlarmConstants.PORT_KEY, String.valueOf(xmppConfig.getXmppServerPort()));
xmppAdapterProperties.put(VirtualFireAlarmConstants.USERNAME_PROPERTY_KEY, xmppConfig.getVirtualFirealarmAdminUsername());
xmppAdapterProperties.put(VirtualFireAlarmConstants.PASSWORD_PROPERTY_KEY, xmppConfig.getVirtualFirealarmAdminPassword());
- xmppAdapterProperties.put(VirtualFireAlarmConstants.JID_PROPERTY_KEY, xmppConfig.getVirtualFirealarmAdminJID());
+ xmppAdapterProperties.put(VirtualFireAlarmConstants.JID_PROPERTY_KEY, xmppConfig.getVirtualFirealarmAdminJID()
+ + "/output-adapter");
outputEventAdapterConfiguration.setStaticProperties(xmppAdapterProperties);
return outputEventAdapterConfiguration;
}
diff --git a/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/plugin/impl/util/VirtualFirealarmEventAdapterSubscription.java b/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/plugin/impl/util/VirtualFirealarmEventAdapterSubscription.java
index ee3ec6a6ed..25489d9b55 100644
--- a/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/plugin/impl/util/VirtualFirealarmEventAdapterSubscription.java
+++ b/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/plugin/impl/util/VirtualFirealarmEventAdapterSubscription.java
@@ -14,6 +14,9 @@ public class VirtualFirealarmEventAdapterSubscription implements InputEventAdapt
if (actualMessage.contains("PUBLISHER")) {
float temperature = Float.parseFloat(actualMessage.split(":")[2]);
VirtualFireAlarmUtils.publishToDAS(deviceId, temperature);
+ } else {
+ float temperature = Float.parseFloat(actualMessage.split(":")[1]);
+ VirtualFireAlarmUtils.publishToDAS(deviceId, temperature);
}
}
}
diff --git a/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/plugin/xmpp/XmppConfig.java b/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/plugin/xmpp/XmppConfig.java
index 3a0eebebbb..12f9b5fcc7 100644
--- a/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/plugin/xmpp/XmppConfig.java
+++ b/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/plugin/xmpp/XmppConfig.java
@@ -21,6 +21,7 @@ package org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin.xmpp;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin.constants.VirtualFireAlarmConstants;
+import org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin.impl.util.VirtualFireAlarmUtils;
import java.io.File;
import java.io.IOException;
@@ -37,6 +38,7 @@ public class XmppConfig {
private String virtualFirealarmAdminUsername;
private String virtualFirealarmAdminPassword;
private String virtualFirealarmAdminJID;
+ private String xmppServerName;
private static XmppConfig xmppConfig = new XmppConfig();
private static final Log log = LogFactory.getLog(XmppConfig.class);
@@ -48,12 +50,13 @@ public class XmppConfig {
Properties properties = new Properties();
properties.load(propertyStream);
xmppServerIP = properties.getProperty(VirtualFireAlarmConstants.HOST_KEY);
+ xmppServerName = properties.getProperty(VirtualFireAlarmConstants.SERVER_NAME);
xmppServerPort = Integer.parseInt(properties.getProperty(VirtualFireAlarmConstants.PORT_KEY));
isEnabled = Boolean.parseBoolean(properties.getProperty(VirtualFireAlarmConstants.IS_ENABLED_KEY));
xmppUsername = properties.getProperty(VirtualFireAlarmConstants.ADMIN_USERNAME);
xmppPassword = properties.getProperty(VirtualFireAlarmConstants.ADMIN_PASSWORD);
virtualFirealarmAdminUsername = "wso2admin_" + VirtualFireAlarmConstants.DEVICE_TYPE;
- virtualFirealarmAdminJID = virtualFirealarmAdminUsername + "@" + xmppServerIP;
+ virtualFirealarmAdminJID = virtualFirealarmAdminUsername + "@" + xmppServerName;
virtualFirealarmAdminPassword = VirtualFireAlarmConstants.XMPP_SERVER_PASSWORD;
} catch (IOException e) {
log.error(e);
@@ -97,4 +100,7 @@ public class XmppConfig {
return virtualFirealarmAdminJID;
}
+ public String getXmppServerName() {
+ return xmppServerName;
+ }
}
diff --git a/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/plugin/xmpp/XmppServerClient.java b/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/plugin/xmpp/XmppServerClient.java
index fccb6c70ad..e2607b71ab 100644
--- a/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/plugin/xmpp/XmppServerClient.java
+++ b/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/plugin/xmpp/XmppServerClient.java
@@ -18,8 +18,6 @@
package org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin.xmpp;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
import org.jivesoftware.smack.AccountManager;
import org.jivesoftware.smack.ConnectionConfiguration;
import org.jivesoftware.smack.XMPPConnection;
@@ -36,7 +34,8 @@ public class XmppServerClient {
if (xmppAccount != null) {
try {
ConnectionConfiguration config = new ConnectionConfiguration(XmppConfig.getInstance().getXmppServerIP(),
- XmppConfig.getInstance().getXmppServerPort());
+ XmppConfig.getInstance().getXmppServerPort(),
+ "Accounts");
XMPPConnection xmppConnection = new XMPPConnection(config);
xmppConnection.connect();
xmppConnection.login(XmppConfig.getInstance().getXmppUsername(), XmppConfig.getInstance().getXmppPassword());
diff --git a/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/plugin/xmpp/XmppUtil.java b/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/plugin/xmpp/XmppUtil.java
index fa6f3c0896..4e60862b84 100644
--- a/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/plugin/xmpp/XmppUtil.java
+++ b/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/plugin/xmpp/XmppUtil.java
@@ -32,10 +32,10 @@ public class XmppUtil {
XmppServerClient xmppServerClient = new XmppServerClient();
try {
XmppAccount xmppAccount = new XmppAccount();
- xmppAccount.setAccountName(XmppConfig.getInstance().getVirtualFirealarmAdminJID());
+ xmppAccount.setAccountName(XmppConfig.getInstance().getVirtualFirealarmAdminUsername());
xmppAccount.setUsername(XmppConfig.getInstance().getVirtualFirealarmAdminUsername());
xmppAccount.setPassword(XmppConfig.getInstance().getVirtualFirealarmAdminPassword());
- xmppAccount.setEmail("");
+ xmppAccount.setEmail(XmppConfig.getInstance().getVirtualFirealarmAdminJID());
xmppServerClient.createAccount(xmppAccount);
} catch (VirtualFirealarmDeviceMgtPluginException e) {
String errorMsg = "An error was encountered whilst trying to create Server XMPP account for device-type - "
diff --git a/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.virtual_firealarm.device-view/device-view.js b/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.virtual_firealarm.device-view/device-view.js
index 2009b37fcb..4dd97dd238 100644
--- a/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.virtual_firealarm.device-view/device-view.js
+++ b/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.virtual_firealarm.device-view/device-view.js
@@ -21,8 +21,7 @@ function onRequest(context) {
var deviceType = context.uriParams.deviceType;
var deviceId = request.getParameter("id");
var autoCompleteParams = [
- {"name" : "deviceId", "value" : deviceId},
- {"name" : "protocol", "value" : "MQTT"}
+ {"name" : "deviceId", "value" : deviceId}
];
if (deviceType != null && deviceType != undefined && deviceId != null && deviceId != undefined) {
diff --git a/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.virtual_firealarm.type-view/private/config.json b/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.virtual_firealarm.type-view/private/config.json
index b8435cd39b..e149dddb78 100644
--- a/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.virtual_firealarm.type-view/private/config.json
+++ b/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.virtual_firealarm.type-view/private/config.json
@@ -2,6 +2,6 @@
"deviceType": {
"label": "Virtual Firealarm",
"category": "virtual",
- "downloadAgentUri": "virtual_firealarm/enrollment/devices/download"
+ "downloadAgentUri": "virtual_firealarm/device/download"
}
}
\ No newline at end of file
diff --git a/features/iot-plugins-feature/iot-base-plugin-feature/org.wso2.carbon.device.mgt.iot.feature/src/main/resources/conf/xmpp.properties b/features/iot-plugins-feature/iot-base-plugin-feature/org.wso2.carbon.device.mgt.iot.feature/src/main/resources/conf/xmpp.properties
index 23e272d69f..c85a6e6b56 100644
--- a/features/iot-plugins-feature/iot-base-plugin-feature/org.wso2.carbon.device.mgt.iot.feature/src/main/resources/conf/xmpp.properties
+++ b/features/iot-plugins-feature/iot-base-plugin-feature/org.wso2.carbon.device.mgt.iot.feature/src/main/resources/conf/xmpp.properties
@@ -2,4 +2,5 @@ enabled=false
host=localhost
port=5222
admin.username=admin
-admin.password=admin
\ No newline at end of file
+admin.password=admin
+serverName=localhost
\ No newline at end of file
diff --git a/features/iot-plugins-feature/virtual-fire-alarm-plugin-feature/org.wso2.carbon.device.mgt.iot.virtualfirealarm.feature/src/main/resources/advanced_agent/deviceConfig.properties b/features/iot-plugins-feature/virtual-fire-alarm-plugin-feature/org.wso2.carbon.device.mgt.iot.virtualfirealarm.feature/src/main/resources/advanced_agent/deviceConfig.properties
index 874f87585e..47a3a73a6c 100644
--- a/features/iot-plugins-feature/virtual-fire-alarm-plugin-feature/org.wso2.carbon.device.mgt.iot.virtualfirealarm.feature/src/main/resources/advanced_agent/deviceConfig.properties
+++ b/features/iot-plugins-feature/virtual-fire-alarm-plugin-feature/org.wso2.carbon.device.mgt.iot.virtualfirealarm.feature/src/main/resources/advanced_agent/deviceConfig.properties
@@ -31,5 +31,5 @@ auth-method=token
auth-token=${DEVICE_TOKEN}
refresh-token=${DEVICE_REFRESH_TOKEN}
push-interval=15
-
+xmpp-server-name=${SERVER_NAME}
diff --git a/features/iot-plugins-feature/virtual-fire-alarm-plugin-feature/org.wso2.carbon.device.mgt.iot.virtualfirealarm.feature/src/main/resources/agent/deviceConfig.properties b/features/iot-plugins-feature/virtual-fire-alarm-plugin-feature/org.wso2.carbon.device.mgt.iot.virtualfirealarm.feature/src/main/resources/agent/deviceConfig.properties
index 874f87585e..47a3a73a6c 100644
--- a/features/iot-plugins-feature/virtual-fire-alarm-plugin-feature/org.wso2.carbon.device.mgt.iot.virtualfirealarm.feature/src/main/resources/agent/deviceConfig.properties
+++ b/features/iot-plugins-feature/virtual-fire-alarm-plugin-feature/org.wso2.carbon.device.mgt.iot.virtualfirealarm.feature/src/main/resources/agent/deviceConfig.properties
@@ -31,5 +31,5 @@ auth-method=token
auth-token=${DEVICE_TOKEN}
refresh-token=${DEVICE_REFRESH_TOKEN}
push-interval=15
-
+xmpp-server-name=${SERVER_NAME}