From c071b9de01870bf42a9aaa26cfa0dec0612bd67e Mon Sep 17 00:00:00 2001 From: Thameera Date: Sun, 21 Jan 2024 17:13:03 +0530 Subject: [PATCH 1/3] Modify operation template --- .../cache/OperationTemplateCacheLoader.java | 2 +- .../OperationTemplateCodesCacheLoader.java | 93 +++++++++++ .../template/dao/OperationTemplateDAO.java | 10 +- .../dao/impl/OperationTemplateDAOImpl.java | 96 ++++++++++-- .../util/OperationTemplateManagementUtil.java | 36 ++++- .../impl/OperationTemplateServiceImpl.java | 145 +++++++++++++++--- .../spi/OperationTemplateService.java | 10 +- .../core/operation/template/util/DAOUtil.java | 1 - .../mgt/core/operation/template/DAOTest.java | 12 +- .../core/operation/template/ServiceTest.java | 39 +++-- 10 files changed, 389 insertions(+), 55 deletions(-) create mode 100644 components/operation-template-mgt/io.entgra.device.mgt.core.operation.template/src/main/java/io/entgra/device/mgt/core/operation/template/cache/OperationTemplateCodesCacheLoader.java diff --git a/components/operation-template-mgt/io.entgra.device.mgt.core.operation.template/src/main/java/io/entgra/device/mgt/core/operation/template/cache/OperationTemplateCacheLoader.java b/components/operation-template-mgt/io.entgra.device.mgt.core.operation.template/src/main/java/io/entgra/device/mgt/core/operation/template/cache/OperationTemplateCacheLoader.java index f151d95d13..69783415a8 100644 --- a/components/operation-template-mgt/io.entgra.device.mgt.core.operation.template/src/main/java/io/entgra/device/mgt/core/operation/template/cache/OperationTemplateCacheLoader.java +++ b/components/operation-template-mgt/io.entgra.device.mgt.core.operation.template/src/main/java/io/entgra/device/mgt/core/operation/template/cache/OperationTemplateCacheLoader.java @@ -65,7 +65,7 @@ public class OperationTemplateCacheLoader extends CacheLoader> { + + private static final Log log = LogFactory.getLog(OperationTemplateCodesCacheLoader.class); + + private final OperationTemplateDAO operationTemplateDAO; + + public OperationTemplateCodesCacheLoader() { + this.operationTemplateDAO = OperationTemplateDAOFactory.getOperationTemplateDAO(); + } + + /** + * + * @param key the non-null key whose value should be loaded + * @return + * @throws OperationTemplateMgtPluginException + */ + @Override + public Set load(String key) throws OperationTemplateMgtPluginException { + OperationTemplateCacheKey operationTemplateCacheKey = OperationTemplateManagementUtil.getOperationTemplateCodeCacheKey( + key); + String subTypeId = operationTemplateCacheKey.getSubTypeId(); + String deviceType = operationTemplateCacheKey.getDeviceType(); + + if (log.isTraceEnabled()) { + log.trace( + "Loading operation template for subtype Id : " + subTypeId + " & deviceType : " + deviceType); + } + try { + ConnectionManagerUtils.openDBConnection(); + return operationTemplateDAO.getOperationTemplateCodesByDeviceTypeAndSubTypeId(deviceType, subTypeId); + } catch (DBConnectionException e) { + String msg = + "Error occurred while obtaining the database connection to retrieve operation template codes for " + + + "subtype Id : " + subTypeId + " & device type : " + deviceType; + log.error(msg); + throw new OperationTemplateMgtPluginException(msg, e); + } catch (InvalidCacheLoadException e) { + String msg = + "CacheLoader returned null for operation template codes for subtype Id : " + subTypeId + + " & device type : " + deviceType; + log.error(msg, e); + return null; + } catch (OperationTemplateManagementDAOException e) { + String msg = + "Error occurred in the database level while retrieving operation template codes for subtype Id : " + + subTypeId + " & device type : " + deviceType; + log.error(msg); + throw new OperationTemplateMgtPluginException(msg, e); + } finally { + ConnectionManagerUtils.closeDBConnection(); + } + } + +} diff --git a/components/operation-template-mgt/io.entgra.device.mgt.core.operation.template/src/main/java/io/entgra/device/mgt/core/operation/template/dao/OperationTemplateDAO.java b/components/operation-template-mgt/io.entgra.device.mgt.core.operation.template/src/main/java/io/entgra/device/mgt/core/operation/template/dao/OperationTemplateDAO.java index 5a0c60947b..2e3bba443d 100644 --- a/components/operation-template-mgt/io.entgra.device.mgt.core.operation.template/src/main/java/io/entgra/device/mgt/core/operation/template/dao/OperationTemplateDAO.java +++ b/components/operation-template-mgt/io.entgra.device.mgt.core.operation.template/src/main/java/io/entgra/device/mgt/core/operation/template/dao/OperationTemplateDAO.java @@ -21,6 +21,9 @@ package io.entgra.device.mgt.core.operation.template.dao; import io.entgra.device.mgt.core.operation.template.dto.OperationTemplate; import io.entgra.device.mgt.core.operation.template.exception.OperationTemplateManagementDAOException; +import java.util.List; +import java.util.Set; + /** * This class represents the key operations associated with persisting mobile-device related * information. @@ -31,8 +34,11 @@ public interface OperationTemplateDAO { OperationTemplate updateOperationTemplate(OperationTemplate operationTemplate) throws OperationTemplateManagementDAOException; - OperationTemplate getOperationTemplate(String subTypeId, String deviceType, String operationCode) throws OperationTemplateManagementDAOException; + OperationTemplate getOperationTemplateByDeviceTypeAndSubTypeIdAndOperationCode(String deviceType, String subTypeId, String operationCode) throws OperationTemplateManagementDAOException; + + List getAllOperationTemplatesByDeviceType(String deviceType) throws OperationTemplateManagementDAOException; - void deleteOperationTemplate(String subTypeId, String deviceCode, String operationCode) throws OperationTemplateManagementDAOException; + int deleteOperationTemplateByDeviceTypeAndSubTypeIdAndOperationCode(String deviceType, String subTypeId, String operationCode) throws OperationTemplateManagementDAOException; + Set getOperationTemplateCodesByDeviceTypeAndSubTypeId(String deviceType, String subTypeId) throws OperationTemplateManagementDAOException; } diff --git a/components/operation-template-mgt/io.entgra.device.mgt.core.operation.template/src/main/java/io/entgra/device/mgt/core/operation/template/dao/impl/OperationTemplateDAOImpl.java b/components/operation-template-mgt/io.entgra.device.mgt.core.operation.template/src/main/java/io/entgra/device/mgt/core/operation/template/dao/impl/OperationTemplateDAOImpl.java index 67a356bca9..17ee2d0bcd 100644 --- a/components/operation-template-mgt/io.entgra.device.mgt.core.operation.template/src/main/java/io/entgra/device/mgt/core/operation/template/dao/impl/OperationTemplateDAOImpl.java +++ b/components/operation-template-mgt/io.entgra.device.mgt.core.operation.template/src/main/java/io/entgra/device/mgt/core/operation/template/dao/impl/OperationTemplateDAOImpl.java @@ -31,6 +31,10 @@ import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Timestamp; +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; +import java.util.Set; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -102,7 +106,7 @@ public class OperationTemplateDAOImpl implements OperationTemplateDAO { stmt.setString(5, operationTemplate.getCode()); stmt.executeUpdate(); - return getOperationTemplate(operationTemplate.getSubTypeId(), operationTemplate.getDeviceType(), operationTemplate.getCode()); + return getOperationTemplateByDeviceTypeAndSubTypeIdAndOperationCode(operationTemplate.getDeviceType(), operationTemplate.getSubTypeId(), operationTemplate.getCode()); } catch (SQLException e) { String msg = "Error occurred while processing update operation template."; log.error(msg); @@ -122,14 +126,14 @@ public class OperationTemplateDAOImpl implements OperationTemplateDAO { * @throws OperationTemplateManagementDAOException */ @Override - public OperationTemplate getOperationTemplate(String subTypeId, String deviceType, String operationCode) + public OperationTemplate getOperationTemplateByDeviceTypeAndSubTypeIdAndOperationCode(String deviceType, String subTypeId, String operationCode) throws OperationTemplateManagementDAOException { try { - String sql = "SELECT * FROM SUB_OPERATION_TEMPLATE WHERE SUB_TYPE_ID = ? AND DEVICE_TYPE = ? AND OPERATION_CODE = ?"; + String sql = "SELECT * FROM SUB_OPERATION_TEMPLATE WHERE DEVICE_TYPE = ? AND SUB_TYPE_ID = ? AND OPERATION_CODE = ?"; Connection conn = ConnectionManagerUtils.getDBConnection(); try (PreparedStatement stmt = conn.prepareStatement(sql)) { - stmt.setString(1, subTypeId); - stmt.setString(2, deviceType); + stmt.setString(1, deviceType); + stmt.setString(2, subTypeId); stmt.setString(3, operationCode); try (ResultSet rs = stmt.executeQuery()) { @@ -151,22 +155,94 @@ public class OperationTemplateDAOImpl implements OperationTemplateDAO { } /** - * @param subTypeId * @param deviceType - * @param operationCode + * @param subTypeId + * @return * @throws OperationTemplateManagementDAOException */ @Override - public void deleteOperationTemplate(String subTypeId, String deviceType, String operationCode) + public Set getOperationTemplateCodesByDeviceTypeAndSubTypeId(String deviceType, String subTypeId) throws OperationTemplateManagementDAOException { - String sql = "DELETE FROM SUB_OPERATION_TEMPLATE WHERE SUB_TYPE_ID = ? AND DEVICE_TYPE = ? AND OPERATION_CODE = ?"; + try { + String sql = "SELECT OPERATION_CODE FROM SUB_OPERATION_TEMPLATE WHERE SUB_TYPE_ID = ? AND DEVICE_TYPE = ?"; Connection conn = ConnectionManagerUtils.getDBConnection(); try (PreparedStatement stmt = conn.prepareStatement(sql)) { stmt.setString(1, subTypeId); stmt.setString(2, deviceType); + + Set deviceTypes = new HashSet<>(); + try (ResultSet rs = stmt.executeQuery()) { + while (rs.next()) { + deviceTypes.add(rs.getString("OPERATION_CODE")); + } + return deviceTypes; + } + } catch (SQLException e) { + String msg = "Error occurred while getting operation template codes for sub type id : " + subTypeId + + " and device type : " + deviceType; + log.error(msg, e); + throw new OperationTemplateManagementDAOException(msg, e); + } + } catch (DBConnectionException e) { + String msg = "Error occurred while obtaining DB connection to getting operation template codes."; + log.error(msg); + throw new OperationTemplateManagementDAOException(msg, e); + } + } + + + /** + * @param deviceType + * @return + * @throws OperationTemplateManagementDAOException + */ + @Override + public List getAllOperationTemplatesByDeviceType(String deviceType) + throws OperationTemplateManagementDAOException { + + try { + String sql = "SELECT * FROM SUB_OPERATION_TEMPLATE WHERE DEVICE_TYPE = ?"; + List operationTemplates = new ArrayList<>(); + + Connection conn = ConnectionManagerUtils.getDBConnection(); + try (PreparedStatement stmt = conn.prepareStatement(sql)) { + stmt.setString(1, deviceType); + try (ResultSet rs = stmt.executeQuery()) { + while (rs.next()) { + operationTemplates.add(DAOUtil.loadOperationTemplate(rs)); + } + return operationTemplates; + } + } catch (SQLException e) { + String msg = "Error occurred while loading operation template list."; + log.error(e.getMessage()); + throw new OperationTemplateManagementDAOException(msg, e); + } + } catch (DBConnectionException e) { + String msg = "Error occurred while obtaining DB connection to loading operation template list."; + log.error(msg); + throw new OperationTemplateManagementDAOException(msg, e); + } + } + + /** + * @param subTypeId + * @param deviceType + * @param operationCode + * @throws OperationTemplateManagementDAOException + */ + @Override + public int deleteOperationTemplateByDeviceTypeAndSubTypeIdAndOperationCode(String deviceType, String subTypeId, String operationCode) + throws OperationTemplateManagementDAOException { + String sql = "DELETE FROM SUB_OPERATION_TEMPLATE WHERE DEVICE_TYPE = ? AND SUB_TYPE_ID = ? AND OPERATION_CODE = ?"; + try { + Connection conn = ConnectionManagerUtils.getDBConnection(); + try (PreparedStatement stmt = conn.prepareStatement(sql)) { + stmt.setString(1, deviceType); + stmt.setString(2, subTypeId); stmt.setString(3, operationCode); - stmt.executeUpdate(); + return stmt.executeUpdate(); } catch (SQLException e) { String msg = "Error occurred while deleting operation template for sub type id : " + subTypeId + " and operation code : " + operationCode; diff --git a/components/operation-template-mgt/io.entgra.device.mgt.core.operation.template/src/main/java/io/entgra/device/mgt/core/operation/template/dao/impl/util/OperationTemplateManagementUtil.java b/components/operation-template-mgt/io.entgra.device.mgt.core.operation.template/src/main/java/io/entgra/device/mgt/core/operation/template/dao/impl/util/OperationTemplateManagementUtil.java index 917288eb6c..b4ba139f6e 100644 --- a/components/operation-template-mgt/io.entgra.device.mgt.core.operation.template/src/main/java/io/entgra/device/mgt/core/operation/template/dao/impl/util/OperationTemplateManagementUtil.java +++ b/components/operation-template-mgt/io.entgra.device.mgt.core.operation.template/src/main/java/io/entgra/device/mgt/core/operation/template/dao/impl/util/OperationTemplateManagementUtil.java @@ -59,8 +59,18 @@ public class OperationTemplateManagementUtil { * @param operationCode * @return */ - public static String setOperationTemplateCacheKey(String subTypeId, String deviceType, String operationCode) { - return subTypeId + "|" + deviceType + "|" + operationCode; + public static String setOperationTemplateCacheKey(String deviceType, String subTypeId, String operationCode) { + return deviceType + "|" + subTypeId + "|" + operationCode; + } + + /** + * + * @param subTypeId + * @param deviceType + * @return + */ + public static String setOperationTemplateCacheKey(String deviceType, String subTypeId) { + return deviceType + "|" + subTypeId; } /** @@ -70,8 +80,8 @@ public class OperationTemplateManagementUtil { */ public static OperationTemplateCacheKey getOperationTemplateCacheKey(String key) { String[] keys = key.split("\\|"); - String subTypeId = keys[0];; - String deviceType = keys[1]; + String deviceType = keys[0];; + String subTypeId = keys[1]; String operationCode = keys[2]; OperationTemplateCacheKey operationTemplateCacheKey = new OperationTemplateCacheKey(); @@ -82,4 +92,22 @@ public class OperationTemplateManagementUtil { return operationTemplateCacheKey; } + /** + * + * @param key + * @return + */ + public static OperationTemplateCacheKey getOperationTemplateCodeCacheKey(String key) { + + String[] keys = key.split("\\|"); + String deviceType = keys[0];; + String subTypeId = keys[1]; + + OperationTemplateCacheKey operationTemplateCacheKey = new OperationTemplateCacheKey(); + operationTemplateCacheKey.setSubTypeId(subTypeId); + operationTemplateCacheKey.setDeviceType(deviceType); + + return operationTemplateCacheKey; + } + } diff --git a/components/operation-template-mgt/io.entgra.device.mgt.core.operation.template/src/main/java/io/entgra/device/mgt/core/operation/template/impl/OperationTemplateServiceImpl.java b/components/operation-template-mgt/io.entgra.device.mgt.core.operation.template/src/main/java/io/entgra/device/mgt/core/operation/template/impl/OperationTemplateServiceImpl.java index 80fa1ea139..f70330da49 100644 --- a/components/operation-template-mgt/io.entgra.device.mgt.core.operation.template/src/main/java/io/entgra/device/mgt/core/operation/template/impl/OperationTemplateServiceImpl.java +++ b/components/operation-template-mgt/io.entgra.device.mgt.core.operation.template/src/main/java/io/entgra/device/mgt/core/operation/template/impl/OperationTemplateServiceImpl.java @@ -22,6 +22,7 @@ import com.google.common.cache.CacheBuilder; import com.google.common.cache.CacheLoader; import com.google.common.cache.LoadingCache; import io.entgra.device.mgt.core.operation.template.cache.OperationTemplateCacheLoader; +import io.entgra.device.mgt.core.operation.template.cache.OperationTemplateCodesCacheLoader; import io.entgra.device.mgt.core.operation.template.dao.OperationTemplateDAO; import io.entgra.device.mgt.core.operation.template.dao.OperationTemplateDAOFactory; import io.entgra.device.mgt.core.operation.template.dao.impl.util.OperationTemplateManagementUtil; @@ -35,6 +36,10 @@ import io.entgra.device.mgt.core.operation.template.util.AssertUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; +import java.util.Set; import java.util.concurrent.ExecutionException; import java.util.concurrent.TimeUnit; @@ -46,6 +51,9 @@ public class OperationTemplateServiceImpl implements OperationTemplateService { private static final Log log = LogFactory.getLog(OperationTemplateServiceImpl.class); private static final LoadingCache operationTemplateCache = CacheBuilder.newBuilder() .expireAfterWrite(15, TimeUnit.MINUTES).build(new OperationTemplateCacheLoader()); + + private static final LoadingCache> operationTemplateCodeCache = CacheBuilder.newBuilder() + .expireAfterWrite(15, TimeUnit.MINUTES).build(new OperationTemplateCodesCacheLoader()); private final OperationTemplateDAO operationTemplateDAO; public OperationTemplateServiceImpl() { @@ -67,10 +75,6 @@ public class OperationTemplateServiceImpl implements OperationTemplateService { operationTemplateDAO.addOperationTemplate(operationTemplate); ConnectionManagerUtils.commitDBTransaction(); - String key = OperationTemplateManagementUtil.setOperationTemplateCacheKey( - operationTemplate.getSubTypeId(), operationTemplate.getDeviceType(), operationTemplate.getCode()); - operationTemplateCache.put(key, operationTemplate); - if (log.isDebugEnabled()) { String msg = "Operation Template added successfully,for subtype id " + operationTemplate.getSubTypeId() + " and operation code " @@ -82,6 +86,61 @@ public class OperationTemplateServiceImpl implements OperationTemplateService { throw new OperationTemplateMgtPluginException(e.getMessage(), e); } finally { ConnectionManagerUtils.closeDBConnection(); + addOperationTemplateDetailsForCacheLoader(operationTemplate); + } + } + + public void addOperationTemplateDetailsForCacheLoader(OperationTemplate operationTemplate) { + try { + String operationTemplateKey = OperationTemplateManagementUtil.setOperationTemplateCacheKey( + operationTemplate.getDeviceType(), operationTemplate.getSubTypeId(), operationTemplate.getCode()); + String operationTemplateCodeKey = OperationTemplateManagementUtil.setOperationTemplateCacheKey( + operationTemplate.getDeviceType(), operationTemplate.getSubTypeId()); + + operationTemplateCache.put(operationTemplateKey, operationTemplate); + + Set operationCodeList = operationTemplateCodeCache.get(operationTemplateCodeKey); + if (operationCodeList == null) { + operationCodeList = new HashSet<>(); + } + operationCodeList.add(operationTemplate.getCode()); + operationTemplateCodeCache.put(operationTemplateCodeKey, operationCodeList); + } catch (Exception e) { + log.error("Error occurred while adding operation template details for the cache loader", e); + } + } + + public void deleteOperationTemplateDetailsForCacheLoader(String deviceType, String subTypeId, String code) { + try { + String operationTemplateKey = OperationTemplateManagementUtil.setOperationTemplateCacheKey( + deviceType, subTypeId, code); + String operationTemplateCodeKey = OperationTemplateManagementUtil.setOperationTemplateCacheKey( + deviceType, subTypeId); + + operationTemplateCache.invalidate(operationTemplateKey); + operationTemplateCodeCache.invalidate(operationTemplateCodeKey); + } catch (Exception e) { + log.error("Error occurred removing operation template details for the cache loader", e); + } + } + + public void refreshOperationTemplateDetailsForCacheLoader(OperationTemplate operationTemplate) { + try { + if (operationTemplate != null) { + String operationTemplateKey = OperationTemplateManagementUtil.setOperationTemplateCacheKey(operationTemplate.getDeviceType(), + operationTemplate.getSubTypeId(), operationTemplate.getCode()); + String operationTemplateCodeKey = OperationTemplateManagementUtil.setOperationTemplateCacheKey( + operationTemplate.getDeviceType(), operationTemplate.getSubTypeId()); + + operationTemplateCache.put(operationTemplateKey, operationTemplate); + Set codeList = operationTemplateCodeCache.get(operationTemplateCodeKey); + codeList.remove(operationTemplate.getCode()); + operationTemplateCodeCache.put(operationTemplateCodeKey, codeList); + + + } + } catch (ExecutionException e) { + log.error("Error occurred while updating operation template cache loader"); } } @@ -102,6 +161,7 @@ public class OperationTemplateServiceImpl implements OperationTemplateService { updatedOperationTemplate = operationTemplateDAO.updateOperationTemplate( operationTemplate); ConnectionManagerUtils.commitDBTransaction(); + if (log.isDebugEnabled()) { String msg = "Operation Template updated successfully,for subtype id " + operationTemplate.getSubTypeId() + " and operation code " + operationTemplate.getCode() @@ -114,12 +174,7 @@ public class OperationTemplateServiceImpl implements OperationTemplateService { throw new OperationTemplateMgtPluginException(e.getMessage(), e); } finally { ConnectionManagerUtils.closeDBConnection(); - - if (updatedOperationTemplate != null) { - String key = OperationTemplateManagementUtil.setOperationTemplateCacheKey( - operationTemplate.getSubTypeId(), operationTemplate.getDeviceType(), operationTemplate.getCode()); - operationTemplateCache.refresh(key); - } + refreshOperationTemplateDetailsForCacheLoader(updatedOperationTemplate); } } @@ -131,12 +186,12 @@ public class OperationTemplateServiceImpl implements OperationTemplateService { * @throws OperationTemplateMgtPluginException */ @Override - public OperationTemplate getOperationTemplate(String subTypeId, String deviceType, String operationCode) + public OperationTemplate getOperationTemplateByDeviceTypeAndSubTypeIdAndOperationCode(String deviceType, String subTypeId, String operationCode) throws OperationTemplateMgtPluginException { try { validateGetOperationTemplate(subTypeId, deviceType, operationCode); - String key = OperationTemplateManagementUtil.setOperationTemplateCacheKey(subTypeId, deviceType, + String key = OperationTemplateManagementUtil.setOperationTemplateCacheKey(deviceType, subTypeId, operationCode); return operationTemplateCache.get(key); } catch (ExecutionException e) { @@ -150,6 +205,27 @@ public class OperationTemplateServiceImpl implements OperationTemplateService { } } + /** + * @param deviceType + * @return + * @throws OperationTemplateMgtPluginException + */ + @Override + public List getAllOperationTemplatesByDeviceType(String deviceType) + throws OperationTemplateMgtPluginException { + AssertUtils.hasText(deviceType, "Invalid device type."); + try { + ConnectionManagerUtils.openDBConnection(); + return operationTemplateDAO.getAllOperationTemplatesByDeviceType(deviceType); + } catch (DBConnectionException | OperationTemplateManagementDAOException e) { + log.error(e.getMessage()); + throw new OperationTemplateMgtPluginException(e.getMessage(), e); + } finally { + ConnectionManagerUtils.closeDBConnection(); + + } + } + /** * @param subTypeId * @param deviceType @@ -157,17 +233,18 @@ public class OperationTemplateServiceImpl implements OperationTemplateService { * @throws OperationTemplateMgtPluginException */ @Override - public void deleteOperationTemplate(String subTypeId, String deviceType, String operationCode) + public void deleteOperationTemplateByDeviceTypeAndSubTypeIdAndOperationCode(String deviceType, String subTypeId, 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); + AssertUtils.isNull(getOperationTemplateByDeviceTypeAndSubTypeIdAndOperationCode(deviceType, subTypeId, operationCode), msg); + int deleted = 0; try { ConnectionManagerUtils.beginDBTransaction(); - operationTemplateDAO.deleteOperationTemplate(subTypeId, deviceType, operationCode); + deleted = operationTemplateDAO.deleteOperationTemplateByDeviceTypeAndSubTypeIdAndOperationCode(deviceType, subTypeId, operationCode); ConnectionManagerUtils.commitDBTransaction(); if (log.isDebugEnabled()) { String debugMsg = "Operation Template deleted successfully,for subtype id " @@ -175,15 +252,43 @@ public class OperationTemplateServiceImpl implements OperationTemplateService { + operationCode + ""; log.debug(debugMsg); } - String key = OperationTemplateManagementUtil.setOperationTemplateCacheKey( - subTypeId, deviceType, operationCode); - operationTemplateCache.invalidate(key); } catch (DBConnectionException | OperationTemplateManagementDAOException e) { log.error(e.getMessage()); throw new OperationTemplateMgtPluginException(e.getMessage(), e); } finally { ConnectionManagerUtils.closeDBConnection(); + if (deleted == 1) { + deleteOperationTemplateDetailsForCacheLoader(deviceType, subTypeId, operationCode); + } + + } + } + /** + * @param deviceType + * @param subTypeId + * @return + * @throws OperationTemplateMgtPluginException + */ + @Override + public Set getOperationTemplateCodesByDeviceTypeAndSubTypeId(String deviceType, String subTypeId) + throws OperationTemplateMgtPluginException { + + try { + AssertUtils.hasText(subTypeId, "Invalid meter device subtype id: " + subTypeId); + AssertUtils.isTrue(Integer.valueOf(subTypeId)>0, "Invalid meter device subtype id: " + subTypeId); + AssertUtils.hasText(deviceType, "Invalid device type."); + + String key = OperationTemplateManagementUtil.setOperationTemplateCacheKey(deviceType, subTypeId); + return operationTemplateCodeCache.get(key); + } catch (ExecutionException e) { + log.error(e.getMessage()); + throw new OperationTemplateMgtPluginException(e.getMessage(), e); + } catch (CacheLoader.InvalidCacheLoadException e) { + String msg = "Operation Template codes doesn't exist for subtype id : " + subTypeId + " and device type : " + + deviceType; + log.error(msg, e); + return null; } } @@ -216,7 +321,7 @@ public class OperationTemplateServiceImpl implements OperationTemplateService { 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(), + AssertUtils.notNull(getOperationTemplateByDeviceTypeAndSubTypeIdAndOperationCode(operationTemplate.getDeviceType(), operationTemplate.getSubTypeId(), operationTemplate.getCode()), msg); } @@ -232,7 +337,7 @@ public class OperationTemplateServiceImpl implements OperationTemplateService { 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(), + AssertUtils.isNull(getOperationTemplateByDeviceTypeAndSubTypeIdAndOperationCode(operationTemplate.getDeviceType(), operationTemplate.getSubTypeId(), operationTemplate.getCode()), msg); } diff --git a/components/operation-template-mgt/io.entgra.device.mgt.core.operation.template/src/main/java/io/entgra/device/mgt/core/operation/template/spi/OperationTemplateService.java b/components/operation-template-mgt/io.entgra.device.mgt.core.operation.template/src/main/java/io/entgra/device/mgt/core/operation/template/spi/OperationTemplateService.java index 659509b34b..332bc585d6 100644 --- a/components/operation-template-mgt/io.entgra.device.mgt.core.operation.template/src/main/java/io/entgra/device/mgt/core/operation/template/spi/OperationTemplateService.java +++ b/components/operation-template-mgt/io.entgra.device.mgt.core.operation.template/src/main/java/io/entgra/device/mgt/core/operation/template/spi/OperationTemplateService.java @@ -21,6 +21,9 @@ package io.entgra.device.mgt.core.operation.template.spi; import io.entgra.device.mgt.core.operation.template.dto.OperationTemplate; import io.entgra.device.mgt.core.operation.template.exception.OperationTemplateMgtPluginException; +import java.util.List; +import java.util.Set; + /** * Operation Template service interface. */ @@ -30,8 +33,11 @@ public interface OperationTemplateService { OperationTemplate updateOperationTemplate(OperationTemplate operationTemplate) throws OperationTemplateMgtPluginException; - OperationTemplate getOperationTemplate(String subTypeId, String deviceType, String operationCode) throws OperationTemplateMgtPluginException; + OperationTemplate getOperationTemplateByDeviceTypeAndSubTypeIdAndOperationCode(String deviceType, String subTypeId, String operationCode) throws OperationTemplateMgtPluginException; + + List getAllOperationTemplatesByDeviceType(String deviceType) throws OperationTemplateMgtPluginException; - void deleteOperationTemplate(String subTypeId, String deviceType, String operationCode) throws OperationTemplateMgtPluginException; + void deleteOperationTemplateByDeviceTypeAndSubTypeIdAndOperationCode(String deviceType, String subTypeId, String operationCode) throws OperationTemplateMgtPluginException; + Set getOperationTemplateCodesByDeviceTypeAndSubTypeId(String deviceType, String subTypeId) throws OperationTemplateMgtPluginException; } diff --git a/components/operation-template-mgt/io.entgra.device.mgt.core.operation.template/src/main/java/io/entgra/device/mgt/core/operation/template/util/DAOUtil.java b/components/operation-template-mgt/io.entgra.device.mgt.core.operation.template/src/main/java/io/entgra/device/mgt/core/operation/template/util/DAOUtil.java index 18edcf7c8c..9953fad0b0 100644 --- a/components/operation-template-mgt/io.entgra.device.mgt.core.operation.template/src/main/java/io/entgra/device/mgt/core/operation/template/util/DAOUtil.java +++ b/components/operation-template-mgt/io.entgra.device.mgt.core.operation.template/src/main/java/io/entgra/device/mgt/core/operation/template/util/DAOUtil.java @@ -44,7 +44,6 @@ public class DAOUtil { public static OperationTemplate loadOperationTemplate(ResultSet rs) throws SQLException, JsonSyntaxException { OperationTemplate operationTemplate = new OperationTemplate(); - Gson g = new Gson(); operationTemplate.setSubTypeId(rs.getString("SUB_TYPE_ID")); operationTemplate.setCode(rs.getString("OPERATION_CODE")); operationTemplate.setDeviceType(rs.getString("DEVICE_TYPE")); diff --git a/components/operation-template-mgt/io.entgra.device.mgt.core.operation.template/src/test/java/io/entgra/device/mgt/core/operation/template/DAOTest.java b/components/operation-template-mgt/io.entgra.device.mgt.core.operation.template/src/test/java/io/entgra/device/mgt/core/operation/template/DAOTest.java index c993cc435e..95594ad92d 100644 --- a/components/operation-template-mgt/io.entgra.device.mgt.core.operation.template/src/test/java/io/entgra/device/mgt/core/operation/template/DAOTest.java +++ b/components/operation-template-mgt/io.entgra.device.mgt.core.operation.template/src/test/java/io/entgra/device/mgt/core/operation/template/DAOTest.java @@ -48,8 +48,8 @@ public class DAOTest extends BaseOperationTemplatePluginTest { throws DBConnectionException, OperationTemplateManagementDAOException { ConnectionManagerUtils.openDBConnection(); - OperationTemplate operationTemplateActual = operationTemplateDAO.getOperationTemplate( - "4", TestUtils.deviceType, TestUtils.operationCode); + OperationTemplate operationTemplateActual = operationTemplateDAO.getOperationTemplateByDeviceTypeAndSubTypeIdAndOperationCode( + TestUtils.deviceType, "4", TestUtils.operationCode); ConnectionManagerUtils.closeDBConnection(); Assert.assertNotNull(operationTemplateActual, "Cannot be null"); Assert.assertEquals(operationTemplateActual.getSubTypeId(), "4"); @@ -72,8 +72,8 @@ public class DAOTest extends BaseOperationTemplatePluginTest { operationTemplateDAO.addOperationTemplate(operationTemplate); ConnectionManagerUtils.commitDBTransaction(); - OperationTemplate operationTemplateActual = operationTemplateDAO.getOperationTemplate( - "4", TestUtils.deviceType, TestUtils.operationCode); + OperationTemplate operationTemplateActual = operationTemplateDAO.getOperationTemplateByDeviceTypeAndSubTypeIdAndOperationCode( + TestUtils.deviceType, "4", TestUtils.operationCode); ConnectionManagerUtils.closeDBConnection(); Assert.assertNotNull(operationTemplateActual, "Cannot be null"); Assert.assertEquals(operationTemplateActual.getSubTypeId(), "4"); @@ -86,8 +86,8 @@ public class DAOTest extends BaseOperationTemplatePluginTest { throws DBConnectionException, OperationTemplateManagementDAOException { ConnectionManagerUtils.beginDBTransaction(); - OperationTemplate operationTemplate = operationTemplateDAO.getOperationTemplate( - "4", TestUtils.deviceType, TestUtils.operationCode); + OperationTemplate operationTemplate = operationTemplateDAO.getOperationTemplateByDeviceTypeAndSubTypeIdAndOperationCode( + TestUtils.deviceType, "4", TestUtils.operationCode); OperationTemplate operationTemplateActual = operationTemplateDAO.updateOperationTemplate( operationTemplate); ConnectionManagerUtils.commitDBTransaction(); diff --git a/components/operation-template-mgt/io.entgra.device.mgt.core.operation.template/src/test/java/io/entgra/device/mgt/core/operation/template/ServiceTest.java b/components/operation-template-mgt/io.entgra.device.mgt.core.operation.template/src/test/java/io/entgra/device/mgt/core/operation/template/ServiceTest.java index e47fd7c1dd..96872a2407 100644 --- a/components/operation-template-mgt/io.entgra.device.mgt.core.operation.template/src/test/java/io/entgra/device/mgt/core/operation/template/ServiceTest.java +++ b/components/operation-template-mgt/io.entgra.device.mgt.core.operation.template/src/test/java/io/entgra/device/mgt/core/operation/template/ServiceTest.java @@ -29,6 +29,9 @@ import org.testng.Assert; import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; +import java.util.List; +import java.util.Set; + public class ServiceTest extends BaseOperationTemplatePluginTest { private static final Log log = LogFactory.getLog(ServiceTest.class); @@ -43,7 +46,8 @@ public class ServiceTest extends BaseOperationTemplatePluginTest { @Test(dependsOnMethods = "testAddOperationTemplate") public void testGetOperationTemplate() throws OperationTemplateMgtPluginException { - OperationTemplate operationTemplateActual = operationTemplateService.getOperationTemplate(TestUtils.subtypeId, TestUtils.deviceType, TestUtils.operationCode); + OperationTemplate operationTemplateActual = operationTemplateService.getOperationTemplateByDeviceTypeAndSubTypeIdAndOperationCode( + TestUtils.deviceType, TestUtils.subtypeId, TestUtils.operationCode); Assert.assertEquals(operationTemplateActual.getSubTypeId(), operationTemplateActual.getSubTypeId()); Assert.assertEquals(operationTemplateActual.getCode(), TestUtils.operationCode); Assert.assertEquals(operationTemplateActual.getDeviceType(), TestUtils.deviceType); @@ -59,7 +63,7 @@ public class ServiceTest extends BaseOperationTemplatePluginTest { operationTemplate.setOperationDefinition(TestUtils.getOperationDefinition(TestUtils.subtypeId, TestUtils.operationCode)); operationTemplateService.addOperationTemplate(operationTemplate); - OperationTemplate operationTemplateActual = operationTemplateService.getOperationTemplate(TestUtils.subtypeId, TestUtils.deviceType, TestUtils.operationCode); + OperationTemplate operationTemplateActual = operationTemplateService.getOperationTemplateByDeviceTypeAndSubTypeIdAndOperationCode(TestUtils.deviceType, TestUtils.subtypeId, TestUtils.operationCode); Assert.assertNotNull(operationTemplateActual, "Cannot be null"); Assert.assertEquals(operationTemplateActual.getOperationDefinition(), TestUtils.getOperationDefinition(TestUtils.subtypeId, TestUtils.operationCode)); Assert.assertEquals(operationTemplateActual.getSubTypeId(), operationTemplateActual.getSubTypeId()); @@ -70,7 +74,7 @@ public class ServiceTest extends BaseOperationTemplatePluginTest { @Test(dependsOnMethods = "testAddOperationTemplate") public void testUpdateOperationTemplate() throws OperationTemplateMgtPluginException { - OperationTemplate operationTemplate = operationTemplateService.getOperationTemplate(TestUtils.subtypeId, TestUtils.deviceType, TestUtils.operationCode); + OperationTemplate operationTemplate = operationTemplateService.getOperationTemplateByDeviceTypeAndSubTypeIdAndOperationCode(TestUtils.deviceType, TestUtils.subtypeId, TestUtils.operationCode); operationTemplate.setOperationDefinition("{}"); OperationTemplate operationTemplateActual = operationTemplateService.updateOperationTemplate(operationTemplate); @@ -81,13 +85,30 @@ public class ServiceTest extends BaseOperationTemplatePluginTest { Assert.assertEquals(operationTemplateActual.getDeviceType(), TestUtils.deviceType); } - @Test(dependsOnMethods = {"testAddOperationTemplate", "testGetOperationTemplate", "testUpdateOperationTemplate"}) - public void testDeleteOperationTemplate() throws OperationTemplateMgtPluginException { - operationTemplateService.deleteOperationTemplate(TestUtils.subtypeId, TestUtils.deviceType, TestUtils.operationCode); - Assert.assertNull(getOperationTemplateBySubtypeIdAndDeviceTypeAndOperationCode(TestUtils.subtypeId, TestUtils.deviceType, TestUtils.operationCode)); + + public OperationTemplate getOperationTemplateBySubtypeIdAndDeviceTypeAndOperationCode(String deviceType, String subtypeId, String operationCode) throws OperationTemplateMgtPluginException { + return operationTemplateService.getOperationTemplateByDeviceTypeAndSubTypeIdAndOperationCode(deviceType, subtypeId, operationCode); + } + + @Test(dependsOnMethods = "testAddOperationTemplate") + public void testGetOperationTemplateCodesByDeviceTypeAndSubTypeId() throws OperationTemplateMgtPluginException { + + Set operationCodes = operationTemplateService.getOperationTemplateCodesByDeviceTypeAndSubTypeId(TestUtils.deviceType, TestUtils.subtypeId); + Assert.assertNotNull(operationCodes, "Cannot be null"); + } + + @Test(dependsOnMethods = "testAddOperationTemplate") + public void testGetAllOperationTemplatesByDeviceType() throws OperationTemplateMgtPluginException { + + List operationTemplates = operationTemplateService.getAllOperationTemplatesByDeviceType(TestUtils.deviceType); + Assert.assertNotNull(operationTemplates, "Cannot be null"); + Assert.assertFalse(operationTemplates.isEmpty(), "operationTemplates is empty"); } - public OperationTemplate getOperationTemplateBySubtypeIdAndDeviceTypeAndOperationCode(String subtypeId, String deviceType, String operationCode) throws OperationTemplateMgtPluginException { - return operationTemplateService.getOperationTemplate(subtypeId, deviceType, operationCode); + @Test(dependsOnMethods = {"testAddOperationTemplate", "testGetOperationTemplate", "testUpdateOperationTemplate", + "testGetOperationTemplateCodesByDeviceTypeAndSubTypeId", "testGetAllOperationTemplatesByDeviceType"}) + public void testDeleteOperationTemplate() throws OperationTemplateMgtPluginException { + operationTemplateService.deleteOperationTemplateByDeviceTypeAndSubTypeIdAndOperationCode(TestUtils.deviceType, TestUtils.subtypeId, TestUtils.operationCode); + Assert.assertNull(getOperationTemplateBySubtypeIdAndDeviceTypeAndOperationCode(TestUtils.deviceType, TestUtils.subtypeId, TestUtils.operationCode)); } } -- 2.36.3 From fbbdd172e7850585816ab7dd991de9181f13c3a0 Mon Sep 17 00:00:00 2001 From: Thameera Date: Mon, 22 Jan 2024 10:45:29 +0530 Subject: [PATCH 2/3] Modify method names --- .../cache/OperationTemplateCacheLoader.java | 2 +- .../OperationTemplateCodesCacheLoader.java | 3 +- .../template/dao/OperationTemplateDAO.java | 8 ++--- .../dao/impl/OperationTemplateDAOImpl.java | 12 +++---- .../impl/OperationTemplateServiceImpl.java | 33 ++++++++++--------- .../spi/OperationTemplateService.java | 8 ++--- .../mgt/core/operation/template/DAOTest.java | 6 ++-- .../core/operation/template/ServiceTest.java | 14 ++++---- 8 files changed, 43 insertions(+), 43 deletions(-) diff --git a/components/operation-template-mgt/io.entgra.device.mgt.core.operation.template/src/main/java/io/entgra/device/mgt/core/operation/template/cache/OperationTemplateCacheLoader.java b/components/operation-template-mgt/io.entgra.device.mgt.core.operation.template/src/main/java/io/entgra/device/mgt/core/operation/template/cache/OperationTemplateCacheLoader.java index 69783415a8..e92ffbadcc 100644 --- a/components/operation-template-mgt/io.entgra.device.mgt.core.operation.template/src/main/java/io/entgra/device/mgt/core/operation/template/cache/OperationTemplateCacheLoader.java +++ b/components/operation-template-mgt/io.entgra.device.mgt.core.operation.template/src/main/java/io/entgra/device/mgt/core/operation/template/cache/OperationTemplateCacheLoader.java @@ -65,7 +65,7 @@ public class OperationTemplateCacheLoader extends CacheLoader getAllOperationTemplatesByDeviceType(String deviceType) throws OperationTemplateManagementDAOException; + List getAllOperationTemplates(String deviceType) throws OperationTemplateManagementDAOException; - int deleteOperationTemplateByDeviceTypeAndSubTypeIdAndOperationCode(String deviceType, String subTypeId, String operationCode) throws OperationTemplateManagementDAOException; + boolean deleteOperationTemplate(String deviceType, String subTypeId, String operationCode) throws OperationTemplateManagementDAOException; - Set getOperationTemplateCodesByDeviceTypeAndSubTypeId(String deviceType, String subTypeId) throws OperationTemplateManagementDAOException; + Set getOperationTemplateCodes(String deviceType, String subTypeId) throws OperationTemplateManagementDAOException; } diff --git a/components/operation-template-mgt/io.entgra.device.mgt.core.operation.template/src/main/java/io/entgra/device/mgt/core/operation/template/dao/impl/OperationTemplateDAOImpl.java b/components/operation-template-mgt/io.entgra.device.mgt.core.operation.template/src/main/java/io/entgra/device/mgt/core/operation/template/dao/impl/OperationTemplateDAOImpl.java index 17ee2d0bcd..441521cba5 100644 --- a/components/operation-template-mgt/io.entgra.device.mgt.core.operation.template/src/main/java/io/entgra/device/mgt/core/operation/template/dao/impl/OperationTemplateDAOImpl.java +++ b/components/operation-template-mgt/io.entgra.device.mgt.core.operation.template/src/main/java/io/entgra/device/mgt/core/operation/template/dao/impl/OperationTemplateDAOImpl.java @@ -106,7 +106,7 @@ public class OperationTemplateDAOImpl implements OperationTemplateDAO { stmt.setString(5, operationTemplate.getCode()); stmt.executeUpdate(); - return getOperationTemplateByDeviceTypeAndSubTypeIdAndOperationCode(operationTemplate.getDeviceType(), operationTemplate.getSubTypeId(), operationTemplate.getCode()); + return getOperationTemplate(operationTemplate.getDeviceType(), operationTemplate.getSubTypeId(), operationTemplate.getCode()); } catch (SQLException e) { String msg = "Error occurred while processing update operation template."; log.error(msg); @@ -126,7 +126,7 @@ public class OperationTemplateDAOImpl implements OperationTemplateDAO { * @throws OperationTemplateManagementDAOException */ @Override - public OperationTemplate getOperationTemplateByDeviceTypeAndSubTypeIdAndOperationCode(String deviceType, String subTypeId, String operationCode) + public OperationTemplate getOperationTemplate(String deviceType, String subTypeId, String operationCode) throws OperationTemplateManagementDAOException { try { String sql = "SELECT * FROM SUB_OPERATION_TEMPLATE WHERE DEVICE_TYPE = ? AND SUB_TYPE_ID = ? AND OPERATION_CODE = ?"; @@ -161,7 +161,7 @@ public class OperationTemplateDAOImpl implements OperationTemplateDAO { * @throws OperationTemplateManagementDAOException */ @Override - public Set getOperationTemplateCodesByDeviceTypeAndSubTypeId(String deviceType, String subTypeId) + public Set getOperationTemplateCodes(String deviceType, String subTypeId) throws OperationTemplateManagementDAOException { try { @@ -198,7 +198,7 @@ public class OperationTemplateDAOImpl implements OperationTemplateDAO { * @throws OperationTemplateManagementDAOException */ @Override - public List getAllOperationTemplatesByDeviceType(String deviceType) + public List getAllOperationTemplates(String deviceType) throws OperationTemplateManagementDAOException { try { @@ -233,7 +233,7 @@ public class OperationTemplateDAOImpl implements OperationTemplateDAO { * @throws OperationTemplateManagementDAOException */ @Override - public int deleteOperationTemplateByDeviceTypeAndSubTypeIdAndOperationCode(String deviceType, String subTypeId, String operationCode) + public boolean deleteOperationTemplate(String deviceType, String subTypeId, String operationCode) throws OperationTemplateManagementDAOException { String sql = "DELETE FROM SUB_OPERATION_TEMPLATE WHERE DEVICE_TYPE = ? AND SUB_TYPE_ID = ? AND OPERATION_CODE = ?"; try { @@ -242,7 +242,7 @@ public class OperationTemplateDAOImpl implements OperationTemplateDAO { stmt.setString(1, deviceType); stmt.setString(2, subTypeId); stmt.setString(3, operationCode); - return stmt.executeUpdate(); + return stmt.executeUpdate() == 1; } catch (SQLException e) { String msg = "Error occurred while deleting operation template for sub type id : " + subTypeId + " and operation code : " + operationCode; diff --git a/components/operation-template-mgt/io.entgra.device.mgt.core.operation.template/src/main/java/io/entgra/device/mgt/core/operation/template/impl/OperationTemplateServiceImpl.java b/components/operation-template-mgt/io.entgra.device.mgt.core.operation.template/src/main/java/io/entgra/device/mgt/core/operation/template/impl/OperationTemplateServiceImpl.java index f70330da49..5bc0d1c238 100644 --- a/components/operation-template-mgt/io.entgra.device.mgt.core.operation.template/src/main/java/io/entgra/device/mgt/core/operation/template/impl/OperationTemplateServiceImpl.java +++ b/components/operation-template-mgt/io.entgra.device.mgt.core.operation.template/src/main/java/io/entgra/device/mgt/core/operation/template/impl/OperationTemplateServiceImpl.java @@ -36,7 +36,6 @@ import io.entgra.device.mgt.core.operation.template.util.AssertUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import java.util.ArrayList; import java.util.HashSet; import java.util.List; import java.util.Set; @@ -110,7 +109,7 @@ public class OperationTemplateServiceImpl implements OperationTemplateService { } } - public void deleteOperationTemplateDetailsForCacheLoader(String deviceType, String subTypeId, String code) { + public void deleteOperationTemplateDetailsFromCacheLoader(String deviceType, String subTypeId, String code) { try { String operationTemplateKey = OperationTemplateManagementUtil.setOperationTemplateCacheKey( deviceType, subTypeId, code); @@ -124,7 +123,7 @@ public class OperationTemplateServiceImpl implements OperationTemplateService { } } - public void refreshOperationTemplateDetailsForCacheLoader(OperationTemplate operationTemplate) { + public void refreshOperationTemplateDetailsFromCacheLoader(OperationTemplate operationTemplate) { try { if (operationTemplate != null) { String operationTemplateKey = OperationTemplateManagementUtil.setOperationTemplateCacheKey(operationTemplate.getDeviceType(), @@ -174,7 +173,9 @@ public class OperationTemplateServiceImpl implements OperationTemplateService { throw new OperationTemplateMgtPluginException(e.getMessage(), e); } finally { ConnectionManagerUtils.closeDBConnection(); - refreshOperationTemplateDetailsForCacheLoader(updatedOperationTemplate); + if (updatedOperationTemplate != null) { + refreshOperationTemplateDetailsFromCacheLoader(updatedOperationTemplate); + } } } @@ -186,7 +187,7 @@ public class OperationTemplateServiceImpl implements OperationTemplateService { * @throws OperationTemplateMgtPluginException */ @Override - public OperationTemplate getOperationTemplateByDeviceTypeAndSubTypeIdAndOperationCode(String deviceType, String subTypeId, String operationCode) + public OperationTemplate getOperationTemplate(String deviceType, String subTypeId, String operationCode) throws OperationTemplateMgtPluginException { try { @@ -211,12 +212,12 @@ public class OperationTemplateServiceImpl implements OperationTemplateService { * @throws OperationTemplateMgtPluginException */ @Override - public List getAllOperationTemplatesByDeviceType(String deviceType) + public List getAllOperationTemplates(String deviceType) throws OperationTemplateMgtPluginException { AssertUtils.hasText(deviceType, "Invalid device type."); try { ConnectionManagerUtils.openDBConnection(); - return operationTemplateDAO.getAllOperationTemplatesByDeviceType(deviceType); + return operationTemplateDAO.getAllOperationTemplates(deviceType); } catch (DBConnectionException | OperationTemplateManagementDAOException e) { log.error(e.getMessage()); throw new OperationTemplateMgtPluginException(e.getMessage(), e); @@ -233,18 +234,18 @@ public class OperationTemplateServiceImpl implements OperationTemplateService { * @throws OperationTemplateMgtPluginException */ @Override - public void deleteOperationTemplateByDeviceTypeAndSubTypeIdAndOperationCode(String deviceType, String subTypeId, String operationCode) + public void deleteOperationTemplate(String deviceType, String subTypeId, 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(getOperationTemplateByDeviceTypeAndSubTypeIdAndOperationCode(deviceType, subTypeId, operationCode), msg); + AssertUtils.isNull(getOperationTemplate(deviceType, subTypeId, operationCode), msg); - int deleted = 0; + boolean isDelete = false; try { ConnectionManagerUtils.beginDBTransaction(); - deleted = operationTemplateDAO.deleteOperationTemplateByDeviceTypeAndSubTypeIdAndOperationCode(deviceType, subTypeId, operationCode); + isDelete = operationTemplateDAO.deleteOperationTemplate(deviceType, subTypeId, operationCode); ConnectionManagerUtils.commitDBTransaction(); if (log.isDebugEnabled()) { String debugMsg = "Operation Template deleted successfully,for subtype id " @@ -257,8 +258,8 @@ public class OperationTemplateServiceImpl implements OperationTemplateService { throw new OperationTemplateMgtPluginException(e.getMessage(), e); } finally { ConnectionManagerUtils.closeDBConnection(); - if (deleted == 1) { - deleteOperationTemplateDetailsForCacheLoader(deviceType, subTypeId, operationCode); + if (isDelete) { + deleteOperationTemplateDetailsFromCacheLoader(deviceType, subTypeId, operationCode); } } @@ -271,7 +272,7 @@ public class OperationTemplateServiceImpl implements OperationTemplateService { * @throws OperationTemplateMgtPluginException */ @Override - public Set getOperationTemplateCodesByDeviceTypeAndSubTypeId(String deviceType, String subTypeId) + public Set getOperationTemplateCodes(String deviceType, String subTypeId) throws OperationTemplateMgtPluginException { try { @@ -321,7 +322,7 @@ public class OperationTemplateServiceImpl implements OperationTemplateService { String msg = "Operation Template already exist for subtype id : " + operationTemplate.getSubTypeId() + " and device type : " + operationTemplate.getDeviceType() + " and operation code : " + operationTemplate.getCode(); - AssertUtils.notNull(getOperationTemplateByDeviceTypeAndSubTypeIdAndOperationCode(operationTemplate.getDeviceType(), operationTemplate.getSubTypeId(), + AssertUtils.notNull(getOperationTemplate(operationTemplate.getDeviceType(), operationTemplate.getSubTypeId(), operationTemplate.getCode()), msg); } @@ -337,7 +338,7 @@ public class OperationTemplateServiceImpl implements OperationTemplateService { String msg = "Operation Template does not exist for subtype id : " + operationTemplate.getSubTypeId() + " and device type : " + operationTemplate.getDeviceType() + " and operation code : " + operationTemplate.getCode(); - AssertUtils.isNull(getOperationTemplateByDeviceTypeAndSubTypeIdAndOperationCode(operationTemplate.getDeviceType(), operationTemplate.getSubTypeId(), + AssertUtils.isNull(getOperationTemplate(operationTemplate.getDeviceType(), operationTemplate.getSubTypeId(), operationTemplate.getCode()), msg); } diff --git a/components/operation-template-mgt/io.entgra.device.mgt.core.operation.template/src/main/java/io/entgra/device/mgt/core/operation/template/spi/OperationTemplateService.java b/components/operation-template-mgt/io.entgra.device.mgt.core.operation.template/src/main/java/io/entgra/device/mgt/core/operation/template/spi/OperationTemplateService.java index 332bc585d6..cb249d0298 100644 --- a/components/operation-template-mgt/io.entgra.device.mgt.core.operation.template/src/main/java/io/entgra/device/mgt/core/operation/template/spi/OperationTemplateService.java +++ b/components/operation-template-mgt/io.entgra.device.mgt.core.operation.template/src/main/java/io/entgra/device/mgt/core/operation/template/spi/OperationTemplateService.java @@ -33,11 +33,11 @@ public interface OperationTemplateService { OperationTemplate updateOperationTemplate(OperationTemplate operationTemplate) throws OperationTemplateMgtPluginException; - OperationTemplate getOperationTemplateByDeviceTypeAndSubTypeIdAndOperationCode(String deviceType, String subTypeId, String operationCode) throws OperationTemplateMgtPluginException; + OperationTemplate getOperationTemplate(String deviceType, String subTypeId, String operationCode) throws OperationTemplateMgtPluginException; - List getAllOperationTemplatesByDeviceType(String deviceType) throws OperationTemplateMgtPluginException; + List getAllOperationTemplates(String deviceType) throws OperationTemplateMgtPluginException; - void deleteOperationTemplateByDeviceTypeAndSubTypeIdAndOperationCode(String deviceType, String subTypeId, String operationCode) throws OperationTemplateMgtPluginException; + void deleteOperationTemplate(String deviceType, String subTypeId, String operationCode) throws OperationTemplateMgtPluginException; - Set getOperationTemplateCodesByDeviceTypeAndSubTypeId(String deviceType, String subTypeId) throws OperationTemplateMgtPluginException; + Set getOperationTemplateCodes(String deviceType, String subTypeId) throws OperationTemplateMgtPluginException; } diff --git a/components/operation-template-mgt/io.entgra.device.mgt.core.operation.template/src/test/java/io/entgra/device/mgt/core/operation/template/DAOTest.java b/components/operation-template-mgt/io.entgra.device.mgt.core.operation.template/src/test/java/io/entgra/device/mgt/core/operation/template/DAOTest.java index 95594ad92d..6074ad2a3c 100644 --- a/components/operation-template-mgt/io.entgra.device.mgt.core.operation.template/src/test/java/io/entgra/device/mgt/core/operation/template/DAOTest.java +++ b/components/operation-template-mgt/io.entgra.device.mgt.core.operation.template/src/test/java/io/entgra/device/mgt/core/operation/template/DAOTest.java @@ -48,7 +48,7 @@ public class DAOTest extends BaseOperationTemplatePluginTest { throws DBConnectionException, OperationTemplateManagementDAOException { ConnectionManagerUtils.openDBConnection(); - OperationTemplate operationTemplateActual = operationTemplateDAO.getOperationTemplateByDeviceTypeAndSubTypeIdAndOperationCode( + OperationTemplate operationTemplateActual = operationTemplateDAO.getOperationTemplate( TestUtils.deviceType, "4", TestUtils.operationCode); ConnectionManagerUtils.closeDBConnection(); Assert.assertNotNull(operationTemplateActual, "Cannot be null"); @@ -72,7 +72,7 @@ public class DAOTest extends BaseOperationTemplatePluginTest { operationTemplateDAO.addOperationTemplate(operationTemplate); ConnectionManagerUtils.commitDBTransaction(); - OperationTemplate operationTemplateActual = operationTemplateDAO.getOperationTemplateByDeviceTypeAndSubTypeIdAndOperationCode( + OperationTemplate operationTemplateActual = operationTemplateDAO.getOperationTemplate( TestUtils.deviceType, "4", TestUtils.operationCode); ConnectionManagerUtils.closeDBConnection(); Assert.assertNotNull(operationTemplateActual, "Cannot be null"); @@ -86,7 +86,7 @@ public class DAOTest extends BaseOperationTemplatePluginTest { throws DBConnectionException, OperationTemplateManagementDAOException { ConnectionManagerUtils.beginDBTransaction(); - OperationTemplate operationTemplate = operationTemplateDAO.getOperationTemplateByDeviceTypeAndSubTypeIdAndOperationCode( + OperationTemplate operationTemplate = operationTemplateDAO.getOperationTemplate( TestUtils.deviceType, "4", TestUtils.operationCode); OperationTemplate operationTemplateActual = operationTemplateDAO.updateOperationTemplate( operationTemplate); diff --git a/components/operation-template-mgt/io.entgra.device.mgt.core.operation.template/src/test/java/io/entgra/device/mgt/core/operation/template/ServiceTest.java b/components/operation-template-mgt/io.entgra.device.mgt.core.operation.template/src/test/java/io/entgra/device/mgt/core/operation/template/ServiceTest.java index 96872a2407..6c439ef013 100644 --- a/components/operation-template-mgt/io.entgra.device.mgt.core.operation.template/src/test/java/io/entgra/device/mgt/core/operation/template/ServiceTest.java +++ b/components/operation-template-mgt/io.entgra.device.mgt.core.operation.template/src/test/java/io/entgra/device/mgt/core/operation/template/ServiceTest.java @@ -46,7 +46,7 @@ public class ServiceTest extends BaseOperationTemplatePluginTest { @Test(dependsOnMethods = "testAddOperationTemplate") public void testGetOperationTemplate() throws OperationTemplateMgtPluginException { - OperationTemplate operationTemplateActual = operationTemplateService.getOperationTemplateByDeviceTypeAndSubTypeIdAndOperationCode( + OperationTemplate operationTemplateActual = operationTemplateService.getOperationTemplate( TestUtils.deviceType, TestUtils.subtypeId, TestUtils.operationCode); Assert.assertEquals(operationTemplateActual.getSubTypeId(), operationTemplateActual.getSubTypeId()); Assert.assertEquals(operationTemplateActual.getCode(), TestUtils.operationCode); @@ -63,7 +63,7 @@ public class ServiceTest extends BaseOperationTemplatePluginTest { operationTemplate.setOperationDefinition(TestUtils.getOperationDefinition(TestUtils.subtypeId, TestUtils.operationCode)); operationTemplateService.addOperationTemplate(operationTemplate); - OperationTemplate operationTemplateActual = operationTemplateService.getOperationTemplateByDeviceTypeAndSubTypeIdAndOperationCode(TestUtils.deviceType, TestUtils.subtypeId, TestUtils.operationCode); + OperationTemplate operationTemplateActual = operationTemplateService.getOperationTemplate(TestUtils.deviceType, TestUtils.subtypeId, TestUtils.operationCode); Assert.assertNotNull(operationTemplateActual, "Cannot be null"); Assert.assertEquals(operationTemplateActual.getOperationDefinition(), TestUtils.getOperationDefinition(TestUtils.subtypeId, TestUtils.operationCode)); Assert.assertEquals(operationTemplateActual.getSubTypeId(), operationTemplateActual.getSubTypeId()); @@ -74,7 +74,7 @@ public class ServiceTest extends BaseOperationTemplatePluginTest { @Test(dependsOnMethods = "testAddOperationTemplate") public void testUpdateOperationTemplate() throws OperationTemplateMgtPluginException { - OperationTemplate operationTemplate = operationTemplateService.getOperationTemplateByDeviceTypeAndSubTypeIdAndOperationCode(TestUtils.deviceType, TestUtils.subtypeId, TestUtils.operationCode); + OperationTemplate operationTemplate = operationTemplateService.getOperationTemplate(TestUtils.deviceType, TestUtils.subtypeId, TestUtils.operationCode); operationTemplate.setOperationDefinition("{}"); OperationTemplate operationTemplateActual = operationTemplateService.updateOperationTemplate(operationTemplate); @@ -87,20 +87,20 @@ public class ServiceTest extends BaseOperationTemplatePluginTest { public OperationTemplate getOperationTemplateBySubtypeIdAndDeviceTypeAndOperationCode(String deviceType, String subtypeId, String operationCode) throws OperationTemplateMgtPluginException { - return operationTemplateService.getOperationTemplateByDeviceTypeAndSubTypeIdAndOperationCode(deviceType, subtypeId, operationCode); + return operationTemplateService.getOperationTemplate(deviceType, subtypeId, operationCode); } @Test(dependsOnMethods = "testAddOperationTemplate") public void testGetOperationTemplateCodesByDeviceTypeAndSubTypeId() throws OperationTemplateMgtPluginException { - Set operationCodes = operationTemplateService.getOperationTemplateCodesByDeviceTypeAndSubTypeId(TestUtils.deviceType, TestUtils.subtypeId); + Set operationCodes = operationTemplateService.getOperationTemplateCodes(TestUtils.deviceType, TestUtils.subtypeId); Assert.assertNotNull(operationCodes, "Cannot be null"); } @Test(dependsOnMethods = "testAddOperationTemplate") public void testGetAllOperationTemplatesByDeviceType() throws OperationTemplateMgtPluginException { - List operationTemplates = operationTemplateService.getAllOperationTemplatesByDeviceType(TestUtils.deviceType); + List operationTemplates = operationTemplateService.getAllOperationTemplates(TestUtils.deviceType); Assert.assertNotNull(operationTemplates, "Cannot be null"); Assert.assertFalse(operationTemplates.isEmpty(), "operationTemplates is empty"); } @@ -108,7 +108,7 @@ public class ServiceTest extends BaseOperationTemplatePluginTest { @Test(dependsOnMethods = {"testAddOperationTemplate", "testGetOperationTemplate", "testUpdateOperationTemplate", "testGetOperationTemplateCodesByDeviceTypeAndSubTypeId", "testGetAllOperationTemplatesByDeviceType"}) public void testDeleteOperationTemplate() throws OperationTemplateMgtPluginException { - operationTemplateService.deleteOperationTemplateByDeviceTypeAndSubTypeIdAndOperationCode(TestUtils.deviceType, TestUtils.subtypeId, TestUtils.operationCode); + operationTemplateService.deleteOperationTemplate(TestUtils.deviceType, TestUtils.subtypeId, TestUtils.operationCode); Assert.assertNull(getOperationTemplateBySubtypeIdAndDeviceTypeAndOperationCode(TestUtils.deviceType, TestUtils.subtypeId, TestUtils.operationCode)); } } -- 2.36.3 From a600c69fdb44fa62922ee7756ee0ccfd7bfef46b Mon Sep 17 00:00:00 2001 From: Thameera Date: Fri, 26 Jan 2024 08:03:44 +0530 Subject: [PATCH 3/3] Operation template codes implementation for subtypes --- .../mgt/dao/impl/DeviceSubTypeDAOImpl.java | 26 +- .../core/subtype/mgt/dao/util/DAOUtil.java | 36 +- .../core/subtype/mgt/dto/DeviceSubType.java | 19 +- .../mgt/core/subtype/mgt/ServiceTest.java | 15 + .../resources/carbon-home/dbscripts/h2.sql | 909 +++++++++++++++++- 5 files changed, 985 insertions(+), 20 deletions(-) diff --git a/components/subtype-mgt/io.entgra.device.mgt.core.subtype.mgt/src/main/java/io/entgra/device/mgt/core/subtype/mgt/dao/impl/DeviceSubTypeDAOImpl.java b/components/subtype-mgt/io.entgra.device.mgt.core.subtype.mgt/src/main/java/io/entgra/device/mgt/core/subtype/mgt/dao/impl/DeviceSubTypeDAOImpl.java index ecfc1fbcc4..6cc2c7cac7 100644 --- a/components/subtype-mgt/io.entgra.device.mgt.core.subtype.mgt/src/main/java/io/entgra/device/mgt/core/subtype/mgt/dao/impl/DeviceSubTypeDAOImpl.java +++ b/components/subtype-mgt/io.entgra.device.mgt.core.subtype.mgt/src/main/java/io/entgra/device/mgt/core/subtype/mgt/dao/impl/DeviceSubTypeDAOImpl.java @@ -18,12 +18,12 @@ package io.entgra.device.mgt.core.subtype.mgt.dao.impl; -import io.entgra.device.mgt.core.subtype.mgt.exception.DBConnectionException; -import io.entgra.device.mgt.core.subtype.mgt.exception.SubTypeMgtDAOException; import io.entgra.device.mgt.core.subtype.mgt.dao.DeviceSubTypeDAO; import io.entgra.device.mgt.core.subtype.mgt.dao.util.ConnectionManagerUtil; -import io.entgra.device.mgt.core.subtype.mgt.dto.DeviceSubType; import io.entgra.device.mgt.core.subtype.mgt.dao.util.DAOUtil; +import io.entgra.device.mgt.core.subtype.mgt.dto.DeviceSubType; +import io.entgra.device.mgt.core.subtype.mgt.exception.DBConnectionException; +import io.entgra.device.mgt.core.subtype.mgt.exception.SubTypeMgtDAOException; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -101,7 +101,9 @@ public class DeviceSubTypeDAOImpl implements DeviceSubTypeDAO { public DeviceSubType getDeviceSubType(String subTypeId, int tenantId, String deviceType) throws SubTypeMgtDAOException { try { - String sql = "SELECT * FROM DM_DEVICE_SUB_TYPE WHERE SUB_TYPE_ID = ? AND TENANT_ID = ? AND DEVICE_TYPE = ?"; + String sql = "SELECT s.*, o.OPERATION_CODE FROM DM_DEVICE_SUB_TYPE s " + + "LEFT JOIN SUB_OPERATION_TEMPLATE o on s.SUB_TYPE_ID = o.SUB_TYPE_ID " + + "WHERE s.SUB_TYPE_ID = ? AND s.TENANT_ID = ? AND s.DEVICE_TYPE = ?"; Connection conn = ConnectionManagerUtil.getDBConnection(); try (PreparedStatement stmt = conn.prepareStatement(sql)) { @@ -109,10 +111,8 @@ public class DeviceSubTypeDAOImpl implements DeviceSubTypeDAO { stmt.setInt(2, tenantId); stmt.setString(3, deviceType); try (ResultSet rs = stmt.executeQuery()) { - if (rs.next()) { - return DAOUtil.loadDeviceSubType(rs); - } - return null; + List deviceSubTypes = DAOUtil.loadDeviceSubTypes(rs); + return (deviceSubTypes != null && !deviceSubTypes.isEmpty()) ? deviceSubTypes.get(0) : null; } } @@ -133,18 +133,20 @@ public class DeviceSubTypeDAOImpl implements DeviceSubTypeDAO { public List getAllDeviceSubTypes(int tenantId, String deviceType) throws SubTypeMgtDAOException { try { - String sql = "SELECT * FROM DM_DEVICE_SUB_TYPE WHERE TENANT_ID = ? AND DEVICE_TYPE = ? ORDER BY " + - "SUB_TYPE_ID"; + String sql = "SELECT s.*, o.OPERATION_CODE FROM DM_DEVICE_SUB_TYPE s " + + "LEFT JOIN SUB_OPERATION_TEMPLATE o on s.SUB_TYPE_ID = o.SUB_TYPE_ID AND s.DEVICE_TYPE = o.DEVICE_TYPE " + + "WHERE s.TENANT_ID = ? AND s.DEVICE_TYPE = ? ORDER BY " + + "s.SUB_TYPE_ID"; Connection conn = ConnectionManagerUtil.getDBConnection(); try (PreparedStatement stmt = conn.prepareStatement(sql)) { stmt.setInt(1, tenantId); stmt.setString(2, deviceType); try (ResultSet rs = stmt.executeQuery()) { - return DAOUtil.loadDeviceSubTypes(rs); + List deviceSubTypes = DAOUtil.loadDeviceSubTypes(rs); + return deviceSubTypes; } } - } catch (DBConnectionException e) { String msg = "Error occurred while obtaining DB connection to retrieve all device sub types for " + deviceType + " subtypes"; diff --git a/components/subtype-mgt/io.entgra.device.mgt.core.subtype.mgt/src/main/java/io/entgra/device/mgt/core/subtype/mgt/dao/util/DAOUtil.java b/components/subtype-mgt/io.entgra.device.mgt.core.subtype.mgt/src/main/java/io/entgra/device/mgt/core/subtype/mgt/dao/util/DAOUtil.java index 34e108a4a6..f4569c6c36 100644 --- a/components/subtype-mgt/io.entgra.device.mgt.core.subtype.mgt/src/main/java/io/entgra/device/mgt/core/subtype/mgt/dao/util/DAOUtil.java +++ b/components/subtype-mgt/io.entgra.device.mgt.core.subtype.mgt/src/main/java/io/entgra/device/mgt/core/subtype/mgt/dao/util/DAOUtil.java @@ -20,11 +20,12 @@ package io.entgra.device.mgt.core.subtype.mgt.dao.util; import com.fasterxml.jackson.core.JsonProcessingException; import io.entgra.device.mgt.core.subtype.mgt.dto.DeviceSubType; - import java.sql.ResultSet; import java.sql.SQLException; import java.util.ArrayList; +import java.util.LinkedHashMap; import java.util.List; +import java.util.Map; public class DAOUtil { @@ -49,10 +50,35 @@ public class DAOUtil { } public static List loadDeviceSubTypes(ResultSet rs) throws SQLException { - List deviceSubTypes = new ArrayList<>(); - while (rs.next()) { - deviceSubTypes.add(loadDeviceSubType(rs)); + try { + Map deviceSubTypes = new LinkedHashMap<>(); + DeviceSubType deviceSubType = new DeviceSubType() { + @Override + public DeviceSubType convertToDeviceSubType() { + return null; + } + + @Override + public String parseSubTypeToJson() throws JsonProcessingException { + return null; + } + }; + while (rs.next()) { + String currentSubTypeId = rs.getString("SUB_TYPE_ID"); + String deviceType = rs.getString("DEVICE_TYPE"); + String operationCode = rs.getString("OPERATION_CODE"); + String key = deviceType + "|" + currentSubTypeId; + if (!deviceSubTypes.containsKey(key)) { + deviceSubType = loadDeviceSubType(rs); + } + if (operationCode != null) { + deviceSubType.addOperationCode(operationCode); + } + deviceSubTypes.put(key, deviceSubType); + } + return new ArrayList<>(deviceSubTypes.values()); + } catch (Exception e) { + return null; } - return deviceSubTypes; } } diff --git a/components/subtype-mgt/io.entgra.device.mgt.core.subtype.mgt/src/main/java/io/entgra/device/mgt/core/subtype/mgt/dto/DeviceSubType.java b/components/subtype-mgt/io.entgra.device.mgt.core.subtype.mgt/src/main/java/io/entgra/device/mgt/core/subtype/mgt/dto/DeviceSubType.java index 84eaa124c6..cc27bb592e 100644 --- a/components/subtype-mgt/io.entgra.device.mgt.core.subtype.mgt/src/main/java/io/entgra/device/mgt/core/subtype/mgt/dto/DeviceSubType.java +++ b/components/subtype-mgt/io.entgra.device.mgt.core.subtype.mgt/src/main/java/io/entgra/device/mgt/core/subtype/mgt/dto/DeviceSubType.java @@ -21,6 +21,9 @@ package io.entgra.device.mgt.core.subtype.mgt.dto; import com.fasterxml.jackson.core.JsonProcessingException; +import java.util.HashSet; +import java.util.Set; + public abstract class DeviceSubType { @@ -29,16 +32,22 @@ public abstract class DeviceSubType { private String deviceType; private String subTypeName; private String typeDefinition; - + private Set operationCodes = new HashSet<>(); public DeviceSubType() { } - public DeviceSubType(String subTypeId, int tenantId, String deviceType, String subTypeName, String typeDefinition) { + public DeviceSubType(String subTypeId, int tenantId, String deviceType, String subTypeName, String typeDefinition, + Set operationCodes) { this.subTypeId = subTypeId; this.tenantId = tenantId; this.deviceType = deviceType; this.subTypeName = subTypeName; this.typeDefinition = typeDefinition; + if (operationCodes != null || !operationCodes.isEmpty()) { + this.operationCodes.addAll(operationCodes); + } + + } public String getSubTypeId() { @@ -85,4 +94,10 @@ public abstract class DeviceSubType { public abstract String parseSubTypeToJson() throws JsonProcessingException; + public void addOperationCode(String code) { + operationCodes.add(code); + } + public Set getOperationCodes() { + return operationCodes; + } } diff --git a/components/subtype-mgt/io.entgra.device.mgt.core.subtype.mgt/src/test/java/io/entgra/device/mgt/core/subtype/mgt/ServiceTest.java b/components/subtype-mgt/io.entgra.device.mgt.core.subtype.mgt/src/test/java/io/entgra/device/mgt/core/subtype/mgt/ServiceTest.java index 8d800a2c69..a11d7a42d3 100644 --- a/components/subtype-mgt/io.entgra.device.mgt.core.subtype.mgt/src/test/java/io/entgra/device/mgt/core/subtype/mgt/ServiceTest.java +++ b/components/subtype-mgt/io.entgra.device.mgt.core.subtype.mgt/src/test/java/io/entgra/device/mgt/core/subtype/mgt/ServiceTest.java @@ -125,4 +125,19 @@ public class ServiceTest extends BaseDeviceSubTypePluginTest { int subTypeCount = deviceSubTypeService.getDeviceSubTypeCount(deviceType); log.info(deviceType + " Device subtypes count: " + subTypeCount); } + + @Test + public void testGetMeterDeviceType() throws SubTypeMgtPluginException { + int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(); + DeviceSubType subTypeActual = deviceSubTypeService.getDeviceSubType("7", tenantId, + "METER"); + Assert.assertNotNull(subTypeActual); + } + + @Test + public void testGetAllMeterDeviceTypes() throws SubTypeMgtPluginException { + int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(); + List subTypeActual = deviceSubTypeService.getAllDeviceSubTypes(tenantId, "METER"); + Assert.assertNotNull(subTypeActual); + } } diff --git a/components/subtype-mgt/io.entgra.device.mgt.core.subtype.mgt/src/test/resources/carbon-home/dbscripts/h2.sql b/components/subtype-mgt/io.entgra.device.mgt.core.subtype.mgt/src/test/resources/carbon-home/dbscripts/h2.sql index f77830c7ed..f3f22f381c 100644 --- a/components/subtype-mgt/io.entgra.device.mgt.core.subtype.mgt/src/test/resources/carbon-home/dbscripts/h2.sql +++ b/components/subtype-mgt/io.entgra.device.mgt.core.subtype.mgt/src/test/resources/carbon-home/dbscripts/h2.sql @@ -26,7 +26,19 @@ `TYPE_DEFINITION` TEXT NOT NULL, PRIMARY KEY (`SUB_TYPE_ID`,`DEVICE_TYPE`) ); - +-- 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) +); -- ----------------------------------------------------- -- Sample data for test cases -- ----------------------------------------------------- @@ -35,3 +47,898 @@ INSERT INTO DM_DEVICE_SUB_TYPE (SUB_TYPE_ID, TENANT_ID, DEVICE_TYPE, SUB_TYPE_NA (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}'); +INSERT INTO DM_DEVICE_SUB_TYPE (SUB_TYPE_ID, TENANT_ID, DEVICE_TYPE, SUB_TYPE_NAME, TYPE_DEFINITION) VALUES ( +'5', -1234, 'METER','Microstar - IEC Bulk', +'{ + "compatibleComModules": { + "4": { + "subTypeId": 4, + "make": "Microstar", + "model": "IEC-GSM", + "socketServerPort": 5258, + "hasICMPSupport": true, + "hasSMSSupport": false, + "hasNMDSupport":false, + "tenantId": -1234 + } + }, + "compatibleComModulesIds": [4], + "supportedOperations": [ + "BILLING_REGISTERS_RETRIEVE", + "TIME_SYNC", + "SELF_TEST", + "LOAD_PROFILE_RETRIEVE" + ], + "defaultRegisters": { + "METER_ID": "1-0:0.0.0()", + "METER_FW_VER": "1-0:0.2.0()", + "TIME": "1-0:0.9.1()", + "DATE": "1-0:0.9.2()" + }, + "userClientMapping": { + "0": 0, + "1": 1, + "2": 2 + }, + "make": "MicroStar", + "model": "IEC Bulk", + "serverAddress": 0, + "defaultClientAddress": 0, + "registerMapping": { + "0.0.0_0": { + "obis": "1-0:0.0.0()", + "attributeIndex": -1, + "classId": -1 + }, + "LP_71.7.0": { + "obis": "1-1:71.7.0", + "attributeIndex": -1, + "classId": -1, + "scalingOption": "CUSTOM", + "scalar": 1000.0 + }, + "LP": { + "obis": "P.01", + "attributeIndex": -1, + "classId": -1, + "isProfileRegister": true + }, + "LP_3.8.0": { + "obis": "1-1:3.8.0", + "attributeIndex": -1, + "classId": -1 + }, + "LP_63.7.0": { + "obis": "1-1:73.7.0", + "attributeIndex": -1, + "classId": -1 + }, + "1.8.2_0": { + "obis": "1-1:1.8.2()", + "attributeIndex": -1, + "classId": -1 + }, + "2.8.0*01_0": { + "obis": "1-1:2.8.0*1()", + "attributeIndex": -1, + "classId": -1 + }, + "1.8.2*01_0": { + "obis": "1-1:1.8.2*1()", + "attributeIndex": -1, + "classId": -1 + }, + "LP_72.7.0": { + "obis": "1-1:72.7.0", + "attributeIndex": -1, + "classId": -1, + "scalingOption": "CUSTOM", + "scalar": 1000.0 + }, + "2.8.1_0": { + "obis": "1-1:2.8.1()", + "attributeIndex": -1, + "classId": -1 + }, + "0.9.2_0": { + "obis": "1-0:0.9.2()", + "attributeIndex": -1, + "classId": -1 + }, + "31.7.0_0": { + "obis": "1-1:31.7.0()", + "attributeIndex": -1, + "classId": -1 + }, + "2.8.3_0": { + "obis": "1-1:2.8.3()", + "attributeIndex": -1, + "classId": -1 + }, + "51.7.0_0": { + "obis": "1-1:51.7.0()", + "attributeIndex": -1, + "classId": -1 + }, + "1.8.0_0": { + "obis": "1-1:1.8.0()", + "attributeIndex": -1, + "classId": -1 + }, + "10.6.0*01_0": { + "obis": "1-1:10.6.0*1()", + "attributeIndex": -1, + "classId": -1 + }, + "71.7.0_0": { + "obis": "1-1:71.7.0()", + "attributeIndex": -1, + "classId": -1 + }, + "2.8.2*01_0": { + "obis": "1-1:2.8.2*1()", + "attributeIndex": -1, + "classId": -1 + }, + "72.7.0_0": { + "obis": "1-1:72.7.0()", + "attributeIndex": -1, + "classId": -1 + }, + "LP_9.5.0": { + "obis": "1-1:9.4.0", + "attributeIndex": -1, + "classId": -1 + }, + "52.7.0_0": { + "obis": "1-1:52.7.0()", + "attributeIndex": -1, + "classId": -1 + }, + "LP_13.7.0": { + "obis": "1-1:13.7.0", + "attributeIndex": -1, + "classId": -1 + }, + "LP_31.7.0": { + "obis": "1-1:31.7.0", + "attributeIndex": -1, + "classId": -1, + "scalingOption": "CUSTOM", + "scalar": 1000.0 + }, + "0.4.3_0": { + "obis": "1-0:0.4.3()", + "attributeIndex": -1, + "classId": -1 + }, + "0.4.5_0": { + "obis": "1-0:0.4.5()", + "attributeIndex": -1, + "classId": -1 + }, + "1.8.3*01_0": { + "obis": "1-1:1.8.3*1()", + "attributeIndex": -1, + "classId": -1 + }, + "32.7.0_0": { + "obis": "1-1:32.7.0()", + "attributeIndex": -1, + "classId": -1 + }, + "1.8.0*01_0": { + "obis": "1-1:1.8.0*1()", + "attributeIndex": -1, + "classId": -1 + }, + "LP_32.7.0": { + "obis": "1-1:32.7.0", + "attributeIndex": -1, + "classId": -1, + "scalingOption": "CUSTOM", + "scalar": 1000.0 + }, + "LP_2.5.0": { + "obis": "1-1:2.4.0", + "attributeIndex": -1, + "classId": -1 + }, + "10.6.0_0": { + "obis": "1-1:10.6.0()", + "attributeIndex": -1, + "classId": -1 + }, + "2.8.3*01_0": { + "obis": "1-1:2.8.3*1()", + "attributeIndex": -1, + "classId": -1 + }, + "1.8.3_0": { + "obis": "1-1:1.8.3()", + "attributeIndex": -1, + "classId": -1 + }, + "LP_33.7.0": { + "obis": "1-1:33.7.0", + "attributeIndex": -1, + "classId": -1 + }, + "0.9.1_0": { + "obis": "1-0:0.9.1()", + "attributeIndex": -1, + "classId": -1 + }, + "2.8.0_0": { + "obis": "1-1:2.8.0()", + "attributeIndex": -1, + "classId": -1 + }, + "LP_1.5.0": { + "obis": "1-1:1.4.0", + "attributeIndex": -1, + "classId": -1 + }, + "2.8.2_0": { + "obis": "1-1:2.8.2()", + "attributeIndex": -1, + "classId": -1 + }, + "1.8.1_0": { + "obis": "1-1:1.8.1()", + "attributeIndex": -1, + "classId": -1 + }, + "LP_51.7.0": { + "obis": "1-1:51.7.0", + "attributeIndex": -1, + "classId": -1, + "scalingOption": "CUSTOM", + "scalar": 1000.0 + }, + "LP_43.7.0": { + "obis": "1-1:53.7.0", + "attributeIndex": -1, + "classId": -1 + }, + "1.8.1*01_0": { + "obis": "1-1:1.8.1*1()", + "attributeIndex": -1, + "classId": -1 + }, + "9.6.0_0": { + "obis": "1-1:9.6.0()", + "attributeIndex": -1, + "classId": -1 + }, + "LP_52.7.0": { + "obis": "1-1:52.7.0", + "attributeIndex": -1, + "classId": -1, + "scalingOption": "CUSTOM", + "scalar": 1000.0 + }, + "14.7.0_0": { + "obis": "1-1:14.7.0()", + "attributeIndex": -1, + "classId": -1 + }, + "9.6.0*01_0": { + "obis": "1-1:9.6.0*1()", + "attributeIndex": -1, + "classId": -1 + }, + "LP_1.8.0": { + "obis": "1-1:1.8.0", + "attributeIndex": -1, + "classId": -1 + }, + "0.4.6_0": { + "obis": "1-0:0.4.6()", + "attributeIndex": -1, + "classId": -1 + }, + "2.8.1*01_0": { + "obis": "1-1:2.8.1*1()", + "attributeIndex": -1, + "classId": -1 + }, + "LP_10.5.0": { + "obis": "1-1:10.4.0", + "attributeIndex": -1, + "classId": -1 + }, + "0.4.2_0": { + "obis": "1-0:0.4.2()", + "attributeIndex": -1, + "classId": -1 + }, + "LP_15.4.0": { + "obis": "1-1:15.4.0", + "attributeIndex": -1, + "classId": -1 + }, + "FW_VER": { + "obis": "1-0:0.2.0()", + "attributeIndex": -1, + "classId": -1 + }, + "LP_2.8.0": { + "obis": "1-1:2.8.0", + "attributeIndex": -1, + "classId": -1 + } + }, + "transportProtocol": "IEC", + "defaultComModuleId": 4, + "defaultComModule": { + "subTypeId": 4, + "make": "Microstar", + "model": "IEC-GSM", + "socketServerPort": 5258, + "hasICMPSupport": true, + "hasSMSSupport": false, + "hasNMDSupport":false, + "tenantId": -1234 + } + }' +); + +INSERT INTO DM_DEVICE_SUB_TYPE (SUB_TYPE_ID, TENANT_ID, DEVICE_TYPE, SUB_TYPE_NAME, TYPE_DEFINITION) VALUES ( +'6', -1234, 'METER', 'Anteleco - IEC 3Phase', +'{ + "compatibleComModules": { + "1": { + "subTypeId": 1, + "make": "AnteLeco", + "model": "ATx-Mega SIM800", + "socketServerPort": 8071, + "hasICMPSupport": true, + "hasSMSSupport": true, + "hasNMDSupport":false, + "tenantId": -1234 + }, + "8": { + "subTypeId": 8, + "make": "AnteLeco", + "model": "NB-IoT B", + "socketServerPort": 8071, + "hasICMPSupport": true, + "hasSMSSupport": true, + "hasNMDSupport":false, + "tenantId": -1234 + }, + "10": { + "subTypeId": 10, + "make": "AnteLeco", + "model": "ATx-Mega SIM800 B", + "socketServerPort": 8071, + "hasICMPSupport": true, + "hasSMSSupport": true, + "hasNMDSupport":false, + "tenantId": -1234 + } + }, + "compatibleComModulesIds": [1,8,10], + "supportedOperations": [ + "BILLING_REGISTERS_RETRIEVE", + "REMOTE_RELAY_ON", + "REMOTE_RELAY_OFF", + "TIME_SYNC", + "SELF_TEST", + "LOAD_PROFILE_RETRIEVE" + ], + "defaultRegisters": { + "METER_ID": "0.0.96.1.0.255()", + "METER_FW_VER": "1.0.0.2.0.255()", + "TIME": "1.0.0.9.1()", + "DATE": "1.0.0.9.2()" + }, + "userClientMapping": { + "0": 0, + "1": 1, + "2": 2 + }, + "make": "Anteleco", + "model": "IEC 3Phase", + "serverAddress": 0, + "defaultClientAddress": 0, + "registerMapping": { + "0.0.0_0": { + "obis": "0.0.96.1.0.255()", + "attributeIndex": -1, + "classId": -1 + }, + "LP_71.7.0": { + "obis": "71.7", + "attributeIndex": -1, + "classId": -1 + }, + "LP": { + "obis": "P.01", + "attributeIndex": -1, + "classId": -1, + "isProfileRegister": true + }, + "CSRQ_RL": { + "obis": "0.0.96.128.1.0()", + "attributeIndex": -1, + "classId": -1 + }, + "LP_3.8.0": { + "obis": "3.8", + "attributeIndex": -1, + "classId": -1 + }, + "2.8.3*01_0": { + "obis": "1.0.2.8.3.1()", + "attributeIndex": -1, + "classId": -1 + }, + "1.8.3_0": { + "obis": "1.0.1.8.3.255()", + "attributeIndex": -1, + "classId": -1 + }, + "LP_63.7.0": { + "obis": "63.5", + "attributeIndex": -1, + "classId": -1 + }, + "1.8.2_0": { + "obis": "1.0.1.8.2.255()", + "attributeIndex": -1, + "classId": -1 + }, + "LP_33.7.0": { + "obis": "33.5", + "attributeIndex": -1, + "classId": -1 + }, + "0.9.1_0": { + "obis": "1.0.0.9.1()", + "attributeIndex": -1, + "classId": -1 + }, + "2.8.0*01_0": { + "obis": "1.0.2.8.0.1()", + "attributeIndex": -1, + "classId": -1 + }, + "2.8.0_0": { + "obis": "1.0.2.8.0.255()", + "attributeIndex": -1, + "classId": -1 + }, + "1.8.2*01_0": { + "obis": "1.0.1.8.2.1()", + "attributeIndex": -1, + "classId": -1 + }, + "LP_72.7.0": { + "obis": "72.7", + "attributeIndex": -1, + "classId": -1 + }, + "LP_1.5.0": { + "obis": "1.5", + "attributeIndex": -1, + "classId": -1 + }, + "2.8.2_0": { + "obis": "1.0.2.8.2.255()", + "attributeIndex": -1, + "classId": -1 + }, + "2.8.1_0": { + "obis": "1.0.2.8.1.255()", + "attributeIndex": -1, + "classId": -1 + }, + "0.9.2_0": { + "obis": "1.0.0.9.2()", + "attributeIndex": -1, + "classId": -1 + }, + "31.7.0_0": { + "obis": "1.0.31.7.0.255()", + "attributeIndex": -1, + "classId": -1 + }, + "2.8.3_0": { + "obis": "1.0.2.8.3.255()", + "attributeIndex": -1, + "classId": -1 + }, + "51.7.0_0": { + "obis": "1.0.51.7.0.255()", + "attributeIndex": -1, + "classId": -1 + }, + "1.8.1_0": { + "obis": "1.0.1.8.1.255()", + "attributeIndex": -1, + "classId": -1 + }, + "1.8.0_0": { + "obis": "1.0.1.8.0.255()", + "attributeIndex": -1, + "classId": -1 + }, + "LP_51.7.0": { + "obis": "51.7", + "attributeIndex": -1, + "classId": -1 + }, + "LP_43.7.0": { + "obis": "43.5", + "attributeIndex": -1, + "classId": -1 + }, + "71.7.0_0": { + "obis": "1.0.71.7.0.255()", + "attributeIndex": -1, + "classId": -1 + }, + "LP_4.8.0": { + "obis": "4.8", + "attributeIndex": -1, + "classId": -1 + }, + "1.8.1*01_0": { + "obis": "1.0.1.8.1.1()", + "attributeIndex": -1, + "classId": -1 + }, + "2.8.2*01_0": { + "obis": "1.0.2.8.2.1()", + "attributeIndex": -1, + "classId": -1 + }, + "72.7.0_0": { + "obis": "1.0.72.7.0.255()", + "attributeIndex": -1, + "classId": -1 + }, + "LP_52.7.0": { + "obis": "52.7", + "attributeIndex": -1, + "classId": -1 + }, + "14.7.0_0": { + "obis": "1.0.14.7.0.255()", + "attributeIndex": -1, + "classId": -1 + }, + "LP_9.5.0": { + "obis": "9.5", + "attributeIndex": -1, + "classId": -1 + }, + "LP_13.5.0": { + "obis": "13.5", + "attributeIndex": -1, + "classId": -1 + }, + "52.7.0_0": { + "obis": "1.0.52.7.0.255()", + "attributeIndex": -1, + "classId": -1 + }, + "LP_31.7.0": { + "obis": "31.7", + "attributeIndex": -1, + "classId": -1 + }, + "LP_1.8.0": { + "obis": "1.8", + "attributeIndex": -1, + "classId": -1 + }, + "1.8.3*01_0": { + "obis": "1.0.1.8.3.1()", + "attributeIndex": -1, + "classId": -1 + }, + "32.7.0_0": { + "obis": "1.0.32.7.0.255()", + "attributeIndex": -1, + "classId": -1 + }, + "1.8.0*01_0": { + "obis": "1.0.1.8.0.1()", + "attributeIndex": -1, + "classId": -1 + }, + "2.8.1*01_0": { + "obis": "1.0.2.8.1.1()", + "attributeIndex": -1, + "classId": -1 + }, + "LP_10.5.0": { + "obis": "10.5", + "attributeIndex": -1, + "classId": -1 + }, + "LP_32.7.0": { + "obis": "32.7", + "attributeIndex": -1, + "classId": -1 + }, + "FW_VER": { + "obis": "1.0.0.2.0.255()", + "attributeIndex": -1, + "classId": -1 + }, + "LP_2.8.0": { + "obis": "2.8", + "attributeIndex": -1, + "classId": -1 + }, + "LP_2.5.0": { + "obis": "2.5", + "attributeIndex": -1, + "classId": -1 + } + }, + "transportProtocol": "IEC", + "defaultComModuleId": 10, + "defaultComModule": { + "subTypeId": 10, + "make": "AnteLeco", + "model": "ATx-Mega SIM800 B", + "socketServerPort": 8071, + "hasICMPSupport": true, + "hasSMSSupport": true, + "hasNMDSupport":false, + "tenantId": -1234 + } + }' +); + +INSERT INTO DM_DEVICE_SUB_TYPE (SUB_TYPE_ID, TENANT_ID, DEVICE_TYPE, SUB_TYPE_NAME, TYPE_DEFINITION) VALUES ( +'7', -1234, 'METER', 'Anteleco - NMD', +'{ + "compatibleComModules": { + "5": { + "subTypeId": 5, + "make": "AnteLeco", + "model": "STM32 M65-NMD", + "socketServerPort": 8071, + "hasICMPSupport": true, + "hasSMSSupport": true, + "hasNMDSupport":true, + "tenantId": -1234 + }, + "9": { + "subTypeId": 9, + "make": "AnteLeco", + "model": "NB-IoT NMD", + "socketServerPort": 8071, + "hasICMPSupport": true, + "hasSMSSupport": true, + "hasNMDSupport":true, + "tenantId": -1234 + } + }, + "compatibleComModulesIds": [5,9], + "supportedOperations": [ + "BILLING_REGISTERS_RETRIEVE", + "STATUS_RETRIEVE", + "TIME_SYNC", + "SELF_TEST", + "LOAD_PROFILE_RETRIEVE" + ], + "defaultRegisters": { + "METER_ID": "0.0.96.1.0.255", + "METER_FW_VER": "1.0.0.2.0.255", + "CLOCK": "0.0.1.0.0.255" + }, + "userClientMapping": { + "1": 2, + "2": 3, + "3": 4 + }, + "make": "Anteleco", + "model": "NMD", + "serverAddress": 1, + "defaultClientAddress": 16, + "registerMapping": { + "CO_128.0.12": { + "obis": "1.0.128.0.12.255", + "attributeIndex": 2, + "classId": 1 + }, + "0.0.0_0": { + "obis": "0.0.96.1.0.255", + "attributeIndex": 2, + "classId": 1 + }, + "CO_128.0.11": { + "obis": "1.0.128.0.11.255", + "attributeIndex": 2, + "classId": 1 + }, + "CO_128.32.0": { + "obis": "1.0.128.32.0.255", + "attributeIndex": 2, + "classId": 1 + }, + "LP": { + "obis": "1.0.99.1.1.255", + "attributeIndex": 2, + "classId": 7, + "isProfileRegister": true + }, + "CO_128.36.0": { + "obis": "1.0.128.36.0.255", + "attributeIndex": 2, + "classId": 1 + }, + "CO_52.7.0": { + "obis": "1.0.52.7.0.255", + "attributeIndex": 2, + "classId": 3 + }, + "CO_96.50.22": { + "obis": "0.0.96.50.22.255", + "attributeIndex": 2, + "classId": 8 + }, + "CO_12.26.0": { + "obis": "1.0.12.26.0.255", + "attributeIndex": 2, + "classId": 3 + }, + "CO_96.50.21": { + "obis": "0.0.96.50.21.255", + "attributeIndex": 2, + "classId": 8 + }, + "0.9.0_0": { + "obis": "0.0.1.0.0.255", + "attributeIndex": 2, + "classId": 8 + }, + "C3DE": { + "obis": "0.0.99.98.10.255", + "attributeIndex": 2, + "classId": 7, + "isProfileRegister": true + }, + "CO_128.0.10": { + "obis": "1.0.128.0.10.255", + "attributeIndex": 2, + "classId": 3 + }, + "C2DE": { + "obis": "0.0.99.98.9.255", + "attributeIndex": 2, + "classId": 7, + "isProfileRegister": true + }, + "C1DE": { + "obis": "0.0.99.98.8.255", + "attributeIndex": 2, + "classId": 7, + "isProfileRegister": true + }, + "CO_0.9.0_0": { + "obis": "0.0.1.0.0.255", + "attributeIndex": 2, + "classId": 8 + }, + "CO_72.128.0": { + "obis": "1.0.72.128.0.255", + "attributeIndex": 2, + "classId": 3 + }, + "CO_52.128.0": { + "obis": "1.0.52.128.0.255", + "attributeIndex": 2, + "classId": 3 + }, + "CO_32.128.0": { + "obis": "1.0.32.128.0.255", + "attributeIndex": 2, + "classId": 3 + }, + "CO_72.7.0": { + "obis": "1.0.72.7.0.255", + "attributeIndex": 2, + "classId": 3 + }, + "CO_128.40.0": { + "obis": "1.0.128.40.0.255", + "attributeIndex": 2, + "classId": 1 + }, + "72.7.0_0": { + "obis": "1.0.72.7.0.255", + "attributeIndex": 2, + "classId": 3 + }, + "14.7.0_0": { + "obis": "1.0.14.7.0.255", + "attributeIndex": 2, + "classId": 3 + }, + "52.7.0_0": { + "obis": "1.0.52.7.0.255", + "attributeIndex": 2, + "classId": 3 + }, + "CO_32.7.0": { + "obis": "1.0.32.7.0.255", + "attributeIndex": 2, + "classId": 3 + }, + "32.7.0_0": { + "obis": "1.0.32.7.0.255", + "attributeIndex": 2, + "classId": 3 + }, + "CO_12.23.0": { + "obis": "1.0.12.23.0.255", + "attributeIndex": 2, + "classId": 3 + }, + "PFEL": { + "obis": "1.0.99.97.0.255", + "attributeIndex": 2, + "classId": 7, + "isProfileRegister": true + }, + "FW_VER": { + "obis": "1.0.0.2.0.255", + "attributeIndex": 2, + "classId": 1 + }, + "96.6.0_0": { + "obis": "0.0.96.6.0.255", + "attributeIndex": 2, + "classId": 3 + }, + "96.6.3_0": { + "obis": "0.0.96.6.3.255", + "attributeIndex": 2, + "classId": 3 + }, + "96.6.3_1": { + "obis": "0.1.96.6.3.255", + "attributeIndex": 2, + "classId": 3 + } + }, + "transportProtocol": "DLMS", + "defaultComModuleId": 5, + "defaultComModule": { + "subTypeId": 5, + "make": "AnteLeco", + "model": "STM32 M65-NMD", + "socketServerPort": 8071, + "hasICMPSupport": true, + "hasSMSSupport": true, + "hasNMDSupport":true, + "tenantId": -1234 + } + }' +); + +INSERT INTO SUB_OPERATION_TEMPLATE(OPERATION_DEFINITION,OPERATION_CODE,SUB_TYPE_ID,DEVICE_TYPE,CREATE_TIMESTAMP,UPDATE_TIMESTAMP) VALUES('{"subTypeId":"5","deviceType":"METER","code":"BILLING_REGISTERS_RETRIEVE","type":"PROFILE","control":"NO_REPEAT","maxAttempts":1,"waitingTime":0,"isEnabled":true,"properties":{"requireDateValidation":"3600000","requireAuthentication":"0"},"transportMode":"NET_ONLY","registerTransactions":[],"registers":["0.0.0_0","0.9.1_0","0.9.2_0","1.8.0_0","1.8.1_0","1.8.2_0","1.8.3_0","2.8.0_0","2.8.1_0","2.8.2_0","2.8.3_0","1.8.0*01_0","1.8.1*01_0","1.8.2*01_0","1.8.3*01_0","2.8.0*01_0","2.8.1*01_0","2.8.2*01_0","2.8.3*01_0","9.6.0_0","9.6.0*01_0","10.6.0_0","10.6.0*01_0","0.4.2_0","0.4.3_0","0.4.5_0","0.4.6_0","14.7.0_0","31.7.0_0","32.7.0_0","51.7.0_0","52.7.0_0","71.7.0_0","72.7.0_0"]}','BILLING_REGISTERS_RETRIEVE',5,'METER',CURRENT_TIMESTAMP(),CURRENT_TIMESTAMP()); + +INSERT INTO SUB_OPERATION_TEMPLATE(OPERATION_DEFINITION,OPERATION_CODE,SUB_TYPE_ID,DEVICE_TYPE,CREATE_TIMESTAMP,UPDATE_TIMESTAMP) VALUES('{"subTypeId":"5","deviceType":"METER","code":"LOAD_PROFILE_RETRIEVE","type":"PROFILE","control":"NO_REPEAT","maxAttempts":1,"waitingTime":0,"isEnabled":true,"properties":{"requireDateValidation":"3600000","requireAuthentication":"0"},"transportMode":"NET_ONLY","registerTransactions":[],"registers":["LP"]}','LOAD_PROFILE_RETRIEVE',5,'METER',CURRENT_TIMESTAMP(),CURRENT_TIMESTAMP()); + +INSERT INTO SUB_OPERATION_TEMPLATE(OPERATION_DEFINITION,OPERATION_CODE,SUB_TYPE_ID,DEVICE_TYPE,CREATE_TIMESTAMP,UPDATE_TIMESTAMP) VALUES('{"subTypeId":"5","deviceType":"METER","code":"TIME_SYNC","type":"PROFILE","control":"NO_REPEAT","maxAttempts":1,"waitingTime":0,"isEnabled":true,"properties":{"requireDateAdjust":"30000","requireAuthentication":"0"},"registerTransactions":[],"registers":["0.9.1_0","0.9.2_0"]}','TIME_SYNC',5,'METER',CURRENT_TIMESTAMP(),CURRENT_TIMESTAMP()); + +INSERT INTO SUB_OPERATION_TEMPLATE(OPERATION_DEFINITION,OPERATION_CODE,SUB_TYPE_ID,DEVICE_TYPE,CREATE_TIMESTAMP,UPDATE_TIMESTAMP) VALUES('{"subTypeId":"5","deviceType":"METER","code":"SELF_TEST","type":"PROFILE","control":"NO_REPEAT","maxAttempts":1,"waitingTime":0,"isEnabled":true,"properties":{"requireDateAdjust":"30000","requireAuthentication":"0"},"transportMode":"NET_ONLY","registerTransactions":[],"registers":["0.0.0_0","0.9.1_0","0.9.2_0","FW_VER","1.8.0_0","1.8.1_0","1.8.2_0","1.8.3_0","2.8.0_0","2.8.1_0","2.8.2_0","2.8.3_0","1.8.0*01_0","1.8.1*01_0","1.8.2*01_0","1.8.3*01_0","2.8.0*01_0","2.8.1*01_0","2.8.2*01_0","2.8.3*01_0","9.6.0_0","9.6.0*01_0","10.6.0_0","10.6.0*01_0","0.4.2_0","0.4.3_0","0.4.5_0","0.4.6_0","14.7.0_0","31.7.0_0","32.7.0_0","51.7.0_0","52.7.0_0","71.7.0_0","72.7.0_0"]}','SELF_TEST',5,'METER',CURRENT_TIMESTAMP(),CURRENT_TIMESTAMP()); + +INSERT INTO SUB_OPERATION_TEMPLATE(OPERATION_DEFINITION,OPERATION_CODE,SUB_TYPE_ID,DEVICE_TYPE,CREATE_TIMESTAMP,UPDATE_TIMESTAMP) VALUES('{"subTypeId":"6","deviceType":"METER","code":"REMOTE_RELAY_ON","type":"PROFILE","control":"NO_REPEAT","maxAttempts":1,"waitingTime":0,"isEnabled":true,"properties":{"requireAuthentication":"0"},"transportMode":"ALLOW_SMS_FALLBACK","registerTransactions":[{"globalRegName":"CSRQ_RL","remoteMethod":{"index":2,"data":"003()","type":"STRING"}}],"registers":["0.9.1_0","0.9.2_0","CSRQ_RL","1.8.0_0","1.8.1_0","1.8.2_0","1.8.3_0","2.8.0_0","2.8.1_0","2.8.2_0","2.8.3_0"]}','REMOTE_RELAY_ON',6,'METER',CURRENT_TIMESTAMP(),CURRENT_TIMESTAMP()); + +INSERT INTO SUB_OPERATION_TEMPLATE(OPERATION_DEFINITION,OPERATION_CODE,SUB_TYPE_ID,DEVICE_TYPE,CREATE_TIMESTAMP,UPDATE_TIMESTAMP) VALUES('{"subTypeId":"6","deviceType":"METER","code":"REMOTE_RELAY_OFF","type":"PROFILE","control":"NO_REPEAT","maxAttempts":1,"waitingTime":0,"isEnabled":true,"properties":{"requireAuthentication":"0"},"transportMode":"ALLOW_SMS_FALLBACK","registerTransactions":[{"globalRegName":"CSRQ_RL","remoteMethod":{"index":1,"data":"004()","type":"STRING"}}],"registers":["0.9.1_0","0.9.2_0","CSRQ_RL","1.8.0_0","1.8.1_0","1.8.2_0","1.8.3_0","2.8.0_0","2.8.1_0","2.8.2_0","2.8.3_0"]}','REMOTE_RELAY_OFF',6,'METER',CURRENT_TIMESTAMP(),CURRENT_TIMESTAMP()); + +INSERT INTO SUB_OPERATION_TEMPLATE(OPERATION_DEFINITION,OPERATION_CODE,SUB_TYPE_ID,DEVICE_TYPE,CREATE_TIMESTAMP,UPDATE_TIMESTAMP) VALUES('{"subTypeId":"6","deviceType":"METER","code":"BILLING_REGISTERS_RETRIEVE","type":"PROFILE","control":"NO_REPEAT","maxAttempts":1,"waitingTime":0,"isEnabled":true,"properties":{"requireDateAdjust":"30000","requireAuthentication":"0"},"transportMode":"ALLOW_SMS_FALLBACK","registerTransactions":[],"registers":["0.0.0_0","0.9.1_0","0.9.2_0","1.8.0_0","1.8.1_0","1.8.2_0","1.8.3_0","2.8.0_0","2.8.1_0","2.8.2_0","2.8.3_0","1.8.0*01_0","1.8.1*01_0","1.8.2*01_0","1.8.3*01_0","2.8.0*01_0","2.8.1*01_0","2.8.2*01_0","2.8.3*01_0","14.7.0_0","31.7.0_0","32.7.0_0","51.7.0_0","52.7.0_0","71.7.0_0","72.7.0_0","CSRQ_RL"]}','BILLING_REGISTERS_RETRIEVE',6,'METER',CURRENT_TIMESTAMP(),CURRENT_TIMESTAMP()); + +INSERT INTO SUB_OPERATION_TEMPLATE(OPERATION_DEFINITION,OPERATION_CODE,SUB_TYPE_ID,DEVICE_TYPE,CREATE_TIMESTAMP,UPDATE_TIMESTAMP) VALUES('{"subTypeId":"6","deviceType":"METER","code":"LOAD_PROFILE_RETRIEVE","type":"PROFILE","control":"NO_REPEAT","maxAttempts":1,"waitingTime":0,"isEnabled":true,"properties":{"requireDateValidation":"3600000","requireAuthentication":"0"},"transportMode":"NET_ONLY","registerTransactions":[],"registers":["LP"]}','LOAD_PROFILE_RETRIEVE',6,'METER',CURRENT_TIMESTAMP(),CURRENT_TIMESTAMP()); + +INSERT INTO SUB_OPERATION_TEMPLATE(OPERATION_DEFINITION,OPERATION_CODE,SUB_TYPE_ID,DEVICE_TYPE,CREATE_TIMESTAMP,UPDATE_TIMESTAMP) VALUES('{"subTypeId":"6","deviceType":"METER","code":"TIME_SYNC","type":"PROFILE","control":"NO_REPEAT","maxAttempts":1,"waitingTime":0,"isEnabled":true,"properties":{"requireDateAdjust":"30000","requireAuthentication":"0"},"registerTransactions":[],"registers":["0.9.1_0","0.9.2_0"]}','TIME_SYNC',6,'METER',CURRENT_TIMESTAMP(),CURRENT_TIMESTAMP()); \ No newline at end of file -- 2.36.3