Merge pull request 'Improvements to the device sub type impl' (#248) from amalka.subasinghe/device-mgt-core:master into master

Reviewed-on: community/device-mgt-core#248
admin-role-isssue
commit 7a9869f044

@ -47,7 +47,7 @@ public class GetDeviceSubTypeCacheLoader extends CacheLoader<String, DeviceSubTy
DeviceSubTypeCacheKey deviceSubTypeCacheKey = DeviceSubTypeMgtUtil.getDeviceSubTypeCacheKey(key);
int tenantId = deviceSubTypeCacheKey.getTenantId();
String subTypeId = deviceSubTypeCacheKey.getSubTypeId();
DeviceSubType.DeviceType deviceType = deviceSubTypeCacheKey.getDeviceType();
String deviceType = deviceSubTypeCacheKey.getDeviceType();
if (log.isTraceEnabled()) {
log.trace("Loading Device subtype for " + deviceType + " subtype & subtype Id : " + subTypeId);

@ -26,20 +26,20 @@ import java.util.List;
public interface DeviceSubTypeDAO {
boolean addDeviceSubType(DeviceSubType deviceSubType) throws SubTypeMgtDAOException;
boolean updateDeviceSubType(String subTypeId, int tenantId, DeviceSubType.DeviceType deviceType, String subTypeName,
boolean updateDeviceSubType(String subTypeId, int tenantId, String deviceType, String subTypeName,
String typeDefinition) throws SubTypeMgtDAOException;
DeviceSubType getDeviceSubType(String subTypeId, int tenantId, DeviceSubType.DeviceType deviceType)
DeviceSubType getDeviceSubType(String subTypeId, int tenantId, String deviceType)
throws SubTypeMgtDAOException;
List<DeviceSubType> getAllDeviceSubTypes(int tenantId, DeviceSubType.DeviceType deviceType)
List<DeviceSubType> getAllDeviceSubTypes(int tenantId, String deviceType)
throws SubTypeMgtDAOException;
int getDeviceSubTypeCount(DeviceSubType.DeviceType deviceType) throws SubTypeMgtDAOException;
int getDeviceSubTypeCount(String deviceType) throws SubTypeMgtDAOException;
boolean checkDeviceSubTypeExist(String subTypeId, int tenantId, DeviceSubType.DeviceType deviceType)
boolean checkDeviceSubTypeExist(String subTypeId, int tenantId, String deviceType)
throws SubTypeMgtDAOException;
DeviceSubType getDeviceSubTypeByProvider(String subTypeName, int tenantId, DeviceSubType.DeviceType deviceType)
DeviceSubType getDeviceSubTypeByProvider(String subTypeName, int tenantId, String deviceType)
throws SubTypeMgtDAOException;
}

@ -26,10 +26,14 @@ import io.entgra.device.mgt.core.device.mgt.common.DeviceManagementConstants;
import io.entgra.device.mgt.core.subtype.mgt.dao.util.ConnectionManagerUtil;
import io.entgra.device.mgt.core.device.mgt.core.config.datasource.DataSourceConfig;
import javax.sql.DataSource;
import java.sql.SQLException;
public class DeviceSubTypeDAOFactory {
private static final Log log = LogFactory.getLog(DeviceSubTypeDAOFactory.class);
private static String databaseEngine;
private static DataSource dataSource;
public static void init(DataSourceConfig dataSourceConfiguration) {
if (log.isDebugEnabled()) {
log.debug("Initializing Device SubType Mgt Data Source");
@ -38,6 +42,17 @@ public class DeviceSubTypeDAOFactory {
databaseEngine = ConnectionManagerUtil.getDatabaseType();
}
public static void init(DataSource dtSource) {
dataSource = dtSource;
try {
databaseEngine = dataSource.getConnection().getMetaData().getDatabaseProductName();
} catch (SQLException var2) {
log.error("Error occurred while retrieving config.datasource connection", var2);
}
}
public static DeviceSubTypeDAO getDeviceSubTypeDAO() {
if (databaseEngine != null) {
//noinspection SwitchStatementWithTooFewBranches

@ -67,7 +67,7 @@ public class DeviceSubTypeDAOImpl implements DeviceSubTypeDAO {
}
@Override
public boolean updateDeviceSubType(String subTypeId, int tenantId, DeviceSubType.DeviceType deviceType,
public boolean updateDeviceSubType(String subTypeId, int tenantId, String deviceType,
String subTypeName, String typeDefinition)
throws SubTypeMgtDAOException {
try {
@ -80,7 +80,7 @@ public class DeviceSubTypeDAOImpl implements DeviceSubTypeDAO {
stmt.setString(2, subTypeName);
stmt.setString(3, subTypeId);
stmt.setInt(4, tenantId);
stmt.setString(5, deviceType.toString());
stmt.setString(5, deviceType);
return stmt.executeUpdate() > 0;
}
@ -98,7 +98,7 @@ public class DeviceSubTypeDAOImpl implements DeviceSubTypeDAO {
}
@Override
public DeviceSubType getDeviceSubType(String subTypeId, int tenantId, DeviceSubType.DeviceType deviceType)
public DeviceSubType getDeviceSubType(String subTypeId, int tenantId, String deviceType)
throws SubTypeMgtDAOException {
try {
String sql = "SELECT * FROM DM_DEVICE_SUB_TYPE WHERE SUB_TYPE_ID = ? AND TENANT_ID = ? AND DEVICE_TYPE = ?";
@ -107,7 +107,7 @@ public class DeviceSubTypeDAOImpl implements DeviceSubTypeDAO {
try (PreparedStatement stmt = conn.prepareStatement(sql)) {
stmt.setString(1, subTypeId);
stmt.setInt(2, tenantId);
stmt.setString(3, deviceType.toString());
stmt.setString(3, deviceType);
try (ResultSet rs = stmt.executeQuery()) {
if (rs.next()) {
return DAOUtil.loadDeviceSubType(rs);
@ -130,7 +130,7 @@ public class DeviceSubTypeDAOImpl implements DeviceSubTypeDAO {
}
@Override
public List<DeviceSubType> getAllDeviceSubTypes(int tenantId, DeviceSubType.DeviceType deviceType)
public List<DeviceSubType> getAllDeviceSubTypes(int tenantId, String deviceType)
throws SubTypeMgtDAOException {
try {
String sql = "SELECT * FROM DM_DEVICE_SUB_TYPE WHERE TENANT_ID = ? AND DEVICE_TYPE = ? ORDER BY " +
@ -139,7 +139,7 @@ public class DeviceSubTypeDAOImpl implements DeviceSubTypeDAO {
Connection conn = ConnectionManagerUtil.getDBConnection();
try (PreparedStatement stmt = conn.prepareStatement(sql)) {
stmt.setInt(1, tenantId);
stmt.setString(2, deviceType.toString());
stmt.setString(2, deviceType);
try (ResultSet rs = stmt.executeQuery()) {
return DAOUtil.loadDeviceSubTypes(rs);
}
@ -159,13 +159,13 @@ public class DeviceSubTypeDAOImpl implements DeviceSubTypeDAO {
}
@Override
public int getDeviceSubTypeCount(DeviceSubType.DeviceType deviceType) throws SubTypeMgtDAOException {
public int getDeviceSubTypeCount(String deviceType) throws SubTypeMgtDAOException {
try {
String sql = "SELECT COUNT(*) as DEVICE_COUNT FROM DM_DEVICE_SUB_TYPE WHERE DEVICE_TYPE = ? ";
Connection conn = ConnectionManagerUtil.getDBConnection();
try (PreparedStatement stmt = conn.prepareStatement(sql)) {
stmt.setString(1, deviceType.toString());
stmt.setString(1, deviceType);
try (ResultSet rs = stmt.executeQuery()) {
if (rs.next()) {
return rs.getInt("DEVICE_COUNT");
@ -188,7 +188,7 @@ public class DeviceSubTypeDAOImpl implements DeviceSubTypeDAO {
}
@Override
public boolean checkDeviceSubTypeExist(String subTypeId, int tenantId, DeviceSubType.DeviceType deviceType)
public boolean checkDeviceSubTypeExist(String subTypeId, int tenantId, String deviceType)
throws SubTypeMgtDAOException {
try {
String sql = "SELECT * FROM DM_DEVICE_SUB_TYPE WHERE SUB_TYPE_ID = ? AND TENANT_ID = ? AND DEVICE_TYPE " +
@ -198,7 +198,7 @@ public class DeviceSubTypeDAOImpl implements DeviceSubTypeDAO {
try (PreparedStatement stmt = conn.prepareStatement(sql)) {
stmt.setString(1, subTypeId);
stmt.setInt(2, tenantId);
stmt.setString(3, deviceType.toString());
stmt.setString(3, deviceType);
try (ResultSet rs = stmt.executeQuery()) {
return rs.next();
}
@ -219,7 +219,7 @@ public class DeviceSubTypeDAOImpl implements DeviceSubTypeDAO {
@Override
public DeviceSubType getDeviceSubTypeByProvider(String subTypeName, int tenantId,
DeviceSubType.DeviceType deviceType)
String deviceType)
throws SubTypeMgtDAOException {
try {
String sql = "SELECT * FROM DM_DEVICE_SUB_TYPE WHERE SUB_TYPE_NAME = ? AND TENANT_ID = ? AND DEVICE_TYPE " +
@ -229,7 +229,7 @@ public class DeviceSubTypeDAOImpl implements DeviceSubTypeDAO {
try (PreparedStatement stmt = conn.prepareStatement(sql)) {
stmt.setString(1, subTypeName);
stmt.setInt(2, tenantId);
stmt.setString(3, deviceType.toString());
stmt.setString(3, deviceType);
try (ResultSet rs = stmt.executeQuery()) {
if (rs.next()) {
return DAOUtil.loadDeviceSubType(rs);

@ -18,6 +18,7 @@
package io.entgra.device.mgt.core.subtype.mgt.dao.util;
import com.fasterxml.jackson.core.JsonProcessingException;
import io.entgra.device.mgt.core.subtype.mgt.dto.DeviceSubType;
import java.sql.ResultSet;
@ -30,17 +31,19 @@ public class DAOUtil {
public static DeviceSubType loadDeviceSubType(ResultSet rs) throws SQLException {
DeviceSubType deviceSubType = new DeviceSubType() {
@Override
public <T> DeviceSubType setDeviceSubType(T objType, String typeDef) {
public <T> DeviceSubType convertToDeviceSubType() {
return null;
}
@Override
public String parseSubTypeToJson(Object objType) { return null; }
public String parseSubTypeToJson() throws JsonProcessingException {
return null;
}
};
deviceSubType.setTenantId(rs.getInt("TENANT_ID"));
deviceSubType.setSubTypeId(rs.getString("SUB_TYPE_ID"));
deviceSubType.setSubTypeName(rs.getString("SUB_TYPE_NAME"));
deviceSubType.setDeviceType(DeviceSubType.DeviceType.valueOf(rs.getString("DEVICE_TYPE")));
deviceSubType.setDeviceType(rs.getString("DEVICE_TYPE"));
deviceSubType.setTypeDefinition(rs.getString("TYPE_DEFINITION"));
return deviceSubType;
}

@ -26,10 +26,21 @@ public abstract class DeviceSubType {
private String subTypeId;
private int tenantId;
private DeviceType deviceType;
private String deviceType;
private String subTypeName;
private String typeDefinition;
public DeviceSubType() {
}
public DeviceSubType(String subTypeId, int tenantId, String deviceType, String subTypeName, String typeDefinition) {
this.subTypeId = subTypeId;
this.tenantId = tenantId;
this.deviceType = deviceType;
this.subTypeName = subTypeName;
this.typeDefinition = typeDefinition;
}
public String getSubTypeId() {
return subTypeId;
}
@ -46,11 +57,11 @@ public abstract class DeviceSubType {
this.tenantId = tenantId;
}
public DeviceType getDeviceType() {
public String getDeviceType() {
return deviceType;
}
public void setDeviceType(DeviceType deviceType) {
public void setDeviceType(String deviceType) {
this.deviceType = deviceType;
}
@ -70,11 +81,8 @@ public abstract class DeviceSubType {
this.typeDefinition = typeDefinition;
}
public abstract <T> DeviceSubType setDeviceSubType(T objType, String typeDef);
public abstract <T> DeviceSubType convertToDeviceSubType();
public abstract String parseSubTypeToJson(Object objType) throws JsonProcessingException;
public abstract String parseSubTypeToJson() throws JsonProcessingException;
public enum DeviceType {
COM, METER, SIM
}
}

@ -21,7 +21,7 @@ package io.entgra.device.mgt.core.subtype.mgt.dto;
public class DeviceSubTypeCacheKey {
int tenantId;
String subTypeId;
DeviceSubType.DeviceType deviceType;
String deviceType;
public int getTenantId() {
return tenantId;
@ -39,11 +39,11 @@ public class DeviceSubTypeCacheKey {
this.subTypeId = subTypeId;
}
public DeviceSubType.DeviceType getDeviceType() {
public String getDeviceType() {
return deviceType;
}
public void setDeviceType(DeviceSubType.DeviceType deviceType) {
public void setDeviceType(String deviceType) {
this.deviceType = deviceType;
}
}

@ -93,7 +93,7 @@ public class DeviceSubTypeServiceImpl implements DeviceSubTypeService {
}
@Override
public boolean updateDeviceSubType(String subTypeId, int tenantId, DeviceSubType.DeviceType deviceType,
public boolean updateDeviceSubType(String subTypeId, int tenantId, String deviceType,
String subTypeName, String typeDefinition)
throws SubTypeMgtPluginException {
String msg = "";
@ -139,13 +139,13 @@ public class DeviceSubTypeServiceImpl implements DeviceSubTypeService {
}
@Override
public DeviceSubType getDeviceSubType(String subTypeId, int tenantId, DeviceSubType.DeviceType deviceType)
public DeviceSubType getDeviceSubType(String subTypeId, int tenantId, String deviceType)
throws SubTypeMgtPluginException {
try {
String key = DeviceSubTypeMgtUtil.setDeviceSubTypeCacheKey(tenantId, subTypeId, deviceType);
return deviceSubTypeCache.get(key);
} catch (CacheLoader.InvalidCacheLoadException e) {
String msg = "Not having any sim subtype for subtype id: " + subTypeId;
String msg = "Not having any" + deviceType + " subtype for subtype id: " + subTypeId;
log.error(msg, e);
return null;
} catch (ExecutionException e) {
@ -156,7 +156,7 @@ public class DeviceSubTypeServiceImpl implements DeviceSubTypeService {
}
@Override
public List<DeviceSubType> getAllDeviceSubTypes(int tenantId, DeviceSubType.DeviceType deviceType)
public List<DeviceSubType> getAllDeviceSubTypes(int tenantId, String deviceType)
throws SubTypeMgtPluginException {
try {
ConnectionManagerUtil.openDBConnection();
@ -177,20 +177,14 @@ public class DeviceSubTypeServiceImpl implements DeviceSubTypeService {
}
@Override
public int getDeviceSubTypeCount(DeviceSubType.DeviceType deviceType) throws SubTypeMgtPluginException {
public int getDeviceSubTypeCount(String deviceType) throws SubTypeMgtPluginException {
try {
ConnectionManagerUtil.openDBConnection();
int result = deviceSubTypeDAO.getDeviceSubTypeCount(deviceType);
if (result <= 0) {
String msg = "There are no any subtypes for device type: " + deviceType;
log.error(msg);
}
return result;
} catch (DBConnectionException e) {
String msg = "Error occurred while obtaining the database connection to retrieve device subtypes count " +
"for " + deviceType + " subtypes";
log.error(msg);
throw new SubTypeMgtPluginException(msg, e);
} catch (SubTypeMgtDAOException e) {
String msg = "Error occurred in the database level while retrieving device subtypes count for " + deviceType
+ " subtypes";
@ -203,16 +197,10 @@ public class DeviceSubTypeServiceImpl implements DeviceSubTypeService {
@Override
public DeviceSubType getDeviceSubTypeByProvider(String subTypeName, int tenantId,
DeviceSubType.DeviceType deviceType)
String deviceType)
throws SubTypeMgtPluginException {
try {
ConnectionManagerUtil.openDBConnection();
return deviceSubTypeDAO.getDeviceSubTypeByProvider(subTypeName, tenantId, deviceType);
} catch (DBConnectionException e) {
String msg = "Error occurred while obtaining the database connection to retrieve device subtype for " +
deviceType + " subtype & subtype name: " + subTypeName;
log.error(msg);
throw new SubTypeMgtPluginException(msg, e);
} catch (SubTypeMgtDAOException e) {
String msg = "Error occurred in the database level while retrieving device subtype for " + deviceType
+ " subtype & subtype name: " + subTypeName;
@ -224,16 +212,10 @@ public class DeviceSubTypeServiceImpl implements DeviceSubTypeService {
}
@Override
public boolean checkDeviceSubTypeExist(String subTypeId, int tenantId, DeviceSubType.DeviceType deviceType)
public boolean checkDeviceSubTypeExist(String subTypeId, int tenantId, String deviceType)
throws SubTypeMgtPluginException {
try {
ConnectionManagerUtil.openDBConnection();
return deviceSubTypeDAO.checkDeviceSubTypeExist(subTypeId, tenantId, deviceType);
} catch (DBConnectionException e) {
String msg = "Error occurred while obtaining the database connection to check device subtype exist for " +
deviceType + " subtype & subtype id: " + subTypeId;
log.error(msg);
throw new SubTypeMgtPluginException(msg, e);
} catch (SubTypeMgtDAOException e) {
String msg = "Error occurred in the database level while checking device subtype exist for " + deviceType
+ " subtype & subtype id: " + subTypeId;

@ -27,20 +27,20 @@ public interface DeviceSubTypeService {
boolean addDeviceSubType(DeviceSubType deviceSubType) throws SubTypeMgtPluginException;
boolean updateDeviceSubType(String subTypeId, int tenantId, DeviceSubType.DeviceType deviceType, String subTypeName,
boolean updateDeviceSubType(String subTypeId, int tenantId, String deviceType, String subTypeName,
String typeDefinition) throws SubTypeMgtPluginException;
DeviceSubType getDeviceSubType(String subTypeId, int tenantId, DeviceSubType.DeviceType deviceType)
DeviceSubType getDeviceSubType(String subTypeId, int tenantId, String deviceType)
throws SubTypeMgtPluginException;
List<DeviceSubType> getAllDeviceSubTypes(int tenantId, DeviceSubType.DeviceType deviceType)
List<DeviceSubType> getAllDeviceSubTypes(int tenantId, String deviceType)
throws SubTypeMgtPluginException;
int getDeviceSubTypeCount(DeviceSubType.DeviceType deviceType) throws SubTypeMgtPluginException;
int getDeviceSubTypeCount(String deviceType) throws SubTypeMgtPluginException;
DeviceSubType getDeviceSubTypeByProvider(String subTypeName, int tenantId, DeviceSubType.DeviceType deviceType)
DeviceSubType getDeviceSubTypeByProvider(String subTypeName, int tenantId, String deviceType)
throws SubTypeMgtPluginException;
boolean checkDeviceSubTypeExist(String subTypeId, int tenantId, DeviceSubType.DeviceType deviceType)
boolean checkDeviceSubTypeExist(String subTypeId, int tenantId, String deviceType)
throws SubTypeMgtPluginException;
}

@ -22,7 +22,7 @@ import io.entgra.device.mgt.core.subtype.mgt.dto.DeviceSubTypeCacheKey;
import io.entgra.device.mgt.core.subtype.mgt.dto.DeviceSubType;
public class DeviceSubTypeMgtUtil {
public static String setDeviceSubTypeCacheKey(int tenantId, String subTypeId, DeviceSubType.DeviceType deviceType) {
public static String setDeviceSubTypeCacheKey(int tenantId, String subTypeId, String deviceType) {
return tenantId + "|" + subTypeId + "|" + deviceType.toString();
}
@ -30,7 +30,7 @@ public class DeviceSubTypeMgtUtil {
String[] keys = key.split("\\|");
int tenantId = Integer.parseInt(keys[0]);
String subTypeId = keys[1];
DeviceSubType.DeviceType deviceType = DeviceSubType.DeviceType.valueOf(keys[2]);
String deviceType = keys[2];
DeviceSubTypeCacheKey deviceSubTypesCacheKey = new DeviceSubTypeCacheKey();
deviceSubTypesCacheKey.setTenantId(tenantId);

@ -18,6 +18,7 @@
package io.entgra.device.mgt.core.subtype.mgt;
import com.fasterxml.jackson.core.JsonProcessingException;
import io.entgra.device.mgt.core.subtype.mgt.dao.DeviceSubTypeDAO;
import io.entgra.device.mgt.core.subtype.mgt.dao.DeviceSubTypeDAOFactory;
import io.entgra.device.mgt.core.subtype.mgt.dao.util.ConnectionManagerUtil;
@ -48,12 +49,12 @@ public class DAONegativeTest extends BaseDeviceSubTypePluginTest {
public void testAddDeviceSubType() throws SubTypeMgtDAOException {
DeviceSubType deviceSubType = new DeviceSubType() {
@Override
public <T> DeviceSubType setDeviceSubType(T objType, String typeDef) {
public <T> DeviceSubType convertToDeviceSubType() {
return null;
}
@Override
public String parseSubTypeToJson(Object objType) {
public String parseSubTypeToJson() throws JsonProcessingException {
return null;
}
};
@ -85,18 +86,18 @@ public class DAONegativeTest extends BaseDeviceSubTypePluginTest {
String subTypeName = "TestSubType";
DeviceSubType deviceSubType = new DeviceSubType() {
@Override
public <T> DeviceSubType setDeviceSubType(T objType, String typeDef) {
public <T> DeviceSubType convertToDeviceSubType() {
return null;
}
@Override
public String parseSubTypeToJson(Object objType) {
public String parseSubTypeToJson() throws JsonProcessingException {
return null;
}
};
deviceSubType.setSubTypeId(subTypeId);
deviceSubType.setSubTypeName(subTypeName);
deviceSubType.setDeviceType(DeviceSubType.DeviceType.COM);
deviceSubType.setDeviceType("COM");
try {
ConnectionManagerUtil.beginDBTransaction();
deviceSubTypeDAO.addDeviceSubType(deviceSubType);
@ -127,17 +128,17 @@ public class DAONegativeTest extends BaseDeviceSubTypePluginTest {
String typeDefinition = TestUtils.createNewDeviceSubType(subTypeId);
DeviceSubType deviceSubType = new DeviceSubType() {
@Override
public <T> DeviceSubType setDeviceSubType(T objType, String typeDef) {
public <T> DeviceSubType convertToDeviceSubType() {
return null;
}
@Override
public String parseSubTypeToJson(Object objType) {
public String parseSubTypeToJson() throws JsonProcessingException {
return null;
}
};
deviceSubType.setSubTypeName(subTypeName);
deviceSubType.setDeviceType(DeviceSubType.DeviceType.COM);
deviceSubType.setDeviceType("COM");
deviceSubType.setTenantId(tenantId);
deviceSubType.setTypeDefinition(typeDefinition);
try {

@ -18,6 +18,7 @@
package io.entgra.device.mgt.core.subtype.mgt;
import com.fasterxml.jackson.core.JsonProcessingException;
import io.entgra.device.mgt.core.subtype.mgt.dao.DeviceSubTypeDAO;
import io.entgra.device.mgt.core.subtype.mgt.dao.DeviceSubTypeDAOFactory;
import io.entgra.device.mgt.core.subtype.mgt.dao.util.ConnectionManagerUtil;
@ -50,14 +51,14 @@ public class DAOTest extends BaseDeviceSubTypePluginTest {
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
ConnectionManagerUtil.openDBConnection();
DeviceSubType subTypeActual = deviceSubTypeDAO.getDeviceSubType("1", tenantId,
DeviceSubType.DeviceType.COM);
"COM");
ConnectionManagerUtil.closeDBConnection();
Assert.assertNotNull(subTypeActual, "Should not be null");
}
@Test(dependsOnMethods = "testAddDeviceSubType")
public void testGetAllDeviceSubTypes() throws DBConnectionException, SubTypeMgtDAOException {
DeviceSubType.DeviceType deviceType = DeviceSubType.DeviceType.COM;
String deviceType = "COM";
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
ConnectionManagerUtil.openDBConnection();
List<DeviceSubType> subTypesActual = deviceSubTypeDAO.getAllDeviceSubTypes(tenantId, deviceType);
@ -71,17 +72,17 @@ public class DAOTest extends BaseDeviceSubTypePluginTest {
String subTypeId = "1";
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
String subTypeName = "TestSubType";
DeviceSubType.DeviceType deviceType = DeviceSubType.DeviceType.COM;
String deviceType = "COM";
String typeDefinition = TestUtils.createNewDeviceSubType(subTypeId);
DeviceSubType deviceSubType = new DeviceSubType() {
@Override
public <T> DeviceSubType setDeviceSubType(T objType, String typeDef) {
public <T> DeviceSubType convertToDeviceSubType() {
return null;
}
@Override
public String parseSubTypeToJson(Object objType) {
public String parseSubTypeToJson() throws JsonProcessingException {
return null;
}
};
@ -104,7 +105,7 @@ public class DAOTest extends BaseDeviceSubTypePluginTest {
public void testUpdateDeviceSubType() throws DBConnectionException, SubTypeMgtDAOException {
String subTypeId = "1";
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
DeviceSubType.DeviceType deviceType = DeviceSubType.DeviceType.COM;
String deviceType = "COM";
String subTypeName = "TestSubType";
String subTypeExpected = TestUtils.createUpdateDeviceSubType(subTypeId);
@ -121,7 +122,7 @@ public class DAOTest extends BaseDeviceSubTypePluginTest {
@Test(dependsOnMethods = "testAddDeviceSubType")
public void testGetDeviceTypeByProvider() throws DBConnectionException, SubTypeMgtDAOException {
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
DeviceSubType.DeviceType deviceType = DeviceSubType.DeviceType.COM;
String deviceType = "COM";
String subTypeName = "TestSubType";
ConnectionManagerUtil.openDBConnection();
DeviceSubType subTypeActual = deviceSubTypeDAO.getDeviceSubTypeByProvider(subTypeName, tenantId, deviceType);
@ -131,7 +132,7 @@ public class DAOTest extends BaseDeviceSubTypePluginTest {
@Test(dependsOnMethods = "testAddDeviceSubType")
public void testGetDeviceTypeCount() throws DBConnectionException, SubTypeMgtDAOException {
DeviceSubType.DeviceType deviceType = DeviceSubType.DeviceType.COM;
String deviceType = "COM";
ConnectionManagerUtil.openDBConnection();
int subTypeCount = deviceSubTypeDAO.getDeviceSubTypeCount(deviceType);
ConnectionManagerUtil.closeDBConnection();

@ -18,6 +18,7 @@
package io.entgra.device.mgt.core.subtype.mgt;
import com.fasterxml.jackson.core.JsonProcessingException;
import io.entgra.device.mgt.core.subtype.mgt.dto.DeviceSubType;
import io.entgra.device.mgt.core.subtype.mgt.exception.SubTypeMgtPluginException;
import io.entgra.device.mgt.core.subtype.mgt.impl.DeviceSubTypeServiceImpl;
@ -45,12 +46,12 @@ public class ServiceNegativeTest extends BaseDeviceSubTypePluginTest {
public void testAddDeviceSubType() throws SubTypeMgtPluginException {
DeviceSubType deviceSubType = new DeviceSubType() {
@Override
public <T> DeviceSubType setDeviceSubType(T objType, String typeDef) {
public <T> DeviceSubType convertToDeviceSubType() {
return null;
}
@Override
public String parseSubTypeToJson(Object objType) {
public String parseSubTypeToJson() throws JsonProcessingException {
return null;
}
};
@ -65,16 +66,16 @@ public class ServiceNegativeTest extends BaseDeviceSubTypePluginTest {
public void testAddDeviceSubTypes() throws SubTypeMgtPluginException {
String subTypeId = "1";
String subTypeName = "TestSubType";
DeviceSubType.DeviceType deviceType = DeviceSubType.DeviceType.SIM;
String deviceType = "SIM";
DeviceSubType deviceSubType = new DeviceSubType() {
@Override
public <T> DeviceSubType setDeviceSubType(T objType, String typeDef) {
public <T> DeviceSubType convertToDeviceSubType() {
return null;
}
@Override
public String parseSubTypeToJson(Object objType) {
public String parseSubTypeToJson() throws JsonProcessingException {
return null;
}
};
@ -91,7 +92,7 @@ public class ServiceNegativeTest extends BaseDeviceSubTypePluginTest {
public void testUpdateDeviceSubTypes() throws SubTypeMgtPluginException {
String subTypeId = "15";
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
DeviceSubType.DeviceType deviceType = DeviceSubType.DeviceType.SIM;
String deviceType = "SIM";
String subTypeName = "TestSubType";
String subTypeExpected = TestUtils.createUpdateDeviceSubType(subTypeId);

@ -18,6 +18,7 @@
package io.entgra.device.mgt.core.subtype.mgt;
import com.fasterxml.jackson.core.JsonProcessingException;
import io.entgra.device.mgt.core.subtype.mgt.dto.DeviceSubType;
import io.entgra.device.mgt.core.subtype.mgt.exception.SubTypeMgtPluginException;
import io.entgra.device.mgt.core.subtype.mgt.impl.DeviceSubTypeServiceImpl;
@ -48,13 +49,13 @@ public class ServiceTest extends BaseDeviceSubTypePluginTest {
public void testGetDeviceType() throws SubTypeMgtPluginException {
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
DeviceSubType subTypeActual = deviceSubTypeService.getDeviceSubType("1", tenantId,
DeviceSubType.DeviceType.METER);
"METER");
TestUtils.verifyDeviceSubType(subTypeActual);
}
@Test(dependsOnMethods = "testAddDeviceSubType")
public void testGetAllDeviceTypes() throws SubTypeMgtPluginException {
DeviceSubType.DeviceType deviceType = DeviceSubType.DeviceType.METER;
String deviceType = "METER";
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
List<DeviceSubType> subTypesActual = deviceSubTypeService.getAllDeviceSubTypes(tenantId, deviceType);
log.info(deviceType + " sub types count should be " + subTypesActual.size());
@ -66,17 +67,17 @@ public class ServiceTest extends BaseDeviceSubTypePluginTest {
String subTypeId = "1";
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
String subTypeName = "TestSubType";
DeviceSubType.DeviceType deviceType = DeviceSubType.DeviceType.METER;
String deviceType = "METER";
String typeDefinition = TestUtils.createNewDeviceSubType(subTypeId);
DeviceSubType deviceSubType = new DeviceSubType() {
@Override
public <T> DeviceSubType setDeviceSubType(T objType, String typeDef) {
public <T> DeviceSubType convertToDeviceSubType() {
return null;
}
@Override
public String parseSubTypeToJson(Object objType) {
public String parseSubTypeToJson() throws JsonProcessingException {
return null;
}
};
@ -96,7 +97,7 @@ public class ServiceTest extends BaseDeviceSubTypePluginTest {
public void testUpdateDeviceSubType() throws SubTypeMgtPluginException {
String subTypeId = "1";
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
DeviceSubType.DeviceType deviceType = DeviceSubType.DeviceType.METER;
String deviceType = "METER";
String subTypeName = "TestSubType";
String subTypeExpected = TestUtils.createUpdateDeviceSubType(subTypeId);
@ -111,7 +112,7 @@ public class ServiceTest extends BaseDeviceSubTypePluginTest {
@Test(dependsOnMethods = "testAddDeviceSubType")
public void testGetDeviceTypeByProvider() throws SubTypeMgtPluginException {
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
DeviceSubType.DeviceType deviceType = DeviceSubType.DeviceType.METER;
String deviceType = "METER";
String subTypeName = "TestSubType";
DeviceSubType subTypeActual = deviceSubTypeService.getDeviceSubTypeByProvider(subTypeName, tenantId,
deviceType);
@ -120,7 +121,7 @@ public class ServiceTest extends BaseDeviceSubTypePluginTest {
@Test(dependsOnMethods = "testAddDeviceSubType")
public void testGetDeviceTypeCount() throws SubTypeMgtPluginException {
DeviceSubType.DeviceType deviceType = DeviceSubType.DeviceType.METER;
String deviceType = "METER";
int subTypeCount = deviceSubTypeService.getDeviceSubTypeCount(deviceType);
log.info(deviceType + " Device subtypes count: " + subTypeCount);
}

@ -47,7 +47,7 @@ public class TestUtils {
public static void verifyDeviceSubType(DeviceSubType deviceSubType) {
String typeDefExpected = TestUtils.createNewDeviceSubType("1");
Assert.assertEquals(deviceSubType.getSubTypeId(), "1");
Assert.assertEquals(deviceSubType.getDeviceType(), DeviceSubType.DeviceType.valueOf("METER"));
Assert.assertEquals(deviceSubType.getDeviceType(), "METER");
Assert.assertEquals(deviceSubType.getSubTypeName(), "TestSubType");
Assert.assertEquals(deviceSubType.getTypeDefinition(), typeDefExpected);
}
@ -55,7 +55,7 @@ public class TestUtils {
public static void verifyDeviceSubTypeDAO(DeviceSubType deviceSubType) {
String typeDefExpected = TestUtils.createNewDeviceSubType("1");
Assert.assertEquals(deviceSubType.getSubTypeId(), "1");
Assert.assertEquals(deviceSubType.getDeviceType(), DeviceSubType.DeviceType.valueOf("COM"));
Assert.assertEquals(deviceSubType.getDeviceType(), "COM");
Assert.assertEquals(deviceSubType.getSubTypeName(), "TestSubType");
Assert.assertEquals(deviceSubType.getTypeDefinition(), typeDefExpected);
}
@ -63,7 +63,7 @@ public class TestUtils {
public static void verifyUpdatedDeviceSubType(DeviceSubType deviceSubType) {
String typeDefExpected = TestUtils.createUpdateDeviceSubType("1");
Assert.assertEquals(deviceSubType.getSubTypeId(), "1");
Assert.assertEquals(deviceSubType.getDeviceType(), DeviceSubType.DeviceType.valueOf("METER"));
Assert.assertEquals(deviceSubType.getDeviceType(), "METER");
Assert.assertEquals(deviceSubType.getSubTypeName(), "TestSubType");
Assert.assertEquals(deviceSubType.getTypeDefinition(), typeDefExpected);
}
@ -71,7 +71,7 @@ public class TestUtils {
public static void verifyUpdatedDeviceSubTypeDAO(DeviceSubType deviceSubType) {
String typeDefExpected = TestUtils.createUpdateDeviceSubType("1");
Assert.assertEquals(deviceSubType.getSubTypeId(), "1");
Assert.assertEquals(deviceSubType.getDeviceType(), DeviceSubType.DeviceType.valueOf("COM"));
Assert.assertEquals(deviceSubType.getDeviceType(), "COM");
Assert.assertEquals(deviceSubType.getSubTypeName(), "TestSubType");
Assert.assertEquals(deviceSubType.getTypeDefinition(), typeDefExpected);
}

@ -804,8 +804,8 @@ CREATE TABLE IF NOT EXISTS DYNAMIC_TASK_PROPERTIES (
CREATE TABLE IF NOT EXISTS DM_DEVICE_SUB_TYPE (
TENANT_ID INT DEFAULT 0,
SUB_TYPE_ID VARCHAR(45) NOT NULL,
DEVICE_TYPE VARCHAR(25) NOT NULL,
SUB_TYPE_NAME VARCHAR(45) NOT NULL,
DEVICE_TYPE VARCHAR(45) NOT NULL,
SUB_TYPE_NAME VARCHAR(100) NOT NULL,
TYPE_DEFINITION TEXT NOT NULL,
PRIMARY KEY (SUB_TYPE_ID,DEVICE_TYPE)
);

@ -876,8 +876,8 @@ IF NOT EXISTS (SELECT * FROM SYS.OBJECTS WHERE OBJECT_ID = OBJECT_ID(N'[DBO].[D
CREATE TABLE DM_DEVICE_SUB_TYPE (
TENANT_ID INT DEFAULT 0,
SUB_TYPE_ID VARCHAR(45) NOT NULL,
DEVICE_TYPE VARCHAR(25) NOT NULL,
SUB_TYPE_NAME VARCHAR(45) NOT NULL,
DEVICE_TYPE VARCHAR(45) NOT NULL,
SUB_TYPE_NAME VARCHAR(100) NOT NULL,
TYPE_DEFINITION TEXT NOT NULL,
PRIMARY KEY (SUB_TYPE_ID,DEVICE_TYPE)
);

@ -873,8 +873,8 @@ CREATE TABLE IF NOT EXISTS DYNAMIC_TASK_PROPERTIES (
CREATE TABLE IF NOT EXISTS DM_DEVICE_SUB_TYPE (
TENANT_ID INT DEFAULT 0,
SUB_TYPE_ID VARCHAR(45) NOT NULL,
DEVICE_TYPE VARCHAR(25) NOT NULL,
SUB_TYPE_NAME VARCHAR(45) NOT NULL,
DEVICE_TYPE VARCHAR(45) NOT NULL,
SUB_TYPE_NAME VARCHAR(100) NOT NULL,
TYPE_DEFINITION TEXT NOT NULL,
PRIMARY KEY (SUB_TYPE_ID,DEVICE_TYPE)
) ENGINE=InnoDB;

@ -1149,8 +1149,8 @@ CREATE TABLE IF NOT EXISTS DYNAMIC_TASK_PROPERTIES (
CREATE TABLE IF NOT EXISTS DM_DEVICE_SUB_TYPE (
TENANT_ID INT DEFAULT 0,
SUB_TYPE_ID VARCHAR(45) NOT NULL,
DEVICE_TYPE VARCHAR(25) NOT NULL,
SUB_TYPE_NAME VARCHAR(45) NOT NULL,
DEVICE_TYPE VARCHAR(45) NOT NULL,
SUB_TYPE_NAME VARCHAR(100) NOT NULL,
TYPE_DEFINITION TEXT NOT NULL,
PRIMARY KEY (SUB_TYPE_ID,DEVICE_TYPE)
) ENGINE=InnoDB;

@ -795,8 +795,8 @@ CREATE TABLE IF NOT EXISTS DYNAMIC_TASK_PROPERTIES (
CREATE TABLE IF NOT EXISTS DM_DEVICE_SUB_TYPE (
TENANT_ID INT DEFAULT 0,
SUB_TYPE_ID VARCHAR(45) NOT NULL,
DEVICE_TYPE VARCHAR(25) NOT NULL,
SUB_TYPE_NAME VARCHAR(45) NOT NULL,
DEVICE_TYPE VARCHAR(45) NOT NULL,
SUB_TYPE_NAME VARCHAR(100) NOT NULL,
TYPE_DEFINITION TEXT NOT NULL,
PRIMARY KEY (SUB_TYPE_ID,DEVICE_TYPE)
) ENGINE=InnoDB;

Loading…
Cancel
Save