Code refactoring

revert-70aa11f8
Supun94 8 years ago
parent eb1575126f
commit 2751d4b856

@ -20,7 +20,5 @@ function onRequest(context) {
var utility = require("/app/modules/utility.js")["utility"]; var utility = require("/app/modules/utility.js")["utility"];
var deviceType = context.uriParams.deviceType; var deviceType = context.uriParams.deviceType;
var deviceId = context.uriParams.deviceId; var deviceId = context.uriParams.deviceId;
new Log().info("Device Type : "+deviceType);
new Log().info("Device ID : "+deviceId);
return {"deviceTypePolicyView": utility.getTenantedDeviceUnitName(deviceType, deviceId,"policy-view")}; return {"deviceTypePolicyView": utility.getTenantedDeviceUnitName(deviceType, deviceId,"policy-view")};
} }

@ -78,13 +78,23 @@ public class MergedEvaluationPoint implements PolicyEvaluationPoint {
profile.setUpdatedDate(currentTimestamp); profile.setUpdatedDate(currentTimestamp);
profile.setDeviceType(deviceIdentifier.getType()); profile.setDeviceType(deviceIdentifier.getType());
profile.setTenantId(PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId()); profile.setTenantId(PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId());
// Set effective policy name
policy.setPolicyName(effectivePolicyName); policy.setPolicyName(effectivePolicyName);
policy.setOwnershipType(pipDevice.getOwnershipType()); policy.setOwnershipType(pipDevice.getOwnershipType());
// Set effective policy Active and Updated
policy.setActive(true); policy.setActive(true);
policy.setUpdated(true); policy.setUpdated(true);
policy.setTenantId(PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId()); policy.setTenantId(PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId());
policy.setDescription("This is a system generated effective policy by merging relevant policies."); String policyIds = "";
Collections.sort(policyList);
for (Policy appliedPolicy : policyList) {
policyIds += appliedPolicy.getId() + ", ";
}
policyIds = policyIds.substring(0, policyIds.length() - 2);
policy.setDescription("This is a system generated effective policy by merging Policy Id : " + policyIds);
// Need to set compliance of the effective policy. Get compliance of first policy using priority order
policy.setCompliance(policyList.get(0).getCompliance()); policy.setCompliance(policyList.get(0).getCompliance());
// Change default 0 effective policy id to (-1)
policy.setId(-1); policy.setId(-1);
return policy; return policy;
} catch (PolicyManagementException e) { } catch (PolicyManagementException e) {

@ -98,6 +98,7 @@ public class PolicyManagerServiceImpl implements PolicyManagerService {
policy = policyEvaluationPoint. policy = policyEvaluationPoint.
getEffectivePolicy(deviceIdentifier); getEffectivePolicy(deviceIdentifier);
if (policy == null) { if (policy == null) {
policyAdministratorPoint.removePolicyUsed(deviceIdentifier);
return null; return null;
} }
this.getPAP().setPolicyUsed(deviceIdentifier, policy); this.getPAP().setPolicyUsed(deviceIdentifier, policy);

@ -89,7 +89,12 @@ public class PolicyEnforcementDelegatorImpl implements PolicyEnforcementDelegato
Policy policy = policyManagerService.getPEP().getEffectivePolicy(identifier); Policy policy = policyManagerService.getPEP().getEffectivePolicy(identifier);
policyAdministratorPoint = policyManagerService.getPAP(); policyAdministratorPoint = policyManagerService.getPAP();
policyAdministratorPoint.setPolicyUsed(identifier, policy); if (policy != null) {
policyAdministratorPoint.setPolicyUsed(identifier, policy);
} else {
policyAdministratorPoint.removePolicyUsed(identifier);
return null;
}
return policy; return policy;
//return PolicyManagementDataHolder.getInstance().getPolicyEvaluationPoint().getEffectivePolicy(identifier); //return PolicyManagementDataHolder.getInstance().getPolicyEvaluationPoint().getEffectivePolicy(identifier);
} catch (PolicyEvaluationException e) { } catch (PolicyEvaluationException e) {

@ -879,10 +879,8 @@ public class PolicyManagerImpl implements PolicyManager {
PolicyManagementDAOFactory.beginTransaction(); PolicyManagementDAOFactory.beginTransaction();
Policy policySaved = policyDAO.getAppliedPolicy(deviceId, device.getEnrolmentInfo().getId()); Policy policySaved = policyDAO.getAppliedPolicy(deviceId, device.getEnrolmentInfo().getId());
if (policySaved != null) { if (policySaved != null && policySaved.getId() != 0) {
if (policySaved.getId() != 0) { policyDAO.updateEffectivePolicyToDevice(deviceId, device.getEnrolmentInfo().getId(), policy);
policyDAO.updateEffectivePolicyToDevice(deviceId, device.getEnrolmentInfo().getId(), policy);
}
} else { } else {
policyDAO.addEffectivePolicyToDevice(deviceId, device.getEnrolmentInfo().getId(), policy); policyDAO.addEffectivePolicyToDevice(deviceId, device.getEnrolmentInfo().getId(), policy);
} }

@ -43,7 +43,9 @@
<MaxRetries>5</MaxRetries> <MaxRetries>5</MaxRetries>
<MinRetriesToMarkUnreachable>8</MinRetriesToMarkUnreachable> <MinRetriesToMarkUnreachable>8</MinRetriesToMarkUnreachable>
<MinRetriesToMarkInactive>20</MinRetriesToMarkInactive> <MinRetriesToMarkInactive>20</MinRetriesToMarkInactive>
<!--<PolicyEvaluationPoint>Simple</PolicyEvaluationPoint>--> <!--Set the policy evaluation point name-->
<!--Simple -> Simple policy evaluation point-->
<!--Merged -> Merged policy evaluation point -->
<PolicyEvaluationPoint>Merged</PolicyEvaluationPoint> <PolicyEvaluationPoint>Merged</PolicyEvaluationPoint>
<Platforms> <Platforms>
<Platform>android</Platform> <Platform>android</Platform>

Loading…
Cancel
Save