Skip to content

Commit

Permalink
feat(impl):[#439] change impl of accepted aspects
Browse files Browse the repository at this point in the history
  • Loading branch information
ds-ext-kmassalski committed Mar 7, 2024
1 parent fdf4c17 commit 6cfc8a2
Show file tree
Hide file tree
Showing 26 changed files with 211 additions and 157 deletions.
4 changes: 3 additions & 1 deletion .config/checkstyle.xml
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,9 @@ page at http://checkstyle.sourceforge.net/config.html -->
<module name="IllegalInstantiation"/>
<module name="InnerAssignment"/>

<module name="MagicNumber"/>
<module name="MagicNumber">
<property name="ignoreNumbers" value="-1, 0, 1, 2, 3"/>
</module>
<module name="MissingSwitchDefault"/>
<module name="SimplifyBooleanExpression"/>
<module name="SimplifyBooleanReturn"/>
Expand Down
21 changes: 16 additions & 5 deletions docs/src/api/irs-api.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ info:
description: The API of the Item Relationship Service (IRS) for retrieving item
graphs along the value chain of CATENA-X partners.
title: IRS API
version: "4.7.0"
version: 4.7.0
servers:
- url: http://localhost:8080
security:
Expand Down Expand Up @@ -1127,7 +1127,7 @@ components:
semanticId:
keys:
- type: Submodel
value: urn:bamm:com.catenax.vehicle:0.1.1#PartDetails
value: urn:bamm:io.catenax.vehicle:0.1.1#PartDetails
type: ModelReference
submodels:
- aspectType: supply_chain_impacted
Expand Down Expand Up @@ -1250,7 +1250,7 @@ components:
semanticId:
keys:
- type: Submodel
value: urn:bamm:com.catenax.vehicle:0.1.1#PartDetails
value: urn:bamm:io.catenax.vehicle:0.1.1#PartDetails
type: ModelReference
submodels:
- aspectType: urn:bamm:io.catenax.single_level_bom_as_built:1.0.0
Expand Down Expand Up @@ -1441,7 +1441,7 @@ components:
type: ModelReference
keys:
- type: Submodel
value: urn:bamm:com.catenax.vehicle:0.1.1#PartDetails
value: urn:bamm:io.catenax.vehicle:0.1.1#PartDetails
submodels:
- aspectType: urn:bamm:io.catenax.single_level_bom_as_built:1.0.0
contractAgreementId: f253718e-a270-4367-901b-9d50d9bd8462
Expand Down Expand Up @@ -2367,9 +2367,14 @@ components:
properties:
aspects:
type: array
description: List of aspect names that will be collected if \<collectAspects\>
flag is set to true.
example: urn:samm:io.catenax.single_level_bom_as_built:2.0.0#SingleLevelBomAsBuilt
items:
type: string
pattern: ^(urn:(b|s)amm:.*\d\.\d\.\d)?(#)?(\w+)?$
maxItems: 2147483647
pattern: ^(urn:(b|s)amm:.*\d\.\d\.\d)?(#)?(\w+)?$
batchSize:
type: integer
format: int32
Expand Down Expand Up @@ -2511,14 +2516,14 @@ components:
description: The requested job definition.
properties:
bomLifecycle:
example: asPlanned
type: string
description: The lifecycle context in which the child part was assembled
into the parent part.
enum:
- asBuilt
- asPlanned
- asSpecified
example: asPlanned
callbackUrl:
type: string
description: "Callback url to notify requestor when job processing is finished.\
Expand All @@ -2529,10 +2534,13 @@ components:
$ref: '#/components/schemas/PartChainIdentificationKey'
incidentBPNSs:
type: array
description: Array of BPNS numbers.
example: BPNS000000000DDD
items:
type: string
pattern: "(BPN)[LSA][\\w\\d]{10}[\\w\\d]{2}"
maxItems: 2147483647
pattern: "(BPN)[LSA][\\w\\d]{10}[\\w\\d]{2}"
required:
- incidentBPNSs
- key
Expand All @@ -2545,9 +2553,12 @@ components:
type: array
description: List of aspect names that will be collected if \<collectAspects\>
flag is set to true.
example: urn:samm:io.catenax.single_level_bom_as_built:2.0.0#SingleLevelBomAsBuilt
items:
type: string
pattern: ^(urn:(b|s)amm:.*\d\.\d\.\d)?(#)?(\w+)?$
maxItems: 2147483647
pattern: ^(urn:(b|s)amm:.*\d\.\d\.\d)?(#)?(\w+)?$
auditContractNegotiation:
type: boolean
description: Flag enables and disables auditing, including provisioning
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ skinparam shadowing false
"identification": "dae4d249-6d66-4818-b576-bf52f3b9ae90",
"semanticId": {
"value": [
"urn:bamm:com.catenax.vehicle:0.1.1#PartDetails"
"urn:bamm:io.catenax.vehicle:0.1.1#PartDetails"
]
},
"endpoints": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -468,7 +468,7 @@ private SubmodelDescriptor createPartSubmodelDescriptor() {
.semanticId(Reference.builder()
.keys(List.of(SemanticId.builder()
.type("Submodel")
.value("urn:bamm:com.catenax.vehicle:0.1.1#PartDetails")
.value("urn:bamm:io.catenax.vehicle:0.1.1#PartDetails")
.build()))
.type("ModelReference")
.build())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,10 @@ public List<AspectModel> getAllAspectModels() {
return List.of(
new AspectModel("urn:bamm:io.catenax.serial_part:1.0.1#SerialPart", "1.0.1",
"SerialPart", MODEL_TYPE, MODEL_STATUS),
new AspectModel("urn:bamm:com.catenax.esr_certificates.esr_certificate:1.0.0#EsrCertificate", "1.0.0",
new AspectModel("urn:bamm:io.catenax.esr_certificates.esr_certificate:1.0.0#EsrCertificate", "1.0.0",
"EsrCertificate", MODEL_TYPE, MODEL_STATUS),
new AspectModel("urn:bamm:io.catenax.single_level_bom_as_built:1.0.0#SingleLevelBomAsBuilt",
"1.0.0", "SingleLevelBomAsBuilt", MODEL_TYPE, MODEL_STATUS),
new AspectModel("urn:bamm:io.catenax.single_level_bom_as_built:2.0.0#SingleLevelBomAsBuilt",
"2.0.0", "SingleLevelBomAsBuilt", MODEL_TYPE, MODEL_STATUS),
new AspectModel("urn:bamm:io.catenax.part_as_specified:2.0.0#PartAsSpecified",
"2.0.0", "PartAsSpecified", MODEL_TYPE, MODEL_STATUS),
new AspectModel("urn:bamm:io.catenax.part_as_planned:1.0.1#PartAsPlanned",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,14 +198,12 @@ private void validateAspectTypeValues(final List<String> aspectTypeValues) {
semanticsHubFacade.getAllAspectModels().models());
log.debug("Number of available AspectModels: '{}'", availableModels.size());
log.debug("Provided AspectModels: '{}'", aspectTypeValues);
final Set<String> availableNames = new HashSet<>(availableModels.stream().map(AspectModel::name).toList());
final Set<String> availableUrns = new HashSet<>(availableModels.stream().map(AspectModel::urn).toList());

final List<String> invalidAspectTypes = aspectTypeValues.stream()
.filter(s -> !availableUrns.contains(s)
&& !availableNames.contains(s)
|| !s.matches(
"^(urn:bamm:.*\\d\\.\\d\\.\\d)?(#)?(\\w+)?$"))
"^(urn:(b|s)amm:.*\\d\\.\\d\\.\\d)?(#)?(\\w+)?$"))
.toList();
if (!invalidAspectTypes.isEmpty()) {
throw new IllegalArgumentException(
Expand Down Expand Up @@ -287,7 +285,7 @@ public Jobs getJobForJobId(final MultiTransferJob multiJob, final boolean includ
public void updateJobsInJobStoreMetrics() {
final List<MultiTransferJob> jobs = jobStore.findAll();
final long numberOfJobs = jobs.size();
log.debug("Number(s) of job in JobStore: {}", numberOfJobs);
log.trace("Number(s) of job in JobStore: {}", numberOfJobs);
meterRegistryService.setNumberOfJobsInJobStore(numberOfJobs);

final Map<JobState, Long> stateCount = jobs.stream()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ public void recordJobStateMetric(final JobState state) {

public void setNumberOfJobsInJobStore(final Long size) {
this.numbersOfJobsInJobStore.set(size);
log.debug("Current size of Job in JobStore is {}", size);
log.trace("Current size of Job in JobStore is {}", size);
}

public void setMeasuredMethodExecutionTime(final String tag, final long duration) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@
import org.eclipse.tractusx.irs.component.Jobs;
import org.eclipse.tractusx.irs.component.RegisterJob;
import org.eclipse.tractusx.irs.component.enums.JobState;
import org.eclipse.tractusx.irs.configuration.security.ApiKeyAuthentication;
import org.eclipse.tractusx.irs.configuration.security.ApiKeyAuthority;
import org.eclipse.tractusx.irs.controllers.IrsController;
import org.eclipse.tractusx.irs.registryclient.discovery.ConnectorEndpointsService;
import org.eclipse.tractusx.irs.testing.containers.MinioContainer;
Expand All @@ -58,7 +60,6 @@
import org.springframework.security.core.context.SecurityContext;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.oauth2.jwt.Jwt;
import org.springframework.security.oauth2.server.resource.authentication.JwtAuthenticationToken;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.support.TestPropertySourceUtils;
Expand Down Expand Up @@ -100,7 +101,7 @@ void shouldStartJobAndRetrieveResult() {
when(connectorEndpointsService.fetchConnectorEndpoints(any())).thenReturn(
List.of("http://localhost/discovery"));

thereIsJwtAuthentication();
thereIsAuthentication();

final JobHandle jobHandle = controller.registerJobForGlobalAssetId(registerJob);
final Optional<Jobs> finishedJob = Awaitility.await()
Expand Down Expand Up @@ -130,7 +131,7 @@ void shouldFillSummaryWithoutBPNLookup() {
when(connectorEndpointsService.fetchConnectorEndpoints(any())).thenReturn(
List.of("http://localhost/discovery"));

thereIsJwtAuthentication();
thereIsAuthentication();

final JobHandle jobHandle = controller.registerJobForGlobalAssetId(registerJob);
final Optional<Jobs> finishedJob = Awaitility.await()
Expand All @@ -156,7 +157,7 @@ void shouldFillSummaryWithBPNLookup() {
final RegisterJob registerJob = TestMother.registerJobWithLookupBPNs();
when(connectorEndpointsService.fetchConnectorEndpoints(any())).thenReturn(
List.of("http://localhost/discovery"));
thereIsJwtAuthentication();
thereIsAuthentication();

final JobHandle jobHandle = controller.registerJobForGlobalAssetId(registerJob);
final Optional<Jobs> finishedJob = Awaitility.await()
Expand All @@ -177,28 +178,22 @@ void shouldFillSummaryWithBPNLookup() {
assertThat(finishedJob.get().getJob().getSummary().getBpnLookups().getFailed()).isZero();
}

private void thereIsJwtAuthentication() {
final JwtAuthenticationToken jwtAuthenticationToken = new JwtAuthenticationToken(jwt(),
List.of(new SimpleGrantedAuthority(IrsRoles.VIEW_IRS)));
private void thereIsAuthentication() {
final ApiKeyAuthentication jwtAuthenticationToken = new ApiKeyAuthentication(new
ApiKeyAuthority("apiKey", List.of(new SimpleGrantedAuthority(IrsRoles.VIEW_IRS))));
jwtAuthenticationToken.setAuthenticated(true);
SecurityContext securityContext = Mockito.mock(SecurityContext.class);
when(securityContext.getAuthentication()).thenReturn(jwtAuthenticationToken);
SecurityContextHolder.setContext(securityContext);
}

Jwt jwt() {
return new Jwt("token", Instant.now(), Instant.now().plusSeconds(30), Map.of("alg", "none"),
Map.of(SUB, "sub", "clientId", "clientId", "bpn", "BPNL00000001CRHK"));
}

@NotNull
private Callable<Optional<Jobs>> getJobDetails(final JobHandle jobHandle) {
return () -> {
try {
thereIsJwtAuthentication();
thereIsAuthentication();
return Optional.ofNullable(controller.getJobById(jobHandle.getId(), true).getBody());
} catch (Exception e) {
e.printStackTrace();
return Optional.empty();
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
import static org.eclipse.tractusx.irs.testing.wiremock.SubmodelFacadeWiremockSupport.PATH_NEGOTIATE;
import static org.eclipse.tractusx.irs.testing.wiremock.SubmodelFacadeWiremockSupport.PATH_STATE;
import static org.eclipse.tractusx.irs.testing.wiremock.SubmodelFacadeWiremockSupport.PATH_TRANSFER;
import static org.eclipse.tractusx.irs.util.TestMother.singleLevelBomAsBuiltAspectName;

import java.time.Duration;
import java.util.List;
Expand Down Expand Up @@ -150,7 +151,7 @@ void shouldStartApplicationAndCollectSemanticModels() throws SchemaNotFoundExcep
final AspectModels allAspectModels = semanticHubService.getAllAspectModels();

// Assert
assertThat(allAspectModels.models()).hasSize(78);
assertThat(allAspectModels.models()).hasSize(79);
}

@Test
Expand Down Expand Up @@ -288,7 +289,7 @@ private void successfulRegistryAndDataRequest(final String globalAssetId, final
"urn:samm:io.catenax.batch:2.0.0#Batch", batchFileName);

final String singleLevelBomAsBuilt = WiremockSupport.submodelRequest(edcAssetId, "SingleLevelBomAsBuilt",
"urn:bamm:io.catenax.single_level_bom_as_built:2.0.0#SingleLevelBomAsBuilt", sbomFileName);
singleLevelBomAsBuiltAspectName, sbomFileName);

final List<String> submodelDescriptors = List.of(batch, singleLevelBomAsBuilt);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
import static org.eclipse.tractusx.irs.testing.wiremock.DtrWiremockSupport.DATAPLANE_PUBLIC_URL;
import static org.eclipse.tractusx.irs.testing.wiremock.DtrWiremockSupport.submodelDescriptor;
import static org.eclipse.tractusx.irs.testing.wiremock.WireMockConfig.responseWithStatus;
import static org.eclipse.tractusx.irs.util.TestMother.batchAspectName;
import static org.eclipse.tractusx.irs.util.TestMother.singleLevelBomAsBuiltAspectName;

import java.nio.charset.StandardCharsets;
import java.util.Base64;
Expand Down Expand Up @@ -79,7 +81,7 @@ static RegisterJob jobRequest(final String globalAssetId, final String bpn, fina
return RegisterJob.builder()
.key(PartChainIdentificationKey.builder().bpn(bpn).globalAssetId(globalAssetId).build())
.depth(depth)
.aspects(List.of("Batch", "SingleLevelBomAsBuilt"))
.aspects(List.of(batchAspectName, singleLevelBomAsBuiltAspectName))
.collectAspects(true)
.lookupBPNs(true)
.direction(Direction.DOWNWARD)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,11 @@

import static org.assertj.core.api.Assertions.assertThat;
import static org.eclipse.tractusx.irs.util.TestMother.jobParameter;
import static org.eclipse.tractusx.irs.util.TestMother.jobParameterCollectAspects;
import static org.eclipse.tractusx.irs.util.TestMother.jobParameterUpward;
import static org.eclipse.tractusx.irs.util.TestMother.shell;
import static org.eclipse.tractusx.irs.util.TestMother.shellDescriptor;
import static org.eclipse.tractusx.irs.util.TestMother.singleLevelBomAsBuiltAspectName;
import static org.eclipse.tractusx.irs.util.TestMother.singleLevelUsageAsBuiltAspectName;
import static org.eclipse.tractusx.irs.util.TestMother.submodelDescriptorWithDspEndpoint;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyString;
Expand Down Expand Up @@ -62,9 +63,6 @@ class RelationshipDelegateTest {
final RelationshipDelegate relationshipDelegate = new RelationshipDelegate(null, submodelFacade,
connectorEndpointsService, jsonUtil);

final String singleLevelBomAsBuiltAspectName = "urn:bamm:io.catenax.single_level_bom_as_built:2.0.0#SingleLevelBomAsBuilt";
final String singleLevelUsageAsBuiltAspectName = "urn:bamm:io.catenax.single_level_usage_as_built:2.0.0#SingleLevelUsageAsBuilt";

@Test
void shouldFillItemContainerWithRelationshipAndAddChildIdsToProcess()
throws EdcClientException, URISyntaxException, IOException {
Expand Down
Loading

0 comments on commit 6cfc8a2

Please sign in to comment.