mirror of
https://repository.entgra.net/community/device-mgt-core.git
synced 2025-10-06 02:01:45 +00:00
Fixing the saving issues
This commit is contained in:
parent
57299063b3
commit
9ca5815ec3
@ -21,7 +21,6 @@ package org.wso2.carbon.policy.mgt.core.impl;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
|
||||
import org.wso2.carbon.device.mgt.common.Feature;
|
||||
import org.wso2.carbon.policy.mgt.common.FeatureManagementException;
|
||||
import org.wso2.carbon.policy.mgt.common.Policy;
|
||||
import org.wso2.carbon.policy.mgt.common.PolicyAdministratorPoint;
|
||||
@ -130,7 +129,7 @@ public class PolicyAdministratorPointImpl implements PolicyAdministratorPoint {
|
||||
|
||||
@Override
|
||||
public void setPolicyUsed(DeviceIdentifier deviceIdentifier, Policy policy) throws PolicyManagementException {
|
||||
policyManager.addAppliedPolicyToDevice(deviceIdentifier, policy.getId(), policy.getProfile().getProfileFeaturesList());
|
||||
policyManager.addAppliedPolicyToDevice(deviceIdentifier, policy);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -60,8 +60,10 @@ public interface PolicyManager {
|
||||
|
||||
List<Device> getPolicyAppliedDevicesIds(int policyId) throws PolicyManagementException;
|
||||
|
||||
void addAppliedPolicyToDevice(DeviceIdentifier deviceIdentifier, int policyId, List<ProfileFeature> profileFeatures) throws
|
||||
PolicyManagementException;
|
||||
void addAppliedPolicyFeaturesToDevice(DeviceIdentifier deviceIdentifier, int policyId, List<ProfileFeature>
|
||||
profileFeatures) throws PolicyManagementException;
|
||||
|
||||
void addAppliedPolicyToDevice(DeviceIdentifier deviceIdentifier, Policy policy) throws PolicyManagementException;
|
||||
|
||||
boolean checkPolicyAvailable(DeviceIdentifier deviceIdentifier) throws PolicyManagementException;
|
||||
|
||||
|
||||
@ -653,14 +653,15 @@ public class PolicyManagerImpl implements PolicyManager {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addAppliedPolicyToDevice(DeviceIdentifier deviceIdentifier, int policyId, List<ProfileFeature> profileFeatures) throws
|
||||
public void addAppliedPolicyFeaturesToDevice(DeviceIdentifier deviceIdentifier, int policyId,
|
||||
List<ProfileFeature> profileFeatures) throws
|
||||
PolicyManagementException {
|
||||
|
||||
int deviceId = -1;
|
||||
try {
|
||||
int tenantId = PolicyManagerUtil.getTenantId();
|
||||
Device device = deviceDAO.getDevice(deviceIdentifier, tenantId);
|
||||
deviceId = device.getId();
|
||||
deviceId = device.getId();
|
||||
boolean exist = policyDAO.checkPolicyAvailable(deviceId);
|
||||
PolicyManagementDAOFactory.beginTransaction();
|
||||
if (exist) {
|
||||
@ -687,6 +688,45 @@ public class PolicyManagerImpl implements PolicyManager {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addAppliedPolicyToDevice(DeviceIdentifier deviceIdentifier, Policy policy) throws
|
||||
PolicyManagementException {
|
||||
|
||||
int deviceId = -1;
|
||||
try {
|
||||
int tenantId = PolicyManagerUtil.getTenantId();
|
||||
Device device = deviceDAO.getDevice(deviceIdentifier, tenantId);
|
||||
deviceId = device.getId();
|
||||
boolean exist = policyDAO.checkPolicyAvailable(deviceId);
|
||||
PolicyManagementDAOFactory.beginTransaction();
|
||||
if (exist) {
|
||||
Policy policySaved = policyDAO.getAppliedPolicy(deviceId);
|
||||
if (!policy.equals(policySaved)) {
|
||||
policyDAO.updateEffectivePolicyToDevice(deviceId, policy.getId(), policy.getProfile().
|
||||
getProfileFeaturesList());
|
||||
}
|
||||
} else {
|
||||
policyDAO.addEffectivePolicyToDevice(deviceId, policy.getId(), policy.getProfile().
|
||||
getProfileFeaturesList());
|
||||
}
|
||||
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 adding the evaluated policy to device (" +
|
||||
deviceId + " - " + policy.getId() + ")";
|
||||
log.error(msg, e);
|
||||
throw new PolicyManagementException(msg, e);
|
||||
} catch (DeviceManagementDAOException e) {
|
||||
String msg = "Error occurred while getting the device details (" + deviceIdentifier.getId() + ")";
|
||||
log.error(msg, e);
|
||||
throw new PolicyManagementException(msg, e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean checkPolicyAvailable(DeviceIdentifier deviceIdentifier) throws PolicyManagementException {
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user