Modify method names

Thameera 10 months ago
parent 933ab53e81
commit 6e44783996

@ -65,7 +65,7 @@ public class OperationTemplateCacheLoader extends CacheLoader<String, OperationT
}
try {
ConnectionManagerUtils.openDBConnection();
return operationTemplateDAO.getOperationTemplateByDeviceTypeAndSubTypeIdAndOperationCode(deviceType, subTypeId, operationCode);
return operationTemplateDAO.getOperationTemplate(deviceType, subTypeId, operationCode);
} catch (DBConnectionException e) {
String msg =
"Error occurred while obtaining the database connection to retrieve operation template for "

@ -30,7 +30,6 @@ import io.entgra.device.mgt.core.operation.template.util.ConnectionManagerUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import java.util.List;
import java.util.Set;
/**
@ -65,7 +64,7 @@ public class OperationTemplateCodesCacheLoader extends CacheLoader<String, Set<S
}
try {
ConnectionManagerUtils.openDBConnection();
return operationTemplateDAO.getOperationTemplateCodesByDeviceTypeAndSubTypeId(deviceType, subTypeId);
return operationTemplateDAO.getOperationTemplateCodes(deviceType, subTypeId);
} catch (DBConnectionException e) {
String msg =
"Error occurred while obtaining the database connection to retrieve operation template codes for "

@ -34,11 +34,11 @@ public interface OperationTemplateDAO {
OperationTemplate updateOperationTemplate(OperationTemplate operationTemplate)
throws OperationTemplateManagementDAOException;
OperationTemplate getOperationTemplateByDeviceTypeAndSubTypeIdAndOperationCode(String deviceType, String subTypeId, String operationCode) throws OperationTemplateManagementDAOException;
OperationTemplate getOperationTemplate(String deviceType, String subTypeId, String operationCode) throws OperationTemplateManagementDAOException;
List<OperationTemplate> getAllOperationTemplatesByDeviceType(String deviceType) throws OperationTemplateManagementDAOException;
List<OperationTemplate> 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<String> getOperationTemplateCodesByDeviceTypeAndSubTypeId(String deviceType, String subTypeId) throws OperationTemplateManagementDAOException;
Set<String> getOperationTemplateCodes(String deviceType, String subTypeId) throws OperationTemplateManagementDAOException;
}

@ -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<String> getOperationTemplateCodesByDeviceTypeAndSubTypeId(String deviceType, String subTypeId)
public Set<String> getOperationTemplateCodes(String deviceType, String subTypeId)
throws OperationTemplateManagementDAOException {
try {
@ -198,7 +198,7 @@ public class OperationTemplateDAOImpl implements OperationTemplateDAO {
* @throws OperationTemplateManagementDAOException
*/
@Override
public List<OperationTemplate> getAllOperationTemplatesByDeviceType(String deviceType)
public List<OperationTemplate> 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;

@ -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<OperationTemplate> getAllOperationTemplatesByDeviceType(String deviceType)
public List<OperationTemplate> 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<String> getOperationTemplateCodesByDeviceTypeAndSubTypeId(String deviceType, String subTypeId)
public Set<String> 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);
}

@ -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<OperationTemplate> getAllOperationTemplatesByDeviceType(String deviceType) throws OperationTemplateMgtPluginException;
List<OperationTemplate> 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<String> getOperationTemplateCodesByDeviceTypeAndSubTypeId(String deviceType, String subTypeId) throws OperationTemplateMgtPluginException;
Set<String> getOperationTemplateCodes(String deviceType, String subTypeId) throws OperationTemplateMgtPluginException;
}

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

@ -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<String> operationCodes = operationTemplateService.getOperationTemplateCodesByDeviceTypeAndSubTypeId(TestUtils.deviceType, TestUtils.subtypeId);
Set<String> operationCodes = operationTemplateService.getOperationTemplateCodes(TestUtils.deviceType, TestUtils.subtypeId);
Assert.assertNotNull(operationCodes, "Cannot be null");
}
@Test(dependsOnMethods = "testAddOperationTemplate")
public void testGetAllOperationTemplatesByDeviceType() throws OperationTemplateMgtPluginException {
List<OperationTemplate> operationTemplates = operationTemplateService.getAllOperationTemplatesByDeviceType(TestUtils.deviceType);
List<OperationTemplate> 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));
}
}

Loading…
Cancel
Save