Skip to content

Commit

Permalink
Fix comments
Browse files Browse the repository at this point in the history
Signed-off-by: BOUHOURS Antoine <[email protected]>
  • Loading branch information
antoinebhs committed Apr 3, 2024
1 parent 2f3b052 commit e544543
Show file tree
Hide file tree
Showing 9 changed files with 44 additions and 15 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
/**
* 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 com.powsybl.network.store.server;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.json.JsonReadFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.common.collect.Lists;
import com.powsybl.network.store.model.ExtensionAttributes;
Expand All @@ -22,14 +27,17 @@
import static com.powsybl.network.store.server.NetworkStoreRepository.BATCH_SIZE;
import static com.powsybl.network.store.server.Utils.bindValues;

/**
* @author Antoine Bouhours <antoine.bouhours at rte-france.com>
*/
@Component
public class ExtensionHandler {
private final DataSource dataSource;
private final ObjectMapper mapper;

public ExtensionHandler(DataSource dataSource, ObjectMapper mapper) {
this.dataSource = dataSource;
this.mapper = mapper.enable(JsonReadFeature.ALLOW_NON_NUMERIC_NUMBERS.mappedFeature());
this.mapper = mapper;
}

public void insertExtensions(Map<OwnerInfo, Map<String, ExtensionAttributes>> extensions) {
Expand Down Expand Up @@ -189,7 +197,7 @@ public <T extends IdentifiableAttributes> void deleteExtensions(UUID networkUuid
}

/**
* Extensions do not always exist in the initial variant and can be added by a
* Extensions do not always exist in the variant and can be added by a
* modification for example. Instead of implementing an UPSERT, we delete then insert
* the extensions.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,7 @@ private void createBatteryMappings() {
batteryMappings.addColumnMapping(PROPERTIES, new ColumnMapping<>(Map.class, BatteryAttributes::getProperties, BatteryAttributes::setProperties));
batteryMappings.addColumnMapping(ALIAS_BY_TYPE, new ColumnMapping<>(Map.class, BatteryAttributes::getAliasByType, BatteryAttributes::setAliasByType));
batteryMappings.addColumnMapping(ALIASES_WITHOUT_TYPE, new ColumnMapping<>(Set.class, BatteryAttributes::getAliasesWithoutType, BatteryAttributes::setAliasesWithoutType));
batteryMappings.addColumnMapping(POSITION, new ColumnMapping<>(ConnectablePositionAttributes.class, BatteryAttributes::getPosition, BatteryAttributes::setPosition));
}

public TableMapping getBusbarSectionMappings() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -770,7 +770,6 @@ public <T extends IdentifiableAttributes> void updateIdentifiables(UUID networkU
}
}
});
// TODO add a without auto commit??
extensionHandler.updateExtensions(networkUuid, resources);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright (c) 2022, RTE (http://www.rte-france.com)
* 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/.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
/**
* 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 com.powsybl.network.store.server;

import com.fasterxml.jackson.core.JsonProcessingException;
Expand All @@ -17,6 +23,9 @@
import java.util.Map;
import java.util.UUID;

/**
* @author Geoffroy Jamgotchian <geoffroy.jamgotchian at rte-france.com>
*/
public final class Utils {
private Utils() throws IllegalAccessException {
throw new IllegalAccessException("Utility class can not be initialize.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,10 @@
</createIndex>
<addPrimaryKey columnNames="networkuuid, variantnum, equipmentid, name" constraintName="extension_pkey" tableName="extension"/>
</changeSet>
<!-- The data migration is skipped if the database is not postgres because we use jsonb methods that are specific to postgres -->
<changeSet author="bouhoursant" id="2986331049277-2">
<sqlFile
dbms="postgresql"
path="migrationExtensions_20240306T120000Z.sql"
relativeToChangelogFile="true"
splitStatements="true"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
INSERT INTO extension (networkuuid, variantnum, equipmentid, equipmentType, name, value_)
SELECT networkuuid, variantnum, id, 'BATTERY', 'activePowerControl',
jsonb_set(
COALESCE(activepowercontrol::jsonb, '{}'::jsonb),
activepowercontrol::jsonb,
'{@type}',
'"activePowerControl"'::jsonb
'"activePowerControl"'
)
FROM battery
WHERE activepowercontrol IS NOT NULL;

INSERT INTO extension (networkuuid, variantnum, equipmentid, equipmentType, name, value_)
SELECT networkuuid, variantnum, id, 'GENERATOR', 'activePowerControl',
jsonb_set(
COALESCE(activepowercontrol::jsonb, '{}'::jsonb),
activepowercontrol::jsonb,
'{@type}',
'"activePowerControl"'::jsonb
)
Expand All @@ -21,7 +21,7 @@ WHERE activepowercontrol IS NOT NULL;
INSERT INTO extension (networkuuid, variantnum, equipmentid, equipmentType, name, value_)
SELECT networkuuid, variantnum, id, 'GENERATOR', 'startup',
jsonb_set(
COALESCE(generatorstartup::jsonb, '{}'::jsonb),
generatorstartup::jsonb,
'{@type}',
'"startup"'::jsonb
)
Expand All @@ -32,7 +32,7 @@ INSERT INTO extension (networkuuid, variantnum, equipmentid, equipmentType, name
SELECT networkuuid, variantnum, id, 'LINE', 'operatingStatus',
jsonb_build_object(
'@type', 'operatingStatus',
'operatingStatus', operatingStatus::text
'operatingStatus', operatingStatus
)
FROM line
WHERE operatingStatus IS NOT NULL;
Expand All @@ -41,7 +41,7 @@ INSERT INTO extension (networkuuid, variantnum, equipmentid, equipmentType, name
SELECT networkuuid, variantnum, id, 'HVDC_LINE', 'operatingStatus',
jsonb_build_object(
'@type', 'operatingStatus',
'operatingStatus', operatingStatus::text
'operatingStatus', operatingStatus
)
FROM hvdcline
WHERE operatingStatus IS NOT NULL;
Expand All @@ -50,7 +50,7 @@ INSERT INTO extension (networkuuid, variantnum, equipmentid, equipmentType, name
SELECT networkuuid, variantnum, id, 'TIE_LINE', 'operatingStatus',
jsonb_build_object(
'@type', 'operatingStatus',
'operatingStatus', operatingStatus::text
'operatingStatus', operatingStatus
)
FROM tieline
WHERE operatingStatus IS NOT NULL;
Expand All @@ -59,7 +59,7 @@ INSERT INTO extension (networkuuid, variantnum, equipmentid, equipmentType, name
SELECT networkuuid, variantnum, id, 'DANGLING_LINE', 'operatingStatus',
jsonb_build_object(
'@type', 'operatingStatus',
'operatingStatus', operatingStatus::text
'operatingStatus', operatingStatus
)
FROM danglingline
WHERE operatingStatus IS NOT NULL;
Expand All @@ -68,7 +68,7 @@ INSERT INTO extension (networkuuid, variantnum, equipmentid, equipmentType, name
SELECT networkuuid, variantnum, id, 'TWO_WINDINGS_TRANSFORMER', 'operatingStatus',
jsonb_build_object(
'@type', 'operatingStatus',
'operatingStatus', operatingStatus::text
'operatingStatus', operatingStatus
)
FROM twowindingstransformer
WHERE operatingStatus IS NOT NULL;
Expand All @@ -77,7 +77,7 @@ INSERT INTO extension (networkuuid, variantnum, equipmentid, equipmentType, name
SELECT networkuuid, variantnum, id, 'THREE_WINDINGS_TRANSFORMER', 'operatingStatus',
jsonb_build_object(
'@type', 'operatingStatus',
'operatingStatus', operatingStatus::text
'operatingStatus', operatingStatus
)
FROM threewindingstransformer
WHERE operatingStatus IS NOT NULL;
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
/**
* 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 com.powsybl.network.store.server;

import com.powsybl.network.store.model.*;
Expand All @@ -16,6 +22,9 @@

import static org.junit.Assert.*;

/**
* @author Antoine Bouhours <antoine.bouhours at rte-france.com>
*/
@RunWith(SpringRunner.class)
@SpringBootTest
@AutoConfigureMockMvc
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import com.powsybl.network.store.model.*;
import com.powsybl.network.store.server.dto.LimitsInfos;
import com.powsybl.network.store.server.dto.OwnerInfo;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
Expand Down

0 comments on commit e544543

Please sign in to comment.