Skip to content

Commit

Permalink
Merge pull request eclipse-tractusx#788 from dsmf/fix/757-access-and-…
Browse files Browse the repository at this point in the history
…usage-policy-validation-flow-correction

fix(policy-validation):[eclipse-tractusx#757] fix
  • Loading branch information
ds-jhartmann authored Jul 11, 2024
2 parents 5b36888 + 492ffa6 commit 3ca5a72
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ _**For better traceability add the corresponding GitHub issue number in each cha

### Fixed

- Fixed ESS Investigation job processing not starting #579
- Access and Usage Policy Validation flow correction. #757
- Fixed ESS Investigation job processing not starting. #579
- Policy store API returns 'rightOperand' without 'odrl:' prefix now (see traceability-foss/issues/970).
- Fixed trivy workflow to fail only on CRITICAL, HIGH (according to https://github.com/eclipse-tractusx/eclipse-tractusx.github.io/pull/949/files).

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,10 @@ public List<Policy> getStoredPolicies(final List<String> bpnls) {
}
}

public List<AcceptedPolicy> getConfiguredDefaultPolicies() {
return allowedPoliciesFromConfig.stream().map(this::toAcceptedPolicy).toList();
}

public Map<String, List<Policy>> getAllStoredPolicies() {
final Map<String, List<Policy>> bpnToPolicies = persistence.readAll();
if (bpnToPolicies.isEmpty()) {
Expand Down Expand Up @@ -267,13 +271,12 @@ private Optional<Policy> findPolicy(final String policyId, final List<String> bp
public List<AcceptedPolicy> getAcceptedPolicies(final String bpn) {

if (bpn == null) {
return getAllPolicies();
return getConfiguredDefaultPolicies();
}

final List<Policy> storedPolicies = getStoredPolicies(List.of(bpn));
final Stream<Policy> result = sortByPolicyId(storedPolicies);
return result.map(this::toAcceptedPolicy).toList();

}

private static Stream<Policy> sortByPolicyId(final List<Policy> policies) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
package org.eclipse.tractusx.irs.policystore.services;

import static java.util.Collections.emptyList;
import static java.util.Collections.emptyMap;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.mockito.ArgumentMatchers.any;
Expand Down Expand Up @@ -312,9 +311,6 @@ class GetAcceptedPoliciesTests {
@Test
void getAcceptedPolicies_whenParameterBpnIsNull_shouldReturnTheConfiguredDefaultPolicy() {

// ARRANGE
when(persistenceMock.readAll()).thenReturn(emptyMap());

// ACT
final var acceptedPolicies = testee.getAcceptedPolicies(null);

Expand Down

0 comments on commit 3ca5a72

Please sign in to comment.