Skip to content

Commit

Permalink
replace ZonedDateTime with Instant (#67)
Browse files Browse the repository at this point in the history
* replace ZonedDateTime with OffsetDateTime
* replace OffsetDateTime with Instant
---------
Signed-off-by: TOURI ANIS <[email protected]>
  • Loading branch information
anistouri authored Jun 6, 2024
1 parent bacd5b7 commit 6efc39d
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import lombok.NoArgsConstructor;
import lombok.Setter;

import java.time.ZonedDateTime;
import java.time.Instant;
import java.util.List;
import java.util.Map;
import java.util.UUID;
Expand All @@ -27,7 +27,7 @@ public class VoltageInitResult {

private UUID resultUuid;

private ZonedDateTime writeTimeStamp;
private Instant writeTimeStamp;

private Map<String, String> indicators;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import lombok.*;
import lombok.experimental.SuperBuilder;

import java.time.ZonedDateTime;
import java.time.Instant;
import java.util.List;
import java.util.UUID;

Expand All @@ -30,7 +30,7 @@ public class VoltageInitParametersInfos {
private UUID uuid;

@Schema(description = "parameters date")
private ZonedDateTime date;
private Instant date;

@Schema(description = "parameters name")
private String name;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,11 @@
*/
package org.gridsuite.voltageinit.server.entities;

import java.time.Instant;
import java.util.List;
import java.util.Map;
import java.util.UUID;

import java.time.ZonedDateTime;

import jakarta.persistence.CollectionTable;
import jakarta.persistence.Column;
import jakarta.persistence.ElementCollection;
Expand Down Expand Up @@ -40,8 +39,8 @@ public class VoltageInitResultEntity {
@Id
private UUID resultUuid;

@Column
private ZonedDateTime writeTimeStamp;
@Column(columnDefinition = "timestamptz")
private Instant writeTimeStamp;

@ElementCollection
@CollectionTable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@
import org.gridsuite.voltageinit.server.dto.parameters.VoltageLimitInfos;
import org.gridsuite.voltageinit.server.util.VoltageLimitParameterType;

import java.time.ZoneOffset;
import java.time.ZonedDateTime;
import java.time.Instant;
import java.time.temporal.ChronoUnit;
import java.util.ArrayList;
import java.util.List;
Expand All @@ -41,8 +40,8 @@ public class VoltageInitParametersEntity {
@Column(name = "id")
private UUID id;

@Column(name = "date")
private ZonedDateTime date;
@Column(name = "date", columnDefinition = "timestamptz")
private Instant date;

@Column(name = "name")
private String name;
Expand Down Expand Up @@ -82,7 +81,7 @@ public class VoltageInitParametersEntity {
private boolean updateBusVoltage;

public VoltageInitParametersEntity(@NonNull VoltageInitParametersInfos voltageInitParametersInfos) {
this.date = ZonedDateTime.now(ZoneOffset.UTC).truncatedTo(ChronoUnit.MICROS);
this.date = Instant.now().truncatedTo(ChronoUnit.MICROS);
assignAttributes(voltageInitParametersInfos);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

import com.powsybl.openreac.parameters.output.OpenReacResult;

import java.time.ZonedDateTime;
import java.time.Instant;
import java.util.List;
import java.util.Map;
import java.util.Objects;
Expand Down Expand Up @@ -63,7 +63,7 @@ private static VoltageInitResultEntity toVoltageInitResultEntity(UUID resultUuid
}
}
).filter(Objects::nonNull).toList();
return new VoltageInitResultEntity(resultUuid, ZonedDateTime.now(), indicators, reactiveSlacks, busVoltages, modificationsGroupUuid,
return new VoltageInitResultEntity(resultUuid, Instant.now(), indicators, reactiveSlacks, busVoltages, modificationsGroupUuid,
isReactiveSlacksOverThreshold, reactiveSlacksThreshold);
}

Expand Down Expand Up @@ -128,6 +128,6 @@ public void insert(UUID resultUuid, OpenReacResult result, Map<String, Bus> netw
@Transactional
public void insertErrorResult(UUID resultUuid, Map<String, String> errorIndicators) {
Objects.requireNonNull(resultUuid);
resultRepository.save(new VoltageInitResultEntity(resultUuid, ZonedDateTime.now(), errorIndicators, List.of(), List.of(), null, false, null));
resultRepository.save(new VoltageInitResultEntity(resultUuid, Instant.now(), errorIndicators, List.of(), List.of(), null, false, null));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.1" encoding="UTF-8" standalone="no"?>
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog" xmlns:ext="http://www.liquibase.org/xml/ns/dbchangelog-ext" xmlns:pro="http://www.liquibase.org/xml/ns/pro" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog-ext http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-ext.xsd http://www.liquibase.org/xml/ns/pro http://www.liquibase.org/xml/ns/pro/liquibase-pro-latest.xsd http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-latest.xsd">
<changeSet author="tourian1 (generated)" id="1716997033555-5">
<modifyDataType tableName="voltage_init_parameters" columnName="date" newDataType="timestamptz"/>
</changeSet>
<changeSet author="tourian1 (generated)" id="1716997033555-6">
<modifyDataType tableName="voltage_init_result" columnName="write_time_stamp" newDataType="timestamptz"/>
</changeSet>
</databaseChangeLog>
5 changes: 4 additions & 1 deletion src/main/resources/db/changelog/db.changelog-master.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,7 @@ databaseChangeLog:
relativeToChangelogFile: true
- include:
file: changesets/changelog_20240407T230420Z.xml
relativeToChangelogFile: true
relativeToChangelogFile: true
- include:
file: changesets/changelog_20240529T153656Z.xml
relativeToChangelogFile: true
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import org.assertj.core.api.AbstractAssert;
import org.assertj.core.api.recursive.comparison.RecursiveComparisonConfiguration;

import java.time.ZonedDateTime;
import java.time.Instant;
import java.util.Date;
import java.util.UUID;

Expand All @@ -31,7 +31,7 @@ public DTOAssert<T> recursivelyEquals(T other) {
private RecursiveComparisonConfiguration getRecursiveConfiguration() {
return RecursiveComparisonConfiguration.builder()
.withIgnoreAllOverriddenEquals(true) // For equals test, need specific tests
.withIgnoredFieldsOfTypes(UUID.class, Date.class, ZonedDateTime.class) // For these types, need specific tests (uuid from db for example)
.withIgnoredFieldsOfTypes(UUID.class, Date.class, Instant.class) // For these types, need specific tests (uuid from db for example)
.withIgnoreCollectionOrder(true) // For collection order test, need specific tests
.build();
}
Expand Down

0 comments on commit 6efc39d

Please sign in to comment.