* PolicyDTO object
* @throws org.wso2.carbon.identity.base.IdentityException
* throws if invalid policy or if policy with same id is exist
*/
public void addPolicy(PolicyDTO policy) throws IdentityException {
PolicyAdmin policyAdmin;
AbstractPolicy policyObj;
EntitlementEngine entitlementEngine = EntitlementEngine
.getInstance(getGovernanceUserRegistry(), CarbonContext.getCurrentContext().getTenantId());
policyObj = PolicyReader.getInstance(null, null).getPolicy(policy.getPolicy());
if (policyObj != null) {
policyAdmin = new PolicyAdmin(new PolicyStore(getGovernanceUserRegistry()));
policy.setPolicyId(policyObj.getId().toASCIIString());
// All the policies wont be active at the time been added.
policy.setActive(policy.isActive());
if (getPolicy(policy.getPolicyId()) != null) {
throw new IdentityException(
"An Entitlement Policy with the given ID already exists");
}
policyAdmin.addOrUpdatePolicy(policy);
entitlementEngine.getRegistryModule().init(null);
} else {
throw new IdentityException("Invalid Entitlement Policy");
}
}