Commit d49eb848 authored by Waleed Akbar's avatar Waleed Akbar
Browse files

feat: Improve policy rule deletion process in PolicyServiceImpl

parent 30ecbb13
Loading
Loading
Loading
Loading
+8 −8
Original line number Diff line number Diff line
@@ -275,17 +275,17 @@ public class PolicyServiceImpl implements PolicyService {
                .getPolicyRuleBasic()
                .setPolicyRuleState(REMOVED_POLICYRULE_STATE);

        // Delete from DB first, then remove from in-memory maps.
        // No setPolicyRule call — that would re-persist the row we're trying to delete.
        contextService
                .setPolicyRule(policyRule)
                .onFailure()
                .transform(failure -> new ExternalServiceFailureException(failure.getMessage()))
                .removePolicyRule(policyRuleId)
                .subscribe()
                .with(
                        tmp ->
                                LOGGER.infof(
                                        "Delete Policy with ID: " + VALID_MESSAGE, policyRuleBasic.getPolicyRuleId()));

        contextService.removePolicyRule(policyRuleId).subscribe().with(x -> {});
                        x -> LOGGER.infof(
                                "Deleted Policy with ID %s from context", policyRuleBasic.getPolicyRuleId()),
                        failure -> LOGGER.errorf(
                                "Failed to delete Policy with ID %s: %s",
                                policyRuleBasic.getPolicyRuleId(), failure.getMessage()));

        return new PolicyRuleState(
                PolicyRuleStateEnum.POLICY_REMOVED, REMOVED_POLICYRULE_STATE.getPolicyRuleStateMessage());