Changing the get effective policy method to store the policy as a operation, and adding ownership type to the policy database

revert-70aa11f8
geethkokila 10 years ago
parent 1bbaac168b
commit 548ce6873f

@ -57,6 +57,7 @@
org.apache.commons.logging,
org.wso2.carbon.device.mgt.common.*,
org.wso2.carbon.device.mgt.core.dto.*,
org.wso2.carbon.device.mgt.core.operation.*,
javax.xml.bind.*,
</Import-Package>
<Export-Package>

@ -22,19 +22,15 @@ 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;
import org.wso2.carbon.policy.mgt.common.PolicyEvaluationException;
import org.wso2.carbon.policy.mgt.common.PolicyEvaluationPoint;
import org.wso2.carbon.policy.mgt.common.PolicyInformationPoint;
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.device.mgt.common.operation.mgt.OperationManagementException;
import org.wso2.carbon.device.mgt.core.operation.mgt.ProfileOperation;
import org.wso2.carbon.policy.mgt.common.*;
import org.wso2.carbon.policy.mgt.core.impl.PolicyAdministratorPointImpl;
import org.wso2.carbon.policy.mgt.core.impl.PolicyInformationPointImpl;
import org.wso2.carbon.policy.mgt.core.internal.PolicyManagementDataHolder;
import org.wso2.carbon.policy.mgt.core.util.PolicyManagementConstants;
import java.util.ArrayList;
import java.util.List;
public class PolicyManagerServiceImpl implements PolicyManagerService {
@ -85,13 +81,45 @@ public class PolicyManagerServiceImpl implements PolicyManagerService {
@Override
public Policy getEffectivePolicy(DeviceIdentifier deviceIdentifier) throws PolicyManagementException {
try {
return PolicyManagementDataHolder.getInstance().getPolicyEvaluationPoint().
Policy policy = PolicyManagementDataHolder.getInstance().getPolicyEvaluationPoint().
getEffectivePolicy(deviceIdentifier);
List<ProfileFeature> effectiveFeatures =policy.getProfile().getProfileFeaturesList();
PolicyOperation policyOperation = new PolicyOperation();
List<ProfileOperation> profileOperationList = new ArrayList<ProfileOperation>();
for (ProfileFeature feature : effectiveFeatures) {
ProfileOperation operation = new ProfileOperation();
operation.setCode(feature.getFeatureCode());
operation.setPayLoad(feature.getContent());
profileOperationList.add(operation);
}
policyOperation.setProfileOperations(profileOperationList);
policyOperation.setCode(PolicyManagementConstants.POLICY_BUNDLE);
List<DeviceIdentifier> deviceIdentifiers = new ArrayList<DeviceIdentifier>();
deviceIdentifiers.add(deviceIdentifier);
PolicyManagementDataHolder.getInstance().getDeviceManagementService().
addOperation(policyOperation, deviceIdentifiers);
return policy;
} catch (PolicyEvaluationException e) {
String msg = "Error occurred while getting the effective policies from the PEP service for device " +
deviceIdentifier.getId() + " - " + deviceIdentifier.getType();
log.error(msg, e);
throw new PolicyManagementException(msg, e);
} catch (OperationManagementException e) {
String msg = "Error occurred while adding the effective feature to database." +
deviceIdentifier.getId() + " - " + deviceIdentifier.getType();
log.error(msg, e);
throw new PolicyManagementException(msg, e);
}
}
@ -99,13 +127,40 @@ public class PolicyManagerServiceImpl implements PolicyManagerService {
public List<ProfileFeature> getEffectiveFeatures(DeviceIdentifier deviceIdentifier) throws
FeatureManagementException {
try {
return PolicyManagementDataHolder.getInstance().getPolicyEvaluationPoint().
List<ProfileFeature> effectiveFeatures = PolicyManagementDataHolder.getInstance().getPolicyEvaluationPoint().
getEffectiveFeatures(deviceIdentifier);
PolicyOperation policyOperation = new PolicyOperation();
List<ProfileOperation> profileOperationList = new ArrayList<ProfileOperation>();
for (ProfileFeature feature : effectiveFeatures) {
ProfileOperation operation = new ProfileOperation();
operation.setCode(feature.getFeatureCode());
operation.setPayLoad(feature.getContent());
profileOperationList.add(operation);
}
policyOperation.setProfileOperations(profileOperationList);
policyOperation.setCode(PolicyManagementConstants.POLICY_BUNDLE);
List<DeviceIdentifier> deviceIdentifiers = new ArrayList<DeviceIdentifier>();
deviceIdentifiers.add(deviceIdentifier);
PolicyManagementDataHolder.getInstance().getDeviceManagementService().
addOperation(policyOperation, deviceIdentifiers);
return effectiveFeatures;
} catch (PolicyEvaluationException e) {
String msg = "Error occurred while getting the effective features from the PEP service " +
deviceIdentifier.getId() + " - " + deviceIdentifier.getType();
log.error(msg, e);
throw new FeatureManagementException(msg, e);
} catch (OperationManagementException e) {
String msg = "Error occurred while adding the effective feature to database." +
deviceIdentifier.getId() + " - " + deviceIdentifier.getType();
log.error(msg, e);
throw new FeatureManagementException(msg, e);
}
}

@ -670,6 +670,7 @@ public class PolicyDAOImpl implements PolicyDAO {
policy.setTenantId(resultSet.getInt("TENANT_ID"));
policy.setPriorityId(resultSet.getInt("PRIORITY"));
policy.setCompliance(resultSet.getString("COMPLIANCE"));
policy.setOwnershipType(resultSet.getString("OWNERSHIP_TYPE"));
policies.add(policy);
}
return policies;
@ -1157,7 +1158,7 @@ public class PolicyDAOImpl implements PolicyDAO {
try {
conn = this.getConnection();
String query = "INSERT INTO DM_POLICY (NAME, PROFILE_ID, TENANT_ID, PRIORITY, COMPLIANCE) VALUES (?, ?, ?, ?, ?)";
String query = "INSERT INTO DM_POLICY (NAME, PROFILE_ID, TENANT_ID, PRIORITY, COMPLIANCE, OWNERSHIP_TYPE) VALUES (?, ?, ?, ?, ?, ?)";
stmt = conn.prepareStatement(query, PreparedStatement.RETURN_GENERATED_KEYS);
stmt.setString(1, policy.getPolicyName());
@ -1165,6 +1166,7 @@ public class PolicyDAOImpl implements PolicyDAO {
stmt.setInt(3, tenantId);
stmt.setInt(4, readHighestPriorityOfPolicies());
stmt.setString(5, policy.getCompliance());
stmt.setString(6, policy.getOwnershipType());
int affectedRows = stmt.executeUpdate();

@ -22,5 +22,6 @@ public final class PolicyManagementConstants {
public static final String DEVICE_CONFIG_XML_NAME = "cdm-config.xml";
public static final String ANY = "ANY";
public static final String POLICY_BUNDLE = "POLICY_BUNDLE";
}

@ -38,6 +38,7 @@ public class PolicyCreator {
users.add("Dilshan");
policy.setUsers(users);
policy.setCompliance("ENFORCE");
policy.setOwnershipType("COPE");
return policy;
}
@ -83,6 +84,8 @@ public class PolicyCreator {
criteria.add(criterion);
policy.setOwnershipType("COPE");
policy.setPolicyCriterias(criteria);
//
// policy.setLatitude("6.927079");
@ -111,6 +114,7 @@ public class PolicyCreator {
policy.setRoles(roles);
policy.setCompliance("ENFORCE");
policy.setOwnershipType("BYOD");
// List<String> users = new ArrayList<String>();
// users.add("Geeth");
@ -155,6 +159,7 @@ public class PolicyCreator {
policy.setDevices(DeviceCreator.getDeviceList(DeviceTypeCreator.getDeviceType()));
policy.setCompliance("MONITOR");
policy.setOwnershipType("BYOD");
List<String> roles = new ArrayList<String>();
roles.add("Role_04");

@ -72,6 +72,7 @@ CREATE TABLE IF NOT EXISTS DM_POLICY (
NAME VARCHAR(45) NULL DEFAULT NULL ,
TENANT_ID INT(11) NOT NULL ,
PROFILE_ID INT(11) NOT NULL ,
OWNERSHIP_TYPE VARCHAR(45) NULL,
COMPLIANCE VARCHAR(100) NULL,
PRIORITY INT NOT NULL ,
PRIMARY KEY (ID) ,

@ -41,6 +41,22 @@ public class PolicyEvaluationServiceImpl implements PolicyEvaluationPoint {
@Override
public List<ProfileFeature> getEffectiveFeatures(DeviceIdentifier deviceIdentifier) throws PolicyEvaluationException {
return evaluation.getEffectivePolicy(deviceIdentifier).getProfile().getProfileFeaturesList();
List<ProfileFeature> effectiveFeatures = evaluation.getEffectivePolicy(deviceIdentifier).
getProfile().getProfileFeaturesList();
/* PolicyOperation policyOperation = new PolicyOperation();
List<ProfileOperation> profileOperationList = new ArrayList<ProfileOperation>();
for (ProfileFeature feature : effectiveFeatures) {
ProfileOperation operation = new ProfileOperation();
operation.setCode(feature.getFeatureCode());
operation.setPayLoad(feature.getContent());
profileOperationList.add(operation);
}
policyOperation.setProfileOperations(profileOperationList);
policyOperation.setCode(PolicyManagementConstants.POLICY_BUNDLE);*/
return effectiveFeatures;
}
}

@ -96,6 +96,7 @@ CREATE TABLE IF NOT EXISTS DM_POLICY (
NAME VARCHAR(45) NULL DEFAULT NULL ,
TENANT_ID INT(11) NOT NULL ,
PROFILE_ID INT(11) NOT NULL ,
OWNERSHIP_TYPE VARCHAR(45) NULL,
COMPLIANCE VARCHAR(100) NULL,
PRIORITY INT NOT NULL ,
PRIMARY KEY (ID) ,

Loading…
Cancel
Save