Skip to content

Commit

Permalink
Merge branch 'main' into hotfix/5.1.3
Browse files Browse the repository at this point in the history
  • Loading branch information
ds-jhartmann authored May 17, 2024
2 parents 3af6d06 + 126ca82 commit 7cd3c53
Show file tree
Hide file tree
Showing 53 changed files with 14,608 additions and 8,537 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,4 @@ docs/src/diagram-replacer/plantuml.jar
# Helm Chart Dependencies
/charts/item-relationship-service/Chart.lock
/charts/item-relationship-service/charts/
/docs/src/api/irs-api.actual.yaml
21 changes: 20 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,25 @@ _**For better traceability add the corresponding GitHub issue number in each cha
- Fix missing and malformed properties for EDC policy transformation. #648


## [5.1.2] - 2024-05-13

### Fixed

- Fixed ESS Investigation job processing not starting #579

### Changed

- Improved policy store API input validation. #528
- Extended datamodel of EdcPolicyPermissionConstraint to include andConstraints
- Marked createAccessPolicy requests with deprecation mark.
- remove edc namespace from EdcContractAgreementNegotiationResponse and
EdcContractAgreementsResponse eclipse-tractusx/traceability-foss#963

## Added

- Added endpoint for dedicated removal of policy from BPNL. #559
- Integration Test Policy Store API Unhappy Path. #519

## [5.1.2] - 2024-05-13

### Fixed
Expand All @@ -34,7 +53,7 @@ _**For better traceability add the corresponding GitHub issue number in each cha

### Fixed

- Fixed issue in EDR Token renewal #358
- Fixed issue in EDR token renewal. #358

### Added

Expand Down
1 change: 1 addition & 0 deletions charts/item-relationship-service/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]


## [7.1.3] - 2024-05-17

### Changed
Expand Down
63 changes: 58 additions & 5 deletions docs/src/api/irs-api.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -815,9 +815,9 @@ paths:
payload:
'@context':
odrl: http://www.w3.org/ns/odrl/2/
'@id': policy-id3
'@id': e917f5f-8dac-49ac-8d10-5b4d254d2b48
policy:
policyId: p3
policyId: e917f5f-8dac-49ac-8d10-5b4d254d2b48
createdOn: 2024-03-28T03:34:42.9454448Z
validUntil: 2025-12-12T23:59:59.999Z
permissions:
Expand Down Expand Up @@ -1016,6 +1016,59 @@ paths:
summary: Removes a policy that should no longer be accepted in EDC negotiation.
tags:
- Item Relationship Service
/irs/policies/{policyId}/bpnl/{bpnl}:
delete:
description: Removes a policy from BPNL that should no longer be accepted in
EDC negotiation.
operationId: removeAllowedPolicyFromBpnl
parameters:
- in: path
name: policyId
required: true
schema:
type: string
- in: path
name: bpnl
required: true
schema:
type: string
pattern: "(BPN)[LSA][\\w\\d]{10}[\\w\\d]{2}"
responses:
"200":
description: OK
"400":
content:
application/json:
examples:
error:
$ref: '#/components/examples/error-response-400'
schema:
$ref: '#/components/schemas/ErrorResponse'
description: Policy deletion failed.
"401":
content:
application/json:
examples:
error:
$ref: '#/components/examples/error-response-401'
schema:
$ref: '#/components/schemas/ErrorResponse'
description: No valid authentication credentials.
"403":
content:
application/json:
examples:
error:
$ref: '#/components/examples/error-response-403'
schema:
$ref: '#/components/schemas/ErrorResponse'
description: Authorization refused by server.
security:
- api_key: []
summary: Removes a policy from BPNL that should no longer be accepted in EDC
negotiation.
tags:
- Item Relationship Service
components:
examples:
aspect-models-list:
Expand Down Expand Up @@ -1793,7 +1846,7 @@ components:
This parameter is optional.
If not set the policy is registered for each existing BPN.
example: BPNL1234567890AB
pattern: "(BPN)[LSA][\\w\\d]{10}[\\w\\d]{2}"
pattern: "(BPNL)[\\w\\d]{10}[\\w\\d]{2}"
payload:
type: object
additionalProperties:
Expand All @@ -1802,7 +1855,7 @@ components:
example:
'@context':
odrl: http://www.w3.org/ns/odrl/2/
'@id': policy-id
'@id': e917f5f-8dac-49ac-8d10-5b4d254d2b48
'@type': PolicyDefinitionRequestDto
policy:
'@type': Policy
Expand Down Expand Up @@ -2195,7 +2248,7 @@ components:
example:
'@context':
odrl: http://www.w3.org/ns/odrl/2/
'@id': policy-id
'@id': e917f5f-8dac-49ac-8d10-5b4d254d2b48
'@type': PolicyDefinitionRequestDto
policy:
'@type': Policy
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

