From d70cea2e461f83239b8f808426df8ae3e543d4f6 Mon Sep 17 00:00:00 2001 From: ayyoob Date: Thu, 22 Jun 2017 19:29:04 +0530 Subject: [PATCH] fixed commit issues --- .../DeviceTypeManagementAdminServiceImpl.java | 2 +- .../mgt/jaxrs/util/DeviceMgtAPIUtils.java | 6 ++-- .../HTTPDeviceTypeManagerService.java | 2 +- .../dao/PropertyBasedPluginDAOImpl.java | 30 ++++--------------- .../main/resources/dbscripts/cdm/mssql.sql | 1 + .../main/resources/dbscripts/cdm/mysql.sql | 1 + .../main/resources/dbscripts/cdm/oracle.sql | 1 + .../resources/dbscripts/cdm/postgresql.sql | 1 + 8 files changed, 15 insertions(+), 29 deletions(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/admin/DeviceTypeManagementAdminServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/admin/DeviceTypeManagementAdminServiceImpl.java index 092aefa53e..3cc9401449 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/admin/DeviceTypeManagementAdminServiceImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/admin/DeviceTypeManagementAdminServiceImpl.java @@ -82,7 +82,7 @@ public class DeviceTypeManagementAdminServiceImpl implements DeviceTypeManagemen DeviceMgtAPIUtils.getDeviceManagementService().registerDeviceType(httpDeviceTypeManagerService); return Response.status(Response.Status.OK).build(); } else { - return Response.status(Response.Status.BAD_REQUEST).entity("device type name does not match the pattern " + return Response.status(Response.Status.BAD_REQUEST).entity("Device type name does not match the pattern " + DEVICETYPE_REGEX_PATTERN).build(); } } catch (DeviceManagementException e) { diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/util/DeviceMgtAPIUtils.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/util/DeviceMgtAPIUtils.java index 1ba20a14ce..2df2daba39 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/util/DeviceMgtAPIUtils.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/util/DeviceMgtAPIUtils.java @@ -538,7 +538,7 @@ public class DeviceMgtAPIUtils { Header httpHeader = new Header(); httpHeader.setName(AUTHORIZATION_HEADER); httpHeader.setValue(authValue); - list.add(httpHeader);//"https" + list.add(httpHeader); eventReciverOptions.setProperty(HTTPConstants.HTTP_HEADERS, list); eventReciverOptions.setProperty(HTTPConstants.CUSTOM_PROTOCOL_HANDLER @@ -570,7 +570,7 @@ public class DeviceMgtAPIUtils { Header httpHeader = new Header(); httpHeader.setName(AUTHORIZATION_HEADER); httpHeader.setValue(authValue); - list.add(httpHeader);//"https" + list.add(httpHeader); eventReciverOptions.setProperty(HTTPConstants.HTTP_HEADERS, list); eventReciverOptions.setProperty(HTTPConstants.CUSTOM_PROTOCOL_HANDLER @@ -602,7 +602,7 @@ public class DeviceMgtAPIUtils { Header httpHeader = new Header(); httpHeader.setName(AUTHORIZATION_HEADER); httpHeader.setValue(authValue); - list.add(httpHeader);//"https" + list.add(httpHeader); eventReciverOptions.setProperty(HTTPConstants.HTTP_HEADERS, list); eventReciverOptions.setProperty(HTTPConstants.CUSTOM_PROTOCOL_HANDLER diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/template/HTTPDeviceTypeManagerService.java b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/template/HTTPDeviceTypeManagerService.java index 56dc171db7..8f9f1f4e24 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/template/HTTPDeviceTypeManagerService.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/template/HTTPDeviceTypeManagerService.java @@ -87,7 +87,7 @@ public class HTTPDeviceTypeManagerService extends DeviceTypeManagerService imple if (feature.getMetadataEntries() != null && feature.getMetadataEntries().size() > 0) { List metaValues = new ArrayList<>(); for (Feature.MetadataEntry metadataEntry : feature.getMetadataEntries()) { - metadataEntry.getValue(); + metaValues.add(metadataEntry.getValue().toString()); } configFeature.setMetaData(metaValues); } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/template/dao/PropertyBasedPluginDAOImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/template/dao/PropertyBasedPluginDAOImpl.java index 55419bb5b2..227c352a82 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/template/dao/PropertyBasedPluginDAOImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/template/dao/PropertyBasedPluginDAOImpl.java @@ -135,36 +135,19 @@ public class PropertyBasedPluginDAOImpl implements PluginDAO { "UPDATE DM_DEVICE_PROPERTIES SET PROPERTY_VALUE = ? WHERE DEVICE_TYPE_NAME = ? AND " + "DEVICE_IDENTIFICATION = ? AND PROPERTY_NAME = ? AND TENANT_ID= ?"); - Device.Property[] properties = new Device.Property[device.getProperties().size()]; - int i =0; for (Device.Property property : device.getProperties()) { - properties[i] = property; - i++; - stmt.setString(1, getPropertyValue(device.getProperties(), property.getValue())); + if (!deviceProps.contains(property.getName())) { + continue; + } + stmt.setString(1, property.getValue()); stmt.setString(1, deviceType); stmt.setString(2, device.getDeviceIdentifier()); stmt.setString(3, property.getName()); stmt.setInt(4, PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true)); stmt.addBatch(); } - int[] updates = stmt.executeBatch(); - if (updates.length > 0) { - for (int j = 0; j < updates.length; j++) { - if (updates[j] < 0) { - stmt = conn.prepareStatement( - "INSERT INTO DM_DEVICE_PROPERTIES(DEVICE_TYPE_NAME, DEVICE_IDENTIFICATION, PROPERTY_NAME, " + - "PROPERTY_VALUE, TENANT_ID) VALUES (?, ?, ?, ?, ?)"); - stmt.setString(1, deviceType); - stmt.setString(2, device.getDeviceIdentifier()); - stmt.setString(3, properties[j].getName()); - stmt.setString(4, getPropertyValue(device.getProperties(), properties[j].getValue())); - stmt.setInt(5, PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true)); - stmt.addBatch(); - } - } - stmt.executeBatch(); - status = true; - } + stmt.executeBatch(); + return true; } catch (SQLException e) { String msg = "Error occurred while modifying the device '" + device.getDeviceIdentifier() + "' data on" + deviceType; @@ -173,7 +156,6 @@ public class PropertyBasedPluginDAOImpl implements PluginDAO { } finally { DeviceTypeUtils.cleanupResources(stmt, null); } - return status; } public boolean deleteDevice(String deviceId) throws DeviceTypeMgtPluginException { diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/mssql.sql b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/mssql.sql index 5ea9aefad1..fcaccc6f4e 100644 --- a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/mssql.sql +++ b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/mssql.sql @@ -100,6 +100,7 @@ IF NOT EXISTS (SELECT * FROM SYS.OBJECTS WHERE OBJECT_ID = OBJECT_ID(N'[DBO].[D CREATE TABLE DM_CONFIG_OPERATION ( OPERATION_ID INTEGER NOT NULL, OPERATION_CONFIG VARBINARY(MAX) DEFAULT NULL, + ENABLED BIT NOT NULL DEFAULT 0, PRIMARY KEY (OPERATION_ID), CONSTRAINT FK_DM_OPERATION_CONFIG FOREIGN KEY (OPERATION_ID) REFERENCES DM_OPERATION (ID) ON DELETE NO ACTION ON UPDATE NO ACTION diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/mysql.sql b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/mysql.sql index a5aabc9c5f..531f443942 100644 --- a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/mysql.sql +++ b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/mysql.sql @@ -86,6 +86,7 @@ CREATE TABLE IF NOT EXISTS DM_OPERATION ( CREATE TABLE IF NOT EXISTS DM_CONFIG_OPERATION ( OPERATION_ID INTEGER NOT NULL, OPERATION_CONFIG BLOB DEFAULT NULL, + ENABLED BOOLEAN NOT NULL DEFAULT FALSE, PRIMARY KEY (OPERATION_ID), CONSTRAINT FK_DM_OPERATION_CONFIG FOREIGN KEY (OPERATION_ID) REFERENCES DM_OPERATION (ID) ON DELETE NO ACTION ON UPDATE NO ACTION diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/oracle.sql b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/oracle.sql index 1fbd477d6d..a84b67f8ac 100644 --- a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/oracle.sql +++ b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/oracle.sql @@ -165,6 +165,7 @@ WHEN (NEW.ID IS NULL) CREATE TABLE DM_CONFIG_OPERATION ( OPERATION_ID NUMBER(10) NOT NULL, OPERATION_CONFIG BLOB DEFAULT NULL, + ENABLED NUMBER(10) DEFAULT 0 NOT NULL, CONSTRAINT PK_DM_CONFIG_OPERATION PRIMARY KEY (OPERATION_ID), CONSTRAINT FK_DM_OPERATION_CONFIG FOREIGN KEY (OPERATION_ID) REFERENCES DM_OPERATION (ID) diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/postgresql.sql b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/postgresql.sql index 499903dca8..6bb1f714fb 100644 --- a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/postgresql.sql +++ b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/postgresql.sql @@ -72,6 +72,7 @@ CREATE TABLE IF NOT EXISTS DM_OPERATION ( CREATE TABLE IF NOT EXISTS DM_CONFIG_OPERATION ( OPERATION_ID INTEGER NOT NULL, OPERATION_CONFIG BYTEA DEFAULT NULL, + ENABLED BOOLEAN NOT NULL DEFAULT FALSE, PRIMARY KEY (OPERATION_ID), CONSTRAINT fk_dm_operation_config FOREIGN KEY (OPERATION_ID) REFERENCES DM_OPERATION (ID) ON DELETE NO ACTION ON UPDATE NO ACTION