Skip to content

Commit

Permalink
springboot 3.1.2 (#344)
Browse files Browse the repository at this point in the history
Signed-off-by: Abdelsalem <[email protected]>
Co-authored-by: HARPER Jon <[email protected]>
  • Loading branch information
AbdelHedhili and jonenst committed Sep 22, 2023
1 parent 2442ae3 commit 4fcdf56
Show file tree
Hide file tree
Showing 20 changed files with 82 additions and 40 deletions.
7 changes: 6 additions & 1 deletion network-store-client/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,21 @@
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
</dependency>

<dependency>
<groupId>org.jgrapht</groupId>
<artifactId>jgrapht-core</artifactId>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>${slf4j.version}</version>
</dependency>

<!-- runtime scope -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>log4j-over-slf4j</artifactId>
<version>${slf4j.version}</version>
<scope>runtime</scope>
</dependency>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
import jakarta.annotation.PostConstruct;
import jakarta.annotation.PreDestroy;
import java.nio.file.Path;
import java.util.*;
import java.util.concurrent.ExecutorService;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,15 @@
*/
package com.powsybl.network.store.client;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.datatype.joda.JodaModule;
import com.powsybl.commons.PowsyblException;
import com.powsybl.network.store.model.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.web.client.RestTemplateBuilder;
import org.springframework.core.ParameterizedTypeReference;
import org.springframework.http.*;
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
import org.springframework.web.client.RestTemplate;
import org.springframework.web.util.DefaultUriBuilderFactory;
import org.springframework.web.util.UriComponentsBuilder;
Expand All @@ -37,11 +40,22 @@ public RestClientImpl(RestTemplateBuilder restTemplateBuilder) {
}

public static RestTemplateBuilder createRestTemplateBuilder(String baseUri) {
return new RestTemplateBuilder()
.uriTemplateHandler(new DefaultUriBuilderFactory(UriComponentsBuilder.fromUriString(baseUri)
return new RestTemplateBuilder(restTemplate1 -> restTemplate1.setMessageConverters(List.of(createMapping()))).uriTemplateHandler(new DefaultUriBuilderFactory(UriComponentsBuilder.fromUriString(baseUri)
.path(NetworkStoreApi.VERSION)));
}

private static ObjectMapper createObjectMapper() {
ObjectMapper objectMapper = new ObjectMapper();
objectMapper.registerModule(new JodaModule());
return objectMapper;
}

private static MappingJackson2HttpMessageConverter createMapping() {
var converter = new MappingJackson2HttpMessageConverter();
converter.setObjectMapper(createObjectMapper());
return converter;
}

private <T extends IdentifiableAttributes> ResponseEntity<TopLevelDocument<T>> getDocument(String url, Object... uriVariables) {
return restTemplate.exchange(url,
HttpMethod.GET,
Expand All @@ -59,8 +73,8 @@ private static <T extends IdentifiableAttributes> TopLevelDocument<T> getBody(Re
return body;
}

private static PowsyblException createHttpException(String url, String method, HttpStatus httpStatus) {
return new PowsyblException("Fail to " + method + " at " + url + ", status: " + httpStatus);
private static PowsyblException createHttpException(String url, String method, HttpStatusCode httpStatusCode) {
return new PowsyblException("Fail to " + method + " at " + url + ", status: " + httpStatusCode);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
package com.powsybl.network.store.client;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.datatype.joda.JodaModule;
import com.google.common.base.Stopwatch;
import com.google.common.collect.Lists;
import com.powsybl.commons.PowsyblException;
Expand Down Expand Up @@ -46,6 +47,8 @@ public RestNetworkStoreClient(RestClient restClient) {
public RestNetworkStoreClient(RestClient restClient, ObjectMapper objectMapper) {
this.restClient = Objects.requireNonNull(restClient);
this.objectMapper = Objects.requireNonNull(objectMapper);
objectMapper.registerModule(new JodaModule());

}

// network
Expand Down Expand Up @@ -234,7 +237,7 @@ public Optional<Resource<SubstationAttributes>> getSubstation(UUID networkUuid,

@Override
public void updateSubstations(UUID networkUuid, List<Resource<SubstationAttributes>> substationResources, AttributeFilter attributeFilter) {
updateAll("substation", "/networks/{networkUuid}/substations/", substationResources, attributeFilter, networkUuid);
updateAll("substation", "/networks/{networkUuid}/substations", substationResources, attributeFilter, networkUuid);
}

public void removeSubstations(UUID networkUuid, int variantNum, List<String> substationsId) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,26 +19,23 @@
import java.nio.charset.StandardCharsets;
import java.util.Optional;

import static org.springframework.http.HttpStatus.Series.CLIENT_ERROR;
import static org.springframework.http.HttpStatus.Series.SERVER_ERROR;

/**
* @author Geoffroy Jamgotchian <geoffroy.jamgotchian at rte-france.com>
*/
public class RestTemplateResponseErrorHandler implements ResponseErrorHandler {

@Override
public boolean hasError(ClientHttpResponse response) throws IOException {
return response.getStatusCode().series() == CLIENT_ERROR
|| response.getStatusCode().series() == SERVER_ERROR;
return response.getStatusCode().is4xxClientError()
|| response.getStatusCode().is5xxServerError();
}

@Override
public void handleError(ClientHttpResponse response) throws IOException {
if (response.getStatusCode().series() == HttpStatus.Series.SERVER_ERROR) {
if (response.getStatusCode().is5xxServerError()) {
throw new HttpServerErrorException(response.getStatusCode(), response.getStatusText(),
response.getBody().readAllBytes(), StandardCharsets.UTF_8);
} else if (response.getStatusCode().series() == HttpStatus.Series.CLIENT_ERROR) {
} else if (response.getStatusCode().is4xxClientError()) {
if (response.getStatusCode() != HttpStatus.NOT_FOUND) {
throw new HttpClientErrorException(response.getStatusCode(), response.getStatusText(),
response.getBody().readAllBytes(), StandardCharsets.UTF_8);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
package com.powsybl.network.store.client;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.datatype.joda.JodaModule;
import com.google.common.collect.ImmutableList;
import com.powsybl.commons.PowsyblException;
import com.powsybl.iidm.network.*;
Expand Down Expand Up @@ -68,6 +69,7 @@ public class RestNetworkStoreClientTest {

@Before
public void setUp() throws IOException {
objectMapper.registerModule(new JodaModule());
Resource<NetworkAttributes> n1 = Resource.networkBuilder()
.id("n1")
.attributes(NetworkAttributes.builder()
Expand Down
2 changes: 2 additions & 0 deletions network-store-iidm-impl/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,13 @@
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>log4j-over-slf4j</artifactId>
<version>${slf4j.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>${slf4j.version}</version>
<scope>test</scope>
</dependency>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ protected void checkNodeBus1() {

private String getConnectionBus1() {
if (bus1 != null) {
if ((connectableBus1 != null) && (!bus1.equals(connectableBus1))) {
if (!bus1.equals(connectableBus1)) {
throw new ValidationException(this, "connection bus 1 is different to connectable bus 1");
}
return bus1;
Expand Down Expand Up @@ -172,7 +172,7 @@ protected void checkNodeBus2() {

private String getConnectionBus2() {
if (bus2 != null) {
if ((connectableBus2 != null) && (!bus2.equals(connectableBus2))) {
if (connectableBus2 != null && !bus2.equals(connectableBus2)) {
throw new ValidationException(this, "connection bus 2 is different to connectable bus 2");
}
return bus2;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ private void checkNode() {

private String getConnectionBus() {
if (bus != null) {
if ((connectableBus != null) && (!bus.equals(connectableBus))) {
if (connectableBus != null && !bus.equals(connectableBus)) {
throw new ValidationException(this, "connection bus is different to connectable bus");
}
return bus;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,8 @@ protected boolean isCalculatedBusValid(Set<Integer> nodesOrBusesConnected, Map<I
EquipmentCount<Integer> equipmentCount = new EquipmentCount<>();
equipmentCount.count(nodesOrBusesConnected, verticesByNodeOrBus);
return !isBusView ? !nodesOrBusesConnected.isEmpty() :
(equipmentCount.busbarSectionCount >= 1 && equipmentCount.feederCount >= 1)
|| (equipmentCount.branchCount >= 1 && equipmentCount.feederCount >= 2);
equipmentCount.busbarSectionCount >= 1 && equipmentCount.feederCount >= 1
|| equipmentCount.branchCount >= 1 && equipmentCount.feederCount >= 2;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -370,8 +370,8 @@ public int getInternalConnectionCount() {
@Override
public void removeInternalConnections(int node1, int node2) {
if (!getVoltageLevelResource().getAttributes().getInternalConnections()
.removeIf(attributes -> (attributes.getNode1() == node1 && attributes.getNode2() == node2) ||
(attributes.getNode1() == node2 && attributes.getNode2() == node1))) {
.removeIf(attributes -> attributes.getNode1() == node1 && attributes.getNode2() == node2 ||
attributes.getNode1() == node2 && attributes.getNode2() == node1)) {
throw new PowsyblException("Internal connection not found between " + node1 + " and " + node2);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ private static void checkRemovability(Substation substation, Branch branch) {
Objects.requireNonNull(branch);
Substation s1 = branch.getTerminal1().getVoltageLevel().getSubstation().orElse(null);
Substation s2 = branch.getTerminal2().getVoltageLevel().getSubstation().orElse(null);
if ((s1 != substation) || (s2 != substation)) {
if (s1 != substation || s2 != substation) {
throw createIsolationException(substation);
}
}
Expand All @@ -50,7 +50,7 @@ private static void checkRemovability(Substation substation, ThreeWindingsTransf
Substation s1 = twt.getLeg1().getTerminal().getVoltageLevel().getSubstation().orElse(null);
Substation s2 = twt.getLeg2().getTerminal().getVoltageLevel().getSubstation().orElse(null);
Substation s3 = twt.getLeg3().getTerminal().getVoltageLevel().getSubstation().orElse(null);
if ((s1 != substation) || (s2 != substation) || (s3 != substation)) {
if (s1 != substation || s2 != substation || s3 != substation) {
throw createIsolationException(substation);
}
}
Expand All @@ -62,7 +62,7 @@ private static void checkRemovability(Substation substation, HvdcConverterStatio
if (hvdcLine != null) {
Substation s1 = hvdcLine.getConverterStation1().getTerminal().getVoltageLevel().getSubstation().orElse(null);
Substation s2 = hvdcLine.getConverterStation2().getTerminal().getVoltageLevel().getSubstation().orElse(null);
if ((s1 != substation) || (s2 != substation)) {
if (s1 != substation || s2 != substation) {
throw createIsolationException(substation);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ public boolean isConnected() {
return this.getBusView().getBus() != null;
} else {
var attributes = getAttributes();
return (attributes.getBus() != null) && attributes.getBus().equals(attributes.getConnectableBus());
return attributes.getBus() != null && attributes.getBus().equals(attributes.getConnectableBus());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ protected void checkParams() {

private String getConnectionBus() {
if (bus != null) {
if ((connectableBus != null) && (!bus.equals(connectableBus))) {
if (connectableBus != null && !bus.equals(connectableBus)) {
throw new ValidationException(this, "connection bus leg " + legNumber + " is different to connectable bus");
}
return bus;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ static void checkRemovability(VoltageLevel voltageLevel) {
if (MULTIPLE_TERMINALS_CONNECTABLE_TYPES.contains(type)) {
// Reject lines, 2WT and 3WT
throw new AssertionError("The voltage level '" + voltageLevel.getId() + "' cannot be removed because of a remaining " + type);
} else if ((type == IdentifiableType.HVDC_CONVERTER_STATION) && (network.getHvdcLine((HvdcConverterStation<?>) connectable) != null)) {
} else if (type == IdentifiableType.HVDC_CONVERTER_STATION && network.getHvdcLine((HvdcConverterStation<?>) connectable) != null) {
// Reject all converter stations connected to a HVDC line
throw new AssertionError("The voltage level '" + voltageLevel.getId() + "' cannot be removed because of a remaining HVDC line");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public HvdcOperatorActivePowerRangeImpl setOprFromCS2toCS1(float oprFromCS2toCS1
}

private float checkOPR(float opr, HvdcConverterStation<?> from, HvdcConverterStation<?> to) {
if ((!Float.isNaN(opr)) && (opr < 0)) {
if (!Float.isNaN(opr) && opr < 0) {
String message = "OPR from " + from.getId() + " to " + to.getId() + " must be greater than 0 (current value " + opr + ").";
throw new IllegalArgumentException(message);
}
Expand Down
9 changes: 5 additions & 4 deletions network-store-model/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<name>Network store model</name>

<properties>
<swagger-annotations.version>2.1.10</swagger-annotations.version>
<swagger-annotations.version>2.2.9</swagger-annotations.version>
</properties>

<build>
Expand Down Expand Up @@ -56,9 +56,9 @@
<artifactId>jackson-datatype-joda</artifactId>
</dependency>
<dependency>
<groupId>io.swagger.core.v3</groupId>
<artifactId>swagger-annotations</artifactId>
<version>${swagger-annotations.version}</version>
<groupId>io.swagger.core.v3</groupId>
<artifactId>swagger-annotations-jakarta</artifactId>
<version>${swagger-annotations.version}</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
Expand Down Expand Up @@ -90,6 +90,7 @@
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>${slf4j.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
include = JsonTypeInfo.As.PROPERTY,
property = "type")
@JsonSubTypes({
@JsonSubTypes.Type(value = ReactiveCapabilityCurveAttributes.class, name = "ReactiveCapabilityCurve"),
@JsonSubTypes.Type(value = MinMaxReactiveLimitsAttributes.class, name = "MinMaxReactiveLimits")
@JsonSubTypes.Type(value = ReactiveCapabilityCurveAttributes.class, name = "ReactiveCapabilityCurve"),
@JsonSubTypes.Type(value = MinMaxReactiveLimitsAttributes.class, name = "MinMaxReactiveLimits")
})
@JsonInclude(JsonInclude.Include.NON_NULL)
public interface ReactiveLimitsAttributes {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
include = JsonTypeInfo.As.PROPERTY,
property = "type")
@JsonSubTypes({
@JsonSubTypes.Type(value = ShuntCompensatorLinearModelAttributes.class, name = "LinearModel"),
@JsonSubTypes.Type(value = ShuntCompensatorNonLinearModelAttributes.class, name = "NonLinearModel")
@JsonSubTypes.Type(value = ShuntCompensatorLinearModelAttributes.class, name = "LinearModel"),
@JsonSubTypes.Type(value = ShuntCompensatorNonLinearModelAttributes.class, name = "NonLinearModel")
})
@JsonInclude(JsonInclude.Include.NON_NULL)
public interface ShuntCompensatorModelAttributes {
Expand Down
24 changes: 21 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<parent>
<groupId>com.powsybl</groupId>
<artifactId>powsybl-parent</artifactId>
<version>12</version>
<version>15</version>
<relativePath/>
</parent>

Expand Down Expand Up @@ -47,11 +47,12 @@
</developers>

<properties>
<springboot.version>2.7.3</springboot.version>
<springboot.version>3.1.2</springboot.version>
<commons-lang3.version>3.9</commons-lang3.version>
<powsybl-dependencies.version>2023.2.1</powsybl-dependencies.version>
<powsybl-ws-commons.version>1.5.0</powsybl-ws-commons.version>

<slf4j.version>2.0.4</slf4j.version>
<logback.version>1.4.5</logback.version>
<sonar.coverage.jacoco.xmlReportPaths>
../network-store-client-distribution/target/site/jacoco-aggregate/jacoco.xml,
../../network-store-client-distributiont/target/site/jacoco-aggregate/jacoco.xml,
Expand Down Expand Up @@ -86,6 +87,23 @@
<scope>import</scope>
</dependency>

<!-- Force compatible version with springboot 3 that is otherwise set by powsybl -->
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>${logback.version}</version>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-core</artifactId>
<version>${logback.version}</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>${slf4j.version}</version>
</dependency>

<!-- project specific dependencies (also overrides imports, but separate for clarity) -->
<dependency>
<groupId>com.powsybl</groupId>
Expand Down

0 comments on commit 4fcdf56

Please sign in to comment.