Skip to content

Commit

Permalink
[backend] wip
Browse files Browse the repository at this point in the history
  • Loading branch information
savacano28 committed Oct 3, 2024
1 parent 1952a29 commit e8455f5
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -504,9 +504,7 @@ public static List<InjectTargetWithResult> getTargetsWithResultsWithRawQueries(f
.toList());
}

List<String> injectAssetIds = inject.getInject_assets().stream()
.map(RawAsset::getAsset_id)
.collect(Collectors.toList());
List<String> injectAssetIds = inject.getInject_assets();

assetsToRefine.removeAll(
assetsToRemove
Expand Down
9 changes: 7 additions & 2 deletions openbas-api/src/main/java/io/openbas/utils/ResultUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@
import io.openbas.database.model.Inject;
import io.openbas.database.model.InjectExpectation;
import io.openbas.database.raw.RawInjectExpectationForCompute;
import io.openbas.database.raw.RawTeam;
import io.openbas.database.repository.InjectExpectationRepository;
import io.openbas.database.repository.InjectRepository;
import io.openbas.database.repository.TeamRepository;
import io.openbas.rest.atomic_testing.form.InjectTargetWithResult;
import io.openbas.rest.inject.form.InjectExpectationResultsByAttackPattern;
import io.openbas.utils.AtomicTestingMapper.ExpectationResultsByType;
Expand Down Expand Up @@ -68,9 +70,12 @@ public static List<InjectTargetWithResult> computeTargetResults(@NotNull List<In
.toList();
}

public static List<InjectTargetWithResult> computeTargetResultsWithRawExercise(@NotNull List<Inject> injects, InjectRepository injectRepository, InjectExpectationRepository injectExpectationRepository) {
public static List<InjectTargetWithResult> computeTargetResultsWithRawExercise(@NotNull List<Inject> injects, InjectRepository injectRepository, InjectExpectationRepository injectExpectationRepository, TeamRepository teamRepository) {
List<String> injectIds = injects.stream().map(Inject::getId).toList();
Map<String, RawTeam> teamMap = teamRepository.rawTeamByInjectIds(injectIds).stream().collect(Collectors.toMap(RawTeam::getTeam_id, team -> team));

return injects.stream()
.flatMap(inject -> getTargetsWithResultsWithRawQueries(inject.getId(), injectRepository, injectExpectationRepository).stream())
.flatMap(inject -> getTargetsWithResultsWithRawQueries(inject.getId(), injectRepository, injectExpectationRepository, teamMap, mapAssets, mapAssetsGroups).stream())
.distinct()
.toList();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,12 @@ public interface TeamRepository extends CrudRepository<Team, String>,
"WHERE team_id IN :ids ;", nativeQuery = true)
List<RawTeam> rawTeamByIds(@Param("ids") List<String> ids);

@Query(value="SELECT DISTINCT( team_id, team_name) "
+ "FROM teams t "
+ "LEFT JOIN injects_teams it ON t.team_id = it.team_id "
+ "WHERE it.inject_id IN :ids ;", nativeQuery = true)
List<RawTeam> rawTeamByInjectIds(@Param("ids") List<String> ids);

@Query(value="SELECT teams.team_id, teams.team_name, teams.team_description, teams.team_created_at, teams.team_updated_at, teams.team_organization, " +
" team_contextual, " +
" coalesce(array_agg(DISTINCT teams_tags.tag_id) FILTER ( WHERE teams_tags.tag_id IS NOT NULL ), '{}') as team_tags, " +
Expand Down

0 comments on commit e8455f5

Please sign in to comment.