-
Notifications
You must be signed in to change notification settings - Fork 194
[backend/frontend] feat(scv): implement Security Domains Icon Bar (#4284) #4651
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
Open
GaetanSantucci
wants to merge
15
commits into
release/current
Choose a base branch
from
issue/4284
base: release/current
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
968343f
[frontend|backend]feat(dashboards):Display and interact with Security…
johanah29 8b8114c
Implement IconBar
GaetanSantucci 3a107b5
WIP
GaetanSantucci f508a5b
remove InjectorContractSwitchFilter
GaetanSantucci 3815a95
improve domain count
GaetanSantucci 70d38dc
improve iconbar
GaetanSantucci 9fd6423
Add test for domain count
GaetanSantucci 6b7f99c
fix lint
GaetanSantucci cf39fc6
clean code
GaetanSantucci 8d4bd81
fix test
GaetanSantucci 1c50595
fix variable use
GaetanSantucci b1846be
improve some code
GaetanSantucci ed09349
fix linter
GaetanSantucci 315eaf9
generate api types
GaetanSantucci 0fcc5d9
clean code
GaetanSantucci File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
55 changes: 55 additions & 0 deletions
55
...i/src/main/java/io/openaev/rest/injector_contract/InjectorContractDomainStatsService.java
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| package io.openaev.rest.injector_contract; | ||
|
|
||
| import io.openaev.database.model.Domain; | ||
| import io.openaev.database.model.InjectorContract; | ||
| import io.openaev.database.specification.InjectorContractSpecification; | ||
| import io.openaev.rest.injector_contract.input.InjectorContractSearchPaginationInput; | ||
| import io.openaev.rest.injector_contract.output.InjectorContractDomainCountOutput; | ||
| import io.openaev.service.UserService; | ||
| import jakarta.persistence.EntityManager; | ||
| import jakarta.persistence.PersistenceContext; | ||
| import jakarta.persistence.Tuple; | ||
| import jakarta.persistence.criteria.*; | ||
| import java.util.List; | ||
| import lombok.RequiredArgsConstructor; | ||
| import org.springframework.data.jpa.domain.Specification; | ||
| import org.springframework.stereotype.Service; | ||
|
|
||
| @Service | ||
| @RequiredArgsConstructor | ||
| public class InjectorContractDomainStatsService { | ||
|
|
||
| @PersistenceContext private final EntityManager entityManager; | ||
|
|
||
| private final UserService userService; | ||
|
|
||
| public List<InjectorContractDomainCountOutput> countByDomain( | ||
| InjectorContractSearchPaginationInput input) { | ||
|
|
||
| CriteriaBuilder cb = entityManager.getCriteriaBuilder(); | ||
| CriteriaQuery<Tuple> cq = cb.createTupleQuery(); | ||
| Root<InjectorContract> root = cq.from(InjectorContract.class); | ||
|
|
||
| Specification<InjectorContract> spec = | ||
| InjectorContractSpecification.hasAccessToInjectorContract(userService.currentUser()); | ||
|
|
||
| Predicate predicate = spec.toPredicate(root, cq, cb); | ||
| if (predicate != null) { | ||
| cq.where(predicate); | ||
| } | ||
|
|
||
| Join<InjectorContract, Domain> domainJoin = root.join("domains", JoinType.LEFT); | ||
|
|
||
| cq.multiselect( | ||
| domainJoin.get("id").alias("domainId"), | ||
| cb.countDistinct(root.get("id")).alias("contractCount")) | ||
| .groupBy(domainJoin.get("id")); | ||
|
|
||
| return entityManager.createQuery(cq).getResultList().stream() | ||
| .map( | ||
| t -> | ||
| new InjectorContractDomainCountOutput( | ||
| t.get("domainId", String.class), t.get("contractCount", Long.class))) | ||
| .toList(); | ||
| } | ||
| } |
This file contains hidden or 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
29 changes: 29 additions & 0 deletions
29
...main/java/io/openaev/rest/injector_contract/output/InjectorContractDomainCountOutput.java
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| package io.openaev.rest.injector_contract.output; | ||
|
|
||
| import com.fasterxml.jackson.annotation.JsonProperty; | ||
| import io.swagger.v3.oas.annotations.media.Schema; | ||
| import jakarta.validation.constraints.NotBlank; | ||
| import jakarta.validation.constraints.NotNull; | ||
| import lombok.Getter; | ||
| import lombok.NoArgsConstructor; | ||
| import lombok.Setter; | ||
|
|
||
| @Getter | ||
| @Setter | ||
| @NoArgsConstructor | ||
| public class InjectorContractDomainCountOutput { | ||
| @NotBlank | ||
| @JsonProperty("domain") | ||
| @Schema(description = "The domain name extracted from OpenAEV", example = "Endpoints") | ||
| private String domain; | ||
|
|
||
| @NotNull | ||
| @JsonProperty("count") | ||
| @Schema(description = "Total number of observations linked to this domain", example = "42") | ||
| private Long count; | ||
GaetanSantucci marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| public InjectorContractDomainCountOutput(String domain, Long count) { | ||
| this.domain = domain; | ||
| this.count = count; | ||
| } | ||
| } | ||
17 changes: 17 additions & 0 deletions
17
.../src/main/java/io/openaev/rest/injector_contract/output/InjectorContractSearchResult.java
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| package io.openaev.rest.injector_contract.output; | ||
|
|
||
| import java.util.List; | ||
| import java.util.Map; | ||
| import lombok.Data; | ||
|
|
||
| @Data | ||
| public class InjectorContractSearchResult { | ||
| private List<InjectorContractFullOutput> contracts; | ||
| private Map<String, Long> injectorContractDomainCounts; | ||
|
|
||
| public InjectorContractSearchResult( | ||
| List<InjectorContractFullOutput> contracts, Map<String, Long> domainCounts) { | ||
| this.contracts = contracts; | ||
| this.injectorContractDomainCounts = domainCounts; | ||
| } | ||
| } | ||
|
Comment on lines
+7
to
+17
|
||
This file contains hidden or 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 was deleted.
Oops, something went wrong.
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| import { type Dispatch } from 'redux'; | ||
|
|
||
| import { delReferential, getReferential, postReferential, putReferential, simpleCall, simplePostCall } from '../utils/Action'; | ||
| import { | ||
| type InjectorContract, | ||
| type InjectorContractAddInput, | ||
| type InjectorContractUpdateInput, | ||
| type InjectorContractUpdateMappingInput, | ||
| type SearchPaginationInput, | ||
| } from '../utils/api-types'; | ||
| import * as schema from './Schema'; | ||
|
|
||
| const INJECTOR_CONTRACT_URI = '/api/injector_contracts'; | ||
|
|
||
| export const fetchInjectorContract = (injectorContractId: InjectorContract['injector_contract_id']) => (dispatch: Dispatch) => { | ||
| return getReferential(schema.injectorContract, `${INJECTOR_CONTRACT_URI}/${injectorContractId}`)(dispatch); | ||
| }; | ||
|
|
||
| export const directFetchInjectorContract = (injectorContractId: InjectorContract['injector_contract_id']) => { | ||
| return simpleCall(`${INJECTOR_CONTRACT_URI}/${injectorContractId}`); | ||
| }; | ||
|
|
||
| export const fetchInjectorsContracts = () => (dispatch: Dispatch) => { | ||
| return getReferential(schema.arrayOfInjectorContracts, `${INJECTOR_CONTRACT_URI}`)(dispatch); | ||
| }; | ||
|
|
||
| export const searchInjectorContracts = (paginationInput: SearchPaginationInput) => { | ||
| const data = paginationInput; | ||
| const uri = `${INJECTOR_CONTRACT_URI}/search`; | ||
| return simplePostCall(uri, data); | ||
| }; | ||
|
|
||
| export const updateInjectorContract = (injectorContractId: InjectorContract['injector_contract_id'], data: InjectorContractUpdateInput) => (dispatch: Dispatch) => { | ||
| return putReferential(schema.injectorContract, `${INJECTOR_CONTRACT_URI}/${injectorContractId}`, data)(dispatch); | ||
| }; | ||
|
|
||
| export const updateInjectorContractMapping = (injectorContractId: InjectorContract['injector_contract_id'], data: InjectorContractUpdateMappingInput) => (dispatch: Dispatch) => { | ||
| const uri = `${INJECTOR_CONTRACT_URI}/${injectorContractId}/mapping`; | ||
| return putReferential(schema.injectorContract, uri, data)(dispatch); | ||
| }; | ||
|
|
||
| export const addInjectorContract = (data: InjectorContractAddInput) => (dispatch: Dispatch) => { | ||
| return postReferential(schema.injectorContract, `${INJECTOR_CONTRACT_URI}`, data)(dispatch); | ||
| }; | ||
|
|
||
| // This action must use InjectorContractSearchPaginationInput to stay | ||
| // synchronized with the search route filters | ||
| export const fetchDomainCounts = (data: SearchPaginationInput) => { | ||
| const uri = `${INJECTOR_CONTRACT_URI}/domain-counts`; | ||
| return simplePostCall(uri, data); | ||
| }; | ||
|
|
||
| export const deleteInjectorContract = (injectorContractId: InjectorContract['injector_contract_id']) => (dispatch: Dispatch) => { | ||
| return delReferential(`${INJECTOR_CONTRACT_URI}/${injectorContractId}`, 'injectorcontracts', injectorContractId)(dispatch); | ||
| }; |
This file contains hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.