From 428ce25b6f9ebb54d6357bc6368207637df35241 Mon Sep 17 00:00:00 2001 From: amalhub Date: Tue, 27 Sep 2016 20:46:00 +0530 Subject: [PATCH 1/4] Fixing issue: https://wso2.org/jira/browse/EMM-1646 --- .../org.wso2.carbon.certificate.mgt.api/pom.xml | 2 +- .../device-mgt/org.wso2.carbon.device.mgt.api/pom.xml | 6 +++--- .../device-mgt/org.wso2.carbon.device.mgt.common/pom.xml | 2 +- .../org.wso2.carbon.device.mgt.server.feature/pom.xml | 2 +- pom.xml | 4 ++-- 5 files changed, 8 insertions(+), 8 deletions(-) diff --git a/components/certificate-mgt/org.wso2.carbon.certificate.mgt.api/pom.xml b/components/certificate-mgt/org.wso2.carbon.certificate.mgt.api/pom.xml index 769015dd8d..2bfe2c2519 100644 --- a/components/certificate-mgt/org.wso2.carbon.certificate.mgt.api/pom.xml +++ b/components/certificate-mgt/org.wso2.carbon.certificate.mgt.api/pom.xml @@ -162,7 +162,7 @@ swagger-core - com.fasterxml.jackson.core + org.wso2.orbit.com.fasterxml.jackson.core jackson-annotations diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/pom.xml b/components/device-mgt/org.wso2.carbon.device.mgt.api/pom.xml index a53c50bcaa..3523606ef7 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/pom.xml +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/pom.xml @@ -231,7 +231,7 @@ slf4j-api - com.fasterxml.jackson.core + org.wso2.orbit.com.fasterxml.jackson.core jackson-core @@ -249,7 +249,7 @@ slf4j-api - com.fasterxml.jackson.core + org.wso2.orbit.com.fasterxml.jackson.core jackson-core @@ -270,7 +270,7 @@ provided - com.fasterxml.jackson.core + org.wso2.orbit.com.fasterxml.jackson.core jackson-annotations diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.common/pom.xml b/components/device-mgt/org.wso2.carbon.device.mgt.common/pom.xml index e33265ac2b..ad937f4a86 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.common/pom.xml +++ b/components/device-mgt/org.wso2.carbon.device.mgt.common/pom.xml @@ -66,7 +66,7 @@ provided - com.fasterxml.jackson.core + org.wso2.orbit.com.fasterxml.jackson.core jackson-annotations diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/pom.xml b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/pom.xml index fbcb139624..395f2b0904 100644 --- a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/pom.xml +++ b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/pom.xml @@ -125,7 +125,7 @@ org.wso2.carbon.identity:org.wso2.carbon.identity.oauth.stub:${identity.inbound.auth.oauth.version} - com.fasterxml.jackson.core:jackson-annotations:${jackson-annotations.version} + org.wso2.orbit.com.fasterxml.jackson.core:jackson-annotations:${jackson-annotations.version} diff --git a/pom.xml b/pom.xml index ba1fec5a24..9447965615 100644 --- a/pom.xml +++ b/pom.xml @@ -1501,7 +1501,7 @@ ${carbon.device.mgt.version} - com.fasterxml.jackson.core + org.wso2.orbit.com.fasterxml.jackson.core jackson-annotations ${jackson-annotations.version} @@ -1893,7 +1893,7 @@ 1.0.2 - 2.7.4 + 2.6.1.wso2v1 1.2.0.wso2v1 5.0.2.Final From 7596f7876d94a00adc1a1fd610468b66d21640cc Mon Sep 17 00:00:00 2001 From: dilanua Date: Wed, 28 Sep 2016 14:11:00 +0530 Subject: [PATCH 2/4] Improving device view info.retrieval - UI --- .../modules/business-controllers/device.js | 79 ++++++++++++++----- 1 file changed, 58 insertions(+), 21 deletions(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/business-controllers/device.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/business-controllers/device.js index d743797ba3..6f57d8ae56 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/business-controllers/device.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/business-controllers/device.js @@ -76,32 +76,69 @@ deviceModule = function () { function (backendResponse) { var response = {}; if (backendResponse.status == 200 && backendResponse.responseText) { - response["status"] = "success"; var device = parse(backendResponse.responseText); - var propertiesList = device["properties"]; - var properties = {}; - for (var i = 0; i < propertiesList.length; i++) { - properties[propertiesList[i]["name"]] = - propertiesList[i]["value"]; + + var filteredDeviceData = {}; + if (device["deviceIdentifier"]) { + filteredDeviceData["deviceIdentifier"] = device["deviceIdentifier"]; } - var deviceObject = {}; - deviceObject[constants["DEVICE_IDENTIFIER"]] = device["deviceIdentifier"]; - deviceObject[constants["DEVICE_NAME"]] = device["name"]; - deviceObject[constants["DEVICE_OWNERSHIP"]] = device["enrolmentInfo"]["ownership"]; - deviceObject[constants["DEVICE_OWNER"]] = device["enrolmentInfo"]["owner"]; - deviceObject[constants["DEVICE_STATUS"]] = device["enrolmentInfo"]["status"]; - deviceObject[constants["DEVICE_TYPE"]] = device["type"]; - if (device["type"] == constants["PLATFORM_IOS"]) { - properties[constants["DEVICE_MODEL"]] = properties[constants["DEVICE_PRODUCT"]]; - delete properties[constants["DEVICE_PRODUCT"]]; - properties[constants["DEVICE_VENDOR"]] = constants["VENDOR_APPLE"]; + if (device["type"]) { + filteredDeviceData["type"] = device["type"]; } - deviceObject[constants["DEVICE_PROPERTIES"]] = properties; - if (device["deviceInfo"]) { - deviceObject[constants["DEVICE_INFO"]] = device["deviceInfo"]; + if (device["name"]) { + filteredDeviceData["name"] = device["name"]; + } + if (device["enrolmentInfo"]) { + var enrolmentInfo = {}; + if (device["enrolmentInfo"]["status"]) { + enrolmentInfo["status"] = device["enrolmentInfo"]["status"]; + } + if (device["enrolmentInfo"]["owner"]) { + enrolmentInfo["owner"] = device["enrolmentInfo"]["owner"]; + } + if (device["enrolmentInfo"]["ownership"]) { + enrolmentInfo["ownership"] = device["enrolmentInfo"]["ownership"]; + } + filteredDeviceData["enrolmentInfo"] = enrolmentInfo; + } + if (device["properties"] && device["properties"].length > 0) { + var propertiesList = device["properties"]; + var properties = {}; + for (var i = 0; i < propertiesList.length; i++) { + if (propertiesList[i]["value"]) { + properties[propertiesList[i]["name"]] = + propertiesList[i]["value"]; + } + } + + filteredDeviceData["initialDeviceInfo"] = properties; + + if (properties["DEVICE_INFO"]) { + var initialDeviceInfoList = parse(properties["DEVICE_INFO"]); + var initialDeviceInfo = {}; + for (var j = 0; j < initialDeviceInfoList.length; j++) { + if (initialDeviceInfoList[j]["value"]) { + initialDeviceInfo[initialDeviceInfoList[j]["name"]] = + initialDeviceInfoList[j]["value"]; + } + } + + filteredDeviceData["initialDeviceInfo"]["DEVICE_INFO"] = initialDeviceInfo; + } } - response["content"] = deviceObject; + if (filteredDeviceData["type"]) { + if (filteredDeviceData["type"] == constants["PLATFORM_IOS"]) { + if (filteredDeviceData["properties"]) { + filteredDeviceData["properties"]["VENDOR"] = "Apple"; + } + } + } + if (device["deviceInfo"]) { + filteredDeviceData["latestDeviceInfo"] = device["deviceInfo"]; + } + response["content"] = filteredDeviceData; + response["status"] = "success"; return response; } else if (backendResponse.status == 401) { response["status"] = "unauthorized"; From 82be4ef5a81914c7448c2a7170705f4768d7d388 Mon Sep 17 00:00:00 2001 From: Megala Date: Wed, 28 Sep 2016 15:15:24 +0530 Subject: [PATCH 3/4] Fixing oracle script issues --- ...CertificateManagementServiceComponent.java | 11 +++++++---- .../DeviceManagementServiceComponent.java | 9 +++++++-- .../dao/impl/OracleNotificationDAOImpl.java | 12 ++++++------ .../resources/dbscripts/certMgt/oracle.sql | 14 +++++++++++++- .../main/resources/dbscripts/cdm/oracle.sql | 19 +++++-------------- 5 files changed, 38 insertions(+), 27 deletions(-) diff --git a/components/certificate-mgt/org.wso2.carbon.certificate.mgt.core/src/main/java/org/wso2/carbon/certificate/mgt/core/internal/CertificateManagementServiceComponent.java b/components/certificate-mgt/org.wso2.carbon.certificate.mgt.core/src/main/java/org/wso2/carbon/certificate/mgt/core/internal/CertificateManagementServiceComponent.java index 80198c9560..0766abe86d 100644 --- a/components/certificate-mgt/org.wso2.carbon.certificate.mgt.core/src/main/java/org/wso2/carbon/certificate/mgt/core/internal/CertificateManagementServiceComponent.java +++ b/components/certificate-mgt/org.wso2.carbon.certificate.mgt.core/src/main/java/org/wso2/carbon/certificate/mgt/core/internal/CertificateManagementServiceComponent.java @@ -106,9 +106,14 @@ public class CertificateManagementServiceComponent { private void setupDeviceManagementSchema(DataSourceConfig config) throws CertificateManagementException { CertificateMgtSchemaInitializer initializer = new CertificateMgtSchemaInitializer(config); - log.info("Initializing Certificate management repository database schema"); + String checkSql = "select * from DM_DEVICE_CERTIFICATE"; try { - initializer.createRegistryDatabase(); + if (!initializer.isDatabaseStructureCreated(checkSql)) { + log.info("Initializing Certificate management repository database schema"); + initializer.createRegistryDatabase(); + } else { + log.info("Certificate management repository database already exists. Not creating a new database."); + } } catch (Exception e) { throw new CertificateManagementException( "Error occurred while initializing Certificate Management database schema", e); @@ -117,6 +122,4 @@ public class CertificateManagementServiceComponent { log.debug("Certificate management metadata repository schema has been successfully initialized"); } } - - } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/internal/DeviceManagementServiceComponent.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/internal/DeviceManagementServiceComponent.java index 887f5d966e..f871964569 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/internal/DeviceManagementServiceComponent.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/internal/DeviceManagementServiceComponent.java @@ -265,9 +265,14 @@ public class DeviceManagementServiceComponent { private void setupDeviceManagementSchema(DataSourceConfig config) throws DeviceManagementException { DeviceManagementSchemaInitializer initializer = new DeviceManagementSchemaInitializer(config); - log.info("Initializing device management repository database schema"); + String checkSql = "select * from DM_DEVICE_TYPE"; try { - initializer.createRegistryDatabase(); + if (!initializer.isDatabaseStructureCreated(checkSql)) { + log.info("Initializing device management repository database schema"); + initializer.createRegistryDatabase(); + } else { + log.info("Device management database already exists. Not creating a new database."); + } } catch (Exception e) { throw new DeviceManagementException( "Error occurred while initializing Device Management database schema", e); diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/notification/mgt/dao/impl/OracleNotificationDAOImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/notification/mgt/dao/impl/OracleNotificationDAOImpl.java index 7b6ec31ccb..7e1cefccb7 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/notification/mgt/dao/impl/OracleNotificationDAOImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/notification/mgt/dao/impl/OracleNotificationDAOImpl.java @@ -86,13 +86,13 @@ public class OracleNotificationDAOImpl extends AbstractNotificationDAOImpl { try { conn = NotificationManagementDAOFactory.getConnection(); String sql = "SELECT n1.NOTIFICATION_ID, n1.DEVICE_ID, n1.OPERATION_ID, n1.STATUS," + - " n1.DESCRIPTION, d.DEVICE_IDENTIFICATION, d.NAME as DEVICE_NAME, t.NAME AS DEVICE_TYPE FROM " + - "DM_DEVICE d, DM_DEVICE_TYPE t, (SELECT NOTIFICATION_ID, DEVICE_ID, " + - "OPERATION_ID, STATUS, DESCRIPTION FROM DM_NOTIFICATION WHERE " + - "TENANT_ID = ? AND STATUS = ?) n1 WHERE n1.DEVICE_ID = d.ID AND d.DEVICE_TYPE_ID=t.ID " + - "AND TENANT_ID = ?"; + " n1.DESCRIPTION, d.DEVICE_IDENTIFICATION, d.NAME as DEVICE_NAME, t.NAME AS DEVICE_TYPE FROM " + + "DM_DEVICE d, DM_DEVICE_TYPE t, (SELECT NOTIFICATION_ID, DEVICE_ID, " + + "OPERATION_ID, STATUS, DESCRIPTION FROM DM_NOTIFICATION WHERE " + + "TENANT_ID = ? AND STATUS = ?) n1 WHERE n1.DEVICE_ID = d.ID AND d.DEVICE_TYPE_ID=t.ID " + + "AND TENANT_ID = ?"; - sql = sql + " OFFSET >= ? AND ROWNUM <= ?"; + sql = sql + " ORDER BY n1.NOTIFICATION_ID OFFSET ? ROWS FETCH NEXT ? ROWS ONLY"; stmt = conn.prepareStatement(sql); stmt.setInt(1, tenantId); diff --git a/features/certificate-mgt/org.wso2.carbon.certificate.mgt.server.feature/src/main/resources/dbscripts/certMgt/oracle.sql b/features/certificate-mgt/org.wso2.carbon.certificate.mgt.server.feature/src/main/resources/dbscripts/certMgt/oracle.sql index 75732199f6..825380bd28 100644 --- a/features/certificate-mgt/org.wso2.carbon.certificate.mgt.server.feature/src/main/resources/dbscripts/certMgt/oracle.sql +++ b/features/certificate-mgt/org.wso2.carbon.certificate.mgt.server.feature/src/main/resources/dbscripts/certMgt/oracle.sql @@ -5,4 +5,16 @@ CREATE TABLE DM_DEVICE_CERTIFICATE ( TENANT_ID NUMBER(10) DEFAULT 0, USERNAME VARCHAR2(500) DEFAULT NULL, PRIMARY KEY (ID) -) \ No newline at end of file +) +/ + +-- Generate ID using sequence and trigger +CREATE SEQUENCE DM_DEVICE_CERTIFICATE_seq START WITH 1 INCREMENT BY 1 NOCACHE +/ +CREATE OR REPLACE TRIGGER DM_DEVICE_CERTIFICATE_seq_tr +BEFORE INSERT ON DM_DEVICE_CERTIFICATE FOR EACH ROW +WHEN (NEW.ID IS NULL) + BEGIN + SELECT DM_DEVICE_CERTIFICATE_seq.NEXTVAL INTO :NEW.ID FROM DUAL; + END; +/ \ No newline at end of file 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 39785fc532..f3883d8c3c 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 @@ -3,7 +3,8 @@ CREATE TABLE DM_DEVICE_TYPE ( NAME VARCHAR2(300) DEFAULT NULL, PROVIDER_TENANT_ID INTEGER DEFAULT 0, SHARED_WITH_ALL_TENANTS NUMBER(1) DEFAULT 0 NOT NULL, - CONSTRAINT PK_DM_DEVICE_TYPE PRIMARY KEY (ID) + CONSTRAINT PK_DM_DEVICE_TYPE PRIMARY KEY (ID), + UNIQUE (NAME) ) / -- Generate ID using sequence and trigger @@ -44,16 +45,6 @@ WHEN (NEW.ID IS NULL) SELECT DM_GROUP_seq.NEXTVAL INTO :NEW.ID FROM DUAL; END; / --- Generate ID using sequence and trigger -CREATE SEQUENCE DM_DEVICE_CERTIFICATE_seq START WITH 1 INCREMENT BY 1 NOCACHE -/ -CREATE OR REPLACE TRIGGER DM_DEVICE_CERTIFICATE_seq_tr -BEFORE INSERT ON DM_DEVICE_CERTIFICATE FOR EACH ROW -WHEN (NEW.ID IS NULL) - BEGIN - SELECT DM_DEVICE_CERTIFICATE_seq.NEXTVAL INTO :NEW.ID FROM DUAL; - END; -/ CREATE TABLE DM_DEVICE ( ID NUMBER(10) NOT NULL, @@ -436,7 +427,7 @@ CREATE TABLE DM_DEVICE_POLICY_APPLIED ( POLICY_ID NUMBER(10) NOT NULL , POLICY_CONTENT BLOB NULL , TENANT_ID NUMBER(10) NOT NULL, - APPLIED BOOLEAN NULL , + APPLIED NUMBER(1) DEFAULT 0, CREATED_TIME TIMESTAMP(0) NULL , UPDATED_TIME TIMESTAMP(0) NULL , APPLIED_TIME TIMESTAMP(0) NULL , @@ -860,8 +851,8 @@ POLICY_ID, STATUS AS IS_COMPLIANT FROM 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; / + CREATE VIEW FEATURE_NON_COMPLIANCE_INFO AS SELECT DM_DEVICE.ID AS DEVICE_ID, @@ -885,7 +876,7 @@ DM_POLICY_COMPLIANCE_STATUS.ENROLMENT_ID = DM_ENROLMENT.ID AND DM_POLICY_COMPLIANCE_STATUS.DEVICE_ID = DM_DEVICE.ID AND DM_DEVICE.DEVICE_TYPE_ID = DM_DEVICE_TYPE.ID AND DM_DEVICE.ID = DM_DEVICE_DETAIL.DEVICE_ID -ORDER BY TENANT_ID, DEVICE_ID; +/ -- END OF DASHBOARD RELATED VIEWS -- From cd50fe88bc336fbb83b58cd7255d72bd763fabf6 Mon Sep 17 00:00:00 2001 From: Megala Date: Wed, 28 Sep 2016 16:22:59 +0530 Subject: [PATCH 4/4] Reformatting the code --- .../mgt/dao/impl/OracleNotificationDAOImpl.java | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/notification/mgt/dao/impl/OracleNotificationDAOImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/notification/mgt/dao/impl/OracleNotificationDAOImpl.java index 7e1cefccb7..f5ca55ebbd 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/notification/mgt/dao/impl/OracleNotificationDAOImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/notification/mgt/dao/impl/OracleNotificationDAOImpl.java @@ -85,12 +85,12 @@ public class OracleNotificationDAOImpl extends AbstractNotificationDAOImpl { List notifications = null; try { conn = NotificationManagementDAOFactory.getConnection(); - String sql = "SELECT n1.NOTIFICATION_ID, n1.DEVICE_ID, n1.OPERATION_ID, n1.STATUS," + - " n1.DESCRIPTION, d.DEVICE_IDENTIFICATION, d.NAME as DEVICE_NAME, t.NAME AS DEVICE_TYPE FROM " + - "DM_DEVICE d, DM_DEVICE_TYPE t, (SELECT NOTIFICATION_ID, DEVICE_ID, " + - "OPERATION_ID, STATUS, DESCRIPTION FROM DM_NOTIFICATION WHERE " + - "TENANT_ID = ? AND STATUS = ?) n1 WHERE n1.DEVICE_ID = d.ID AND d.DEVICE_TYPE_ID=t.ID " + - "AND TENANT_ID = ?"; + String sql = "SELECT n1.NOTIFICATION_ID, n1.DEVICE_ID, n1.OPERATION_ID, n1.STATUS," + + " n1.DESCRIPTION, d.DEVICE_IDENTIFICATION, d.NAME as DEVICE_NAME, t.NAME AS DEVICE_TYPE FROM " + + "DM_DEVICE d, DM_DEVICE_TYPE t, (SELECT NOTIFICATION_ID, DEVICE_ID, " + + "OPERATION_ID, STATUS, DESCRIPTION FROM DM_NOTIFICATION WHERE " + + "TENANT_ID = ? AND STATUS = ?) n1 WHERE n1.DEVICE_ID = d.ID AND d.DEVICE_TYPE_ID=t.ID " + + "AND TENANT_ID = ?"; sql = sql + " ORDER BY n1.NOTIFICATION_ID OFFSET ? ROWS FETCH NEXT ? ROWS ONLY";