Skip to content

Commit 3acd796

Browse files
authored
[GridDyna] Using gridsuite filter library for mapping (#96)
1 parent 48b9b0d commit 3acd796

File tree

59 files changed

+2346
-2995
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+2346
-2995
lines changed

pom.xml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,11 @@
9696
<groupId>com.powsybl</groupId>
9797
<artifactId>powsybl-ws-commons</artifactId>
9898
</dependency>
99+
<dependency>
100+
<groupId>org.gridsuite</groupId>
101+
<artifactId>gridsuite-filter</artifactId>
102+
<version>1.0.9</version>
103+
</dependency>
99104
<dependency>
100105
<groupId>org.springframework.boot</groupId>
101106
<artifactId>spring-boot-starter-web</artifactId>
@@ -175,5 +180,10 @@
175180
<artifactId>h2</artifactId>
176181
<scope>test</scope>
177182
</dependency>
183+
<dependency>
184+
<groupId>org.wiremock</groupId>
185+
<artifactId>wiremock</artifactId>
186+
<scope>test</scope>
187+
</dependency>
178188
</dependencies>
179189
</project>
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/**
2+
* Copyright (c) 2024, RTE (http://www.rte-france.com)
3+
* This Source Code Form is subject to the terms of the Mozilla Public
4+
* License, v. 2.0. If a copy of the MPL was not distributed with this
5+
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
6+
*/
7+
package org.gridsuite.mapping.server;
8+
9+
import lombok.Getter;
10+
11+
/**
12+
* @author Thang PHAM <quyet-thang.pham at rte-france.com>
13+
*/
14+
@Getter
15+
public class DynamicMappingException extends RuntimeException {
16+
17+
public enum Type {
18+
URI_SYNTAX,
19+
MAPPING_NAME_NOT_PROVIDED,
20+
GET_FILTER_ERROR,
21+
CREATE_FILTER_ERROR,
22+
UPDATE_FILTER_ERROR,
23+
DUPLICATE_FILTER_ERROR,
24+
DELETE_FILTER_ERROR,
25+
FILTER_NOT_FOUND
26+
}
27+
28+
private final Type type;
29+
30+
public DynamicMappingException(Type type, String message) {
31+
super(message);
32+
this.type = type;
33+
}
34+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,52 @@
1+
/*
2+
* Copyright (c) 2024, RTE (http://www.rte-france.com)
3+
* This Source Code Form is subject to the terms of the Mozilla Public
4+
* License, v. 2.0. If a copy of the MPL was not distributed with this
5+
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
6+
*/
7+
18
package org.gridsuite.mapping.server;
29

10+
import org.slf4j.Logger;
11+
import org.slf4j.LoggerFactory;
12+
import org.springframework.http.HttpStatus;
313
import org.springframework.http.ResponseEntity;
414
import org.springframework.web.bind.annotation.ControllerAdvice;
515
import org.springframework.web.bind.annotation.ExceptionHandler;
616
import org.springframework.web.client.HttpClientErrorException;
717

18+
/**
19+
* @author Thang PHAM <quyet-thang.pham at rte-france.com>
20+
*/
821
@ControllerAdvice
922
public class RestResponseEntityExceptionHandler {
23+
24+
private static final Logger LOGGER = LoggerFactory.getLogger(RestResponseEntityExceptionHandler.class);
25+
1026
@ExceptionHandler(HttpClientErrorException.class)
1127
protected ResponseEntity<Object> handleHttpClientErrorException(HttpClientErrorException exception) {
1228
return ResponseEntity.status(exception.getStatusCode()).body(exception.getStatusText());
1329
}
30+
31+
@ExceptionHandler(DynamicMappingException.class)
32+
protected ResponseEntity<Object> handleDynamicSimulationException(DynamicMappingException exception) {
33+
if (LOGGER.isErrorEnabled()) {
34+
LOGGER.error(exception.getMessage(), exception);
35+
}
36+
37+
DynamicMappingException.Type type = exception.getType();
38+
return switch (type) {
39+
case MAPPING_NAME_NOT_PROVIDED
40+
-> ResponseEntity.status(HttpStatus.BAD_REQUEST).body(exception.getMessage());
41+
case FILTER_NOT_FOUND
42+
-> ResponseEntity.status(HttpStatus.NOT_FOUND).body(exception.getMessage());
43+
case URI_SYNTAX,
44+
GET_FILTER_ERROR,
45+
CREATE_FILTER_ERROR,
46+
UPDATE_FILTER_ERROR,
47+
DUPLICATE_FILTER_ERROR,
48+
DELETE_FILTER_ERROR
49+
-> ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(exception.getMessage());
50+
};
51+
}
1452
}

src/main/java/org/gridsuite/mapping/server/controller/MappingController.java

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515
import org.gridsuite.mapping.server.dto.RenameObject;
1616
import org.gridsuite.mapping.server.dto.models.Model;
1717
import org.gridsuite.mapping.server.service.MappingService;
18-
import org.springframework.web.bind.annotation.RequestMapping;
19-
import org.springframework.http.*;
18+
import org.springframework.http.MediaType;
19+
import org.springframework.http.ResponseEntity;
2020
import org.springframework.web.bind.annotation.*;
2121

2222
import java.util.List;
@@ -39,6 +39,13 @@ public ResponseEntity<List<InputMapping>> getMappingList() {
3939
return ResponseEntity.ok().contentType(MediaType.APPLICATION_JSON).body(mappingService.getMappingList());
4040
}
4141

42+
@GetMapping(value = "/{mappingName}")
43+
@Operation(summary = "Get a mapping by name")
44+
@ApiResponses(value = {@ApiResponse(responseCode = "200", description = "The requested mapping")})
45+
public ResponseEntity<InputMapping> getMapping(@PathVariable("mappingName") String mappingName) {
46+
return ResponseEntity.ok().contentType(MediaType.APPLICATION_JSON).body(mappingService.getMapping(mappingName));
47+
}
48+
4249
@GetMapping(value = "/{mappingName}/models")
4350
@Operation(summary = "Get models used in the given mapping")
4451
@ApiResponses(value = {@ApiResponse(responseCode = "200", description = "The list of mapped models")})
@@ -51,9 +58,9 @@ public ResponseEntity<List<Model>> getMappedModelsList(@PathVariable("mappingNam
5158
@ApiResponses(value = {@ApiResponse(responseCode = "200", description = "The id of the mapping"),
5259
@ApiResponse(responseCode = "409", description = "The mapping already exist"),
5360
@ApiResponse(responseCode = "500", description = "The storage is down or a mapping with the same name already exists")})
54-
public ResponseEntity<InputMapping> createMapping(@PathVariable("mappingName") String mappingName, @RequestBody InputMapping mapping) {
55-
InputMapping createMapping = mappingService.createMapping(mappingName, mapping);
56-
return ResponseEntity.ok().body(createMapping);
61+
public ResponseEntity<InputMapping> saveMapping(@PathVariable(name = "mappingName", required = false) String mappingName, @RequestBody InputMapping mapping) {
62+
InputMapping savedMapping = mappingService.saveMapping(mappingName, mapping);
63+
return ResponseEntity.ok().body(savedMapping);
5764
}
5865

5966
@DeleteMapping(path = "/{mappingName}")
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/**
2+
* Copyright (c) 2024, RTE (http://www.rte-france.com)
3+
* This Source Code Form is subject to the terms of the Mozilla Public
4+
* License, v. 2.0. If a copy of the MPL was not distributed with this
5+
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
6+
*/
7+
package org.gridsuite.mapping.server.controller;
8+
9+
import io.swagger.v3.oas.annotations.Operation;
10+
import io.swagger.v3.oas.annotations.responses.ApiResponse;
11+
import io.swagger.v3.oas.annotations.responses.ApiResponses;
12+
import io.swagger.v3.oas.annotations.tags.Tag;
13+
import lombok.AllArgsConstructor;
14+
import org.gridsuite.mapping.server.dto.ParameterFile;
15+
import org.gridsuite.mapping.server.service.ParameterService;
16+
import org.springframework.http.MediaType;
17+
import org.springframework.http.ResponseEntity;
18+
import org.springframework.web.bind.annotation.GetMapping;
19+
import org.springframework.web.bind.annotation.RequestMapping;
20+
import org.springframework.web.bind.annotation.RequestParam;
21+
import org.springframework.web.bind.annotation.RestController;
22+
23+
/**
24+
* @author Thang PHAM <quyet-thang.pham at rte-france.com>
25+
*/
26+
@RestController
27+
@RequestMapping(value = "/parameters")
28+
@Tag(name = "Mapping server")
29+
@AllArgsConstructor
30+
public class ParameterController {
31+
32+
private final ParameterService parameterService;
33+
34+
@GetMapping(value = "/export")
35+
@Operation(summary = "Export parameter sets in used models of a given mapping into *.par format")
36+
@ApiResponses(value = {
37+
@ApiResponse(responseCode = "200", description = "Used parameter sets serialized in *.par format")})
38+
public ResponseEntity<ParameterFile> exportParameters(@RequestParam("mappingName") String mappingName) {
39+
return ResponseEntity.ok().contentType(MediaType.APPLICATION_JSON).body(parameterService.exportParameters(mappingName));
40+
}
41+
42+
}

src/main/java/org/gridsuite/mapping/server/controller/ScriptController.java

Lines changed: 0 additions & 90 deletions
This file was deleted.

src/main/java/org/gridsuite/mapping/server/dto/InputMapping.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,10 @@ public class InputMapping implements Mapping {
2828
@Schema(description = "Name")
2929
private String name;
3030

31-
@Schema(description = "Mapping rules")
31+
@Schema(description = "Rules")
3232
private List<Rule> rules;
3333

34-
@Schema(description = "Mapping automata")
34+
@Schema(description = "Automata")
3535
private List<Automaton> automata;
3636

3737
@Schema(description = "Mapping should control its parameters")
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/**
2+
* Copyright (c) 2024, RTE (http://www.rte-france.com)
3+
* This Source Code Form is subject to the terms of the Mozilla Public
4+
* License, v. 2.0. If a copy of the MPL was not distributed with this
5+
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
6+
*/
7+
package org.gridsuite.mapping.server.dto;
8+
9+
import io.swagger.v3.oas.annotations.media.Schema;
10+
import lombok.AllArgsConstructor;
11+
import lombok.Data;
12+
13+
/**
14+
* @author Thang PHAM <quyet-thang.pham at rte-france.com>
15+
*/
16+
@Data
17+
@Schema(description = "Parameter sets in *.par format")
18+
@AllArgsConstructor
19+
public class ParameterFile {
20+
21+
@Schema(description = "Name of the parent mapping")
22+
private String mappingName;
23+
24+
@Schema(description = "Parameter file content in *.par format")
25+
private String fileContent;
26+
27+
}

0 commit comments

Comments
 (0)