Merge branch 'master' into master

scope-fixes
commit 31889b4a05

@ -870,6 +870,14 @@ public class GeoLocationBasedServiceImpl implements GeoLocationBasedService {
PaginationResult paginationResult = new PaginationResult(); PaginationResult paginationResult = new PaginationResult();
paginationResult.setData(geofenceList); paginationResult.setData(geofenceList);
paginationResult.setRecordsTotal(geofenceList.size()); paginationResult.setRecordsTotal(geofenceList.size());
try {
GeoLocationProviderService geoService = DeviceMgtAPIUtils.getGeoService();
paginationResult.setTotalDeviceCount(geoService.getGeoFenceCount());
} catch (GeoLocationBasedServiceException e) {
String msg = "Failed to retrieve geofence data";
log.error(msg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
}
return Response.status(Response.Status.OK).entity(paginationResult).build(); return Response.status(Response.Status.OK).entity(paginationResult).build();
} }

@ -19,6 +19,7 @@ package io.entgra.device.mgt.core.device.mgt.api.jaxrs.service.impl;
import com.google.gson.JsonArray; import com.google.gson.JsonArray;
import com.google.gson.JsonObject; import com.google.gson.JsonObject;
import io.entgra.device.mgt.core.device.mgt.common.Device;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
@ -320,32 +321,42 @@ public class UserManagementServiceImpl implements UserManagementService {
@Consumes(MediaType.WILDCARD) @Consumes(MediaType.WILDCARD)
@Override @Override
public Response removeUser(@QueryParam("username") String username, @QueryParam("domain") String domain) { public Response removeUser(@QueryParam("username") String username, @QueryParam("domain") String domain) {
boolean nameWithDomain = false;
if (domain != null && !domain.isEmpty()) { if (domain != null && !domain.isEmpty()) {
username = domain + '/' + username; username = domain + '/' + username;
nameWithDomain = true;
} }
try { try {
int deviceCount;
UserStoreManager userStoreManager = DeviceMgtAPIUtils.getUserStoreManager(); UserStoreManager userStoreManager = DeviceMgtAPIUtils.getUserStoreManager();
if (!userStoreManager.isExistingUser(username)) { if (!userStoreManager.isExistingUser(username)) {
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
log.debug("User by username: " + username + " does not exist for removal."); log.debug("User by user: " + username + " does not exist for removal.");
} }
String msg = "User by username: " + username + " does not exist for removal."; String msg = "User by user: " + username + " does not exist for removal.";
return Response.status(Response.Status.NOT_FOUND).entity(msg).build(); return Response.status(Response.Status.NOT_FOUND).entity(msg).build();
} }
// Un-enroll all devices for the user
DeviceManagementProviderService deviceManagementService = DeviceMgtAPIUtils.getDeviceManagementService(); DeviceManagementProviderService deviceManagementService = DeviceMgtAPIUtils.getDeviceManagementService();
deviceManagementService.setStatus(username, EnrolmentInfo.Status.REMOVED); if (nameWithDomain) {
deviceCount = deviceManagementService.getDeviceCount(username.split("/")[1]);
userStoreManager.deleteUser(username); } else {
if (log.isDebugEnabled()) { deviceCount = deviceManagementService.getDeviceCount(username);
log.debug("User '" + username + "' was successfully removed."); }
if (deviceCount == 0) {
userStoreManager.deleteUser(username);
if (log.isDebugEnabled()) {
log.debug("User '" + username + "' was successfully removed.");
}
return Response.status(Response.Status.OK).build();
} else {
String msg = "There are enrolled devices for user: " + username + ". Please remove them before deleting the user.";
log.error(msg);
return Response.status(400).entity(msg).build();
} }
return Response.status(Response.Status.OK).build();
} catch (DeviceManagementException | UserStoreException e) { } catch (DeviceManagementException | UserStoreException e) {
String msg = "Exception in trying to remove user by username: " + username; String msg = "Exception in trying to remove user by user: " + username;
log.error(msg, e); log.error(msg, e);
return Response.serverError().entity( return Response.status(400).entity(msg).build();
new ErrorResponse.ErrorResponseBuilder().setMessage(msg).build()).build();
} }
} }

