mirror of
https://repository.entgra.net/community/device-mgt-core.git
synced 2025-10-06 02:01:45 +00:00
Merge branch 'master' of https://github.com/wso2/carbon-device-mgt
This commit is contained in:
commit
ed9eebca52
@ -39,6 +39,7 @@ public interface PolicyAdministratorPoint {
|
||||
Policy updatePolicy(Policy policy) throws PolicyManagementException;
|
||||
|
||||
boolean deletePolicy(Policy policy) throws PolicyManagementException;
|
||||
boolean deletePolicy(int policyId) throws PolicyManagementException;
|
||||
|
||||
/**
|
||||
* This method adds a policy per device which should be implemented by the related plugins.
|
||||
|
||||
@ -48,6 +48,8 @@ public interface PolicyManagerService {
|
||||
|
||||
boolean deletePolicy(Policy policy) throws PolicyManagementException;
|
||||
|
||||
boolean deletePolicy(int policyId) throws PolicyManagementException;
|
||||
|
||||
Policy getEffectivePolicy(DeviceIdentifier deviceIdentifier) throws PolicyManagementException;
|
||||
|
||||
List<ProfileFeature> getEffectiveFeatures(DeviceIdentifier deviceIdentifier) throws FeatureManagementException;
|
||||
|
||||
@ -78,6 +78,11 @@ public class PolicyManagerServiceImpl implements PolicyManagerService {
|
||||
return policyAdministratorPoint.deletePolicy(policy);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean deletePolicy(int policyId) throws PolicyManagementException {
|
||||
return policyAdministratorPoint.deletePolicy(policyId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Policy getEffectivePolicy(DeviceIdentifier deviceIdentifier) throws PolicyManagementException {
|
||||
try {
|
||||
|
||||
@ -82,6 +82,8 @@ public interface PolicyDAO {
|
||||
|
||||
boolean deletePolicy(Policy policy) throws PolicyManagerDAOException;
|
||||
|
||||
boolean deletePolicy(int policyId) throws PolicyManagerDAOException;
|
||||
|
||||
boolean deleteAllPolicyRelatedConfigs(int policyId) throws PolicyManagerDAOException;
|
||||
|
||||
List<String> getPolicyAppliedRoles(int policyId) throws PolicyManagerDAOException;
|
||||
|
||||
@ -1073,6 +1073,31 @@ public class PolicyDAOImpl implements PolicyDAO {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean deletePolicy(int policyId) throws PolicyManagerDAOException {
|
||||
Connection conn;
|
||||
PreparedStatement stmt = null;
|
||||
|
||||
try {
|
||||
conn = this.getConnection();
|
||||
String query = "DELETE FROM DM_POLICY WHERE ID = ?";
|
||||
stmt = conn.prepareStatement(query);
|
||||
stmt.setInt(1, policyId);
|
||||
stmt.executeUpdate();
|
||||
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Policy (" + policyId+ ") delete from database.");
|
||||
}
|
||||
return true;
|
||||
} catch (SQLException e) {
|
||||
String msg = "Unable to delete the policy (" + policyId + ") from database.";
|
||||
log.error(msg);
|
||||
throw new PolicyManagerDAOException(msg, e);
|
||||
} finally {
|
||||
PolicyManagementDAOUtil.cleanupResources(stmt, null);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean deleteAllPolicyRelatedConfigs(int policyId) throws PolicyManagerDAOException {
|
||||
|
||||
|
||||
@ -68,6 +68,11 @@ public class PolicyAdministratorPointImpl implements PolicyAdministratorPoint {
|
||||
return policyManager.deletePolicy(policy);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean deletePolicy(int policyId) throws PolicyManagementException {
|
||||
return policyManager.deletePolicy(policyId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Policy addPolicyToDevice(List<DeviceIdentifier> deviceIdentifierList, Policy policy) throws PolicyManagementException {
|
||||
return policyManager.addPolicyToDevice(deviceIdentifierList, policy);
|
||||
|
||||
@ -39,7 +39,7 @@ public class PolicyFilterImpl implements PolicyFilter {
|
||||
for (Policy policy : policies) {
|
||||
|
||||
List<String> tempRoles = policy.getRoles();
|
||||
if (tempRoles == null) {
|
||||
if (tempRoles.isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
if (PolicyManagementConstants.ANY.equalsIgnoreCase(tempRoles.get(0))) {
|
||||
|
||||
@ -34,6 +34,8 @@ public interface PolicyManager {
|
||||
|
||||
boolean deletePolicy(Policy policy) throws PolicyManagementException;
|
||||
|
||||
boolean deletePolicy(int policyId) throws PolicyManagementException;
|
||||
|
||||
Policy addPolicyToDevice(List<DeviceIdentifier> deviceIdentifierList, Policy policy) throws
|
||||
PolicyManagementException;
|
||||
|
||||
|
||||
@ -233,6 +233,29 @@ public class PolicyManagerImpl implements PolicyManager {
|
||||
return bool;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean deletePolicy(int policyId) throws PolicyManagementException {
|
||||
boolean bool;
|
||||
try {
|
||||
PolicyManagementDAOFactory.beginTransaction();
|
||||
policyDAO.deleteAllPolicyRelatedConfigs(policyId);
|
||||
bool = policyDAO.deletePolicy(policyId);
|
||||
PolicyManagementDAOFactory.commitTransaction();
|
||||
|
||||
} catch (PolicyManagerDAOException e) {
|
||||
try {
|
||||
PolicyManagementDAOFactory.rollbackTransaction();
|
||||
} catch (PolicyManagerDAOException e1) {
|
||||
log.warn("Error occurred while roll backing the transaction.");
|
||||
}
|
||||
String msg = "Error occurred while deleting the policy ("
|
||||
+ policyId +")";
|
||||
log.error(msg, e);
|
||||
throw new PolicyManagementException(msg, e);
|
||||
}
|
||||
return bool;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Policy addPolicyToDevice(List<DeviceIdentifier> deviceIdentifierList, Policy policy) throws
|
||||
PolicyManagementException {
|
||||
|
||||
@ -77,6 +77,11 @@ public class PolicyManagementService implements PolicyManagerService {
|
||||
return policyManagerService.deletePolicy(policy);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean deletePolicy(int policyId) throws PolicyManagementException {
|
||||
return policyManagerService.deletePolicy(policyId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Policy getEffectivePolicy(DeviceIdentifier deviceIdentifier) throws PolicyManagementException {
|
||||
return policyManagerService.getEffectivePolicy(deviceIdentifier);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user