private static Entry<Enforcer> handleSudoRetrievePolicyResponse(final Object response) { if (response instanceof SudoRetrievePolicyResponse) { final SudoRetrievePolicyResponse sudoRetrievePolicyResponse = (SudoRetrievePolicyResponse) response; final Policy policy = sudoRetrievePolicyResponse.getPolicy(); final long revision = policy.getRevision().map(PolicyRevision::toLong) .orElseThrow(badPolicyResponse("no revision")); return Entry.of(revision, PolicyEnforcers.defaultEvaluator(policy)); } else if (response instanceof PolicyNotAccessibleException) { return Entry.nonexistent(); } else { throw new IllegalStateException("expect SudoRetrievePolicyResponse, got: " + response); } }
public PolicyAssert hasNoRevision() { isNotNull(); final Optional<PolicyRevision> actualRevisionOptional = actual.getRevision(); assertThat(actualRevisionOptional.isPresent()) // .overridingErrorMessage("Expected Policy not have a revision but it had <%s>", actualRevisionOptional.orElse(null)) // .isFalse(); return this; }
private void handleSyncPolicyResponse(final Thing syncedThing, final SudoRetrievePolicyResponse response) { log.debug("Retrieved policy response='{}' for thing ID='{}' and policyId='{}' (attempt={}).", response, thingId, policyId, syncAttempts); log.debug("Policy from retrieved policy response is: {}", response.getPolicy()); final Policy policy = response.getPolicy(); final boolean isExpectedPolicyId = policy.getId() .filter(policyId::equals) .isPresent(); if (isExpectedPolicyId) { policyRevision = policy.getRevision().map(PolicyRevision::toLong).orElse(UNKNOWN_REVISION); final Enforcer thePolicyEnforcer = PolicyEnforcers.defaultEvaluator(policy); this.policyEnforcer = thePolicyEnforcer; updateSearchIndexWithPolicy(syncedThing, thePolicyEnforcer); } else { log.warning("Received policy ID <{0}> is not expected ID <{1}>!", policy.getId(), policyId); } }
private void handleSyncPolicyResponse(final Thing syncedThing, final SudoRetrievePolicyResponse response) { log.debug("Retrieved policy response='{}' for thing ID='{}' and policyId='{}' (attempt={}).", response, thingId, policyId, syncAttempts); log.debug("Policy from retrieved policy response is: {}", response.getPolicy()); final Policy policy = response.getPolicy(); final boolean isExpectedPolicyId = policy.getId() .filter(policyId::equals) .isPresent(); if (isExpectedPolicyId) { policyRevision = policy.getRevision().map(PolicyRevision::toLong).orElse(UNKNOWN_REVISION); final Enforcer thePolicyEnforcer = PolicyEnforcers.defaultEvaluator(policy); this.policyEnforcer = thePolicyEnforcer; updateSearchIndexWithPolicy(syncedThing, thePolicyEnforcer); } else { log.warning("Received policy ID <{0}> is not expected ID <{1}>!", policy.getId(), policyId); } }
/** * Returns a new builder for a {@code Policy} based on the given {@code existingPolicy}. * * @param existingPolicy the existing Policy to instantiate the builder with. * @return the new builder. * @throws NullPointerException if {@code existingPolicy} is {@code null}. * @throws PolicyIdInvalidException if {@code policyId} did not comply to {@link Policy#ID_REGEX}. */ public static PolicyBuilder of(final Policy existingPolicy) { checkNotNull(existingPolicy, "existing Policy"); @SuppressWarnings("ConstantConditions") final ImmutablePolicyBuilder result = new ImmutablePolicyBuilder() .setLifecycle(existingPolicy.getLifecycle().orElse(null)) .setRevision(existingPolicy.getRevision().orElse(null)) .setModified(existingPolicy.getModified().orElse(null)); existingPolicy.getId().ifPresent(result::setId); existingPolicy.forEach(result::set); return result; }
public PolicyAssert hasRevision(final PolicyRevision expectedRevision) { isNotNull(); final Optional<PolicyRevision> revisionOptional = actual.getRevision(); assertThat(revisionOptional) // .overridingErrorMessage("Expected Policy revision to be \n<%s> but it was \n<%s>", expectedRevision, revisionOptional.orElse(null)) // .contains(expectedRevision); return this; }