-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[GridDyna] Using gridsuite filter library for mapping (#96)
- Loading branch information
Showing
59 changed files
with
2,346 additions
and
2,995 deletions.
There are no files selected for viewing
This file contains 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
34 changes: 34 additions & 0 deletions
34
src/main/java/org/gridsuite/mapping/server/DynamicMappingException.java
This file contains 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,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; | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
src/main/java/org/gridsuite/mapping/server/RestResponseEntityExceptionHandler.java
This file contains 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 |
---|---|---|
@@ -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()); | ||
}; | ||
} | ||
} |
This file contains 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
42 changes: 42 additions & 0 deletions
42
src/main/java/org/gridsuite/mapping/server/controller/ParameterController.java
This file contains 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,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)); | ||
} | ||
|
||
} |
90 changes: 0 additions & 90 deletions
90
src/main/java/org/gridsuite/mapping/server/controller/ScriptController.java
This file was deleted.
Oops, something went wrong.
This file contains 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
27 changes: 27 additions & 0 deletions
27
src/main/java/org/gridsuite/mapping/server/dto/ParameterFile.java
This file contains 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,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; | ||
|
||
} |
Oops, something went wrong.