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
index 271d6bd76..a195a5eae 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/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
@@ -81,7 +81,6 @@ public class AndroidSenseManagerServiceImpl implements AndroidSenseManagerServic
device.setEnrolmentInfo(enrolmentInfo);
boolean added = APIUtil.getDeviceManagementService().enrollDevice(device);
if (added) {
- APIUtil.registerApiAccessRoles(APIUtil.getAuthenticatedUser());
AndroidConfiguration androidConfiguration = new AndroidConfiguration();
androidConfiguration.setTenantDomain(APIUtil.getAuthenticatedUserTenantDomain());
String mqttEndpoint = MqttConfig.getInstance().getMqttQueueEndpoint();
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/util/APIUtil.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/util/APIUtil.java
index 01c661ee1..44df21241 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/util/APIUtil.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/util/APIUtil.java
@@ -175,45 +175,4 @@ public class APIUtil {
}
return deviceAccessAuthorizationService;
}
-
- public static void registerApiAccessRoles(String user) {
- UserStoreManager userStoreManager = null;
- try {
- userStoreManager = getUserStoreManager();
- String[] userList = new String[]{user};
- if (userStoreManager != null) {
- String rolesOfUser[] = userStoreManager.getRoleListOfUser(user);
- if (!userStoreManager.isExistingRole(Constants.DEFAULT_ROLE_NAME)) {
- userStoreManager.addRole(Constants.DEFAULT_ROLE_NAME, userList, Constants.DEFAULT_PERMISSION);
- } else if (rolesOfUser != null && Arrays.asList(rolesOfUser).contains(Constants.DEFAULT_ROLE_NAME)) {
- return;
- } else {
- userStoreManager.updateUserListOfRole(Constants.DEFAULT_ROLE_NAME, new String[0], userList);
- }
- }
- } catch (UserStoreException e) {
- log.error("Error while creating a role and adding a user for virtual_firealarm.", e);
- }
- }
-
- public static UserStoreManager getUserStoreManager() {
- RealmService realmService;
- UserStoreManager userStoreManager;
- try {
- PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext();
- realmService = (RealmService) ctx.getOSGiService(RealmService.class, null);
- if (realmService == null) {
- String msg = "Realm service has not initialized.";
- log.error(msg);
- throw new IllegalStateException(msg);
- }
- int tenantId = ctx.getTenantId();
- userStoreManager = realmService.getTenantUserRealm(tenantId).getUserStoreManager();
- } catch (UserStoreException e) {
- String msg = "Error occurred while retrieving current user store manager";
- log.error(msg, e);
- throw new IllegalStateException(msg);
- }
- return userStoreManager;
- }
}
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/util/Constants.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/util/Constants.java
index 9ad05580e..03415ddf1 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/util/Constants.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/util/Constants.java
@@ -24,10 +24,5 @@ import org.wso2.carbon.user.core.Permission;
* This hold the constants related to the device type.
*/
public class Constants {
-
- public static final String DEFAULT_PERMISSION_RESOURCE = "/permission/admin/device-mgt/android_sense/user";
- public static final String DEFAULT_ROLE_NAME = "android_sense_user";
- public static final Permission DEFAULT_PERMISSION[] = new Permission[]{new Permission(Constants.DEFAULT_PERMISSION_RESOURCE,
- "ui.execute")};
public static final String LOCALHOST = "localhost";
}
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 2f6762e14..26e63ecaf 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
@@ -30,56 +30,56 @@
Set words
- /device-mgt/android_sense/user
+ /device-mgt/user/operations
/device/*/words
POST
android_sense_user
set word threshold information
- /device-mgt/android_sense/user
+ /device-mgt/user/operations
/device/*/words/threshold
POST
android_sense_user
delete words
- /device-mgt/android_sense/user
+ /device-mgt/user/operations
/device/*/words
DELETE
android_sense_user
get device stats
- /device-mgt/android_sense/user
+ /device-mgt/user/stats
/stats/*/sensors/*
GET
android_sense_device
Get device
- /device-mgt/android_sense/user
+ /device-mgt/user/devices/list
/enrollment/devices/*
GET
android_sense_user
Add device
- /device-mgt/user
+ /device-mgt/user/devices
/enrollment/devices/*
POST
android_sense_user
Remove device
- /device-mgt/android_sense/user
+ /device-mgt/user/devices/remove
/enrollment/devices/*
DELETE
android_sense_user
Update device
- /device-mgt/android_sense/user
+ /device-mgt/user/devices/update
/enrollment/devices/*
PUT
android_sense_user
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/ArduinoManagerServiceImpl.java
index b1cfb00f4..c2e0cd30d 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/ArduinoManagerServiceImpl.java
@@ -246,12 +246,7 @@ public class ArduinoManagerServiceImpl implements ArduinoManagerService {
device.setType(ArduinoConstants.DEVICE_TYPE);
enrolmentInfo.setOwner(APIUtil.getAuthenticatedUser());
device.setEnrolmentInfo(enrolmentInfo);
- boolean added = APIUtil.getDeviceManagementService().enrollDevice(device);
- if (added) {
- APIUtil.registerApiAccessRoles(APIUtil.getAuthenticatedUser());
- return true;
- }
- return false;
+ return APIUtil.getDeviceManagementService().enrollDevice(device);
} catch (DeviceManagementException e) {
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/APIUtil.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/APIUtil.java
index 5f21e20f3..10f1ea92d 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/APIUtil.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/APIUtil.java
@@ -160,47 +160,6 @@ public class APIUtil {
return threadLocalCarbonContext.getTenantDomain();
}
- public static void registerApiAccessRoles(String user) {
- UserStoreManager userStoreManager = null;
- try {
- userStoreManager = getUserStoreManager();
- String[] userList = new String[]{user};
- if (userStoreManager != null) {
- String rolesOfUser[] = userStoreManager.getRoleListOfUser(user);
- if (!userStoreManager.isExistingRole(Constants.DEFAULT_ROLE_NAME)) {
- userStoreManager.addRole(Constants.DEFAULT_ROLE_NAME, userList, Constants.DEFAULT_PERMISSION);
- } else if (rolesOfUser != null && Arrays.asList(rolesOfUser).contains(Constants.DEFAULT_ROLE_NAME)) {
- return;
- } else {
- userStoreManager.updateUserListOfRole(Constants.DEFAULT_ROLE_NAME, new String[0], userList);
- }
- }
- } catch (UserStoreException e) {
- log.error("Error while creating a role and adding a user for virtual_firealarm.", e);
- }
- }
-
- public static UserStoreManager getUserStoreManager() {
- RealmService realmService;
- UserStoreManager userStoreManager;
- try {
- PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext();
- realmService = (RealmService) ctx.getOSGiService(RealmService.class, null);
- if (realmService == null) {
- String msg = "Realm service has not initialized.";
- log.error(msg);
- throw new IllegalStateException(msg);
- }
- int tenantId = ctx.getTenantId();
- userStoreManager = realmService.getTenantUserRealm(tenantId).getUserStoreManager();
- } catch (UserStoreException e) {
- String msg = "Error occurred while retrieving current user store manager";
- log.error(msg, e);
- throw new IllegalStateException(msg);
- }
- return userStoreManager;
- }
-
public static DeviceAccessAuthorizationService getDeviceAccessAuthorizationService() {
PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext();
DeviceAccessAuthorizationService deviceAccessAuthorizationService =
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/Constants.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/Constants.java
deleted file mode 100644
index 6b3bbbf4e..000000000
--- 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/Constants.java
+++ /dev/null
@@ -1,32 +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.util;
-
-import org.wso2.carbon.user.core.Permission;
-
-/**
- * This hold the constants related to the device type.
- */
-public class Constants {
-
- public static final String DEFAULT_PERMISSION_RESOURCE = "/permission/admin/device-mgt/arduino/user";
- public static final String DEFAULT_ROLE_NAME = "arduino_user";
- public static final Permission DEFAULT_PERMISSION[] = new Permission[]{new Permission(Constants.DEFAULT_PERMISSION_RESOURCE,
- "ui.execute")};
-}
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 9155da2f5..c59a0b979 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
@@ -31,49 +31,49 @@
control bulb
- /device-mgt/arduino/user
+ device-mgt/user/operations
/device/*/bulb
POST
arduino_user
get controls
- /device-mgt/arduino/user
+ device-mgt/user/operations
/device/*/controls
POST
arduino_device
get temperature stats
- /device-mgt/arduino/user
+ device-mgt/user/stats
/device/stats/*
GET
arduino_device
Get device
- /device-mgt/arduino/user
+ /device-mgt/user/devices/list
/enrollment/devices/*
GET
arduino_user
Remove device
- /device-mgt/arduino/user
+ /device-mgt/user/devices/remove
/enrollment/devices/*
DELETE
arduino_user
Download device
- /device-mgt/user
+ /device-mgt/user/devices
/enrollment/devices/download
GET
arduino_user
Update device
- /device-mgt/arduino/user
+ /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.plugin/src/main/java/org/wso2/carbon/device/mgt/iot/arduino/plugin/impl/ArduinoManager.java b/components/iot-plugins/arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.plugin/src/main/java/org/wso2/carbon/device/mgt/iot/arduino/plugin/impl/ArduinoManager.java
index 5c7174d96..35dbdb4ea 100644
--- a/components/iot-plugins/arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.plugin/src/main/java/org/wso2/carbon/device/mgt/iot/arduino/plugin/impl/ArduinoManager.java
+++ b/components/iot-plugins/arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.plugin/src/main/java/org/wso2/carbon/device/mgt/iot/arduino/plugin/impl/ArduinoManager.java
@@ -31,7 +31,7 @@ import org.wso2.carbon.device.mgt.common.configuration.mgt.TenantConfiguration;
import org.wso2.carbon.device.mgt.common.license.mgt.License;
import org.wso2.carbon.device.mgt.common.license.mgt.LicenseManagementException;
import org.wso2.carbon.device.mgt.iot.arduino.plugin.exception.ArduinoDeviceMgtPluginException;
-import org.wso2.carbon.device.mgt.iot.arduino.plugin.impl.dao.ArduinoDAO;
+import org.wso2.carbon.device.mgt.iot.arduino.plugin.impl.dao.ArduinoDAOUtil;
import org.wso2.carbon.device.mgt.iot.arduino.plugin.impl.feature.ArduinoFeatureManager;
import java.util.List;
@@ -41,7 +41,7 @@ import java.util.List;
*/
public class ArduinoManager implements DeviceManager {
- private static final ArduinoDAO arduinoDAO = new ArduinoDAO();
+ private static final ArduinoDAOUtil arduinoDAO = new ArduinoDAOUtil();
private static final Log log = LogFactory.getLog(ArduinoManager.class);
private ArduinoFeatureManager arduinoFeatureManager = new ArduinoFeatureManager();
@@ -70,12 +70,12 @@ public class ArduinoManager implements DeviceManager {
if (log.isDebugEnabled()) {
log.debug("Enrolling a new Arduino device : " + device.getDeviceIdentifier());
}
- ArduinoDAO.beginTransaction();
+ ArduinoDAOUtil.beginTransaction();
status = arduinoDAO.getDeviceDAO().addDevice(device);
- ArduinoDAO.commitTransaction();
+ ArduinoDAOUtil.commitTransaction();
} catch (ArduinoDeviceMgtPluginException e) {
try {
- ArduinoDAO.rollbackTransaction();
+ ArduinoDAOUtil.rollbackTransaction();
} catch (ArduinoDeviceMgtPluginException iotDAOEx) {
String msg = "Error occurred while roll back the device enrol transaction :" + device.toString();
log.warn(msg, iotDAOEx);
@@ -94,12 +94,12 @@ public class ArduinoManager implements DeviceManager {
if (log.isDebugEnabled()) {
log.debug("Modifying the Arduino device enrollment data");
}
- ArduinoDAO.beginTransaction();
+ ArduinoDAOUtil.beginTransaction();
status = arduinoDAO.getDeviceDAO().updateDevice(device);
- ArduinoDAO.commitTransaction();
+ ArduinoDAOUtil.commitTransaction();
} catch (ArduinoDeviceMgtPluginException e) {
try {
- ArduinoDAO.rollbackTransaction();
+ ArduinoDAOUtil.rollbackTransaction();
} catch (ArduinoDeviceMgtPluginException iotDAOEx) {
String msg = "Error occurred while roll back the update device transaction :" + device.toString();
log.warn(msg, iotDAOEx);
@@ -119,12 +119,12 @@ public class ArduinoManager implements DeviceManager {
if (log.isDebugEnabled()) {
log.debug("Dis-enrolling Arduino device : " + deviceId);
}
- ArduinoDAO.beginTransaction();
+ ArduinoDAOUtil.beginTransaction();
status = arduinoDAO.getDeviceDAO().deleteDevice(deviceId.getId());
- ArduinoDAO.commitTransaction();
+ ArduinoDAOUtil.commitTransaction();
} catch (ArduinoDeviceMgtPluginException e) {
try {
- ArduinoDAO.rollbackTransaction();
+ ArduinoDAOUtil.rollbackTransaction();
} catch (ArduinoDeviceMgtPluginException iotDAOEx) {
String msg = "Error occurred while roll back the device dis enrol transaction :" + deviceId.toString();
log.warn(msg, iotDAOEx);
@@ -222,12 +222,12 @@ public class ArduinoManager implements DeviceManager {
log.debug(
"updating the details of Arduino device : " + deviceIdentifier);
}
- ArduinoDAO.beginTransaction();
+ ArduinoDAOUtil.beginTransaction();
status = arduinoDAO.getDeviceDAO().updateDevice(device);
- ArduinoDAO.commitTransaction();
+ ArduinoDAOUtil.commitTransaction();
} catch (ArduinoDeviceMgtPluginException e) {
try {
- ArduinoDAO.rollbackTransaction();
+ ArduinoDAOUtil.rollbackTransaction();
} catch (ArduinoDeviceMgtPluginException iotDAOEx) {
String msg = "Error occurred while roll back the update device info transaction :" + device.toString();
log.warn(msg, iotDAOEx);
diff --git a/components/iot-plugins/arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.plugin/src/main/java/org/wso2/carbon/device/mgt/iot/arduino/plugin/impl/dao/ArduinoDAO.java b/components/iot-plugins/arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.plugin/src/main/java/org/wso2/carbon/device/mgt/iot/arduino/plugin/impl/dao/ArduinoDAOUtil.java
similarity index 93%
rename from components/iot-plugins/arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.plugin/src/main/java/org/wso2/carbon/device/mgt/iot/arduino/plugin/impl/dao/ArduinoDAO.java
rename to components/iot-plugins/arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.plugin/src/main/java/org/wso2/carbon/device/mgt/iot/arduino/plugin/impl/dao/ArduinoDAOUtil.java
index 133f0c74d..6e8895f4a 100644
--- a/components/iot-plugins/arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.plugin/src/main/java/org/wso2/carbon/device/mgt/iot/arduino/plugin/impl/dao/ArduinoDAO.java
+++ b/components/iot-plugins/arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.plugin/src/main/java/org/wso2/carbon/device/mgt/iot/arduino/plugin/impl/dao/ArduinoDAOUtil.java
@@ -22,7 +22,7 @@ import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.device.mgt.iot.arduino.plugin.constants.ArduinoConstants;
import org.wso2.carbon.device.mgt.iot.arduino.plugin.exception.ArduinoDeviceMgtPluginException;
-import org.wso2.carbon.device.mgt.iot.arduino.plugin.impl.dao.impl.ArduinoDeviceDAOImpl;
+
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
@@ -30,13 +30,13 @@ import javax.sql.DataSource;
import java.sql.Connection;
import java.sql.SQLException;
-public class ArduinoDAO {
+public class ArduinoDAOUtil {
- private static final Log log = LogFactory.getLog(ArduinoDAO.class);
+ private static final Log log = LogFactory.getLog(ArduinoDAOUtil.class);
static DataSource dataSource;
private static ThreadLocal currentConnection = new ThreadLocal();
- public ArduinoDAO() {
+ public ArduinoDAOUtil() {
initArduinoDAO();
}
@@ -49,8 +49,8 @@ public class ArduinoDAO {
}
}
- public ArduinoDeviceDAOImpl getDeviceDAO() {
- return new ArduinoDeviceDAOImpl();
+ public ArduinoDeviceDAO getDeviceDAO() {
+ return new ArduinoDeviceDAO();
}
public static void beginTransaction() throws ArduinoDeviceMgtPluginException {
diff --git a/components/iot-plugins/arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.plugin/src/main/java/org/wso2/carbon/device/mgt/iot/arduino/plugin/impl/dao/impl/ArduinoDeviceDAOImpl.java b/components/iot-plugins/arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.plugin/src/main/java/org/wso2/carbon/device/mgt/iot/arduino/plugin/impl/dao/ArduinoDeviceDAO.java
similarity index 93%
rename from components/iot-plugins/arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.plugin/src/main/java/org/wso2/carbon/device/mgt/iot/arduino/plugin/impl/dao/impl/ArduinoDeviceDAOImpl.java
rename to components/iot-plugins/arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.plugin/src/main/java/org/wso2/carbon/device/mgt/iot/arduino/plugin/impl/dao/ArduinoDeviceDAO.java
index 1bb0f164f..411f88e10 100644
--- a/components/iot-plugins/arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.plugin/src/main/java/org/wso2/carbon/device/mgt/iot/arduino/plugin/impl/dao/impl/ArduinoDeviceDAOImpl.java
+++ b/components/iot-plugins/arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.plugin/src/main/java/org/wso2/carbon/device/mgt/iot/arduino/plugin/impl/dao/ArduinoDeviceDAO.java
@@ -16,7 +16,7 @@
* under the License.
*/
-package org.wso2.carbon.device.mgt.iot.arduino.plugin.impl.dao.impl;
+package org.wso2.carbon.device.mgt.iot.arduino.plugin.impl.dao;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -24,7 +24,7 @@ import org.wso2.carbon.device.mgt.common.Device;
import org.wso2.carbon.device.mgt.iot.arduino.plugin.exception.ArduinoDeviceMgtPluginException;
import org.wso2.carbon.device.mgt.iot.arduino.plugin.impl.util.ArduinoUtils;
import org.wso2.carbon.device.mgt.iot.arduino.plugin.constants.ArduinoConstants;
-import org.wso2.carbon.device.mgt.iot.arduino.plugin.impl.dao.ArduinoDAO;
+
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
@@ -35,10 +35,10 @@ import java.util.List;
/**
* Implements CRUD for arduino Devices.
*/
-public class ArduinoDeviceDAOImpl {
+public class ArduinoDeviceDAO {
- private static final Log log = LogFactory.getLog(ArduinoDeviceDAOImpl.class);
+ private static final Log log = LogFactory.getLog(ArduinoDeviceDAO.class);
public Device getDevice(String deviceId) throws ArduinoDeviceMgtPluginException {
Connection conn = null;
@@ -46,7 +46,7 @@ public class ArduinoDeviceDAOImpl {
Device device = null;
ResultSet resultSet = null;
try {
- conn = ArduinoDAO.getConnection();
+ conn = ArduinoDAOUtil.getConnection();
String selectDBQuery =
"SELECT ARDUINO_DEVICE_ID, DEVICE_NAME FROM ARDUINO_DEVICE WHERE ARDUINO_DEVICE_ID = ?";
stmt = conn.prepareStatement(selectDBQuery);
@@ -67,7 +67,7 @@ public class ArduinoDeviceDAOImpl {
throw new ArduinoDeviceMgtPluginException(msg, e);
} finally {
ArduinoUtils.cleanupResources(stmt, resultSet);
- ArduinoDAO.closeConnection();
+ ArduinoDAOUtil.closeConnection();
}
return device;
}
@@ -77,7 +77,7 @@ public class ArduinoDeviceDAOImpl {
Connection conn = null;
PreparedStatement stmt = null;
try {
- conn = ArduinoDAO.getConnection();
+ conn = ArduinoDAOUtil.getConnection();
String createDBQuery =
"INSERT INTO ARDUINO_DEVICE(ARDUINO_DEVICE_ID, DEVICE_NAME) VALUES (?, ?)";
@@ -108,7 +108,7 @@ public class ArduinoDeviceDAOImpl {
Connection conn = null;
PreparedStatement stmt = null;
try {
- conn = ArduinoDAO.getConnection();
+ conn = ArduinoDAOUtil.getConnection();
String updateDBQuery =
"UPDATE ARDUINO_DEVICE SET DEVICE_NAME = ? WHERE ARDUINO_DEVICE_ID = ?";
@@ -139,7 +139,7 @@ public class ArduinoDeviceDAOImpl {
Connection conn = null;
PreparedStatement stmt = null;
try {
- conn = ArduinoDAO.getConnection();
+ conn = ArduinoDAOUtil.getConnection();
String deleteDBQuery =
"DELETE FROM ARDUINO_DEVICE WHERE ARDUINO_DEVICE_ID = ?";
stmt = conn.prepareStatement(deleteDBQuery);
@@ -170,7 +170,7 @@ public class ArduinoDeviceDAOImpl {
Device device;
List devices = new ArrayList();
try {
- conn = ArduinoDAO.getConnection();
+ conn = ArduinoDAOUtil.getConnection();
String selectDBQuery =
"SELECT ARDUINO_DEVICE_ID, DEVICE_NAME FROM ARDUINO_DEVICE";
stmt = conn.prepareStatement(selectDBQuery);
@@ -190,7 +190,7 @@ public class ArduinoDeviceDAOImpl {
throw new ArduinoDeviceMgtPluginException(msg, e);
} finally {
ArduinoUtils.cleanupResources(stmt, resultSet);
- ArduinoDAO.closeConnection();
+ ArduinoDAOUtil.closeConnection();
}
}
}
\ No newline at end of file
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 37b89b0c1..6813569dd 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
@@ -59,7 +59,7 @@
Get Devices
- /device-mgt/user/devices/devices
+ /device-mgt/user/devices/list
/enrollment/devices
GET
raspberrypi_user
@@ -73,7 +73,7 @@
Get Temperature Data
- /device-mgt/user/operations
+ /device-mgt/user/stats
/device/stats/*
GET
raspberrypi_user
diff --git a/components/iot-plugins/raspberrypi-plugin/org.wso2.carbon.device.mgt.iot.raspberrypi.plugin/src/main/java/org/wso2/carbon/device/mgt/iot/raspberrypi/plugin/impl/RaspberrypiManager.java b/components/iot-plugins/raspberrypi-plugin/org.wso2.carbon.device.mgt.iot.raspberrypi.plugin/src/main/java/org/wso2/carbon/device/mgt/iot/raspberrypi/plugin/impl/RaspberrypiManager.java
index 098438d46..98d3959f0 100644
--- a/components/iot-plugins/raspberrypi-plugin/org.wso2.carbon.device.mgt.iot.raspberrypi.plugin/src/main/java/org/wso2/carbon/device/mgt/iot/raspberrypi/plugin/impl/RaspberrypiManager.java
+++ b/components/iot-plugins/raspberrypi-plugin/org.wso2.carbon.device.mgt.iot.raspberrypi.plugin/src/main/java/org/wso2/carbon/device/mgt/iot/raspberrypi/plugin/impl/RaspberrypiManager.java
@@ -30,7 +30,7 @@ import org.wso2.carbon.device.mgt.common.configuration.mgt.TenantConfiguration;
import org.wso2.carbon.device.mgt.common.license.mgt.License;
import org.wso2.carbon.device.mgt.common.license.mgt.LicenseManagementException;
import org.wso2.carbon.device.mgt.iot.raspberrypi.plugin.exception.RaspberrypiDeviceMgtPluginException;
-import org.wso2.carbon.device.mgt.iot.raspberrypi.plugin.impl.dao.RaspberrypiDAO;
+import org.wso2.carbon.device.mgt.iot.raspberrypi.plugin.impl.dao.RaspberrypiDAOUtil;
import java.util.List;
/**
@@ -38,7 +38,7 @@ import java.util.List;
*/
public class RaspberrypiManager implements DeviceManager {
- private static final RaspberrypiDAO raspberrypiDAO = new RaspberrypiDAO();
+ private static final RaspberrypiDAOUtil raspberrypiDAO = new RaspberrypiDAOUtil();
private static final Log log = LogFactory.getLog(RaspberrypiManager.class);
@Override
@@ -64,12 +64,12 @@ public class RaspberrypiManager implements DeviceManager {
if (log.isDebugEnabled()) {
log.debug("Enrolling a new Raspberrypi device : " + device.getDeviceIdentifier());
}
- RaspberrypiDAO.beginTransaction();
+ RaspberrypiDAOUtil.beginTransaction();
status = raspberrypiDAO.getDeviceDAO().addDevice(device);
- RaspberrypiDAO.commitTransaction();
+ RaspberrypiDAOUtil.commitTransaction();
} catch (RaspberrypiDeviceMgtPluginException e) {
try {
- RaspberrypiDAO.rollbackTransaction();
+ RaspberrypiDAOUtil.rollbackTransaction();
} catch (RaspberrypiDeviceMgtPluginException iotDAOEx) {
String msg = "Error occurred while roll back the device enrol transaction :" + device.toString();
log.warn(msg, iotDAOEx);
@@ -88,12 +88,12 @@ public class RaspberrypiManager implements DeviceManager {
if (log.isDebugEnabled()) {
log.debug("Modifying the Raspberrypi device enrollment data");
}
- RaspberrypiDAO.beginTransaction();
+ RaspberrypiDAOUtil.beginTransaction();
status = raspberrypiDAO.getDeviceDAO().updateDevice(device);
- RaspberrypiDAO.commitTransaction();
+ RaspberrypiDAOUtil.commitTransaction();
} catch (RaspberrypiDeviceMgtPluginException e) {
try {
- RaspberrypiDAO.rollbackTransaction();
+ RaspberrypiDAOUtil.rollbackTransaction();
} catch (RaspberrypiDeviceMgtPluginException iotDAOEx) {
String msg = "Error occurred while roll back the update device transaction :" + device.toString();
log.warn(msg, iotDAOEx);
@@ -113,12 +113,12 @@ public class RaspberrypiManager implements DeviceManager {
if (log.isDebugEnabled()) {
log.debug("Dis-enrolling Raspberrypi device : " + deviceId);
}
- RaspberrypiDAO.beginTransaction();
+ RaspberrypiDAOUtil.beginTransaction();
status = raspberrypiDAO.getDeviceDAO().deleteDevice(deviceId.getId());
- RaspberrypiDAO.commitTransaction();
+ RaspberrypiDAOUtil.commitTransaction();
} catch (RaspberrypiDeviceMgtPluginException e) {
try {
- RaspberrypiDAO.rollbackTransaction();
+ RaspberrypiDAOUtil.rollbackTransaction();
} catch (RaspberrypiDeviceMgtPluginException iotDAOEx) {
String msg = "Error occurred while roll back the device dis enrol transaction :" + deviceId.toString();
log.warn(msg, iotDAOEx);
@@ -216,12 +216,12 @@ public class RaspberrypiManager implements DeviceManager {
log.debug(
"updating the details of Raspberrypi device : " + deviceIdentifier);
}
- RaspberrypiDAO.beginTransaction();
+ RaspberrypiDAOUtil.beginTransaction();
status = raspberrypiDAO.getDeviceDAO().updateDevice(device);
- RaspberrypiDAO.commitTransaction();
+ RaspberrypiDAOUtil.commitTransaction();
} catch (RaspberrypiDeviceMgtPluginException e) {
try {
- RaspberrypiDAO.rollbackTransaction();
+ RaspberrypiDAOUtil.rollbackTransaction();
} catch (RaspberrypiDeviceMgtPluginException iotDAOEx) {
String msg = "Error occurred while roll back the update device info transaction :" + device.toString();
log.warn(msg, iotDAOEx);
diff --git a/components/iot-plugins/raspberrypi-plugin/org.wso2.carbon.device.mgt.iot.raspberrypi.plugin/src/main/java/org/wso2/carbon/device/mgt/iot/raspberrypi/plugin/impl/dao/RaspberrypiDAO.java b/components/iot-plugins/raspberrypi-plugin/org.wso2.carbon.device.mgt.iot.raspberrypi.plugin/src/main/java/org/wso2/carbon/device/mgt/iot/raspberrypi/plugin/impl/dao/RaspberrypiDAOUtil.java
similarity index 94%
rename from components/iot-plugins/raspberrypi-plugin/org.wso2.carbon.device.mgt.iot.raspberrypi.plugin/src/main/java/org/wso2/carbon/device/mgt/iot/raspberrypi/plugin/impl/dao/RaspberrypiDAO.java
rename to components/iot-plugins/raspberrypi-plugin/org.wso2.carbon.device.mgt.iot.raspberrypi.plugin/src/main/java/org/wso2/carbon/device/mgt/iot/raspberrypi/plugin/impl/dao/RaspberrypiDAOUtil.java
index cdd317743..3eb68ee79 100644
--- a/components/iot-plugins/raspberrypi-plugin/org.wso2.carbon.device.mgt.iot.raspberrypi.plugin/src/main/java/org/wso2/carbon/device/mgt/iot/raspberrypi/plugin/impl/dao/RaspberrypiDAO.java
+++ b/components/iot-plugins/raspberrypi-plugin/org.wso2.carbon.device.mgt.iot.raspberrypi.plugin/src/main/java/org/wso2/carbon/device/mgt/iot/raspberrypi/plugin/impl/dao/RaspberrypiDAOUtil.java
@@ -22,7 +22,7 @@ import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.device.mgt.iot.raspberrypi.plugin.exception.RaspberrypiDeviceMgtPluginException;
import org.wso2.carbon.device.mgt.iot.raspberrypi.plugin.constants.RaspberrypiConstants;
-import org.wso2.carbon.device.mgt.iot.raspberrypi.plugin.impl.dao.impl.RaspberrypiDeviceDAOImpl;
+
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
@@ -30,18 +30,18 @@ import javax.sql.DataSource;
import java.sql.Connection;
import java.sql.SQLException;
-public class RaspberrypiDAO {
+public class RaspberrypiDAOUtil {
- private static final Log log = LogFactory.getLog(RaspberrypiDAO.class);
+ private static final Log log = LogFactory.getLog(RaspberrypiDAOUtil.class);
static DataSource dataSource;
private static ThreadLocal currentConnection = new ThreadLocal();
- public RaspberrypiDAO() {
+ public RaspberrypiDAOUtil() {
initRaspberrypiDAO();
}
- public RaspberrypiDeviceDAOImpl getDeviceDAO() {
- return new RaspberrypiDeviceDAOImpl();
+ public RaspberrypiDeviceDAO getDeviceDAO() {
+ return new RaspberrypiDeviceDAO();
}
public static void initRaspberrypiDAO() {
diff --git a/components/iot-plugins/raspberrypi-plugin/org.wso2.carbon.device.mgt.iot.raspberrypi.plugin/src/main/java/org/wso2/carbon/device/mgt/iot/raspberrypi/plugin/impl/dao/impl/RaspberrypiDeviceDAOImpl.java b/components/iot-plugins/raspberrypi-plugin/org.wso2.carbon.device.mgt.iot.raspberrypi.plugin/src/main/java/org/wso2/carbon/device/mgt/iot/raspberrypi/plugin/impl/dao/RaspberrypiDeviceDAO.java
similarity index 93%
rename from components/iot-plugins/raspberrypi-plugin/org.wso2.carbon.device.mgt.iot.raspberrypi.plugin/src/main/java/org/wso2/carbon/device/mgt/iot/raspberrypi/plugin/impl/dao/impl/RaspberrypiDeviceDAOImpl.java
rename to components/iot-plugins/raspberrypi-plugin/org.wso2.carbon.device.mgt.iot.raspberrypi.plugin/src/main/java/org/wso2/carbon/device/mgt/iot/raspberrypi/plugin/impl/dao/RaspberrypiDeviceDAO.java
index ae9c22620..83cb3f51c 100644
--- a/components/iot-plugins/raspberrypi-plugin/org.wso2.carbon.device.mgt.iot.raspberrypi.plugin/src/main/java/org/wso2/carbon/device/mgt/iot/raspberrypi/plugin/impl/dao/impl/RaspberrypiDeviceDAOImpl.java
+++ b/components/iot-plugins/raspberrypi-plugin/org.wso2.carbon.device.mgt.iot.raspberrypi.plugin/src/main/java/org/wso2/carbon/device/mgt/iot/raspberrypi/plugin/impl/dao/RaspberrypiDeviceDAO.java
@@ -16,14 +16,13 @@
* under the License.
*/
-package org.wso2.carbon.device.mgt.iot.raspberrypi.plugin.impl.dao.impl;
+package org.wso2.carbon.device.mgt.iot.raspberrypi.plugin.impl.dao;
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.iot.raspberrypi.plugin.exception.RaspberrypiDeviceMgtPluginException;
import org.wso2.carbon.device.mgt.iot.raspberrypi.plugin.impl.util.RaspberrypiUtils;
-import org.wso2.carbon.device.mgt.iot.raspberrypi.plugin.impl.dao.RaspberrypiDAO;
import org.wso2.carbon.device.mgt.iot.raspberrypi.plugin.constants.RaspberrypiConstants;
import java.sql.Connection;
import java.sql.PreparedStatement;
@@ -35,9 +34,9 @@ import java.util.List;
/**
* Implements CRUD for Raspberrypi Devices.
*/
-public class RaspberrypiDeviceDAOImpl {
+public class RaspberrypiDeviceDAO {
- private static final Log log = LogFactory.getLog(RaspberrypiDeviceDAOImpl.class);
+ private static final Log log = LogFactory.getLog(RaspberrypiDeviceDAO.class);
public Device getDevice(String iotDeviceId) throws RaspberrypiDeviceMgtPluginException {
Connection conn;
@@ -45,7 +44,7 @@ public class RaspberrypiDeviceDAOImpl {
Device device = null;
ResultSet resultSet = null;
try {
- conn = RaspberrypiDAO.getConnection();
+ conn = RaspberrypiDAOUtil.getConnection();
String selectDBQuery =
"SELECT RASPBERRYPI_DEVICE_ID, DEVICE_NAME FROM RASPBERRYPI_DEVICE WHERE RASPBERRYPI_DEVICE_ID = ?";
stmt = conn.prepareStatement(selectDBQuery);
@@ -66,7 +65,7 @@ public class RaspberrypiDeviceDAOImpl {
throw new RaspberrypiDeviceMgtPluginException(msg, e);
} finally {
RaspberrypiUtils.cleanupResources(stmt, resultSet);
- RaspberrypiDAO.closeConnection();
+ RaspberrypiDAOUtil.closeConnection();
}
return device;
}
@@ -76,7 +75,7 @@ public class RaspberrypiDeviceDAOImpl {
Connection conn;
PreparedStatement stmt = null;
try {
- conn = RaspberrypiDAO.getConnection();
+ conn = RaspberrypiDAOUtil.getConnection();
String createDBQuery =
"INSERT INTO RASPBERRYPI_DEVICE(RASPBERRYPI_DEVICE_ID, DEVICE_NAME) VALUES (?, ?)";
@@ -107,7 +106,7 @@ public class RaspberrypiDeviceDAOImpl {
Connection conn;
PreparedStatement stmt = null;
try {
- conn = RaspberrypiDAO.getConnection();
+ conn = RaspberrypiDAOUtil.getConnection();
String updateDBQuery = "UPDATE RASPBERRYPI_DEVICE SET DEVICE_NAME = ? WHERE RASPBERRYPI_DEVICE_ID = ?";
stmt = conn.prepareStatement(updateDBQuery);
stmt.setString(1, device.getName());
@@ -136,7 +135,7 @@ public class RaspberrypiDeviceDAOImpl {
Connection conn;
PreparedStatement stmt = null;
try {
- conn = RaspberrypiDAO.getConnection();
+ conn = RaspberrypiDAOUtil.getConnection();
String deleteDBQuery = "DELETE FROM RASPBERRYPI_DEVICE WHERE RASPBERRYPI_DEVICE_ID = ?";
stmt = conn.prepareStatement(deleteDBQuery);
stmt.setString(1, iotDeviceId);
@@ -165,7 +164,7 @@ public class RaspberrypiDeviceDAOImpl {
Device device;
List devices = new ArrayList<>();
try {
- conn = RaspberrypiDAO.getConnection();
+ conn = RaspberrypiDAOUtil.getConnection();
String selectDBQuery = "SELECT RASPBERRYPI_DEVICE_ID, DEVICE_NAME FROM RASPBERRYPI_DEVICE";
stmt = conn.prepareStatement(selectDBQuery);
resultSet = stmt.executeQuery();
@@ -185,7 +184,7 @@ public class RaspberrypiDeviceDAOImpl {
throw new RaspberrypiDeviceMgtPluginException(msg, e);
} finally {
RaspberrypiUtils.cleanupResources(stmt, resultSet);
- RaspberrypiDAO.closeConnection();
+ RaspberrypiDAOUtil.closeConnection();
}
}
}
\ 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/util/APIUtil.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/APIUtil.java
index 7f5801056..8f2612ac4 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/APIUtil.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/APIUtil.java
@@ -160,47 +160,6 @@ public class APIUtil {
return threadLocalCarbonContext.getTenantDomain();
}
- public static UserStoreManager getUserStoreManager() {
- RealmService realmService;
- UserStoreManager userStoreManager;
- try {
- PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext();
- realmService = (RealmService) ctx.getOSGiService(RealmService.class, null);
- if (realmService == null) {
- String msg = "Realm service has not initialized.";
- log.error(msg);
- throw new IllegalStateException(msg);
- }
- int tenantId = ctx.getTenantId();
- userStoreManager = realmService.getTenantUserRealm(tenantId).getUserStoreManager();
- } catch (UserStoreException e) {
- String msg = "Error occurred while retrieving current user store manager";
- log.error(msg, e);
- throw new IllegalStateException(msg);
- }
- return userStoreManager;
- }
-
- public static void registerApiAccessRoles(String user) {
- UserStoreManager userStoreManager = null;
- try {
- userStoreManager = getUserStoreManager();
- String[] userList = new String[]{user};
- if (userStoreManager != null) {
- String rolesOfUser[] = userStoreManager.getRoleListOfUser(user);
- if (!userStoreManager.isExistingRole(Constants.DEFAULT_ROLE_NAME)) {
- userStoreManager.addRole(Constants.DEFAULT_ROLE_NAME, userList, Constants.DEFAULT_PERMISSION);
- } else if (rolesOfUser != null && Arrays.asList(rolesOfUser).contains(Constants.DEFAULT_ROLE_NAME)) {
- return;
- } else {
- userStoreManager.updateUserListOfRole(Constants.DEFAULT_ROLE_NAME, new String[0], userList);
- }
- }
- } catch (UserStoreException e) {
- log.error("Error while creating a role and adding a user for virtual_firealarm.", e);
- }
- }
-
public static DeviceAccessAuthorizationService getDeviceAccessAuthorizationService() {
PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext();
DeviceAccessAuthorizationService deviceAccessAuthorizationService =
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/Constants.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/Constants.java
deleted file mode 100644
index 97ae2b8f8..000000000
--- 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/Constants.java
+++ /dev/null
@@ -1,32 +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.util;
-
-import org.wso2.carbon.user.core.Permission;
-
-/**
- * This hold the constants related to the device type.
- */
-public class Constants {
-
- public static final String DEFAULT_PERMISSION_RESOURCE = "/permission/admin/device-mgt/virtual_firealarm/user";
- public static final String DEFAULT_ROLE_NAME = "virtual_firealarm_user";
- public static final Permission DEFAULT_PERMISSION[] = new Permission[]{new Permission(Constants.DEFAULT_PERMISSION_RESOURCE,
- "ui.execute")};
-}
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 7f0067726..5bfa0a85e 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
@@ -30,14 +30,14 @@
Get device
- /device-mgt/virtual_firealarm/user
+ /device-mgt/user/devices/list
/enrollment/devices/*
GET
virtual_firealarm_user
Remove device
- /device-mgt/virtual_firealarm/user
+ /device-mgt/user/devices/remove
/enrollment/devices/*
DELETE
virtual_firealarm_user
@@ -51,42 +51,42 @@
Update device
- /device-mgt/virtual_firealarm/user
+ /device-mgt/user/devices/update
/enrollment/devices/*
POST
virtual_firealarm_user
Get Devices
- /device-mgt/virtual_firealarm/user
+ /device-mgt/user/devices/list
/enrollment/devices
GET
virtual_firealarm_user
Register Device
- /device-mgt/virtual_firealarm/user
+ /device-mgt/user/operations
/device/register/*/*/*
POST
virtual_firealarm_device
Control Buzz
- /device-mgt/virtual_firealarm/user
+ /device-mgt/user/operations
/device/*/buzz
POST
virtual_firealarm_user
Push Temperature
- /device-mgt/virtual_firealarm/user
+ /device-mgt/user/stats
/device/temperature
POST
virtual_firealarm_device
Get Stats
- /device-mgt/virtual_firealarm/user
+ /device-mgt/user/stats
/device/stats/*
GET
virtual_firealarm_device
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/VirtualFireAlarmManager.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/VirtualFireAlarmManager.java
index a90c15359..557376624 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/VirtualFireAlarmManager.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/VirtualFireAlarmManager.java
@@ -30,7 +30,7 @@ import org.wso2.carbon.device.mgt.common.configuration.mgt.TenantConfiguration;
import org.wso2.carbon.device.mgt.common.license.mgt.License;
import org.wso2.carbon.device.mgt.common.license.mgt.LicenseManagementException;
import org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin.exception.VirtualFirealarmDeviceMgtPluginException;
-import org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin.impl.dao.VirtualFireAlarmDAO;
+import org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin.impl.dao.VirtualFireAlarmDAOUtil;
import org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin.impl.feature.VirtualFirealarmFeatureManager;
import java.util.List;
@@ -40,7 +40,7 @@ import java.util.List;
*/
public class VirtualFireAlarmManager implements DeviceManager {
- private static final VirtualFireAlarmDAO virtualFireAlarmDAO = new VirtualFireAlarmDAO();
+ private static final VirtualFireAlarmDAOUtil virtualFireAlarmDAO = new VirtualFireAlarmDAOUtil();
private static final Log log = LogFactory.getLog(VirtualFireAlarmManager.class);
private FeatureManager virtualFirealarmFeatureManager = new VirtualFirealarmFeatureManager();
@@ -67,12 +67,12 @@ public class VirtualFireAlarmManager implements DeviceManager {
if (log.isDebugEnabled()) {
log.debug("Enrolling a new Virtual Firealarm device : " + device.getDeviceIdentifier());
}
- VirtualFireAlarmDAO.beginTransaction();
+ VirtualFireAlarmDAOUtil.beginTransaction();
status = virtualFireAlarmDAO.getDeviceDAO().addDevice(device);
- VirtualFireAlarmDAO.commitTransaction();
+ VirtualFireAlarmDAOUtil.commitTransaction();
} catch (VirtualFirealarmDeviceMgtPluginException e) {
try {
- VirtualFireAlarmDAO.rollbackTransaction();
+ VirtualFireAlarmDAOUtil.rollbackTransaction();
} catch (VirtualFirealarmDeviceMgtPluginException iotDAOEx) {
String msg = "Error occurred while roll back the device enrol transaction :" + device.toString();
log.warn(msg, iotDAOEx);
@@ -91,12 +91,12 @@ public class VirtualFireAlarmManager implements DeviceManager {
if (log.isDebugEnabled()) {
log.debug("Modifying the Virtual Firealarm device enrollment data");
}
- VirtualFireAlarmDAO.beginTransaction();
+ VirtualFireAlarmDAOUtil.beginTransaction();
status = virtualFireAlarmDAO.getDeviceDAO().updateDevice(device);
- VirtualFireAlarmDAO.commitTransaction();
+ VirtualFireAlarmDAOUtil.commitTransaction();
} catch (VirtualFirealarmDeviceMgtPluginException e) {
try {
- VirtualFireAlarmDAO.rollbackTransaction();
+ VirtualFireAlarmDAOUtil.rollbackTransaction();
} catch (VirtualFirealarmDeviceMgtPluginException iotDAOEx) {
String msg = "Error occurred while roll back the update device transaction :" + device.toString();
log.warn(msg, iotDAOEx);
@@ -116,12 +116,12 @@ public class VirtualFireAlarmManager implements DeviceManager {
if (log.isDebugEnabled()) {
log.debug("Dis-enrolling Virtual Firealarm device : " + deviceId);
}
- VirtualFireAlarmDAO.beginTransaction();
+ VirtualFireAlarmDAOUtil.beginTransaction();
status = virtualFireAlarmDAO.getDeviceDAO().deleteDevice(deviceId.getId());
- VirtualFireAlarmDAO.commitTransaction();
+ VirtualFireAlarmDAOUtil.commitTransaction();
} catch (VirtualFirealarmDeviceMgtPluginException e) {
try {
- VirtualFireAlarmDAO.rollbackTransaction();
+ VirtualFireAlarmDAOUtil.rollbackTransaction();
} catch (VirtualFirealarmDeviceMgtPluginException iotDAOEx) {
String msg = "Error occurred while roll back the device dis enrol transaction :" + deviceId.toString();
log.warn(msg, iotDAOEx);
@@ -219,12 +219,12 @@ public class VirtualFireAlarmManager implements DeviceManager {
log.debug(
"updating the details of Virtual Firealarm device : " + deviceIdentifier);
}
- VirtualFireAlarmDAO.beginTransaction();
+ VirtualFireAlarmDAOUtil.beginTransaction();
status = virtualFireAlarmDAO.getDeviceDAO().updateDevice(device);
- VirtualFireAlarmDAO.commitTransaction();
+ VirtualFireAlarmDAOUtil.commitTransaction();
} catch (VirtualFirealarmDeviceMgtPluginException e) {
try {
- VirtualFireAlarmDAO.rollbackTransaction();
+ VirtualFireAlarmDAOUtil.rollbackTransaction();
} catch (VirtualFirealarmDeviceMgtPluginException iotDAOEx) {
String msg = "Error occurred while roll back the update device info transaction :" + device.toString();
log.warn(msg, iotDAOEx);
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/dao/VirtualFireAlarmDAO.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/dao/VirtualFireAlarmDAOUtil.java
similarity index 93%
rename from 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/dao/VirtualFireAlarmDAO.java
rename to 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/dao/VirtualFireAlarmDAOUtil.java
index 8064c524e..a3ec4f274 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/dao/VirtualFireAlarmDAO.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/dao/VirtualFireAlarmDAOUtil.java
@@ -22,7 +22,7 @@ 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.exception.VirtualFirealarmDeviceMgtPluginException;
-import org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin.impl.dao.impl.VirtualFireAlarmDeviceDAOImpl;
+
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
@@ -30,13 +30,13 @@ import javax.sql.DataSource;
import java.sql.Connection;
import java.sql.SQLException;
-public class VirtualFireAlarmDAO {
+public class VirtualFireAlarmDAOUtil {
- private static final Log log = LogFactory.getLog(VirtualFireAlarmDAO.class);
+ private static final Log log = LogFactory.getLog(VirtualFireAlarmDAOUtil.class);
static DataSource dataSource;
private static ThreadLocal currentConnection = new ThreadLocal();
- public VirtualFireAlarmDAO() {
+ public VirtualFireAlarmDAOUtil() {
initFireAlarmDAO();
}
@@ -49,8 +49,8 @@ public class VirtualFireAlarmDAO {
}
}
- public VirtualFireAlarmDeviceDAOImpl getDeviceDAO() {
- return new VirtualFireAlarmDeviceDAOImpl();
+ public VirtualFireAlarmDeviceDAO getDeviceDAO() {
+ return new VirtualFireAlarmDeviceDAO();
}
public static void beginTransaction() throws VirtualFirealarmDeviceMgtPluginException {
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/dao/impl/VirtualFireAlarmDeviceDAOImpl.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/dao/VirtualFireAlarmDeviceDAO.java
similarity index 93%
rename from 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/dao/impl/VirtualFireAlarmDeviceDAOImpl.java
rename to 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/dao/VirtualFireAlarmDeviceDAO.java
index c4896b0ab..c20a83372 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/dao/impl/VirtualFireAlarmDeviceDAOImpl.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/dao/VirtualFireAlarmDeviceDAO.java
@@ -16,14 +16,13 @@
* under the License.
*/
-package org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin.impl.dao.impl;
+package org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin.impl.dao;
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.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.dao.VirtualFireAlarmDAO;
import org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin.impl.util.VirtualFireAlarmUtils;
import java.sql.Connection;
import java.sql.PreparedStatement;
@@ -35,9 +34,9 @@ import java.util.List;
/**
* Implements CRUD for virtual firealarm Devices.
*/
-public class VirtualFireAlarmDeviceDAOImpl {
+public class VirtualFireAlarmDeviceDAO {
- private static final Log log = LogFactory.getLog(VirtualFireAlarmDeviceDAOImpl.class);
+ private static final Log log = LogFactory.getLog(VirtualFireAlarmDeviceDAO.class);
public Device getDevice(String deviceId) throws VirtualFirealarmDeviceMgtPluginException {
Connection conn = null;
@@ -45,7 +44,7 @@ public class VirtualFireAlarmDeviceDAOImpl {
Device device = null;
ResultSet resultSet = null;
try {
- conn = VirtualFireAlarmDAO.getConnection();
+ conn = VirtualFireAlarmDAOUtil.getConnection();
String selectDBQuery =
"SELECT VIRTUAL_FIREALARM_DEVICE_ID, DEVICE_NAME" +
" FROM VIRTUAL_FIREALARM_DEVICE WHERE VIRTUAL_FIREALARM_DEVICE_ID = ?";
@@ -67,7 +66,7 @@ public class VirtualFireAlarmDeviceDAOImpl {
throw new VirtualFirealarmDeviceMgtPluginException(msg, e);
} finally {
VirtualFireAlarmUtils.cleanupResources(stmt, resultSet);
- VirtualFireAlarmDAO.closeConnection();
+ VirtualFireAlarmDAOUtil.closeConnection();
}
return device;
@@ -78,7 +77,7 @@ public class VirtualFireAlarmDeviceDAOImpl {
Connection conn = null;
PreparedStatement stmt = null;
try {
- conn = VirtualFireAlarmDAO.getConnection();
+ conn = VirtualFireAlarmDAOUtil.getConnection();
String createDBQuery =
"INSERT INTO VIRTUAL_FIREALARM_DEVICE(VIRTUAL_FIREALARM_DEVICE_ID, DEVICE_NAME) VALUES (?, ?)";
@@ -109,7 +108,7 @@ public class VirtualFireAlarmDeviceDAOImpl {
Connection conn = null;
PreparedStatement stmt = null;
try {
- conn = VirtualFireAlarmDAO.getConnection();
+ conn = VirtualFireAlarmDAOUtil.getConnection();
String updateDBQuery =
"UPDATE VIRTUAL_FIREALARM_DEVICE SET DEVICE_NAME = ? WHERE VIRTUAL_FIREALARM_DEVICE_ID = ?";
@@ -140,7 +139,7 @@ public class VirtualFireAlarmDeviceDAOImpl {
Connection conn = null;
PreparedStatement stmt = null;
try {
- conn = VirtualFireAlarmDAO.getConnection();
+ conn = VirtualFireAlarmDAOUtil.getConnection();
String deleteDBQuery = "DELETE FROM VIRTUAL_FIREALARM_DEVICE WHERE VIRTUAL_FIREALARM_DEVICE_ID = ?";
stmt = conn.prepareStatement(deleteDBQuery);
stmt.setString(1, iotDeviceId);
@@ -169,7 +168,7 @@ public class VirtualFireAlarmDeviceDAOImpl {
Device device;
List devices = new ArrayList<>();
try {
- conn = VirtualFireAlarmDAO.getConnection();
+ conn = VirtualFireAlarmDAOUtil.getConnection();
String selectDBQuery =
"SELECT VIRTUAL_FIREALARM_DEVICE_ID, DEVICE_NAME FROM VIRTUAL_FIREALARM_DEVICE";
stmt = conn.prepareStatement(selectDBQuery);
@@ -190,7 +189,7 @@ public class VirtualFireAlarmDeviceDAOImpl {
throw new VirtualFirealarmDeviceMgtPluginException(msg, e);
} finally {
VirtualFireAlarmUtils.cleanupResources(stmt, resultSet);
- VirtualFireAlarmDAO.closeConnection();
+ VirtualFireAlarmDAOUtil.closeConnection();
}
}
}
\ No newline at end of file