From d3091d1e2dd25441dab59fc92699d02715caf4fa Mon Sep 17 00:00:00 2001 From: Teryk Bellahsene Date: Fri, 6 Feb 2015 09:23:38 +0100 Subject: [PATCH] SONAR-5183 timezones - fix views and devcockpit --- .../TimeMachineConfigurationPersister.java | 2 +- .../org/sonar/batch/ProjectConfigurator.java | 4 +- .../sonar/batch/components/PastSnapshot.java | 2 +- .../components/PastSnapshotFinderByDays.java | 6 +- .../PastSnapshotFinderByPreviousAnalysis.java | 4 +- .../PastSnapshotFinderByPreviousVersion.java | 2 +- .../PastSnapshotFinderByVersion.java | 2 +- .../batch/components/PeriodsDefinition.java | 4 +- .../components/TimeMachineConfiguration.java | 2 +- .../sonar/batch/index/ResourcePersister.java | 10 +- .../PastSnapshotFinderByDaysTest.java | 2 +- .../components/PastSnapshotFinderTest.java | 4 +- .../batch/components/PastSnapshotTest.java | 10 +- .../main/java/org/sonar/api/batch/Event.java | 2 +- .../sonar/api/database/model/Snapshot.java | 101 +++++++++++++++--- .../api/database/model/SnapshotTest.java | 6 +- 16 files changed, 115 insertions(+), 48 deletions(-) diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/TimeMachineConfigurationPersister.java b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/TimeMachineConfigurationPersister.java index 13f1a85efbf..84125404fb0 100644 --- a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/TimeMachineConfigurationPersister.java +++ b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/TimeMachineConfigurationPersister.java @@ -77,6 +77,6 @@ public final class TimeMachineConfigurationPersister implements Decorator { int periodIndex = pastSnapshot.getIndex(); snapshot.setPeriodMode(periodIndex, pastSnapshot.getMode()); snapshot.setPeriodModeParameter(periodIndex, pastSnapshot.getModeParameter()); - snapshot.setPeriodDate(periodIndex, dateToLong(pastSnapshot.getDate())); + snapshot.setPeriodDateMs(periodIndex, dateToLong(pastSnapshot.getDate())); } } diff --git a/sonar-batch/src/main/java/org/sonar/batch/ProjectConfigurator.java b/sonar-batch/src/main/java/org/sonar/batch/ProjectConfigurator.java index 4447bf9e4b4..b345f2e1b0a 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/ProjectConfigurator.java +++ b/sonar-batch/src/main/java/org/sonar/batch/ProjectConfigurator.java @@ -95,12 +95,12 @@ public class ProjectConfigurator implements BatchComponent { ResourceModel persistedProject = databaseSession.getSingleResult(ResourceModel.class, "key", projectKey, "enabled", true); if (persistedProject != null) { Snapshot lastSnapshot = databaseSession.getSingleResult(Snapshot.class, "resourceId", persistedProject.getId(), "last", true); - boolean analysisBeforeLastSnapshot = lastSnapshot != null && analysisDate.getTime() <= lastSnapshot.getCreatedAt(); + boolean analysisBeforeLastSnapshot = lastSnapshot != null && analysisDate.getTime() <= lastSnapshot.getCreatedAtMs(); if (analysisBeforeLastSnapshot) { throw new IllegalArgumentException( "'sonar.projectDate' property cannot be older than the date of the last known quality snapshot on this project. Value: '" + settings.getString(CoreProperties.PROJECT_DATE_PROPERTY) + "'. " + - "Latest quality snapshot: '" + formatDateTime(longToDate(lastSnapshot.getCreatedAt())) + "Latest quality snapshot: '" + formatDateTime(longToDate(lastSnapshot.getCreatedAtMs())) + "'. This property may only be used to rebuild the past in a chronological order."); } } diff --git a/sonar-batch/src/main/java/org/sonar/batch/components/PastSnapshot.java b/sonar-batch/src/main/java/org/sonar/batch/components/PastSnapshot.java index aaaca928970..48955f9738f 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/components/PastSnapshot.java +++ b/sonar-batch/src/main/java/org/sonar/batch/components/PastSnapshot.java @@ -75,7 +75,7 @@ public class PastSnapshot { } public Date getDate() { - return projectSnapshot != null ? longToDate(projectSnapshot.getCreatedAt()) : null; + return projectSnapshot != null ? longToDate(projectSnapshot.getCreatedAtMs()) : null; } public PastSnapshot setMode(String mode) { diff --git a/sonar-batch/src/main/java/org/sonar/batch/components/PastSnapshotFinderByDays.java b/sonar-batch/src/main/java/org/sonar/batch/components/PastSnapshotFinderByDays.java index a3aa8b8387f..0f802682c8a 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/components/PastSnapshotFinderByDays.java +++ b/sonar-batch/src/main/java/org/sonar/batch/components/PastSnapshotFinderByDays.java @@ -41,10 +41,10 @@ public class PastSnapshotFinderByDays implements BatchExtension { } PastSnapshot findFromDays(Snapshot projectSnapshot, int days) { - Date targetDate = DateUtils.addDays(longToDate(projectSnapshot.getCreatedAt()), -days); + Date targetDate = DateUtils.addDays(longToDate(projectSnapshot.getCreatedAtMs()), -days); String hql = "from " + Snapshot.class.getSimpleName() + " where resourceId=:resourceId AND status=:status AND createdAt<:date AND qualifier<>:lib order by createdAt asc"; List snapshots = session.createQuery(hql) - .setParameter("date", projectSnapshot.getCreatedAt()) + .setParameter("date", projectSnapshot.getCreatedAtMs()) .setParameter("resourceId", projectSnapshot.getResourceId()) .setParameter("status", Snapshot.STATUS_PROCESSED) .setParameter("lib", Qualifiers.LIBRARY) @@ -65,7 +65,7 @@ public class PastSnapshotFinderByDays implements BatchExtension { long bestDistance = Long.MAX_VALUE; Snapshot nearest = null; for (Snapshot snapshot : snapshots) { - long distance = distance(longToDate(snapshot.getCreatedAt()), targetDate); + long distance = distance(longToDate(snapshot.getCreatedAtMs()), targetDate); if (distance <= bestDistance) { bestDistance = distance; nearest = snapshot; diff --git a/sonar-batch/src/main/java/org/sonar/batch/components/PastSnapshotFinderByPreviousAnalysis.java b/sonar-batch/src/main/java/org/sonar/batch/components/PastSnapshotFinderByPreviousAnalysis.java index 627e1943b0c..506295775ef 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/components/PastSnapshotFinderByPreviousAnalysis.java +++ b/sonar-batch/src/main/java/org/sonar/batch/components/PastSnapshotFinderByPreviousAnalysis.java @@ -44,7 +44,7 @@ public class PastSnapshotFinderByPreviousAnalysis implements BatchExtension { String hql = "from " + Snapshot.class.getSimpleName() + " where createdAt<:date AND resourceId=:resourceId AND status=:status and last=:last and qualifier<>:lib order by createdAt desc"; List snapshots = session.createQuery(hql) - .setParameter("date", projectSnapshot.getCreatedAt()) + .setParameter("date", projectSnapshot.getCreatedAtMs()) .setParameter("resourceId", projectSnapshot.getResourceId()) .setParameter("status", Snapshot.STATUS_PROCESSED) .setParameter("last", true) @@ -56,7 +56,7 @@ public class PastSnapshotFinderByPreviousAnalysis implements BatchExtension { return new PastSnapshot(CoreProperties.TIMEMACHINE_MODE_PREVIOUS_ANALYSIS); } Snapshot snapshot = snapshots.get(0); - Date targetDate = longToDate(snapshot.getCreatedAt()); + Date targetDate = longToDate(snapshot.getCreatedAtMs()); SimpleDateFormat format = new SimpleDateFormat(DateUtils.DATE_FORMAT); return new PastSnapshot(CoreProperties.TIMEMACHINE_MODE_PREVIOUS_ANALYSIS, targetDate, snapshot).setModeParameter(format.format(targetDate)); } diff --git a/sonar-batch/src/main/java/org/sonar/batch/components/PastSnapshotFinderByPreviousVersion.java b/sonar-batch/src/main/java/org/sonar/batch/components/PastSnapshotFinderByPreviousVersion.java index 85fc0f855da..6437688bf68 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/components/PastSnapshotFinderByPreviousVersion.java +++ b/sonar-batch/src/main/java/org/sonar/batch/components/PastSnapshotFinderByPreviousVersion.java @@ -57,7 +57,7 @@ public class PastSnapshotFinderByPreviousVersion implements BatchExtension { Event previousVersionEvent = events.get(0); Snapshot snapshot = session.getSingleResult(Snapshot.class, "id", previousVersionEvent.getSnapshot().getId()); - return new PastSnapshot(CoreProperties.TIMEMACHINE_MODE_PREVIOUS_VERSION, longToDate(snapshot.getCreatedAt()), snapshot).setModeParameter(snapshot.getVersion()); + return new PastSnapshot(CoreProperties.TIMEMACHINE_MODE_PREVIOUS_VERSION, longToDate(snapshot.getCreatedAtMs()), snapshot).setModeParameter(snapshot.getVersion()); } } diff --git a/sonar-batch/src/main/java/org/sonar/batch/components/PastSnapshotFinderByVersion.java b/sonar-batch/src/main/java/org/sonar/batch/components/PastSnapshotFinderByVersion.java index 3995c2cb69d..161bd87b2ee 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/components/PastSnapshotFinderByVersion.java +++ b/sonar-batch/src/main/java/org/sonar/batch/components/PastSnapshotFinderByVersion.java @@ -53,7 +53,7 @@ public class PastSnapshotFinderByVersion implements BatchExtension { result = new PastSnapshot(CoreProperties.TIMEMACHINE_MODE_VERSION); } else { Snapshot snapshot = snapshots.get(0); - Date targetDate = longToDate(snapshot.getCreatedAt()); + Date targetDate = longToDate(snapshot.getCreatedAtMs()); result = new PastSnapshot(CoreProperties.TIMEMACHINE_MODE_VERSION, targetDate, snapshot).setModeParameter(version); } return result; diff --git a/sonar-batch/src/main/java/org/sonar/batch/components/PeriodsDefinition.java b/sonar-batch/src/main/java/org/sonar/batch/components/PeriodsDefinition.java index 9f75d86fcb6..6f1eb16a5bc 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/components/PeriodsDefinition.java +++ b/sonar-batch/src/main/java/org/sonar/batch/components/PeriodsDefinition.java @@ -79,8 +79,8 @@ public class PeriodsDefinition implements BatchComponent { if (projectId != null) { snapshot = new Snapshot(); snapshot.setResourceId(projectId.intValue()); - snapshot.setCreatedAt(dateToLong(projectTree.getRootProject().getAnalysisDate())); - snapshot.setBuildDate(System.currentTimeMillis()); + snapshot.setCreatedAtMs(dateToLong(projectTree.getRootProject().getAnalysisDate())); + snapshot.setBuildDateMs(System.currentTimeMillis()); snapshot.setVersion(projectTree.getRootProject().getAnalysisVersion()); } return snapshot; diff --git a/sonar-batch/src/main/java/org/sonar/batch/components/TimeMachineConfiguration.java b/sonar-batch/src/main/java/org/sonar/batch/components/TimeMachineConfiguration.java index 28c4957d89f..2d4c71bc9c1 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/components/TimeMachineConfiguration.java +++ b/sonar-batch/src/main/java/org/sonar/batch/components/TimeMachineConfiguration.java @@ -60,7 +60,7 @@ public class TimeMachineConfiguration implements BatchComponent { PastSnapshot pastSnapshot = projectPastSnapshot.clonePastSnapshot(); modulePastSnapshots.add(pastSnapshot); // When no snapshot is found, date of the period is null - periods.add(new Period(pastSnapshot.getIndex(), snapshot != null ? longToDate(snapshot.getCreatedAt()) : null)); + periods.add(new Period(pastSnapshot.getIndex(), snapshot != null ? longToDate(snapshot.getCreatedAtMs()) : null)); log(pastSnapshot); } } diff --git a/sonar-batch/src/main/java/org/sonar/batch/index/ResourcePersister.java b/sonar-batch/src/main/java/org/sonar/batch/index/ResourcePersister.java index 7373053e2c0..8b739aada02 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/index/ResourcePersister.java +++ b/sonar-batch/src/main/java/org/sonar/batch/index/ResourcePersister.java @@ -135,8 +135,8 @@ public class ResourcePersister implements ScanPersister { Snapshot snapshot = new Snapshot(model, parentSnapshot); snapshot.setVersion(project.getAnalysisVersion()); - snapshot.setCreatedAt(dateToLong(project.getAnalysisDate())); - snapshot.setBuildDate(System.currentTimeMillis()); + snapshot.setCreatedAtMs(dateToLong(project.getAnalysisDate())); + snapshot.setBuildDateMs(System.currentTimeMillis()); snapshot = session.save(snapshot); session.commit(); @@ -170,8 +170,8 @@ public class ResourcePersister implements ScanPersister { Snapshot snapshot = findLibrarySnapshot(model.getId(), library.getVersion()); if (snapshot == null) { snapshot = new Snapshot(model, null); - snapshot.setCreatedAt(dateToLong(analysisDate)); - snapshot.setBuildDate(System.currentTimeMillis()); + snapshot.setCreatedAtMs(dateToLong(analysisDate)); + snapshot.setBuildDateMs(System.currentTimeMillis()); snapshot.setVersion(library.getVersion()); snapshot.setStatus(Snapshot.STATUS_PROCESSED); @@ -219,7 +219,7 @@ public class ResourcePersister implements ScanPersister { } Snapshot snapshot = new Snapshot(model, parentSnapshot); - snapshot.setBuildDate(System.currentTimeMillis()); + snapshot.setBuildDateMs(System.currentTimeMillis()); snapshot = session.save(snapshot); session.commit(); return snapshot; diff --git a/sonar-batch/src/test/java/org/sonar/batch/components/PastSnapshotFinderByDaysTest.java b/sonar-batch/src/test/java/org/sonar/batch/components/PastSnapshotFinderByDaysTest.java index 44b69304b45..1b136e9ae72 100644 --- a/sonar-batch/src/test/java/org/sonar/batch/components/PastSnapshotFinderByDaysTest.java +++ b/sonar-batch/src/test/java/org/sonar/batch/components/PastSnapshotFinderByDaysTest.java @@ -107,7 +107,7 @@ public class PastSnapshotFinderByDaysTest extends AbstractDbUnitTestCase { private Snapshot newSnapshot(int id, String date) throws ParseException { Snapshot snapshot = new Snapshot(); snapshot.setId(id); - snapshot.setCreatedAt(dateFormat.parse(date).getTime()); + snapshot.setCreatedAtMs(dateFormat.parse(date).getTime()); return snapshot; } } diff --git a/sonar-batch/src/test/java/org/sonar/batch/components/PastSnapshotFinderTest.java b/sonar-batch/src/test/java/org/sonar/batch/components/PastSnapshotFinderTest.java index f821e63057f..c335d3b87d6 100644 --- a/sonar-batch/src/test/java/org/sonar/batch/components/PastSnapshotFinderTest.java +++ b/sonar-batch/src/test/java/org/sonar/batch/components/PastSnapshotFinderTest.java @@ -148,7 +148,7 @@ public class PastSnapshotFinderTest { public void should_find_by_previous_analysis() throws ParseException { final Date date = DateUtils.parseDate("2010-05-18"); Snapshot snapshot = new Snapshot(); - snapshot.setCreatedAt(date.getTime()); + snapshot.setCreatedAtMs(date.getTime()); when(finderByPreviousAnalysis.findByPreviousAnalysis(null)).thenReturn(new PastSnapshot(CoreProperties.TIMEMACHINE_MODE_PREVIOUS_ANALYSIS, date, snapshot)); PastSnapshot variationSnapshot = finder.find(null, 2, CoreProperties.TIMEMACHINE_MODE_PREVIOUS_ANALYSIS); @@ -175,7 +175,7 @@ public class PastSnapshotFinderTest { final SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd"); final Date date = format.parse("2010-05-18"); Snapshot snapshot = new Snapshot(); - snapshot.setCreatedAt(date.getTime()); + snapshot.setCreatedAtMs(date.getTime()); when(finderByPreviousVersion.findByPreviousVersion(null)).thenReturn(new PastSnapshot(CoreProperties.TIMEMACHINE_MODE_PREVIOUS_VERSION, date, snapshot)); PastSnapshot variationSnapshot = finder.find(null, 2, CoreProperties.TIMEMACHINE_MODE_PREVIOUS_VERSION); diff --git a/sonar-batch/src/test/java/org/sonar/batch/components/PastSnapshotTest.java b/sonar-batch/src/test/java/org/sonar/batch/components/PastSnapshotTest.java index 4113cfc069c..3d38431f780 100644 --- a/sonar-batch/src/test/java/org/sonar/batch/components/PastSnapshotTest.java +++ b/sonar-batch/src/test/java/org/sonar/batch/components/PastSnapshotTest.java @@ -32,7 +32,7 @@ public class PastSnapshotTest { @Test public void test_some_setters_and_getters() { - Snapshot snapshot = new Snapshot().setQualifier(Qualifiers.FILE).setCreatedAt(System.currentTimeMillis()); + Snapshot snapshot = new Snapshot().setQualifier(Qualifiers.FILE).setCreatedAtMs(System.currentTimeMillis()); snapshot.setId(10); PastSnapshot pastSnapshot = new PastSnapshot(CoreProperties.TIMEMACHINE_MODE_VERSION, new Date(), snapshot) @@ -57,7 +57,7 @@ public class PastSnapshotTest { @Test public void testToStringForVersion() { - PastSnapshot pastSnapshot = new PastSnapshot(CoreProperties.TIMEMACHINE_MODE_VERSION, new Date(), new Snapshot().setCreatedAt(System.currentTimeMillis())).setModeParameter("2.3"); + PastSnapshot pastSnapshot = new PastSnapshot(CoreProperties.TIMEMACHINE_MODE_VERSION, new Date(), new Snapshot().setCreatedAtMs(System.currentTimeMillis())).setModeParameter("2.3"); assertThat(pastSnapshot.toString()).startsWith("Compare to version 2.3"); } @@ -75,7 +75,7 @@ public class PastSnapshotTest { @Test public void testToStringForNumberOfDaysWithSnapshot() { - PastSnapshot pastSnapshot = new PastSnapshot(CoreProperties.TIMEMACHINE_MODE_DAYS, new Date(), new Snapshot().setCreatedAt(System.currentTimeMillis())).setModeParameter("30"); + PastSnapshot pastSnapshot = new PastSnapshot(CoreProperties.TIMEMACHINE_MODE_DAYS, new Date(), new Snapshot().setCreatedAtMs(System.currentTimeMillis())).setModeParameter("30"); assertThat(pastSnapshot.toString()).startsWith("Compare over 30 days ("); } @@ -87,13 +87,13 @@ public class PastSnapshotTest { @Test public void testToStringForDateWithSnapshot() { - PastSnapshot pastSnapshot = new PastSnapshot(CoreProperties.TIMEMACHINE_MODE_DATE, new Date(), new Snapshot().setCreatedAt(System.currentTimeMillis())); + PastSnapshot pastSnapshot = new PastSnapshot(CoreProperties.TIMEMACHINE_MODE_DATE, new Date(), new Snapshot().setCreatedAtMs(System.currentTimeMillis())); assertThat(pastSnapshot.toString()).startsWith("Compare to date "); } @Test public void testToStringForPreviousAnalysis() { - PastSnapshot pastSnapshot = new PastSnapshot(CoreProperties.TIMEMACHINE_MODE_PREVIOUS_ANALYSIS, new Date(), new Snapshot().setCreatedAt(System.currentTimeMillis())); + PastSnapshot pastSnapshot = new PastSnapshot(CoreProperties.TIMEMACHINE_MODE_PREVIOUS_ANALYSIS, new Date(), new Snapshot().setCreatedAtMs(System.currentTimeMillis())); assertThat(pastSnapshot.toString()).startsWith("Compare to previous analysis "); } diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/Event.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/Event.java index 406161ed758..8c802c2ca98 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/batch/Event.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/batch/Event.java @@ -125,7 +125,7 @@ public class Event extends BaseIdentifiable { public final void setSnapshot(Snapshot snapshot) { this.snapshot = snapshot; if (snapshot != null) { - this.date = (snapshot.getCreatedAt() == null ? null : new Date(snapshot.getCreatedAt())); + this.date = (snapshot.getCreatedAtMs() == null ? null : new Date(snapshot.getCreatedAtMs())); this.resourceId = snapshot.getResourceId(); } } diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/database/model/Snapshot.java b/sonar-plugin-api/src/main/java/org/sonar/api/database/model/Snapshot.java index 347690a8a21..2a3a9972653 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/database/model/Snapshot.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/database/model/Snapshot.java @@ -29,9 +29,13 @@ import org.sonar.api.database.DatabaseSession; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.Table; + import java.io.Serializable; import java.util.Date; +import static org.sonar.api.utils.DateUtils.dateToLong; +import static org.sonar.api.utils.DateUtils.longToDate; + /** * A class to map a snapshot with its hibernate model */ @@ -153,7 +157,7 @@ public class Snapshot extends BaseIdentifiable implements Serializable } else { this.parentId = parent.getId(); this.rootId = (parent.getRootId() == null ? parent.getId() : parent.getRootId()); - this.createdAt = parent.getCreatedAt(); + this.createdAt = parent.getCreatedAtMs(); this.depth = parent.getDepth() + 1; this.path = new StringBuilder() .append(parent.getPath()) @@ -191,7 +195,11 @@ public class Snapshot extends BaseIdentifiable implements Serializable * * @since 2.14 */ - public Long getBuildDate() { + public Date getBuildDate() { + return longToDate(buildDate); + } + + public Long getBuildDateMs() { return buildDate; } @@ -200,16 +208,30 @@ public class Snapshot extends BaseIdentifiable implements Serializable * * @since 2.14 */ - public Snapshot setBuildDate(Long d) { + public Snapshot setBuildDate(Date date) { + this.buildDate = dateToLong(date); + return this; + } + + public Snapshot setBuildDateMs(Long d) { this.buildDate = d; return this; } - public Long getCreatedAt() { + public Date getCreatedAt() { + return longToDate(createdAt); + } + + public Long getCreatedAtMs() { return createdAt; } - public Snapshot setCreatedAt(Long createdAt) { + public Snapshot setCreatedAt(Date createdAt) { + this.createdAt = dateToLong(createdAt); + return this; + } + + public Snapshot setCreatedAtMs(Long createdAt) { this.createdAt = createdAt; return this; } @@ -482,7 +504,11 @@ public class Snapshot extends BaseIdentifiable implements Serializable return this; } - public Long getPeriod1Date() { + public Date getPeriod1Date() { + return longToDate(period1Date); + } + + public Long getPeriod1DateMs() { return period1Date; } @@ -491,12 +517,21 @@ public class Snapshot extends BaseIdentifiable implements Serializable * * @since 2.5 */ - public Snapshot setPeriod1Date(Long period1Date) { + public Snapshot setPeriod1Date(Date period1Date) { + this.period1Date = dateToLong(period1Date); + return this; + } + + public Snapshot setPeriod1DateMs(Long period1Date) { this.period1Date = period1Date; return this; } - public Long getPeriod2Date() { + public Date getPeriod2Date() { + return longToDate(period2Date); + } + + public Long getPeriod2DateMs() { return period2Date; } @@ -505,12 +540,21 @@ public class Snapshot extends BaseIdentifiable implements Serializable * * @since 2.5 */ - public Snapshot setPeriod2Date(Long period2Date) { + public Snapshot setPeriod2Date(Date period2Date) { + this.period2Date = dateToLong(period2Date); + return this; + } + + public Snapshot setPeriod2DateMs(Long period2Date) { this.period2Date = period2Date; return this; } - public Long getPeriod3Date() { + public Date getPeriod3Date() { + return longToDate(period3Date); + } + + public Long getPeriod3DateMs() { return period3Date; } @@ -519,12 +563,21 @@ public class Snapshot extends BaseIdentifiable implements Serializable * * @since 2.5 */ - public Snapshot setPeriod3Date(Long period3Date) { + public Snapshot setPeriod3Date(Date period3Date) { + this.period3Date = dateToLong(period3Date); + return this; + } + + public Snapshot setPeriod3DateMs(Long period3Date) { this.period3Date = period3Date; return this; } - public Long getPeriod4Date() { + public Date getPeriod4Date() { + return longToDate(period4Date); + } + + public Long getPeriod4DateMs() { return period4Date; } @@ -533,12 +586,21 @@ public class Snapshot extends BaseIdentifiable implements Serializable * * @since 2.5 */ - public Snapshot setPeriod4Date(Long period4Date) { + public Snapshot setPeriod4Date(Date period4Date) { + this.period4Date = dateToLong(period4Date); + return this; + } + + public Snapshot setPeriod4DateMs(Long period4Date) { this.period4Date = period4Date; return this; } - public Long getPeriod5Date() { + public Date getPeriod5Date() { + return longToDate(period5Date); + } + + public Long getPeriod5DateMs() { return period5Date; } @@ -547,7 +609,12 @@ public class Snapshot extends BaseIdentifiable implements Serializable * * @since 2.5 */ - public Snapshot setPeriod5Date(Long period5Date) { + public Snapshot setPeriod5Date(Date period5Date) { + this.period5Date = dateToLong(period5Date); + return this; + } + + public Snapshot setPeriod5DateMs(Long period5Date) { this.period5Date = period5Date; return this; } @@ -647,7 +714,7 @@ public class Snapshot extends BaseIdentifiable implements Serializable * * @since 2.5 */ - public Snapshot setPeriodDate(int periodIndex, Long date) { + public Snapshot setPeriodDateMs(int periodIndex, Long date) { switch (periodIndex) { case 1: period1Date = date; @@ -698,7 +765,7 @@ public class Snapshot extends BaseIdentifiable implements Serializable Snapshot other = (Snapshot) obj; return new EqualsBuilder() .append(resourceId, other.getResourceId()) - .append(createdAt, other.getCreatedAt()) + .append(createdAt, other.getCreatedAtMs()) .isEquals(); } diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/database/model/SnapshotTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/database/model/SnapshotTest.java index c102f844234..148572c83fb 100644 --- a/sonar-plugin-api/src/test/java/org/sonar/api/database/model/SnapshotTest.java +++ b/sonar-plugin-api/src/test/java/org/sonar/api/database/model/SnapshotTest.java @@ -29,11 +29,11 @@ public class SnapshotTest { @Test public void testGetDate() { Snapshot snapshot = new Snapshot(); - assertNull(snapshot.getCreatedAt()); + assertNull(snapshot.getCreatedAtMs()); Long now = System.currentTimeMillis(); - snapshot.setCreatedAt(now); - assertEquals(now, snapshot.getCreatedAt()); + snapshot.setCreatedAtMs(now); + assertEquals(now, snapshot.getCreatedAtMs()); } @Test -- 2.39.5