Skip to content

Commit

Permalink
Merge pull request #726 from eclipse-tractusx/chore/fix-ess
Browse files Browse the repository at this point in the history
Chore/fix ess
  • Loading branch information
ds-jhartmann authored Jun 27, 2024
2 parents dbed329 + 9568757 commit 0eda802
Show file tree
Hide file tree
Showing 8 changed files with 187 additions and 162 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,13 @@ public static SupplyChainImpacted jobContainsIncidentBPNs(final List<AssetAdmini
* @return Yes, if one or more of the siteIds of PartAsPlanned matches the incident BPNs.
* No, if none of the job siteIds matches the incident BPNs.
* Unknown if PartAsPlanned contains no siteIds.
* @throws InvalidAspectTypeFormatException if any of the sites does not contain a catenaXSiteId
* @throws InvalidAspectTypeFormatException if any of the sites does not contain a catenaXsiteId
*/
public static SupplyChainImpacted jobContainsIncidentBPNSs(
final PartSiteInformationAsPlanned partSiteInformationAsPlanned, final List<String> incidentBPNs)
throws InvalidAspectTypeFormatException {
if (partSiteInformationAsPlanned.sites().stream().anyMatch(site -> site.catenaXSiteId() == null)) {
throw new InvalidAspectTypeFormatException("'PartSiteInformationAsPlanned' exists, but catenaXSiteId could not be found.");
if (partSiteInformationAsPlanned.sites().stream().anyMatch(site -> site.catenaXsiteId() == null)) {
throw new InvalidAspectTypeFormatException("'PartSiteInformationAsPlanned' exists, but catenaXsiteId could not be found.");
}
final List<String> siteIds = partSiteInformationAsPlanned.getCatenaXSiteId();
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,9 @@ public void registerEdcAsset() {
private void registerAsset(final String assetId, final String notificationType, final String path) {
final var body = """
{
"@context": {},
"@context": {
"@vocab": "https://w3id.org/edc/v0.0.1/ns/"
},
"@id": "%s",
"properties": {
"description": "ESS notification endpoint",
Expand Down Expand Up @@ -142,33 +144,42 @@ private void registerAsset(final String assetId, final String notificationType,

private void registerPolicy(final String policyId) {
final var body = """
{
"@context": {
"@vocab": "https://w3id.org/edc/v0.0.1/ns/",
"cx-policy": "https://w3id.org/catenax/policy/",
"odrl": "http://www.w3.org/ns/odrl/2/"
},
"@id": "%s",
"policy": {
"@type": "odrl:Set",
"odrl:permission": [
{
"@context": {
"odrl": "http://www.w3.org/ns/odrl/2/"
},
"@id": "%s",
"policy": {
"odrl:permission": [
{
"odrl:action": "use",
"odrl:constraint": {
"@type": "AtomicConstraint",
"odrl:or": [
{
"@type": "Constraint",
"odrl:leftOperand": "PURPOSE",
"odrl:operator": {
"@id": "odrl:eq"
},
"odrl:rightOperand": "ID 3.1 Trace"
}
]
}
}
]
}
"odrl:action": "use",
"odrl:constraint": {
"@type": "AtomicConstraint",
"odrl:and": [
{
"odrl:leftOperand": "cx-policy:FrameworkAgreement",
"odrl:operator": {
"@id": "odrl:eq"
},
"odrl:rightOperand": "traceability:1.0"
},
{
"odrl:leftOperand": "cx-policy:UsagePurpose",
"odrl:operator": {
"@id": "odrl:eq"
},
"odrl:rightOperand": "cx.core.industrycore:1"
}
]
}
}
""".formatted(policyId);
]
}
}
""".formatted(policyId);
final var entity = restTemplate.exchange(edcProviderUrl + policydefinitionsPath, HttpMethod.POST,
toEntity(body), String.class);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@
@Slf4j
public class EssService {

private static final String PART_AS_PLANNED = SemanticModelNames.PART_AS_PLANNED_2_0_0;
private static final String PART_SITE_INFORMATION_AS_PLANNED = SemanticModelNames.PART_SITE_INFORMATION_AS_PLANNED_1_0_0;
public static final String PART_AS_PLANNED = SemanticModelNames.PART_AS_PLANNED_1_0_1;
public static final String PART_SITE_INFORMATION_AS_PLANNED = SemanticModelNames.PART_SITE_INFORMATION_AS_PLANNED_1_0_0;

private final IrsItemGraphQueryService irsItemGraphQueryService;
private final BpnInvestigationJobCache bpnInvestigationJobCache;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@
package org.eclipse.tractusx.irs.ess.bpn.validation;

import static org.assertj.core.api.Assertions.assertThat;
import static org.eclipse.tractusx.irs.ess.service.EssService.PART_AS_PLANNED;
import static org.eclipse.tractusx.irs.ess.service.EssService.PART_SITE_INFORMATION_AS_PLANNED;
import static org.eclipse.tractusx.irs.util.TestMother.shell;
import static org.eclipse.tractusx.irs.util.TestMother.submodelDescriptor;

import java.time.ZonedDateTime;
import java.util.ArrayList;
Expand All @@ -37,6 +40,7 @@
import org.eclipse.tractusx.irs.component.Shell;
import org.eclipse.tractusx.irs.component.assetadministrationshell.AssetAdministrationShellDescriptor;
import org.eclipse.tractusx.irs.component.assetadministrationshell.IdentifierKeyValuePair;
import org.eclipse.tractusx.irs.component.assetadministrationshell.SubmodelDescriptor;
import org.eclipse.tractusx.irs.component.partasplanned.PartAsPlanned;
import org.eclipse.tractusx.irs.component.partasplanned.ValidityPeriod;
import org.eclipse.tractusx.irs.component.partsiteinformationasplanned.PartSiteInformationAsPlanned;
Expand All @@ -61,7 +65,8 @@ void shouldReturnNoWhenBPNsDoNotContainShellBPNs() {
final Jobs jobs = jobResult(parentId, cxIdBPNMap);

// Act
final SupplyChainImpacted actual = BPNIncidentValidation.jobContainsIncidentBPNs(jobs.getShells().stream().map(Shell::payload).toList(), bpns);
final SupplyChainImpacted actual = BPNIncidentValidation.jobContainsIncidentBPNs(
jobs.getShells().stream().map(Shell::payload).toList(), bpns);

// Assert
assertThat(actual).isEqualTo(SupplyChainImpacted.NO);
Expand All @@ -82,7 +87,8 @@ void shouldReturnYesWhenBPNsContainShellBPNs() {
final Jobs jobs = jobResult(parentId, cxIdBPNMap);

// Act
final SupplyChainImpacted actual = BPNIncidentValidation.jobContainsIncidentBPNs(jobs.getShells().stream().map(Shell::payload).toList(), bpns);
final SupplyChainImpacted actual = BPNIncidentValidation.jobContainsIncidentBPNs(
jobs.getShells().stream().map(Shell::payload).toList(), bpns);

// Assert
assertThat(actual).isEqualTo(SupplyChainImpacted.YES);
Expand All @@ -98,7 +104,8 @@ void shouldReturnYesWhenNoChildrenAndParentContainsBPN() {
final Jobs jobs = jobResult(parentId, cxIdBPNMap);

// Act
final SupplyChainImpacted actual = BPNIncidentValidation.jobContainsIncidentBPNs(jobs.getShells().stream().map(Shell::payload).toList(), bpns);
final SupplyChainImpacted actual = BPNIncidentValidation.jobContainsIncidentBPNs(
jobs.getShells().stream().map(Shell::payload).toList(), bpns);

// Assert
assertThat(actual).isEqualTo(SupplyChainImpacted.YES);
Expand All @@ -114,7 +121,8 @@ void shouldReturnNoWhenNoChildrenAndParentDoesNotContainBPN() {
final Jobs jobs = jobResult(parentId, cxIdBPNMap);

// Act
final SupplyChainImpacted actual = BPNIncidentValidation.jobContainsIncidentBPNs(jobs.getShells().stream().map(Shell::payload).toList(), bpns);
final SupplyChainImpacted actual = BPNIncidentValidation.jobContainsIncidentBPNs(
jobs.getShells().stream().map(Shell::payload).toList(), bpns);

// Assert
assertThat(actual).isEqualTo(SupplyChainImpacted.NO);
Expand All @@ -129,7 +137,8 @@ void shouldReturnUnknownWhenJobContainsNoShells() {
final Jobs jobs = jobResult(parentId, cxIdBPNMap);

// Act
final SupplyChainImpacted actual = BPNIncidentValidation.jobContainsIncidentBPNs(jobs.getShells().stream().map(Shell::payload).toList(), bpns);
final SupplyChainImpacted actual = BPNIncidentValidation.jobContainsIncidentBPNs(
jobs.getShells().stream().map(Shell::payload).toList(), bpns);

// Assert
assertThat(actual).isEqualTo(SupplyChainImpacted.UNKNOWN);
Expand All @@ -151,7 +160,8 @@ void shouldReturnUnknownWhenJobContainsShellWithoutBPN() {
.build();

// Act
final SupplyChainImpacted actual = BPNIncidentValidation.jobContainsIncidentBPNs(jobs.getShells().stream().map(Shell::payload).toList(), bpns);
final SupplyChainImpacted actual = BPNIncidentValidation.jobContainsIncidentBPNs(
jobs.getShells().stream().map(Shell::payload).toList(), bpns);

// Assert
assertThat(actual).isEqualTo(SupplyChainImpacted.UNKNOWN);
Expand All @@ -164,7 +174,7 @@ void shouldReturnNoWhenPartSideInformationDoesNotContainBPNS() throws InvalidAsp
final PartSiteInformationAsPlanned partSiteInformation = PartSiteInformationAsPlanned.builder()
.sites(List.of(
Site.builder()
.catenaXSiteId(
.catenaXsiteId(
"BPNS123456")
.build()))
.build();
Expand All @@ -183,7 +193,7 @@ void shouldReturnYesWhenPartSideInformationContainBPNS() throws InvalidAspectTyp
final PartSiteInformationAsPlanned partSiteInformation = PartSiteInformationAsPlanned.builder()
.sites(List.of(
Site.builder()
.catenaXSiteId(
.catenaXsiteId(
"BPNS00000003B0Q0")
.build()))
.build();
Expand Down Expand Up @@ -278,12 +288,16 @@ private static Jobs jobResult(final String parentId, final Map<String, String> c
}

private static AssetAdministrationShellDescriptor createShell(final String catenaXId, final String bpn) {
final List<SubmodelDescriptor> submodelDescriptors = List.of(
submodelDescriptor(PART_AS_PLANNED, "test", "test"),
submodelDescriptor(PART_SITE_INFORMATION_AS_PLANNED, "test", "test"));
return AssetAdministrationShellDescriptor.builder()
.globalAssetId(catenaXId)
.specificAssetIds(List.of(IdentifierKeyValuePair.builder()
.name("manufacturerId")
.value(bpn)
.build()))
.submodelDescriptors(submodelDescriptors)
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ void shouldCreateTombstoneWhenSiteIdIsMissing() throws EdcClientException {
final Optional<BpnInvestigationJob> job = bpnInvestigationJobCache.findByJobId(jobId);
assertThat(job).isPresent();
assertThat(job.get().getJobSnapshot().getTombstones()).hasSize(1);
assertThat(job.get().getJobSnapshot().getTombstones().get(0).getProcessingError().getErrorDetail()).isEqualTo("'PartSiteInformationAsPlanned' exists, but catenaXSiteId could not be found.");
assertThat(job.get().getJobSnapshot().getTombstones().get(0).getProcessingError().getErrorDetail()).isEqualTo("'PartSiteInformationAsPlanned' exists, but catenaXsiteId could not be found.");
}

private void createMockForJobIdAndShell(final UUID mockedJobId, final String mockedShell,
Expand Down Expand Up @@ -378,7 +378,7 @@ private static Submodel getPartSiteInformationAsPlanned() {
"functionValidUntil": "2025-02-08T04:30:48.000Z",
"function": "production",
"functionValidFrom": "2019-08-21T02:10:36.000Z",
"catenaXSiteId": "BPNS000004711DMY"
"catenaXsiteId": "BPNS000004711DMY"
}
]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,6 @@
@Jacksonized
public record PartSiteInformationAsPlanned(String catenaXId, List<Site> sites) {
public List<String> getCatenaXSiteId() {
return sites().stream().map(Site::catenaXSiteId).toList();
return sites().stream().map(Site::catenaXsiteId).toList();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,5 @@
@Builder
@Jacksonized
public record Site(ZonedDateTime functionValidUntil, String function, ZonedDateTime functionValidFrom,
String catenaXSiteId) {
String catenaXsiteId) {
}
Loading

0 comments on commit 0eda802

Please sign in to comment.