diff --git a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.api/src/main/java/io/entgra/device/mgt/core/device/mgt/api/jaxrs/service/impl/GeoLocationBasedServiceImpl.java b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.api/src/main/java/io/entgra/device/mgt/core/device/mgt/api/jaxrs/service/impl/GeoLocationBasedServiceImpl.java index b45725c5c1..837e9ea9e7 100644 --- a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.api/src/main/java/io/entgra/device/mgt/core/device/mgt/api/jaxrs/service/impl/GeoLocationBasedServiceImpl.java +++ b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.api/src/main/java/io/entgra/device/mgt/core/device/mgt/api/jaxrs/service/impl/GeoLocationBasedServiceImpl.java @@ -870,6 +870,14 @@ public class GeoLocationBasedServiceImpl implements GeoLocationBasedService { PaginationResult paginationResult = new PaginationResult(); paginationResult.setData(geofenceList); 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(); } diff --git a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.api/src/main/java/io/entgra/device/mgt/core/device/mgt/api/jaxrs/service/impl/UserManagementServiceImpl.java b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.api/src/main/java/io/entgra/device/mgt/core/device/mgt/api/jaxrs/service/impl/UserManagementServiceImpl.java index 6d24ee6aa3..cdf3fb8342 100644 --- a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.api/src/main/java/io/entgra/device/mgt/core/device/mgt/api/jaxrs/service/impl/UserManagementServiceImpl.java +++ b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.api/src/main/java/io/entgra/device/mgt/core/device/mgt/api/jaxrs/service/impl/UserManagementServiceImpl.java @@ -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.JsonObject; +import io.entgra.device.mgt.core.device.mgt.common.Device; import org.apache.commons.lang.StringUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -320,32 +321,42 @@ public class UserManagementServiceImpl implements UserManagementService { @Consumes(MediaType.WILDCARD) @Override public Response removeUser(@QueryParam("username") String username, @QueryParam("domain") String domain) { + boolean nameWithDomain = false; if (domain != null && !domain.isEmpty()) { username = domain + '/' + username; + nameWithDomain = true; } try { + int deviceCount; UserStoreManager userStoreManager = DeviceMgtAPIUtils.getUserStoreManager(); if (!userStoreManager.isExistingUser(username)) { 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(); } - // Un-enroll all devices for the user DeviceManagementProviderService deviceManagementService = DeviceMgtAPIUtils.getDeviceManagementService(); - deviceManagementService.setStatus(username, EnrolmentInfo.Status.REMOVED); - - userStoreManager.deleteUser(username); - if (log.isDebugEnabled()) { - log.debug("User '" + username + "' was successfully removed."); + if (nameWithDomain) { + deviceCount = deviceManagementService.getDeviceCount(username.split("/")[1]); + } else { + deviceCount = deviceManagementService.getDeviceCount(username); + } + 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) { - 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); - return Response.serverError().entity( - new ErrorResponse.ErrorResponseBuilder().setMessage(msg).build()).build(); + return Response.status(400).entity(msg).build(); } } diff --git a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.api/src/test/java/io/entgra/device/mgt/core/device/mgt/api/jaxrs/service/impl/UserManagementServiceImplTest.java b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.api/src/test/java/io/entgra/device/mgt/core/device/mgt/api/jaxrs/service/impl/UserManagementServiceImplTest.java index e517561279..d032194a1f 100644 --- a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.api/src/test/java/io/entgra/device/mgt/core/device/mgt/api/jaxrs/service/impl/UserManagementServiceImplTest.java +++ b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.api/src/test/java/io/entgra/device/mgt/core/device/mgt/api/jaxrs/service/impl/UserManagementServiceImplTest.java @@ -18,6 +18,7 @@ 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.invocation.InvocationOnMock; import org.mockito.stubbing.Answer; @@ -272,7 +273,7 @@ public class UserManagementServiceImplTest { .toReturn(this.userStoreManager); PowerMockito.stub(PowerMockito.method(DeviceMgtAPIUtils.class, "getDeviceManagementService")) .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()); Response response = userManagementService.removeUser(TEST_USERNAME, null); 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(), "Response returned successful for a user updating request with problematic inputs"); 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 = userManagementService.getRolesOfUser(TEST3_USERNAME, null); Assert.assertEquals(response.getStatus(), Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), diff --git a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.common/src/main/java/io/entgra/device/mgt/core/device/mgt/common/geo/service/GeoLocationProviderService.java b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.common/src/main/java/io/entgra/device/mgt/core/device/mgt/common/geo/service/GeoLocationProviderService.java index 920cdac80e..c214971604 100644 --- a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.common/src/main/java/io/entgra/device/mgt/core/device/mgt/common/geo/service/GeoLocationProviderService.java +++ b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.common/src/main/java/io/entgra/device/mgt/core/device/mgt/common/geo/service/GeoLocationProviderService.java @@ -171,4 +171,11 @@ public interface GeoLocationProviderService { * @throws GeoLocationBasedServiceException any errors occurred while reading event records to geofence */ List 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; } diff --git a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/dao/GeofenceDAO.java b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/dao/GeofenceDAO.java index a6fcf172e5..1546d4034e 100644 --- a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/dao/GeofenceDAO.java +++ b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/dao/GeofenceDAO.java @@ -174,4 +174,12 @@ public interface GeofenceDAO { * @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; } diff --git a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/dao/impl/AbstractGeofenceDAOImpl.java b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/dao/impl/AbstractGeofenceDAOImpl.java index c575ea60dc..393a11bf20 100644 --- a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/dao/impl/AbstractGeofenceDAOImpl.java +++ b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/dao/impl/AbstractGeofenceDAOImpl.java @@ -644,4 +644,28 @@ public abstract class AbstractGeofenceDAOImpl implements GeofenceDAO { 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); + } + } + } diff --git a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/dao/impl/device/GenericDeviceDAOImpl.java b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/dao/impl/device/GenericDeviceDAOImpl.java index 32bffa5af4..fcb1799568 100644 --- a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/dao/impl/device/GenericDeviceDAOImpl.java +++ b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/dao/impl/device/GenericDeviceDAOImpl.java @@ -94,7 +94,7 @@ public class GenericDeviceDAOImpl extends AbstractDeviceDAOImpl { "t.NAME AS DEVICE_TYPE "; //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 + "FROM DM_DEVICE d " + "INNER JOIN DM_DEVICE_TYPE t ON d.DEVICE_TYPE_ID = t.ID " + @@ -170,7 +170,7 @@ public class GenericDeviceDAOImpl extends AbstractDeviceDAOImpl { if (isSerialProvided) { stmt.setString(paramIdx++, "%" + serial + "%"); } - if (!request.getCustomProperty().isEmpty()) { + if (request.getCustomProperty() != null && !request.getCustomProperty().isEmpty()) { for (Map.Entry entry : request.getCustomProperty().entrySet()) { stmt.setString(paramIdx++, "%" + entry.getValue() + "%"); } diff --git a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/geo/service/GeoLocationProviderServiceImpl.java b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/geo/service/GeoLocationProviderServiceImpl.java index ac5c6fac5b..edac4eaa09 100644 --- a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/geo/service/GeoLocationProviderServiceImpl.java +++ b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/geo/service/GeoLocationProviderServiceImpl.java @@ -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 * diff --git a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/service/DeviceManagementProviderServiceImpl.java b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/service/DeviceManagementProviderServiceImpl.java index 8413b1499f..344325ae10 100644 --- a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/service/DeviceManagementProviderServiceImpl.java +++ b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/service/DeviceManagementProviderServiceImpl.java @@ -652,7 +652,7 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv Map deviceManagerMap = new HashMap<>(); List deviceCacheKeyList = new ArrayList<>(); List existingDevices; - List validDevices = new ArrayList<>();; + List validDevices = new ArrayList<>(); int tenantId = this.getTenantId(); try { diff --git a/components/subtype-mgt/io.entgra.device.mgt.core.subtype.mgt/src/main/java/io/entgra/device/mgt/core/subtype/mgt/cache/GetDeviceSubTypeCacheLoader.java b/components/subtype-mgt/io.entgra.device.mgt.core.subtype.mgt/src/main/java/io/entgra/device/mgt/core/subtype/mgt/cache/GetDeviceSubTypeCacheLoader.java index 7819a2ed99..c6d8c0e69d 100644 --- a/components/subtype-mgt/io.entgra.device.mgt.core.subtype.mgt/src/main/java/io/entgra/device/mgt/core/subtype/mgt/cache/GetDeviceSubTypeCacheLoader.java +++ b/components/subtype-mgt/io.entgra.device.mgt.core.subtype.mgt/src/main/java/io/entgra/device/mgt/core/subtype/mgt/cache/GetDeviceSubTypeCacheLoader.java @@ -47,7 +47,7 @@ public class GetDeviceSubTypeCacheLoader extends CacheLoader getAllDeviceSubTypes(int tenantId, DeviceSubType.DeviceType deviceType) + List 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; } diff --git a/components/subtype-mgt/io.entgra.device.mgt.core.subtype.mgt/src/main/java/io/entgra/device/mgt/core/subtype/mgt/dao/DeviceSubTypeDAOFactory.java b/components/subtype-mgt/io.entgra.device.mgt.core.subtype.mgt/src/main/java/io/entgra/device/mgt/core/subtype/mgt/dao/DeviceSubTypeDAOFactory.java index 0a6c962cd4..d83558cd59 100644 --- a/components/subtype-mgt/io.entgra.device.mgt.core.subtype.mgt/src/main/java/io/entgra/device/mgt/core/subtype/mgt/dao/DeviceSubTypeDAOFactory.java +++ b/components/subtype-mgt/io.entgra.device.mgt.core.subtype.mgt/src/main/java/io/entgra/device/mgt/core/subtype/mgt/dao/DeviceSubTypeDAOFactory.java @@ -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 diff --git a/components/subtype-mgt/io.entgra.device.mgt.core.subtype.mgt/src/main/java/io/entgra/device/mgt/core/subtype/mgt/dao/impl/DeviceSubTypeDAOImpl.java b/components/subtype-mgt/io.entgra.device.mgt.core.subtype.mgt/src/main/java/io/entgra/device/mgt/core/subtype/mgt/dao/impl/DeviceSubTypeDAOImpl.java index a6224a2ed2..ecfc1fbcc4 100644 --- a/components/subtype-mgt/io.entgra.device.mgt.core.subtype.mgt/src/main/java/io/entgra/device/mgt/core/subtype/mgt/dao/impl/DeviceSubTypeDAOImpl.java +++ b/components/subtype-mgt/io.entgra.device.mgt.core.subtype.mgt/src/main/java/io/entgra/device/mgt/core/subtype/mgt/dao/impl/DeviceSubTypeDAOImpl.java @@ -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 getAllDeviceSubTypes(int tenantId, DeviceSubType.DeviceType deviceType) + public List 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); diff --git a/components/subtype-mgt/io.entgra.device.mgt.core.subtype.mgt/src/main/java/io/entgra/device/mgt/core/subtype/mgt/dao/util/DAOUtil.java b/components/subtype-mgt/io.entgra.device.mgt.core.subtype.mgt/src/main/java/io/entgra/device/mgt/core/subtype/mgt/dao/util/DAOUtil.java index 9473a88c6b..34e108a4a6 100644 --- a/components/subtype-mgt/io.entgra.device.mgt.core.subtype.mgt/src/main/java/io/entgra/device/mgt/core/subtype/mgt/dao/util/DAOUtil.java +++ b/components/subtype-mgt/io.entgra.device.mgt.core.subtype.mgt/src/main/java/io/entgra/device/mgt/core/subtype/mgt/dao/util/DAOUtil.java @@ -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 DeviceSubType setDeviceSubType(T objType, String typeDef) { + public 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; } diff --git a/components/subtype-mgt/io.entgra.device.mgt.core.subtype.mgt/src/main/java/io/entgra/device/mgt/core/subtype/mgt/dto/DeviceSubType.java b/components/subtype-mgt/io.entgra.device.mgt.core.subtype.mgt/src/main/java/io/entgra/device/mgt/core/subtype/mgt/dto/DeviceSubType.java index f914bf9930..84eaa124c6 100644 --- a/components/subtype-mgt/io.entgra.device.mgt.core.subtype.mgt/src/main/java/io/entgra/device/mgt/core/subtype/mgt/dto/DeviceSubType.java +++ b/components/subtype-mgt/io.entgra.device.mgt.core.subtype.mgt/src/main/java/io/entgra/device/mgt/core/subtype/mgt/dto/DeviceSubType.java @@ -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 DeviceSubType setDeviceSubType(T objType, String typeDef); + public abstract DeviceSubType convertToDeviceSubType(); - public abstract String parseSubTypeToJson(Object objType) throws JsonProcessingException; + public abstract String parseSubTypeToJson() throws JsonProcessingException; - public enum DeviceType { - COM, METER, SIM - } } diff --git a/components/subtype-mgt/io.entgra.device.mgt.core.subtype.mgt/src/main/java/io/entgra/device/mgt/core/subtype/mgt/dto/DeviceSubTypeCacheKey.java b/components/subtype-mgt/io.entgra.device.mgt.core.subtype.mgt/src/main/java/io/entgra/device/mgt/core/subtype/mgt/dto/DeviceSubTypeCacheKey.java index eb66f92a46..2834300d5f 100644 --- a/components/subtype-mgt/io.entgra.device.mgt.core.subtype.mgt/src/main/java/io/entgra/device/mgt/core/subtype/mgt/dto/DeviceSubTypeCacheKey.java +++ b/components/subtype-mgt/io.entgra.device.mgt.core.subtype.mgt/src/main/java/io/entgra/device/mgt/core/subtype/mgt/dto/DeviceSubTypeCacheKey.java @@ -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; } } diff --git a/components/subtype-mgt/io.entgra.device.mgt.core.subtype.mgt/src/main/java/io/entgra/device/mgt/core/subtype/mgt/impl/DeviceSubTypeServiceImpl.java b/components/subtype-mgt/io.entgra.device.mgt.core.subtype.mgt/src/main/java/io/entgra/device/mgt/core/subtype/mgt/impl/DeviceSubTypeServiceImpl.java index 5af54eabf9..24d8ced648 100644 --- a/components/subtype-mgt/io.entgra.device.mgt.core.subtype.mgt/src/main/java/io/entgra/device/mgt/core/subtype/mgt/impl/DeviceSubTypeServiceImpl.java +++ b/components/subtype-mgt/io.entgra.device.mgt.core.subtype.mgt/src/main/java/io/entgra/device/mgt/core/subtype/mgt/impl/DeviceSubTypeServiceImpl.java @@ -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 getAllDeviceSubTypes(int tenantId, DeviceSubType.DeviceType deviceType) + public List 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; diff --git a/components/subtype-mgt/io.entgra.device.mgt.core.subtype.mgt/src/main/java/io/entgra/device/mgt/core/subtype/mgt/spi/DeviceSubTypeService.java b/components/subtype-mgt/io.entgra.device.mgt.core.subtype.mgt/src/main/java/io/entgra/device/mgt/core/subtype/mgt/spi/DeviceSubTypeService.java index 6ccf98d748..c77987f255 100644 --- a/components/subtype-mgt/io.entgra.device.mgt.core.subtype.mgt/src/main/java/io/entgra/device/mgt/core/subtype/mgt/spi/DeviceSubTypeService.java +++ b/components/subtype-mgt/io.entgra.device.mgt.core.subtype.mgt/src/main/java/io/entgra/device/mgt/core/subtype/mgt/spi/DeviceSubTypeService.java @@ -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 getAllDeviceSubTypes(int tenantId, DeviceSubType.DeviceType deviceType) + List 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; } diff --git a/components/subtype-mgt/io.entgra.device.mgt.core.subtype.mgt/src/main/java/io/entgra/device/mgt/core/subtype/mgt/util/DeviceSubTypeMgtUtil.java b/components/subtype-mgt/io.entgra.device.mgt.core.subtype.mgt/src/main/java/io/entgra/device/mgt/core/subtype/mgt/util/DeviceSubTypeMgtUtil.java index 76222e21f7..1d84bbf0f9 100644 --- a/components/subtype-mgt/io.entgra.device.mgt.core.subtype.mgt/src/main/java/io/entgra/device/mgt/core/subtype/mgt/util/DeviceSubTypeMgtUtil.java +++ b/components/subtype-mgt/io.entgra.device.mgt.core.subtype.mgt/src/main/java/io/entgra/device/mgt/core/subtype/mgt/util/DeviceSubTypeMgtUtil.java @@ -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); diff --git a/components/subtype-mgt/io.entgra.device.mgt.core.subtype.mgt/src/test/java/io/entgra/device/mgt/core/subtype/mgt/DAONegativeTest.java b/components/subtype-mgt/io.entgra.device.mgt.core.subtype.mgt/src/test/java/io/entgra/device/mgt/core/subtype/mgt/DAONegativeTest.java index 421fb804ae..e0492ace14 100644 --- a/components/subtype-mgt/io.entgra.device.mgt.core.subtype.mgt/src/test/java/io/entgra/device/mgt/core/subtype/mgt/DAONegativeTest.java +++ b/components/subtype-mgt/io.entgra.device.mgt.core.subtype.mgt/src/test/java/io/entgra/device/mgt/core/subtype/mgt/DAONegativeTest.java @@ -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 DeviceSubType setDeviceSubType(T objType, String typeDef) { + public 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 DeviceSubType setDeviceSubType(T objType, String typeDef) { + public 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 DeviceSubType setDeviceSubType(T objType, String typeDef) { + public 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 { diff --git a/components/subtype-mgt/io.entgra.device.mgt.core.subtype.mgt/src/test/java/io/entgra/device/mgt/core/subtype/mgt/DAOTest.java b/components/subtype-mgt/io.entgra.device.mgt.core.subtype.mgt/src/test/java/io/entgra/device/mgt/core/subtype/mgt/DAOTest.java index f4c51ab6d1..89d5797491 100644 --- a/components/subtype-mgt/io.entgra.device.mgt.core.subtype.mgt/src/test/java/io/entgra/device/mgt/core/subtype/mgt/DAOTest.java +++ b/components/subtype-mgt/io.entgra.device.mgt.core.subtype.mgt/src/test/java/io/entgra/device/mgt/core/subtype/mgt/DAOTest.java @@ -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 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 DeviceSubType setDeviceSubType(T objType, String typeDef) { + public 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(); diff --git a/components/subtype-mgt/io.entgra.device.mgt.core.subtype.mgt/src/test/java/io/entgra/device/mgt/core/subtype/mgt/ServiceNegativeTest.java b/components/subtype-mgt/io.entgra.device.mgt.core.subtype.mgt/src/test/java/io/entgra/device/mgt/core/subtype/mgt/ServiceNegativeTest.java index 0c1d15e382..0624cd0afd 100644 --- a/components/subtype-mgt/io.entgra.device.mgt.core.subtype.mgt/src/test/java/io/entgra/device/mgt/core/subtype/mgt/ServiceNegativeTest.java +++ b/components/subtype-mgt/io.entgra.device.mgt.core.subtype.mgt/src/test/java/io/entgra/device/mgt/core/subtype/mgt/ServiceNegativeTest.java @@ -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 DeviceSubType setDeviceSubType(T objType, String typeDef) { + public 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 DeviceSubType setDeviceSubType(T objType, String typeDef) { + public 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); diff --git a/components/subtype-mgt/io.entgra.device.mgt.core.subtype.mgt/src/test/java/io/entgra/device/mgt/core/subtype/mgt/ServiceTest.java b/components/subtype-mgt/io.entgra.device.mgt.core.subtype.mgt/src/test/java/io/entgra/device/mgt/core/subtype/mgt/ServiceTest.java index d5e3b96556..8d800a2c69 100644 --- a/components/subtype-mgt/io.entgra.device.mgt.core.subtype.mgt/src/test/java/io/entgra/device/mgt/core/subtype/mgt/ServiceTest.java +++ b/components/subtype-mgt/io.entgra.device.mgt.core.subtype.mgt/src/test/java/io/entgra/device/mgt/core/subtype/mgt/ServiceTest.java @@ -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 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 DeviceSubType setDeviceSubType(T objType, String typeDef) { + public 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); } diff --git a/components/subtype-mgt/io.entgra.device.mgt.core.subtype.mgt/src/test/java/io/entgra/device/mgt/core/subtype/mgt/TestUtils.java b/components/subtype-mgt/io.entgra.device.mgt.core.subtype.mgt/src/test/java/io/entgra/device/mgt/core/subtype/mgt/TestUtils.java index b5b8011e76..24f70a7afd 100644 --- a/components/subtype-mgt/io.entgra.device.mgt.core.subtype.mgt/src/test/java/io/entgra/device/mgt/core/subtype/mgt/TestUtils.java +++ b/components/subtype-mgt/io.entgra.device.mgt.core.subtype.mgt/src/test/java/io/entgra/device/mgt/core/subtype/mgt/TestUtils.java @@ -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); } diff --git a/features/device-mgt/io.entgra.device.mgt.core.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/h2.sql b/features/device-mgt/io.entgra.device.mgt.core.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/h2.sql index 4f9f9fa5dc..b1f68e0570 100644 --- a/features/device-mgt/io.entgra.device.mgt.core.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/h2.sql +++ b/features/device-mgt/io.entgra.device.mgt.core.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/h2.sql @@ -594,7 +594,7 @@ CREATE TABLE IF NOT EXISTS DM_METADATA ( METADATA_ID INT AUTO_INCREMENT NOT NULL, DATA_TYPE VARCHAR(16) NOT NULL, METADATA_KEY VARCHAR(128) NOT NULL, - METADATA_VALUE VARCHAR(65535) NOT NULL, + METADATA_VALUE TEXT NOT NULL, TENANT_ID INTEGER NOT NULL, PRIMARY KEY (METADATA_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 ( 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) ); diff --git a/features/device-mgt/io.entgra.device.mgt.core.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/mssql.sql b/features/device-mgt/io.entgra.device.mgt.core.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/mssql.sql index 4c8c753448..7090ca20ff 100644 --- a/features/device-mgt/io.entgra.device.mgt.core.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/mssql.sql +++ b/features/device-mgt/io.entgra.device.mgt.core.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/mssql.sql @@ -664,7 +664,7 @@ CREATE TABLE DM_METADATA ( METADATA_ID INTEGER IDENTITY(1,1) NOT NULL, DATA_TYPE VARCHAR(16) NOT NULL, METADATA_KEY VARCHAR(128) NOT NULL, - METADATA_VALUE VARCHAR(8000) NOT NULL, + METADATA_VALUE TEXT NOT NULL, TENANT_ID INTEGER NOT NULL, PRIMARY KEY (METADATA_ID), CONSTRAINT METADATA_KEY_TENANT_ID UNIQUE(METADATA_KEY, TENANT_ID) @@ -672,6 +672,7 @@ CREATE TABLE DM_METADATA ( -- END OF METADATA 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 ( ID INT IDENTITY 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 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 SELECT TOP 100 PERCENT 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 ( 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) ); @@ -904,7 +905,7 @@ CREATE TABLE SUB_OPERATION_TEMPLATE ( OPERATION_DEFINITION VARCHAR(MAX) NOT NULL, OPERATION_CODE varchar(100) 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, UPDATE_TIMESTAMP BIGINT NULL DEFAULT NULL, 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) ); --- END SUB_OPERATION_TEMPLATE TABLE-- \ No newline at end of file +-- END SUB_OPERATION_TEMPLATE TABLE-- diff --git a/features/device-mgt/io.entgra.device.mgt.core.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/mysql.sql b/features/device-mgt/io.entgra.device.mgt.core.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/mysql.sql index 2f4bd489f0..5e33d6b2b4 100644 --- a/features/device-mgt/io.entgra.device.mgt.core.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/mysql.sql +++ b/features/device-mgt/io.entgra.device.mgt.core.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/mysql.sql @@ -656,7 +656,7 @@ CREATE TABLE IF NOT EXISTS DM_METADATA ( METADATA_ID INTEGER NOT NULL AUTO_INCREMENT, DATA_TYPE VARCHAR(16) NOT NULL, METADATA_KEY VARCHAR(128) NOT NULL, - METADATA_VALUE VARCHAR(65535) NOT NULL, + METADATA_VALUE TEXT NOT NULL, TENANT_ID INTEGER NOT NULL, PRIMARY KEY (METADATA_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 ( 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; diff --git a/features/device-mgt/io.entgra.device.mgt.core.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/oracle.sql b/features/device-mgt/io.entgra.device.mgt.core.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/oracle.sql index f85e4349e5..035f31d31d 100644 --- a/features/device-mgt/io.entgra.device.mgt.core.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/oracle.sql +++ b/features/device-mgt/io.entgra.device.mgt.core.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/oracle.sql @@ -999,7 +999,7 @@ CREATE TABLE DM_METADATA ( DATA_TYPE VARCHAR2(16) 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 -- - METADATA_VALUE VARCHAR2(4000) NOT NULL, + METADATA_VALUE TEXT NOT NULL, TENANT_ID INTEGER NOT NULL, CONSTRAINT PK_DM_METADATA PRIMARY KEY (METADATA_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 ( 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; diff --git a/features/device-mgt/io.entgra.device.mgt.core.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/postgresql.sql b/features/device-mgt/io.entgra.device.mgt.core.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/postgresql.sql index 2d72a7b423..1b9393885c 100644 --- a/features/device-mgt/io.entgra.device.mgt.core.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/postgresql.sql +++ b/features/device-mgt/io.entgra.device.mgt.core.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/postgresql.sql @@ -660,7 +660,7 @@ CREATE TABLE IF NOT EXISTS DM_METADATA ( METADATA_ID BIGSERIAL PRIMARY KEY, DATA_TYPE VARCHAR(16) NOT NULL, METADATA_KEY VARCHAR(128) NOT NULL, - METADATA_VALUE VARCHAR(65535) NOT NULL, + METADATA_VALUE TEXT NOT NULL, TENANT_ID INTEGER NOT NULL, 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 ( 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;