import java.util.List;
import java.util.NoSuchElementException;
import java.util.UUID;

import jakarta.validation.ConstraintViolationException;
import lombok.extern.slf4j.Slf4j;
Expand Down Expand Up @@ -55,15 +56,18 @@ public class IrsExceptionHandler {
*/
@ExceptionHandler(ResponseStatusException.class)
public ResponseEntity<ErrorResponse> handleResponseStatusException(final ResponseStatusException exception) {
log.info(exception.getClass().getName(), exception);
final UUID errorRef = UUID.randomUUID();
final String messageTemplate = "%s (errorRef: %s)";
log.info(messageTemplate.formatted(exception.getClass().getName(), errorRef), exception);

final HttpStatus httpStatus = HttpStatus.valueOf(exception.getStatusCode().value());

return ResponseEntity.status(httpStatus)
.body(ErrorResponse.builder()
.withStatusCode(httpStatus)
.withError(httpStatus.getReasonPhrase())
.withMessages(List.of(exception.getReason()))
.withMessages(List.of(messageTemplate.formatted(exception.getReason(),
errorRef)))
.build());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,12 @@

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.eclipse.tractusx.irs.common.auth.SecurityHelperService;
import org.eclipse.tractusx.irs.component.JobHandle;
import org.eclipse.tractusx.irs.component.Jobs;
import org.eclipse.tractusx.irs.component.Notification;
import org.eclipse.tractusx.irs.component.PartChainIdentificationKey;
import org.eclipse.tractusx.irs.component.RegisterBpnInvestigationJob;
import org.eclipse.tractusx.irs.component.RegisterJob;
import org.eclipse.tractusx.irs.component.enums.AspectType;
import org.eclipse.tractusx.irs.component.enums.BomLifecycle;
import org.eclipse.tractusx.irs.component.enums.JobState;
import org.eclipse.tractusx.irs.connector.job.JobStore;
Expand All @@ -57,8 +55,10 @@
@Slf4j
public class EssService {

private static final String PART_AS_PLANNED = "urn:samm:io.catenax.part_as_planned:2.0.0#PartAsPlanned";
private static final String PART_SITE_INFORMATION_AS_PLANNED = "urn:bamm:io.catenax.part_site_information_as_planned:1.0.0#PartSiteInformationAsPlanned";

private final IrsItemGraphQueryService irsItemGraphQueryService;
private final SecurityHelperService securityHelperService;
private final BpnInvestigationJobCache bpnInvestigationJobCache;
private final JobStore jobStore;
private final EssRecursiveNotificationHandler recursiveNotificationHandler;
Expand Down Expand Up @@ -167,8 +167,7 @@ private RegisterJob bpnInvestigations(final PartChainIdentificationKey key, fina
.key(key)
.bomLifecycle(bomLifecycle != null ? bomLifecycle : BomLifecycle.AS_PLANNED)
.depth(1)
.aspects(List.of(AspectType.PART_SITE_INFORMATION_AS_PLANNED.toString(),
AspectType.PART_AS_PLANNED.toString()))
.aspects(List.of(PART_SITE_INFORMATION_AS_PLANNED, PART_AS_PLANNED))
.collectAspects(true)
.build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import java.io.InputStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;
Expand Down Expand Up @@ -88,20 +89,25 @@ void generatedOpenApiMatchesContract() throws Exception {
final Map<String, Object> definedYamlMap = mapper.readerForMapOf(Object.class).readValue(definedYaml);
final Map<String, Object> generatedYamlMap = mapper.readerForMapOf(Object.class).readValue(generatedYaml);

// To correctly display both documentations examples - manual and generated by annotations -
// we need to remove verification for some "examples", otherwise one or another won't display correctly
assertThat(generatedYamlMap)

.usingRecursiveComparison()

.ignoringFields("components.schemas.PageResult.example")
.ignoringFields("components.schemas.AspectModels.example")
.ignoringFields("components.schemas.BatchOrderResponse.example")
.ignoringFields("components.schemas.Jobs.example")
.ignoringFields("components.schemas.Policy")
.ignoringFields("components.schemas.BatchResponse.example")

.isEqualTo(definedYamlMap);
try {
// To correctly display both documentations examples - manual and generated by annotations -
// we need to remove verification for some "examples", otherwise one or another won't display correctly
assertThat(generatedYamlMap)

.usingRecursiveComparison()

.ignoringFields("components.schemas.PageResult.example")
.ignoringFields("components.schemas.AspectModels.example")
.ignoringFields("components.schemas.BatchOrderResponse.example")
.ignoringFields("components.schemas.Jobs.example")
.ignoringFields("components.schemas.Policy")
.ignoringFields("components.schemas.BatchResponse.example")

.isEqualTo(definedYamlMap);
} catch (AssertionError e) {
// write changed API to file for easier comparison
Files.writeString(Paths.get("../docs/src/api/irs-api.actual.yaml"), generatedYaml);
}

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
import java.util.Optional;
import java.util.UUID;

import org.eclipse.tractusx.irs.common.auth.SecurityHelperService;
import org.eclipse.tractusx.irs.component.GlobalAssetIdentification;
import org.eclipse.tractusx.irs.component.Job;
import org.eclipse.tractusx.irs.component.JobHandle;
Expand All @@ -63,13 +62,11 @@ class EssServiceTest {

private final IrsItemGraphQueryService irsItemGraphQueryService = mock(IrsItemGraphQueryService.class);

private final SecurityHelperService securityHelperService = mock(SecurityHelperService.class);

private final BpnInvestigationJobCache bpnInvestigationJobCache = new InMemoryBpnInvestigationJobCache();
private final JobStore jobStore = mock(JobStore.class);
private final EssRecursiveNotificationHandler recursiveNotificationHandler = Mockito.mock(
EssRecursiveNotificationHandler.class);
private final EssService essService = new EssService(irsItemGraphQueryService, securityHelperService, bpnInvestigationJobCache,
private final EssService essService = new EssService(irsItemGraphQueryService, bpnInvestigationJobCache,
jobStore, recursiveNotificationHandler);

@Test
Expand Down Expand Up @@ -98,7 +95,6 @@ void shouldSuccessfullyStartJobAndReturnWithExtendedSubmodelList() {
when(irsItemGraphQueryService.registerItemJob(any(RegisterJob.class), any())).thenReturn(JobHandle.builder().id(createdJobId).build());
when(jobStore.find(createdJobId.toString())).thenReturn(Optional.of(MultiTransferJob.builder().job(expectedResponse.getJob()).build()));
when(irsItemGraphQueryService.getJobForJobId(any(MultiTransferJob.class), eq(true))).thenReturn(expectedResponse);
when(securityHelperService.isAdmin()).thenReturn(true);

final JobHandle jobHandle = essService.startIrsJob(request);
final Jobs jobs = essService.getIrsJob(jobHandle.getId().toString());
Expand Down Expand Up @@ -235,7 +231,6 @@ void shouldReturnCorrectFirstLevelImpactedSupplierBpnAndHopsNumberWhenImpactedSu
void shouldKeepJobInRunningIfNotificationIsOpen() {
final String notificationId = UUID.randomUUID().toString();
final UUID jobId = UUID.randomUUID();
when(securityHelperService.isAdmin()).thenReturn(true);

final BpnInvestigationJob bpnInvestigationJob = new BpnInvestigationJob(
Jobs.builder().job(Job.builder().id(jobId).build()).build(),
Expand All @@ -258,7 +253,6 @@ void shouldThrowResponseStatusExceptionWhenIdDoesntExists() {
void shouldCompleteJobIfAllNotificationsSentWereAnswered() {
// Arrange
final String notificationId = UUID.randomUUID().toString();
when(securityHelperService.isAdmin()).thenReturn(true);

final UUID jobId = UUID.randomUUID();
final Jobs jobSnapshot = job(jobId);
Expand Down Expand Up @@ -288,8 +282,6 @@ void shouldCompleteJobIfAllNotificationsSentWereAnswered() {
@Test
void shouldCompleteJobIfFinalNotificationWasReceived() {
// Arrange
when(securityHelperService.isAdmin()).thenReturn(true);

final UUID jobId = UUID.randomUUID();
final Jobs jobSnapshot = job(jobId);
final String notificationId = UUID.randomUUID().toString();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,14 @@ public static String getPolicyTemplate() throws IOException {
return E2ETestHelper.getTemplateFileContent("policy-for-e2e-tests.json");
}

public static String getPolicyTemplateWithoutDefinition() throws IOException {
return E2ETestHelper.getTemplateFileContent("policy-for-e2e-tests-without-definition.json");
}

public static String getPolicyTemplateWithEmptyDefinition() throws IOException {
return E2ETestHelper.getTemplateFileContent("policy-for-e2e-tests-with-empty-definition.json");
}

@SuppressWarnings("unchecked")
public static Map<String, ArrayList<LinkedHashMap<String, ?>>> fetchPoliciesForBpn(
final AuthenticationPropertiesBuilder authenticationPropertiesBuilder, final String bpn) {
Expand Down Expand Up @@ -188,14 +196,20 @@ public static ValidatableResponse registerPolicyForBpn(

final CreatePolicyRequest createPolicyRequest;
try {

CreatePolicyRequestBuilder builder = CreatePolicyRequest.builder();

if (validUntil != null) {
builder = builder.validUntil(OffsetDateTime.parse(validUntil));
}
createPolicyRequest = builder.businessPartnerNumber(bpn)
.payload(E2ETestHelperForPolicyStoreApi.jsonFromString(objectMapper,
policyJson))
.build();

builder = builder.businessPartnerNumber(bpn);

if (policyJson != null) {
builder = builder.payload(E2ETestHelperForPolicyStoreApi.jsonFromString(objectMapper, policyJson));
}

createPolicyRequest = builder.build();
} catch (JsonProcessingException e) {
throw new RuntimeException(e);
}
Expand Down Expand Up @@ -254,6 +268,16 @@ public static ValidatableResponse deletePolicy(
.then();
}

public static ValidatableResponse removePolicyFromBpnl(
final AuthenticationPropertiesBuilder authenticationPropertiesBuilder, final String policyId,
final String bpnl) {
return givenAuthentication(authenticationPropertiesBuilder).pathParam("policyId", policyId)
.pathParam("bpnl", bpnl)
.when()
.delete(URL_IRS_POLICIES + "/{policyId}/bpnl/{bpnl}")
.then();
}

@Data
@NoArgsConstructor
public static final class PolicyAttributes {
Expand Down
Loading

0 comments on commit 7cd3c53

Please sign in to comment.