@ -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.Log ;
import org.apache.commons.logging.LogFactory ;
import org.apache.commons.logging.LogFactory ;
import java.util.ArrayList ;
import java.util.HashSet ;
import java.util.HashSet ;
import java.util.List ;
import java.util.List ;
import java.util.Set ;
import java.util.Set ;
@ -110,7 +109,7 @@ public class OperationTemplateServiceImpl implements OperationTemplateService {
}
}
}
}
public void deleteOperationTemplateDetailsF or CacheLoader( String deviceType , String subTypeId , String code ) {
public void deleteOperationTemplateDetailsF rom CacheLoader( String deviceType , String subTypeId , String code ) {
try {
try {
String operationTemplateKey = OperationTemplateManagementUtil . setOperationTemplateCacheKey (
String operationTemplateKey = OperationTemplateManagementUtil . setOperationTemplateCacheKey (
deviceType , subTypeId , code ) ;
deviceType , subTypeId , code ) ;
@ -124,7 +123,7 @@ public class OperationTemplateServiceImpl implements OperationTemplateService {
}
}
}
}
public void refreshOperationTemplateDetailsF or CacheLoader( OperationTemplate operationTemplate ) {
public void refreshOperationTemplateDetailsF rom CacheLoader( OperationTemplate operationTemplate ) {
try {
try {
if ( operationTemplate ! = null ) {
if ( operationTemplate ! = null ) {
String operationTemplateKey = OperationTemplateManagementUtil . setOperationTemplateCacheKey ( operationTemplate . getDeviceType ( ) ,
String operationTemplateKey = OperationTemplateManagementUtil . setOperationTemplateCacheKey ( operationTemplate . getDeviceType ( ) ,
@ -174,7 +173,9 @@ public class OperationTemplateServiceImpl implements OperationTemplateService {
throw new OperationTemplateMgtPluginException ( e . getMessage ( ) , e ) ;
throw new OperationTemplateMgtPluginException ( e . getMessage ( ) , e ) ;
} finally {
} finally {
ConnectionManagerUtils . closeDBConnection ( ) ;
ConnectionManagerUtils . closeDBConnection ( ) ;
refreshOperationTemplateDetailsForCacheLoader ( updatedOperationTemplate ) ;
if ( updatedOperationTemplate ! = null ) {
refreshOperationTemplateDetailsFromCacheLoader ( updatedOperationTemplate ) ;
}
}
}
}
}
@ -186,7 +187,7 @@ public class OperationTemplateServiceImpl implements OperationTemplateService {
* @throws OperationTemplateMgtPluginException
* @throws OperationTemplateMgtPluginException
* /
* /
@Override
@Override
public OperationTemplate getOperationTemplate ByDeviceTypeAndSubTypeIdAndOperationCode ( String deviceType , String subTypeId , String operationCode )
public OperationTemplate getOperationTemplate ( String deviceType , String subTypeId , String operationCode )
throws OperationTemplateMgtPluginException {
throws OperationTemplateMgtPluginException {
try {
try {
@ -211,12 +212,12 @@ public class OperationTemplateServiceImpl implements OperationTemplateService {
* @throws OperationTemplateMgtPluginException
* @throws OperationTemplateMgtPluginException
* /
* /
@Override
@Override
public List < OperationTemplate > getAllOperationTemplates ByDeviceType ( String deviceType )
public List < OperationTemplate > getAllOperationTemplates ( String deviceType )
throws OperationTemplateMgtPluginException {
throws OperationTemplateMgtPluginException {
AssertUtils . hasText ( deviceType , "Invalid device type." ) ;
AssertUtils . hasText ( deviceType , "Invalid device type." ) ;
try {
try {
ConnectionManagerUtils . openDBConnection ( ) ;
ConnectionManagerUtils . openDBConnection ( ) ;
return operationTemplateDAO . getAllOperationTemplates ByDeviceType ( deviceType ) ;
return operationTemplateDAO . getAllOperationTemplates ( deviceType ) ;
} catch ( DBConnectionException | OperationTemplateManagementDAOException e ) {
} catch ( DBConnectionException | OperationTemplateManagementDAOException e ) {
log . error ( e . getMessage ( ) ) ;
log . error ( e . getMessage ( ) ) ;
throw new OperationTemplateMgtPluginException ( e . getMessage ( ) , e ) ;
throw new OperationTemplateMgtPluginException ( e . getMessage ( ) , e ) ;
@ -233,18 +234,18 @@ public class OperationTemplateServiceImpl implements OperationTemplateService {
* @throws OperationTemplateMgtPluginException
* @throws OperationTemplateMgtPluginException
* /
* /
@Override
@Override
public void deleteOperationTemplate ByDeviceTypeAndSubTypeIdAndOperationCode ( String deviceType , String subTypeId , String operationCode )
public void deleteOperationTemplate ( String deviceType , String subTypeId , String operationCode )
throws OperationTemplateMgtPluginException {
throws OperationTemplateMgtPluginException {
String msg = "Operation Template does not exist for subtype id : " + subTypeId
String msg = "Operation Template does not exist for subtype id : " + subTypeId
+ " and device type : " + deviceType + " and operation code : "
+ " and device type : " + deviceType + " and operation code : "
+ operationCode ;
+ operationCode ;
AssertUtils . isNull ( getOperationTemplate ByDeviceTypeAndSubTypeIdAndOperationCode ( deviceType , subTypeId , operationCode ) , msg ) ;
AssertUtils . isNull ( getOperationTemplate ( deviceType , subTypeId , operationCode ) , msg ) ;
int deleted = 0 ;
boolean isDelete = false ;
try {
try {
ConnectionManagerUtils . beginDBTransaction ( ) ;
ConnectionManagerUtils . beginDBTransaction ( ) ;
deleted = operationTemplateDAO . deleteOperationTemplat eByDeviceTypeAndSubTypeIdAndOperationCod e( deviceType , subTypeId , operationCode ) ;
isDelete = operationTemplateDAO . deleteOperationTemplat e( deviceType , subTypeId , operationCode ) ;
ConnectionManagerUtils . commitDBTransaction ( ) ;
ConnectionManagerUtils . commitDBTransaction ( ) ;
if ( log . isDebugEnabled ( ) ) {
if ( log . isDebugEnabled ( ) ) {
String debugMsg = "Operation Template deleted successfully,for subtype id "
String debugMsg = "Operation Template deleted successfully,for subtype id "
@ -257,8 +258,8 @@ public class OperationTemplateServiceImpl implements OperationTemplateService {
throw new OperationTemplateMgtPluginException ( e . getMessage ( ) , e ) ;
throw new OperationTemplateMgtPluginException ( e . getMessage ( ) , e ) ;
} finally {
} finally {
ConnectionManagerUtils . closeDBConnection ( ) ;
ConnectionManagerUtils . closeDBConnection ( ) ;
if ( deleted = = 1 ) {
if ( isDelete ) {
deleteOperationTemplateDetailsF or CacheLoader( deviceType , subTypeId , operationCode ) ;
deleteOperationTemplateDetailsF rom CacheLoader( deviceType , subTypeId , operationCode ) ;
}
}
}
}
@ -271,7 +272,7 @@ public class OperationTemplateServiceImpl implements OperationTemplateService {
* @throws OperationTemplateMgtPluginException
* @throws OperationTemplateMgtPluginException
* /
* /
@Override
@Override
public Set < String > getOperationTemplateCodes ByDeviceTypeAndSubTypeId ( String deviceType , String subTypeId )
public Set < String > getOperationTemplateCodes ( String deviceType , String subTypeId )
throws OperationTemplateMgtPluginException {
throws OperationTemplateMgtPluginException {
try {
try {
@ -321,7 +322,7 @@ public class OperationTemplateServiceImpl implements OperationTemplateService {
String msg = "Operation Template already exist for subtype id : " + operationTemplate . getSubTypeId ( )
String msg = "Operation Template already exist for subtype id : " + operationTemplate . getSubTypeId ( )
+ " and device type : " + operationTemplate . getDeviceType ( ) + " and operation code : "
+ " and device type : " + operationTemplate . getDeviceType ( ) + " and operation code : "
+ operationTemplate . getCode ( ) ;
+ operationTemplate . getCode ( ) ;
AssertUtils . notNull ( getOperationTemplate ByDeviceTypeAndSubTypeIdAndOperationCode ( operationTemplate . getDeviceType ( ) , operationTemplate . getSubTypeId ( ) ,
AssertUtils . notNull ( getOperationTemplate ( operationTemplate . getDeviceType ( ) , operationTemplate . getSubTypeId ( ) ,
operationTemplate . getCode ( ) ) , msg ) ;
operationTemplate . getCode ( ) ) , msg ) ;
}
}
@ -337,7 +338,7 @@ public class OperationTemplateServiceImpl implements OperationTemplateService {
String msg = "Operation Template does not exist for subtype id : " + operationTemplate . getSubTypeId ( )
String msg = "Operation Template does not exist for subtype id : " + operationTemplate . getSubTypeId ( )
+ " and device type : " + operationTemplate . getDeviceType ( ) + " and operation code : "
+ " and device type : " + operationTemplate . getDeviceType ( ) + " and operation code : "
+ operationTemplate . getCode ( ) ;
+ operationTemplate . getCode ( ) ;
AssertUtils . isNull ( getOperationTemplate ByDeviceTypeAndSubTypeIdAndOperationCode ( operationTemplate . getDeviceType ( ) , operationTemplate . getSubTypeId ( ) ,
AssertUtils . isNull ( getOperationTemplate ( operationTemplate . getDeviceType ( ) , operationTemplate . getSubTypeId ( ) ,
operationTemplate . getCode ( ) ) , msg ) ;
operationTemplate . getCode ( ) ) , msg ) ;
}
}