Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(impl):[TRI-798] move checking depth to delegate #77

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -60,10 +60,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 @@ -109,9 +109,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 @@ -121,15 +127,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