Fixing issues related to apis to call and get effective policy

revert-70aa11f8
geethkokila 10 years ago
parent a872caeefc
commit 2ef37b8aa8

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

@ -536,7 +536,7 @@ public class PolicyDAOImpl implements PolicyDAO {
stmt.setTimestamp(4, currentTimestamp); stmt.setTimestamp(4, currentTimestamp);
stmt.setTimestamp(5, currentTimestamp); stmt.setTimestamp(5, currentTimestamp);
stmt.executeQuery(); stmt.executeUpdate();
} catch (SQLException e) { } catch (SQLException e) {
String msg = "Error occurred while adding the evaluated feature list to device."; 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.setBoolean(2, true);
stmt.setInt(3, deviceId); stmt.setInt(3, deviceId);
stmt.executeQuery(); stmt.executeUpdate();
} catch (SQLException e) { } catch (SQLException e) {
String msg = "Error occurred while updating applied policy to device (" + deviceId + ")"; 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()); Timestamp currentTimestamp = new Timestamp(Calendar.getInstance().getTime().getTime());
try { try {
conn = this.getConnection(); 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 = conn.prepareStatement(query);
stmt.setInt(1, policyId); stmt.setInt(1, policyId);
stmt.setObject(2, profileFeatures); stmt.setObject(2, profileFeatures);
stmt.setTimestamp(3, currentTimestamp); stmt.setTimestamp(3, currentTimestamp);
stmt.setBoolean(4, false); stmt.setBoolean(4, false);
stmt.setInt(5, deviceId); stmt.setInt(5, deviceId);
stmt.executeQuery(); stmt.executeUpdate();
} catch (SQLException e) { } catch (SQLException e) {
String msg = "Error occurred while updating the evaluated feature list to device."; 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 deviceType = new DeviceType();
deviceType.setName(deviceIdentifier.getType()); deviceType.setName(deviceIdentifier.getType());
deviceManagementService = getDeviceManagementService();
try { try {
device = deviceManagementService.getDevice(deviceIdentifier); device = deviceManagementService.getDevice(deviceIdentifier);
@ -146,4 +147,8 @@ public class PolicyInformationPointImpl implements PolicyInformationPoint {
return finalPolicies; 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.osgi.service.component.ComponentContext;
import org.wso2.carbon.device.mgt.core.service.DeviceManagementService; import org.wso2.carbon.device.mgt.core.service.DeviceManagementService;
import org.wso2.carbon.policy.mgt.common.PolicyEvaluationPoint; 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.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.PolicyConfigurationManager;
import org.wso2.carbon.policy.mgt.core.config.PolicyManagementConfig; 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.config.datasource.DataSourceConfig;
import org.wso2.carbon.policy.mgt.core.dao.PolicyManagementDAOFactory; 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; import org.wso2.carbon.user.core.service.RealmService;
/** /**
@ -67,7 +66,7 @@ public class PolicyManagementServiceComponent {
PolicyManagementDAOFactory.init(dsConfig); PolicyManagementDAOFactory.init(dsConfig);
componentContext.getBundleContext().registerService( componentContext.getBundleContext().registerService(
PolicyManagerService.class.getName(), new PolicyManagementService(), null); PolicyManagerService.class.getName(), new PolicyManagerServiceImpl(), null);
} catch (Throwable t) { } catch (Throwable t) {
log.error("Error occurred while initializing the Policy management core.", 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.dao.DeviceTypeDAO;
import org.wso2.carbon.device.mgt.core.dto.Device; import org.wso2.carbon.device.mgt.core.dto.Device;
import org.wso2.carbon.device.mgt.core.dto.DeviceType; import org.wso2.carbon.device.mgt.core.dto.DeviceType;
import org.wso2.carbon.policy.mgt.common.Policy; import org.wso2.carbon.policy.mgt.common.*;
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.core.dao.*; 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.PolicyManager;
import org.wso2.carbon.policy.mgt.core.mgt.ProfileManager;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@ -44,6 +42,7 @@ public class PolicyManagerImpl implements PolicyManager {
private FeatureDAO featureDAO; private FeatureDAO featureDAO;
private DeviceDAO deviceDAO; private DeviceDAO deviceDAO;
private DeviceTypeDAO deviceTypeDAO; private DeviceTypeDAO deviceTypeDAO;
private ProfileManager profileManager;
private static Log log = LogFactory.getLog(PolicyManagerImpl.class); private static Log log = LogFactory.getLog(PolicyManagerImpl.class);
public PolicyManagerImpl() { public PolicyManagerImpl() {
@ -52,6 +51,7 @@ public class PolicyManagerImpl implements PolicyManager {
this.featureDAO = PolicyManagementDAOFactory.getFeatureDAO(); this.featureDAO = PolicyManagementDAOFactory.getFeatureDAO();
this.deviceDAO = DeviceManagementDAOFactory.getDeviceDAO(); this.deviceDAO = DeviceManagementDAOFactory.getDeviceDAO();
this.deviceTypeDAO = DeviceManagementDAOFactory.getDeviceTypeDAO(); this.deviceTypeDAO = DeviceManagementDAOFactory.getDeviceTypeDAO();
this.profileManager = new ProfileManagerImpl();
} }
@Override @Override
@ -463,13 +463,16 @@ public class PolicyManagerImpl implements PolicyManager {
List<Policy> policies = new ArrayList<Policy>(); List<Policy> policies = new ArrayList<Policy>();
try { try {
DeviceType deviceType = deviceTypeDAO.getDeviceType(deviceTypeName); // DeviceType deviceType = deviceTypeDAO.getDeviceType(deviceTypeName);
List<Profile> profileList = profileDAO.getProfilesOfDeviceType(deviceType);
List<Profile> profileList = profileManager.getProfilesOfDeviceType(deviceTypeName);
List<Policy> allPolicies = policyDAO.getAllPolicies(); List<Policy> allPolicies = policyDAO.getAllPolicies();
for (Profile profile : profileList) { for (Profile profile : profileList) {
for (Policy policy : allPolicies) { for (Policy policy : allPolicies) {
if (policy.getProfileId() == profile.getProfileId()) { if (policy.getProfileId() == profile.getProfileId()) {
policy.setProfile(profile);
policies.add(policy); policies.add(policy);
} }
} }
@ -479,12 +482,16 @@ public class PolicyManagerImpl implements PolicyManager {
String msg = "Error occurred while getting all the policies."; String msg = "Error occurred while getting all the policies.";
log.error(msg, e); log.error(msg, e);
throw new PolicyManagementException(msg, e); throw new PolicyManagementException(msg, e);
} catch (ProfileManagerDAOException e) { // } catch (ProfileManagerDAOException e) {
String msg = "Error occurred while getting the profiles related to device type (" + deviceTypeName + ")"; // String msg = "Error occurred while getting the profiles related to device type (" + deviceTypeName + ")";
log.error(msg, e); // log.error(msg, e);
throw new PolicyManagementException(msg, e); // throw new PolicyManagementException(msg, e);
} catch (DeviceManagementDAOException e) { // } catch (DeviceManagementDAOException e) {
String msg = "Error occurred while getting device type object related to (" + deviceTypeName + ")"; // 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); log.error(msg, e);
throw new PolicyManagementException(msg, e); throw new PolicyManagementException(msg, e);
} }

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

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

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

@ -19,10 +19,10 @@
<DeviceMgtTestDBConfigurations> <DeviceMgtTestDBConfigurations>
<DBType typeName="MySql"> <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> <driverclass>com.mysql.jdbc.Driver</driverclass>
<userName>root</userName> <userName>root</userName>
<pwd>root</pwd> <pwd></pwd>
</DBType> </DBType>
<DBType typeName="H2"> <DBType typeName="H2">
<connectionurl>jdbc:h2:mem:WSO2_TEST_DB;DB_CLOSE_ON_EXIT=FALSE;LOCK_TIMEOUT=60000</connectionurl> <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 PolicyManagerService policyManagerService;
private List<Policy> policyList = new ArrayList<Policy>(); private List<Policy> policyList = new ArrayList<Policy>();
public SimpleEvaluationImpl() { // public SimpleEvaluationImpl() {
policyManagerService = PolicyDecisionPointDataHolder.getInstance().getPolicyManagerService(); // policyManagerService = PolicyDecisionPointDataHolder.getInstance().getPolicyManagerService();
} // }
@Override @Override
public Policy getEffectivePolicy(DeviceIdentifier deviceIdentifier) throws PolicyEvaluationException { public Policy getEffectivePolicy(DeviceIdentifier deviceIdentifier) throws PolicyEvaluationException {
Policy policy = new Policy(); Policy policy = new Policy();
PolicyAdministratorPoint policyAdministratorPoint; PolicyAdministratorPoint policyAdministratorPoint;
PolicyInformationPoint policyInformationPoint; PolicyInformationPoint policyInformationPoint;
policyManagerService = getPolicyManagerService();
try { try {
if (policyManagerService != null) { if (policyManagerService != null) {
@ -74,4 +75,8 @@ public class SimpleEvaluationImpl implements SimpleEvaluation {
public void sortPolicies() throws PolicyEvaluationException { public void sortPolicies() throws PolicyEvaluationException {
Collections.sort(policyList); Collections.sort(policyList);
} }
private PolicyManagerService getPolicyManagerService(){
return PolicyDecisionPointDataHolder.getInstance().getPolicyManagerService();
}
} }

Loading…
Cancel
Save