From 5775a857cef75304c0e35bbd801a7a01552e8a08 Mon Sep 17 00:00:00 2001 From: Simon Brandhof Date: Wed, 25 Jun 2014 15:50:17 +0200 Subject: [PATCH] SONAR-5007 fix link to profile changelog --- .../sonar/batch/rule/QProfileEventsDecorator.java | 15 +++++++++------ .../batch/rule/QProfileEventsDecoratorTest.java | 4 ++-- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/sonar-batch/src/main/java/org/sonar/batch/rule/QProfileEventsDecorator.java b/sonar-batch/src/main/java/org/sonar/batch/rule/QProfileEventsDecorator.java index cfbed1da0e6..28c1fea24c3 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/rule/QProfileEventsDecorator.java +++ b/sonar-batch/src/main/java/org/sonar/batch/rule/QProfileEventsDecorator.java @@ -111,18 +111,21 @@ public class QProfileEventsDecorator implements Decorator { event.setCategory(Event.CATEGORY_PROFILE); Date from = previousProfile.getRulesUpdatedAt(); - // strictly greater than previous date - // This hack must be done because date precision is millisecond in db/es and date format is select only - from = DateUtils.addSeconds(from, 1); - String data = KeyValueFormat.format(ImmutableSortedMap.of( "key", profile.getKey(), - "from", UtcDateUtils.formatDateTime(from), - "to", UtcDateUtils.formatDateTime(profile.getRulesUpdatedAt()))); + "from", UtcDateUtils.formatDateTime(fixDate(from)), + "to", UtcDateUtils.formatDateTime(fixDate(profile.getRulesUpdatedAt())))); event.setData(data); persistenceManager.saveEvent(context.getResource(), event); } + /** + * This hack must be done because date precision is millisecond in db/es and date format is select only + */ + private Date fixDate(Date date) { + return DateUtils.addSeconds(date, 1); + } + private void markAsRemoved(DecoratorContext context, QProfile profile) { context.createEvent(String.format("Stop using %s", profileLabel(profile)), null, Event.CATEGORY_PROFILE, null); } diff --git a/sonar-batch/src/test/java/org/sonar/batch/rule/QProfileEventsDecoratorTest.java b/sonar-batch/src/test/java/org/sonar/batch/rule/QProfileEventsDecoratorTest.java index 3d7f46fde69..6618cc7f832 100644 --- a/sonar-batch/src/test/java/org/sonar/batch/rule/QProfileEventsDecoratorTest.java +++ b/sonar-batch/src/test/java/org/sonar/batch/rule/QProfileEventsDecoratorTest.java @@ -122,8 +122,8 @@ public class QProfileEventsDecoratorTest { Event event = (Event) item; return event.getCategory().equals(Event.CATEGORY_PROFILE) && "Changes in 'Java One' (Java)".equals(event.getName()) && - // "from" is one second more ! - "from=2014-01-15T12:00:01+0000;key=J1;to=2014-02-20T12:00:00+0000".equals(event.getData()); + // "from" and "to" must have one second more because of lack of ms precision + "from=2014-01-15T12:00:01+0000;key=J1;to=2014-02-20T12:00:01+0000".equals(event.getData()); } })); } -- 2.39.5