Skip to content

Commit 19488e9

Browse files
committed
Introduce HistoryEntry with ZonedDateTime
Deprecate usage of java.sql.Timestamp. Get rid of all deprecated calls inside ACTool. This relates to #867
1 parent 5b664a8 commit 19488e9

3 files changed

Lines changed: 35 additions & 15 deletions

File tree

accesscontroltool-bundle/src/main/java/biz/netcentric/cq/tools/actool/api/HistoryEntry.java

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
*/
1616

1717
import java.sql.Timestamp;
18+
import java.time.ZonedDateTime;
1819

1920
import org.osgi.annotation.versioning.ProviderType;
2021

@@ -24,23 +25,45 @@
2425
@ProviderType
2526
public final class HistoryEntry {
2627

27-
private Timestamp timestamp;
28+
private ZonedDateTime date;
2829
private String message;
2930
private long index;
3031

32+
/**
33+
* Creates a new history entry. Calls {@link #HistoryEntry(long, ZonedDateTime, String)} internally with a converted timestamp using the current time zone.
34+
* @param index
35+
* @param timestamp
36+
* @param message
37+
* @deprecated Use {@link #HistoryEntry(long, ZonedDateTime, String)} instead.
38+
*/
39+
@Deprecated
3140
public HistoryEntry(long index, Timestamp timestamp, String message) {
41+
this(index, timestamp.toInstant().atZone(ZonedDateTime.now().getZone()), message);
42+
}
43+
44+
public HistoryEntry(long index, ZonedDateTime date, String message) {
3245
super();
3346
this.index = index;
34-
this.timestamp = timestamp;
47+
this.date = date;
3548
this.message = message;
3649
}
3750

51+
@Deprecated
3852
public Timestamp getTimestamp() {
39-
return timestamp;
53+
return Timestamp.from(date.toInstant());
4054
}
4155

56+
@Deprecated
4257
public void setTimestamp(Timestamp timestamp) {
43-
this.timestamp = timestamp;
58+
setDate(timestamp.toInstant().atZone(ZonedDateTime.now().getZone()));
59+
}
60+
61+
public ZonedDateTime getDate() {
62+
return date;
63+
}
64+
65+
public void setDate(ZonedDateTime date) {
66+
this.date = date;
4467
}
4568

4669
public String getMessage() {
@@ -61,7 +84,7 @@ public void setIndex(long index) {
6184

6285
@Override
6386
public String toString() {
64-
return "HistoryEntry [timestamp=" + timestamp + ", message=" + message
87+
return "HistoryEntry [date=" + date + ", message=" + message
6588
+ ", index=" + index + "]";
6689
}
6790

accesscontroltool-bundle/src/main/java/biz/netcentric/cq/tools/actool/api/package-info.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
@Version("3.3.0")
1+
@Version("3.4.0")
22
package biz.netcentric.cq.tools.actool.api;
33

44
/*-

accesscontroltool-bundle/src/main/java/biz/netcentric/cq/tools/actool/history/impl/PersistableInstallationLogger.java

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import java.text.DateFormat;
2323
import java.text.NumberFormat;
2424
import java.text.SimpleDateFormat;
25+
import java.time.ZonedDateTime;
2526
import java.util.Collection;
2627
import java.util.Date;
2728
import java.util.HashSet;
@@ -141,8 +142,7 @@ public void addWarning(Logger log, String warning) {
141142
}
142143

143144
protected void addWarning(String warning) {
144-
warnings.add(new HistoryEntry(msgIndex, new Timestamp(
145-
new Date().getTime()), MSG_IDENTIFIER_WARNING + warning));
145+
warnings.add(new HistoryEntry(msgIndex, ZonedDateTime.now(), MSG_IDENTIFIER_WARNING + warning));
146146
listeners.forEach(l -> l.accept(InstallationLogLevel.WARNING, warning));
147147
msgIndex++;
148148
}
@@ -154,8 +154,7 @@ public void addMessage(Logger log, String message) {
154154
}
155155

156156
protected void addMessage(String message) {
157-
messages.add(new HistoryEntry(msgIndex, new Timestamp(new Date()
158-
.getTime()), " " + message));
157+
messages.add(new HistoryEntry(msgIndex, ZonedDateTime.now(), " " + message));
159158
listeners.forEach(l -> l.accept(InstallationLogLevel.INFO, message));
160159
msgIndex++;
161160
}
@@ -175,8 +174,7 @@ public void addError(final String error, Throwable e) {
175174
if (e != null) {
176175
fullErrorValue += " / e=" + e;
177176
}
178-
errors.add(new HistoryEntry(msgIndex, new Timestamp(
179-
new Date().getTime()), MSG_IDENTIFIER_ERROR + fullErrorValue));
177+
errors.add(new HistoryEntry(msgIndex, ZonedDateTime.now(), MSG_IDENTIFIER_ERROR + fullErrorValue));
180178
listeners.forEach(l -> l.accept(InstallationLogLevel.ERROR, error));
181179
success = false;
182180
msgIndex++;
@@ -195,8 +193,7 @@ public void addVerboseMessage(Logger log, String message) {
195193
}
196194

197195
protected void addVerboseMessage(String message) {
198-
verboseMessages.add(new HistoryEntry(msgIndex, new Timestamp(
199-
new Date().getTime()), " " + message));
196+
verboseMessages.add(new HistoryEntry(msgIndex, ZonedDateTime.now(), " " + message));
200197
listeners.forEach(l -> l.accept(InstallationLogLevel.TRACE, message));
201198
msgIndex++;
202199
}
@@ -268,7 +265,7 @@ private String getMessageString(Set<HistoryEntry> messageHistorySet) {
268265
StringBuilder sb = new StringBuilder();
269266
if (!messageHistorySet.isEmpty()) {
270267
for (HistoryEntry entry : messageHistorySet) {
271-
sb.append(EOL + timestampFormat.format(entry.getTimestamp()) + ": "
268+
sb.append(EOL + timestampFormat.format(entry.getDate()) + ": "
272269
+ entry.getMessage());
273270
}
274271
}

0 commit comments

Comments
 (0)