Fixing the saving issues

revert-70aa11f8
geethkokila 10 years ago
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.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.device.mgt.common.DeviceIdentifier; 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.FeatureManagementException;
import org.wso2.carbon.policy.mgt.common.Policy; import org.wso2.carbon.policy.mgt.common.Policy;
import org.wso2.carbon.policy.mgt.common.PolicyAdministratorPoint; import org.wso2.carbon.policy.mgt.common.PolicyAdministratorPoint;
@ -130,7 +129,7 @@ public class PolicyAdministratorPointImpl implements PolicyAdministratorPoint {
@Override @Override
public void setPolicyUsed(DeviceIdentifier deviceIdentifier, Policy policy) throws PolicyManagementException { public void setPolicyUsed(DeviceIdentifier deviceIdentifier, Policy policy) throws PolicyManagementException {
policyManager.addAppliedPolicyToDevice(deviceIdentifier, policy.getId(), policy.getProfile().getProfileFeaturesList()); policyManager.addAppliedPolicyToDevice(deviceIdentifier, policy);
} }
@Override @Override

@ -60,8 +60,10 @@ public interface PolicyManager {
List<Device> getPolicyAppliedDevicesIds(int policyId) throws PolicyManagementException; List<Device> getPolicyAppliedDevicesIds(int policyId) throws PolicyManagementException;
void addAppliedPolicyToDevice(DeviceIdentifier deviceIdentifier, int policyId, List<ProfileFeature> profileFeatures) throws void addAppliedPolicyFeaturesToDevice(DeviceIdentifier deviceIdentifier, int policyId, List<ProfileFeature>
PolicyManagementException; profileFeatures) throws PolicyManagementException;
void addAppliedPolicyToDevice(DeviceIdentifier deviceIdentifier, Policy policy) throws PolicyManagementException;
boolean checkPolicyAvailable(DeviceIdentifier deviceIdentifier) throws PolicyManagementException; boolean checkPolicyAvailable(DeviceIdentifier deviceIdentifier) throws PolicyManagementException;

@ -653,14 +653,15 @@ public class PolicyManagerImpl implements PolicyManager {
} }
@Override @Override
public void addAppliedPolicyToDevice(DeviceIdentifier deviceIdentifier, int policyId, List<ProfileFeature> profileFeatures) throws public void addAppliedPolicyFeaturesToDevice(DeviceIdentifier deviceIdentifier, int policyId,
List<ProfileFeature> profileFeatures) throws
PolicyManagementException { PolicyManagementException {
int deviceId = -1; int deviceId = -1;
try { try {
int tenantId = PolicyManagerUtil.getTenantId(); int tenantId = PolicyManagerUtil.getTenantId();
Device device = deviceDAO.getDevice(deviceIdentifier, tenantId); Device device = deviceDAO.getDevice(deviceIdentifier, tenantId);
deviceId = device.getId(); deviceId = device.getId();
boolean exist = policyDAO.checkPolicyAvailable(deviceId); boolean exist = policyDAO.checkPolicyAvailable(deviceId);
PolicyManagementDAOFactory.beginTransaction(); PolicyManagementDAOFactory.beginTransaction();
if (exist) { 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 @Override
public boolean checkPolicyAvailable(DeviceIdentifier deviceIdentifier) throws PolicyManagementException { public boolean checkPolicyAvailable(DeviceIdentifier deviceIdentifier) throws PolicyManagementException {

Loading…
Cancel
Save