Skip to content

Commit

Permalink
add short-circuit parameters element type (#93)
Browse files Browse the repository at this point in the history
Signed-off-by: David BRAQUART <[email protected]>
  • Loading branch information
dbraquart authored Jun 27, 2024
1 parent 72cd150 commit b21bd3d
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ public class DirectoryService implements IDirectoryElementsService {
private static final String ELEMENTS_SERVER_ROOT_PATH = DELIMITER + DIRECTORY_SERVER_API_VERSION + DELIMITER
+ "elements";

private static final String ELEMENTS_SERVER_ELEMENT_PATH = ELEMENTS_SERVER_ROOT_PATH + DELIMITER
+ "{elementUuid}";

private static final String PARAM_IDS = "ids";
private static final String PARAM_FOR_DELETION = "forDeletion";

Expand All @@ -53,17 +56,19 @@ public DirectoryService(
CaseService caseService, ParametersService parametersService, RestTemplate restTemplate, RemoteServicesProperties remoteServicesProperties) {
this.directoryServerBaseUri = remoteServicesProperties.getServiceUri("directory-server");
this.restTemplate = restTemplate;
this.genericServices = Map.of(
FILTER, filterService,
CONTINGENCY_LIST, contingencyListService,
STUDY, studyService,
DIRECTORY, this,
MODIFICATION, networkModificationService,
CASE, caseService,
ParametersType.VOLTAGE_INIT_PARAMETERS.name(), parametersService,
ParametersType.SECURITY_ANALYSIS_PARAMETERS.name(), parametersService,
ParametersType.LOADFLOW_PARAMETERS.name(), parametersService,
ParametersType.SENSITIVITY_PARAMETERS.name(), parametersService);
this.genericServices = Map.ofEntries(
Map.entry(FILTER, filterService),
Map.entry(CONTINGENCY_LIST, contingencyListService),
Map.entry(STUDY, studyService),
Map.entry(DIRECTORY, this),
Map.entry(MODIFICATION, networkModificationService),
Map.entry(CASE, caseService),
Map.entry(ParametersType.VOLTAGE_INIT_PARAMETERS.name(), parametersService),
Map.entry(ParametersType.SECURITY_ANALYSIS_PARAMETERS.name(), parametersService),
Map.entry(ParametersType.LOADFLOW_PARAMETERS.name(), parametersService),
Map.entry(ParametersType.SENSITIVITY_PARAMETERS.name(), parametersService),
Map.entry(ParametersType.SHORT_CIRCUIT_PARAMETERS.name(), parametersService)
);
}

public void setDirectoryServerBaseUri(String directoryServerBaseUri) {
Expand Down Expand Up @@ -108,7 +113,7 @@ public ElementAttributes duplicateElement(UUID elementUuid, UUID newElementUuid,

public void deleteDirectoryElement(UUID elementUuid, String userId) {
String path = UriComponentsBuilder
.fromPath(ELEMENTS_SERVER_ROOT_PATH + "/{elementUuid}")
.fromPath(ELEMENTS_SERVER_ELEMENT_PATH)
.buildAndExpand(elementUuid)
.toUriString();
HttpHeaders headers = new HttpHeaders();
Expand Down Expand Up @@ -162,7 +167,7 @@ public void deleteElementsFromDirectory(List<UUID> elementUuids, UUID parentDire

public ElementAttributes getElementInfos(UUID elementUuid) {
String path = UriComponentsBuilder
.fromPath(ELEMENTS_SERVER_ROOT_PATH + "/{elementUuid}")
.fromPath(ELEMENTS_SERVER_ELEMENT_PATH)
.buildAndExpand(elementUuid)
.toUriString();
return restTemplate.exchange(directoryServerBaseUri + path, HttpMethod.GET, null, ElementAttributes.class)
Expand All @@ -181,11 +186,7 @@ private List<ElementAttributes> getElementsInfos(List<UUID> elementsUuids, List<
elementAttributesList = restTemplate.exchange(directoryServerBaseUri + path, HttpMethod.GET, null,
new ParameterizedTypeReference<List<ElementAttributes>>() {
}).getBody();
if (elementAttributesList != null) {
return elementAttributesList;
} else {
return Collections.emptyList();
}
return Objects.requireNonNullElse(elementAttributesList, Collections.emptyList());
}

public int getUserCasesCount(String userId) {
Expand All @@ -203,7 +204,7 @@ public int getUserCasesCount(String userId) {

public void notifyDirectoryChanged(UUID elementUuid, String userId) {
String path = UriComponentsBuilder
.fromPath(ELEMENTS_SERVER_ROOT_PATH + "/{elementUuid}/notification?type={update_directory}")
.fromPath(ELEMENTS_SERVER_ELEMENT_PATH + "/notification?type={update_directory}")
.buildAndExpand(elementUuid, NotificationType.UPDATE_DIRECTORY.name())
.toUriString();

Expand All @@ -223,11 +224,7 @@ private List<ElementAttributes> getDirectoryElements(UUID directoryUuid, String
new HttpEntity<>(headers), new ParameterizedTypeReference<List<ElementAttributes>>() {
}).getBody();

if (elementAttributesList != null) {
return elementAttributesList;
} else {
return Collections.emptyList();
}
return Objects.requireNonNullElse(elementAttributesList, Collections.emptyList());
}

public void deleteElement(UUID id, String userId) {
Expand Down Expand Up @@ -267,7 +264,7 @@ public List<ElementAttributes> getElementsMetadata(List<UUID> ids, List<String>

public void updateElement(UUID elementUuid, ElementAttributes elementAttributes, String userId) {
String path = UriComponentsBuilder
.fromPath(ELEMENTS_SERVER_ROOT_PATH + "/{elementUuid}")
.fromPath(ELEMENTS_SERVER_ELEMENT_PATH)
.buildAndExpand(elementUuid)
.toUriString();
HttpHeaders headers = new HttpHeaders();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ public class ParametersService implements IDirectoryElementsService {
private final Map<ParametersType, String> genericParametersServices = Map.of(ParametersType.VOLTAGE_INIT_PARAMETERS, "voltage-init-server",
ParametersType.SECURITY_ANALYSIS_PARAMETERS, "security-analysis-server",
ParametersType.LOADFLOW_PARAMETERS, "loadflow-server",
ParametersType.SENSITIVITY_PARAMETERS, "sensitivity-analysis-server");
ParametersType.SENSITIVITY_PARAMETERS, "sensitivity-analysis-server",
ParametersType.SHORT_CIRCUIT_PARAMETERS, "shortcircuit-server");

private RemoteServicesProperties remoteServicesProperties;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,6 @@ public enum ParametersType {
VOLTAGE_INIT_PARAMETERS,
SECURITY_ANALYSIS_PARAMETERS,
LOADFLOW_PARAMETERS,
SENSITIVITY_PARAMETERS
SENSITIVITY_PARAMETERS,
SHORT_CIRCUIT_PARAMETERS
}
3 changes: 3 additions & 0 deletions src/main/resources/application-local.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,7 @@ gridsuite:
-
name: user-admin-server
base-uri: http://localhost:5033
-
name: shortcircuit-server
base-uri: http://localhost:5031

0 comments on commit b21bd3d

Please sign in to comment.