@ -18,6 +18,7 @@
package io.entgra.device.mgt.core.device.mgt.api.jaxrs.service.impl; package io.entgra.device.mgt.core.device.mgt.api.jaxrs.service.impl;
import io.entgra.device.mgt.core.device.mgt.common.Device;
import org.mockito.Mockito; import org.mockito.Mockito;
import org.mockito.invocation.InvocationOnMock; import org.mockito.invocation.InvocationOnMock;
import org.mockito.stubbing.Answer; import org.mockito.stubbing.Answer;
@ -272,7 +273,7 @@ public class UserManagementServiceImplTest {
.toReturn(this.userStoreManager); .toReturn(this.userStoreManager);
PowerMockito.stub(PowerMockito.method(DeviceMgtAPIUtils.class, "getDeviceManagementService")) PowerMockito.stub(PowerMockito.method(DeviceMgtAPIUtils.class, "getDeviceManagementService"))
.toReturn(this.deviceManagementProviderService); .toReturn(this.deviceManagementProviderService);
Mockito.doReturn(true).when(deviceManagementProviderService).setStatus(Mockito.anyString(), Mockito.any()); Mockito.doReturn(0).when(deviceManagementProviderService).getDeviceCount(TEST_USERNAME);
Mockito.doNothing().when(userStoreManager).deleteUser(Mockito.anyString()); Mockito.doNothing().when(userStoreManager).deleteUser(Mockito.anyString());
Response response = userManagementService.removeUser(TEST_USERNAME, null); Response response = userManagementService.removeUser(TEST_USERNAME, null);
Assert.assertEquals(response.getStatus(), Response.Status.OK.getStatusCode(), Assert.assertEquals(response.getStatus(), Response.Status.OK.getStatusCode(),
@ -337,7 +338,7 @@ public class UserManagementServiceImplTest {
Assert.assertEquals(response.getStatus(), Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), Assert.assertEquals(response.getStatus(), Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(),
"Response returned successful for a user updating request with problematic inputs"); "Response returned successful for a user updating request with problematic inputs");
response = userManagementService.removeUser(TEST3_USERNAME, null); response = userManagementService.removeUser(TEST3_USERNAME, null);
Assert.assertEquals(response.getStatus(), Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), Assert.assertEquals(response.getStatus(), Response.Status.BAD_REQUEST.getStatusCode(),
"Response returned successful for a user removal request with problematic inputs"); "Response returned successful for a user removal request with problematic inputs");
response = userManagementService.getRolesOfUser(TEST3_USERNAME, null); response = userManagementService.getRolesOfUser(TEST3_USERNAME, null);
Assert.assertEquals(response.getStatus(), Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), Assert.assertEquals(response.getStatus(), Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(),

@ -171,4 +171,11 @@ public interface GeoLocationProviderService {
* @throws GeoLocationBasedServiceException any errors occurred while reading event records to geofence * @throws GeoLocationBasedServiceException any errors occurred while reading event records to geofence
*/ */
List<EventConfig> getEventsOfGeoFence(int geoFenceId) throws GeoLocationBasedServiceException; List<EventConfig> getEventsOfGeoFence(int geoFenceId) throws GeoLocationBasedServiceException;
/**
* Get geo fence count by tenant id
* @return returns the geofence count of tenant.
* @throws GeoLocationBasedServiceException any errors occurred while reading event records to geofence
*/
int getGeoFenceCount() throws GeoLocationBasedServiceException;
} }

@ -174,4 +174,12 @@ public interface GeofenceDAO {
* @throws DeviceManagementDAOException * @throws DeviceManagementDAOException
*/ */
GeofenceData getGeofence(int fenceId, boolean requireGroupData) throws DeviceManagementDAOException; GeofenceData getGeofence(int fenceId, boolean requireGroupData) throws DeviceManagementDAOException;
/**
* This method is used to get the geofence count by tenant id.
* @param tenantId tenant id.
* @return returns the geofence count of tenant.
* @throws DeviceManagementDAOException
*/
int getGeofenceCount(int tenantId) throws DeviceManagementDAOException;
} }

@ -644,4 +644,28 @@ public abstract class AbstractGeofenceDAOImpl implements GeofenceDAO {
throw new DeviceManagementDAOException(msg, e); throw new DeviceManagementDAOException(msg, e);
} }
} }
@Override
public int getGeofenceCount(int tenantId) throws DeviceManagementDAOException {
try {
Connection conn = this.getConnection();
String sql = "SELECT COUNT(*) AS geofence_count " +
"FROM DM_GEOFENCE " +
"WHERE TENANT_ID = ?";
try (PreparedStatement stmt = conn.prepareStatement(sql)) {
stmt.setInt(1, tenantId);
try (ResultSet rst = stmt.executeQuery()) {
if (rst.next()) {
return rst.getInt("geofence_count");
}
}
}
return 0; // Return 0 if no records found for the given tenantId.
} catch (SQLException e) {
String msg = "Error occurred while retrieving Geofence count of the tenant " + tenantId;
log.error(msg, e);
throw new DeviceManagementDAOException(msg, e);
}
}
} }

