add some modifications to operation template

guava-cache-improvements
Thameera 2 years ago
parent 7562c1fbf1
commit 800fa4fb9a

@ -44,7 +44,6 @@ public class OperationTemplateDAOImpl implements OperationTemplateDAO {
private static final Log log = LogFactory.getLog(OperationTemplateDAOImpl.class);
/**
*
* @param operationTemplate
* @throws OperationTemplateManagementDAOException
*/
@ -82,7 +81,6 @@ public class OperationTemplateDAOImpl implements OperationTemplateDAO {
}
/**
*
* @param operationTemplate
* @return
* @throws OperationTemplateManagementDAOException
@ -93,15 +91,16 @@ public class OperationTemplateDAOImpl implements OperationTemplateDAO {
try {
String sql =
"UPDATE SUB_OPERATION_TEMPLATE SET OPERATION_DEFINITION = ? WHERE SUB_TYPE_ID = ? AND DEVICE_TYPE = ? "
"UPDATE SUB_OPERATION_TEMPLATE SET OPERATION_DEFINITION = ?, UPDATE_TIMESTAMP = ? WHERE SUB_TYPE_ID = ? AND DEVICE_TYPE = ? "
+ "AND OPERATION_CODE = ?";
Connection conn = ConnectionManagerUtils.getDBConnection();
try (PreparedStatement stmt = conn.prepareStatement(sql)) {
stmt.setString(1, operationTemplate.getOperationDefinition());
stmt.setInt(2, operationTemplate.getSubTypeId());
stmt.setString(3, operationTemplate.getDeviceType());
stmt.setString(4, operationTemplate.getCode());
stmt.setTimestamp(2, new Timestamp(System.currentTimeMillis()));
stmt.setInt(3, operationTemplate.getSubTypeId());
stmt.setString(4, operationTemplate.getDeviceType());
stmt.setString(5, operationTemplate.getCode());
stmt.executeUpdate();
return getOperationTemplate(operationTemplate.getSubTypeId(), operationTemplate.getDeviceType(), operationTemplate.getCode());
@ -117,7 +116,6 @@ public class OperationTemplateDAOImpl implements OperationTemplateDAO {
}
/**
*
* @param subTypeId
* @param deviceType
* @param operationCode
@ -154,7 +152,6 @@ public class OperationTemplateDAOImpl implements OperationTemplateDAO {
}
/**
*
* @param subTypeId
* @param deviceType
* @param operationCode
@ -185,7 +182,6 @@ public class OperationTemplateDAOImpl implements OperationTemplateDAO {
}
/**
*
* @param subTypeId
* @param deviceType
* @param operationCode

@ -0,0 +1,36 @@
/*
* Copyright (C) 2018 - 2023 Entgra (Pvt) Ltd, Inc - All Rights Reserved.
*
* Unauthorised copying/redistribution of this file, via any medium is strictly prohibited.
*
* Licensed under the Entgra Commercial License, Version 1.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://entgra.io/licenses/entgra-commercial/1.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.
*/
package io.entgra.device.mgt.operation.template.exception;
/**
* Represents the exception thrown during validating the request.
*/
public class BadOperationRequestException extends OperationTemplateMgtPluginException {
private static final long serialVersionUID = 4082332498085984791L;
public BadOperationRequestException(String message, Throwable ex) {
super(message, ex);
}
public BadOperationRequestException(String message) {
super(message);
}
}

@ -20,6 +20,7 @@
package io.entgra.device.mgt.operation.template.impl;
import com.google.common.cache.CacheBuilder;
import com.google.common.cache.CacheLoader;
import com.google.common.cache.LoadingCache;
import io.entgra.device.mgt.operation.template.cache.OperationTemplateCacheLoader;
import io.entgra.device.mgt.operation.template.dao.OperationTemplateDAO;
@ -31,13 +32,13 @@ import io.entgra.device.mgt.operation.template.exception.OperationTemplateManage
import io.entgra.device.mgt.operation.template.exception.OperationTemplateMgtPluginException;
import io.entgra.device.mgt.operation.template.spi.OperationTemplateService;
import io.entgra.device.mgt.operation.template.util.ConnectionManagerUtils;
import io.entgra.device.mgt.operation.template.util.AssertUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
/**
* Operation Template service impl class.
*/
@ -60,6 +61,8 @@ public class OperationTemplateServiceImpl implements OperationTemplateService {
public void addOperationTemplate(OperationTemplate operationTemplate)
throws OperationTemplateMgtPluginException {
validateAddOperationTemplate(operationTemplate);
try {
ConnectionManagerUtils.beginDBTransaction();
operationTemplateDAO.addOperationTemplate(operationTemplate);
@ -92,7 +95,9 @@ public class OperationTemplateServiceImpl implements OperationTemplateService {
public OperationTemplate updateOperationTemplate(OperationTemplate operationTemplate)
throws OperationTemplateMgtPluginException {
validateUpdateOperationTemplate(operationTemplate);
OperationTemplate updatedOperationTemplate = null;
try {
ConnectionManagerUtils.beginDBTransaction();
updatedOperationTemplate = operationTemplateDAO.updateOperationTemplate(
@ -130,12 +135,19 @@ public class OperationTemplateServiceImpl implements OperationTemplateService {
public OperationTemplate getOperationTemplate(int subTypeId, String deviceType, String operationCode)
throws OperationTemplateMgtPluginException {
try {
validateGetOperationTemplate(subTypeId, deviceType, operationCode);
String key = OperationTemplateManagementUtil.setOperationTemplateCacheKey(subTypeId, deviceType,
operationCode);
return operationTemplateCache.get(key);
} catch (ExecutionException e) {
log.error(e.getMessage());
throw new OperationTemplateMgtPluginException(e.getMessage(), e);
} catch (CacheLoader.InvalidCacheLoadException e) {
String msg = "Operation Template doesn't exist for subtype id : " + subTypeId + " and device type : "
+ deviceType + " and operation code : " + operationCode;
log.error(msg, e);
return null;
}
}
@ -149,15 +161,20 @@ public class OperationTemplateServiceImpl implements OperationTemplateService {
public void deleteOperationTemplate(int subTypeId, String deviceType, String operationCode)
throws OperationTemplateMgtPluginException {
String msg = "Operation Template does not exist for subtype id : " + subTypeId
+ " and device type : " + deviceType + " and operation code : "
+ operationCode;
AssertUtils.isNull(getOperationTemplate(subTypeId, deviceType, operationCode), msg);
try {
ConnectionManagerUtils.beginDBTransaction();
operationTemplateDAO.deleteOperationTemplate(subTypeId, deviceType, operationCode);
ConnectionManagerUtils.commitDBTransaction();
if (log.isDebugEnabled()) {
String msg = "Operation Template deleted successfully,for subtype id "
String debugMsg = "Operation Template deleted successfully,for subtype id "
+ subTypeId + " and operation code "
+ operationCode + "";
log.debug(msg);
log.debug(debugMsg);
}
String key = OperationTemplateManagementUtil.setOperationTemplateCacheKey(
subTypeId, deviceType, operationCode);
@ -172,26 +189,51 @@ public class OperationTemplateServiceImpl implements OperationTemplateService {
}
/**
*
* @param subTypeId
* @param operationCode
* @param deviceType
* @return
* @param operationCode
* @throws OperationTemplateMgtPluginException
*/
@Override
public boolean isExistsOperationTemplateBySubtypeIdAndOperationCode(int subTypeId,
String operationCode, String deviceType) throws OperationTemplateMgtPluginException {
try {
ConnectionManagerUtils.openDBConnection();
return operationTemplateDAO.isExistsOperationTemplateBySubtypeIdAndOperationCode(subTypeId, deviceType,
operationCode);
private void validateGetOperationTemplate(int subTypeId, String deviceType, String operationCode)
throws OperationTemplateMgtPluginException {
} catch (DBConnectionException | OperationTemplateManagementDAOException e) {
log.error(e.getMessage());
throw new OperationTemplateMgtPluginException(e.getMessage(), e);
} finally {
ConnectionManagerUtils.closeDBConnection();
}
AssertUtils.isTrue(subTypeId > 0, "Invalid meter device subtype id: " + subTypeId);
AssertUtils.hasText(operationCode, "Validation failed due to invalid operation code: " + operationCode);
AssertUtils.hasText(deviceType, "Invalid device type.");
AssertUtils.isTrue(deviceType.equals("METER"), "Invalid device type. ");
}
/**
* @param operationTemplate
* @throws OperationTemplateMgtPluginException
*/
private void validateAddOperationTemplate(OperationTemplate operationTemplate) throws OperationTemplateMgtPluginException {
AssertUtils.isNull(operationTemplate, "Operation Template can not be null");
AssertUtils.hasText(operationTemplate.getOperationDefinition(), "Operation definition can not be null");
String msg = "Operation Template already exist for subtype id : " + operationTemplate.getSubTypeId()
+ " and device type : " + operationTemplate.getDeviceType() + " and operation code : "
+ operationTemplate.getCode();
AssertUtils.notNull(getOperationTemplate(operationTemplate.getSubTypeId(), operationTemplate.getDeviceType(),
operationTemplate.getCode()), msg);
}
/**
* @param operationTemplate
* @throws OperationTemplateMgtPluginException
*/
private void validateUpdateOperationTemplate(OperationTemplate operationTemplate) throws OperationTemplateMgtPluginException {
AssertUtils.isNull(operationTemplate, "Operation Template can not be null");
AssertUtils.hasText(operationTemplate.getOperationDefinition(), "Operation definition can not be null");
String msg = "Operation Template does not exist for subtype id : " + operationTemplate.getSubTypeId()
+ " and device type : " + operationTemplate.getDeviceType() + " and operation code : "
+ operationTemplate.getCode();
AssertUtils.isNull(getOperationTemplate(operationTemplate.getSubTypeId(), operationTemplate.getDeviceType(),
operationTemplate.getCode()), msg);
}
}

@ -28,9 +28,11 @@ import io.entgra.device.mgt.operation.template.exception.OperationTemplateMgtPlu
public interface OperationTemplateService {
void addOperationTemplate(OperationTemplate operationTemplate) throws OperationTemplateMgtPluginException;
OperationTemplate updateOperationTemplate(OperationTemplate operationTemplate) throws OperationTemplateMgtPluginException;
OperationTemplate getOperationTemplate(int subTypeId, String deviceType, String operationCode) throws OperationTemplateMgtPluginException;
void deleteOperationTemplate(int subTypeId, String deviceType, String operationCode) throws OperationTemplateMgtPluginException;
boolean isExistsOperationTemplateBySubtypeIdAndOperationCode(int subTypeId, String deviceType, String operationCode) throws OperationTemplateMgtPluginException;
}

@ -0,0 +1,75 @@
/*
* Copyright (C) 2018 - 2023 Entgra (Pvt) Ltd, Inc - All Rights Reserved.
*
* Unauthorised copying/redistribution of this file, via any medium is strictly prohibited.
*
* Licensed under the Entgra Commercial License, Version 1.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://entgra.io/licenses/entgra-commercial/1.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.
*/
package io.entgra.device.mgt.operation.template.util;
import io.entgra.device.mgt.operation.template.exception.BadOperationRequestException;
import io.entgra.device.mgt.operation.template.exception.OperationTemplateMgtPluginException;
import org.apache.commons.lang.StringUtils;
public class AssertUtils {
private AssertUtils() {
throw new IllegalStateException("ValidationUtils class");
}
/**
* @param object
* @param msg
* @throws OperationTemplateMgtPluginException
*/
public static void isNull(Object object, String msg) throws OperationTemplateMgtPluginException {
if (object == null) {
throw new BadOperationRequestException(msg);
}
}
/**
* @param object
* @param msg
* @throws OperationTemplateMgtPluginException
*/
public static void notNull(Object object, String msg) throws OperationTemplateMgtPluginException {
if (object != null) {
throw new BadOperationRequestException(msg);
}
}
/**
* @param text
* @param msg
* @throws OperationTemplateMgtPluginException
*/
public static void hasText(String text, String msg) throws OperationTemplateMgtPluginException {
if (StringUtils.isEmpty(text)) {
throw new BadOperationRequestException(msg);
}
}
/**
* @param expression
* @param msg
* @throws OperationTemplateMgtPluginException
*/
public static void isTrue(boolean expression, String msg) throws OperationTemplateMgtPluginException {
if (!expression) {
throw new BadOperationRequestException(msg);
}
}
}

@ -83,11 +83,10 @@ public class ServiceTest extends BaseOperationTemplatePluginTest {
Assert.assertEquals(operationTemplateActual.getDeviceType(), TestUtils.deviceType);
}
@Test(dependsOnMethods = {"testAddOperationTemplate", "testGetOperationTemplate", "testUpdateOperationTemplate"},
expectedExceptions = {CacheLoader.InvalidCacheLoadException.class})
@Test(dependsOnMethods = {"testAddOperationTemplate", "testGetOperationTemplate", "testUpdateOperationTemplate"})
public void testDeleteOperationTemplate() throws OperationTemplateMgtPluginException {
operationTemplateService.deleteOperationTemplate(TestUtils.subtypeId, TestUtils.deviceType, TestUtils.operationCode);
getOperationTemplateBySubtypeIdAndDeviceTypeAndOperationCode(TestUtils.subtypeId, TestUtils.deviceType, TestUtils.operationCode);
Assert.assertNull(getOperationTemplateBySubtypeIdAndDeviceTypeAndOperationCode(TestUtils.subtypeId, TestUtils.deviceType, TestUtils.operationCode));
}
public OperationTemplate getOperationTemplateBySubtypeIdAndDeviceTypeAndOperationCode(int subtypeId, String deviceType, String operationCode) throws OperationTemplateMgtPluginException {

@ -145,7 +145,6 @@ public abstract class BaseOperationTemplatePluginTest {
conn = ConnectionManagerUtils.getDBConnection();
stmt = conn.createStatement();
stmt.executeUpdate("RUNSCRIPT FROM './src/test/resources/carbon-home/dbscripts/dm-db-h2.sql'");
stmt.executeUpdate("RUNSCRIPT FROM './src/test/resources/carbon-home/dbscripts/h2.sql'");
} finally {
TestUtils.cleanupResources(conn, stmt, null);
}

@ -735,4 +735,24 @@ CREATE TABLE IF NOT EXISTS DM_DEVICE_SUB_TYPE (
PRIMARY KEY (SUB_TYPE_ID,DEVICE_TYPE)
);
-- END OF DM_DEVICE_SUB_TYPE TABLE--
-- END OF DM_DEVICE_SUB_TYPE TABLE--
-- SUB_OPERATION_TEMPLATE TABLE--
CREATE TABLE 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),
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--
INSERT INTO DM_DEVICE_SUB_TYPE (SUB_TYPE_ID, TENANT_ID, DEVICE_TYPE, SUB_TYPE_NAME, TYPE_DEFINITION) VALUES
(3,-1234,'METER','TestSubType','{"make": "TestSubType", "model": "ATx-Mega SIM800", "subTypeId": 3, "hasSMSSupport": true, "hasICMPSupport": true, "socketServerPort": 8071}'),
(4,-1234,'METER','TestSubType','{"make": "TestSubType", "model": "ATx-Mega SIM800", "subTypeId": 4, "hasSMSSupport": true, "hasICMPSupport": true, "socketServerPort": 8071}');

@ -1,425 +0,0 @@
-- -----------------------------------------------------
-- Table `POWER_METER_DEVICE`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `POWER_METER_DEVICE` (
`ID` INTEGER AUTO_INCREMENT NOT NULL,
`SERIAL` VARCHAR(45) NOT NULL,
`IP_ADDRESS` VARCHAR(45) NULL DEFAULT NULL,
`SIM_NUMBER` VARCHAR(45) NULL DEFAULT NULL,
`SUB_TYPE_ID` INT NOT NULL,
`CUSTOMER_REF` VARCHAR(45) NULL DEFAULT NULL,
`NODE_TYPE` VARCHAR(45) NULL DEFAULT NULL,
`CATEGORY` VARCHAR(45) NULL DEFAULT NULL,
`BRANCH` VARCHAR(45) NULL DEFAULT NULL,
`DEPOT` VARCHAR(45) NULL DEFAULT NULL,
`SUBSTATION_ID` VARCHAR(45) NULL DEFAULT NULL,
`HAS_EXPORT` VARCHAR(5) NULL DEFAULT NULL,
`COM_MODULE_IMEI` VARCHAR(45) NULL DEFAULT NULL,
`HAS_E_BILLING` VARCHAR(5) NULL DEFAULT NULL,
`IS_FEEDER_END` VARCHAR(5) NULL DEFAULT NULL,
`POLE_ID` VARCHAR(45) NULL DEFAULT NULL,
`METER_FW_VER` VARCHAR(45) NULL DEFAULT NULL,
`ASSIGNED_ON` TIMESTAMP NULL DEFAULT NULL,
PRIMARY KEY (`ID`, `SERIAL`));
-- -----------------------------------------------------
-- Table `COMMUNICATION_MODULE`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `COMMUNICATION_MODULE` (
`IMEI` VARCHAR(45) NOT NULL,
`SIM_IMSI` VARCHAR(45) NULL DEFAULT NULL,
`FW_VERSION` INT NULL DEFAULT 0,
`SUB_TYPE_ID` INT NOT NULL,
`SMS_PIN` VARCHAR(45) NULL DEFAULT NULL,
`BRANCH` VARCHAR(45) NULL DEFAULT NULL,
PRIMARY KEY (`IMEI`));
-- -----------------------------------------------------
-- Table `METER_AUTHENTICATION_INFO`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `METER_AUTHENTICATION_INFO` (
`ID` INT NOT NULL AUTO_INCREMENT,
`CLIENT_ADDRESS` INT NOT NULL,
`AUTHENTICATION` VARCHAR(100) NOT NULL,
`USER_ID` INT NOT NULL,
`PASSWORD` VARCHAR(100) NOT NULL,
`METER_SERIAL_ID` VARCHAR(45) NOT NULL,
PRIMARY KEY (`ID`));
CREATE INDEX IDX_METER_AUTHENTICATION_INFO
ON METER_AUTHENTICATION_INFO(CLIENT_ADDRESS, METER_SERIAL_ID);
-- -----------------------------------------------------
-- Table `METER_READINGS`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `METER_READINGS` (
`ID` INT NOT NULL AUTO_INCREMENT,
`OPERATION_ID` INT NOT NULL,
`OPERATION_CODE` VARCHAR(45) NOT NULL,
`SUB_TYPE_ID` INT NOT NULL,
`NODE_TYPE` VARCHAR(45) NULL DEFAULT NULL,
`CATEGORY` VARCHAR(45) NULL DEFAULT NULL,
`HAS_EXPORT` BOOLEAN NULL DEFAULT NULL,
`HAS_E_BILLING` BOOLEAN NULL DEFAULT NULL,
`BRANCH` VARCHAR(45) NULL DEFAULT NULL,
`DEPOT` VARCHAR(45) NULL DEFAULT NULL,
`SUBSTATION_ID` VARCHAR(45) NULL DEFAULT NULL,
`SERIAL` VARCHAR(45) NOT NULL,
`CUSTOMER_REF` VARCHAR(45) NULL DEFAULT NULL,
`RESPONSE` BLOB NOT NULL,
`TIMESTAMP` BIGINT(15) NOT NULL,
`IS_PARTIAL_RESULT` BOOLEAN NOT NULL DEFAULT FALSE,
PRIMARY KEY (`ID`));
--
-- Table structure for table `LAST_METER_READING`
--
CREATE TABLE IF NOT EXISTS LAST_METER_READING (
SERIAL VARCHAR(45) NOT NULL,
OPERATION_ID INTEGER NOT NULL,
SUB_TYPE_ID INT NOT NULL DEFAULT 0,
NODE_TYPE VARCHAR(45) NULL DEFAULT NULL,
CATEGORY VARCHAR(45) NULL DEFAULT NULL,
HAS_EXPORT BOOLEAN NULL DEFAULT NULL,
HAS_E_BILLING BOOLEAN NULL DEFAULT NULL,
BRANCH VARCHAR(45) NULL DEFAULT NULL,
DEPOT VARCHAR(45) NULL DEFAULT NULL,
SUBSTATION_ID VARCHAR(45) NULL DEFAULT NULL,
CUSTOMER_REF VARCHAR(45) NULL DEFAULT NULL,
RESPONSE LONGBLOB NOT NULL,
LAST_READING_TIMESTAMP BIGINT NOT NULL,
PRIMARY KEY (SERIAL)
);
-- -----------------------------------------------------
-- Table `PROFILE_READINGS`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `PROFILE_READINGS` (
`ID` INT NOT NULL AUTO_INCREMENT,
`OPERATION_ID` INT NOT NULL,
`OBIS` VARCHAR(45) NULL DEFAULT NULL,
`SUB_TYPE_ID` INT NOT NULL,
`NODE_TYPE` VARCHAR(45) NULL DEFAULT NULL,
`CATEGORY` VARCHAR(45) NULL DEFAULT NULL,
`HAS_EXPORT` BOOLEAN NULL DEFAULT NULL,
`HAS_E_BILLING` BOOLEAN NULL DEFAULT NULL,
`BRANCH` VARCHAR(45) NULL DEFAULT NULL,
`DEPOT` VARCHAR(45) NULL DEFAULT NULL,
`SUBSTATION_ID` VARCHAR(45) NULL DEFAULT NULL,
`SERIAL` VARCHAR(45) NOT NULL,
`CUSTOMER_REF` VARCHAR(45) NULL DEFAULT NULL,
`PROFILE_DATA` BLOB NOT NULL,
`TIMESTAMP` BIGINT(15) NOT NULL,
PRIMARY KEY (`ID`));
-- -----------------------------------------------------
-- Table `METER_INSTALL`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `METER_INSTALL` (
`ID` INT NOT NULL AUTO_INCREMENT,
`SERIAL` VARCHAR(45) NOT NULL,
`USERNAME` VARCHAR(45) NULL DEFAULT NULL,
`JOB_ID` VARCHAR(45) NULL DEFAULT NULL,
`LAB_SEAL` VARCHAR(45) NULL DEFAULT NULL,
`COM_MODULE_SEAL` VARCHAR(45) NULL DEFAULT NULL,
`TERMINAL_COVER_SEAL` VARCHAR(45) NULL DEFAULT NULL,
`METER_ENCLOSURE_SEAL` VARCHAR(45) NULL DEFAULT NULL,
`PRINTED_SERIAL` VARCHAR(45) NULL DEFAULT NULL,
`CUSTOMER_REF` VARCHAR(45) NULL DEFAULT NULL,
`IMPORT_READING` DOUBLE DEFAULT 0,
`EXPORT_READING` DOUBLE DEFAULT 0,
`READING_TIMESTAMP` BIGINT(15) DEFAULT 0,
`TIMESTAMP` TIMESTAMP NOT NULL,
PRIMARY KEY (`ID`));
-- -----------------------------------------------------
-- Table `METER_UNINSTALL`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `METER_UNINSTALL` (
`ID` INT NOT NULL AUTO_INCREMENT,
`SERIAL` VARCHAR(45) NOT NULL,
`USERNAME` VARCHAR(45) NULL DEFAULT NULL,
`JOB_ID` VARCHAR(45) NULL DEFAULT NULL,
`LAB_SEAL` VARCHAR(45) NULL DEFAULT NULL,
`COM_MODULE_SEAL` VARCHAR(45) NULL DEFAULT NULL,
`TERMINAL_COVER_SEAL` VARCHAR(45) NULL DEFAULT NULL,
`METER_ENCLOSURE_SEAL` VARCHAR(45) NULL DEFAULT NULL,
`PRINTED_SERIAL` VARCHAR(45) NULL DEFAULT NULL,
`CUSTOMER_REF` VARCHAR(45) NULL DEFAULT NULL,
`IMPORT_READING` DOUBLE DEFAULT 0,
`EXPORT_READING` DOUBLE DEFAULT 0,
`READING_TIMESTAMP` BIGINT(15) DEFAULT 0,
`TIMESTAMP` TIMESTAMP NOT NULL,
PRIMARY KEY (`ID`));
-- -----------------------------------------------------
-- Table `RSSI_LEVEL`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `RSSI_LEVEL` (
`ID` INT NOT NULL AUTO_INCREMENT,
`IMEI` VARCHAR(45) NOT NULL,
`SIM_IMSI` VARCHAR(45) NULL DEFAULT NULL,
`FW_VERSION` INT NULL DEFAULT 0,
`COM_TYPE_ID` INT NOT NULL,
`RSSI` INT NULL DEFAULT 0,
`NETWORK` VARCHAR(45) NULL DEFAULT NULL,
`CELL_ID` VARCHAR(45) NULL DEFAULT NULL,
`LAC` VARCHAR(45) NULL DEFAULT NULL,
`RSRP` DECIMAL (5, 2) NULL DEFAULT 0,
`RSRQ` DECIMAL (5, 2) NULL DEFAULT 0,
`SNR` DECIMAL (5, 2) NULL DEFAULT 0,
`PCI` INT NULL DEFAULT 0,
`TRANSPORT` VARCHAR(45) NULL DEFAULT NULL,
`TIMESTAMP` BIGINT(15) NOT NULL,
PRIMARY KEY (`ID`));
-- -----------------------------------------------------
-- Table `REQUEST`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `REQUEST` (
`ID` int NOT NULL AUTO_INCREMENT,
`DUE_DATE` bigint DEFAULT '0',
`REQUESTED_BY` varchar(100) NOT NULL,
`REQUESTED_DATE` bigint DEFAULT '0',
`STATUS` varchar(45) NOT NULL,
`BRANCH` varchar(45) DEFAULT NULL,
`REMARKS` varchar(255) NOT NULL,
`REQUEST_TYPE` int NOT NULL,
PRIMARY KEY (`ID`)
) ;
-- -----------------------------------------------------
-- Table `METER_ASSIGNMENT_REQUEST`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `METER_ASSIGNMENT_REQUEST` (
`ID` int NOT NULL,
`SUB_TYPE_ID` int NOT NULL,
`PRIMARY_CT_RATIO` float DEFAULT '0',
`SECONDARY_CT_RATIO` float DEFAULT '0',
`PRIMARY_PT_RATIO` float DEFAULT '0',
`SECONDARY_PT_RATIO` float DEFAULT '0',
`NODE_TYPE` varchar(45) DEFAULT NULL,
`REQUESTED_COUNT` int NOT NULL,
`ACCEPTED_COUNT` int DEFAULT NULL,
`ASSIGNED_COUNT` int DEFAULT NULL,
`SUBSTATION_ID` varchar(45) DEFAULT NULL,
`CUSTOMER_REF` varchar(45) DEFAULT NULL,
`DEPOT` VARCHAR(45) DEFAULT NULL,
`PURPOSE` VARCHAR(50) DEFAULT NULL,
`ADDRESS` VARCHAR(255) DEFAULT NULL,
`DESCRIPTION` VARCHAR(100) DEFAULT NULL,
PRIMARY KEY (`ID`),
CONSTRAINT `fk_ASSIGNMENT_REQUEST_REQUEST` FOREIGN KEY (`ID`) REFERENCES `REQUEST` (`ID`)
) ;
-- -----------------------------------------------------
-- Table `DISCONNECTION_REQUEST`
-- -------------------------------------------------------
CREATE TABLE IF NOT EXISTS `DISCONNECTION_REQUEST` (
`ID` int NOT NULL,
`ACTIVITY_ID` VARCHAR(45) DEFAULT NULL,
PRIMARY KEY (`ID`),
CONSTRAINT `fk_DISCONNECTION_REQUEST_REQUEST` FOREIGN KEY (`ID`) REFERENCES `REQUEST` (`ID`)
) ;
-- -----------------------------------------------------
-- Table `FIELD_TEST_REQUEST`
-- -------------------------------------------------------
CREATE TABLE IF NOT EXISTS `FIELD_TEST_REQUEST` (
`ID` int NOT NULL,
`TEAM` varchar(255) DEFAULT NULL,
`SCHEDULED_DATE` bigint DEFAULT '0',
`RESULT` varchar(50) DEFAULT NULL,
`ATTACHMENT` blob,
PRIMARY KEY (`ID`),
CONSTRAINT `fk_ASSIGNMENT_FIELD_TEST_REQUEST_REQUEST` FOREIGN KEY (`ID`) REFERENCES `REQUEST` (`ID`)
);
-- -----------------------------------------------------
-- Table `LOAD_PROFILE_REQUEST`
-- -------------------------------------------------------
CREATE TABLE IF NOT EXISTS `LOAD_PROFILE_REQUEST` (
`ID` int NOT NULL,
`ACTIVITY_ID` VARCHAR(45) DEFAULT NULL,
`START_DATE` bigint DEFAULT '0',
`END_DATE` bigint DEFAULT '0',
PRIMARY KEY (`ID`),
CONSTRAINT `fk_LOAD_PROFILE_REQUEST_REQUEST_REQUEST` FOREIGN KEY (`ID`) REFERENCES `REQUEST` (`ID`)
);
-- -----------------------------------------------------
-- Table `READOUT_REQUEST`
-- -------------------------------------------------------
CREATE TABLE `READOUT_REQUEST` (
`ID` int NOT NULL,
`ACTIVITY_ID` VARCHAR(45) DEFAULT NULL,
PRIMARY KEY (`ID`),
CONSTRAINT `fk_READUOT_REQUEST_REQUEST_REQUEST` FOREIGN KEY (`ID`) REFERENCES `REQUEST` (`ID`)
);
-- -----------------------------------------------------
-- Table `COM_MODULE_REQUEST`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `COM_MODULE_REQUEST` (
`ID` INT NOT NULL,
`MODULE_TYPE` VARCHAR(45) NOT NULL,
`REQUESTED_COUNT` INT NOT NULL,
`ACCEPTED_COUNT` INT DEFAULT NULL,
`ASSIGNED_COUNT` INT DEFAULT NULL,
PRIMARY KEY (`ID`),
CONSTRAINT `fk_COM_MODULE_REQUEST_REQUEST` FOREIGN KEY (`ID`)
REFERENCES `REQUEST` (`ID`)
);
-- -----------------------------------------------------
-- Table `RECONNECTION_REQUEST`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `RECONNECTION_REQUEST` (
`ID` int NOT NULL,
`ACTIVITY_ID` VARCHAR(45) DEFAULT NULL,
PRIMARY KEY (`ID`),
CONSTRAINT `fk_RECONNECTION_REQUEST_REQUEST` FOREIGN KEY (`ID`)
REFERENCES `REQUEST` (`ID`) ON DELETE NO ACTION ON UPDATE NO ACTION
);
-----------------------------------------------------
-- Table `REQUEST_LIFECYCLE_EVENT`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `REQUEST_LIFECYCLE_EVENT` (
`ID` int NOT NULL AUTO_INCREMENT,
`REQUEST_ID` int NOT NULL,
`UPDATED_BY` varchar(100) NOT NULL,
`UPDATED_DATE` bigint DEFAULT '0',
`STATUS` varchar(45) NOT NULL,
`REMARKS` varchar(200) DEFAULT NULL,
PRIMARY KEY (`ID`),
CONSTRAINT `fk_REQUEST_LIFECYCLE_EVENT_REQUEST` FOREIGN KEY (`REQUEST_ID`) REFERENCES `REQUEST` (`ID`)
) ;
-- -----------------------------------------------------
-- Table `DEVICE_EVENTS`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `PROCESSED_DEVICE_EVENTS` (
`ID` INT NOT NULL AUTO_INCREMENT,
`METER_SERIAL` VARCHAR(45),
`IP_ADDRESS` VARCHAR(45),
`NUMBER` VARCHAR(45),
`TYPE` VARCHAR(45) NOT NULL,
`KEY` VARCHAR(100) NOT NULL,
`VALUE` VARCHAR(100) NOT NULL,
`EVENT` VARCHAR(45) NOT NULL,
`TIMESTAMP` BIGINT(15) DEFAULT 0,
PRIMARY KEY (`ID`));
-- -----------------------------------------------------
-- Table `DM_DEVICE_SUB_TYPE`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `DM_DEVICE_SUB_TYPE` (
`TENANT_ID` INT DEFAULT 0,
`SUB_TYPE_ID` INT 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`)
);
-- -----------------------------------------------------
-- Table `OPERATION_TEMPLATE`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `OPERATION_TEMPLATE`(
`TEMPLATE_ID` INT NOT NULL AUTO_INCREMENT,
`SUB_TYPE_ID` INT NOT NULL,
`OPERATION_CODE` VARCHAR(100) NOT NULL,
`OPERATION_DEFINITION` TEXT DEFAULT NULL,
PRIMARY KEY (`TEMPLATE_ID`)
);
-- -----------------------------------------------------
-- Table `GENERIC_METER_REGISTER`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `GENERIC_METER_REGISTER`(
`RRPK_ID` VARCHAR(100) NOT NULL,
`DESCRIPTION` VARCHAR(100) NOT NULL,
`UNIT` VARCHAR(45) NULL DEFAULT NULL,
`ORDER` INT NOT NULL,
PRIMARY KEY (`RRPK_ID`)
);
CREATE TABLE 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),
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)
);
-- -----------------------------------------------------
-- Sample data for DAO test cases
-- -----------------------------------------------------
INSERT INTO DM_DEVICE_TYPE(NAME, DEVICE_TYPE_META, LAST_UPDATED_TIMESTAMP, PROVIDER_TENANT_ID, SHARED_WITH_ALL_TENANTS) VALUES
('android','NULL','2020-10-14 16:05:15',-1234,1),('power-meter','NULL','2020-10-14 16:05:15',-1234,1),
('communication-module','NULL','2020-10-14 16:05:15',-1234,1),('sim','NULL','2020-10-14 16:05:15',-1234,1);
INSERT INTO DM_DEVICE(DESCRIPTION, NAME, DEVICE_TYPE_ID, DEVICE_IDENTIFICATION, LAST_UPDATED_TIMESTAMP, TENANT_ID) VALUES
('+94713192111', '192.168.118.111', 4, '413012689159555', '2022-04-04 16:55:52', '-1234'),
('NULL', '864495036647555', 3, '864495036647555', '2022-04-04 16:56:52', '-1234'),
('NULL', '000019729555', 2, '000019729555', '2022-04-04 16:56:52', '-1234');
INSERT INTO DM_ENROLMENT(DEVICE_ID,OWNER,OWNERSHIP,STATUS,IS_TRANSFERRED,DATE_OF_ENROLMENT,DATE_OF_LAST_UPDATE,TENANT_ID) VALUES
(1,'admin','COPE','ACTIVE',0,'2022-04-11 15:41:30','2022-04-11 15:41:30',-1234),
(2,'admin','COPE','ACTIVE',0,'2022-04-11 15:41:30','2022-04-11 15:41:30',-1234),
(3,'admin','COPE','ACTIVE',0,'2022-04-11 15:41:30','2022-04-11 15:41:30',-1234);
INSERT INTO DM_DEVICE_PROPERTIES (DEVICE_TYPE_NAME,DEVICE_IDENTIFICATION,PROPERTY_NAME,PROPERTY_VALUE,TENANT_ID) VALUES
('sim','413012689159555','APN','LECOSMSTC',-1234),
('sim','413012689159555','IP_ADDRESS','192.168.118.111',-1234),
('sim','413012689159555','MOBILE_NO','+94713192111',-1234),
('sim','413012689159555','SUB_TYPE_ID','1',-1234),
('sim','413012689159555','token',NULL,-1234),
('communication-module','864495036647555','BRANCH','KOTTE',-1234),
('communication-module','864495036647555','FW_VERSION','6',-1234),
('communication-module','864495036647555','SIM_IMSI','413012689159555',-1234),
('communication-module','864495036647555','SIM_PIN','1234',-1234),
('communication-module','864495036647555','SUB_TYPE_ID','1',-1234),
('communication-module','864495036647555','token',NULL,-1234),
('power-meter','000019729555','BRANCH','KOTTE',-1234),
('power-meter','000019729555','CATEGORY','BILLING_BULK',-1234),
('power-meter','000019729555','COM_MODULE_IMEI','864495036647555',-1234),
('power-meter','000019729555','CUSTOMER_REF','0602297555',-1234),
('power-meter','000019729555','DEPOT','PITA-KOTTE',-1234),
('power-meter','000019729555','HAS_EXPORT','false',-1234),
('power-meter','000019729555','HAS_E_BILLING','false',-1234),
('power-meter','000019729555','IP_ADDRESS','192.168.118.111',-1234),
('power-meter','000019729555','IS_FEEDER_END','false',-1234),
('power-meter','000019729555','NODE_TYPE','BILLING',-1234),
('power-meter','000019729555','POLE_ID','NW55/5/15C',-1234),
('power-meter','000019729555','SIM_NUMBER','+94713192111',-1234),
('power-meter','000019729555','SUBSTATION_ID','AZ8555',-1234),
('power-meter','000019729555','SUB_TYPE_ID','1',-1234),
('power-meter','000019729555','token',NULL,-1234);
-- INSERT INTO SIM_DEVICE (IMSI,IP_ADDRESS,MOBILE_NO,SUB_TYPE_ID,APN) VALUES ('413012689159555','10.217.55.155','+94713192111',1,'LECOSMSTC');
INSERT INTO COMMUNICATION_MODULE(IMEI,SIM_IMSI,FW_VERSION,SUB_TYPE_ID,BRANCH,SMS_PIN) VALUES ('864495036647555','413012689159555',6,1,'KOTTE','1234');
INSERT INTO POWER_METER_DEVICE (SERIAL,IP_ADDRESS,SIM_NUMBER,COM_MODULE_IMEI,SUB_TYPE_ID,CUSTOMER_REF,NODE_TYPE,CATEGORY,BRANCH,DEPOT,SUBSTATION_ID,HAS_EXPORT,HAS_E_BILLING,IS_FEEDER_END,POLE_ID,ASSIGNED_ON)
VALUES ('000019729555','192.168.118.111','+94713192111','864495036647555',1,'0602297555','BILLING','BILLING_BULK','KOTTE','PITA-KOTTE','AZ82555','false','false','false','NW55/5/15C',NULL);
INSERT INTO DM_DEVICE_SUB_TYPE (SUB_TYPE_ID, TENANT_ID, DEVICE_TYPE, SUB_TYPE_NAME, TYPE_DEFINITION) VALUES
(3,-1234,'METER','TestSubType','{"make": "TestSubType", "model": "ATx-Mega SIM800", "subTypeId": 3, "hasSMSSupport": true, "hasICMPSupport": true, "socketServerPort": 8071}'),
(4,-1234,'METER','TestSubType','{"make": "TestSubType", "model": "ATx-Mega SIM800", "subTypeId": 4, "hasSMSSupport": true, "hasICMPSupport": true, "socketServerPort": 8071}');

@ -810,3 +810,19 @@ CREATE TABLE IF NOT EXISTS DM_TRACCAR_UNSYNCED_DEVICES (
PRIMARY KEY (ID)
);
-- END OF DM_TRACCAR_UNSYNCED_DEVICES TABLE --
-- SUB_OPERATION_TEMPLATE TABLE--
CREATE TABLE 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),
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--

@ -795,3 +795,6 @@ CREATE TABLE IF NOT EXISTS DM_TRACCAR_UNSYNCED_DEVICES (
PRIMARY KEY (ID)
);
-- END OF DM_TRACCAR_UNSYNCED_DEVICES TABLE --
-- SUB_OPERATION_TEMPLATE TABLE--
--TODO: Need to add SUB_OPERATION_TEMPLATE

@ -873,4 +873,19 @@ CREATE TABLE IF NOT EXISTS DM_TRACCAR_UNSYNCED_DEVICES (
TENANT_ID INTEGER DEFAULT 0,
PRIMARY KEY (ID)
);
-- END OF DM_TRACCAR_UNSYNCED_DEVICES TABLE --
-- SUB_OPERATION_TEMPLATE TABLE--
CREATE TABLE SUB_OPERATION_TEMPLATE (
SUB_OPERATION_TEMPLATE_ID int NOT NULL AUTO_INCREMENT,
OPERATION_DEFINITION json 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),
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)
) ENGINE=InnoDB;
-- END OF SUB_OPERATION_TEMPLATE TABLE--

@ -1142,3 +1142,6 @@ CREATE TABLE DM_TRACCAR_UNSYNCED_DEVICES (
CONSTRAINT DM_TRACCAR_UNSYNCED_DEVICES_PK PRIMARY KEY (ID)
);
-- END OF DM_TRACCAR_UNSYNCED_DEVICES TABLE --
-- SUB_OPERATION_TEMPLATE TABLE--
--TODO: Need to add SUB_OPERATION_TEMPLATE

@ -796,3 +796,6 @@ CREATE TABLE IF NOT EXISTS DM_TRACCAR_UNSYNCED_DEVICES (
PRIMARY KEY (ID)
);
-- END OF DM_TRACCAR_UNSYNCED_DEVICES TABLE --
-- SUB_OPERATION_TEMPLATE TABLE--
--TODO: Need to add SUB_OPERATION_TEMPLATE

Loading…
Cancel
Save