Skip to content

Commit

Permalink
[backend] Improv performance on atomic testing pagination list
Browse files Browse the repository at this point in the history
  • Loading branch information
RomuDeuxfois committed Jun 14, 2024
1 parent e514184 commit c3f721c
Show file tree
Hide file tree
Showing 13 changed files with 459 additions and 298 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.openbas.rest.atomic_testing;

import io.openbas.aop.LogExecutionTime;
import io.openbas.database.model.Inject;
import io.openbas.database.model.InjectExpectation;
import io.openbas.inject_expectation.InjectExpectationService;
Expand All @@ -8,15 +9,16 @@
import io.openbas.rest.atomic_testing.form.InjectResultDTO;
import io.openbas.rest.exception.ElementNotFoundException;
import io.openbas.rest.helper.RestBehavior;
import io.openbas.rest.inject.output.AtomicTestingOutput;
import io.openbas.service.AtomicTestingService;
import io.openbas.utils.AtomicTestingMapper;
import io.openbas.utils.pagination.SearchPaginationInput;
import jakarta.transaction.Transactional;
import jakarta.validation.Valid;
import jakarta.validation.constraints.NotBlank;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Page;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

import java.util.List;
Expand All @@ -33,16 +35,11 @@ public class AtomicTestingApi extends RestBehavior {
private final InjectExpectationService injectExpectationService;

@PostMapping("/search")
public Page<InjectResultDTO> findAllAtomicTestings(
@LogExecutionTime
@Transactional(readOnly = true)
public Page<AtomicTestingOutput> findAllAtomicTestings(
@RequestBody @Valid final SearchPaginationInput searchPaginationInput) {
return this.atomicTestingService.findAllAtomicTestings(searchPaginationInput)
.map(inject -> AtomicTestingMapper.toDto(
inject, getTargets(
inject.getTeams(),
inject.getAssets(),
inject.getAssetGroups()
)
));
return this.atomicTestingService.findAllAtomicTestings(searchPaginationInput);
}

@GetMapping("/{injectId}")
Expand All @@ -53,7 +50,7 @@ public InjectResultDTO findAtomicTesting(@PathVariable String injectId) {
}

@PostMapping()
@Transactional(rollbackOn = Exception.class)
@Transactional(rollbackFor = Exception.class)
public InjectResultDTO createAtomicTesting(@Valid @RequestBody AtomicTestingInput input) {
Inject inject = this.atomicTestingService.createOrUpdate(input, null);
return AtomicTestingMapper.toDto(
Expand All @@ -66,7 +63,7 @@ inject, getTargets(
}

@PutMapping("/{injectId}")
@Transactional(rollbackOn = Exception.class)
@Transactional(rollbackFor = Exception.class)
public InjectResultDTO updateAtomicTesting(
@PathVariable @NotBlank final String injectId,
@Valid @RequestBody final AtomicTestingInput input) {
Expand Down Expand Up @@ -100,7 +97,7 @@ public List<InjectExpectation> findTargetResult(
}

@PutMapping("/{injectId}/tags")
@Transactional(rollbackOn = Exception.class)
@Transactional(rollbackFor = Exception.class)
public InjectResultDTO updateAtomicTestingTags(
@PathVariable @NotBlank final String injectId,
@Valid @RequestBody final AtomicTestingUpdateTagsInput input) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@
import jakarta.validation.constraints.NotNull;
import lombok.Data;

import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;
import java.util.*;

@Data
public class InjectOutput {
Expand Down Expand Up @@ -49,6 +47,15 @@ public class InjectOutput {
@JsonProperty("inject_type")
public String injectType;

@JsonProperty("inject_teams")
private List<String> teams;

@JsonProperty("inject_assets")
private List<String> assets;

@JsonProperty("inject_asset_groups")
private List<String> assetGroups;

public InjectOutput(
String id,
String title,
Expand All @@ -72,13 +79,18 @@ public InjectOutput(
this.dependsDuration = dependsDuration;
this.injectorContract = injectorContract;
this.tags = tags != null ? new HashSet<>(Arrays.asList(tags)) : new HashSet<>();

this.teams = teams != null ? new ArrayList<>(Arrays.asList(teams)) : new ArrayList<>();
this.assets = assets != null ? new ArrayList<>(Arrays.asList(assets)) : new ArrayList<>();
this.assetGroups = assetGroups != null ? new ArrayList<>(Arrays.asList(assetGroups)) : new ArrayList<>();

this.isReady = InjectModelHelper.isReady(
injectorContract,
content,
allTeams,
teams != null ? new HashSet<>(Arrays.asList(teams)) : new HashSet<>(),
assets != null ? new HashSet<>(Arrays.asList(assets)) : new HashSet<>(),
assetGroups != null ? new HashSet<>(Arrays.asList(assetGroups)) : new HashSet<>()
this.teams,
this.assets,
this.assetGroups
);
this.injectType = injectType;
}
Expand Down
Loading

0 comments on commit c3f721c

Please sign in to comment.