@ -94,7 +94,7 @@ public class GenericDeviceDAOImpl extends AbstractDeviceDAOImpl {
"t.NAME AS DEVICE_TYPE "; "t.NAME AS DEVICE_TYPE ";
//Filter by serial number or any Custom Property in DM_DEVICE_INFO //Filter by serial number or any Custom Property in DM_DEVICE_INFO
if (serial != null || !request.getCustomProperty().isEmpty()) { if ((serial != null) || (request.getCustomProperty() != null && !request.getCustomProperty().isEmpty())) {
sql = sql + sql = sql +
"FROM DM_DEVICE d " + "FROM DM_DEVICE d " +
"INNER JOIN DM_DEVICE_TYPE t ON d.DEVICE_TYPE_ID = t.ID " + "INNER JOIN DM_DEVICE_TYPE t ON d.DEVICE_TYPE_ID = t.ID " +
@ -170,7 +170,7 @@ public class GenericDeviceDAOImpl extends AbstractDeviceDAOImpl {
if (isSerialProvided) { if (isSerialProvided) {
stmt.setString(paramIdx++, "%" + serial + "%"); stmt.setString(paramIdx++, "%" + serial + "%");
} }
if (!request.getCustomProperty().isEmpty()) { if (request.getCustomProperty() != null && !request.getCustomProperty().isEmpty()) {
for (Map.Entry<String, String> entry : request.getCustomProperty().entrySet()) { for (Map.Entry<String, String> entry : request.getCustomProperty().entrySet()) {
stmt.setString(paramIdx++, "%" + entry.getValue() + "%"); stmt.setString(paramIdx++, "%" + entry.getValue() + "%");
} }

@ -1747,6 +1747,32 @@ public class GeoLocationProviderServiceImpl implements GeoLocationProviderServic
} }
} }
@Override
public int getGeoFenceCount() throws GeoLocationBasedServiceException {
int tenantId;
try {
tenantId = DeviceManagementDAOUtil.getTenantId();
} catch (DeviceManagementDAOException e) {
String msg = "Error occurred while retrieving tenant id while get geofence data";
log.error(msg, e);
throw new GeoLocationBasedServiceException(msg, e);
}
try {
EventManagementDAOFactory.openConnection();
return geofenceDAO.getGeofenceCount(tenantId);
} catch (DeviceManagementDAOException e) {
String msg = "Error occurred while retrieving geofence data for the tenant " + tenantId;
log.error(msg, e);
throw new GeoLocationBasedServiceException(msg, e);
} catch (SQLException e) {
String msg = "Failed to open the DB connection to retrieve Geofence";
log.error(msg, e);
throw new GeoLocationBasedServiceException(msg, e);
} finally {
EventManagementDAOFactory.closeConnection();
}
}
/** /**
* Delete events of geofence * Delete events of geofence
* *

@ -652,7 +652,7 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
Map<String, DeviceManager> deviceManagerMap = new HashMap<>(); Map<String, DeviceManager> deviceManagerMap = new HashMap<>();
List<DeviceCacheKey> deviceCacheKeyList = new ArrayList<>(); List<DeviceCacheKey> deviceCacheKeyList = new ArrayList<>();
List<Device> existingDevices; List<Device> existingDevices;
List<Device> validDevices = new ArrayList<>();; List<Device> validDevices = new ArrayList<>();
int tenantId = this.getTenantId(); int tenantId = this.getTenantId();
try { try {

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

@ -26,20 +26,20 @@ import java.util.List;
public interface DeviceSubTypeDAO { public interface DeviceSubTypeDAO {
boolean addDeviceSubType(DeviceSubType deviceSubType) throws SubTypeMgtDAOException; 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; String typeDefinition) throws SubTypeMgtDAOException;
DeviceSubType getDeviceSubType(String subTypeId, int tenantId, DeviceSubType.DeviceType deviceType) DeviceSubType getDeviceSubType(String subTypeId, int tenantId, String deviceType)
throws SubTypeMgtDAOException; throws SubTypeMgtDAOException;
List<DeviceSubType> getAllDeviceSubTypes(int tenantId, DeviceSubType.DeviceType deviceType) List<DeviceSubType> getAllDeviceSubTypes(int tenantId, String deviceType)
throws SubTypeMgtDAOException; 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; throws SubTypeMgtDAOException;
DeviceSubType getDeviceSubTypeByProvider(String subTypeName, int tenantId, DeviceSubType.DeviceType deviceType) DeviceSubType getDeviceSubTypeByProvider(String subTypeName, int tenantId, String deviceType)
throws SubTypeMgtDAOException; 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.subtype.mgt.dao.util.ConnectionManagerUtil;
import io.entgra.device.mgt.core.device.mgt.core.config.datasource.DataSourceConfig; import io.entgra.device.mgt.core.device.mgt.core.config.datasource.DataSourceConfig;
import javax.sql.DataSource;
import java.sql.SQLException;
public class DeviceSubTypeDAOFactory { public class DeviceSubTypeDAOFactory {
private static final Log log = LogFactory.getLog(DeviceSubTypeDAOFactory.class); private static final Log log = LogFactory.getLog(DeviceSubTypeDAOFactory.class);
private static String databaseEngine; private static String databaseEngine;
private static DataSource dataSource;
public static void init(DataSourceConfig dataSourceConfiguration) { public static void init(DataSourceConfig dataSourceConfiguration) {
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
log.debug("Initializing Device SubType Mgt Data Source"); log.debug("Initializing Device SubType Mgt Data Source");
@ -38,6 +42,17 @@ public class DeviceSubTypeDAOFactory {
databaseEngine = ConnectionManagerUtil.getDatabaseType(); 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() { public static DeviceSubTypeDAO getDeviceSubTypeDAO() {
if (databaseEngine != null) { if (databaseEngine != null) {
//noinspection SwitchStatementWithTooFewBranches //noinspection SwitchStatementWithTooFewBranches

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

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

@ -26,10 +26,21 @@ public abstract class DeviceSubType {
private String subTypeId; private String subTypeId;
private int tenantId; private int tenantId;
private DeviceType deviceType; private String deviceType;
private String subTypeName; private String subTypeName;
private String typeDefinition; 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() { public String getSubTypeId() {
return subTypeId; return subTypeId;
} }
@ -46,11 +57,11 @@ public abstract class DeviceSubType {
this.tenantId = tenantId; this.tenantId = tenantId;
} }
public DeviceType getDeviceType() { public String getDeviceType() {
return deviceType; return deviceType;
} }
public void setDeviceType(DeviceType deviceType) { public void setDeviceType(String deviceType) {
this.deviceType = deviceType; this.deviceType = deviceType;
} }
@ -70,11 +81,8 @@ public abstract class DeviceSubType {
this.typeDefinition = typeDefinition; 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 { public class DeviceSubTypeCacheKey {
int tenantId; int tenantId;
String subTypeId; String subTypeId;
DeviceSubType.DeviceType deviceType; String deviceType;
public int getTenantId() { public int getTenantId() {
return tenantId; return tenantId;
@ -39,11 +39,11 @@ public class DeviceSubTypeCacheKey {
this.subTypeId = subTypeId; this.subTypeId = subTypeId;
} }
public DeviceSubType.DeviceType getDeviceType() { public String getDeviceType() {
return deviceType; return deviceType;
} }
public void setDeviceType(DeviceSubType.DeviceType deviceType) { public void setDeviceType(String deviceType) {
this.deviceType = deviceType; this.deviceType = deviceType;
} }
} }

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

@ -27,20 +27,20 @@ public interface DeviceSubTypeService {
boolean addDeviceSubType(DeviceSubType deviceSubType) throws SubTypeMgtPluginException; 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; String typeDefinition) throws SubTypeMgtPluginException;
DeviceSubType getDeviceSubType(String subTypeId, int tenantId, DeviceSubType.DeviceType deviceType) DeviceSubType getDeviceSubType(String subTypeId, int tenantId, String deviceType)
throws SubTypeMgtPluginException; throws SubTypeMgtPluginException;
List<DeviceSubType> getAllDeviceSubTypes(int tenantId, DeviceSubType.DeviceType deviceType) List<DeviceSubType> getAllDeviceSubTypes(int tenantId, String deviceType)
throws SubTypeMgtPluginException; 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; throws SubTypeMgtPluginException;
boolean checkDeviceSubTypeExist(String subTypeId, int tenantId, DeviceSubType.DeviceType deviceType) boolean checkDeviceSubTypeExist(String subTypeId, int tenantId, String deviceType)
throws SubTypeMgtPluginException; 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; import io.entgra.device.mgt.core.subtype.mgt.dto.DeviceSubType;
public class DeviceSubTypeMgtUtil { 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(); return tenantId + "|" + subTypeId + "|" + deviceType.toString();
} }
@ -30,7 +30,7 @@ public class DeviceSubTypeMgtUtil {
String[] keys = key.split("\\|"); String[] keys = key.split("\\|");
int tenantId = Integer.parseInt(keys[0]); int tenantId = Integer.parseInt(keys[0]);
String subTypeId = keys[1]; String subTypeId = keys[1];
DeviceSubType.DeviceType deviceType = DeviceSubType.DeviceType.valueOf(keys[2]); String deviceType = keys[2];
DeviceSubTypeCacheKey deviceSubTypesCacheKey = new DeviceSubTypeCacheKey(); DeviceSubTypeCacheKey deviceSubTypesCacheKey = new DeviceSubTypeCacheKey();
deviceSubTypesCacheKey.setTenantId(tenantId); deviceSubTypesCacheKey.setTenantId(tenantId);

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

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

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

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

@ -47,7 +47,7 @@ public class TestUtils {
public static void verifyDeviceSubType(DeviceSubType deviceSubType) { public static void verifyDeviceSubType(DeviceSubType deviceSubType) {
String typeDefExpected = TestUtils.createNewDeviceSubType("1"); String typeDefExpected = TestUtils.createNewDeviceSubType("1");
Assert.assertEquals(deviceSubType.getSubTypeId(), "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.getSubTypeName(), "TestSubType");
Assert.assertEquals(deviceSubType.getTypeDefinition(), typeDefExpected); Assert.assertEquals(deviceSubType.getTypeDefinition(), typeDefExpected);
} }
@ -55,7 +55,7 @@ public class TestUtils {
public static void verifyDeviceSubTypeDAO(DeviceSubType deviceSubType) { public static void verifyDeviceSubTypeDAO(DeviceSubType deviceSubType) {
String typeDefExpected = TestUtils.createNewDeviceSubType("1"); String typeDefExpected = TestUtils.createNewDeviceSubType("1");
Assert.assertEquals(deviceSubType.getSubTypeId(), "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.getSubTypeName(), "TestSubType");
Assert.assertEquals(deviceSubType.getTypeDefinition(), typeDefExpected); Assert.assertEquals(deviceSubType.getTypeDefinition(), typeDefExpected);
} }
@ -63,7 +63,7 @@ public class TestUtils {
public static void verifyUpdatedDeviceSubType(DeviceSubType deviceSubType) { public static void verifyUpdatedDeviceSubType(DeviceSubType deviceSubType) {
String typeDefExpected = TestUtils.createUpdateDeviceSubType("1"); String typeDefExpected = TestUtils.createUpdateDeviceSubType("1");
Assert.assertEquals(deviceSubType.getSubTypeId(), "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.getSubTypeName(), "TestSubType");
Assert.assertEquals(deviceSubType.getTypeDefinition(), typeDefExpected); Assert.assertEquals(deviceSubType.getTypeDefinition(), typeDefExpected);
} }
@ -71,7 +71,7 @@ public class TestUtils {
public static void verifyUpdatedDeviceSubTypeDAO(DeviceSubType deviceSubType) { public static void verifyUpdatedDeviceSubTypeDAO(DeviceSubType deviceSubType) {
String typeDefExpected = TestUtils.createUpdateDeviceSubType("1"); String typeDefExpected = TestUtils.createUpdateDeviceSubType("1");
Assert.assertEquals(deviceSubType.getSubTypeId(), "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.getSubTypeName(), "TestSubType");
Assert.assertEquals(deviceSubType.getTypeDefinition(), typeDefExpected); Assert.assertEquals(deviceSubType.getTypeDefinition(), typeDefExpected);
} }

@ -594,7 +594,7 @@ CREATE TABLE IF NOT EXISTS DM_METADATA (
METADATA_ID INT AUTO_INCREMENT NOT NULL, METADATA_ID INT AUTO_INCREMENT NOT NULL,
DATA_TYPE VARCHAR(16) NOT NULL, DATA_TYPE VARCHAR(16) NOT NULL,
METADATA_KEY VARCHAR(128) NOT NULL, METADATA_KEY VARCHAR(128) NOT NULL,
METADATA_VALUE VARCHAR(65535) NOT NULL, METADATA_VALUE TEXT NOT NULL,
TENANT_ID INTEGER NOT NULL, TENANT_ID INTEGER NOT NULL,
PRIMARY KEY (METADATA_ID), PRIMARY KEY (METADATA_ID),
CONSTRAINT METADATA_KEY_TENANT_ID UNIQUE (METADATA_KEY, TENANT_ID) CONSTRAINT METADATA_KEY_TENANT_ID UNIQUE (METADATA_KEY, TENANT_ID)
@ -804,8 +804,8 @@ CREATE TABLE IF NOT EXISTS DYNAMIC_TASK_PROPERTIES (
CREATE TABLE IF NOT EXISTS DM_DEVICE_SUB_TYPE ( CREATE TABLE IF NOT EXISTS DM_DEVICE_SUB_TYPE (
TENANT_ID INT DEFAULT 0, TENANT_ID INT DEFAULT 0,
SUB_TYPE_ID VARCHAR(45) NOT NULL, SUB_TYPE_ID VARCHAR(45) NOT NULL,
DEVICE_TYPE VARCHAR(25) NOT NULL, DEVICE_TYPE VARCHAR(45) NOT NULL,
SUB_TYPE_NAME VARCHAR(45) NOT NULL, SUB_TYPE_NAME VARCHAR(100) NOT NULL,
TYPE_DEFINITION TEXT NOT NULL, TYPE_DEFINITION TEXT NOT NULL,
PRIMARY KEY (SUB_TYPE_ID,DEVICE_TYPE) PRIMARY KEY (SUB_TYPE_ID,DEVICE_TYPE)
); );

@ -664,7 +664,7 @@ CREATE TABLE DM_METADATA (
METADATA_ID INTEGER IDENTITY(1,1) NOT NULL, METADATA_ID INTEGER IDENTITY(1,1) NOT NULL,
DATA_TYPE VARCHAR(16) NOT NULL, DATA_TYPE VARCHAR(16) NOT NULL,
METADATA_KEY VARCHAR(128) NOT NULL, METADATA_KEY VARCHAR(128) NOT NULL,
METADATA_VALUE VARCHAR(8000) NOT NULL, METADATA_VALUE TEXT NOT NULL,
TENANT_ID INTEGER NOT NULL, TENANT_ID INTEGER NOT NULL,
PRIMARY KEY (METADATA_ID), PRIMARY KEY (METADATA_ID),
CONSTRAINT METADATA_KEY_TENANT_ID UNIQUE(METADATA_KEY, TENANT_ID) CONSTRAINT METADATA_KEY_TENANT_ID UNIQUE(METADATA_KEY, TENANT_ID)
@ -672,6 +672,7 @@ CREATE TABLE DM_METADATA (
-- END OF METADATA TABLE -- -- END OF METADATA TABLE --
-- DM_OTP_DATA TABLE -- -- DM_OTP_DATA TABLE --
IF NOT EXISTS (SELECT * FROM SYS.OBJECTS WHERE OBJECT_ID = OBJECT_ID(N'[DBO].[DM_OTP_DATA]') AND TYPE IN (N'U'))
CREATE TABLE DM_OTP_DATA ( CREATE TABLE DM_OTP_DATA (
ID INT IDENTITY NOT NULL, ID INT IDENTITY NOT NULL,
OTP_TOKEN VARCHAR(100) NOT NULL, OTP_TOKEN VARCHAR(100) NOT NULL,
@ -721,7 +722,7 @@ DM_POLICY_COMPLIANCE_STATUS) DEVICE_WITH_POLICY_INFO
ON DEVICE_INFO.DEVICE_ID = DEVICE_WITH_POLICY_INFO.DEVICE_ID ON DEVICE_INFO.DEVICE_ID = DEVICE_WITH_POLICY_INFO.DEVICE_ID
ORDER BY DEVICE_INFO.DEVICE_ID'); ORDER BY DEVICE_INFO.DEVICE_ID');
IF NOT EXISTS (SELECT * FROM SYS.VIEWS WHERE NAME = 'CREATE VIEW FEATURE_NON_COMPLIANCE_INFO') IF NOT EXISTS (SELECT * FROM SYS.VIEWS WHERE NAME = 'FEATURE_NON_COMPLIANCE_INFO')
exec('CREATE VIEW FEATURE_NON_COMPLIANCE_INFO AS exec('CREATE VIEW FEATURE_NON_COMPLIANCE_INFO AS
SELECT TOP 100 PERCENT SELECT TOP 100 PERCENT
DM_DEVICE.ID AS DEVICE_ID, DM_DEVICE.ID AS DEVICE_ID,
@ -876,8 +877,8 @@ IF NOT EXISTS (SELECT * FROM SYS.OBJECTS WHERE OBJECT_ID = OBJECT_ID(N'[DBO].[D
CREATE TABLE DM_DEVICE_SUB_TYPE ( CREATE TABLE DM_DEVICE_SUB_TYPE (
TENANT_ID INT DEFAULT 0, TENANT_ID INT DEFAULT 0,
SUB_TYPE_ID VARCHAR(45) NOT NULL, SUB_TYPE_ID VARCHAR(45) NOT NULL,
DEVICE_TYPE VARCHAR(25) NOT NULL, DEVICE_TYPE VARCHAR(45) NOT NULL,
SUB_TYPE_NAME VARCHAR(45) NOT NULL, SUB_TYPE_NAME VARCHAR(100) NOT NULL,
TYPE_DEFINITION TEXT NOT NULL, TYPE_DEFINITION TEXT NOT NULL,
PRIMARY KEY (SUB_TYPE_ID,DEVICE_TYPE) PRIMARY KEY (SUB_TYPE_ID,DEVICE_TYPE)
); );
@ -904,7 +905,7 @@ CREATE TABLE SUB_OPERATION_TEMPLATE (
OPERATION_DEFINITION VARCHAR(MAX) NOT NULL, OPERATION_DEFINITION VARCHAR(MAX) NOT NULL,
OPERATION_CODE varchar(100) NOT NULL, OPERATION_CODE varchar(100) NOT NULL,
SUB_TYPE_ID VARCHAR(45) NOT NULL, SUB_TYPE_ID VARCHAR(45) NOT NULL,
DEVICE_TYPE VARCHAR(25) NOT NULL, DEVICE_TYPE VARCHAR(45) NOT NULL,
CREATE_TIMESTAMP BIGINT NULL DEFAULT NULL, CREATE_TIMESTAMP BIGINT NULL DEFAULT NULL,
UPDATE_TIMESTAMP BIGINT NULL DEFAULT NULL, UPDATE_TIMESTAMP BIGINT NULL DEFAULT NULL,
PRIMARY KEY (SUB_OPERATION_TEMPLATE_ID), PRIMARY KEY (SUB_OPERATION_TEMPLATE_ID),
@ -912,4 +913,4 @@ CREATE TABLE SUB_OPERATION_TEMPLATE (
CONSTRAINT fk_SUB_OPERATION_TEMPLATE_DM_DEVICE_SUB_TYPE FOREIGN KEY (SUB_TYPE_ID, DEVICE_TYPE) REFERENCES DM_DEVICE_SUB_TYPE (SUB_TYPE_ID, DEVICE_TYPE) CONSTRAINT fk_SUB_OPERATION_TEMPLATE_DM_DEVICE_SUB_TYPE FOREIGN KEY (SUB_TYPE_ID, DEVICE_TYPE) REFERENCES DM_DEVICE_SUB_TYPE (SUB_TYPE_ID, DEVICE_TYPE)
); );
-- END SUB_OPERATION_TEMPLATE TABLE-- -- END SUB_OPERATION_TEMPLATE TABLE--

@ -656,7 +656,7 @@ CREATE TABLE IF NOT EXISTS DM_METADATA (
METADATA_ID INTEGER NOT NULL AUTO_INCREMENT, METADATA_ID INTEGER NOT NULL AUTO_INCREMENT,
DATA_TYPE VARCHAR(16) NOT NULL, DATA_TYPE VARCHAR(16) NOT NULL,
METADATA_KEY VARCHAR(128) NOT NULL, METADATA_KEY VARCHAR(128) NOT NULL,
METADATA_VALUE VARCHAR(65535) NOT NULL, METADATA_VALUE TEXT NOT NULL,
TENANT_ID INTEGER NOT NULL, TENANT_ID INTEGER NOT NULL,
PRIMARY KEY (METADATA_ID), PRIMARY KEY (METADATA_ID),
UNIQUE KEY METADATA_KEY_TENANT_ID (METADATA_KEY,TENANT_ID) UNIQUE KEY METADATA_KEY_TENANT_ID (METADATA_KEY,TENANT_ID)
@ -873,8 +873,8 @@ CREATE TABLE IF NOT EXISTS DYNAMIC_TASK_PROPERTIES (
CREATE TABLE IF NOT EXISTS DM_DEVICE_SUB_TYPE ( CREATE TABLE IF NOT EXISTS DM_DEVICE_SUB_TYPE (
TENANT_ID INT DEFAULT 0, TENANT_ID INT DEFAULT 0,
SUB_TYPE_ID VARCHAR(45) NOT NULL, SUB_TYPE_ID VARCHAR(45) NOT NULL,
DEVICE_TYPE VARCHAR(25) NOT NULL, DEVICE_TYPE VARCHAR(45) NOT NULL,
SUB_TYPE_NAME VARCHAR(45) NOT NULL, SUB_TYPE_NAME VARCHAR(100) NOT NULL,
TYPE_DEFINITION TEXT NOT NULL, TYPE_DEFINITION TEXT NOT NULL,
PRIMARY KEY (SUB_TYPE_ID,DEVICE_TYPE) PRIMARY KEY (SUB_TYPE_ID,DEVICE_TYPE)
) ENGINE=InnoDB; ) ENGINE=InnoDB;

@ -999,7 +999,7 @@ CREATE TABLE DM_METADATA (
DATA_TYPE VARCHAR2(16) NOT NULL, DATA_TYPE VARCHAR2(16) NOT NULL,
METADATA_KEY VARCHAR2(128) NOT NULL, METADATA_KEY VARCHAR2(128) NOT NULL,
-- Can be upgrade to 32767 bytes if the MAX_STRING_SIZE initialization parameter is set to EXTENDED -- -- Can be upgrade to 32767 bytes if the MAX_STRING_SIZE initialization parameter is set to EXTENDED --
METADATA_VALUE VARCHAR2(4000) NOT NULL, METADATA_VALUE TEXT NOT NULL,
TENANT_ID INTEGER NOT NULL, TENANT_ID INTEGER NOT NULL,
CONSTRAINT PK_DM_METADATA PRIMARY KEY (METADATA_ID), CONSTRAINT PK_DM_METADATA PRIMARY KEY (METADATA_ID),
CONSTRAINT METADATA_KEY_TENANT_ID UNIQUE (METADATA_KEY, TENANT_ID) CONSTRAINT METADATA_KEY_TENANT_ID UNIQUE (METADATA_KEY, TENANT_ID)
@ -1149,8 +1149,8 @@ CREATE TABLE IF NOT EXISTS DYNAMIC_TASK_PROPERTIES (
CREATE TABLE IF NOT EXISTS DM_DEVICE_SUB_TYPE ( CREATE TABLE IF NOT EXISTS DM_DEVICE_SUB_TYPE (
TENANT_ID INT DEFAULT 0, TENANT_ID INT DEFAULT 0,
SUB_TYPE_ID VARCHAR(45) NOT NULL, SUB_TYPE_ID VARCHAR(45) NOT NULL,
DEVICE_TYPE VARCHAR(25) NOT NULL, DEVICE_TYPE VARCHAR(45) NOT NULL,
SUB_TYPE_NAME VARCHAR(45) NOT NULL, SUB_TYPE_NAME VARCHAR(100) NOT NULL,
TYPE_DEFINITION TEXT NOT NULL, TYPE_DEFINITION TEXT NOT NULL,
PRIMARY KEY (SUB_TYPE_ID,DEVICE_TYPE) PRIMARY KEY (SUB_TYPE_ID,DEVICE_TYPE)
) ENGINE=InnoDB; ) ENGINE=InnoDB;

@ -660,7 +660,7 @@ CREATE TABLE IF NOT EXISTS DM_METADATA (
METADATA_ID BIGSERIAL PRIMARY KEY, METADATA_ID BIGSERIAL PRIMARY KEY,
DATA_TYPE VARCHAR(16) NOT NULL, DATA_TYPE VARCHAR(16) NOT NULL,
METADATA_KEY VARCHAR(128) NOT NULL, METADATA_KEY VARCHAR(128) NOT NULL,
METADATA_VALUE VARCHAR(65535) NOT NULL, METADATA_VALUE TEXT NOT NULL,
TENANT_ID INTEGER NOT NULL, TENANT_ID INTEGER NOT NULL,
CONSTRAINT METADATA_KEY_TENANT_ID UNIQUE(METADATA_KEY, TENANT_ID) CONSTRAINT METADATA_KEY_TENANT_ID UNIQUE(METADATA_KEY, TENANT_ID)
); );
@ -795,8 +795,8 @@ CREATE TABLE IF NOT EXISTS DYNAMIC_TASK_PROPERTIES (
CREATE TABLE IF NOT EXISTS DM_DEVICE_SUB_TYPE ( CREATE TABLE IF NOT EXISTS DM_DEVICE_SUB_TYPE (
TENANT_ID INT DEFAULT 0, TENANT_ID INT DEFAULT 0,
SUB_TYPE_ID VARCHAR(45) NOT NULL, SUB_TYPE_ID VARCHAR(45) NOT NULL,
DEVICE_TYPE VARCHAR(25) NOT NULL, DEVICE_TYPE VARCHAR(45) NOT NULL,
SUB_TYPE_NAME VARCHAR(45) NOT NULL, SUB_TYPE_NAME VARCHAR(100) NOT NULL,
TYPE_DEFINITION TEXT NOT NULL, TYPE_DEFINITION TEXT NOT NULL,
PRIMARY KEY (SUB_TYPE_ID,DEVICE_TYPE) PRIMARY KEY (SUB_TYPE_ID,DEVICE_TYPE)
) ENGINE=InnoDB; ) ENGINE=InnoDB;

Loading…
Cancel
Save