From 4acb8b2c33e7b5879f782ee28e7a8ef323e3414f Mon Sep 17 00:00:00 2001 From: Charitha Goonetilleke Date: Sun, 26 May 2024 14:34:58 +0530 Subject: [PATCH 1/3] Changes for https://repository.entgra.net/community/device-mgt-core/pulls/394 --- .../api/mocks/DeviceManagementProviderServiceMock.java | 5 +++++ pom.xml | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/components/mobile-plugins/android-plugin/io.entgra.device.mgt.plugins.mobile.android.api/src/test/java/io/entgra/device/mgt/plugins/mobile/android/api/mocks/DeviceManagementProviderServiceMock.java b/components/mobile-plugins/android-plugin/io.entgra.device.mgt.plugins.mobile.android.api/src/test/java/io/entgra/device/mgt/plugins/mobile/android/api/mocks/DeviceManagementProviderServiceMock.java index df3d03d95..bf5314ee9 100644 --- a/components/mobile-plugins/android-plugin/io.entgra.device.mgt.plugins.mobile.android.api/src/test/java/io/entgra/device/mgt/plugins/mobile/android/api/mocks/DeviceManagementProviderServiceMock.java +++ b/components/mobile-plugins/android-plugin/io.entgra.device.mgt.plugins.mobile.android.api/src/test/java/io/entgra/device/mgt/plugins/mobile/android/api/mocks/DeviceManagementProviderServiceMock.java @@ -413,6 +413,11 @@ public class DeviceManagementProviderServiceMock implements DeviceManagementProv } + @Override + public boolean recordDeviceUpdate(DeviceIdentifier deviceIdentifier) throws DeviceManagementException { + return false; + } + @Override public boolean modifyEnrollment(Device device) throws DeviceManagementException { return TestUtils.getDeviceId().equals(device.getDeviceIdentifier()); diff --git a/pom.xml b/pom.xml index 4563b1471..7aac39bf1 100644 --- a/pom.xml +++ b/pom.xml @@ -1166,7 +1166,7 @@ - 5.0.41-SNAPSHOT + 5.0.42-SNAPSHOT [5.0.0, 6.0.0) From ff9abb7563e7476a2b1aaf73d4d1262793554a5e Mon Sep 17 00:00:00 2001 From: Amalka Subasinghe Date: Mon, 27 May 2024 11:59:13 +0000 Subject: [PATCH 2/3] mqtt qos property included for input and set default 0 Co-authored-by: Amalka Subasinghe Co-committed-by: Amalka Subasinghe --- .../adapter/mqtt/MQTTEventAdapterFactory.java | 9 +++++++++ .../adapter/mqtt/util/MQTTAdapterListener.java | 4 +++- .../MQTTBrokerConnectionConfiguration.java | 18 ++++++++++++++++++ .../mqtt/util/MQTTEventAdapterConstants.java | 1 + .../adapter/mqtt/i18n/Resources.properties | 1 + .../adapter/mqtt/MQTTEventAdapterFactory.java | 2 +- 6 files changed, 33 insertions(+), 2 deletions(-) diff --git a/components/extensions/cdmf-transport-adapters/input/io.entgra.device.mgt.plugins.input.adapter.mqtt/src/main/java/io/entgra/device/mgt/plugins/input/adapter/mqtt/MQTTEventAdapterFactory.java b/components/extensions/cdmf-transport-adapters/input/io.entgra.device.mgt.plugins.input.adapter.mqtt/src/main/java/io/entgra/device/mgt/plugins/input/adapter/mqtt/MQTTEventAdapterFactory.java index 0987956c2..027125fff 100644 --- a/components/extensions/cdmf-transport-adapters/input/io.entgra.device.mgt.plugins.input.adapter.mqtt/src/main/java/io/entgra/device/mgt/plugins/input/adapter/mqtt/MQTTEventAdapterFactory.java +++ b/components/extensions/cdmf-transport-adapters/input/io.entgra.device.mgt.plugins.input.adapter.mqtt/src/main/java/io/entgra/device/mgt/plugins/input/adapter/mqtt/MQTTEventAdapterFactory.java @@ -124,6 +124,15 @@ public class MQTTEventAdapterFactory extends InputEventAdapterFactory { clientId.setHint(resourceBundle.getString(MQTTEventAdapterConstants.ADAPTER_CONF_CLIENTID_HINT)); propertyList.add(clientId); + // set qos + Property qosProperty = new Property(MQTTEventAdapterConstants.ADAPTER_MESSAGE_QOS); + qosProperty.setDisplayName(resourceBundle.getString(MQTTEventAdapterConstants.ADAPTER_MESSAGE_QOS)); + qosProperty.setRequired(false); + qosProperty.setOptions(new String[]{"0", "1", "2"}); + qosProperty.setDefaultValue("0"); + + propertyList.add(qosProperty); + return propertyList; } diff --git a/components/extensions/cdmf-transport-adapters/input/io.entgra.device.mgt.plugins.input.adapter.mqtt/src/main/java/io/entgra/device/mgt/plugins/input/adapter/mqtt/util/MQTTAdapterListener.java b/components/extensions/cdmf-transport-adapters/input/io.entgra.device.mgt.plugins.input.adapter.mqtt/src/main/java/io/entgra/device/mgt/plugins/input/adapter/mqtt/util/MQTTAdapterListener.java index 10293bc8c..9f12a5544 100644 --- a/components/extensions/cdmf-transport-adapters/input/io.entgra.device.mgt.plugins.input.adapter.mqtt/src/main/java/io/entgra/device/mgt/plugins/input/adapter/mqtt/util/MQTTAdapterListener.java +++ b/components/extensions/cdmf-transport-adapters/input/io.entgra.device.mgt.plugins.input.adapter.mqtt/src/main/java/io/entgra/device/mgt/plugins/input/adapter/mqtt/util/MQTTAdapterListener.java @@ -56,6 +56,7 @@ public class MQTTAdapterListener implements MqttCallback, Runnable { private MQTTBrokerConnectionConfiguration mqttBrokerConnectionConfiguration; private String topic; + private int qos; private String topicStructure; private String tenantDomain; private volatile boolean connectionSucceeded = false; @@ -79,6 +80,7 @@ public class MQTTAdapterListener implements MqttCallback, Runnable { int keepAlive = mqttBrokerConnectionConfiguration.getKeepAlive(); this.topicStructure = new String(topic); this.topic = PropertyUtils.replacePlaceholders(topic); + this.qos = mqttBrokerConnectionConfiguration.getQos(); this.eventAdapterListener = inputEventAdapterListener; this.tenantDomain = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain(); @@ -158,7 +160,7 @@ public class MQTTAdapterListener implements MqttCallback, Runnable { return false; } try { - mqttClient.subscribe(topic); + mqttClient.subscribe(topic, qos); log.info("mqtt receiver subscribed to topic: " + topic); } catch (MqttException e) { log.error("Failed to subscribe to topic: " + topic + ", Retrying....."); diff --git a/components/extensions/cdmf-transport-adapters/input/io.entgra.device.mgt.plugins.input.adapter.mqtt/src/main/java/io/entgra/device/mgt/plugins/input/adapter/mqtt/util/MQTTBrokerConnectionConfiguration.java b/components/extensions/cdmf-transport-adapters/input/io.entgra.device.mgt.plugins.input.adapter.mqtt/src/main/java/io/entgra/device/mgt/plugins/input/adapter/mqtt/util/MQTTBrokerConnectionConfiguration.java index 06e00e42b..472eec277 100644 --- a/components/extensions/cdmf-transport-adapters/input/io.entgra.device.mgt.plugins.input.adapter.mqtt/src/main/java/io/entgra/device/mgt/plugins/input/adapter/mqtt/util/MQTTBrokerConnectionConfiguration.java +++ b/components/extensions/cdmf-transport-adapters/input/io.entgra.device.mgt.plugins.input.adapter.mqtt/src/main/java/io/entgra/device/mgt/plugins/input/adapter/mqtt/util/MQTTBrokerConnectionConfiguration.java @@ -32,6 +32,7 @@ public class MQTTBrokerConnectionConfiguration { private String brokerScopes = null; private boolean cleanSession = true; private int keepAlive; + private int qos; private String brokerUrl; private String dcrUrl; private String contentValidatorType; @@ -83,6 +84,14 @@ public class MQTTBrokerConnectionConfiguration { return adapterName; } + public int getQos() { + return qos; + } + + public void setQos(int qos) { + this.qos = qos; + } + public MQTTBrokerConnectionConfiguration(InputEventAdapterConfiguration eventAdapterConfiguration, Map globalProperties) throws InputEventAdapterException { @@ -131,6 +140,15 @@ public class MQTTBrokerConnectionConfiguration { } else { keepAlive = MQTTEventAdapterConstants.ADAPTER_CONF_DEFAULT_KEEP_ALIVE; } + + String qosVal = globalProperties.get(MQTTEventAdapterConstants.ADAPTER_MESSAGE_QOS); + if (qosVal != null && !qosVal.isEmpty()) { + this.qos = Integer.parseInt(qosVal); + } else { + qosVal = eventAdapterConfiguration.getProperties().get(MQTTEventAdapterConstants.ADAPTER_MESSAGE_QOS); + this.qos = Integer.parseInt(qosVal); + } + this.contentTransformerType = eventAdapterConfiguration.getProperties() .get(MQTTEventAdapterConstants.ADAPTER_CONF_CONTENT_TRANSFORMER_TYPE); } diff --git a/components/extensions/cdmf-transport-adapters/input/io.entgra.device.mgt.plugins.input.adapter.mqtt/src/main/java/io/entgra/device/mgt/plugins/input/adapter/mqtt/util/MQTTEventAdapterConstants.java b/components/extensions/cdmf-transport-adapters/input/io.entgra.device.mgt.plugins.input.adapter.mqtt/src/main/java/io/entgra/device/mgt/plugins/input/adapter/mqtt/util/MQTTEventAdapterConstants.java index fc047cffd..7d26fc1b5 100644 --- a/components/extensions/cdmf-transport-adapters/input/io.entgra.device.mgt.plugins.input.adapter.mqtt/src/main/java/io/entgra/device/mgt/plugins/input/adapter/mqtt/util/MQTTEventAdapterConstants.java +++ b/components/extensions/cdmf-transport-adapters/input/io.entgra.device.mgt.plugins.input.adapter.mqtt/src/main/java/io/entgra/device/mgt/plugins/input/adapter/mqtt/util/MQTTEventAdapterConstants.java @@ -47,6 +47,7 @@ public class MQTTEventAdapterConstants { public static final String ADAPTER_CONF_CLEAN_SESSION_HINT = "cleanSession.hint"; public static final String ADAPTER_CONF_KEEP_ALIVE = "keepAlive"; public static final int ADAPTER_CONF_DEFAULT_KEEP_ALIVE = 20000; + public static final String ADAPTER_MESSAGE_QOS = "qos"; public static final int INITIAL_RECONNECTION_DURATION = 4000; public static final int RECONNECTION_PROGRESS_FACTOR = 2; diff --git a/components/extensions/cdmf-transport-adapters/input/io.entgra.device.mgt.plugins.input.adapter.mqtt/src/main/resources/io/entgra/device/mgt/plugins/input/adapter/mqtt/i18n/Resources.properties b/components/extensions/cdmf-transport-adapters/input/io.entgra.device.mgt.plugins.input.adapter.mqtt/src/main/resources/io/entgra/device/mgt/plugins/input/adapter/mqtt/i18n/Resources.properties index aee8d9a4c..9552188b8 100644 --- a/components/extensions/cdmf-transport-adapters/input/io.entgra.device.mgt.plugins.input.adapter.mqtt/src/main/resources/io/entgra/device/mgt/plugins/input/adapter/mqtt/i18n/Resources.properties +++ b/components/extensions/cdmf-transport-adapters/input/io.entgra.device.mgt.plugins.input.adapter.mqtt/src/main/resources/io/entgra/device/mgt/plugins/input/adapter/mqtt/i18n/Resources.properties @@ -18,6 +18,7 @@ topic=Topic topic.hint=Topic subscribed +qos=Quality of Service clientId=Client Id clientId.hint=client identifier is used by the server to identify a client when it reconnects, It used for durable subscriptions or reliable delivery of messages is required. url=Broker Url (Not required), If it is not provided then it will connect to the default broker. diff --git a/components/extensions/cdmf-transport-adapters/output/io.entgra.device.mgt.plugins.output.adapter.mqtt/src/main/java/io/entgra/device/mgt/plugins/output/adapter/mqtt/MQTTEventAdapterFactory.java b/components/extensions/cdmf-transport-adapters/output/io.entgra.device.mgt.plugins.output.adapter.mqtt/src/main/java/io/entgra/device/mgt/plugins/output/adapter/mqtt/MQTTEventAdapterFactory.java index 6e63d8169..14f1ed1d9 100644 --- a/components/extensions/cdmf-transport-adapters/output/io.entgra.device.mgt.plugins.output.adapter.mqtt/src/main/java/io/entgra/device/mgt/plugins/output/adapter/mqtt/MQTTEventAdapterFactory.java +++ b/components/extensions/cdmf-transport-adapters/output/io.entgra.device.mgt.plugins.output.adapter.mqtt/src/main/java/io/entgra/device/mgt/plugins/output/adapter/mqtt/MQTTEventAdapterFactory.java @@ -92,7 +92,7 @@ public class MQTTEventAdapterFactory extends OutputEventAdapterFactory { qos.setDisplayName(resourceBundle.getString(MQTTEventAdapterConstants.ADAPTER_MESSAGE_QOS)); qos.setRequired(false); qos.setOptions(new String[]{"0", "1", "2"}); - qos.setDefaultValue("2"); + qos.setDefaultValue("0"); // set topic Property topicProperty = new Property(MQTTEventAdapterConstants.ADAPTER_MESSAGE_TOPIC); From 831c25a590bbc43cd1edcfeb1fae095072fa7a08 Mon Sep 17 00:00:00 2001 From: tcdlpds Date: Mon, 10 Jun 2024 14:54:23 +0530 Subject: [PATCH 3/3] Fix build failure --- .../src/test/resources/sql/h2.sql | 328 +++--------------- .../DeviceManagementProviderServiceMock.java | 32 +- 2 files changed, 63 insertions(+), 297 deletions(-) diff --git a/components/extensions/siddhi-extensions/io.entgra.device.mgt.plugins.extension.siddhi.device/src/test/resources/sql/h2.sql b/components/extensions/siddhi-extensions/io.entgra.device.mgt.plugins.extension.siddhi.device/src/test/resources/sql/h2.sql index 15ffa6960..4ffd33e50 100644 --- a/components/extensions/siddhi-extensions/io.entgra.device.mgt.plugins.extension.siddhi.device/src/test/resources/sql/h2.sql +++ b/components/extensions/siddhi-extensions/io.entgra.device.mgt.plugins.extension.siddhi.device/src/test/resources/sql/h2.sql @@ -8,20 +8,13 @@ CREATE TABLE IF NOT EXISTS DM_DEVICE_TYPE ( PRIMARY KEY (ID) ); -CREATE TABLE IF NOT EXISTS DM_DEVICE_CERTIFICATE ( - ID INTEGER auto_increment NOT NULL, - SERIAL_NUMBER VARCHAR(500) DEFAULT NULL, - CERTIFICATE BLOB DEFAULT NULL, - TENANT_ID INTEGER DEFAULT 0, - USERNAME VARCHAR(500) DEFAULT NULL, - PRIMARY KEY (ID) -); - CREATE TABLE IF NOT EXISTS DM_GROUP ( ID INTEGER AUTO_INCREMENT NOT NULL, GROUP_NAME VARCHAR(100) DEFAULT NULL, - STATUS VARCHAR(50) DEFAULT NULL, DESCRIPTION TEXT DEFAULT NULL, + STATUS VARCHAR(50) DEFAULT NULL, + DATE_OF_CREATE BIGINT DEFAULT NULL, + DATE_OF_LAST_UPDATE BIGINT DEFAULT NULL, OWNER VARCHAR(255) DEFAULT NULL, PARENT_PATH VARCHAR(255) DEFAULT NULL, TENANT_ID INTEGER DEFAULT 0, @@ -39,6 +32,15 @@ CREATE TABLE IF NOT EXISTS DM_ROLE_GROUP_MAP ( REFERENCES DM_GROUP (ID) ON DELETE CASCADE ON UPDATE CASCADE ); +CREATE TABLE IF NOT EXISTS DM_DEVICE_CERTIFICATE ( + ID INTEGER auto_increment NOT NULL, + SERIAL_NUMBER VARCHAR(500) DEFAULT NULL, + CERTIFICATE BLOB DEFAULT NULL, + TENANT_ID INTEGER DEFAULT 0, + USERNAME VARCHAR(500) DEFAULT NULL, + PRIMARY KEY (ID) + ); + CREATE TABLE IF NOT EXISTS DM_DEVICE ( ID INTEGER auto_increment NOT NULL, DESCRIPTION TEXT DEFAULT NULL, @@ -90,13 +92,17 @@ CREATE TABLE IF NOT EXISTS DM_OPERATION ( OPERATION_CODE VARCHAR(1000) NOT NULL, INITIATED_BY VARCHAR(100) NULL, OPERATION_DETAILS BLOB DEFAULT NULL, + OPERATION_PROPERTIES BLOB DEFAULT NULL, ENABLED BOOLEAN NOT NULL DEFAULT FALSE, + TENANT_ID INTEGER NOT NULL, PRIMARY KEY (ID) ); CREATE TABLE IF NOT EXISTS DM_ENROLMENT ( ID INTEGER AUTO_INCREMENT NOT NULL, DEVICE_ID INTEGER NOT NULL, + DEVICE_TYPE VARCHAR(300) NOT NULL, + DEVICE_IDENTIFICATION VARCHAR(300) NOT NULL, OWNER VARCHAR(255) NOT NULL, OWNERSHIP VARCHAR(45) DEFAULT NULL, STATUS VARCHAR(50) NULL, @@ -109,6 +115,7 @@ CREATE TABLE IF NOT EXISTS DM_ENROLMENT ( DM_DEVICE (ID) ON DELETE NO ACTION ON UPDATE NO ACTION, CONSTRAINT uk_dm_device_enrolment UNIQUE (DEVICE_ID, OWNER, OWNERSHIP, TENANT_ID) ); + CREATE TABLE IF NOT EXISTS DM_DEVICE_STATUS ( ID INTEGER AUTO_INCREMENT NOT NULL, ENROLMENT_ID INTEGER NOT NULL, @@ -122,6 +129,7 @@ CREATE TABLE IF NOT EXISTS DM_DEVICE_STATUS ( CONSTRAINT fk_dm_device_status_enrolment FOREIGN KEY (ENROLMENT_ID) REFERENCES DM_ENROLMENT (ID) ON DELETE CASCADE ON UPDATE CASCADE ); + CREATE TABLE IF NOT EXISTS DM_ENROLMENT_OP_MAPPING ( ID INTEGER AUTO_INCREMENT NOT NULL, ENROLMENT_ID INTEGER NOT NULL, @@ -191,8 +199,8 @@ CREATE TABLE IF NOT EXISTS DM_PROFILE ( CREATE TABLE IF NOT EXISTS DM_POLICY ( ID INT NOT NULL AUTO_INCREMENT , NAME VARCHAR(45) DEFAULT NULL , + PAYLOAD_VERSION VARCHAR (45) DEFAULT NULL, DESCRIPTION VARCHAR(1000) NULL, - PAYLOAD_VERSION VARCHAR (45) NULL, TENANT_ID INT NOT NULL , PROFILE_ID INT NOT NULL , OWNERSHIP_TYPE VARCHAR(45) NULL, @@ -209,6 +217,21 @@ CREATE TABLE IF NOT EXISTS DM_POLICY ( ON UPDATE NO ACTION ); +CREATE TABLE IF NOT EXISTS DM_POLICY_CORRECTIVE_ACTION ( + ID INT NOT NULL AUTO_INCREMENT, + ACTION_TYPE VARCHAR(45) NOT NULL, + CORRECTIVE_POLICY_ID INT DEFAULT NULL, + POLICY_ID INT NOT NULL, + FEATURE_ID INT DEFAULT NULL, + IS_REACTIVE BOOLEAN NOT NULL DEFAULT FALSE, + PRIMARY KEY (ID), + CONSTRAINT FK_DM_POLICY_DM_POLICY_CORRECTIVE_ACTION + FOREIGN KEY (POLICY_ID) + REFERENCES DM_POLICY (ID) + ON DELETE NO ACTION + ON UPDATE NO ACTION + ); + CREATE TABLE IF NOT EXISTS DM_DEVICE_POLICY ( ID INT NOT NULL AUTO_INCREMENT , DEVICE_ID INT NOT NULL , @@ -255,21 +278,6 @@ CREATE TABLE IF NOT EXISTS DM_PROFILE_FEATURES ( ON UPDATE NO ACTION ); -CREATE TABLE IF NOT EXISTS DM_POLICY_CORRECTIVE_ACTION ( - ID INT NOT NULL AUTO_INCREMENT, - ACTION_TYPE VARCHAR(45) NOT NULL, - CORRECTIVE_POLICY_ID INT DEFAULT NULL, - POLICY_ID INT NOT NULL, - FEATURE_ID INT DEFAULT NULL, - IS_REACTIVE BOOLEAN NOT NULL DEFAULT FALSE, - PRIMARY KEY (ID), - CONSTRAINT FK_DM_POLICY_DM_POLICY_CORRECTIVE_ACTION - FOREIGN KEY (POLICY_ID) - REFERENCES DM_POLICY (ID) - ON DELETE NO ACTION - ON UPDATE NO ACTION -); - CREATE TABLE IF NOT EXISTS DM_ROLE_POLICY ( ID INT NOT NULL AUTO_INCREMENT , ROLE_NAME VARCHAR(45) NOT NULL , @@ -342,7 +350,7 @@ CREATE TABLE IF NOT EXISTS DM_POLICY_CRITERIA_PROPERTIES ( POLICY_CRITERION_ID INT NOT NULL, PROP_KEY VARCHAR(45) NULL, PROP_VALUE VARCHAR(100) NULL, - CONTENT BLOB NULL, + CONTENT BLOB NULL COMMENT 'This is used to ', PRIMARY KEY (ID), CONSTRAINT FK_POLICY_CRITERIA_PROPERTIES FOREIGN KEY (POLICY_CRITERION_ID) @@ -418,21 +426,11 @@ CREATE TABLE IF NOT EXISTS DM_APPLICATION ( -- POLICY RELATED TABLES FINISHED -- -CREATE TABLE IF NOT EXISTS DM_APP_ICONS ( - ID INTEGER AUTO_INCREMENT NOT NULL, - ICON_PATH VARCHAR(150) DEFAULT NULL, - PACKAGE_NAME VARCHAR(150) NOT NULL, - VERSION VARCHAR(50) DEFAULT '1.1.0', - CREATED_TIMESTAMP TIMESTAMP NOT NULL, - TENANT_ID INTEGER NOT NULL, - PRIMARY KEY (ID) -); - -- NOTIFICATION TABLE -- CREATE TABLE IF NOT EXISTS DM_NOTIFICATION ( NOTIFICATION_ID INTEGER AUTO_INCREMENT NOT NULL, DEVICE_ID INTEGER NOT NULL, - OPERATION_ID INTEGER NULL, + OPERATION_ID INTEGER NOT NULL, TENANT_ID INTEGER NOT NULL, STATUS VARCHAR(10) NULL, DESCRIPTION VARCHAR(1000) NULL, @@ -462,8 +460,6 @@ CREATE TABLE IF NOT EXISTS DM_DEVICE_INFO ( ON UPDATE NO ACTION ); -CREATE INDEX IDX_DM_DEVICE_INFO_DID_EID_KFIELD ON DM_DEVICE_INFO(DEVICE_ID, ENROLMENT_ID, KEY_FIELD); - CREATE TABLE IF NOT EXISTS DM_DEVICE_LOCATION ( ID INTEGER AUTO_INCREMENT NOT NULL, DEVICE_ID INT NULL, @@ -494,6 +490,7 @@ CREATE TABLE IF NOT EXISTS DM_DEVICE_LOCATION ( ON DELETE NO ACTION ON UPDATE NO ACTION ); + CREATE INDEX DM_DEVICE_LOCATION_GEO_hashx ON DM_DEVICE_LOCATION(GEO_HASH ASC); CREATE TABLE IF NOT EXISTS DM_DEVICE_DETAIL ( @@ -529,27 +526,6 @@ CREATE TABLE IF NOT EXISTS DM_DEVICE_DETAIL ( ON UPDATE NO ACTION ); -CREATE INDEX IDX_DM_DEVICE_DETAIL_DID_EID ON DM_DEVICE_DETAIL(DEVICE_ID, ENROLMENT_ID); - -CREATE TABLE IF NOT EXISTS DM_DEVICE_HISTORY_LAST_SEVEN_DAYS -( - ID INTEGER AUTO_INCREMENT NOT NULL, - DEVICE_ID INT NOT NULL, - DEVICE_ID_NAME VARCHAR(255) NOT NULL, - TENANT_ID INT NOT NULL, - DEVICE_TYPE_NAME VARCHAR(45) NOT NULL, - LATITUDE DOUBLE NULL, - LONGITUDE DOUBLE NULL, - SPEED FLOAT NULL, - HEADING FLOAT NULL, - TIMESTAMP BIGINT NOT NULL, - GEO_HASH VARCHAR(45) NULL, - DEVICE_OWNER VARCHAR(45) NULL, - DEVICE_ALTITUDE DOUBLE NULL, - DISTANCE DOUBLE NULL, - PRIMARY KEY (ID) -); - -- POLICY AND DEVICE GROUP MAPPING -- CREATE TABLE IF NOT EXISTS DM_DEVICE_GROUP_POLICY ( ID INT NOT NULL AUTO_INCREMENT, @@ -570,51 +546,6 @@ CREATE TABLE IF NOT EXISTS DM_DEVICE_GROUP_POLICY ( ); -- END OF POLICY AND DEVICE GROUP MAPPING -- - -CREATE TABLE IF NOT EXISTS DM_DEVICE_TYPE_PLATFORM ( - ID INT NOT NULL AUTO_INCREMENT, - DEVICE_TYPE_ID INT NULL DEFAULT 0, - VERSION_NAME VARCHAR(100) NULL, - VERSION_STATUS VARCHAR(100) NULL DEFAULT 'ACTIVE', - PRIMARY KEY (ID), - CONSTRAINT DM_DEVICE_TYPE_DM_DEVICE_TYPE_PLATFORM_MAPPING - FOREIGN KEY (DEVICE_TYPE_ID) - REFERENCES DM_DEVICE_TYPE (ID) ON DELETE CASCADE ON UPDATE CASCADE, - CONSTRAINT device_type_version_uk - UNIQUE ( - DEVICE_TYPE_ID, - VERSION_NAME - ) -); - --- METADATA TABLE -- -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(8000) NOT NULL, - TENANT_ID INTEGER NOT NULL, - PRIMARY KEY (METADATA_ID), - CONSTRAINT METADATA_KEY_TENANT_ID UNIQUE (METADATA_KEY, TENANT_ID) -); --- END OF METADATA TABLE -- - --- DM_OTP_DATA TABLE -- -CREATE TABLE IF NOT EXISTS DM_OTP_DATA ( - ID INT AUTO_INCREMENT NOT NULL, - OTP_TOKEN VARCHAR(100) NOT NULL, - TENANT_ID INT NOT NULL, - USERNAME VARCHAR(500) DEFAULT NOT NULL, - EMAIL VARCHAR(100) NOT NULL, - EMAIL_TYPE VARCHAR(20) NOT NULL, - META_INFO VARCHAR(20000) NOT NULL, - CREATED_AT TIMESTAMP NOT NULL, - EXPIRY_TIME INT NOT NULL DEFAULT 3600, - IS_EXPIRED BOOLEAN DEFAULT false, - PRIMARY KEY (ID) -); --- END OF DM_OTP_DATA TABLE -- - -- DASHBOARD RELATED VIEWS -- CREATE VIEW POLICY_COMPLIANCE_INFO AS SELECT @@ -670,171 +601,22 @@ 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 -- - --- DM_GEOFENCE TABLE-- - -CREATE TABLE IF NOT EXISTS DM_GEOFENCE ( - ID INT NOT NULL AUTO_INCREMENT, - FENCE_NAME VARCHAR(255) NOT NULL, - DESCRIPTION TEXT DEFAULT NULL, - LATITUDE DOUBLE DEFAULT NULL, - LONGITUDE DOUBLE DEFAULT NULL, - RADIUS DOUBLE DEFAULT NULL, - GEO_JSON TEXT DEFAULT NULL, - FENCE_SHAPE VARCHAR(100) DEFAULT NULL, - CREATED_TIMESTAMP TIMESTAMP NOT NULL, - OWNER VARCHAR(255) NOT NULL, - TENANT_ID INTEGER DEFAULT 0, - PRIMARY KEY (ID) -); - --- END OF DM_GEOFENCE TABLE-- - --- DM_GEOFENCE_GROUP_MAPPING TABLE-- -CREATE TABLE IF NOT EXISTS DM_GEOFENCE_GROUP_MAPPING ( - ID INT NOT NULL AUTO_INCREMENT, - FENCE_ID INT NOT NULL, - GROUP_ID INT NOT NULL, - PRIMARY KEY (ID), - CONSTRAINT fk_dm_geofence_group_mapping_geofence FOREIGN KEY (FENCE_ID) REFERENCES - DM_GEOFENCE (ID) ON DELETE NO ACTION ON UPDATE NO ACTION, - CONSTRAINT fk_dm_geofence_group_mapping_group FOREIGN KEY (GROUP_ID) REFERENCES - DM_GROUP (ID) ON DELETE NO ACTION ON UPDATE NO ACTION -); - --- END OF DM_GEOFENCE_GROUP_MAPPING TABLE-- - --- DM_DEVICE_EVENT TABLE -- - -CREATE TABLE IF NOT EXISTS DM_DEVICE_EVENT ( - ID INT NOT NULL AUTO_INCREMENT, - EVENT_SOURCE VARCHAR(100) NOT NULL, - EVENT_LOGIC VARCHAR(100) NOT NULL, - ACTIONS TEXT DEFAULT NULL, - CREATED_TIMESTAMP TIMESTAMP NOT NULL, - TENANT_ID INTEGER DEFAULT 0, - PRIMARY KEY (ID) -); - --- END OF DM_DEVICE_EVENT TABLE -- - --- DM_DEVICE_EVENT_GROUP_MAPPING TABLE-- -CREATE TABLE IF NOT EXISTS DM_DEVICE_EVENT_GROUP_MAPPING ( - ID INT NOT NULL AUTO_INCREMENT, - EVENT_ID INT NOT NULL, - GROUP_ID INT NOT NULL, - PRIMARY KEY (ID), - CONSTRAINT fk_dm_event_group_mapping_event FOREIGN KEY (EVENT_ID) REFERENCES - DM_DEVICE_EVENT (ID) ON DELETE NO ACTION ON UPDATE NO ACTION, - CONSTRAINT fk_dm_event_group_mapping_group FOREIGN KEY (GROUP_ID) REFERENCES - DM_GROUP (ID) ON DELETE NO ACTION ON UPDATE NO ACTION -); - --- END OF DM_DEVICE_EVENT_GROUP_MAPPING TABLE-- - --- DM_GEOFENCE_GROUP_MAPPING TABLE-- -CREATE TABLE IF NOT EXISTS DM_GEOFENCE_EVENT_MAPPING ( - ID INT NOT NULL AUTO_INCREMENT, - FENCE_ID INT NOT NULL, - EVENT_ID INT NOT NULL, - PRIMARY KEY (ID), - CONSTRAINT fk_dm_geofence_event_mapping_geofence FOREIGN KEY (FENCE_ID) REFERENCES - DM_GEOFENCE (ID) ON DELETE NO ACTION ON UPDATE NO ACTION, - CONSTRAINT fk_dm_geofence_event_mapping_event FOREIGN KEY (EVENT_ID) REFERENCES - DM_DEVICE_EVENT (ID) ON DELETE NO ACTION ON UPDATE NO ACTION -); - --- END OF DM_GEOFENCE_GROUP_MAPPING TABLE-- +/* + * Copyright (c) 2018 - 2023, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved. + * + * Entgra (Pvt) Ltd. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ --- DM_EXT_GROUP_MAPPING TABLE-- -CREATE TABLE IF NOT EXISTS DM_EXT_GROUP_MAPPING ( - ID INT NOT NULL AUTO_INCREMENT, - TRACCAR_GROUP_ID INT DEFAULT 0, - GROUP_ID INT NOT NULL, - TENANT_ID INT NOT NULL, - STATUS INT DEFAULT 0, - PRIMARY KEY (ID) -); --- END OF DM_EXT_GROUP_MAPPING TABLE-- - --- END OF DM_EXT_DEVICE_MAPPING TABLE-- -CREATE TABLE IF NOT EXISTS DM_EXT_DEVICE_MAPPING ( - ID INT NOT NULL AUTO_INCREMENT, - TRACCAR_DEVICE_ID INT DEFAULT 0, - DEVICE_ID INT NOT NULL, - TENANT_ID INT NOT NULL, - STATUS INT DEFAULT 0, - PRIMARY KEY (ID) -); --- END OF DM_EXT_DEVICE_MAPPING TABLE-- - --- END OF DM_EXT_PERMISSION_MAPPING TABLE-- -CREATE TABLE IF NOT EXISTS DM_EXT_PERMISSION_MAPPING ( - TRACCAR_DEVICE_ID INT DEFAULT 0, - TRACCAR_USER_ID INT DEFAULT 0 -); --- END OF DM_EXT_PERMISSION_MAPPING TABLE-- - --- DYNAMIC TASK TABLES-- -CREATE TABLE IF NOT EXISTS DYNAMIC_TASK ( - DYNAMIC_TASK_ID INTEGER AUTO_INCREMENT NOT NULL, - NAME VARCHAR(300) DEFAULT NULL , - CRON VARCHAR(8000) DEFAULT NULL, - IS_ENABLED BOOLEAN NOT NULL DEFAULT FALSE, - TASK_CLASS_NAME VARCHAR(8000) DEFAULT NULL, - TENANT_ID INTEGER DEFAULT 0, - PRIMARY KEY (DYNAMIC_TASK_ID) -); - -CREATE TABLE IF NOT EXISTS DYNAMIC_TASK_PROPERTIES ( - DYNAMIC_TASK_ID INTEGER NOT NULL, - PROPERTY_NAME VARCHAR(100) DEFAULT 0, - PROPERTY_VALUE VARCHAR(100) DEFAULT NULL, - TENANT_ID VARCHAR(100), - PRIMARY KEY (DYNAMIC_TASK_ID, PROPERTY_NAME, TENANT_ID), - CONSTRAINT FK_DYNAMIC_TASK_TASK_PROPERTIES FOREIGN KEY (DYNAMIC_TASK_ID) REFERENCES - DYNAMIC_TASK (DYNAMIC_TASK_ID) ON DELETE CASCADE ON UPDATE CASCADE -); --- END OF DYNAMIC TASK TABLE-- - --- DM_DEVICE_SUB_TYPE TABLE-- -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, - TYPE_DEFINITION TEXT NOT NULL, - PRIMARY KEY (SUB_TYPE_ID,DEVICE_TYPE) -); --- END OF DM_DEVICE_SUB_TYPE TABLE-- - --- DM_TRACCAR_UNSYNCED_DEVICES TABLE -- -CREATE TABLE IF NOT EXISTS DM_TRACCAR_UNSYNCED_DEVICES ( - ID INT NOT NULL AUTO_INCREMENT, - DEVICE_NAME VARCHAR(100) NOT NULL, - IOTS_DEVICE_IDENTIFIER VARCHAR(300) DEFAULT NULL UNIQUE, - TRACCAR_DEVICE_UNIQUE_ID INT NOT NULL, - TRACCAR_USENAME VARCHAR(100) NULL, - STATUS VARCHAR(100) NULL, - TENANT_ID INTEGER DEFAULT 0, - PRIMARY KEY (ID) -); --- END OF DM_TRACCAR_UNSYNCED_DEVICES TABLE -- - --- SUB_OPERATION_TEMPLATE TABLE-- -CREATE TABLE IF NOT EXISTS SUB_OPERATION_TEMPLATE ( - SUB_OPERATION_TEMPLATE_ID INT NOT NULL AUTO_INCREMENT, - OPERATION_DEFINITION TEXT NOT NULL, - OPERATION_CODE VARCHAR(100) NOT NULL, - SUB_TYPE_ID INT NOT NULL, - DEVICE_TYPE VARCHAR(25) NOT NULL, - CREATE_TIMESTAMP TIMESTAMP NULL DEFAULT NULL, - UPDATE_TIMESTAMP TIMESTAMP NULL DEFAULT NULL, - PRIMARY KEY (SUB_OPERATION_TEMPLATE_ID), - CONSTRAINT uk_sub_operation_template UNIQUE (SUB_TYPE_ID, OPERATION_CODE, DEVICE_TYPE), --- UNIQUE KEY SUB_OPERATION_TEMPLATE (SUB_TYPE_ID, OPERATION_CODE, 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 OF SUB_OPERATION_TEMPLATE TABLE-- +-- END OF DASHBOARD RELATED VIEWS -- diff --git a/components/mobile-plugins/android-plugin/io.entgra.device.mgt.plugins.mobile.android.api/src/test/java/io/entgra/device/mgt/plugins/mobile/android/api/mocks/DeviceManagementProviderServiceMock.java b/components/mobile-plugins/android-plugin/io.entgra.device.mgt.plugins.mobile.android.api/src/test/java/io/entgra/device/mgt/plugins/mobile/android/api/mocks/DeviceManagementProviderServiceMock.java index e3e61d716..07e13e2ac 100644 --- a/components/mobile-plugins/android-plugin/io.entgra.device.mgt.plugins.mobile.android.api/src/test/java/io/entgra/device/mgt/plugins/mobile/android/api/mocks/DeviceManagementProviderServiceMock.java +++ b/components/mobile-plugins/android-plugin/io.entgra.device.mgt.plugins.mobile.android.api/src/test/java/io/entgra/device/mgt/plugins/mobile/android/api/mocks/DeviceManagementProviderServiceMock.java @@ -18,33 +18,13 @@ package io.entgra.device.mgt.plugins.mobile.android.api.mocks; -import io.entgra.device.mgt.core.device.mgt.common.ActivityPaginationRequest; -import io.entgra.device.mgt.core.device.mgt.common.Device; -import io.entgra.device.mgt.core.device.mgt.common.DeviceIdentifier; -import io.entgra.device.mgt.core.device.mgt.common.DeviceTransferRequest; -import io.entgra.device.mgt.core.device.mgt.common.DynamicTaskContext; -import io.entgra.device.mgt.core.device.mgt.common.StartupOperationConfig; +import io.entgra.device.mgt.core.device.mgt.common.*; import io.entgra.device.mgt.core.device.mgt.common.app.mgt.Application; import io.entgra.device.mgt.core.device.mgt.common.app.mgt.ApplicationManagementException; -import io.entgra.device.mgt.core.device.mgt.common.configuration.mgt.AmbiguousConfigurationException; -import io.entgra.device.mgt.core.device.mgt.common.configuration.mgt.ConfigurationEntry; -import io.entgra.device.mgt.core.device.mgt.common.configuration.mgt.DeviceConfiguration; +import io.entgra.device.mgt.core.device.mgt.common.configuration.mgt.*; import io.entgra.device.mgt.core.device.mgt.common.device.details.DeviceData; import io.entgra.device.mgt.core.device.mgt.common.device.details.DeviceLocationHistorySnapshot; -import io.entgra.device.mgt.core.device.mgt.common.exceptions.DeviceManagementException; -import io.entgra.device.mgt.core.device.mgt.common.EnrolmentInfo; -import io.entgra.device.mgt.core.device.mgt.common.FeatureManager; -import io.entgra.device.mgt.core.device.mgt.common.exceptions.DeviceNotFoundException; -import io.entgra.device.mgt.core.device.mgt.common.exceptions.DeviceTypeNotFoundException; -import io.entgra.device.mgt.core.device.mgt.common.exceptions.InvalidDeviceException; -import io.entgra.device.mgt.core.device.mgt.common.MonitoringOperation; -import io.entgra.device.mgt.core.device.mgt.common.OperationMonitoringTaskConfig; -import io.entgra.device.mgt.core.device.mgt.common.PaginationRequest; -import io.entgra.device.mgt.core.device.mgt.common.PaginationResult; -import io.entgra.device.mgt.core.device.mgt.common.exceptions.UnauthorizedDeviceAccessException; -import io.entgra.device.mgt.core.device.mgt.common.exceptions.UserNotFoundException; -import io.entgra.device.mgt.core.device.mgt.common.configuration.mgt.ConfigurationManagementException; -import io.entgra.device.mgt.core.device.mgt.common.configuration.mgt.PlatformConfiguration; +import io.entgra.device.mgt.core.device.mgt.common.exceptions.*; import io.entgra.device.mgt.core.device.mgt.common.geo.service.GeoCluster; import io.entgra.device.mgt.core.device.mgt.common.geo.service.GeoQuery; import io.entgra.device.mgt.core.device.mgt.common.invitation.mgt.DeviceEnrollmentInvitationDetails; @@ -63,7 +43,6 @@ import io.entgra.device.mgt.core.device.mgt.core.dto.DeviceTypeVersion; import io.entgra.device.mgt.core.device.mgt.core.service.DeviceManagementProviderService; import io.entgra.device.mgt.core.device.mgt.core.service.EmailMetaInfo; import io.entgra.device.mgt.plugins.mobile.android.api.utils.TestUtils; - import org.apache.commons.collections.map.SingletonMap; import java.sql.Timestamp; @@ -396,6 +375,11 @@ public class DeviceManagementProviderServiceMock implements DeviceManagementProv } + @Override + public boolean recordDeviceUpdate(DeviceIdentifier deviceIdentifier) throws DeviceManagementException { + return false; + } + @Override public boolean modifyEnrollment(Device device) throws DeviceManagementException { return TestUtils.getDeviceId().equals(device.getDeviceIdentifier());