Skip to content

Commit

Permalink
[GridDyna] Using gridsuite filter library for mapping (#96)
Browse files Browse the repository at this point in the history
  • Loading branch information
thangqp authored Jul 12, 2024
1 parent 48b9b0d commit 3acd796
Show file tree
Hide file tree
Showing 59 changed files with 2,346 additions and 2,995 deletions.
10 changes: 10 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,11 @@
<groupId>com.powsybl</groupId>
<artifactId>powsybl-ws-commons</artifactId>
</dependency>
<dependency>
<groupId>org.gridsuite</groupId>
<artifactId>gridsuite-filter</artifactId>
<version>1.0.9</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
Expand Down Expand Up @@ -175,5 +180,10 @@
<artifactId>h2</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.wiremock</groupId>
<artifactId>wiremock</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/**
* Copyright (c) 2024, RTE (http://www.rte-france.com)
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
package org.gridsuite.mapping.server;

import lombok.Getter;

/**
* @author Thang PHAM <quyet-thang.pham at rte-france.com>
*/
@Getter
public class DynamicMappingException extends RuntimeException {

public enum Type {
URI_SYNTAX,
MAPPING_NAME_NOT_PROVIDED,
GET_FILTER_ERROR,
CREATE_FILTER_ERROR,
UPDATE_FILTER_ERROR,
DUPLICATE_FILTER_ERROR,
DELETE_FILTER_ERROR,
FILTER_NOT_FOUND
}

private final Type type;

public DynamicMappingException(Type type, String message) {
super(message);
this.type = type;
}
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,52 @@
/*
* Copyright (c) 2024, RTE (http://www.rte-france.com)
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/

package org.gridsuite.mapping.server;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.client.HttpClientErrorException;

/**
* @author Thang PHAM <quyet-thang.pham at rte-france.com>
*/
@ControllerAdvice
public class RestResponseEntityExceptionHandler {

private static final Logger LOGGER = LoggerFactory.getLogger(RestResponseEntityExceptionHandler.class);

@ExceptionHandler(HttpClientErrorException.class)
protected ResponseEntity<Object> handleHttpClientErrorException(HttpClientErrorException exception) {
return ResponseEntity.status(exception.getStatusCode()).body(exception.getStatusText());
}

@ExceptionHandler(DynamicMappingException.class)
protected ResponseEntity<Object> handleDynamicSimulationException(DynamicMappingException exception) {
if (LOGGER.isErrorEnabled()) {
LOGGER.error(exception.getMessage(), exception);
}

DynamicMappingException.Type type = exception.getType();
return switch (type) {
case MAPPING_NAME_NOT_PROVIDED
-> ResponseEntity.status(HttpStatus.BAD_REQUEST).body(exception.getMessage());
case FILTER_NOT_FOUND
-> ResponseEntity.status(HttpStatus.NOT_FOUND).body(exception.getMessage());
case URI_SYNTAX,
GET_FILTER_ERROR,
CREATE_FILTER_ERROR,
UPDATE_FILTER_ERROR,
DUPLICATE_FILTER_ERROR,
DELETE_FILTER_ERROR
-> ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(exception.getMessage());
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
import org.gridsuite.mapping.server.dto.RenameObject;
import org.gridsuite.mapping.server.dto.models.Model;
import org.gridsuite.mapping.server.service.MappingService;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.http.*;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

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

@GetMapping(value = "/{mappingName}")
@Operation(summary = "Get a mapping by name")
@ApiResponses(value = {@ApiResponse(responseCode = "200", description = "The requested mapping")})
public ResponseEntity<InputMapping> getMapping(@PathVariable("mappingName") String mappingName) {
return ResponseEntity.ok().contentType(MediaType.APPLICATION_JSON).body(mappingService.getMapping(mappingName));
}

@GetMapping(value = "/{mappingName}/models")
@Operation(summary = "Get models used in the given mapping")
@ApiResponses(value = {@ApiResponse(responseCode = "200", description = "The list of mapped models")})
Expand All @@ -51,9 +58,9 @@ public ResponseEntity<List<Model>> getMappedModelsList(@PathVariable("mappingNam
@ApiResponses(value = {@ApiResponse(responseCode = "200", description = "The id of the mapping"),
@ApiResponse(responseCode = "409", description = "The mapping already exist"),
@ApiResponse(responseCode = "500", description = "The storage is down or a mapping with the same name already exists")})
public ResponseEntity<InputMapping> createMapping(@PathVariable("mappingName") String mappingName, @RequestBody InputMapping mapping) {
InputMapping createMapping = mappingService.createMapping(mappingName, mapping);
return ResponseEntity.ok().body(createMapping);
public ResponseEntity<InputMapping> saveMapping(@PathVariable(name = "mappingName", required = false) String mappingName, @RequestBody InputMapping mapping) {
InputMapping savedMapping = mappingService.saveMapping(mappingName, mapping);
return ResponseEntity.ok().body(savedMapping);
}

@DeleteMapping(path = "/{mappingName}")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/**
* Copyright (c) 2024, RTE (http://www.rte-france.com)
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
package org.gridsuite.mapping.server.controller;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.AllArgsConstructor;
import org.gridsuite.mapping.server.dto.ParameterFile;
import org.gridsuite.mapping.server.service.ParameterService;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
* @author Thang PHAM <quyet-thang.pham at rte-france.com>
*/
@RestController
@RequestMapping(value = "/parameters")
@Tag(name = "Mapping server")
@AllArgsConstructor
public class ParameterController {

private final ParameterService parameterService;

@GetMapping(value = "/export")
@Operation(summary = "Export parameter sets in used models of a given mapping into *.par format")
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "Used parameter sets serialized in *.par format")})
public ResponseEntity<ParameterFile> exportParameters(@RequestParam("mappingName") String mappingName) {
return ResponseEntity.ok().contentType(MediaType.APPLICATION_JSON).body(parameterService.exportParameters(mappingName));
}

}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ public class InputMapping implements Mapping {
@Schema(description = "Name")
private String name;

@Schema(description = "Mapping rules")
@Schema(description = "Rules")
private List<Rule> rules;

@Schema(description = "Mapping automata")
@Schema(description = "Automata")
private List<Automaton> automata;

@Schema(description = "Mapping should control its parameters")
Expand Down
27 changes: 27 additions & 0 deletions src/main/java/org/gridsuite/mapping/server/dto/ParameterFile.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/**
* Copyright (c) 2024, RTE (http://www.rte-france.com)
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
package org.gridsuite.mapping.server.dto;

import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor;
import lombok.Data;

/**
* @author Thang PHAM <quyet-thang.pham at rte-france.com>
*/
@Data
@Schema(description = "Parameter sets in *.par format")
@AllArgsConstructor
public class ParameterFile {

@Schema(description = "Name of the parent mapping")
private String mappingName;

@Schema(description = "Parameter file content in *.par format")
private String fileContent;

}
Loading

0 comments on commit 3acd796

Please sign in to comment.