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)); } }