@ -96,6 +96,7 @@ public class PolicyManagerImpl implements PolicyManager {
public Policy addPolicy ( Policy policy ) throws PolicyManagementException {
public Policy addPolicy ( Policy policy ) throws PolicyManagementException {
String tenantId = String . valueOf ( PrivilegedCarbonContext . getThreadLocalCarbonContext ( ) . getTenantId ( ) ) ;
String tenantId = String . valueOf ( PrivilegedCarbonContext . getThreadLocalCarbonContext ( ) . getTenantId ( ) ) ;
String tenantDomain = String . valueOf ( PrivilegedCarbonContext . getThreadLocalCarbonContext ( ) . getTenantDomain ( ) ) ;
String tenantDomain = String . valueOf ( PrivilegedCarbonContext . getThreadLocalCarbonContext ( ) . getTenantDomain ( ) ) ;
String userName = String . valueOf ( PrivilegedCarbonContext . getThreadLocalCarbonContext ( ) . getUsername ( ) ) ;
try {
try {
PolicyManagementDAOFactory . beginTransaction ( ) ;
PolicyManagementDAOFactory . beginTransaction ( ) ;
if ( policy . getProfile ( ) ! = null & & policy . getProfile ( ) . getProfileId ( ) = = 0 ) {
if ( policy . getProfile ( ) ! = null & & policy . getProfile ( ) . getProfileId ( ) = = 0 ) {
@ -178,7 +179,7 @@ public class PolicyManagerImpl implements PolicyManager {
PolicyManagementDAOFactory . closeConnection ( ) ;
PolicyManagementDAOFactory . closeConnection ( ) ;
}
}
String stringPayload = new Gson ( ) . toJson ( policy ) ;
String stringPayload = new Gson ( ) . toJson ( policy ) ;
log . info ( "Policy C reated", policyLogContextBuilder . setPolicyName ( policy . getPolicyName ( ) ) . setPayload ( stringPayload ) . setTenantID ( tenantId ) . setTenantDomain ( tenantDomain ) . build ( ) ) ;
log . info ( "Policy c reated", policyLogContextBuilder . setPolicyName ( policy . getPolicyName ( ) ) . setPayload ( stringPayload ) . setActionTag ( "ADD_POLICY" ) . setUserName ( userName ) . setTenantID ( tenantId ) . setTenantDomain ( tenantDomain ) . build ( ) ) ;
return policy ;
return policy ;
}
}
@ -186,6 +187,7 @@ public class PolicyManagerImpl implements PolicyManager {
public Policy updatePolicy ( Policy policy ) throws PolicyManagementException {
public Policy updatePolicy ( Policy policy ) throws PolicyManagementException {
String tenantId = String . valueOf ( PrivilegedCarbonContext . getThreadLocalCarbonContext ( ) . getTenantId ( ) ) ;
String tenantId = String . valueOf ( PrivilegedCarbonContext . getThreadLocalCarbonContext ( ) . getTenantId ( ) ) ;
String tenantDomain = String . valueOf ( PrivilegedCarbonContext . getThreadLocalCarbonContext ( ) . getTenantDomain ( ) ) ;
String tenantDomain = String . valueOf ( PrivilegedCarbonContext . getThreadLocalCarbonContext ( ) . getTenantDomain ( ) ) ;
String userName = String . valueOf ( PrivilegedCarbonContext . getThreadLocalCarbonContext ( ) . getUsername ( ) ) ;
try {
try {
// Previous policy needs to be obtained before beginning the transaction
// Previous policy needs to be obtained before beginning the transaction
Policy previousPolicy = this . getPolicy ( policy . getId ( ) ) ;
Policy previousPolicy = this . getPolicy ( policy . getId ( ) ) ;
@ -328,7 +330,7 @@ public class PolicyManagerImpl implements PolicyManager {
PolicyManagementDAOFactory . closeConnection ( ) ;
PolicyManagementDAOFactory . closeConnection ( ) ;
}
}
String stringPayload = new Gson ( ) . toJson ( policy ) ;
String stringPayload = new Gson ( ) . toJson ( policy ) ;
log . info ( "Policy U pdated", policyLogContextBuilder . setPolicyName ( policy . getPolicyName ( ) ) . setPayload ( stringPayload ) . setTenantID ( tenantId ) . setTenantDomain ( tenantDomain ) . build ( ) ) ;
log . info ( "Policy u pdated", policyLogContextBuilder . setPolicyName ( policy . getPolicyName ( ) ) . setPayload ( stringPayload ) . setActionTag ( "UPDATE_POLICY" ) . setUserName ( userName ) . setTenantID ( tenantId ) . setTenantDomain ( tenantDomain ) . build ( ) ) ;
return policy ;
return policy ;
}
}
@ -518,6 +520,10 @@ public class PolicyManagerImpl implements PolicyManager {
@Override
@Override
public boolean updatePolicyPriorities ( List < Policy > policies ) throws PolicyManagementException {
public boolean updatePolicyPriorities ( List < Policy > policies ) throws PolicyManagementException {
String tenantId = String . valueOf ( PrivilegedCarbonContext . getThreadLocalCarbonContext ( ) . getTenantId ( ) ) ;
String tenantDomain = String . valueOf ( PrivilegedCarbonContext . getThreadLocalCarbonContext ( ) . getTenantDomain ( ) ) ;
String userName = String . valueOf ( PrivilegedCarbonContext . getThreadLocalCarbonContext ( ) . getUsername ( ) ) ;
String stringPayload = new Gson ( ) . toJson ( policies ) ;
boolean bool ;
boolean bool ;
try {
try {
List < Policy > existingPolicies ;
List < Policy > existingPolicies ;
@ -546,18 +552,24 @@ public class PolicyManagerImpl implements PolicyManager {
} finally {
} finally {
PolicyManagementDAOFactory . closeConnection ( ) ;
PolicyManagementDAOFactory . closeConnection ( ) ;
}
}
log . info ( "Policy priorities updated" , policyLogContextBuilder . setPayload ( stringPayload ) . setActionTag ( "UPDATE_POLICY_PRIORITIES" ) . setUserName ( userName ) . setTenantID ( tenantId ) . setTenantDomain ( tenantDomain ) . build ( ) ) ;
return bool ;
return bool ;
}
}
@Override
@Override
public boolean deletePolicy ( Policy policy ) throws PolicyManagementException {
public boolean deletePolicy ( Policy policy ) throws PolicyManagementException {
try {
try {
String tenantId = String . valueOf ( PrivilegedCarbonContext . getThreadLocalCarbonContext ( ) . getTenantId ( ) ) ;
String tenantDomain = String . valueOf ( PrivilegedCarbonContext . getThreadLocalCarbonContext ( ) . getTenantDomain ( ) ) ;
String userName = String . valueOf ( PrivilegedCarbonContext . getThreadLocalCarbonContext ( ) . getUsername ( ) ) ;
PolicyManagementDAOFactory . beginTransaction ( ) ;
PolicyManagementDAOFactory . beginTransaction ( ) ;
policyDAO . deleteAllPolicyRelatedConfigs ( policy . getId ( ) ) ;
policyDAO . deleteAllPolicyRelatedConfigs ( policy . getId ( ) ) ;
policyDAO . deletePolicy ( policy . getId ( ) ) ;
policyDAO . deletePolicy ( policy . getId ( ) ) ;
featureDAO . deleteFeaturesOfProfile ( policy . getProfileId ( ) ) ;
featureDAO . deleteFeaturesOfProfile ( policy . getProfileId ( ) ) ;
profileDAO . deleteProfile ( policy . getProfileId ( ) ) ;
profileDAO . deleteProfile ( policy . getProfileId ( ) ) ;
PolicyManagementDAOFactory . commitTransaction ( ) ;
PolicyManagementDAOFactory . commitTransaction ( ) ;
String stringPayload = new Gson ( ) . toJson ( policy ) ;
log . info ( "Policy deleted" , policyLogContextBuilder . setPolicyName ( policy . getPolicyName ( ) ) . setPayload ( stringPayload ) . setActionTag ( "DELETE_POLICY" ) . setUserName ( userName ) . setTenantID ( tenantId ) . setTenantDomain ( tenantDomain ) . build ( ) ) ;
return true ;
return true ;
} catch ( PolicyManagerDAOException e ) {
} catch ( PolicyManagerDAOException e ) {
PolicyManagementDAOFactory . rollbackTransaction ( ) ;
PolicyManagementDAOFactory . rollbackTransaction ( ) ;
@ -578,6 +590,9 @@ public class PolicyManagerImpl implements PolicyManager {
@Override
@Override
public boolean deletePolicy ( int policyId ) throws PolicyManagementException {
public boolean deletePolicy ( int policyId ) throws PolicyManagementException {
String tenantId = String . valueOf ( PrivilegedCarbonContext . getThreadLocalCarbonContext ( ) . getTenantId ( ) ) ;
String tenantDomain = String . valueOf ( PrivilegedCarbonContext . getThreadLocalCarbonContext ( ) . getTenantDomain ( ) ) ;
String userName = String . valueOf ( PrivilegedCarbonContext . getThreadLocalCarbonContext ( ) . getUsername ( ) ) ;
boolean bool ;
boolean bool ;
List < Policy > policies = this . getPolicies ( ) ;
List < Policy > policies = this . getPolicies ( ) ;
Policy pol = null ;
Policy pol = null ;
@ -608,6 +623,8 @@ public class PolicyManagerImpl implements PolicyManager {
featureDAO . deleteFeaturesOfProfile ( policy . getProfileId ( ) ) ;
featureDAO . deleteFeaturesOfProfile ( policy . getProfileId ( ) ) ;
profileDAO . deleteProfile ( policy . getProfileId ( ) ) ;
profileDAO . deleteProfile ( policy . getProfileId ( ) ) ;
PolicyManagementDAOFactory . commitTransaction ( ) ;
PolicyManagementDAOFactory . commitTransaction ( ) ;
String stringPayload = new Gson ( ) . toJson ( policy ) ;
log . info ( "Policy deleted" , policyLogContextBuilder . setPolicyName ( policy . getPolicyName ( ) ) . setPayload ( stringPayload ) . setActionTag ( "DELETE_POLICY" ) . setUserName ( userName ) . setTenantID ( tenantId ) . setTenantDomain ( tenantDomain ) . build ( ) ) ;
return bool ;
return bool ;
} catch ( PolicyManagerDAOException e ) {
} catch ( PolicyManagerDAOException e ) {
PolicyManagementDAOFactory . rollbackTransaction ( ) ;
PolicyManagementDAOFactory . rollbackTransaction ( ) ;
@ -666,6 +683,9 @@ public class PolicyManagerImpl implements PolicyManager {
List < Device > deviceList = new ArrayList < > ( ) ;
List < Device > deviceList = new ArrayList < > ( ) ;
DeviceManagementProviderService deviceManagementService = PolicyManagementDataHolder
DeviceManagementProviderService deviceManagementService = PolicyManagementDataHolder
. getInstance ( ) . getDeviceManagementService ( ) ;
. getInstance ( ) . getDeviceManagementService ( ) ;
String tenantId = String . valueOf ( PrivilegedCarbonContext . getThreadLocalCarbonContext ( ) . getTenantId ( ) ) ;
String tenantDomain = String . valueOf ( PrivilegedCarbonContext . getThreadLocalCarbonContext ( ) . getTenantDomain ( ) ) ;
String userName = String . valueOf ( PrivilegedCarbonContext . getThreadLocalCarbonContext ( ) . getUsername ( ) ) ;
for ( DeviceIdentifier deviceIdentifier : deviceIdentifierList ) {
for ( DeviceIdentifier deviceIdentifier : deviceIdentifierList ) {
try {
try {
Device device = deviceManagementService . getDevice ( deviceIdentifier , false ) ;
Device device = deviceManagementService . getDevice ( deviceIdentifier , false ) ;
@ -694,6 +714,9 @@ public class PolicyManagerImpl implements PolicyManager {
}
}
policy . setDevices ( deviceList ) ;
policy . setDevices ( deviceList ) ;
}
}
String policyPayload = new Gson ( ) . toJson ( policy ) ;
String deviceListPayload = new Gson ( ) . toJson ( deviceList ) ;
log . info ( "Policy added to devices" , policyLogContextBuilder . setPolicyName ( policy . getPolicyName ( ) ) . setPayload ( " Policy: " + policyPayload + " DeviceList: " + deviceListPayload ) . setActionTag ( "ADD_POLICY_TO_DEVICE" ) . setUserName ( userName ) . setTenantID ( tenantId ) . setTenantDomain ( tenantDomain ) . build ( ) ) ;
} catch ( PolicyManagerDAOException e ) {
} catch ( PolicyManagerDAOException e ) {
PolicyManagementDAOFactory . rollbackTransaction ( ) ;
PolicyManagementDAOFactory . rollbackTransaction ( ) ;
throw new PolicyManagementException ( "Error occurred while adding the policy ("
throw new PolicyManagementException ( "Error occurred while adding the policy ("