Skip to content

Commit

Permalink
Merge pull request #77 from catenax-ng/feature/TRI-798-move-checking-…
Browse files Browse the repository at this point in the history
…depth-to-delegate

feat(impl):[TRI-798] move checking depth to delegate
  • Loading branch information
ds-ext-kmassalski authored Jan 10, 2023
2 parents 725687f + 0867760 commit 38502a9
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import java.util.stream.Stream;

import lombok.extern.slf4j.Slf4j;
import org.eclipse.tractusx.irs.component.JobParameter;
import org.eclipse.tractusx.irs.connector.job.MultiTransferJob;
import org.eclipse.tractusx.irs.connector.job.RecursiveJobHandler;

Expand Down Expand Up @@ -52,17 +51,9 @@ public Stream<ItemDataRequest> initiate(final MultiTransferJob job) {
public Stream<ItemDataRequest> recurse(final MultiTransferJob job, final AASTransferProcess transferProcess) {
log.info("Starting recursive request for job {}", job.getJobIdString());

final JobParameter jobParameter = job.getJobParameter();
final int expectedDepth = jobParameter.getDepth();
final Integer currentDepth = transferProcess.getDepth();

if (expectedDepthOfTreeIsNotReached(expectedDepth, currentDepth)) {
return transferProcess.getIdsToProcess()
.stream()
.map(itemId -> ItemDataRequest.nextDepthNode(itemId, currentDepth));
}

return Stream.empty();
return transferProcess.getIdsToProcess()
.stream()
.map(itemId -> ItemDataRequest.nextDepthNode(itemId, transferProcess.getDepth()));
}

@Override
Expand All @@ -73,8 +64,4 @@ public void complete(final MultiTransferJob job) {
logic.assemblePartialItemGraphBlobs(completedTransfers, targetBlobName.toString());
}

private boolean expectedDepthOfTreeIsNotReached(final Integer expectedDepth, final Integer currentDepth) {
log.info("Expected tree depth is {}, current depth is {}", expectedDepth, currentDepth);
return currentDepth < expectedDepth;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,9 @@ public class BpdmDelegate extends AbstractDelegate {

private final BpdmFacade bpdmFacade;

public BpdmDelegate(final BpdmFacade bpdmFacade) {
super(null); // no next step
public BpdmDelegate(final AbstractDelegate nextStep,
final BpdmFacade bpdmFacade) {
super(nextStep);
this.bpdmFacade = bpdmFacade;
}

Expand All @@ -72,7 +73,12 @@ public ItemContainer process(final ItemContainer.ItemContainerBuilder itemContai
itemContainerBuilder.tombstone(Tombstone.from(itemId, null, e, retryCount, ProcessStep.BPDM_REQUEST));
}

return next(itemContainerBuilder, jobData, aasTransferProcess, itemId);
if (expectedDepthOfTreeIsNotReached(jobData.getDepth(), aasTransferProcess.getDepth())) {
return next(itemContainerBuilder, jobData, aasTransferProcess, itemId);
}

// depth reached - stop processing
return itemContainerBuilder.build();
}

private void bpnFromManufacturerId(final ItemContainer.ItemContainerBuilder itemContainerBuilder,
Expand All @@ -94,4 +100,9 @@ private void bpnFromManufacturerId(final ItemContainer.ItemContainerBuilder item
});
}

private boolean expectedDepthOfTreeIsNotReached(final int expectedDepth, final int currentDepth) {
log.info("Expected tree depth is {}, current depth is {}", expectedDepth, currentDepth);
return currentDepth < expectedDepth;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,10 @@ public class SubmodelDelegate extends AbstractDelegate {
private final JsonValidatorService jsonValidatorService;
private final JsonUtil jsonUtil;

public SubmodelDelegate(final AbstractDelegate nextStep, final EdcSubmodelFacade submodelFacade,
public SubmodelDelegate(final EdcSubmodelFacade submodelFacade,
final SemanticsHubFacade semanticsHubFacade, final JsonValidatorService jsonValidatorService,
final JsonUtil jsonUtil) {
super(nextStep);
super(null); // no next step
this.submodelFacade = submodelFacade;
this.semanticsHubFacade = semanticsHubFacade;
this.jsonValidatorService = jsonValidatorService;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,15 @@ public TimedAspect timedAspect(final MeterRegistry registry) {
}

@Bean
public DigitalTwinDelegate digitalTwinDelegate(final RelationshipDelegate relationshipDelegate,
public DigitalTwinDelegate digitalTwinDelegate(final BpdmDelegate bpdmDelegate,
final DigitalTwinRegistryFacade digitalTwinRegistryFacade) {
return new DigitalTwinDelegate(relationshipDelegate, digitalTwinRegistryFacade);
return new DigitalTwinDelegate(bpdmDelegate, digitalTwinRegistryFacade);
}

@Bean
public BpdmDelegate bpdmDelegate(final RelationshipDelegate relationshipDelegate,
final BpdmFacade bpdmFacade) {
return new BpdmDelegate(relationshipDelegate, bpdmFacade);
}

@Bean
Expand All @@ -122,15 +128,9 @@ public RelationshipDelegate relationshipDelegate(final SubmodelDelegate submodel
}

@Bean
public SubmodelDelegate submodelDelegate(final BpdmDelegate bpdmDelegate, final EdcSubmodelFacade submodelFacade,
public SubmodelDelegate submodelDelegate(final EdcSubmodelFacade submodelFacade,
final SemanticsHubFacade semanticsHubFacade, final JsonValidatorService jsonValidatorService) {
return new SubmodelDelegate(bpdmDelegate, submodelFacade, semanticsHubFacade, jsonValidatorService, jsonUtil());
return new SubmodelDelegate(submodelFacade, semanticsHubFacade, jsonValidatorService, jsonUtil());
}

@Bean
public BpdmDelegate bpdmDelegate(final BpdmFacade bpdmFacade) {
return new BpdmDelegate(bpdmFacade);
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
import org.eclipse.tractusx.irs.aaswrapper.job.AASTransferProcess;
import org.eclipse.tractusx.irs.aaswrapper.job.ItemContainer;
import org.eclipse.tractusx.irs.bpdm.BpdmFacade;
import org.eclipse.tractusx.irs.component.JobParameter;
import org.eclipse.tractusx.irs.component.assetadministrationshell.AssetAdministrationShellDescriptor;
import org.eclipse.tractusx.irs.component.assetadministrationshell.IdentifierKeyValuePair;
import org.eclipse.tractusx.irs.component.enums.ProcessStep;
Expand All @@ -46,7 +45,7 @@
class BpdmDelegateTest {

final BpdmFacade bpdmFacade = mock(BpdmFacade.class);
final BpdmDelegate bpdmDelegate = new BpdmDelegate(bpdmFacade);
final BpdmDelegate bpdmDelegate = new BpdmDelegate(null, bpdmFacade);

@Test
void shouldFillItemContainerWithBpn() {
Expand All @@ -57,7 +56,7 @@ void shouldFillItemContainerWithBpn() {

// when
final ItemContainer result = bpdmDelegate.process(itemContainerWithShell, jobParameter(),
new AASTransferProcess(), "itemId");
new AASTransferProcess("id", 0), "itemId");

// then
assertThat(result).isNotNull();
Expand All @@ -73,7 +72,7 @@ void shouldCreateTombstoneForMissingManufacturerId() {

// when
final ItemContainer result = bpdmDelegate.process(itemContainerWithShell, jobParameter(),
new AASTransferProcess(), "itemId");
new AASTransferProcess("id", 0), "itemId");

// then
assertThat(result).isNotNull();
Expand All @@ -92,7 +91,7 @@ void shouldCreateTombstoneForNotValidBpn() {

// when
final ItemContainer result = bpdmDelegate.process(itemContainerWithShell, jobParameter(),
new AASTransferProcess(), "itemId");
new AASTransferProcess("id", 0), "itemId");

// then
assertThat(result).isNotNull();
Expand All @@ -111,7 +110,7 @@ void shouldCatchRestClientExceptionAndPutTombstone() {

// when
final ItemContainer result = bpdmDelegate.process(itemContainerWithShell, jobParameter(),
new AASTransferProcess(), "itemId");
new AASTransferProcess("id", 0), "itemId");

// then
assertThat(result).isNotNull();
Expand All @@ -129,7 +128,7 @@ void shouldCreateTombstoneForMissingBpnForGivenManufacturerId() {

// when
final ItemContainer result = bpdmDelegate.process(itemContainerWithShell, jobParameter(),
new AASTransferProcess(), "itemId");
new AASTransferProcess("id", 0), "itemId");

// then
assertThat(result).isNotNull();
Expand All @@ -147,7 +146,7 @@ void shouldNotCreateBpnsAndTombstonesIfShellIsMissing() {

// when
final ItemContainer result = bpdmDelegate.process(itemContainerWithoutShell, jobParameter(),
new AASTransferProcess(), "itemId");
new AASTransferProcess("id", 0), "itemId");

// then
assertThat(result).isNotNull();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class SubmodelDelegateTest {
final EdcSubmodelFacade submodelFacade = mock(EdcSubmodelFacade.class);
final SemanticsHubFacade semanticsHubFacade = mock(SemanticsHubFacade.class);
final JsonValidatorService jsonValidatorService = mock(JsonValidatorService.class);
final SubmodelDelegate submodelDelegate = new SubmodelDelegate(null, submodelFacade,
final SubmodelDelegate submodelDelegate = new SubmodelDelegate(submodelFacade,
semanticsHubFacade, jsonValidatorService, new JsonUtil());

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ void registerJobWithoutDepthShouldBuildFullTree() {
void registerJobWithCollectAspectsShouldIncludeSubmodels() throws InvalidSchemaException {
// given
when(jsonValidatorService.validate(any(), any())).thenReturn(ValidationResult.builder().valid(true).build());
final RegisterJob registerJob = registerJobWithGlobalAssetIdAndDepth("urn:uuid:4132cd2b-cbe7-4881-a6b4-39fdc31cca2b", 0,
final RegisterJob registerJob = registerJobWithGlobalAssetIdAndDepth("urn:uuid:4132cd2b-cbe7-4881-a6b4-39fdc31cca2b", 100,
List.of(AspectType.SERIAL_PART_TYPIZATION, AspectType.PRODUCT_DESCRIPTION, AspectType.ASSEMBLY_PART_RELATIONSHIP), true);
final int expectedSubmodelsSizeFullTree = 3; // stub

Expand Down Expand Up @@ -135,7 +135,7 @@ void registerJobShouldCreateTombstonesWhenNotPassingJsonSchemaValidation() throw
@Test
void registerJobWithDepthShouldBuildTreeUntilGivenDepth() {
// given
final RegisterJob registerJob = registerJobWithDepthAndAspect(0, null);
final RegisterJob registerJob = registerJobWithDepthAndAspect(1, null);
final int expectedRelationshipsSizeFirstDepth = 1; // stub

// when
Expand Down

0 comments on commit 38502a9

Please sign in to comment.