-
Notifications
You must be signed in to change notification settings - Fork 0
Move global filter utils #168
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
Tristan-WorkGH
wants to merge
7
commits into
main
Choose a base branch
from
move-global-filter-utils
base: main
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
7 commits
Select commit
Hold shift + click to select a range
9702607
prepare
Tristan-WorkGH 8c8839f
prepare
Tristan-WorkGH 5c0d577
Welcome to new endpoint
Tristan-WorkGH daf34bb
fix trailling slash handling
Tristan-WorkGH 6ba4ce9
Merge branch 'main' into move-global-filter-utils
FranckLecuyer 4f3d418
Add missing GlobalFilterController unit test
FranckLecuyer 0b384b6
change descr
dbraquart 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
136 changes: 44 additions & 92 deletions
136
src/main/java/org/gridsuite/filter/server/FilterService.java
Large diffs are not rendered by default.
Oops, something went wrong.
45 changes: 45 additions & 0 deletions
45
src/main/java/org/gridsuite/filter/server/GlobalFilterController.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,45 @@ | ||
package org.gridsuite.filter.server; | ||
|
||
import io.swagger.v3.oas.annotations.Operation; | ||
import io.swagger.v3.oas.annotations.Parameter; | ||
import io.swagger.v3.oas.annotations.responses.ApiResponse; | ||
import io.swagger.v3.oas.annotations.tags.Tag; | ||
import lombok.AllArgsConstructor; | ||
import org.gridsuite.filter.globalfilter.GlobalFilter; | ||
import org.gridsuite.filter.utils.EquipmentType; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.MediaType; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.lang.NonNull; | ||
import org.springframework.validation.annotation.Validated; | ||
import org.springframework.web.bind.annotation.*; | ||
import org.springframework.web.client.HttpClientErrorException; | ||
|
||
import java.util.List; | ||
import java.util.UUID; | ||
|
||
@Validated | ||
@RestController | ||
@RequestMapping(value = "/" + FilterApi.API_VERSION + "/global-filter", | ||
produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE) | ||
@Tag(name = "GlobalFilter component controller") | ||
@AllArgsConstructor | ||
public class GlobalFilterController { | ||
private final GlobalFilterService service; | ||
|
||
@PostMapping(value = "") | ||
@Operation(summary = "Get network equipments IDs that match the filter(s)") | ||
@ApiResponse(responseCode = "200", description = "The list of matching elements IDs") | ||
@ApiResponse(responseCode = "400", description = "Invalid parameters") | ||
@ApiResponse(responseCode = "404", description = "The filter does not exists") | ||
public ResponseEntity<List<String>> getResults( | ||
@Parameter(description = "The network UUID") @RequestParam(name = "networkUuid") @NonNull final UUID networkUuid, | ||
@Parameter(description = "The variant ID of the network") @RequestParam(name = "variantId") @NonNull final String variantId, | ||
@Parameter(description = "The equipments types to filter and return") @RequestParam(name = "equipmentTypes") @NonNull final List<EquipmentType> equipmentTypes, | ||
@Parameter(description = "The filter(s) to apply") @RequestBody @NonNull final GlobalFilter filterParams) { | ||
if (filterParams.isEmpty()) { | ||
throw HttpClientErrorException.create(HttpStatus.BAD_REQUEST, "At least one filter must be specified.", null, null, null); | ||
} | ||
return ResponseEntity.ok(service.getFilteredIds(networkUuid, variantId, filterParams, equipmentTypes)); | ||
} | ||
} |
54 changes: 54 additions & 0 deletions
54
src/main/java/org/gridsuite/filter/server/GlobalFilterService.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,54 @@ | ||
package org.gridsuite.filter.server; | ||
|
||
import com.powsybl.commons.PowsyblException; | ||
import com.powsybl.iidm.network.Network; | ||
import com.powsybl.network.store.client.NetworkStoreService; | ||
import com.powsybl.network.store.client.PreloadingStrategy; | ||
import lombok.AllArgsConstructor; | ||
import lombok.NonNull; | ||
import org.gridsuite.filter.AbstractFilter; | ||
import org.gridsuite.filter.globalfilter.AbstractGlobalFilterService; | ||
import org.gridsuite.filter.globalfilter.GlobalFilter; | ||
import org.gridsuite.filter.utils.EquipmentType; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
import org.springframework.web.server.ResponseStatusException; | ||
|
||
import java.util.List; | ||
import java.util.UUID; | ||
|
||
@Service | ||
@AllArgsConstructor | ||
public class GlobalFilterService extends AbstractGlobalFilterService { | ||
private final NetworkStoreService networkStoreService; | ||
private final RepositoryService repositoriesService; | ||
|
||
/** {@inheritDoc} */ | ||
@Override | ||
protected Network getNetwork(@NonNull final UUID networkUuid, @NonNull final String variantId) { | ||
try { | ||
Network network = networkStoreService.getNetwork(networkUuid, PreloadingStrategy.COLLECTION); | ||
network.getVariantManager().setWorkingVariant(variantId); | ||
return network; | ||
} catch (final PowsyblException ex) { | ||
throw new ResponseStatusException(HttpStatus.NOT_FOUND, ex.getMessage()); | ||
} | ||
} | ||
|
||
/** {@inheritDoc} */ | ||
@Override | ||
@Transactional(readOnly = true) | ||
public List<AbstractFilter> getFilters(@NonNull final List<UUID> filtersUuids) { | ||
return this.repositoriesService.getFilters(filtersUuids); | ||
} | ||
|
||
/* Expose it publicly */ | ||
/** {@inheritDoc} */ | ||
@Override | ||
public List<String> getFilteredIds(@NonNull final UUID networkUuid, @NonNull final String variantId, | ||
@NonNull final GlobalFilter globalFilter, | ||
@NonNull final List<EquipmentType> equipmentTypes) { | ||
return super.getFilteredIds(networkUuid, variantId, globalFilter, equipmentTypes); | ||
} | ||
} |
98 changes: 98 additions & 0 deletions
98
src/main/java/org/gridsuite/filter/server/RepositoryService.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,98 @@ | ||
package org.gridsuite.filter.server; | ||
|
||
import lombok.Getter; | ||
import lombok.NonNull; | ||
import org.apache.commons.collections4.ListUtils; | ||
import org.gridsuite.filter.AbstractFilter; | ||
import org.gridsuite.filter.FilterLoader; | ||
import org.gridsuite.filter.server.dto.FilterAttributes; | ||
import org.gridsuite.filter.server.repositories.expertfilter.ExpertFilterRepository; | ||
import org.gridsuite.filter.server.repositories.identifierlistfilter.IdentifierListFilterRepository; | ||
import org.gridsuite.filter.server.repositories.proxies.AbstractFilterRepositoryProxy; | ||
import org.gridsuite.filter.server.repositories.proxies.expertfiler.ExpertFilterRepositoryProxy; | ||
import org.gridsuite.filter.server.repositories.proxies.identifierlistfilter.IdentifierListFilterRepositoryProxy; | ||
import org.gridsuite.filter.utils.FilterType; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.Optional; | ||
import java.util.UUID; | ||
import java.util.stream.Stream; | ||
|
||
/** | ||
* More an utility service to call a methode on all {@link AbstractFilterRepositoryProxy repositories} | ||
* and merge the result. | ||
*/ | ||
@Service | ||
public class RepositoryService { | ||
private final IdentifierListFilterRepositoryProxy identifierListFilterProxy; | ||
private final ExpertFilterRepositoryProxy expertFilterProxy; | ||
@Getter private final FilterLoader filterLoader; | ||
|
||
public RepositoryService(final IdentifierListFilterRepository identifierListFilterRepository, | ||
final ExpertFilterRepository expertFilterRepository) { | ||
this.identifierListFilterProxy = new IdentifierListFilterRepositoryProxy(identifierListFilterRepository); | ||
this.expertFilterProxy = new ExpertFilterRepositoryProxy(expertFilterRepository); | ||
this.filterLoader = new FilterLoaderImpl(Map.of( | ||
FilterType.IDENTIFIER_LIST.name(), this.identifierListFilterProxy, | ||
FilterType.EXPERT.name(), this.expertFilterProxy | ||
)); | ||
} | ||
|
||
public AbstractFilterRepositoryProxy<?, ?> getRepositoryFromType(@NonNull final FilterType type) { | ||
return switch (type) { | ||
case IDENTIFIER_LIST -> identifierListFilterProxy; | ||
case EXPERT -> expertFilterProxy; | ||
}; | ||
} | ||
|
||
public AbstractFilterRepositoryProxy<?, ?> getRepositoryFromType(@NonNull final AbstractFilter filter) { | ||
return this.getRepositoryFromType(filter.getType()); | ||
} | ||
|
||
/** @see AbstractFilterRepositoryProxy#deleteById(UUID) */ | ||
public boolean deleteFilter(@NonNull final UUID id) { | ||
return this.identifierListFilterProxy.deleteById(id) || this.expertFilterProxy.deleteById(id); | ||
} | ||
|
||
/** @see AbstractFilterRepositoryProxy#deleteAllByIds(List) */ | ||
public void deleteFilters(@NonNull final List<UUID> ids) { | ||
this.identifierListFilterProxy.deleteAllByIds(ids); | ||
this.expertFilterProxy.deleteAllByIds(ids); | ||
} | ||
|
||
/** @see AbstractFilterRepositoryProxy#deleteAll() */ | ||
public void deleteAll() { | ||
this.identifierListFilterProxy.deleteAll(); | ||
this.expertFilterProxy.deleteAll(); | ||
} | ||
|
||
/** @see AbstractFilterRepositoryProxy#getFiltersAttributes() */ | ||
@Transactional(readOnly = true) | ||
public Stream<FilterAttributes> getFiltersAttributes() { | ||
return Stream.concat(this.identifierListFilterProxy.getFiltersAttributes(), this.expertFilterProxy.getFiltersAttributes()); | ||
} | ||
|
||
/** @see AbstractFilterRepositoryProxy#getFiltersAttributes(List) */ | ||
@Transactional(readOnly = true) | ||
public Stream<FilterAttributes> getFiltersAttributes(@NonNull final List<UUID> ids) { | ||
return Stream.concat(this.identifierListFilterProxy.getFiltersAttributes(ids), this.expertFilterProxy.getFiltersAttributes(ids)); | ||
} | ||
|
||
/** @see AbstractFilterRepositoryProxy#getFilters(List) */ | ||
@Transactional(readOnly = true) | ||
public List<AbstractFilter> getFilters(@NonNull final List<UUID> ids) { | ||
return ListUtils.union( | ||
this.identifierListFilterProxy.getFilters(ids), | ||
this.expertFilterProxy.getFilters(ids) | ||
); | ||
} | ||
|
||
/** @see AbstractFilterRepositoryProxy#getFilter(UUID) */ | ||
@Transactional(readOnly = true) | ||
public Optional<AbstractFilter> getFilter(@NonNull final UUID id) { | ||
return this.identifierListFilterProxy.getFilter(id).or(() -> this.expertFilterProxy.getFilter(id)); | ||
} | ||
} |
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 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 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 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.
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.