Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@

<properties>
<powsybl-ws-dependencies.version>2.25.0</powsybl-ws-dependencies.version>
<powsybl-ws-commons.version>1.28.1</powsybl-ws-commons.version>
<powsybl-ws-commons.version>1.30.0</powsybl-ws-commons.version>

<gridsuite-filter.version>1.6.0</gridsuite-filter.version>

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/**
* Copyright (c) 2025, 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.computation;

import com.powsybl.ws.commons.error.BusinessErrorCode;

public enum ComputationBusinessErrorCode implements BusinessErrorCode {
RESULT_NOT_FOUND("computation.resultNotFound"),
INVALID_FILTER_FORMAT("computation.invalidFilterFormat"),
INVALID_SORT_FORMAT("computation.invalidSortFormat"),
INVALID_FILTER("computation.invalidFilter"),
NETWORK_NOT_FOUND("computation.networkNotFound"),
PARAMETERS_NOT_FOUND("computation.parametersNotFound"),
FILE_EXPORT_ERROR("computation.fileExportError"),
EVALUATE_FILTER_FAILED("computation.evaluateFilterFailed"),
LIMIT_REDUCTION_CONFIG_ERROR("computation.limitReductionConfigError"),
SPECIFIC("computation.specific"),;

private final String code;

ComputationBusinessErrorCode(String code) {
this.code = code;
}

public String value() {
return code;
}
}
46 changes: 13 additions & 33 deletions src/main/java/org/gridsuite/computation/ComputationException.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,58 +6,38 @@
*/
package org.gridsuite.computation;

import com.powsybl.ws.commons.error.AbstractBusinessException;
import lombok.Getter;
import lombok.NonNull;

import java.util.Objects;

/**
* @author Anis Touri <anis.touri at rte-france.com>
*/
@Getter
public class ComputationException extends RuntimeException {
public enum Type {
RESULT_NOT_FOUND("Result not found."),
INVALID_FILTER_FORMAT("The filter format is invalid."),
INVALID_SORT_FORMAT("The sort format is invalid"),
INVALID_FILTER("Invalid filter"),
NETWORK_NOT_FOUND("Network not found"),
PARAMETERS_NOT_FOUND("Computation parameters not found"),
FILE_EXPORT_ERROR("Error exporting the file"),
EVALUATE_FILTER_FAILED("Error evaluating the file"),
LIMIT_REDUCTION_CONFIG_ERROR("Error int the configuration of the limit reduction"),
SPECIFIC("Unknown error during the computation");

private final String defaultMessage;

Type(String defaultMessage) {
this.defaultMessage = defaultMessage;
}
}

private final Type exceptionType;
public class ComputationException extends AbstractBusinessException {

public ComputationException(Type exceptionType) {
super(Objects.requireNonNull(exceptionType.defaultMessage));
this.exceptionType = Objects.requireNonNull(exceptionType);
}
private final ComputationBusinessErrorCode errorCode;

public ComputationException(String message) {
super(message);
this.exceptionType = Type.SPECIFIC;
this.errorCode = ComputationBusinessErrorCode.SPECIFIC;
}

public ComputationException(String message, Throwable cause) {
super(message, cause);
this.exceptionType = Type.SPECIFIC;
this.errorCode = ComputationBusinessErrorCode.SPECIFIC;
}

public ComputationException(Type exceptionType, String message) {
super(message);
this.exceptionType = Objects.requireNonNull(exceptionType);
@NonNull
@Override
public ComputationBusinessErrorCode getBusinessErrorCode() {
return errorCode;
}

public ComputationException(Type exceptionType, String message, Throwable cause) {
super(message, cause);
this.exceptionType = Objects.requireNonNull(exceptionType);
public ComputationException(ComputationBusinessErrorCode errorCode, String message) {
super(message);
this.errorCode = Objects.requireNonNull(errorCode);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

import java.util.List;

import static org.gridsuite.computation.ComputationBusinessErrorCode.INVALID_FILTER_FORMAT;

/**
* @author maissa Souissi <maissa.souissi at rte-france.com>
*/
Expand All @@ -32,7 +34,7 @@ private static <T> T fromStringToDTO(String jsonString, ObjectMapper objectMappe
try {
return objectMapper.readValue(jsonString, typeReference);
} catch (JsonProcessingException e) {
throw new ComputationException(ComputationException.Type.INVALID_FILTER_FORMAT);
throw new ComputationException(INVALID_FILTER_FORMAT, e.getMessage());
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/**
* Copyright (c) 2025, 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.computation;

import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.EnumSource;

import static org.assertj.core.api.AssertionsForClassTypes.assertThat;

class ComputationBusinessErrorCodeTest {
@ParameterizedTest
@EnumSource(ComputationBusinessErrorCode.class)
void valueMatchesEnumName(ComputationBusinessErrorCode code) {
assertThat(code.value()).startsWith("computation.");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class ComputationExceptionTest {
void testMessageConstructor() {
var e = new ComputationException("test");
assertEquals("test", e.getMessage());
assertEquals(ComputationBusinessErrorCode.SPECIFIC, e.getBusinessErrorCode());
}

@Test
Expand All @@ -28,4 +29,11 @@ void testMessageAndThrowableConstructor() {
assertEquals("test", e.getMessage());
assertEquals(cause, e.getCause());
}

@Test
void testBusinessErrorCodeConstructor() {
var e = new ComputationException(ComputationBusinessErrorCode.PARAMETERS_NOT_FOUND, "test");
assertEquals("test", e.getMessage());
assertEquals(ComputationBusinessErrorCode.PARAMETERS_NOT_FOUND, e.getBusinessErrorCode());
}
}