Skip to content

Commit

Permalink
[backend/frontend] Add the ability to customize the expiration time (#…
Browse files Browse the repository at this point in the history
…1171)

Co-authored-by: Romuald Lemesle <[email protected]>
  • Loading branch information
johanah29 and RomuDeuxfois authored Sep 30, 2024
1 parent 5803b8f commit 24bd966
Show file tree
Hide file tree
Showing 43 changed files with 1,948 additions and 1,375 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,74 +20,75 @@
@Log
public class ExpectationsExpirationManagerService {

private final InjectExpectationService injectExpectationService;
private final ExpectationsExpirationManagerConfig config;
private final InjectExpectationService injectExpectationService;
private final ExpectationsExpirationManagerConfig config;


@Transactional(rollbackFor = Exception.class)
public void computeExpectations() {
List<InjectExpectation> expectations = this.injectExpectationService.expectationsNotFill();
if (!expectations.isEmpty()) {
this.computeExpectationsForAssets(expectations);
this.computeExpectationsForAssetGroups(expectations);
this.computeExpectations(expectations);
}
@Transactional(rollbackFor = Exception.class)
public void computeExpectations() {
List<InjectExpectation> expectations = this.injectExpectationService.expectationsNotFill();
if (!expectations.isEmpty()) {
this.computeExpectationsForAssets(expectations);
this.computeExpectationsForAssetGroups(expectations);
this.computeExpectations(expectations);
}
}

// -- PRIVATE --
// -- PRIVATE --

private void computeExpectations(@NotNull final List<InjectExpectation> expectations) {
List<InjectExpectation> expectationAssets = expectations.stream().toList();
expectationAssets.forEach((expectation) -> {
// Maximum time for detection
if (isExpired(expectation, this.config.getExpirationTimeInMinute())) {
String result = computeFailedMessage(expectation.getType());
this.injectExpectationService.computeExpectation(
expectation,
this.config.getId(),
"collector",
PRODUCT_NAME,
result,
false
);
}
});
}
private void computeExpectations(@NotNull final List<InjectExpectation> expectations) {
List<InjectExpectation> expectationAssets = expectations.stream().toList();
expectationAssets.forEach((expectation) -> {
if (isExpired(expectation)) {
String result = computeFailedMessage(expectation.getType());
this.injectExpectationService.computeExpectation(
expectation,
this.config.getId(),
"collector",
PRODUCT_NAME,
result,
false
);
}

private void computeExpectationsForAssets(@NotNull final List<InjectExpectation> expectations) {
List<InjectExpectation> expectationAssets = expectations.stream().filter(e -> e.getAsset() != null).toList();
expectationAssets.forEach((expectation) -> {
// Maximum time for detection
if (isExpired(expectation, this.config.getAssetExpirationTimeInMinute())) {
String result = computeFailedMessage(expectation.getType());
this.injectExpectationService.computeExpectation(
expectation,
this.config.getId(),
"collector",
PRODUCT_NAME,
result,
false
);
}
});
}
});
}

private void computeExpectationsForAssetGroups(@NotNull final List<InjectExpectation> expectations) {
List<InjectExpectation> expectationAssetGroups = expectations.stream().filter(e -> e.getAssetGroup() != null).toList();
expectationAssetGroups.forEach((expectationAssetGroup -> {
List<InjectExpectation> expectationAssets = this.injectExpectationService.expectationsForAssets(
expectationAssetGroup.getInject(), expectationAssetGroup.getAssetGroup(), expectationAssetGroup.getType()
);
// Every expectation assets are filled
if (expectationAssets.stream().noneMatch(e -> e.getResults().isEmpty())) {
this.injectExpectationService.computeExpectationGroup(
expectationAssetGroup,
expectationAssets,
this.config.getId(),
"collector",
PRODUCT_NAME
);
}
}));
}
private void computeExpectationsForAssets(@NotNull final List<InjectExpectation> expectations) {
List<InjectExpectation> expectationAssets = expectations.stream().filter(e -> e.getAsset() != null).toList();
expectationAssets.forEach((expectation) -> {
if (isExpired(expectation)) {
String result = computeFailedMessage(expectation.getType());
this.injectExpectationService.computeExpectation(
expectation,
this.config.getId(),
"collector",
PRODUCT_NAME,
result,
false
);
}

});
}

private void computeExpectationsForAssetGroups(@NotNull final List<InjectExpectation> expectations) {
List<InjectExpectation> expectationAssetGroups = expectations.stream().filter(e -> e.getAssetGroup() != null)
.toList();
expectationAssetGroups.forEach((expectationAssetGroup -> {
List<InjectExpectation> expectationAssets = this.injectExpectationService.expectationsForAssets(
expectationAssetGroup.getInject(), expectationAssetGroup.getAssetGroup(), expectationAssetGroup.getType()
);
// Every expectation assets are filled
if (expectationAssets.stream().noneMatch(e -> e.getResults().isEmpty())) {
this.injectExpectationService.computeExpectationGroup(
expectationAssetGroup,
expectationAssets,
this.config.getId(),
"collector",
PRODUCT_NAME
);
}
}));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,13 @@

public class ExpectationUtils {

public static boolean isExpired(@NotNull final InjectExpectation expectation, final int expirationTime) {
return expectation.getCreatedAt().isBefore(Instant.now().minus(expirationTime, ChronoUnit.MINUTES));
private ExpectationUtils() {

}

public static boolean isExpired(@NotNull final InjectExpectation expectation) {
Instant expirationTime = Instant.now().minus(expectation.getExpirationTime() / 60, ChronoUnit.MINUTES);
return expectation.getCreatedAt().isBefore(expirationTime);
}

public static String computeFailedMessage(@NotNull final EXPECTATION_TYPE expectationType) {
Expand Down
Loading

0 comments on commit 24bd966

Please sign in to comment.