-
Notifications
You must be signed in to change notification settings - Fork 87
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[backend/frontend] Add quick filters on scenarios, simulations and at…
…omic testing (#1294)
- Loading branch information
1 parent
2e610f0
commit 5d40676
Showing
68 changed files
with
1,813 additions
and
1,065 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 0 additions & 36 deletions
36
openbas-api/src/main/java/io/openbas/rest/exercise/utils/ExerciseUtils.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 0 additions & 36 deletions
36
openbas-api/src/main/java/io/openbas/rest/injector_contract/utils/InjectorContractUtils.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 35 additions & 14 deletions
49
openbas-api/src/main/java/io/openbas/rest/scenario/utils/ScenarioUtils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,57 @@ | ||
package io.openbas.rest.scenario.utils; | ||
|
||
import io.openbas.database.model.Filters; | ||
import io.openbas.database.model.Scenario; | ||
import io.openbas.utils.CustomFilterUtils; | ||
import io.openbas.database.specification.ScenarioSpecification; | ||
import io.openbas.utils.pagination.SearchPaginationInput; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.springframework.data.jpa.domain.Specification; | ||
|
||
import java.util.Collections; | ||
import java.util.Map; | ||
import java.util.Optional; | ||
import java.util.function.Function; | ||
import java.util.function.UnaryOperator; | ||
|
||
public class ScenarioUtils { | ||
import static io.openbas.utils.CustomFilterUtils.computeMode; | ||
import static java.util.Optional.ofNullable; | ||
|
||
private static final String SCENARIO_KILL_CHAIN_PHASES_FILTER = "scenario_kill_chain_phases"; | ||
private static final Map<String, String> CORRESPONDENCE_MAP = Collections.singletonMap( | ||
SCENARIO_KILL_CHAIN_PHASES_FILTER, "injects.injectorContract.attackPatterns.killChainPhases.id" | ||
); | ||
public class ScenarioUtils { | ||
|
||
private ScenarioUtils() { | ||
|
||
} | ||
|
||
private static final String SCENARIO_RECURRENCE_FILTER = "scenario_recurrence"; | ||
|
||
/** | ||
* Manage filters that are not directly managed by the generic mechanics -> scenario_kill_chain_phases | ||
*/ | ||
public static UnaryOperator<Specification<Scenario>> handleCustomFilter( | ||
public static Function<Specification<Scenario>, Specification<Scenario>> handleDeepFilter( | ||
@NotNull final SearchPaginationInput searchPaginationInput) { | ||
return handleCustomFilter(searchPaginationInput); | ||
} | ||
|
||
private static UnaryOperator<Specification<Scenario>> handleCustomFilter( | ||
@NotNull final SearchPaginationInput searchPaginationInput) { | ||
return CustomFilterUtils.handleCustomFilter( | ||
searchPaginationInput, | ||
SCENARIO_KILL_CHAIN_PHASES_FILTER, | ||
CORRESPONDENCE_MAP | ||
); | ||
// Existence of the filter | ||
Optional<Filters.Filter> scenarioRecurrenceFilterOpt = ofNullable(searchPaginationInput.getFilterGroup()) | ||
.flatMap(f -> f.findByKey(SCENARIO_RECURRENCE_FILTER)); | ||
|
||
if (scenarioRecurrenceFilterOpt.isPresent()) { | ||
// Purge filter | ||
searchPaginationInput.getFilterGroup().removeByKey(SCENARIO_RECURRENCE_FILTER); | ||
Specification<Scenario> customSpecification = null; | ||
if (scenarioRecurrenceFilterOpt.get().getValues().contains("Scheduled")) { | ||
customSpecification = ScenarioSpecification.isRecurring(); | ||
} else if (scenarioRecurrenceFilterOpt.get().getValues().contains("Not planned")) { | ||
customSpecification = ScenarioSpecification.noRecurring(); | ||
} | ||
if (customSpecification != null) { | ||
return computeMode(searchPaginationInput, customSpecification); | ||
} | ||
return (Specification<Scenario> specification) -> specification; | ||
} else { | ||
return (Specification<Scenario> specification) -> specification; | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.