-
-
Notifications
You must be signed in to change notification settings - Fork 217
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1449 from MSaguer/historyGenerator
Add generation timestamp in history file
- Loading branch information
Showing
27 changed files
with
396 additions
and
86 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
21 changes: 21 additions & 0 deletions
21
src/main/java/tech/jhipster/lite/common/domain/TimeUtils.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,21 @@ | ||
package tech.jhipster.lite.common.domain; | ||
|
||
import java.time.Clock; | ||
import java.time.LocalDateTime; | ||
import java.time.format.DateTimeFormatter; | ||
|
||
public class TimeUtils { | ||
|
||
private static final DateTimeFormatter DATE_TIME_FORMATTER = DateTimeFormatter.ofPattern("yyyyMMddHHmmss"); | ||
|
||
private TimeUtils() {} | ||
|
||
public static String getDateString(Clock clock) { | ||
return getDateString(clock, 0); | ||
} | ||
|
||
public static String getDateString(Clock clock, int plusSecond) { | ||
LocalDateTime localDateTime = LocalDateTime.now(clock).plusSeconds(plusSecond); | ||
return localDateTime.format(DATE_TIME_FORMATTER); | ||
} | ||
} |
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
15 changes: 1 addition & 14 deletions
15
src/main/java/tech/jhipster/lite/generator/history/domain/GeneratorHistoryData.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,18 +1,5 @@ | ||
package tech.jhipster.lite.generator.history.domain; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
public class GeneratorHistoryData { | ||
|
||
private final List<GeneratorHistoryValue> values = new ArrayList<>(); | ||
|
||
public List<GeneratorHistoryValue> getValues() { | ||
return values; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "GeneratorHistoryData{" + "values=" + values + '}'; | ||
} | ||
} | ||
public record GeneratorHistoryData(List<GeneratorHistoryValue> values) {} |
4 changes: 3 additions & 1 deletion
4
src/main/java/tech/jhipster/lite/generator/history/domain/GeneratorHistoryValue.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,3 +1,5 @@ | ||
package tech.jhipster.lite.generator.history.domain; | ||
|
||
public record GeneratorHistoryValue(String serviceId) {} | ||
import java.time.Instant; | ||
|
||
public record GeneratorHistoryValue(String serviceId, Instant timestamp) {} |
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
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
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
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
21 changes: 21 additions & 0 deletions
21
...pster/lite/generator/history/infrastructure/secondary/dto/DefaultInstantDeserializer.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,21 @@ | ||
package tech.jhipster.lite.generator.history.infrastructure.secondary.dto; | ||
|
||
import com.fasterxml.jackson.datatype.jsr310.deser.InstantDeserializer; | ||
import java.time.Instant; | ||
import java.time.format.DateTimeFormatter; | ||
|
||
@SuppressWarnings("java:S110") | ||
public class DefaultInstantDeserializer extends InstantDeserializer<Instant> { | ||
|
||
public DefaultInstantDeserializer() { | ||
super( | ||
Instant.class, | ||
DateTimeFormatter.ISO_INSTANT, | ||
Instant::from, | ||
a -> Instant.ofEpochMilli(a.value), | ||
a -> Instant.ofEpochSecond(a.integer, a.fraction), | ||
null, | ||
true // yes, replace zero offset with Z | ||
); | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
...jhipster/lite/generator/history/infrastructure/secondary/dto/GeneratorHistoryDataDTO.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,22 @@ | ||
package tech.jhipster.lite.generator.history.infrastructure.secondary.dto; | ||
|
||
import java.util.Collections; | ||
import java.util.List; | ||
import tech.jhipster.lite.generator.history.domain.GeneratorHistoryData; | ||
import tech.jhipster.lite.generator.history.domain.GeneratorHistoryValue; | ||
|
||
public record GeneratorHistoryDataDTO(List<GeneratorHistoryValueDTO> values) { | ||
public static GeneratorHistoryDataDTO from(List<GeneratorHistoryValue> values) { | ||
if (values == null) { | ||
return new GeneratorHistoryDataDTO(Collections.emptyList()); | ||
} | ||
return new GeneratorHistoryDataDTO(values.stream().map(GeneratorHistoryValueDTO::from).distinct().toList()); | ||
} | ||
|
||
public static GeneratorHistoryData to(List<GeneratorHistoryValueDTO> values) { | ||
if (values == null) { | ||
return new GeneratorHistoryData(Collections.emptyList()); | ||
} | ||
return new GeneratorHistoryData(values.stream().map(GeneratorHistoryValueDTO::to).distinct().toList()); | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
...hipster/lite/generator/history/infrastructure/secondary/dto/GeneratorHistoryValueDTO.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,21 @@ | ||
package tech.jhipster.lite.generator.history.infrastructure.secondary.dto; | ||
|
||
import com.fasterxml.jackson.databind.annotation.JsonDeserialize; | ||
import com.fasterxml.jackson.databind.annotation.JsonSerialize; | ||
import com.fasterxml.jackson.datatype.jsr310.ser.InstantSerializer; | ||
import java.time.Instant; | ||
import tech.jhipster.lite.generator.history.domain.GeneratorHistoryValue; | ||
|
||
public record GeneratorHistoryValueDTO( | ||
String serviceId, | ||
|
||
@JsonSerialize(using = InstantSerializer.class) @JsonDeserialize(using = DefaultInstantDeserializer.class) Instant timestamp | ||
) { | ||
public static GeneratorHistoryValueDTO from(GeneratorHistoryValue value) { | ||
return new GeneratorHistoryValueDTO(value.serviceId(), value.timestamp()); | ||
} | ||
|
||
public static GeneratorHistoryValue to(GeneratorHistoryValueDTO value) { | ||
return new GeneratorHistoryValue(value.serviceId, value.timestamp); | ||
} | ||
} |
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
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
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
Oops, something went wrong.