Fixing issues related to apis to call and get effective policy

4.x.x
geethkokila 10 years ago
parent a872caeefc
commit 2ef37b8aa8

@ -303,7 +303,7 @@ public class FeatureDAOImpl implements FeatureDAO {
try {
conn = this.getConnection();
String query = "SELECT PF.ID AS ID, PF.FEATURE_ID FEATURE_ID, F.NAME NAME, F.CODE CODE, " +
"F.EVALUATION_RULE RULE, F.CONTENT AS CONTENT FROM DM_PROFILE_FEATURES AS PF " +
"F.EVALUATION_RULE RULE, PF.CONTENT AS CONTENT, PF.PROFILE_ID PROFILE_ID FROM DM_PROFILE_FEATURES AS PF " +
"JOIN DM_FEATURES AS F ON F.ID = PF.FEATURE_ID";
stmt = conn.prepareStatement(query);
resultSet = stmt.executeQuery();
@ -320,6 +320,7 @@ public class FeatureDAOImpl implements FeatureDAO {
profileFeature.setFeature(feature);
profileFeature.setId(resultSet.getInt("ID"));
profileFeature.setContent(resultSet.getObject("CONTENT"));
profileFeature.setProfileId(resultSet.getInt("PROFILE_ID"));
featureList.add(profileFeature);
}

@ -536,7 +536,7 @@ public class PolicyDAOImpl implements PolicyDAO {
stmt.setTimestamp(4, currentTimestamp);
stmt.setTimestamp(5, currentTimestamp);
stmt.executeQuery();
stmt.executeUpdate();
} catch (SQLException e) {
String msg = "Error occurred while adding the evaluated feature list to device.";
@ -562,7 +562,7 @@ public class PolicyDAOImpl implements PolicyDAO {
stmt.setBoolean(2, true);
stmt.setInt(3, deviceId);
stmt.executeQuery();
stmt.executeUpdate();
} catch (SQLException e) {
String msg = "Error occurred while updating applied policy to device (" + deviceId + ")";
@ -583,14 +583,15 @@ public class PolicyDAOImpl implements PolicyDAO {
Timestamp currentTimestamp = new Timestamp(Calendar.getInstance().getTime().getTime());
try {
conn = this.getConnection();
String query = "UPDATE DM_DEVICE_POLICY_APPLIED SET POLICY_ID = ?, POLICY_CONTENT = ? UPDATED_TIME = ?, APPLIED = ? WHERE DEVICE_ID = ?";
String query = "UPDATE DM_DEVICE_POLICY_APPLIED SET POLICY_ID = ?, POLICY_CONTENT = ?, UPDATED_TIME = ?, " +
"APPLIED = ? WHERE DEVICE_ID = ?";
stmt = conn.prepareStatement(query);
stmt.setInt(1, policyId);
stmt.setObject(2, profileFeatures);
stmt.setTimestamp(3, currentTimestamp);
stmt.setBoolean(4, false);
stmt.setInt(5, deviceId);
stmt.executeQuery();
stmt.executeUpdate();
} catch (SQLException e) {
String msg = "Error occurred while updating the evaluated feature list to device.";

@ -61,6 +61,7 @@ public class PolicyInformationPointImpl implements PolicyInformationPoint {
DeviceType deviceType = new DeviceType();
deviceType.setName(deviceIdentifier.getType());
deviceManagementService = getDeviceManagementService();
try {
device = deviceManagementService.getDevice(deviceIdentifier);
@ -146,4 +147,8 @@ public class PolicyInformationPointImpl implements PolicyInformationPoint {
return finalPolicies;
}
private DeviceManagementService getDeviceManagementService() {
return PolicyManagementDataHolder.getInstance().getDeviceManagementService();
}
}

@ -23,13 +23,12 @@ import org.apache.commons.logging.LogFactory;
import org.osgi.service.component.ComponentContext;
import org.wso2.carbon.device.mgt.core.service.DeviceManagementService;
import org.wso2.carbon.policy.mgt.common.PolicyEvaluationPoint;
import org.wso2.carbon.policy.mgt.common.PolicyInformationPoint;
import org.wso2.carbon.policy.mgt.core.PolicyManagerService;
import org.wso2.carbon.policy.mgt.core.PolicyManagerServiceImpl;
import org.wso2.carbon.policy.mgt.core.config.PolicyConfigurationManager;
import org.wso2.carbon.policy.mgt.core.config.PolicyManagementConfig;
import org.wso2.carbon.policy.mgt.core.config.datasource.DataSourceConfig;
import org.wso2.carbon.policy.mgt.core.dao.PolicyManagementDAOFactory;
import org.wso2.carbon.policy.mgt.core.service.PolicyManagementService;
import org.wso2.carbon.user.core.service.RealmService;
/**
@ -67,7 +66,7 @@ public class PolicyManagementServiceComponent {
PolicyManagementDAOFactory.init(dsConfig);
componentContext.getBundleContext().registerService(
PolicyManagerService.class.getName(), new PolicyManagementService(), null);
PolicyManagerService.class.getName(), new PolicyManagerServiceImpl(), null);
} catch (Throwable t) {
log.error("Error occurred while initializing the Policy management core.", t);

@ -27,12 +27,10 @@ import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOFactory;
import org.wso2.carbon.device.mgt.core.dao.DeviceTypeDAO;
import org.wso2.carbon.device.mgt.core.dto.Device;
import org.wso2.carbon.device.mgt.core.dto.DeviceType;
import org.wso2.carbon.policy.mgt.common.Policy;
import org.wso2.carbon.policy.mgt.common.PolicyManagementException;
import org.wso2.carbon.policy.mgt.common.Profile;
import org.wso2.carbon.policy.mgt.common.ProfileFeature;
import org.wso2.carbon.policy.mgt.common.*;
import org.wso2.carbon.policy.mgt.core.dao.*;
import org.wso2.carbon.policy.mgt.core.mgt.PolicyManager;
import org.wso2.carbon.policy.mgt.core.mgt.ProfileManager;
import java.util.ArrayList;
import java.util.List;
@ -44,6 +42,7 @@ public class PolicyManagerImpl implements PolicyManager {
private FeatureDAO featureDAO;
private DeviceDAO deviceDAO;
private DeviceTypeDAO deviceTypeDAO;
private ProfileManager profileManager;
private static Log log = LogFactory.getLog(PolicyManagerImpl.class);
public PolicyManagerImpl() {
@ -52,6 +51,7 @@ public class PolicyManagerImpl implements PolicyManager {
this.featureDAO = PolicyManagementDAOFactory.getFeatureDAO();
this.deviceDAO = DeviceManagementDAOFactory.getDeviceDAO();
this.deviceTypeDAO = DeviceManagementDAOFactory.getDeviceTypeDAO();
this.profileManager = new ProfileManagerImpl();
}
@Override
@ -463,13 +463,16 @@ public class PolicyManagerImpl implements PolicyManager {
List<Policy> policies = new ArrayList<Policy>();
try {
DeviceType deviceType = deviceTypeDAO.getDeviceType(deviceTypeName);
List<Profile> profileList = profileDAO.getProfilesOfDeviceType(deviceType);
// DeviceType deviceType = deviceTypeDAO.getDeviceType(deviceTypeName);
List<Profile> profileList = profileManager.getProfilesOfDeviceType(deviceTypeName);
List<Policy> allPolicies = policyDAO.getAllPolicies();
for (Profile profile : profileList) {
for (Policy policy : allPolicies) {
if (policy.getProfileId() == profile.getProfileId()) {
policy.setProfile(profile);
policies.add(policy);
}
}
@ -479,12 +482,16 @@ public class PolicyManagerImpl implements PolicyManager {
String msg = "Error occurred while getting all the policies.";
log.error(msg, e);
throw new PolicyManagementException(msg, e);
} catch (ProfileManagerDAOException e) {
String msg = "Error occurred while getting the profiles related to device type (" + deviceTypeName + ")";
log.error(msg, e);
throw new PolicyManagementException(msg, e);
} catch (DeviceManagementDAOException e) {
String msg = "Error occurred while getting device type object related to (" + deviceTypeName + ")";
// } catch (ProfileManagerDAOException e) {
// String msg = "Error occurred while getting the profiles related to device type (" + deviceTypeName + ")";
// log.error(msg, e);
// throw new PolicyManagementException(msg, e);
// } catch (DeviceManagementDAOException e) {
// String msg = "Error occurred while getting device type object related to (" + deviceTypeName + ")";
// log.error(msg, e);
// throw new PolicyManagementException(msg, e);
} catch (ProfileManagementException e) {
String msg = "Error occurred while getting all the profile features.";
log.error(msg, e);
throw new PolicyManagementException(msg, e);
}

@ -235,7 +235,7 @@ public class PolicyDAOTestCase {
List<DeviceIdentifier> deviceIdentifierList = new ArrayList<DeviceIdentifier>();
DeviceIdentifier deviceIdentifier = new DeviceIdentifier();
deviceIdentifier.setId(device.getDeviceIdentificationId());
deviceIdentifier.setType("ANDROID");
deviceIdentifier.setType("android");
deviceIdentifierList.add(deviceIdentifier);
policyManager.addPolicyToDevice(deviceIdentifierList, policy);
@ -266,7 +266,7 @@ public class PolicyDAOTestCase {
public void getDeviceTypeRelatedPolicy() throws PolicyManagementException {
PolicyAdministratorPoint policyAdministratorPoint = new PolicyAdministratorPointImpl();
List<Policy> policyList = policyAdministratorPoint.getPoliciesOfDeviceType("ANDROID");
List<Policy> policyList = policyAdministratorPoint.getPoliciesOfDeviceType("android");
log.debug("----------Device type related policy---------");

@ -25,7 +25,7 @@ public class DeviceTypeCreator {
public static DeviceType getDeviceType(){
DeviceType deviceType = new DeviceType();
deviceType.setName("ANDROID");
deviceType.setName("android");
deviceType.setId(1);
return deviceType;

@ -32,7 +32,7 @@ public class ProfileCreator {
DeviceType deviceType = new DeviceType();
deviceType.setId(1);
deviceType.setName("ANDROID");
deviceType.setName("android");
profile.setProfileFeaturesList(ProfileFeatureCreator.getProfileFeature(features));
profile.setProfileName("Test Profile");

@ -19,10 +19,10 @@
<DeviceMgtTestDBConfigurations>
<DBType typeName="MySql">
<connectionurl>jdbc:mysql://10.100.0.47:3306/WSO2CDM</connectionurl>
<connectionurl>jdbc:mysql://localhost:3306/WSO2CDM</connectionurl>
<driverclass>com.mysql.jdbc.Driver</driverclass>
<userName>root</userName>
<pwd>root</pwd>
<pwd></pwd>
</DBType>
<DBType typeName="H2">
<connectionurl>jdbc:h2:mem:WSO2_TEST_DB;DB_CLOSE_ON_EXIT=FALSE;LOCK_TIMEOUT=60000</connectionurl>

@ -36,15 +36,16 @@ public class SimpleEvaluationImpl implements SimpleEvaluation {
private PolicyManagerService policyManagerService;
private List<Policy> policyList = new ArrayList<Policy>();
public SimpleEvaluationImpl() {
policyManagerService = PolicyDecisionPointDataHolder.getInstance().getPolicyManagerService();
}
// public SimpleEvaluationImpl() {
// policyManagerService = PolicyDecisionPointDataHolder.getInstance().getPolicyManagerService();
// }
@Override
public Policy getEffectivePolicy(DeviceIdentifier deviceIdentifier) throws PolicyEvaluationException {
Policy policy = new Policy();
PolicyAdministratorPoint policyAdministratorPoint;
PolicyInformationPoint policyInformationPoint;
policyManagerService = getPolicyManagerService();
try {
if (policyManagerService != null) {
@ -74,4 +75,8 @@ public class SimpleEvaluationImpl implements SimpleEvaluation {
public void sortPolicies() throws PolicyEvaluationException {
Collections.sort(policyList);
}
private PolicyManagerService getPolicyManagerService(){
return PolicyDecisionPointDataHolder.getInstance().getPolicyManagerService();
}
}

Loading…
Cancel
Save